-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmonitor.ino
More file actions
140 lines (121 loc) · 3.4 KB
/
monitor.ino
File metadata and controls
140 lines (121 loc) · 3.4 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/* This module handles the debug messages sent to the main Serial port
* so events can be monitored or debugged via the connected PC
* adjut the boolean flags below to enable or disable outputs
*/
boolean debug_packet_raw = false;
boolean debug_packet_decode = false;
boolean debug_item_state = true;
boolean debug_wifi_cmd = true;
boolean debug_wifi_rest = true;
boolean debug_wifi_reply = false;
boolean debug_xbee = true;
// Print the raw XBee packet data in hex codes
void DebugPrintPacketRaw(unsigned char* buf, int buflen, boolean force)
{
if (!debug_packet_raw && !force) return;
Serial.println("Received Packet Data");
for (int i = 0; i < buflen; i++)
{
char s[16];
sprintf(s, "%02x ", buf[i]);
Serial.print(s);
}
Serial.println();
}
void DebugPrintPacketRaw(unsigned char* buf, int buflen)
{
DebugPrintPacketRaw(buf, buflen, false);
}
// print the decoded XBee IO packet information, allow flag override on errors
void DebugPrintPacketDecode(struct XBeePacket &xbeedata, boolean force)
{
if (!debug_packet_decode && !force) return;
// Debug echo parsed data
Serial.println("XBee Packet Contents");
Serial.print("API "); Serial.println(xbeedata.api, HEX);
Serial.print("DeviceID ");
for (int i = 0; i < 8; i++) {char s[8]; sprintf(s, "%02x ", xbeedata.xid[i]); Serial.print(s);}
Serial.println();
Serial.print("My ID "); Serial.print(xbeedata.mid >> 8, HEX); Serial.println(xbeedata.mid & 0xff, HEX);
Serial.print("Pack Type "); Serial.println(xbeedata.ptype, HEX);
for (int i = 0; i < 13; i++)
{
if (xbeedata.dioValid[i])
{
char s[20];
sprintf(s, "DIO %2d %d", i, xbeedata.dio[i]);
Serial.println(s);
}
}
for (int i = 0; i < 4; i++)
{
if (xbeedata.analogValid[i])
{
char s[20];
sprintf(s, "Analog %2d %d", i, xbeedata.analog[i]);
Serial.println(s);
}
}
Serial.println();
}
// monitor an XBee packet decode only if enabled by flags
void DebugPrintPacketDecode(struct XBeePacket &xbeedata)
{
DebugPrintPacketDecode(xbeedata, false);
}
// monitor the decoded sensor event boolean
void DebugPrintItemStateBool(const char *name, boolean state, boolean changed)
{
if (!debug_item_state) return;
char s[64];
sprintf(s, "%-20s %3d %s", name, state ? 1 : 0, changed ? "CHANGED" : "");
Serial.println(s);
}
// monitor the decoded sensor event integer
void DebugPrintItemStateInt(const char *name, int state, boolean changed)
{
if (!debug_item_state) return;
char s[64];
sprintf(s, "%-20s %3d %s", name, state, changed ? "CHANGED" : 0);
Serial.println(s);
}
// monitor the wifi command strings
void DebugWifiCmd(const String &s)
{
if (!debug_wifi_cmd) return;
Serial.print("WIFI CMD: ");
Serial.println(s);
}
// monitor the outgoing Rest requests
void DebugWifiRest(const String &s)
{
if (!debug_wifi_rest) return;
Serial.print("WIFI REST: ");
Serial.println(s);
Serial.println();
}
// monitor a WiFi reply
void DebugWifiReply(const String &s)
{
if (!debug_wifi_reply) return;
Serial.print("WIFI REPLY: ");
Serial.println(s);
}
// log a Wifi error
void DebugWifiError(const String &s)
{
Serial.print("WIFI ERROR: ");
Serial.println(s);
}
// print a string to the monitor
void DebugPrintXBee(String &s)
{
if (!debug_xbee) return;
Serial.println(s);
}
// configure the serial port at startup
boolean setupMonitor()
{
Serial.begin(57600); // PC
return true;
}