-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLDudp.cpp
98 lines (70 loc) · 2.46 KB
/
LDudp.cpp
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
LDudp.h - library for sending simple udp log - implementation
started from Test.cpp example
Copyright (c) 2019 Trip-g.com LLC. All right reserved.
*/
// include nothing
// include this library's description file
#include "LDudp.h"
// include description files for other libraries used (if any)
WiFiUDP tg_udp;
// Constructor /////////////////////////////////////////////////////////////////
// Function that handles the creation and setup of instances
LDudp::LDudp(IPAddress lip,IPAddress mlip, int lp, int mlp,IPAddress sip)
{
// initialize this instance's variables
_logip = lip;
_multicastadd = mlip;
_logport = lp;
_multicastport = mlp;
_selfip = sip;
// do whatever is required to initialize the library
}
// Public Methods //////////////////////////////////////////////////////////////
// Functions available in Wiring sketches, this library, and other libraries
uint8_t LDudp::logD_UDP(char data[], const char c_from[], char f_msg[])
//uint8_t LDudp::logD_UDP(uint8_t b)
{
// eventhough this function is public, it can access
// and modify this library's private variables
if (!tg_udp.beginPacket(_logip, _logport)){
//Log.warning("FAILED! UDP beginpacket Called From:%S f_msg:%S" CR , c_from, f_msg);
return 0;
}
tg_udp.print(data);
_ldu_status = tg_udp.endPacket();
if (!_ldu_status) {
//Log.warning("FAILED! UDP endPacket Called From:%S f_msg:%S" CR , c_from, f_msg);
} else {
//Log.notice("SUCCESS! UDP endPacket Called From:%S f_msg:%S" CR , c_from, f_msg);
}
return _ldu_status;
}
// it can also call private functions of this library
uint8_t LDudp::logM_UDP(char data[], const char c_from[], char f_msg[])
{
// eventhough this function is public, it can access
// and modify this library's private variables
tg_udp.beginPacketMulticast(_multicastadd, _multicastport, _selfip);
return tg_udp.endPacket();
// it can also call private functions of this library
}
size_t LDudp::write( uint8_t b )
{
if (!_collecting) {
tg_udp.beginPacket(_logip, _logport);
_collecting = 1;
}
//tg_udp.write(reinterpret_cast<const char*>(b));
//tg_udp.write(b, sizeof(buffer));
//buffer[ count++ ] = b;
if (b == '\n') {
tg_udp.endPacket();
_collecting = 0;
} else {
tg_udp.write(b);
}
return 1;
}
// Private Methods /////////////////////////////////////////////////////////////
// Functions only available to other functions in this library