A libery to connect to telegesis zigbee module. Bassed on implemtation of XBEE

Fork of xbee_lib by Tristan Hughes

Committer:
gert_lauritsen
Date:
Fri Oct 18 06:18:20 2013 +0000
Revision:
14:dcf2390f89e2
Parent:
12:debf76f0c0bf
Child:
16:65c47cf83467
Ny med zigbee fungerende

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gert_lauritsen 11:18ff088287ea 1 #ifndef telegesis_h
gert_lauritsen 11:18ff088287ea 2 #define telegesis_h
gert_lauritsen 11:18ff088287ea 3
tristanjph 0:2656fb225c5d 4 #include "mbed.h"
tristanjph 0:2656fb225c5d 5
gert_lauritsen 7:45511c3d2950 6 /** Zigbee interface class for configuring, sending and recieving data using an telegesis zigbee */
gert_lauritsen 11:18ff088287ea 7 #define START_BYTE 0x7e
gert_lauritsen 11:18ff088287ea 8 #define ESCAPE 0x7d
gert_lauritsen 11:18ff088287ea 9 #define MAX_FRAME_DATA_SIZE 110
gert_lauritsen 11:18ff088287ea 10
gert_lauritsen 7:45511c3d2950 11 class zigbee
tristanjph 2:cb627ea9b817 12 {
tristanjph 0:2656fb225c5d 13 private:
tristanjph 0:2656fb225c5d 14 PinName _tx;
tristanjph 0:2656fb225c5d 15 PinName _rx;
tristanjph 3:682615a0717e 16 PinName _reset;
tristanjph 0:2656fb225c5d 17 public:
gert_lauritsen 7:45511c3d2950 18
gert_lauritsen 11:18ff088287ea 19 zigbee(PinName tx, PinName rx);
gert_lauritsen 7:45511c3d2950 20 ~zigbee();
gert_lauritsen 7:45511c3d2950 21
gert_lauritsen 7:45511c3d2950 22
gert_lauritsen 7:45511c3d2950 23 /** Gets the serial number/mac address of the zigbee and places it into serial_no.
gert_lauritsen 7:45511c3d2950 24 * @param serial_no array to store the serial of zigbee (must be 8 long).
tristanjph 2:cb627ea9b817 25 * @return Returns 1 on success.
tristanjph 2:cb627ea9b817 26 */
gert_lauritsen 11:18ff088287ea 27 int GetSerial();
tristanjph 6:6455a079bdb3 28 /** Sets the encryption key. This should be a 128-bit key.
tristanjph 2:cb627ea9b817 29 * @param key Pointer to the network key to set.
tristanjph 2:cb627ea9b817 30 * @return Returns 1 on success.
tristanjph 1:c3d9bdcb0b03 31 */
tristanjph 5:714651141a83 32 int SetKey(char*);
gert_lauritsen 7:45511c3d2950 33
tristanjph 2:cb627ea9b817 34 /** Recieves data sent to the xbee.
tristanjph 2:cb627ea9b817 35 * @param data_buf Pointer to the buffer to put recieved data into.
tristanjph 2:cb627ea9b817 36 * @param numchar Number of characters to read. If 0, will use the size of data_buf.
tristanjph 2:cb627ea9b817 37 */
tristanjph 2:cb627ea9b817 38 void RecieveData(char*, int);
gert_lauritsen 10:263f7251c111 39 /** Get hw version and local ID (64bit uniq number)
gert_lauritsen 10:263f7251c111 40 *
gert_lauritsen 10:263f7251c111 41 */
gert_lauritsen 7:45511c3d2950 42 int ATI();
gert_lauritsen 10:263f7251c111 43 /** Sends a ping to Coo or any other adresse
gert_lauritsen 8:4682155753ec 44 *
gert_lauritsen 7:45511c3d2950 45 */
gert_lauritsen 7:45511c3d2950 46 int PingOut();
gert_lauritsen 10:263f7251c111 47 /** Scan the Pan for nodes
gert_lauritsen 7:45511c3d2950 48 */
gert_lauritsen 7:45511c3d2950 49 int PanScan();
gert_lauritsen 10:263f7251c111 50 /** Make a new network. It then gets the role as coordinator
gert_lauritsen 7:45511c3d2950 51 */
gert_lauritsen 7:45511c3d2950 52 int Establish_Network();
gert_lauritsen 10:263f7251c111 53 /** Join a pan
gert_lauritsen 7:45511c3d2950 54 */
gert_lauritsen 7:45511c3d2950 55 int JoinNetwork();
gert_lauritsen 10:263f7251c111 56 /**
gert_lauritsen 10:263f7251c111 57 * Scan network
gert_lauritsen 7:45511c3d2950 58 */
gert_lauritsen 7:45511c3d2950 59 int ScanNetwork();
gert_lauritsen 10:263f7251c111 60 /**
gert_lauritsen 10:263f7251c111 61 *Give info on what role the modem has in the network
gert_lauritsen 7:45511c3d2950 62 */
gert_lauritsen 10:263f7251c111 63
gert_lauritsen 7:45511c3d2950 64 int NetworkInfo();
gert_lauritsen 10:263f7251c111 65 /**
gert_lauritsen 7:45511c3d2950 66 */
gert_lauritsen 12:debf76f0c0bf 67 int Reset();
gert_lauritsen 8:4682155753ec 68 /** Sends data using the ascii mode
gert_lauritsen 10:263f7251c111 69 */
gert_lauritsen 9:c8e4339ccc29 70 int UniCast(char *adr,char *payload);
gert_lauritsen 8:4682155753ec 71 /** Sends data using the binary mode
gert_lauritsen 8:4682155753ec 72 */
gert_lauritsen 9:c8e4339ccc29 73 int UniCastb(char *adr,char *payload, char payloadSize);
gert_lauritsen 11:18ff088287ea 74
gert_lauritsen 10:263f7251c111 75
gert_lauritsen 9:c8e4339ccc29 76 /** converts a string to a long
gert_lauritsen 9:c8e4339ccc29 77 */
gert_lauritsen 11:18ff088287ea 78 unsigned long hextolong(const char *hex);
gert_lauritsen 8:4682155753ec 79 /** convertes a string to a int
gert_lauritsen 8:4682155753ec 80 */
gert_lauritsen 11:18ff088287ea 81 unsigned int hextoint(const char *hex);
gert_lauritsen 9:c8e4339ccc29 82 /**
gert_lauritsen 9:c8e4339ccc29 83 */
gert_lauritsen 7:45511c3d2950 84 int EUI64;
gert_lauritsen 9:c8e4339ccc29 85 /** COO or FBB
gert_lauritsen 9:c8e4339ccc29 86 */
gert_lauritsen 7:45511c3d2950 87 char Devicetype[3];
gert_lauritsen 9:c8e4339ccc29 88 /** Gives type of HW
gert_lauritsen 9:c8e4339ccc29 89 */
gert_lauritsen 9:c8e4339ccc29 90 char HWType[15];
gert_lauritsen 9:c8e4339ccc29 91 /** incomming data
gert_lauritsen 9:c8e4339ccc29 92 */
gert_lauritsen 9:c8e4339ccc29 93 char Zdata[100];
gert_lauritsen 11:18ff088287ea 94 /**
gert_lauritsen 11:18ff088287ea 95
gert_lauritsen 11:18ff088287ea 96 */
gert_lauritsen 12:debf76f0c0bf 97 uint64_t LocalID;
gert_lauritsen 11:18ff088287ea 98 /**
gert_lauritsen 11:18ff088287ea 99 * indication of incoming data
gert_lauritsen 11:18ff088287ea 100 */
gert_lauritsen 11:18ff088287ea 101 uint8_t Zdat;
gert_lauritsen 11:18ff088287ea 102 /**
gert_lauritsen 11:18ff088287ea 103 * Indicator on that we have got a ack on a packet
gert_lauritsen 11:18ff088287ea 104 */
gert_lauritsen 11:18ff088287ea 105 uint8_t PacketAck;
gert_lauritsen 11:18ff088287ea 106
gert_lauritsen 11:18ff088287ea 107 int channel, NodeID, EPID,framesize, PanOnline;
gert_lauritsen 11:18ff088287ea 108 /**
gert_lauritsen 11:18ff088287ea 109 * Reads all available serial bytes until a packet is parsed, an error occurs, or the buffer is empty.
gert_lauritsen 11:18ff088287ea 110 * You may call <i>xbee</i>.getResponse().isAvailable() after calling this method to determine if
gert_lauritsen 11:18ff088287ea 111 * a packet is ready, or <i>xbee</i>.getResponse().isError() to determine if
gert_lauritsen 11:18ff088287ea 112 * a error occurred.
gert_lauritsen 11:18ff088287ea 113 * <p/>
gert_lauritsen 11:18ff088287ea 114 * This method should always return quickly since it does not wait for serial data to arrive.
gert_lauritsen 11:18ff088287ea 115 * You will want to use this method if you are doing other timely stuff in your loop, where
gert_lauritsen 11:18ff088287ea 116 * a delay would cause problems.
gert_lauritsen 11:18ff088287ea 117 * NOTE: calling this method resets the current response, so make sure you first consume the
gert_lauritsen 11:18ff088287ea 118 * current response
gert_lauritsen 11:18ff088287ea 119 */
gert_lauritsen 11:18ff088287ea 120 void readPacket();
gert_lauritsen 11:18ff088287ea 121 /**Looks for a packet but dont wait
gert_lauritsen 11:18ff088287ea 122 */
gert_lauritsen 12:debf76f0c0bf 123 void SeePacket();
gert_lauritsen 11:18ff088287ea 124
gert_lauritsen 11:18ff088287ea 125
gert_lauritsen 11:18ff088287ea 126 private:
gert_lauritsen 14:dcf2390f89e2 127
gert_lauritsen 14:dcf2390f89e2 128
gert_lauritsen 11:18ff088287ea 129 uint8_t _pos;
gert_lauritsen 11:18ff088287ea 130 // last byte read
gert_lauritsen 11:18ff088287ea 131 uint8_t b;
gert_lauritsen 11:18ff088287ea 132 uint8_t _checksumTotal;
gert_lauritsen 11:18ff088287ea 133 uint8_t _nextFrameId;
gert_lauritsen 11:18ff088287ea 134 int SeqNumber;
gert_lauritsen 12:debf76f0c0bf 135 uint8_t GotFrame; //indicate that a frame has been recieved
gert_lauritsen 11:18ff088287ea 136 // buffer for incoming RX packets. holds only the api specific frame data, starting after the api id byte and prior to checksum
gert_lauritsen 11:18ff088287ea 137 uint8_t _responseFrameData[MAX_FRAME_DATA_SIZE];
gert_lauritsen 11:18ff088287ea 138 char _responseFrameString[MAX_FRAME_DATA_SIZE];
gert_lauritsen 11:18ff088287ea 139
gert_lauritsen 11:18ff088287ea 140 Serial _zbee;
gert_lauritsen 12:debf76f0c0bf 141 bool wait4OK();
gert_lauritsen 11:18ff088287ea 142 };
gert_lauritsen 11:18ff088287ea 143
gert_lauritsen 11:18ff088287ea 144 #endif