Common
common packages for kyubic
 
Loading...
Searching...
No Matches
path_finder.hpp
Go to the documentation of this file.
1
11#ifndef _PATH_FINDER_HPP
12#define _PATH_FINDER_HPP
13
14#include <netinet/in.h>
15
16#include <memory>
17#include <string>
18
23
29{
30
36{
37private:
38 const char * address;
39 const int port;
40 const int timeout_ms;
41
42 int sockfd;
43 struct sockaddr_in server;
44
45 static const size_t BUFFER_SIZE = 65536;
46 unsigned char buffer[BUFFER_SIZE];
47
48 // Parsers
49 pd0::Pd0Parser parser0;
50 pd5::Pd5Parser parser5;
51
52 // Data Storage
53 pd0::Pd0Ensemble pd0_data;
54 pd5::Pd5Ensemble pd5_data;
55
56 // 0 = PD0, 5 = PD5, -1 = None
57 int last_data_type = -1;
58
59public:
67 explicit Listener(const char * _address, const int _port, const int _timeout_ms = 1000);
68
72 ~Listener();
73
79 bool listen();
80
87 ssize_t read(unsigned char * buffer, size_t size);
88
93 bool has_pd0_data() const;
94
99 bool has_pd5_data() const;
100
105 std::shared_ptr<pd0::Pd0Ensemble> get_pd0_data();
106
111 std::shared_ptr<pd5::Pd5Ensemble> get_pd5_data();
112};
113
119{
120 const char * address;
121 const int port;
122 const int timeout_ms;
123
124 int sockfd;
125 struct sockaddr_in server;
126
127 const std::string CRCF = "\r\n";
128 const std::string ping_cmd = "CS";
129 const std::string break_cmd = "===";
130
131public:
138 explicit Sender(const char * _address, const int _port, const int _timeout_ms = 1000);
139
143 ~Sender();
144
151 ssize_t read(unsigned char * buffer, size_t size);
152
156 void flush_buffer();
157
164 bool send_cmd(const std::string & cmd, const uint & wait_time = 0, bool newline = true);
165
170 bool send_break_cmd();
171
176 bool send_ping_cmd();
177};
178
179} // namespace driver::dvl_driver::path_finder
180
181#endif // _PATH_FINDER_HPP
Handles TCP reception of DVL data and dispatches parsing to PD0 or PD5 parsers.
Definition: path_finder.hpp:36
bool has_pd0_data() const
Check if valid PD0 data is currently available.
Definition: path_finder.cpp:114
~Listener()
Destructor. Closes the socket.
Definition: path_finder.cpp:66
std::shared_ptr< pd5::Pd5Ensemble > get_pd5_data()
Retrieve the latest parsed PD5 data.
Definition: path_finder.cpp:123
bool listen()
Listen for incoming data and attempt to parse it.
Definition: path_finder.cpp:78
bool has_pd5_data() const
Check if valid PD5 data is currently available.
Definition: path_finder.cpp:116
std::shared_ptr< pd0::Pd0Ensemble > get_pd0_data()
Retrieve the latest parsed PD0 data.
Definition: path_finder.cpp:118
ssize_t read(unsigned char *buffer, size_t size)
Read raw bytes from the socket.
Definition: path_finder.cpp:73
Handles TCP transmission of commands to the DVL.
Definition: path_finder.hpp:119
bool send_break_cmd()
Send a Soft Break ("===") to wake up the DVL.
Definition: path_finder.cpp:218
bool send_cmd(const std::string &cmd, const uint &wait_time=0, bool newline=true)
Send a generic string command to the DVL.
Definition: path_finder.cpp:204
ssize_t read(unsigned char *buffer, size_t size)
Read response from DVL after sending a command.
Definition: path_finder.cpp:166
bool send_ping_cmd()
Send the Start Pinging command ("CS").
Definition: path_finder.cpp:220
void flush_buffer()
Clear socket buffer.
Definition: path_finder.cpp:171
~Sender()
Destructor. Closes the socket.
Definition: path_finder.cpp:159
Class to parse PD0 binary data packets.
Definition: pd0_parser.hpp:25
Class to parse PD4/PD5 binary data packets.
Definition: pd5_parser.hpp:25
Parser for Teledyne RDI PD0 Data Format.
Teledyne RDI PD0 Data Format.
Parser for Teledyne RDI PD4/PD5 Data Format.
Teledyne RDI PD5 Data Format.