srs-control 0.2.2
Loading...
Searching...
No Matches
ConnectionBase.cpp
Go to the documentation of this file.
9#include <asio/awaitable.hpp>
10#include <asio/buffer.hpp>
11#include <asio/use_awaitable.hpp>
12#include <cstdint>
13#include <fmt/base.h>
14#include <fmt/core.h>
15#include <fmt/format.h>
16#include <fmt/ranges.h>
17#include <memory>
18#include <span>
19#include <spdlog/spdlog.h>
20
21namespace srs::connection
22{
23
24 auto CommandBase::send_message(std::shared_ptr<FecCommandSocket> socket, std::shared_ptr<CommandBase> connection)
25 -> asio::awaitable<void>
26 {
27 const auto _ = ExitLogger{};
28 auto stat = AppReport::FecSwitchStat{};
29 stat.send_time = socket->get_time_us();
30 auto data_size = co_await socket->get_socket().async_send_to(
31 asio::buffer(connection->write_msg_buffer_.data()), connection->remote_endpoint_, asio::use_awaitable);
32 stat.receiv_time = socket->get_time_us();
33 spdlog::debug("Connection {}: {} bytes data sent from local endpoint {} to the remote endpoint {}: \n\t{:02x}",
34 connection->get_name(),
35 data_size,
36 socket->get_socket().local_endpoint(),
37 connection->remote_endpoint_,
38 fmt::join(connection->write_msg_buffer_.data(), " "));
39 stat.connection_name = connection->get_name();
40 socket->log_time_stamps(fmt::format("{}", connection->remote_endpoint_), stat);
41 co_return;
42 }
43
45 uint32_t counter,
46 std::span<const CommunicateEntryType> data,
47 uint16_t address)
48 {
49 // TODO: make the end part a static data
50 buffer.serialize(counter,
52 address,
56 buffer.serialize(data);
57 }
58
59 auto CommandBase::check_response(std::span<char> response_msg) const -> bool
60 {
62 {
63 spdlog::trace("write_msg_response_buffer is empty!");
64 return true;
65 }
66 return write_msg_response_buffer_ == response_msg;
67 }
68} // namespace srs::connection
process::SerializableMsgBuffer write_msg_response_buffer_
static auto send_message(std::shared_ptr< FecCommandSocket > socket, std::shared_ptr< CommandBase > connection) -> asio::awaitable< void >
auto check_response(std::span< char > response_msg) const -> bool
static void encode_write_msg(process::SerializableMsgBuffer &buffer, uint32_t counter, std::span< const CommunicateEntryType > data, uint16_t address)
constexpr auto WRITE_COMMAND_BITS
constexpr auto DEFAULT_TYPE_BITS
constexpr auto ZERO_UINT16_PADDING
constexpr auto COMMAND_LENGTH_BITS