XBee-Arduino  0.2
XBee.h
1 
20 #ifndef XBee_h
21 #define XBee_h
22 
23 #if defined(ARDUINO) && ARDUINO >= 100
24  #include "Arduino.h"
25 #else
26  #include "WProgram.h"
27 #endif
28 
29 #include <inttypes.h>
30 
31 #define SERIES_1
32 #define SERIES_2
33 
34 // set to ATAP value of XBee. AP=2 is recommended
35 #define ATAP 2
36 
37 #define START_BYTE 0x7e
38 #define ESCAPE 0x7d
39 #define XON 0x11
40 #define XOFF 0x13
41 
42 // This value determines the size of the byte array for receiving RX packets
43 // Most users won't be dealing with packets this large so you can adjust this
44 // value to reduce memory consumption. But, remember that
45 // if a RX packet exceeds this size, it cannot be parsed!
46 
47 // This value is determined by the largest packet size (100 byte payload + 64-bit address + option byte and rssi byte) of a series 1 radio
48 #define MAX_FRAME_DATA_SIZE 110
49 
50 #define BROADCAST_ADDRESS 0xffff
51 #define ZB_BROADCAST_ADDRESS 0xfffe
52 
53 // the non-variable length of the frame data (not including frame id or api id or variable data size (e.g. payload, at command set value)
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
59 // start/length(2)/api/frameid/checksum bytes
60 #define PACKET_OVERHEAD_LENGTH 6
61 // api is always the third byte in packet
62 #define API_ID_INDEX 3
63 
64 // frame position of rssi byte
65 #define RX_16_RSSI_OFFSET 2
66 #define RX_64_RSSI_OFFSET 8
67 
68 #define DEFAULT_FRAME_ID 1
69 #define NO_RESPONSE_FRAME_ID 0
70 
71 // TODO put in tx16 class
72 #define ACK_OPTION 0
73 #define DISABLE_ACK_OPTION 1
74 #define BROADCAST_OPTION 4
75 
76 // RX options
77 #define ZB_PACKET_ACKNOWLEDGED 0x01
78 #define ZB_BROADCAST_PACKET 0x02
79 
80 // not everything is implemented!
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
105 
106 
110 #define SUCCESS 0x0
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
119 
120 // modem status
121 #define HARDWARE_RESET 0
122 #define WATCHDOG_TIMER_RESET 1
123 #define ASSOCIATED 2
124 #define DISASSOCIATED 3
125 #define SYNCHRONIZATION_LOST 4
126 #define COORDINATOR_REALIGNMENT 5
127 #define COORDINATOR_STARTED 6
128 
129 #define ZB_BROADCAST_RADIUS_MAX_HOPS 0
130 
131 #define ZB_TX_UNICAST 0
132 #define ZB_TX_BROADCAST 8
133 
134 #define AT_OK 0
135 #define AT_ERROR 1
136 #define AT_INVALID_COMMAND 2
137 #define AT_INVALID_PARAMETER 3
138 #define AT_NO_RESPONSE 4
139 
140 #define NO_ERROR 0
141 #define CHECKSUM_FAILURE 1
142 #define PACKET_EXCEEDS_BYTE_ARRAY_LENGTH 2
143 #define UNEXPECTED_START_BYTE 3
144 
152 public:
153  //static const int MODEM_STATUS = 0x8a;
157  XBeeResponse();
161  uint8_t getApiId();
162  void setApiId(uint8_t apiId);
166  uint8_t getMsbLength();
167  void setMsbLength(uint8_t msbLength);
171  uint8_t getLsbLength();
172  void setLsbLength(uint8_t lsbLength);
176  uint8_t getChecksum();
177  void setChecksum(uint8_t checksum);
182  uint8_t getFrameDataLength();
183  void setFrameData(uint8_t* frameDataPtr);
192  uint8_t* getFrameData();
193 
194  void setFrameLength(uint8_t frameLength);
195  // to support future 65535 byte packets I guess
199  uint16_t getPacketLength();
203  void reset();
207  void init();
208 #ifdef SERIES_2
209 
213  void getZBTxStatusResponse(XBeeResponse &response);
218  void getZBRxResponse(XBeeResponse &response);
223  void getZBRxIoSampleResponse(XBeeResponse &response);
224 #endif
225 #ifdef SERIES_1
226 
229  void getTxStatusResponse(XBeeResponse &response);
233  void getRx16Response(XBeeResponse &response);
237  void getRx64Response(XBeeResponse &response);
241  void getRx16IoSampleResponse(XBeeResponse &response);
245  void getRx64IoSampleResponse(XBeeResponse &response);
246 #endif
247 
250  void getAtCommandResponse(XBeeResponse &responses);
258  void getModemStatusResponse(XBeeResponse &response);
262  bool isAvailable();
263  void setAvailable(bool complete);
267  bool isError();
272  uint8_t getErrorCode();
273  void setErrorCode(uint8_t errorCode);
274 protected:
275  // pointer to frameData
276  uint8_t* _frameDataPtr;
277 private:
278  void setCommon(XBeeResponse &target);
279  uint8_t _apiId;
280  uint8_t _msbLength;
281  uint8_t _lsbLength;
282  uint8_t _checksum;
283  uint8_t _frameLength;
284  bool _complete;
285  uint8_t _errorCode;
286 };
287 
288 class XBeeAddress {
289 public:
290  XBeeAddress();
291 };
292 
296 class XBeeAddress64 : public XBeeAddress {
297 public:
298  XBeeAddress64(uint32_t msb, uint32_t lsb);
299  XBeeAddress64();
300  uint32_t getMsb();
301  uint32_t getLsb();
302  void setMsb(uint32_t msb);
303  void setLsb(uint32_t lsb);
304  //bool operator==(XBeeAddress64 addr);
305  //bool operator!=(XBeeAddress64 addr);
306 private:
307  uint32_t _msb;
308  uint32_t _lsb;
309 };
310 
311 //class XBeeAddress16 : public XBeeAddress {
312 //public:
313 // XBeeAddress16(uint16_t addr);
314 // XBeeAddress16();
315 // uint16_t getAddress();
316 // void setAddress(uint16_t addr);
317 //private:
318 // uint16_t _addr;
319 //};
320 
325 public:
326  FrameIdResponse();
327  uint8_t getFrameId();
328 private:
329  uint8_t _frameId;
330 };
331 
335 class RxDataResponse : public XBeeResponse {
336 public:
337  RxDataResponse();
342  uint8_t getData(int index);
346  uint8_t* getData();
350  virtual uint8_t getDataLength() = 0;
354  virtual uint8_t getDataOffset() = 0;
355 };
356 
357 // getResponse to return the proper subclass:
358 // we maintain a pointer to each type of response, when a response is parsed, it is allocated only if NULL
359 // can we allocate an object in a function?
360 
361 #ifdef SERIES_2
362 
366  public:
368  uint16_t getRemoteAddress();
369  uint8_t getTxRetryCount();
370  uint8_t getDeliveryStatus();
371  uint8_t getDiscoveryStatus();
372  bool isSuccess();
373 };
374 
378 class ZBRxResponse : public RxDataResponse {
379 public:
380  ZBRxResponse();
381  XBeeAddress64& getRemoteAddress64();
382  uint16_t getRemoteAddress16();
383  uint8_t getOption();
384  uint8_t getDataLength();
385  // frame position where data starts
386  uint8_t getDataOffset();
387 private:
388  XBeeAddress64 _remoteAddress64;
389 };
390 
395 public:
397  bool containsAnalog();
398  bool containsDigital();
402  bool isAnalogEnabled(uint8_t pin);
406  bool isDigitalEnabled(uint8_t pin);
411  uint16_t getAnalog(uint8_t pin);
416  bool isDigitalOn(uint8_t pin);
417  uint8_t getDigitalMaskMsb();
418  uint8_t getDigitalMaskLsb();
419  uint8_t getAnalogMask();
420 };
421 
422 #endif
423 
424 #ifdef SERIES_1
425 
429  public:
431  uint8_t getStatus();
432  bool isSuccess();
433 };
434 
438 class RxResponse : public RxDataResponse {
439 public:
440  RxResponse();
441  // remember rssi is negative but this is unsigned byte so it's up to you to convert
442  uint8_t getRssi();
443  uint8_t getOption();
444  bool isAddressBroadcast();
445  bool isPanBroadcast();
446  uint8_t getDataLength();
447  uint8_t getDataOffset();
448  virtual uint8_t getRssiOffset() = 0;
449 };
450 
454 class Rx16Response : public RxResponse {
455 public:
456  Rx16Response();
457  uint8_t getRssiOffset();
458  uint16_t getRemoteAddress16();
459 protected:
460  uint16_t _remoteAddress;
461 };
462 
466 class Rx64Response : public RxResponse {
467 public:
468  Rx64Response();
469  uint8_t getRssiOffset();
470  XBeeAddress64& getRemoteAddress64();
471 private:
472  XBeeAddress64 _remoteAddress;
473 };
474 
479  public:
484  uint8_t getSampleSize();
485  bool containsAnalog();
486  bool containsDigital();
490  bool isAnalogEnabled(uint8_t pin);
494  bool isDigitalEnabled(uint8_t pin);
499  uint16_t getAnalog(uint8_t pin, uint8_t sample);
504  bool isDigitalOn(uint8_t pin, uint8_t sample);
505  uint8_t getSampleOffset();
506  private:
507 };
508 
510 public:
512  uint16_t getRemoteAddress16();
513  uint8_t getRssiOffset();
514 
515 };
516 
518 public:
520  XBeeAddress64& getRemoteAddress64();
521  uint8_t getRssiOffset();
522 private:
523  XBeeAddress64 _remoteAddress;
524 };
525 
526 #endif
527 
532 public:
534  uint8_t getStatus();
535 };
536 
541  public:
546  uint8_t* getCommand();
551  uint8_t getStatus();
556  uint8_t* getValue();
560  uint8_t getValueLength();
564  bool isOk();
565 };
566 
571  public:
576  uint8_t* getCommand();
581  uint8_t getStatus();
586  uint8_t* getValue();
590  uint8_t getValueLength();
594  uint16_t getRemoteAddress16();
602  bool isOk();
603  private:
604  XBeeAddress64 _remoteAddress64;
605 };
606 
607 
615 class XBeeRequest {
616 public:
621  XBeeRequest(uint8_t apiId, uint8_t frameId);
625  void setFrameId(uint8_t frameId);
629  uint8_t getFrameId();
633  uint8_t getApiId();
634  // setting = 0 makes this a pure virtual function, meaning the subclass must implement, like abstract in java
641  virtual uint8_t getFrameData(uint8_t pos) = 0;
645  virtual uint8_t getFrameDataLength() = 0;
646  //void reset();
647 protected:
648  void setApiId(uint8_t apiId);
649 private:
650  uint8_t _apiId;
651  uint8_t _frameId;
652 };
653 
654 // TODO add reset/clear method since responses are often reused
676 class XBee {
677 public:
678  XBee();
691  void readPacket();
696  bool readPacket(int timeout);
706  void begin(Stream &serial);
707  void getResponse(XBeeResponse &response);
716  void send(XBeeRequest &request);
717  //uint8_t sendAndWaitForResponse(XBeeRequest &request, int timeout);
721  uint8_t getNextFrameId();
725  void setSerial(Stream &serial);
726 private:
727  bool available();
728  uint8_t read();
729  void flush();
730  void write(uint8_t val);
731  void sendByte(uint8_t b, bool escape);
732  void resetResponse();
733  XBeeResponse _response;
734  bool _escape;
735  // current packet position for response. just a state variable for packet parsing and has no relevance for the response otherwise
736  uint8_t _pos;
737  // last byte read
738  uint8_t b;
739  uint8_t _checksumTotal;
740  uint8_t _nextFrameId;
741  // buffer for incoming RX packets. holds only the api specific frame data, starting after the api id byte and prior to checksum
742  uint8_t _responseFrameData[MAX_FRAME_DATA_SIZE];
743  Stream* _serial;
744 };
745 
749 class PayloadRequest : public XBeeRequest {
750 public:
751  PayloadRequest(uint8_t apiId, uint8_t frameId, uint8_t *payload, uint8_t payloadLength);
755  uint8_t* getPayload();
759  void setPayload(uint8_t* payloadPtr);
763  uint8_t getPayloadLength();
769  void setPayloadLength(uint8_t payloadLength);
770 private:
771  uint8_t* _payloadPtr;
772  uint8_t _payloadLength;
773 };
774 
775 #ifdef SERIES_1
776 
785 class Tx16Request : public PayloadRequest {
786 public:
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);
796  Tx16Request();
797  uint16_t getAddress16();
798  void setAddress16(uint16_t addr16);
799  uint8_t getOption();
800  void setOption(uint8_t option);
801  uint8_t getFrameData(uint8_t pos);
802  uint8_t getFrameDataLength();
803 protected:
804 private:
805  uint16_t _addr16;
806  uint8_t _option;
807 };
808 
817 class Tx64Request : public PayloadRequest {
818 public:
819  Tx64Request(XBeeAddress64 &addr64, uint8_t option, uint8_t *payload, uint8_t payloadLength, uint8_t frameId);
823  Tx64Request(XBeeAddress64 &addr64, uint8_t *payload, uint8_t payloadLength);
828  Tx64Request();
829  XBeeAddress64& getAddress64();
830  void setAddress64(XBeeAddress64& addr64);
831  // TODO move option to superclass
832  uint8_t getOption();
833  void setOption(uint8_t option);
834  uint8_t getFrameData(uint8_t pos);
835  uint8_t getFrameDataLength();
836 private:
837  XBeeAddress64 _addr64;
838  uint8_t _option;
839 };
840 
841 #endif
842 
843 
844 #ifdef SERIES_2
845 
858 class ZBTxRequest : public PayloadRequest {
859 public:
863  ZBTxRequest(XBeeAddress64 &addr64, uint8_t *payload, uint8_t payloadLength);
864  ZBTxRequest(XBeeAddress64 &addr64, uint16_t addr16, uint8_t broadcastRadius, uint8_t option, uint8_t *payload, uint8_t payloadLength, uint8_t frameId);
869  ZBTxRequest();
870  XBeeAddress64& getAddress64();
871  uint16_t getAddress16();
872  uint8_t getBroadcastRadius();
873  uint8_t getOption();
874  void setAddress64(XBeeAddress64& addr64);
875  void setAddress16(uint16_t addr16);
876  void setBroadcastRadius(uint8_t broadcastRadius);
877  void setOption(uint8_t option);
878 protected:
879  // declare virtual functions
880  uint8_t getFrameData(uint8_t pos);
881  uint8_t getFrameDataLength();
882 private:
883  XBeeAddress64 _addr64;
884  uint16_t _addr16;
885  uint8_t _broadcastRadius;
886  uint8_t _option;
887 };
888 
889 #endif
890 
896 public:
898  AtCommandRequest(uint8_t *command);
899  AtCommandRequest(uint8_t *command, uint8_t *commandValue, uint8_t commandValueLength);
900  uint8_t getFrameData(uint8_t pos);
901  uint8_t getFrameDataLength();
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);
911  void clearCommandValue();
912  //void reset();
913 private:
914  uint8_t *_command;
915  uint8_t *_commandValue;
916  uint8_t _commandValueLength;
917 };
918 
924 public:
930  RemoteAtCommandRequest(uint16_t remoteAddress16, uint8_t *command, uint8_t *commandValue, uint8_t commandValueLength);
935  RemoteAtCommandRequest(uint16_t remoteAddress16, uint8_t *command);
940  RemoteAtCommandRequest(XBeeAddress64 &remoteAddress64, uint8_t *command, uint8_t *commandValue, uint8_t commandValueLength);
945  RemoteAtCommandRequest(XBeeAddress64 &remoteAddress64, uint8_t *command);
946  uint16_t getRemoteAddress16();
947  void setRemoteAddress16(uint16_t remoteAddress16);
948  XBeeAddress64& getRemoteAddress64();
949  void setRemoteAddress64(XBeeAddress64 &remoteAddress64);
950  bool getApplyChanges();
951  void setApplyChanges(bool applyChanges);
952  uint8_t getFrameData(uint8_t pos);
953  uint8_t getFrameDataLength();
954  static XBeeAddress64 broadcastAddress64;
955 // static uint16_t broadcast16Address;
956 private:
957  XBeeAddress64 _remoteAddress64;
958  uint16_t _remoteAddress16;
959  bool _applyChanges;
960 };
961 
962 
963 
964 #endif //XBee_h
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
Definition: XBee.h:288
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
Definition: XBee.h:517
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
Definition: XBee.h:509
uint8_t getFrameDataLength()
Returns the size of the api frame (not including frame id or api id or checksum). ...
Definition: XBee.cpp:1232