// // Created by casic on 25-2-25. // #ifndef TCP_SERVICE_HPP #define TCP_SERVICE_HPP #include <vector> #include <boost/asio.hpp> #include "message_observer.hpp" using boost::asio::serial_port_base; class TcpService final : public MessageObserver { public: explicit TcpService(boost::asio::io_context &io_context, const std::string &port_name, int baud_rate); void start(int port); void init_serial_port(const std::string &port_name, int baud_rate); void on_message_received(const std::vector<uint8_t> &command) override; void on_node_arrived(const int &node) override; private: int _socket_fd; std::vector<int> _client_sockets; boost::asio::io_context &_context; boost::asio::serial_port _port; void handle_data_packet(std::vector<uint8_t> &data); void handle_client(int client_socket); }; #endif //TCP_SERVICE_HPP