Newer
Older
casic_unitree_dog / src / tcp_service.hpp
//
// Created by casic on 25-2-25.
//

#ifndef TCP_SERVICE_HPP
#define TCP_SERVICE_HPP

#include <vector>
#include <boost/asio.hpp>

using boost::asio::serial_port_base;

class TcpService {
public:
    static TcpService &getInstance() {
        static TcpService instance;
        return instance;
    }

    TcpService(const TcpService &) = delete;

    TcpService &operator=(const TcpService &) = delete;

    void start(int port);

    /**
     * 更新节点信息
     * @param node
     */
    void update_node(int node);

    /**
     * 更新甲烷浓度数据
     * @param value
     */
    void update_gas_value(int value);

private:
    TcpService() = default;

    ~TcpService() = default;

    int _socket_fd = -1;
    std::vector<int> _client_sockets{};
    int gas_value = 0;

    void handle_client(int client_socket);
};


#endif //TCP_SERVICE_HPP