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

Fork of xbee_lib by Tristan Hughes

Committer:
gert_lauritsen
Date:
Sat Oct 19 22:06:53 2013 +0000
Revision:
21:9c5b72a64495
Parent:
20:070dc2050052
Child:
23:8a7329b46e95
update og debug

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