SRS-control 0.1.4
Loading...
Searching...
No Matches
ConnectionBase.cpp
Go to the documentation of this file.
7#include <boost/asio/awaitable.hpp>
8#include <boost/asio/buffer.hpp>
9#include <boost/asio/use_awaitable.hpp>
10#include <cstdint>
11#include <fmt/base.h>
12#include <fmt/core.h>
13#include <fmt/ranges.h>
14#include <memory>
15#include <span>
16#include <spdlog/spdlog.h>
17
18namespace srs::connection
19{
20
21 auto CommandBase::send_message(std::shared_ptr<FecCommandSocket> socket, std::shared_ptr<CommandBase> connection)
22 -> asio::awaitable<void>
23 {
24 spdlog::debug("Connection {}: Sending data using external socket at time {} us...",
25 connection->get_name(),
26 socket->get_time_us());
27 auto data_size = co_await socket->get_socket().async_send_to(
28 asio::buffer(connection->write_msg_buffer_.data()), connection->remote_endpoint_, asio::use_awaitable);
29 spdlog::debug("Connection {}: {} bytes data sent to the remote endpoint {} at time {} us: \n\t{:02x}",
30 connection->get_name(),
31 data_size,
32 connection->remote_endpoint_,
33 socket->get_time_us(),
34 fmt::join(connection->write_msg_buffer_.data(), " "));
35 co_return;
36 }
37
39 uint32_t counter,
40 std::span<const CommunicateEntryType> data,
41 uint16_t address)
42 {
43 // TODO: make the end part a static data
44 buffer.serialize(counter,
46 address,
50 buffer.serialize(data);
51 }
52
53 auto CommandBase::check_response(std::span<char> response_msg) const -> bool
54 {
56 {
57 spdlog::trace("write_msg_response_buffer is empty!");
58 return true;
59 }
60 return write_msg_response_buffer_ == response_msg;
61 }
62} // 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