RMW desert 1.0
Loading...
Searching...
No Matches
TcpDaemon.h
Go to the documentation of this file.
1/****************************************************************************
2 * Copyright (C) 2024 Davide Costa *
3 * *
4 * This file is part of RMW desert. *
5 * *
6 * RMW desert is free software: you can redistribute it and/or modify it *
7 * under the terms of the GNU General Public License as published by the *
8 * Free Software Foundation, either version 3 of the License, or any *
9 * later version. *
10 * *
11 * RMW desert is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with RMW desert. If not, see <http://www.gnu.org/licenses/>. *
18 ****************************************************************************/
19
33#ifndef TCP_DAEMON_H_
34#define TCP_DAEMON_H_
35
38#include <queue>
39#include <vector>
40#include <cstdint>
41#include <cstdio>
42#include <cstring>
43#include <thread>
44#include <chrono>
45
46#include <arpa/inet.h>
47#include <sys/socket.h>
48#include <sys/poll.h>
49#include <unistd.h>
50
51#include "rmw/error_handling.h"
52
55#define MAX_PACKET_LENGTH 512
56
57#define ADDRESS "127.0.0.1"
58
59#define START_MARKER 0b10011001
60#define END_MARKER 0b01010101
61#define BYTE_MASK 0b11111111
62
64{
65 public:
66 TcpDaemon();
67
76 bool init(int port);
85 static std::vector<uint8_t> read_packet();
94 static void enqueue_packet(std::vector<uint8_t> packet);
95
96
97 private:
98 static int _client_fd;
99 static std::queue<std::vector<uint8_t>> _rx_packets;
100 static std::queue<std::vector<uint8_t>> _tx_packets;
101
102 void socket_rx_communication();
103 void socket_tx_communication();
104
105};
106
107#endif
Definition TcpDaemon.h:64
static void enqueue_packet(std::vector< uint8_t > packet)
Enqueue a packet in the _tx_packets member as vector of bytes.
Definition TcpDaemon.cpp:58
bool init(int port)
Initialize the socket communication.
Definition TcpDaemon.cpp:11
static std::vector< uint8_t > read_packet()
Read a packet from the _rx_packets member as vector of bytes.
Definition TcpDaemon.cpp:47