50 return std::string{ acq_on_connect.get_response_msg() };
54 return std::string{ acq_off_connect.get_response_msg() };
70 buffer.serialize(send_suffix);
71 return std::string{ buffer.data() };
76 buffer.serialize(send_suffix);
77 return std::string{ buffer.data() };
85 static const auto msg_map = std::map<std::string, SRSEmulator::ReceiveType>{
86 { get_send_msg_from_receive_type(acq_on), acq_on },
87 { get_send_msg_from_receive_type(acq_off), acq_off },
89 auto msg_iter = std::ranges::find_if(
90 msg_map, [msg](
const auto& suffix_type) ->
bool {
return msg.ends_with(suffix_type.first); });
92 spdlog::trace(
"msg_map available options {}",
93 fmt::join(msg_map | std::views::transform(
94 [](
const auto& str_type) -> std::string
96 return fmt::format(
"{}: {:02x}",
97 magic_enum::enum_name(str_type.second),
98 fmt::join(str_type.first,
" "));
101 if (msg_iter == msg_map.end())
105 return msg_iter->second;
112 asio::ip::
udp::endpoint{ asio::ip::
udp::v4(),
113 static_cast<asio::ip::port_type>(
config_.listen_port) } }
130 auto timer_waiter = [](std::shared_ptr<asio::system_timer> timer) -> asio::awaitable<void>
131 { [[maybe_unused]]
auto [err] =
co_await timer->async_wait(asio::as_tuple(asio::use_awaitable)); };
150 -> asio::awaitable<void>
152 auto msg = get_msg_from_receive_type(result_type);
153 [[maybe_unused]]
const auto size =
154 co_await udp_socket_.async_send_to(asio::buffer(msg), endpoint, asio::use_awaitable);
155 spdlog::trace(
"SRS server: sent the data {:02x} to the remote point {}", fmt::join(msg,
" "), endpoint);
160 auto msg_buffer = std::vector<char>{};
162 auto executor =
co_await asio::this_coro::executor;
165 spdlog::trace(
"SRS server: listening on the local port {}",
udp_socket_.local_endpoint());
166 auto remote_endpoint = asio::ip::udp::endpoint{};
168 co_await udp_socket_.async_receive_from(asio::buffer(msg_buffer), remote_endpoint, asio::use_awaitable);
169 auto msg = std::string_view{ msg_buffer.data(), msg_size };
170 auto result = check_receive_msg_type(msg);
171 spdlog::trace(
"SRS server: Request type {:?} received with the msg: {:02x}",
172 magic_enum::enum_name(result),
173 fmt::join(msg,
" "));
186 spdlog::trace(
"SRS server: existing coroutine");
195 spdlog::info(
"Server: Starting to send data from emulator ...");
196 auto total_size = std::size_t{ 0 };
197 auto executor =
co_await asio::this_coro::executor;
199 asio::ip::udp::endpoint{
200 asio::ip::make_address(
"127.0.0.1"),
201 static_cast<asio::ip::port_type
>(
config_.data_port) } };
208 if (not read_str.has_value())
210 spdlog::critical(
"Server: error occurred from the reading the frame with msg: {}", read_str.error());
213 if (read_str.value().empty())
222 co_await send_coro.async_resume(std::optional<std::string_view>{}, asio::use_awaitable);
229 auto send_size =
co_await send_coro.async_resume(std::optional{ read_str.value() }, asio::use_awaitable);
230 total_size += send_size.value_or(0);
232 spdlog::debug(
"reaching the end of send_data coroutine. Sent total data size: {}", total_size);