Skip to content

Commit

Permalink
Merge pull request #12 from matthijskooijman/fixes-and-bump
Browse files Browse the repository at this point in the history
A few more fixes and bump version to 0.6.0
  • Loading branch information
andrewrapp committed Sep 16, 2015
2 parents ce5f8cf + d773527 commit 1bfd365
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 38 deletions.
66 changes: 42 additions & 24 deletions Printers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,43 +24,48 @@ void printHex(Print& p, const uint8_t* buf, size_t len, const __FlashStringHelpe

void printErrorCb(uint8_t code, uintptr_t data) {
Print *p = (Print*)data;
p->print(F("Error reading API packet. Error code: "));
p->println(code);
if (!p) return;
p->print(F("Error reading API packet. Error code: 0x"));
p->println(code, HEX);
}

void printErrorCb(ZBTxStatusResponse& r, uintptr_t data) {
Print *p = (Print*)data;
if (!p) return;
if (!r.isSuccess()) {
p->print(F("Error sending Zigbee packet. Delivery status: "));
p->println(r.getDeliveryStatus());
p->print(F("Error sending Zigbee packet. Delivery status: 0x"));
p->println(r.getDeliveryStatus(), HEX);
}
}

void printErrorCb(TxStatusResponse& r, uintptr_t data) {
Print *p = (Print*)data;
if (!p) return;
if (!r.isSuccess()) {
p->print(F("Error sending packet. Delivery status: "));
p->println(r.getStatus());
p->print(F("Error sending packet. Delivery status: 0x"));
p->println(r.getStatus(), HEX);
}
}

void printErrorCb(AtCommandResponse& r, uintptr_t data) {
Print *p = (Print*)data;
if (!p) return;
if (!r.isOk()) {
p->print(F("Error sending "));
p->write(r.getCommand(), 2);
p->print(F(" command. Status: "));
p->println(r.getStatus());
p->print(F(" command. Status: 0x"));
p->println(r.getStatus(), HEX);
}
}

void printErrorCb(RemoteAtCommandResponse& r, uintptr_t data) {
Print *p = (Print*)data;
if (!p) return;
if (!r.isOk()) {
p->print(F("Error sending remote "));
p->write(r.getCommand(), 2);
p->print(F(" command. Status: "));
p->println(r.getStatus());
p->print(F(" command. Status: 0x"));
p->println(r.getStatus(), HEX);
}
}

Expand Down Expand Up @@ -90,7 +95,8 @@ void printErrorCb(XBeeResponse& r, uintptr_t data) {

void printRawResponseCb(XBeeResponse& response, uintptr_t data) {
Print *p = (Print*)data;
p->print("Response received: ");
if (!p) return;
p->print("Response: ");
// Reconstruct the original packet
uint8_t header[] = {START_BYTE, response.getMsbLength(), response.getLsbLength(), response.getApiId()};
printHex(*p, header, sizeof(header), F(" "), NULL);
Expand All @@ -114,7 +120,8 @@ static void printField(Print* p, const __FlashStringHelper *prefix, T data) {

void printResponseCb(ZBTxStatusResponse& status, uintptr_t data) {
Print *p = (Print*)data;
p->println(F("ZBTxStatusResponse received:"));
if (!p) return;
p->println(F("ZBTxStatusResponse:"));
printField(p, F(" FrameId: 0x"), status.getFrameId());
printField(p, F(" To: 0x"), status.getRemoteAddress());
printField(p, F(" Delivery status: 0x"), status.getDeliveryStatus());
Expand All @@ -123,7 +130,8 @@ void printResponseCb(ZBTxStatusResponse& status, uintptr_t data) {

void printResponseCb(ZBRxResponse& rx, uintptr_t data) {
Print *p = (Print*)data;
p->println(F("ZBRxResponse received:"));
if (!p) return;
p->println(F("ZBRxResponse:"));
printField(p, F(" From: 0x"), rx.getRemoteAddress64());
printField(p, F(" From: 0x"), rx.getRemoteAddress16());
printField(p, F(" Receive options: 0x"), rx.getOption());
Expand All @@ -137,7 +145,8 @@ void printResponseCb(ZBRxResponse& rx, uintptr_t data) {

void printResponseCb(ZBExplicitRxResponse& rx, uintptr_t data) {
Print *p = (Print*)data;
p->println(F("ZBExplicitRxResponse received:"));
if (!p) return;
p->println(F("ZBExplicitRxResponse:"));
printField(p, F(" From: 0x"), rx.getRemoteAddress64());
printField(p, F(" From: 0x"), rx.getRemoteAddress16());
printField(p, F(" Receive options: 0x"), rx.getOption());
Expand All @@ -155,7 +164,8 @@ void printResponseCb(ZBExplicitRxResponse& rx, uintptr_t data) {

void printResponseCb(ZBRxIoSampleResponse& rx, uintptr_t data) {
Print *p = (Print*)data;
p->println(F("ZBRxIoSampleResponse received:"));
if (!p) return;
p->println(F("ZBRxIoSampleResponse:"));
printField(p, F(" From: 0x"), rx.getRemoteAddress64());
printField(p, F(" From: 0x"), rx.getRemoteAddress16());
printField(p, F(" Receive options: 0x"), rx.getOption());
Expand All @@ -181,14 +191,16 @@ void printResponseCb(ZBRxIoSampleResponse& rx, uintptr_t data) {

void printResponseCb(TxStatusResponse& status, uintptr_t data) {
Print *p = (Print*)data;
p->println(F("TxStatusResponse received:"));
if (!p) return;
p->println(F("TxStatusResponse:"));
printField(p, F(" FrameId: 0x"), status.getFrameId());
printField(p, F(" Status: 0x"), status.getStatus());
}

void printResponseCb(Rx16Response& rx, uintptr_t data) {
Print *p = (Print*)data;
p->println("Rx16Response received:");
if (!p) return;
p->println("Rx16Response:");
printField(p, F(" From: 0x"), rx.getRemoteAddress16());
printField(p, F(" Rssi: 0x"), rx.getRssi());
printField(p, F(" Receive options: 0x"), rx.getOption());
Expand All @@ -202,7 +214,8 @@ void printResponseCb(Rx16Response& rx, uintptr_t data) {

void printResponseCb(Rx64Response& rx, uintptr_t data) {
Print *p = (Print*)data;
p->println("Rx64Response received:");
if (!p) return;
p->println("Rx64Response:");
printField(p, F(" From: 0x"), rx.getRemoteAddress64());
printField(p, F(" Rssi: 0x"), rx.getRssi());
printField(p, F(" Receive options: 0x"), rx.getOption());
Expand Down Expand Up @@ -247,7 +260,8 @@ static void printSamples(Print* p, RxIoSampleBaseResponse& rx) {

void printResponseCb(Rx16IoSampleResponse& rx, uintptr_t data) {
Print *p = (Print*)data;
p->println("Rx16IoSampleResponse received:");
if (!p) return;
p->println("Rx16IoSampleResponse:");
printField(p, F(" From: 0x"), rx.getRemoteAddress16());
printField(p, F(" Rssi: 0x"), rx.getRssi());
printField(p, F(" Receive options: 0x"), rx.getOption());
Expand All @@ -257,7 +271,8 @@ void printResponseCb(Rx16IoSampleResponse& rx, uintptr_t data) {

void printResponseCb(Rx64IoSampleResponse& rx, uintptr_t data) {
Print *p = (Print*)data;
p->println("Rx64IoSampleResponse received:");
if (!p) return;
p->println("Rx64IoSampleResponse:");
printField(p, F(" From: 0x"), rx.getRemoteAddress64());
printField(p, F(" Rssi: 0x"), rx.getRssi());
printField(p, F(" Receive options: 0x"), rx.getOption());
Expand All @@ -267,13 +282,15 @@ void printResponseCb(Rx64IoSampleResponse& rx, uintptr_t data) {

void printResponseCb(ModemStatusResponse& status, uintptr_t data) {
Print *p = (Print*)data;
p->println("ModemStatusResponse received:");
if (!p) return;
p->println("ModemStatusResponse:");
printField(p, F(" Status: 0x"), status.getStatus());
}

void printResponseCb(AtCommandResponse& at, uintptr_t data) {
Print *p = (Print*)data;
p->println("AtCommandResponse received:");
if (!p) return;
p->println("AtCommandResponse:");
p->print(F(" Command: "));
p->write(at.getCommand(), 2);
p->println();
Expand All @@ -287,7 +304,8 @@ void printResponseCb(AtCommandResponse& at, uintptr_t data) {

void printResponseCb(RemoteAtCommandResponse& at, uintptr_t data) {
Print *p = (Print*)data;
p->println("AtRemoteCommandResponse received:");
if (!p) return;
p->println("AtRemoteCommandResponse:");
printField(p, F(" To: 0x"), at.getRemoteAddress64());
printField(p, F(" To: 0x"), at.getRemoteAddress16());
p->print(F(" Command: "));
Expand All @@ -303,7 +321,7 @@ void printResponseCb(RemoteAtCommandResponse& at, uintptr_t data) {

void printResponseCb(XBeeResponse& r, uintptr_t data) {
uint8_t id = r.getApiId();
// Figure out the API type and call the corresonding function
// Figure out the API type and call the corresponding function
if (id == ZB_TX_STATUS_RESPONSE) {
ZBTxStatusResponse response;
r.getZBTxStatusResponse(response);
Expand Down
29 changes: 29 additions & 0 deletions Printers.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,33 @@ void printResponseCb(AtCommandResponse& at, uintptr_t data);
void printResponseCb(RemoteAtCommandResponse& at, uintptr_t data);
void printResponseCb(XBeeResponse& r, uintptr_t data);

// The following functions are non-callback version of the above,
// intended to be called with Print instance (such as Serial) directly,
// saving the casts.

// Print any error in these status response (prints nothing when the
// status is ok).
inline void printError(ZBTxStatusResponse& r, Print& print) { printErrorCb(r, (uintptr_t)(Print*)&print); }
inline void printError(TxStatusResponse& r, Print& print) { printErrorCb(r, (uintptr_t)(Print*)&print); }
inline void printError(AtCommandResponse& r, Print& print) { printErrorCb(r, (uintptr_t)(Print*)&print); }
inline void printError(RemoteAtCommandResponse& r, Print& print) { printErrorCb(r, (uintptr_t)(Print*)&print); }
inline void printError(XBeeResponse& r, Print& print) { printErrorCb(r, (uintptr_t)(Print*)&print); }

// Print the raw bytes of a response
inline void printRawResponse(XBeeResponse& r, Print& print) { printRawResponseCb(r, (uintptr_t)(Print*)&print); }

// Print a human-readable version of a response
inline void printResponse(ZBTxStatusResponse& r, Print& print) { printResponseCb(r, (uintptr_t)(Print*)&print); }
inline void printResponse(ZBRxResponse& r, Print& print) { printResponseCb(r, (uintptr_t)(Print*)&print); }
inline void printResponse(ZBExplicitRxResponse& r, Print& print) { printResponseCb(r, (uintptr_t)(Print*)&print); }
inline void printResponse(ZBRxIoSampleResponse& r, Print& print) { printResponseCb(r, (uintptr_t)(Print*)&print); }
inline void printResponse(TxStatusResponse& r, Print& print) { printResponseCb(r, (uintptr_t)(Print*)&print); }
inline void printResponse(Rx16Response& r, Print& print) { printResponseCb(r, (uintptr_t)(Print*)&print); }
inline void printResponse(Rx64Response& r, Print& print) { printResponseCb(r, (uintptr_t)(Print*)&print); }
inline void printResponse(Rx16IoSampleResponse& r, Print& print) { printResponseCb(r, (uintptr_t)(Print*)&print); }
inline void printResponse(Rx64IoSampleResponse& r, Print& print) { printResponseCb(r, (uintptr_t)(Print*)&print); }
inline void printResponse(ModemStatusResponse& r, Print& print) { printResponseCb(r, (uintptr_t)(Print*)&print); }
inline void printResponse(AtCommandResponse& r, Print& print) { printResponseCb(r, (uintptr_t)(Print*)&print); }
inline void printResponse(RemoteAtCommandResponse& r, Print& print) { printResponseCb(r, (uintptr_t)(Print*)&print); }
inline void printResponse(XBeeResponse& r, Print& print) { printResponseCb(r, (uintptr_t)(Print*)&print); }
#endif // XBee_Printers_h
14 changes: 8 additions & 6 deletions XBee.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1054,17 +1054,19 @@ void PayloadRequest::setPayloadLength(uint8_t payloadLength) {
#ifdef SERIES_2

ZBTxRequest::ZBTxRequest() : PayloadRequest(ZB_TX_REQUEST, DEFAULT_FRAME_ID, NULL, 0) {

_addr16 = ZB_BROADCAST_ADDRESS;
_broadcastRadius = ZB_BROADCAST_RADIUS_MAX_HOPS;
_option = ZB_TX_UNICAST;
}

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) {
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) {
_addr64 = addr64;
_addr16 = addr16;
_broadcastRadius = broadcastRadius;
_option = option;
}

ZBTxRequest::ZBTxRequest(XBeeAddress64 &addr64, uint8_t *data, uint8_t dataLength): PayloadRequest(ZB_TX_REQUEST, DEFAULT_FRAME_ID, data, dataLength) {
ZBTxRequest::ZBTxRequest(const XBeeAddress64 &addr64, uint8_t *data, uint8_t dataLength): PayloadRequest(ZB_TX_REQUEST, DEFAULT_FRAME_ID, data, dataLength) {
_addr64 = addr64;
_addr16 = ZB_BROADCAST_ADDRESS;
_broadcastRadius = ZB_BROADCAST_RADIUS_MAX_HOPS;
Expand Down Expand Up @@ -1121,7 +1123,7 @@ uint8_t ZBTxRequest::getOption() {
return _option;
}

void ZBTxRequest::setAddress64(XBeeAddress64& addr64) {
void ZBTxRequest::setAddress64(const XBeeAddress64& addr64) {
_addr64 = addr64;
}

Expand Down Expand Up @@ -1229,7 +1231,7 @@ void ZBExplicitTxRequest::setProfileId(uint16_t profileId) {
#ifdef SERIES_1

Tx16Request::Tx16Request() : PayloadRequest(TX_16_REQUEST, DEFAULT_FRAME_ID, NULL, 0) {

_option = ACK_OPTION;
}

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

Tx64Request::Tx64Request() : PayloadRequest(TX_64_REQUEST, DEFAULT_FRAME_ID, NULL, 0) {

_option = ACK_OPTION;
}

Tx64Request::Tx64Request(XBeeAddress64 &addr64, uint8_t option, uint8_t *data, uint8_t dataLength, uint8_t frameId) : PayloadRequest(TX_64_REQUEST, frameId, data, dataLength) {
Expand Down
9 changes: 5 additions & 4 deletions XBee.h
Original file line number Diff line number Diff line change
Expand Up @@ -1188,18 +1188,19 @@ class ZBTxRequest : public PayloadRequest {
/**
* Creates a unicast ZBTxRequest with the ACK option and DEFAULT_FRAME_ID
*/
ZBTxRequest(XBeeAddress64 &addr64, uint8_t *payload, uint8_t payloadLength);
ZBTxRequest(XBeeAddress64 &addr64, uint16_t addr16, uint8_t broadcastRadius, uint8_t option, uint8_t *payload, uint8_t payloadLength, uint8_t frameId);
ZBTxRequest(const XBeeAddress64 &addr64, uint8_t *payload, uint8_t payloadLength);
ZBTxRequest(const XBeeAddress64 &addr64, uint16_t addr16, uint8_t broadcastRadius, uint8_t option, uint8_t *payload, uint8_t payloadLength, uint8_t frameId);
/**
* Creates a default instance of this class. At a minimum you must specify
* a payload, payload length and a destination address before sending this request.
* a payload, payload length and a 64-bit destination address before sending
* this request.
*/
ZBTxRequest();
XBeeAddress64& getAddress64();
uint16_t getAddress16();
uint8_t getBroadcastRadius();
uint8_t getOption();
void setAddress64(XBeeAddress64& addr64);
void setAddress64(const XBeeAddress64& addr64);
void setAddress16(uint16_t addr16);
void setBroadcastRadius(uint8_t broadcastRadius);
void setOption(uint8_t option);
Expand Down
2 changes: 1 addition & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<project default="dist" name="XBee-Arduino">
<property file="build.properties"/>
<property name="dist.dir" value="dist"/>
<property name="release" value="0.5"/>
<property name="release" value="0.6.0"/>

<target name="init">
<mkdir dir="${dist.dir}/XBee"/>
Expand Down
6 changes: 3 additions & 3 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name=XBee-Arduino library
version=0.5.0
author=Andrew Wrapp
maintainer=Andrew Wrapp <andrew.wrapp@gmail.com>
version=0.6.0
author=Andrew Rapp
maintainer=Andrew Rapp <andrew.rapp@gmail.com>
sentence=Library for talking to to various wireless XBee modules from Digi.
paragraph=This supports various devices, configured to use the more advanced "API" mode.
category=Communication
Expand Down

0 comments on commit 1bfd365

Please sign in to comment.