Skip to content

Commit 1bfd365

Browse files
committed
Merge pull request #12 from matthijskooijman/fixes-and-bump
A few more fixes and bump version to 0.6.0
2 parents ce5f8cf + d773527 commit 1bfd365

File tree

6 files changed

+88
-38
lines changed

6 files changed

+88
-38
lines changed

Printers.cpp

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,43 +24,48 @@ void printHex(Print& p, const uint8_t* buf, size_t len, const __FlashStringHelpe
2424

2525
void 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

3132
void 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

3941
void 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

4750
void 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

5761
void 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

9196
void 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

115121
void 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

124131
void 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

138146
void 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

156165
void 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

182192
void 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

189200
void 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

203215
void 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

248261
void 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

258272
void 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

268283
void 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

274290
void 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

288305
void 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

304322
void 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);

Printers.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,33 @@ void printResponseCb(AtCommandResponse& at, uintptr_t data);
124124
void printResponseCb(RemoteAtCommandResponse& at, uintptr_t data);
125125
void printResponseCb(XBeeResponse& r, uintptr_t data);
126126

127+
// The following functions are non-callback version of the above,
128+
// intended to be called with Print instance (such as Serial) directly,
129+
// saving the casts.
130+
131+
// Print any error in these status response (prints nothing when the
132+
// status is ok).
133+
inline void printError(ZBTxStatusResponse& r, Print& print) { printErrorCb(r, (uintptr_t)(Print*)&print); }
134+
inline void printError(TxStatusResponse& r, Print& print) { printErrorCb(r, (uintptr_t)(Print*)&print); }
135+
inline void printError(AtCommandResponse& r, Print& print) { printErrorCb(r, (uintptr_t)(Print*)&print); }
136+
inline void printError(RemoteAtCommandResponse& r, Print& print) { printErrorCb(r, (uintptr_t)(Print*)&print); }
137+
inline void printError(XBeeResponse& r, Print& print) { printErrorCb(r, (uintptr_t)(Print*)&print); }
138+
139+
// Print the raw bytes of a response
140+
inline void printRawResponse(XBeeResponse& r, Print& print) { printRawResponseCb(r, (uintptr_t)(Print*)&print); }
141+
142+
// Print a human-readable version of a response
143+
inline void printResponse(ZBTxStatusResponse& r, Print& print) { printResponseCb(r, (uintptr_t)(Print*)&print); }
144+
inline void printResponse(ZBRxResponse& r, Print& print) { printResponseCb(r, (uintptr_t)(Print*)&print); }
145+
inline void printResponse(ZBExplicitRxResponse& r, Print& print) { printResponseCb(r, (uintptr_t)(Print*)&print); }
146+
inline void printResponse(ZBRxIoSampleResponse& r, Print& print) { printResponseCb(r, (uintptr_t)(Print*)&print); }
147+
inline void printResponse(TxStatusResponse& r, Print& print) { printResponseCb(r, (uintptr_t)(Print*)&print); }
148+
inline void printResponse(Rx16Response& r, Print& print) { printResponseCb(r, (uintptr_t)(Print*)&print); }
149+
inline void printResponse(Rx64Response& r, Print& print) { printResponseCb(r, (uintptr_t)(Print*)&print); }
150+
inline void printResponse(Rx16IoSampleResponse& r, Print& print) { printResponseCb(r, (uintptr_t)(Print*)&print); }
151+
inline void printResponse(Rx64IoSampleResponse& r, Print& print) { printResponseCb(r, (uintptr_t)(Print*)&print); }
152+
inline void printResponse(ModemStatusResponse& r, Print& print) { printResponseCb(r, (uintptr_t)(Print*)&print); }
153+
inline void printResponse(AtCommandResponse& r, Print& print) { printResponseCb(r, (uintptr_t)(Print*)&print); }
154+
inline void printResponse(RemoteAtCommandResponse& r, Print& print) { printResponseCb(r, (uintptr_t)(Print*)&print); }
155+
inline void printResponse(XBeeResponse& r, Print& print) { printResponseCb(r, (uintptr_t)(Print*)&print); }
127156
#endif // XBee_Printers_h

XBee.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,17 +1054,19 @@ void PayloadRequest::setPayloadLength(uint8_t payloadLength) {
10541054
#ifdef SERIES_2
10551055

10561056
ZBTxRequest::ZBTxRequest() : PayloadRequest(ZB_TX_REQUEST, DEFAULT_FRAME_ID, NULL, 0) {
1057-
1057+
_addr16 = ZB_BROADCAST_ADDRESS;
1058+
_broadcastRadius = ZB_BROADCAST_RADIUS_MAX_HOPS;
1059+
_option = ZB_TX_UNICAST;
10581060
}
10591061

1060-
ZBTxRequest::ZBTxRequest(XBeeAddress64 &addr64, uint16_t addr16, uint8_t broadcastRadius, uint8_t option, uint8_t *data, uint8_t dataLength, uint8_t frameId): PayloadRequest(ZB_TX_REQUEST, frameId, data, dataLength) {
1062+
ZBTxRequest::ZBTxRequest(const XBeeAddress64 &addr64, uint16_t addr16, uint8_t broadcastRadius, uint8_t option, uint8_t *data, uint8_t dataLength, uint8_t frameId): PayloadRequest(ZB_TX_REQUEST, frameId, data, dataLength) {
10611063
_addr64 = addr64;
10621064
_addr16 = addr16;
10631065
_broadcastRadius = broadcastRadius;
10641066
_option = option;
10651067
}
10661068

1067-
ZBTxRequest::ZBTxRequest(XBeeAddress64 &addr64, uint8_t *data, uint8_t dataLength): PayloadRequest(ZB_TX_REQUEST, DEFAULT_FRAME_ID, data, dataLength) {
1069+
ZBTxRequest::ZBTxRequest(const XBeeAddress64 &addr64, uint8_t *data, uint8_t dataLength): PayloadRequest(ZB_TX_REQUEST, DEFAULT_FRAME_ID, data, dataLength) {
10681070
_addr64 = addr64;
10691071
_addr16 = ZB_BROADCAST_ADDRESS;
10701072
_broadcastRadius = ZB_BROADCAST_RADIUS_MAX_HOPS;
@@ -1121,7 +1123,7 @@ uint8_t ZBTxRequest::getOption() {
11211123
return _option;
11221124
}
11231125

1124-
void ZBTxRequest::setAddress64(XBeeAddress64& addr64) {
1126+
void ZBTxRequest::setAddress64(const XBeeAddress64& addr64) {
11251127
_addr64 = addr64;
11261128
}
11271129

@@ -1229,7 +1231,7 @@ void ZBExplicitTxRequest::setProfileId(uint16_t profileId) {
12291231
#ifdef SERIES_1
12301232

12311233
Tx16Request::Tx16Request() : PayloadRequest(TX_16_REQUEST, DEFAULT_FRAME_ID, NULL, 0) {
1232-
1234+
_option = ACK_OPTION;
12331235
}
12341236

12351237
Tx16Request::Tx16Request(uint16_t addr16, uint8_t option, uint8_t *data, uint8_t dataLength, uint8_t frameId) : PayloadRequest(TX_16_REQUEST, frameId, data, dataLength) {
@@ -1276,7 +1278,7 @@ void Tx16Request::setOption(uint8_t option) {
12761278
}
12771279

12781280
Tx64Request::Tx64Request() : PayloadRequest(TX_64_REQUEST, DEFAULT_FRAME_ID, NULL, 0) {
1279-
1281+
_option = ACK_OPTION;
12801282
}
12811283

12821284
Tx64Request::Tx64Request(XBeeAddress64 &addr64, uint8_t option, uint8_t *data, uint8_t dataLength, uint8_t frameId) : PayloadRequest(TX_64_REQUEST, frameId, data, dataLength) {

XBee.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,18 +1188,19 @@ class ZBTxRequest : public PayloadRequest {
11881188
/**
11891189
* Creates a unicast ZBTxRequest with the ACK option and DEFAULT_FRAME_ID
11901190
*/
1191-
ZBTxRequest(XBeeAddress64 &addr64, uint8_t *payload, uint8_t payloadLength);
1192-
ZBTxRequest(XBeeAddress64 &addr64, uint16_t addr16, uint8_t broadcastRadius, uint8_t option, uint8_t *payload, uint8_t payloadLength, uint8_t frameId);
1191+
ZBTxRequest(const XBeeAddress64 &addr64, uint8_t *payload, uint8_t payloadLength);
1192+
ZBTxRequest(const XBeeAddress64 &addr64, uint16_t addr16, uint8_t broadcastRadius, uint8_t option, uint8_t *payload, uint8_t payloadLength, uint8_t frameId);
11931193
/**
11941194
* Creates a default instance of this class. At a minimum you must specify
1195-
* a payload, payload length and a destination address before sending this request.
1195+
* a payload, payload length and a 64-bit destination address before sending
1196+
* this request.
11961197
*/
11971198
ZBTxRequest();
11981199
XBeeAddress64& getAddress64();
11991200
uint16_t getAddress16();
12001201
uint8_t getBroadcastRadius();
12011202
uint8_t getOption();
1202-
void setAddress64(XBeeAddress64& addr64);
1203+
void setAddress64(const XBeeAddress64& addr64);
12031204
void setAddress16(uint16_t addr16);
12041205
void setBroadcastRadius(uint8_t broadcastRadius);
12051206
void setOption(uint8_t option);

build.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<project default="dist" name="XBee-Arduino">
33
<property file="build.properties"/>
44
<property name="dist.dir" value="dist"/>
5-
<property name="release" value="0.5"/>
5+
<property name="release" value="0.6.0"/>
66

77
<target name="init">
88
<mkdir dir="${dist.dir}/XBee"/>

library.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name=XBee-Arduino library
2-
version=0.5.0
3-
author=Andrew Wrapp
4-
maintainer=Andrew Wrapp <andrew.wrapp@gmail.com>
2+
version=0.6.0
3+
author=Andrew Rapp
4+
maintainer=Andrew Rapp <andrew.rapp@gmail.com>
55
sentence=Library for talking to to various wireless XBee modules from Digi.
66
paragraph=This supports various devices, configured to use the more advanced "API" mode.
77
category=Communication

0 commit comments

Comments
 (0)