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 #ifndef 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 #ifndef RADIOLIB_GODMODE
176  private:
177 #endif
178  Module* _mod;
179  uint8_t _frameID = 0x01;
180  size_t _frameLength = 0;
181  bool _frameHeaderProcessed = false;
182 
183  #ifdef RADIOLIB_STATIC_ONLY
184  char _packetData[RADIOLIB_STATIC_ARRAY_SIZE];
185  #else
186  char* _packetData = new char[0];
187  #endif
188  uint8_t _packetSource[8] = {0, 0, 0, 0, 0, 0, 0, 0};
189 
190  int16_t confirmChanges();
191 
192  void sendApiFrame(uint8_t type, uint8_t id, const char* data);
193  void sendApiFrame(uint8_t type, uint8_t id, uint8_t* data, uint16_t length);
194  int16_t readApiFrame(uint8_t frameID, uint8_t codePos, uint16_t timeout = 5000);
195 
196  uint16_t getNumBytes(uint32_t timeout = 10000, size_t minBytes = 10);
197 };
198 
199 #endif
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
int16_t setDestinationAddress(const char *destinationAddressHigh, const char *destinationAddressLow)
Sets destination XBee address.
Definition: XBee.cpp:226
XBee Serial interface. This class is used for XBees in transparent mode, i.e. when two XBees act as a...
Definition: XBee.h:39
Implements all common low-level SPI/UART/I2C methods to control the wireless module. Every module class contains one private instance of this class.
Definition: Module.h:17
Interface class for Arduino Serial. Only calls the appropriate methods for the active UART interface...
Definition: ISerial.h:16
XBeeSerial(Module *mod)
Default constructor.
Definition: XBee.cpp:180
Control class for XBee modules.
Definition: XBee.h:96
void reset()
Resets module using interrupt/GPIO pin 1.
Definition: XBee.cpp:218
int16_t begin(long speed)
Initialization method.
Definition: XBee.cpp:184