-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdebug.h
More file actions
116 lines (99 loc) · 2.64 KB
/
Copy pathdebug.h
File metadata and controls
116 lines (99 loc) · 2.64 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
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#ifndef DEBUG_H
#define DEBUG_H
#ifndef DEBUG
#define DEBUG 1 // enable (1) / disable (0) Serial prints
#endif
#if DEBUG
#include <Arduino.h>
#include <stdint.h>
#define PRINT_INIT() do { \
while (!Serial); \
Serial.begin(9600); \
Serial.println(F("Let's clean some air!")); \
} while (0)
#define PRINT_FLUSH() Serial.flush()
#define PRINT(ARG) Serial.print(ARG)
#define PRINT_HEX(ARG) Serial.print(ARG, HEX)
#define PRINTLN(ARG) Serial.println(ARG)
/* According to DR enums in lmic/lorabase_X.h */
#define PRINT_DATARATE(ARG) do { \
switch (ARG) { \
case 0: \
PRINT("DR_SF12"); \
break; \
case 1: \
PRINT("DR_SF11"); \
break; \
case 2: \
PRINT("DR_SF10"); \
break; \
case 3: \
PRINT("DR_SF9"); \
break; \
case 4: \
PRINT("DR_SF8"); \
break; \
case 5: \
PRINT("DR_SF7"); \
break; \
case 6: \
PRINT("DR_SF7B"); \
break; \
case 7: \
PRINT("DR_FSK"); \
break; \
case 8: \
PRINT("DR_NONE"); \
break; \
default: \
PRINT("INVALID DATARATE"); \
} \
} while (0)
#define PRINT_RECEIVED_MSG() do { \
PRINT(F(" Received downlink message with ")); \
PRINT(LMIC.dataLen); \
PRINTLN(F(" bytes of payload")); \
PRINT(F(" RSSI [dBm]: ")); \
PRINTLN(LMIC.rssi); \
PRINT(F(" SNR [dB]: ")); \
PRINTLN(LMIC.snr / 4); \
u1_t bPort = 0; \
if (LMIC.txrxFlags & TXRX_PORT) { \
bPort = LMIC.frame[LMIC.dataBeg - 1]; \
PRINT(F(" Received message on port ")); \
PRINTLN(bPort); \
} \
if (LMIC.txrxFlags & TXRX_ACK) { \
PRINTLN(F(" Received ack")); \
} \
} while (0)
#define PRINT_KEY(KEY) do { \
for (uint8_t i = 0; i < sizeof(KEY); i++) { \
if (i != 0) PRINT("-"); \
if (KEY[i] < 16) PRINT(0); \
PRINT_HEX(KEY[i]); \
} \
} while (0)
#define PRINT_ADDRESSES_AND_KEYS() do { \
u4_t netid = 0; \
devaddr_t devaddr = 0; \
u1_t nwkKey[16]; \
u1_t artKey[16]; \
LMIC_getSessionKeys(&netid, &devaddr, nwkKey, artKey); \
PRINT(F("netid: ")); PRINTLN(netid); \
PRINT(F("devaddr: ")); PRINT_HEX(devaddr); PRINTLN(""); \
PRINT(F("AppSKey: ")); PRINT_KEY(artKey); PRINTLN(""); \
PRINT(F("NwSKey: ")); PRINT_KEY(nwkKey); PRINTLN(""); \
PRINT_FLUSH(); \
} while (0)
#else // DEBUG
#define PRINT_INIT() do {} while (0)
#define PRINT_FLUSH() do {} while (0)
#define PRINT(ARG) do {} while (0)
#define PRINT_HEX(ARG) do {} while (0)
#define PRINTLN(ARG) do {} while (0)
#define PRINT_RECEIVED_MSG() do {} while (0)
#define PRINT_DATARATE(ARG) do {} while (0)
#define PRINT_ADDRESSES_AND_KEYS() do {} while (0)
#endif // DEBUG
#endif /* DEBUG_H */