@@ -24,43 +24,48 @@ void printHex(Print& p, const uint8_t* buf, size_t len, const __FlashStringHelpe
2424
2525void printErrorCb (uint8_t code, uintptr_t data) {
2626 Print *p = (Print*)data;
27- p->print (F (" Error reading API packet. Error code: " ));
28- p->println (code);
27+ if (!p) return ;
28+ p->print (F (" Error reading API packet. Error code: 0x" ));
29+ p->println (code, HEX);
2930}
3031
3132void printErrorCb (ZBTxStatusResponse& r, uintptr_t data) {
3233 Print *p = (Print*)data;
34+ if (!p) return ;
3335 if (!r.isSuccess ()) {
34- p->print (F (" Error sending Zigbee packet. Delivery status: " ));
35- p->println (r.getDeliveryStatus ());
36+ p->print (F (" Error sending Zigbee packet. Delivery status: 0x " ));
37+ p->println (r.getDeliveryStatus (), HEX );
3638 }
3739}
3840
3941void printErrorCb (TxStatusResponse& r, uintptr_t data) {
4042 Print *p = (Print*)data;
43+ if (!p) return ;
4144 if (!r.isSuccess ()) {
42- p->print (F (" Error sending packet. Delivery status: " ));
43- p->println (r.getStatus ());
45+ p->print (F (" Error sending packet. Delivery status: 0x " ));
46+ p->println (r.getStatus (), HEX );
4447 }
4548}
4649
4750void printErrorCb (AtCommandResponse& r, uintptr_t data) {
4851 Print *p = (Print*)data;
52+ if (!p) return ;
4953 if (!r.isOk ()) {
5054 p->print (F (" Error sending " ));
5155 p->write (r.getCommand (), 2 );
52- p->print (F (" command. Status: " ));
53- p->println (r.getStatus ());
56+ p->print (F (" command. Status: 0x " ));
57+ p->println (r.getStatus (), HEX );
5458 }
5559}
5660
5761void printErrorCb (RemoteAtCommandResponse& r, uintptr_t data) {
5862 Print *p = (Print*)data;
63+ if (!p) return ;
5964 if (!r.isOk ()) {
6065 p->print (F (" Error sending remote " ));
6166 p->write (r.getCommand (), 2 );
62- p->print (F (" command. Status: " ));
63- p->println (r.getStatus ());
67+ p->print (F (" command. Status: 0x " ));
68+ p->println (r.getStatus (), HEX );
6469 }
6570}
6671
@@ -90,7 +95,8 @@ void printErrorCb(XBeeResponse& r, uintptr_t data) {
9095
9196void printRawResponseCb (XBeeResponse& response, uintptr_t data) {
9297 Print *p = (Print*)data;
93- p->print (" Response received: " );
98+ if (!p) return ;
99+ p->print (" Response: " );
94100 // Reconstruct the original packet
95101 uint8_t header[] = {START_BYTE, response.getMsbLength (), response.getLsbLength (), response.getApiId ()};
96102 printHex (*p, header, sizeof (header), F (" " ), NULL );
@@ -114,7 +120,8 @@ static void printField(Print* p, const __FlashStringHelper *prefix, T data) {
114120
115121void printResponseCb (ZBTxStatusResponse& status, uintptr_t data) {
116122 Print *p = (Print*)data;
117- p->println (F (" ZBTxStatusResponse received:" ));
123+ if (!p) return ;
124+ p->println (F (" ZBTxStatusResponse:" ));
118125 printField (p, F (" FrameId: 0x" ), status.getFrameId ());
119126 printField (p, F (" To: 0x" ), status.getRemoteAddress ());
120127 printField (p, F (" Delivery status: 0x" ), status.getDeliveryStatus ());
@@ -123,7 +130,8 @@ void printResponseCb(ZBTxStatusResponse& status, uintptr_t data) {
123130
124131void printResponseCb (ZBRxResponse& rx, uintptr_t data) {
125132 Print *p = (Print*)data;
126- p->println (F (" ZBRxResponse received:" ));
133+ if (!p) return ;
134+ p->println (F (" ZBRxResponse:" ));
127135 printField (p, F (" From: 0x" ), rx.getRemoteAddress64 ());
128136 printField (p, F (" From: 0x" ), rx.getRemoteAddress16 ());
129137 printField (p, F (" Receive options: 0x" ), rx.getOption ());
@@ -137,7 +145,8 @@ void printResponseCb(ZBRxResponse& rx, uintptr_t data) {
137145
138146void printResponseCb (ZBExplicitRxResponse& rx, uintptr_t data) {
139147 Print *p = (Print*)data;
140- p->println (F (" ZBExplicitRxResponse received:" ));
148+ if (!p) return ;
149+ p->println (F (" ZBExplicitRxResponse:" ));
141150 printField (p, F (" From: 0x" ), rx.getRemoteAddress64 ());
142151 printField (p, F (" From: 0x" ), rx.getRemoteAddress16 ());
143152 printField (p, F (" Receive options: 0x" ), rx.getOption ());
@@ -155,7 +164,8 @@ void printResponseCb(ZBExplicitRxResponse& rx, uintptr_t data) {
155164
156165void printResponseCb (ZBRxIoSampleResponse& rx, uintptr_t data) {
157166 Print *p = (Print*)data;
158- p->println (F (" ZBRxIoSampleResponse received:" ));
167+ if (!p) return ;
168+ p->println (F (" ZBRxIoSampleResponse:" ));
159169 printField (p, F (" From: 0x" ), rx.getRemoteAddress64 ());
160170 printField (p, F (" From: 0x" ), rx.getRemoteAddress16 ());
161171 printField (p, F (" Receive options: 0x" ), rx.getOption ());
@@ -181,14 +191,16 @@ void printResponseCb(ZBRxIoSampleResponse& rx, uintptr_t data) {
181191
182192void printResponseCb (TxStatusResponse& status, uintptr_t data) {
183193 Print *p = (Print*)data;
184- p->println (F (" TxStatusResponse received:" ));
194+ if (!p) return ;
195+ p->println (F (" TxStatusResponse:" ));
185196 printField (p, F (" FrameId: 0x" ), status.getFrameId ());
186197 printField (p, F (" Status: 0x" ), status.getStatus ());
187198}
188199
189200void printResponseCb (Rx16Response& rx, uintptr_t data) {
190201 Print *p = (Print*)data;
191- p->println (" Rx16Response received:" );
202+ if (!p) return ;
203+ p->println (" Rx16Response:" );
192204 printField (p, F (" From: 0x" ), rx.getRemoteAddress16 ());
193205 printField (p, F (" Rssi: 0x" ), rx.getRssi ());
194206 printField (p, F (" Receive options: 0x" ), rx.getOption ());
@@ -202,7 +214,8 @@ void printResponseCb(Rx16Response& rx, uintptr_t data) {
202214
203215void printResponseCb (Rx64Response& rx, uintptr_t data) {
204216 Print *p = (Print*)data;
205- p->println (" Rx64Response received:" );
217+ if (!p) return ;
218+ p->println (" Rx64Response:" );
206219 printField (p, F (" From: 0x" ), rx.getRemoteAddress64 ());
207220 printField (p, F (" Rssi: 0x" ), rx.getRssi ());
208221 printField (p, F (" Receive options: 0x" ), rx.getOption ());
@@ -247,7 +260,8 @@ static void printSamples(Print* p, RxIoSampleBaseResponse& rx) {
247260
248261void printResponseCb (Rx16IoSampleResponse& rx, uintptr_t data) {
249262 Print *p = (Print*)data;
250- p->println (" Rx16IoSampleResponse received:" );
263+ if (!p) return ;
264+ p->println (" Rx16IoSampleResponse:" );
251265 printField (p, F (" From: 0x" ), rx.getRemoteAddress16 ());
252266 printField (p, F (" Rssi: 0x" ), rx.getRssi ());
253267 printField (p, F (" Receive options: 0x" ), rx.getOption ());
@@ -257,7 +271,8 @@ void printResponseCb(Rx16IoSampleResponse& rx, uintptr_t data) {
257271
258272void printResponseCb (Rx64IoSampleResponse& rx, uintptr_t data) {
259273 Print *p = (Print*)data;
260- p->println (" Rx64IoSampleResponse received:" );
274+ if (!p) return ;
275+ p->println (" Rx64IoSampleResponse:" );
261276 printField (p, F (" From: 0x" ), rx.getRemoteAddress64 ());
262277 printField (p, F (" Rssi: 0x" ), rx.getRssi ());
263278 printField (p, F (" Receive options: 0x" ), rx.getOption ());
@@ -267,13 +282,15 @@ void printResponseCb(Rx64IoSampleResponse& rx, uintptr_t data) {
267282
268283void printResponseCb (ModemStatusResponse& status, uintptr_t data) {
269284 Print *p = (Print*)data;
270- p->println (" ModemStatusResponse received:" );
285+ if (!p) return ;
286+ p->println (" ModemStatusResponse:" );
271287 printField (p, F (" Status: 0x" ), status.getStatus ());
272288}
273289
274290void printResponseCb (AtCommandResponse& at, uintptr_t data) {
275291 Print *p = (Print*)data;
276- p->println (" AtCommandResponse received:" );
292+ if (!p) return ;
293+ p->println (" AtCommandResponse:" );
277294 p->print (F (" Command: " ));
278295 p->write (at.getCommand (), 2 );
279296 p->println ();
@@ -287,7 +304,8 @@ void printResponseCb(AtCommandResponse& at, uintptr_t data) {
287304
288305void printResponseCb (RemoteAtCommandResponse& at, uintptr_t data) {
289306 Print *p = (Print*)data;
290- p->println (" AtRemoteCommandResponse received:" );
307+ if (!p) return ;
308+ p->println (" AtRemoteCommandResponse:" );
291309 printField (p, F (" To: 0x" ), at.getRemoteAddress64 ());
292310 printField (p, F (" To: 0x" ), at.getRemoteAddress16 ());
293311 p->print (F (" Command: " ));
@@ -303,7 +321,7 @@ void printResponseCb(RemoteAtCommandResponse& at, uintptr_t data) {
303321
304322void printResponseCb (XBeeResponse& r, uintptr_t data) {
305323 uint8_t id = r.getApiId ();
306- // Figure out the API type and call the corresonding function
324+ // Figure out the API type and call the corresponding function
307325 if (id == ZB_TX_STATUS_RESPONSE) {
308326 ZBTxStatusResponse response;
309327 r.getZBTxStatusResponse (response);
0 commit comments