-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathtelem_udp.h
55 lines (42 loc) · 1.45 KB
/
telem_udp.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "INIReader.h"
#ifdef _WIN32
#include <Winsock2.h>
#else
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#endif
#include "telem_client.h"
class Telem_UDP : public Telem_Client {
public:
Telem_UDP() :
Telem_Client()
{ }
uint32_t handle_recv();
void init() override;
void configure(INIReader *config) override;
void pack_select_fds(fd_set &fds_read, fd_set &fds_write, fd_set &fds_err, uint8_t &nfds) override;
void handle_select_fds(fd_set &fds_read, fd_set &fds_write, fd_set &fds_err, uint8_t &nfds) override;
void do_writer_sends() override;
bool send_message(const mavlink_message_t &msg) override;
bool any_data_to_send() override {
return _send_buf_start != _send_buf_stop;
}
private:
int fd = -1;
struct sockaddr_in sa = {}; // our send-from address
struct sockaddr_in sa_destination = {}; /* udp address to connect to */
void create_and_bind(INIReader *config);
void pack_sockaddr(INIReader *config);
bool sane_packet(uint8_t *pkt, uint16_t bpktlen);
virtual bool sane_recv_buf(uint8_t *pkt, uint16_t pktlen) const;
/* send buffer stuff: */
mavlink_message_t _send_buf[256]; // way too big?
uint32_t send_buf_size() const override {
return 256;
}
std::string udp_ip(INIReader *config) const;
uint16_t udp_port(INIReader *config) const;
bool is_server(INIReader *config) const;
bool _is_server = false;
};