A libery to connect to telegesis zigbee module. Bassed on implemtation of XBEE
Fork of xbee_lib by
telegesis.h
- Committer:
- gert_lauritsen
- Date:
- 2014-11-28
- Revision:
- 30:f9cdb6f62586
- Parent:
- 29:6711180763b6
- Child:
- 31:c59bc92a047e
File content as of revision 30:f9cdb6f62586:
#ifndef telegesis_h #define telegesis_h #include "mbed.h" #include <RawSerial.h> /**Eksemple #include "telegesis.h" zigbee ZB(p9,p10); int main() { ZB.Reset(); wait(1); ZB.GetSerial(); while(1) { ZB.GetSerial(); ZB.RecieveData(read_data,0); ZB.UniCast("0000","tester forbindelse"); if (ZB.Zdat) { ZB.Zdat=0; printf(ZB.Zdata); } } } */ /** Zigbee interface class for configuring, sending and recieving data using an telegesis zigbee */ #define START_BYTE 0x7e #define ESCAPE 0x7d #define MAX_FRAME_DATA_SIZE 90 #define ZdataSize 80 typedef struct { char Ready; char ID[17]; char Data[ZdataSize]; }ZdatRec; class zigbee { private: PinName _tx; PinName _rx; PinName _reset; public: zigbee(PinName tx, PinName rx); ~zigbee(); /** Gets the serial number/mac address of the zigbee and places it into serial_no. * @param serial_no array to store the serial of zigbee (must be 8 long). * @return Returns 1 on success. */ 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. */ int SetKey(char*); /** Recieves data sent to the xbee. * @param data_buf Pointer to the buffer to put recieved data into. * @param numchar Number of characters to read. If 0, will use the size of data_buf. */ void RecieveData(char*, int); /** Get hw version and local ID (64bit uniq number) * */ int ATI(); /** Sends a ping to Coo or any other adresse * */ int PingOut(); /** Scan the Pan for nodes */ int PanScan(); /** Make a new network. It then gets the role as coordinator */ int Establish_Network(); /** Join a pan */ int JoinNetwork(); /** Leave a Pan */ int LeaveNetwork(); /** * Scan network */ int ScanNetwork(); /** *Give info on what role the modem has in the network */ int NetworkInfo(); /** */ int Reset(); /** Sends data using the ascii mode */ int UniCast(char *adr,char *payload); /** Sends data using the binary mode */ int UniCastb(char *adr,char *payload, char payloadSize); /** converts a string to a long */ unsigned long hextolong(const char *hex); /** convertes a string to a int */ unsigned int hextoint(const char *hex); /** */ int EUI64; /** COO or FBB */ char Devicetype[4]; /** Gives type of HW */ char PanNumber[5]; /** Gives number on current PAN of HW */ int PanChan; /* channel nummer on pan */ int PansNear[5]; /* Gives pannumber af those near */ char HWType[15]; /** incomming data */ ZdatRec In; //char Zdata[ZdataSize]; /** */ void SletZdata(void); char LocalID[17]; /** * indication of incoming data */ //uint8_t Zdat; /** * Indicator on that we have got a ack on a packet */ uint8_t PacketAck; /*Wait for ok from radio */ bool wait4OK(); int channel, NodeID, EPID,framesize, PanOnline; char NetNodeID[17]; //a remote node char NetInfo; //indication that network info is ready /** */ uint8_t ErrorCode; /** * 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 */ void SeePacket(); /** * Non blocking check og data. To be used in NON IRQ mode */ bool Work(); char _responseFrameString[MAX_FRAME_DATA_SIZE]; uint8_t GotFrame; //indicate that a frame has been recieved uint8_t Ok; private: uint8_t b; int SeqNumber; char tmpstr[30]; // buffer for incoming RX packets. holds only the api specific frame data, starting after the api id byte and prior to checksum RawSerial _zbee; bool wait4Offline(); bool wait4JPAN(); bool wait4str(char *p); char *list[ZdataSize]; size_t comma_parse ( char *line, char *list[], size_t size ); }; #endif