23 #if defined(ARDUINO) && ARDUINO >= 100
37 #define START_BYTE 0x7e
48 #define MAX_FRAME_DATA_SIZE 110
50 #define BROADCAST_ADDRESS 0xffff
51 #define ZB_BROADCAST_ADDRESS 0xfffe
54 #define ZB_TX_API_LENGTH 12
55 #define TX_16_API_LENGTH 3
56 #define TX_64_API_LENGTH 9
57 #define AT_COMMAND_API_LENGTH 2
58 #define REMOTE_AT_COMMAND_API_LENGTH 13
60 #define PACKET_OVERHEAD_LENGTH 6
62 #define API_ID_INDEX 3
65 #define RX_16_RSSI_OFFSET 2
66 #define RX_64_RSSI_OFFSET 8
68 #define DEFAULT_FRAME_ID 1
69 #define NO_RESPONSE_FRAME_ID 0
73 #define DISABLE_ACK_OPTION 1
74 #define BROADCAST_OPTION 4
77 #define ZB_PACKET_ACKNOWLEDGED 0x01
78 #define ZB_BROADCAST_PACKET 0x02
84 #define TX_64_REQUEST 0x0
85 #define TX_16_REQUEST 0x1
86 #define AT_COMMAND_REQUEST 0x08
87 #define AT_COMMAND_QUEUE_REQUEST 0x09
88 #define REMOTE_AT_REQUEST 0x17
89 #define ZB_TX_REQUEST 0x10
90 #define ZB_EXPLICIT_TX_REQUEST 0x11
91 #define RX_64_RESPONSE 0x80
92 #define RX_16_RESPONSE 0x81
93 #define RX_64_IO_RESPONSE 0x82
94 #define RX_16_IO_RESPONSE 0x83
95 #define AT_RESPONSE 0x88
96 #define TX_STATUS_RESPONSE 0x89
97 #define MODEM_STATUS_RESPONSE 0x8a
98 #define ZB_RX_RESPONSE 0x90
99 #define ZB_EXPLICIT_RX_RESPONSE 0x91
100 #define ZB_TX_STATUS_RESPONSE 0x8b
101 #define ZB_IO_SAMPLE_RESPONSE 0x92
102 #define ZB_IO_NODE_IDENTIFIER_RESPONSE 0x95
103 #define AT_COMMAND_RESPONSE 0x88
104 #define REMOTE_AT_COMMAND_RESPONSE 0x97
111 #define CCA_FAILURE 0x2
112 #define INVALID_DESTINATION_ENDPOINT_SUCCESS 0x15
113 #define NETWORK_ACK_FAILURE 0x21
114 #define NOT_JOINED_TO_NETWORK 0x22
115 #define SELF_ADDRESSED 0x23
116 #define ADDRESS_NOT_FOUND 0x24
117 #define ROUTE_NOT_FOUND 0x25
118 #define PAYLOAD_TOO_LARGE 0x74
121 #define HARDWARE_RESET 0
122 #define WATCHDOG_TIMER_RESET 1
124 #define DISASSOCIATED 3
125 #define SYNCHRONIZATION_LOST 4
126 #define COORDINATOR_REALIGNMENT 5
127 #define COORDINATOR_STARTED 6
129 #define ZB_BROADCAST_RADIUS_MAX_HOPS 0
131 #define ZB_TX_UNICAST 0
132 #define ZB_TX_BROADCAST 8
136 #define AT_INVALID_COMMAND 2
137 #define AT_INVALID_PARAMETER 3
138 #define AT_NO_RESPONSE 4
141 #define CHECKSUM_FAILURE 1
142 #define PACKET_EXCEEDS_BYTE_ARRAY_LENGTH 2
143 #define UNEXPECTED_START_BYTE 3
162 void setApiId(uint8_t apiId);
167 void setMsbLength(uint8_t msbLength);
172 void setLsbLength(uint8_t lsbLength);
177 void setChecksum(uint8_t checksum);
183 void setFrameData(uint8_t* frameDataPtr);
194 void setFrameLength(uint8_t frameLength);
263 void setAvailable(
bool complete);
273 void setErrorCode(uint8_t errorCode);
276 uint8_t* _frameDataPtr;
283 uint8_t _frameLength;
302 void setMsb(uint32_t msb);
303 void setLsb(uint32_t lsb);
327 uint8_t getFrameId();
368 uint16_t getRemoteAddress();
369 uint8_t getTxRetryCount();
370 uint8_t getDeliveryStatus();
371 uint8_t getDiscoveryStatus();
382 uint16_t getRemoteAddress16();
397 bool containsAnalog();
398 bool containsDigital();
417 uint8_t getDigitalMaskMsb();
418 uint8_t getDigitalMaskLsb();
419 uint8_t getAnalogMask();
444 bool isAddressBroadcast();
445 bool isPanBroadcast();
448 virtual uint8_t getRssiOffset() = 0;
457 uint8_t getRssiOffset();
458 uint16_t getRemoteAddress16();
460 uint16_t _remoteAddress;
469 uint8_t getRssiOffset();
485 bool containsAnalog();
486 bool containsDigital();
499 uint16_t
getAnalog(uint8_t pin, uint8_t sample);
505 uint8_t getSampleOffset();
512 uint16_t getRemoteAddress16();
513 uint8_t getRssiOffset();
521 uint8_t getRssiOffset();
648 void setApiId(uint8_t apiId);
706 void begin(Stream &serial);
730 void write(uint8_t val);
731 void sendByte(uint8_t b,
bool escape);
732 void resetResponse();
739 uint8_t _checksumTotal;
740 uint8_t _nextFrameId;
742 uint8_t _responseFrameData[MAX_FRAME_DATA_SIZE];
751 PayloadRequest(uint8_t apiId, uint8_t frameId, uint8_t *payload, uint8_t payloadLength);
771 uint8_t* _payloadPtr;
772 uint8_t _payloadLength;
787 Tx16Request(uint16_t addr16, uint8_t option, uint8_t *payload, uint8_t payloadLength, uint8_t frameId);
791 Tx16Request(uint16_t addr16, uint8_t *payload, uint8_t payloadLength);
797 uint16_t getAddress16();
798 void setAddress16(uint16_t addr16);
800 void setOption(uint8_t option);
833 void setOption(uint8_t option);
864 ZBTxRequest(
XBeeAddress64 &addr64, uint16_t addr16, uint8_t broadcastRadius, uint8_t option, uint8_t *payload, uint8_t payloadLength, uint8_t frameId);
871 uint16_t getAddress16();
872 uint8_t getBroadcastRadius();
875 void setAddress16(uint16_t addr16);
876 void setBroadcastRadius(uint8_t broadcastRadius);
877 void setOption(uint8_t option);
885 uint8_t _broadcastRadius;
899 AtCommandRequest(uint8_t *command, uint8_t *commandValue, uint8_t commandValueLength);
902 uint8_t* getCommand();
903 void setCommand(uint8_t* command);
904 uint8_t* getCommandValue();
905 void setCommandValue(uint8_t* command);
906 uint8_t getCommandValueLength();
907 void setCommandValueLength(uint8_t length);
915 uint8_t *_commandValue;
916 uint8_t _commandValueLength;
930 RemoteAtCommandRequest(uint16_t remoteAddress16, uint8_t *command, uint8_t *commandValue, uint8_t commandValueLength);
946 uint16_t getRemoteAddress16();
947 void setRemoteAddress16(uint16_t remoteAddress16);
950 bool getApplyChanges();
951 void setApplyChanges(
bool applyChanges);
958 uint16_t _remoteAddress16;
uint8_t getApiId()
Returns Api Id of the response.
Definition: XBee.cpp:34
Super class of all XBee requests (TX packets) Users should never create an instance of this class; in...
Definition: XBee.h:615
uint8_t getFrameDataLength()
Returns the size of the api frame (not including frame id or api id or checksum). ...
Definition: XBee.cpp:1413
Tx64Request()
Creates a default instance of this class.
Definition: XBee.cpp:1193
This class is extended by all Responses that include a frame id.
Definition: XBee.h:324
uint8_t getNextFrameId()
Returns a sequential frame id between 1 and 255.
Definition: XBee.cpp:773
Represents a Series 1 TX Status packet.
Definition: XBee.h:428
bool isOk()
Returns true if command was successful.
Definition: XBee.cpp:604
Represents a Series 1 RX packet.
Definition: XBee.h:438
bool isAnalogEnabled(uint8_t pin)
Returns true if the specified analog pin is enabled.
Definition: XBee.cpp:317
uint8_t getPayloadLength()
Returns the length of the payload array, as specified by the user.
Definition: XBee.cpp:1009
uint8_t * getPayload()
Returns the payload of the packet, if not null.
Definition: XBee.cpp:1001
uint8_t getValueLength()
Returns the length of the command value array.
Definition: XBee.cpp:609
uint8_t getChecksum()
Returns the packet checksum.
Definition: XBee.cpp:58
void getZBRxIoSampleResponse(XBeeResponse &response)
Call with instance of ZBRxIoSampleResponse class only if getApiId() == ZB_IO_SAMPLE_RESPONSE to popul...
Definition: XBee.cpp:255
bool isAnalogEnabled(uint8_t pin)
Returns true if the pin is enabled.
Definition: XBee.cpp:205
void init()
Initializes the response.
Definition: XBee.cpp:733
uint8_t getLsbLength()
Returns the LSB length of the packet.
Definition: XBee.cpp:50
virtual uint8_t getDataLength()=0
Returns the length of the payload.
Represents a 64-bit XBee Address.
Definition: XBee.h:296
void begin(Stream &serial)
Starts the serial connection on the specified serial port.
Definition: XBee.cpp:786
uint8_t getApiId()
Returns the API id.
Definition: XBee.cpp:975
void getRx16IoSampleResponse(XBeeResponse &response)
Call with instance of Rx16IoSampleResponse only if getApiId() == RX_16_IO_RESPONSE.
Definition: XBee.cpp:484
Represents a Remote AT Command RX packet.
Definition: XBee.h:570
void getRx64Response(XBeeResponse &response)
Call with instance of Rx64Response only if getApiId() == RX_64_RESPONSE.
Definition: XBee.cpp:578
uint8_t * getValue()
Returns an array containing the command value.
Definition: XBee.cpp:699
uint8_t getFrameDataLength()
Returns the size of the api frame (not including frame id or api id or checksum). ...
Definition: XBee.cpp:1106
Represents a Series 1 16-bit address RX packet.
Definition: XBee.h:454
uint8_t * getCommand()
Returns an array containing the two character command.
Definition: XBee.cpp:596
uint8_t getErrorCode()
Returns an error code, or zero, if successful.
Definition: XBee.cpp:86
void getModemStatusResponse(XBeeResponse &response)
Call with instance of ModemStatusResponse only if getApiId() == MODEM_STATUS_RESPONSE.
Definition: XBee.cpp:673
uint16_t getPacketLength()
Returns the length of the packet.
Definition: XBee.cpp:721
void setSerial(Stream &serial)
Specify the serial port.
Definition: XBee.cpp:790
Represents a Series 2 RX I/O Sample packet.
Definition: XBee.h:394
Represents an Remote AT Command TX packet The command is used to configure a remote XBee radio...
Definition: XBee.h:923
uint8_t getFrameDataLength()
Returns the size of the api frame (not including frame id or api id or checksum). ...
Definition: XBee.cpp:1314
uint8_t getStatus()
Returns the command status code.
Definition: XBee.cpp:691
bool isDigitalOn(uint8_t pin, uint8_t sample)
Returns true if the specified pin is high/on.
Definition: XBee.cpp:459
uint8_t getSampleSize()
Returns the number of samples in this packet.
Definition: XBee.cpp:301
void setPayload(uint8_t *payloadPtr)
Sets the payload array.
Definition: XBee.cpp:1005
Represents a Series 1 RX I/O Sample packet.
Definition: XBee.h:478
uint16_t getAnalog(uint8_t pin)
Returns the 10-bit analog reading of the specified pin.
Definition: XBee.cpp:218
virtual uint8_t getDataOffset()=0
Returns the position in the frame data where the data begins.
bool isAvailable()
Returns true if the response has been successfully parsed and is complete and ready for use...
Definition: XBee.cpp:74
bool isError()
Returns true if the response contains errors.
Definition: XBee.cpp:82
ZBTxRequest()
Creates a default instance of this class.
Definition: XBee.cpp:1058
XBeeResponse()
Default constructor.
Definition: XBee.cpp:30
bool isDigitalOn(uint8_t pin)
Returns true if the specified pin is high/on.
Definition: XBee.cpp:243
uint8_t getFrameData(uint8_t pos)
Starting after the frame id (pos = 0) and up to but not including the checksum Note: Unlike Digi's de...
Definition: XBee.cpp:1207
void getRx16Response(XBeeResponse &response)
Call with instance of Rx16Response only if getApiId() == RX_16_RESPONSE.
Definition: XBee.cpp:563
void getZBTxStatusResponse(XBeeResponse &response)
Call with instance of ZBTxStatusResponse class only if getApiId() == ZB_TX_STATUS_RESPONSE to populat...
Definition: XBee.cpp:131
Represents an AT Command TX packet The command is used to configure the serially connected XBee radio...
Definition: XBee.h:895
uint8_t getFrameData(uint8_t pos)
Starting after the frame id (pos = 0) and up to but not including the checksum Note: Unlike Digi's de...
Definition: XBee.cpp:1076
Represents a Series 1 TX packet that corresponds to Api Id: TX_64_REQUEST.
Definition: XBee.h:817
uint8_t getDataOffset()
Returns the position in the frame data where the data begins.
Definition: XBee.cpp:153
Represents a Modem Status RX packet.
Definition: XBee.h:531
XBeeAddress64 & getRemoteAddress64()
Returns the 64-bit address of the remote radio.
Definition: XBee.cpp:626
uint8_t getFrameDataLength()
Returns the length of the frame data: all bytes after the api id, and prior to the checksum Note up t...
Definition: XBee.cpp:66
bool isDigitalEnabled(uint8_t pin)
Returns true if the specified digital pin is enabled.
Definition: XBee.cpp:321
Represents a Series 2 RX packet.
Definition: XBee.h:378
void readPacket()
Reads all available serial bytes until a packet is parsed, an error occurs, or the buffer is empty...
Definition: XBee.cpp:855
uint8_t getMsbLength()
Returns the MSB length of the packet.
Definition: XBee.cpp:42
void readPacketUntilAvailable()
Reads until a packet is received or an error occurs.
Definition: XBee.cpp:825
uint8_t getDataLength()
Returns the length of the payload.
Definition: XBee.cpp:551
void getRemoteAtCommandResponse(XBeeResponse &response)
Call with instance of RemoteAtCommandResponse only if getApiId() == REMOTE_AT_COMMAND_RESPONSE.
Definition: XBee.cpp:630
uint16_t getRemoteAddress16()
Returns the 16-bit address of the remote radio.
Definition: XBee.cpp:622
Tx16Request()
Creates a default instance of this class.
Definition: XBee.cpp:1146
uint8_t getFrameData(uint8_t pos)
Starting after the frame id (pos = 0) and up to but not including the checksum Note: Unlike Digi's de...
Definition: XBee.cpp:1160
bool isDigitalEnabled(uint8_t pin)
Returns true if the pin is enabled.
Definition: XBee.cpp:209
uint8_t * getFrameData()
Returns the buffer that contains the response.
Definition: XBee.cpp:725
void send(XBeeRequest &request)
Sends a XBeeRequest (TX packet) out the serial port.
Definition: XBee.cpp:1423
uint8_t getDataOffset()
Returns the position in the frame data where the data begins.
Definition: XBee.cpp:555
XBeeResponse & getResponse()
Returns a reference to the current response Note: once readPacket is called again this response will ...
Definition: XBee.cpp:810
uint8_t * getData()
Returns the payload array.
Definition: XBee.cpp:652
Represents a Series 1 64-bit address RX packet.
Definition: XBee.h:466
Primary interface for communicating with an XBee Radio.
Definition: XBee.h:676
uint8_t getFrameId()
Returns the frame id.
Definition: XBee.cpp:971
Represents an AT Command RX packet.
Definition: XBee.h:540
void getTxStatusResponse(XBeeResponse &response)
Call with instance of TxStatusResponse only if getApiId() == TX_STATUS_RESPONSE.
Definition: XBee.cpp:526
void setPayloadLength(uint8_t payloadLength)
Sets the length of the payload to include in the request.
Definition: XBee.cpp:1013
void getAtCommandResponse(XBeeResponse &responses)
Call with instance of AtCommandResponse only if getApiId() == AT_COMMAND_RESPONSE.
Definition: XBee.cpp:712
uint8_t getStatus()
Returns the command status code.
Definition: XBee.cpp:600
virtual uint8_t getFrameData(uint8_t pos)=0
Starting after the frame id (pos = 0) and up to but not including the checksum Note: Unlike Digi's de...
uint16_t getAnalog(uint8_t pin, uint8_t sample)
Returns the 10-bit analog reading of the specified pin.
Definition: XBee.cpp:421
uint8_t getFrameData(uint8_t pos)
Starting after the frame id (pos = 0) and up to but not including the checksum Note: Unlike Digi's de...
Definition: XBee.cpp:1381
uint8_t getValueLength()
Returns the length of the command value array.
Definition: XBee.cpp:695
Represents a Series 1 TX packet that corresponds to Api Id: TX_16_REQUEST Be careful not to send a da...
Definition: XBee.h:785
void setFrameId(uint8_t frameId)
Sets the frame id.
Definition: XBee.cpp:967
All TX packets that support payloads extend this class.
Definition: XBee.h:749
The super class of all XBee responses (RX packets) Users should never attempt to create an instance o...
Definition: XBee.h:151
virtual uint8_t getFrameDataLength()=0
Returns the size of the api frame (not including frame id or api id or checksum). ...
uint8_t getFrameDataLength()
Returns the size of the api frame (not including frame id or api id or checksum). ...
Definition: XBee.cpp:1173
Represents a Series 2 TX packet that corresponds to Api Id: ZB_TX_REQUEST.
Definition: XBee.h:858
uint8_t getDataLength()
Returns the length of the payload.
Definition: XBee.cpp:157
uint8_t * getValue()
Returns an array containing the command value.
Definition: XBee.cpp:613
void getZBRxResponse(XBeeResponse &response)
Call with instance of ZBRxResponse class only if getApiId() == ZB_RX_RESPONSE to populate response...
Definition: XBee.cpp:165
bool isOk()
Returns true if status equals AT_OK.
Definition: XBee.cpp:708
XBeeRequest(uint8_t apiId, uint8_t frameId)
Constructor TODO make protected.
Definition: XBee.cpp:962
Common functionality for both Series 1 and 2 data RX data packets.
Definition: XBee.h:335
void clearCommandValue()
Clears the optional commandValue and commandValueLength so that a query may be sent.
Definition: XBee.cpp:1305
void getRx64IoSampleResponse(XBeeResponse &response)
Call with instance of Rx64IoSampleResponse only if getApiId() == RX_64_IO_RESPONSE.
Definition: XBee.cpp:504
uint8_t * getCommand()
Returns an array containing the two character command.
Definition: XBee.cpp:687
uint8_t getFrameData(uint8_t pos)
Starting after the frame id (pos = 0) and up to but not including the checksum Note: Unlike Digi's de...
Definition: XBee.cpp:1294
Represents a Series 2 TX status packet.
Definition: XBee.h:365
void reset()
Resets the response to default values.
Definition: XBee.cpp:739
uint8_t getFrameDataLength()
Returns the size of the api frame (not including frame id or api id or checksum). ...
Definition: XBee.cpp:1232