RadioLib
Universal wireless communication library for Arduino
XBee.h
1 #if !defined(_RADIOLIB_XBEE_H) && !defined(RADIOLIB_EXCLUDE_XBEE)
2 #define _RADIOLIB_XBEE_H
3 
4 #include "../../ISerial.h"
5 #include "../../TypeDef.h"
6 
7 // API reserved characters
8 #define XBEE_API_START 0x7E
9 #define XBEE_API_ESCAPE 0x7D
10 #define XBEE_API_XON 0x11
11 #define XBEE_API_XOFF 0x13
12 
13 // API frame IDs
14 #define XBEE_API_FRAME_AT_COMMAND 0x08
15 #define XBEE_API_FRAME_AT_COMMAND_QUEUE 0x09
16 #define XBEE_API_FRAME_ZIGBEE_TRANSMIT_REQUEST 0x10
17 #define XBEE_API_FRAME_ZIGBEE_ADDRESS_EXPLICIT 0x11
18 #define XBEE_API_FRAME_REMOTE_COMMAND 0x17
19 #define XBEE_API_FRAME_CREATE_SOURCE_ROUTE 0x21
20 #define XBEE_API_FRAME_AT_COMMAND_RESPONSE 0x88
21 #define XBEE_API_FRAME_MODEM_STATUS 0x8A
22 #define XBEE_API_FRAME_ZIGBEE_TRANSMIT_STATUS 0x8B
23 #define XBEE_API_FRAME_ZIGBEE_RECEIVE_PACKET 0x90
24 #define XBEE_API_FRAME_ZIGBEE_EXPLICIT_RX 0x91
25 #define XBEE_API_FRAME_ZIGBEE_IO_DATA_SAMPLE_RX 0x92
26 #define XBEE_API_FRAME_SENSOR_READ 0x94
27 #define XBEE_API_FRAME_NODE_ID 0x95
28 #define XBEE_API_FRAME_REMOTE_COMMAND_RESPONSE 0x97
29 #define XBEE_API_FRAME_EXTENDED_MODEM_STATUS 0x98
30 #define XBEE_API_FRAME_OTA_FW_UPDATE_STATUS 0xA0
31 #define XBEE_API_FRAME_ROUTE_RECORD 0xA1
32 #define XBEE_API_FRAME_MANY_TO_ONE_ROUTE_REQUEST 0xA3
33 
39 class XBeeSerial: public ISerial {
40  public:
46  XBeeSerial(Module* mod);
47 
48  // basic methods
49 
57  int16_t begin(long speed);
58 
62  void reset();
63 
64  // configuration methods
65 
75  int16_t setDestinationAddress(const char* destinationAddressHigh, const char* destinationAddressLow);
76 
82  int16_t setPanId(const char* panId);
83 
84 #if !defined(RADIOLIB_GODMODE)
85  private:
86 #endif
87  bool enterCmdMode();
88 
89 };
90 
96 class XBee {
97  public:
103  XBee(Module* mod);
104 
105  // basic methods
106 
114  int16_t begin(long speed);
115 
119  void reset();
120 
130  int16_t transmit(uint8_t* dest, const char* payload, uint8_t radius = 1);
131 
143  int16_t transmit(uint8_t* dest, uint8_t* destNetwork, const char* payload, uint8_t radius = 1);
144 
150  size_t available();
151 
157  String getPacketSource();
158 
164  String getPacketData();
165 
166  // configuration methods
167 
173  int16_t setPanId(uint8_t* panId);
174 
175 #if !defined(RADIOLIB_GODMODE) && !defined(RADIOLIB_LOW_LEVEL)
176  protected:
177 #endif
178  Module* _mod;
179 
180 #if !defined(RADIOLIB_GODMODE)
181  protected:
182 #endif
183 
184  uint8_t _frameID = 0x01;
185  size_t _frameLength = 0;
186  bool _frameHeaderProcessed = false;
187 
188  #ifdef RADIOLIB_STATIC_ONLY
189  char _packetData[RADIOLIB_STATIC_ARRAY_SIZE];
190  #else
191  char* _packetData = new char[0];
192  #endif
193  uint8_t _packetSource[8] = {0, 0, 0, 0, 0, 0, 0, 0};
194 
195  int16_t confirmChanges();
196 
197  void sendApiFrame(uint8_t type, uint8_t id, const char* data);
198  void sendApiFrame(uint8_t type, uint8_t id, uint8_t* data, uint16_t length);
199  int16_t readApiFrame(uint8_t frameID, uint8_t codePos, uint16_t timeout = 5000);
200 
201  uint16_t getNumBytes(uint32_t timeout = 10000, size_t minBytes = 10);
202 };
203 
204 #endif
XBeeSerial::setPanId
int16_t setPanId(const char *panId)
Sets PAN (Personal Area Network) ID. Both XBees must be in the same PAN in order to use transparent m...
Definition: XBee.cpp:276
XBeeSerial::reset
void reset()
Resets module using interrupt/GPIO pin 1.
Definition: XBee.cpp:218
XBee::available
size_t available()
Gets the number of payload bytes received.
Definition: XBee.cpp:91
XBee::reset
void reset()
Resets module using interrupt/GPIO pin 1.
Definition: XBee.cpp:53
XBee::XBee
XBee(Module *mod)
Default constructor.
Definition: XBee.cpp:4
XBeeSerial
XBee Serial interface. This class is used for XBees in transparent mode, i.e. when two XBees act as a...
Definition: XBee.h:39
XBeeSerial::XBeeSerial
XBeeSerial(Module *mod)
Default constructor.
Definition: XBee.cpp:180
XBee::setPanId
int16_t setPanId(uint8_t *panId)
Sets PAN (Personal Area Network) ID. All XBees must be in the same PAN in order to communicate.
Definition: XBee.cpp:162
ISerial
Interface class for Arduino Serial. Only calls the appropriate methods for the active UART interface.
Definition: ISerial.h:11
XBee::getPacketData
String getPacketData()
Gets packet payload.
Definition: XBee.cpp:157
XBee::getPacketSource
String getPacketSource()
Gets packet source 64-bit address.
Definition: XBee.cpp:149
XBee
Control class for XBee modules.
Definition: XBee.h:96
Module
Implements all common low-level SPI/UART/I2C methods to control the wireless module....
Definition: Module.h:17
XBeeSerial::begin
int16_t begin(long speed)
Initialization method.
Definition: XBee.cpp:184
XBee::begin
int16_t begin(long speed)
Initialization method.
Definition: XBee.cpp:9
XBeeSerial::setDestinationAddress
int16_t setDestinationAddress(const char *destinationAddressHigh, const char *destinationAddressLow)
Sets destination XBee address.
Definition: XBee.cpp:226
XBee::transmit
int16_t transmit(uint8_t *dest, const char *payload, uint8_t radius=1)
Sends data to the destination 64-bit (global) address, when destination 16-bit (local) address is unk...
Definition: XBee.cpp:60