BayEOSArduino Library
|
#include <XBee.h>
Public Member Functions | |
void | readPacket () |
bool | readPacket (int timeout) |
void | readPacketUntilAvailable () |
void | getResponse (XBeeResponse &response) |
XBeeResponse & | getResponse () |
void | send (XBeeRequest &request) |
uint16_t | getPANID (void) |
uint8_t | parseRX16 (BayEOS &client, int rx_panid) |
uint8_t | getNextFrameId () |
virtual void | i_begin (long baud)=0 |
virtual int | i_available ()=0 |
virtual int | read ()=0 |
virtual void | flush ()=0 |
virtual size_t | write (uint8_t val)=0 |
Protected Member Functions | |
void | sendByte (uint8_t b, bool escape) |
void | resetResponse () |
Protected Attributes | |
XBeeResponse | _response |
bool | _escape |
uint8_t | _pos |
uint8_t | b |
uint8_t | _checksumTotal |
uint8_t | _nextFrameId |
uint8_t | _responseFrameData [MAX_FRAME_DATA_SIZE] |
Primary interface for communicating with an XBee Radio. This class provides methods for sending and receiving packets with an XBee radio via the serial port. The XBee radio must be configured in API (packet) mode (AP=2) in order to use this software.
Since this code is designed to run on a microcontroller, with only one thread, you are responsible for reading the data off the serial buffer in a timely manner. This involves a call to a variant of readPacket(...). If your serial port is receiving data faster than you are reading, you can expect to lose packets. Arduino only has a 128 byte serial buffer so it can easily overflow if two or more packets arrive without a call to readPacket(...)
In order to conserve resources, this class only supports storing one response packet in memory at a time. This means that you must fully consume the packet prior to calling readPacket(...), because calling readPacket(...) overwrites the previous response.
This class creates an array of size MAX_FRAME_DATA_SIZE for storing the response packet. You may want to adjust this value to conserve memory.
uint16_t XBeeInterface::getPANID | ( | void | ) |
Returns a sequential frame id between 1 and 255
XBeeResponse & XBeeInterface::getResponse | ( | ) |
Returns a reference to the current response Note: once readPacket is called again this response will be overwritten!
void XBeeInterface::getResponse | ( | XBeeResponse & | response | ) |
Starts the serial connection at the supplied baud rate
bool XBeeInterface::readPacket | ( | int | timeout | ) |
Waits a maximum of timeout milliseconds for a response packet before timing out; returns true if packet is read. Returns false if timeout or error occurs.
void XBeeInterface::readPacketUntilAvailable | ( | ) |
Reads until a packet is received or an error occurs. Caution: use this carefully since if you don't get a response, your Arduino code will hang on this call forever!! often it's better to use a timeout: readPacket(int)
void XBeeInterface::send | ( | XBeeRequest & | request | ) |
Sends a XBeeRequest (TX packet) out the serial port