-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdebug.cpp
57 lines (44 loc) · 878 Bytes
/
debug.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
#include "debug.h"
#define DEBUG_NETWORK 0
#define DEBUG_SERIAL 1
void dbg_init()
{
#if DEBUG_SERIAL
SerialUSB.begin(115200);
#endif
}
void dbg_println(const __FlashStringHelper *n)
{
uint8_t c;
byte *payload;
#if DEBUG_SERIAL
SerialUSB.println(n);
#endif
#if DEBUG_NETWORK
char *pn = (char*)n;
struct net_msg_t msg;
memset(&msg, 0, sizeof(msg));
payload = msg.payload;
memcpy(msg.msgtype,"INFO", 4);
while ((c = pgm_read_byte_near(pn++)) != 0)
*(payload++) = c;
net_transport_send(&msg);
#endif
}
void dbg_println(const char* str)
{
//todo.
dbg_print(str);
}
void dbg_print(const char* str)
{
#if DEBUG_SERIAL
SerialUSB.println(str);
#endif
#if DEBUG_NETWORK
struct net_msg_t msg;
memcpy(msg.msgtype,"INFO", 4);
strncpy((char*)msg.payload, str, sizeof(msg.payload));
net_transport_send(&msg);
#endif
}