A libery to connect to telegesis zigbee module. Bassed on implemtation of XBEE
Fork of xbee_lib by
Diff: telegesis.h
- Revision:
- 11:18ff088287ea
- Parent:
- 10:263f7251c111
- Child:
- 12:debf76f0c0bf
diff -r 263f7251c111 -r 18ff088287ea telegesis.h --- a/telegesis.h Sun Oct 13 20:49:23 2013 +0000 +++ b/telegesis.h Tue Oct 15 09:55:41 2013 +0000 @@ -1,6 +1,15 @@ +#ifndef telegesis_h +#define telegesis_h + #include "mbed.h" /** Zigbee interface class for configuring, sending and recieving data using an telegesis zigbee */ +#define START_BYTE 0x7e +#define ESCAPE 0x7d +#define CR 0x0D +#define LF 0x0A +#define MAX_FRAME_DATA_SIZE 110 + class zigbee { private: @@ -9,7 +18,7 @@ PinName _reset; public: - zigbee(PinName tx, PinName rx, PinName reset); + zigbee(PinName tx, PinName rx); ~zigbee(); @@ -17,7 +26,7 @@ * @param serial_no array to store the serial of zigbee (must be 8 long). * @return Returns 1 on success. */ - int GetSerial(int*); + int GetSerial(); /** Sets the encryption key. This should be a 128-bit key. * @param key Pointer to the network key to set. * @return Returns 1 on success. @@ -63,16 +72,14 @@ /** Sends data using the binary mode */ int UniCastb(char *adr,char *payload, char payloadSize); - /** Pulls Resetpin - */ - void Reset(); + /** converts a string to a long */ - unsigned long hexToLong(const char *hex); + unsigned long hextolong(const char *hex); /** convertes a string to a int */ - unsigned int hexToInt(const char *hex); + unsigned int hextoint(const char *hex); /** */ int EUI64; @@ -85,6 +92,51 @@ /** incomming data */ char Zdata[100]; - - int channel, NodeID, EPID,framesize; -}; \ No newline at end of file + /** + + */ + char LocalID[17]; + /** + * indication of incoming data + */ + uint8_t Zdat; + /** + * Indicator on that we have got a ack on a packet + */ + uint8_t PacketAck; + + int channel, NodeID, EPID,framesize, PanOnline; + /** + * Reads all available serial bytes until a packet is parsed, an error occurs, or the buffer is empty. + * You may call <i>xbee</i>.getResponse().isAvailable() after calling this method to determine if + * a packet is ready, or <i>xbee</i>.getResponse().isError() to determine if + * a error occurred. + * <p/> + * This method should always return quickly since it does not wait for serial data to arrive. + * You will want to use this method if you are doing other timely stuff in your loop, where + * a delay would cause problems. + * NOTE: calling this method resets the current response, so make sure you first consume the + * current response + */ + void readPacket(); + /**Looks for a packet but dont wait + */ + uint8_t SeePacket(); + + +private: + uint8_t _pos; + // last byte read + uint8_t b; + uint8_t _checksumTotal; + uint8_t _nextFrameId; + int SeqNumber; + // 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]; + char _responseFrameString[MAX_FRAME_DATA_SIZE]; + + Serial _zbee; + int wait4OK(); +}; + +#endif