2015/05/16
Dependents: Aigamozu_Robot_ver3_1 Aigamozu_Robot_ver3_2 Aigamozu_Robot_ver3_3 Aigamozu_Robot_ver3_4 ... more
Fork of XBee by
Diff: XBee.h
- Revision:
- 4:f6d73acc1f75
- Parent:
- 3:8573b122fa84
- Child:
- 6:6f84e2840408
--- a/XBee.h Thu Mar 08 17:41:29 2012 +0000 +++ b/XBee.h Tue Mar 13 09:01:52 2012 +0000 @@ -33,6 +33,7 @@ #define SERIES_1 #define SERIES_2 +#define WIFI // set to ATAP value of XBee. AP=2 is recommended #define ATAP 2 @@ -48,7 +49,9 @@ // if a RX packet exceeds this size, it cannot be parsed! // 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 -#define MAX_FRAME_DATA_SIZE 110 +//#define MAX_FRAME_DATA_SIZE 110 +#define MAX_FRAME_DATA_SIZE 1520 +#define MAX_RXBUF_SIZE 32 #define BROADCAST_ADDRESS 0xffff #define ZB_BROADCAST_ADDRESS 0xfffe @@ -182,7 +185,7 @@ * Returns the length of the frame data: all bytes after the api id, and prior to the checksum * Note up to release 0.1.2, this was incorrectly including the checksum in the length. */ - uint8_t getFrameDataLength(); + uint16_t getFrameDataLength(); void setFrameData(uint8_t* frameDataPtr); /** * Returns the buffer that contains the response. @@ -194,7 +197,7 @@ */ uint8_t* getFrameData(); - void setFrameLength(uint8_t frameLength); + void setFrameLength(uint16_t frameLength); // to support future 65535 byte packets I guess /** * Returns the length of the packet @@ -283,7 +286,7 @@ uint8_t _msbLength; uint8_t _lsbLength; uint8_t _checksum; - uint8_t _frameLength; + uint16_t _frameLength; bool _complete; uint8_t _errorCode; }; @@ -348,7 +351,7 @@ /** * Returns the length of the payload */ - virtual uint8_t getDataLength() = 0; + virtual uint16_t getDataLength() = 0; /** * Returns the position in the frame data where the data begins */ @@ -382,7 +385,7 @@ XBeeAddress64& getRemoteAddress64(); uint16_t getRemoteAddress16(); uint8_t getOption(); - virtual uint8_t getDataLength(); + virtual uint16_t getDataLength(); // frame position where data starts virtual uint8_t getDataOffset(); private: @@ -444,7 +447,7 @@ uint8_t getOption(); bool isAddressBroadcast(); bool isPanBroadcast(); - virtual uint8_t getDataLength(); + virtual uint16_t getDataLength(); virtual uint8_t getDataOffset(); virtual uint8_t getRssiOffset() = 0; }; @@ -558,7 +561,7 @@ /** * Returns the length of the command value array. */ - uint8_t getValueLength(); + uint16_t getValueLength(); /** * Returns true if status equals AT_OK */ @@ -588,7 +591,7 @@ /** * Returns the length of the command value array. */ - uint8_t getValueLength(); + uint16_t getValueLength(); /** * Returns the 16-bit address of the remote radio */ @@ -639,11 +642,11 @@ * The reason for this is the API ID and Frame ID are common to all requests, whereas my definition of * frame data is only the API specific data. */ - virtual uint8_t getFrameData(uint8_t pos) = 0; + virtual uint8_t getFrameData(uint16_t pos) = 0; /** * Returns the size of the api frame (not including frame id or api id or checksum). */ - virtual uint8_t getFrameDataLength() = 0; + virtual uint16_t getFrameDataLength() = 0; //void reset(); protected: void setApiId(uint8_t apiId); @@ -677,7 +680,7 @@ class XBee { public: XBee(PinName p_tx, PinName p_rx); - XBee(PinName p_tx, PinName p_rx, PinName p_cts); + XBee(PinName p_tx, PinName p_rx, PinName p_cts, PinName p_rts); // for eclipse dev only // void setSerial(HardwareSerial serial); /** @@ -723,21 +726,27 @@ * Returns a sequential frame id between 1 and 255 */ uint8_t getNextFrameId(); + + void isr_recv (); + int getbuf (); + int bufreadable (); private: void sendByte(uint8_t b, bool escape); void resetResponse(); XBeeResponse _response; bool _escape; // current packet position for response. just a state variable for packet parsing and has no relevance for the response otherwise - uint8_t _pos; + uint16_t _pos, _epos; // last byte read uint8_t b; - uint8_t _checksumTotal; + uint16_t _checksumTotal; uint8_t _nextFrameId; // buffer for incoming RX packets. holds only the api specific frame data, starting after the api id byte and prior to checksum uint8_t _responseFrameData[MAX_FRAME_DATA_SIZE]; Serial _xbee; - DigitalIn *_cts; + char _rxbuf[MAX_RXBUF_SIZE]; + int _rxaddr_w, _rxaddr_r; + bool _rts; }; /** @@ -745,7 +754,7 @@ */ class PayloadRequest : public XBeeRequest { public: - PayloadRequest(uint8_t apiId, uint8_t frameId, uint8_t *payload, uint8_t payloadLength); + PayloadRequest(uint8_t apiId, uint8_t frameId, uint8_t *payload, uint16_t payloadLength); /** * Returns the payload of the packet, if not null */ @@ -757,16 +766,16 @@ /** * Returns the length of the payload array, as specified by the user. */ - uint8_t getPayloadLength(); + uint16_t getPayloadLength(); /** * Sets the length of the payload to include in the request. For example if the payload array * is 50 bytes and you only want the first 10 to be included in the packet, set the length to 10. * Length must be <= to the array length. */ - void setPayloadLength(uint8_t payloadLength); + void setPayloadLength(uint16_t payloadLength); private: uint8_t* _payloadPtr; - uint8_t _payloadLength; + uint16_t _payloadLength; }; #ifdef SERIES_1 @@ -781,11 +790,11 @@ */ class Tx16Request : public PayloadRequest { public: - Tx16Request(uint16_t addr16, uint8_t option, uint8_t *payload, uint8_t payloadLength, uint8_t frameId); + Tx16Request(uint16_t addr16, uint8_t option, uint8_t *payload, uint16_t payloadLength, uint8_t frameId); /** * Creates a Unicast Tx16Request with the ACK option and DEFAULT_FRAME_ID */ - Tx16Request(uint16_t addr16, uint8_t *payload, uint8_t payloadLength); + Tx16Request(uint16_t addr16, uint8_t *payload, uint16_t payloadLength); /** * Creates a default instance of this class. At a minimum you must specify * a payload, payload length and a destination address before sending this request. @@ -795,8 +804,8 @@ void setAddress16(uint16_t addr16); uint8_t getOption(); void setOption(uint8_t option); - virtual uint8_t getFrameData(uint8_t pos); - virtual uint8_t getFrameDataLength(); + virtual uint8_t getFrameData(uint16_t pos); + virtual uint16_t getFrameDataLength(); protected: private: uint16_t _addr16; @@ -813,11 +822,11 @@ */ class Tx64Request : public PayloadRequest { public: - Tx64Request(XBeeAddress64 &addr64, uint8_t option, uint8_t *payload, uint8_t payloadLength, uint8_t frameId); + Tx64Request(XBeeAddress64 &addr64, uint8_t option, uint8_t *payload, uint16_t payloadLength, uint8_t frameId); /** * Creates a unicast Tx64Request with the ACK option and DEFAULT_FRAME_ID */ - Tx64Request(XBeeAddress64 &addr64, uint8_t *payload, uint8_t payloadLength); + Tx64Request(XBeeAddress64 &addr64, uint8_t *payload, uint16_t payloadLength); /** * Creates a default instance of this class. At a minimum you must specify * a payload, payload length and a destination address before sending this request. @@ -828,8 +837,8 @@ // TODO move option to superclass uint8_t getOption(); void setOption(uint8_t option); - virtual uint8_t getFrameData(uint8_t pos); - virtual uint8_t getFrameDataLength(); + virtual uint8_t getFrameData(uint16_t pos); + virtual uint16_t getFrameDataLength(); private: XBeeAddress64 _addr64; uint8_t _option; @@ -857,8 +866,8 @@ /** * Creates a unicast ZBTxRequest with the ACK option and DEFAULT_FRAME_ID */ - ZBTxRequest(XBeeAddress64 &addr64, uint8_t *payload, uint8_t payloadLength); - ZBTxRequest(XBeeAddress64 &addr64, uint16_t addr16, uint8_t broadcastRadius, uint8_t option, uint8_t *payload, uint8_t payloadLength, uint8_t frameId); + ZBTxRequest(XBeeAddress64 &addr64, uint8_t *payload, uint16_t payloadLength); + ZBTxRequest(XBeeAddress64 &addr64, uint16_t addr16, uint8_t broadcastRadius, uint8_t option, uint8_t *payload, uint16_t payloadLength, uint8_t frameId); /** * Creates a default instance of this class. At a minimum you must specify * a payload, payload length and a destination address before sending this request. @@ -874,8 +883,8 @@ void setOption(uint8_t option); protected: // declare virtual functions - virtual uint8_t getFrameData(uint8_t pos); - virtual uint8_t getFrameDataLength(); + virtual uint8_t getFrameData(uint16_t pos); + virtual uint16_t getFrameDataLength(); private: XBeeAddress64 _addr64; uint16_t _addr16; @@ -894,8 +903,8 @@ AtCommandRequest(); AtCommandRequest(uint8_t *command); AtCommandRequest(uint8_t *command, uint8_t *commandValue, uint8_t commandValueLength); - virtual uint8_t getFrameData(uint8_t pos); - virtual uint8_t getFrameDataLength(); + virtual uint8_t getFrameData(uint16_t pos); + virtual uint16_t getFrameDataLength(); uint8_t* getCommand(); void setCommand(uint8_t* command); uint8_t* getCommandValue(); @@ -946,8 +955,8 @@ void setRemoteAddress64(XBeeAddress64 &remoteAddress64); bool getApplyChanges(); void setApplyChanges(bool applyChanges); - virtual uint8_t getFrameData(uint8_t pos); - virtual uint8_t getFrameDataLength(); + virtual uint8_t getFrameData(uint16_t pos); + virtual uint16_t getFrameDataLength(); static XBeeAddress64 broadcastAddress64; // static uint16_t broadcast16Address; private: