forked from markqvist/RNode_Firmware
-
-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathUDPInterface.h
More file actions
67 lines (63 loc) · 1.89 KB
/
UDPInterface.h
File metadata and controls
67 lines (63 loc) · 1.89 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
#include <Reticulum.h>
#include <Interface.h>
#include <Log.h>
#include <Bytes.h>
#include <WiFi.h>
#include <WiFiUdp.h>
#define UDP_LOCAL_HOST "0.0.0.0"
#define UDP_REMOTE_HOST "255.255.255.255"
#define UDP_PORT 4242
//#include "Remote.h"
extern WiFiUDP udp;
extern bool wifi_initialized;
#if defined(HAS_RNS) && defined(UDP_TRANSPORT)
// CBA UDP interface
class UDPInterface : public RNS::InterfaceImpl {
public:
UDPInterface(const char *name) : RNS::InterfaceImpl(name) {
_IN = true;
_OUT = true;
_HW_MTU = 1064;
}
UDPInterface() : UDPInterface("UDPInterface") {}
virtual ~UDPInterface() {
_name = "deleted";
}
protected:
virtual void handle_incoming(const RNS::Bytes& data) {
TRACEF("UDPInterface.handle_incoming: (%u bytes) data: %s", data.size(), data.toHex().c_str());
TRACE("UDPInterface.handle_incoming: sending packet to rns...");
try {
InterfaceImpl::handle_incoming(data);
}
catch (const std::bad_alloc&) {
ERROR("UDPInterface::handle_incoming: bad_alloc - out of memory");
}
catch (std::exception& e) {
ERRORF("UDPInterface::handle_incoming: %s", e.what());
}
}
virtual void send_outgoing(const RNS::Bytes& data) {
try {
//if (udp.availableForWrite()) {
//wl_status_t wifi_status = WiFi.status();
//if (wifi_status == WL_CONNECTED) {
if (wifi_initialized) {
TRACEF("UDPInterface.send_outgoing: (%u bytes) data: %s", data.size(), data.toHex().c_str());
if (udp.beginPacket(UDP_REMOTE_HOST, UDP_PORT) != 0) {
udp.write(data.data(), data.size());
udp.endPacket();
}
}
// Perform post-send housekeeping
InterfaceImpl::handle_outgoing(data);
}
catch (const std::bad_alloc&) {
ERROR("UDPInterface::send_outgoing: bad_alloc - out of memory");
}
catch (std::exception& e) {
ERRORF("UDPInterface::send_outgoing: %s", e.what());
}
}
};
#endif