A libery to connect to telegesis zigbee module. Bassed on implemtation of XBEE
Fork of xbee_lib by
telegesis.h@35:4dec73b3e5a0, 2015-06-01 (annotated)
- Committer:
- gert_lauritsen
- Date:
- Mon Jun 01 20:20:25 2015 +0000
- Revision:
- 35:4dec73b3e5a0
- Parent:
- 34:1b57f1110d59
Just update with interrupt base comm with rtos
Who changed what in which revision?
User | Revision | Line number | New 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" |
gert_lauritsen | 29:6711180763b6 | 5 | #include <RawSerial.h> |
tristanjph | 0:2656fb225c5d | 6 | |
gert_lauritsen | 13:1b557befdeff | 7 | /**Eksemple |
gert_lauritsen | 13:1b557befdeff | 8 | #include "telegesis.h" |
gert_lauritsen | 13:1b557befdeff | 9 | zigbee ZB(p9,p10); |
gert_lauritsen | 13:1b557befdeff | 10 | |
gert_lauritsen | 13:1b557befdeff | 11 | int main() { |
gert_lauritsen | 13:1b557befdeff | 12 | ZB.Reset(); |
gert_lauritsen | 13:1b557befdeff | 13 | wait(1); |
gert_lauritsen | 13:1b557befdeff | 14 | ZB.GetSerial(); |
gert_lauritsen | 13:1b557befdeff | 15 | while(1) { |
gert_lauritsen | 13:1b557befdeff | 16 | ZB.GetSerial(); |
gert_lauritsen | 13:1b557befdeff | 17 | ZB.RecieveData(read_data,0); |
gert_lauritsen | 13:1b557befdeff | 18 | ZB.UniCast("0000","tester forbindelse"); |
gert_lauritsen | 13:1b557befdeff | 19 | if (ZB.Zdat) { |
gert_lauritsen | 13:1b557befdeff | 20 | ZB.Zdat=0; |
gert_lauritsen | 13:1b557befdeff | 21 | printf(ZB.Zdata); |
gert_lauritsen | 13:1b557befdeff | 22 | } |
gert_lauritsen | 13:1b557befdeff | 23 | } |
gert_lauritsen | 13:1b557befdeff | 24 | } |
gert_lauritsen | 13:1b557befdeff | 25 | |
gert_lauritsen | 13:1b557befdeff | 26 | */ |
gert_lauritsen | 7:45511c3d2950 | 27 | /** Zigbee interface class for configuring, sending and recieving data using an telegesis zigbee */ |
gert_lauritsen | 11:18ff088287ea | 28 | #define START_BYTE 0x7e |
gert_lauritsen | 11:18ff088287ea | 29 | #define ESCAPE 0x7d |
gert_lauritsen | 26:2a85af491d92 | 30 | #define MAX_FRAME_DATA_SIZE 90 |
gert_lauritsen | 29:6711180763b6 | 31 | #define ZdataSize 80 |
gert_lauritsen | 31:c59bc92a047e | 32 | //-------------------------------------------------------------------------------------------------------------------- |
gert_lauritsen | 31:c59bc92a047e | 33 | //Typedef.... |
gert_lauritsen | 31:c59bc92a047e | 34 | |
gert_lauritsen | 29:6711180763b6 | 35 | typedef struct { |
gert_lauritsen | 29:6711180763b6 | 36 | char Ready; |
gert_lauritsen | 29:6711180763b6 | 37 | char ID[17]; |
gert_lauritsen | 29:6711180763b6 | 38 | char Data[ZdataSize]; |
gert_lauritsen | 29:6711180763b6 | 39 | }ZdatRec; |
gert_lauritsen | 11:18ff088287ea | 40 | |
gert_lauritsen | 31:c59bc92a047e | 41 | typedef struct { |
gert_lauritsen | 31:c59bc92a047e | 42 | unsigned char channel; |
gert_lauritsen | 31:c59bc92a047e | 43 | char PID[5]; |
gert_lauritsen | 31:c59bc92a047e | 44 | } PanVisibleRec; |
gert_lauritsen | 31:c59bc92a047e | 45 | |
gert_lauritsen | 31:c59bc92a047e | 46 | //-------------------------------------------------------------------------------------------------------------------- |
gert_lauritsen | 31:c59bc92a047e | 47 | |
gert_lauritsen | 31:c59bc92a047e | 48 | |
gert_lauritsen | 7:45511c3d2950 | 49 | class zigbee |
tristanjph | 2:cb627ea9b817 | 50 | { |
tristanjph | 0:2656fb225c5d | 51 | private: |
tristanjph | 0:2656fb225c5d | 52 | PinName _tx; |
tristanjph | 0:2656fb225c5d | 53 | PinName _rx; |
tristanjph | 3:682615a0717e | 54 | PinName _reset; |
gert_lauritsen | 23:8a7329b46e95 | 55 | |
tristanjph | 0:2656fb225c5d | 56 | public: |
gert_lauritsen | 7:45511c3d2950 | 57 | |
gert_lauritsen | 11:18ff088287ea | 58 | zigbee(PinName tx, PinName rx); |
gert_lauritsen | 7:45511c3d2950 | 59 | ~zigbee(); |
gert_lauritsen | 7:45511c3d2950 | 60 | |
gert_lauritsen | 7:45511c3d2950 | 61 | |
gert_lauritsen | 7:45511c3d2950 | 62 | /** Gets the serial number/mac address of the zigbee and places it into serial_no. |
gert_lauritsen | 7:45511c3d2950 | 63 | * @param serial_no array to store the serial of zigbee (must be 8 long). |
tristanjph | 2:cb627ea9b817 | 64 | * @return Returns 1 on success. |
tristanjph | 2:cb627ea9b817 | 65 | */ |
gert_lauritsen | 11:18ff088287ea | 66 | int GetSerial(); |
tristanjph | 6:6455a079bdb3 | 67 | /** Sets the encryption key. This should be a 128-bit key. |
tristanjph | 2:cb627ea9b817 | 68 | * @param key Pointer to the network key to set. |
tristanjph | 2:cb627ea9b817 | 69 | * @return Returns 1 on success. |
tristanjph | 1:c3d9bdcb0b03 | 70 | */ |
gert_lauritsen | 34:1b57f1110d59 | 71 | bool ReadReg(char *Reg); |
gert_lauritsen | 34:1b57f1110d59 | 72 | char RegData[50]; |
tristanjph | 5:714651141a83 | 73 | int SetKey(char*); |
gert_lauritsen | 7:45511c3d2950 | 74 | |
tristanjph | 2:cb627ea9b817 | 75 | /** Recieves data sent to the xbee. |
tristanjph | 2:cb627ea9b817 | 76 | * @param data_buf Pointer to the buffer to put recieved data into. |
tristanjph | 2:cb627ea9b817 | 77 | * @param numchar Number of characters to read. If 0, will use the size of data_buf. |
tristanjph | 2:cb627ea9b817 | 78 | */ |
tristanjph | 2:cb627ea9b817 | 79 | void RecieveData(char*, int); |
gert_lauritsen | 10:263f7251c111 | 80 | /** Get hw version and local ID (64bit uniq number) |
gert_lauritsen | 10:263f7251c111 | 81 | * |
gert_lauritsen | 10:263f7251c111 | 82 | */ |
gert_lauritsen | 7:45511c3d2950 | 83 | int ATI(); |
gert_lauritsen | 10:263f7251c111 | 84 | /** Sends a ping to Coo or any other adresse |
gert_lauritsen | 8:4682155753ec | 85 | * |
gert_lauritsen | 7:45511c3d2950 | 86 | */ |
gert_lauritsen | 34:1b57f1110d59 | 87 | int SetOutputLevel(); |
gert_lauritsen | 7:45511c3d2950 | 88 | int PingOut(); |
gert_lauritsen | 10:263f7251c111 | 89 | /** Scan the Pan for nodes |
gert_lauritsen | 7:45511c3d2950 | 90 | */ |
gert_lauritsen | 7:45511c3d2950 | 91 | int PanScan(); |
gert_lauritsen | 10:263f7251c111 | 92 | /** Make a new network. It then gets the role as coordinator |
gert_lauritsen | 7:45511c3d2950 | 93 | */ |
gert_lauritsen | 7:45511c3d2950 | 94 | int Establish_Network(); |
gert_lauritsen | 10:263f7251c111 | 95 | /** Join a pan |
gert_lauritsen | 7:45511c3d2950 | 96 | */ |
gert_lauritsen | 7:45511c3d2950 | 97 | int JoinNetwork(); |
gert_lauritsen | 20:070dc2050052 | 98 | /** Leave a Pan |
gert_lauritsen | 20:070dc2050052 | 99 | */ |
gert_lauritsen | 20:070dc2050052 | 100 | int LeaveNetwork(); |
gert_lauritsen | 10:263f7251c111 | 101 | /** |
gert_lauritsen | 10:263f7251c111 | 102 | * Scan network |
gert_lauritsen | 7:45511c3d2950 | 103 | */ |
gert_lauritsen | 7:45511c3d2950 | 104 | int ScanNetwork(); |
gert_lauritsen | 10:263f7251c111 | 105 | /** |
gert_lauritsen | 10:263f7251c111 | 106 | *Give info on what role the modem has in the network |
gert_lauritsen | 7:45511c3d2950 | 107 | */ |
gert_lauritsen | 10:263f7251c111 | 108 | |
gert_lauritsen | 7:45511c3d2950 | 109 | int NetworkInfo(); |
gert_lauritsen | 10:263f7251c111 | 110 | /** |
gert_lauritsen | 7:45511c3d2950 | 111 | */ |
gert_lauritsen | 12:debf76f0c0bf | 112 | int Reset(); |
gert_lauritsen | 8:4682155753ec | 113 | /** Sends data using the ascii mode |
gert_lauritsen | 10:263f7251c111 | 114 | */ |
gert_lauritsen | 9:c8e4339ccc29 | 115 | int UniCast(char *adr,char *payload); |
gert_lauritsen | 8:4682155753ec | 116 | /** Sends data using the binary mode |
gert_lauritsen | 8:4682155753ec | 117 | */ |
gert_lauritsen | 9:c8e4339ccc29 | 118 | int UniCastb(char *adr,char *payload, char payloadSize); |
gert_lauritsen | 11:18ff088287ea | 119 | |
gert_lauritsen | 10:263f7251c111 | 120 | |
gert_lauritsen | 9:c8e4339ccc29 | 121 | /** converts a string to a long |
gert_lauritsen | 9:c8e4339ccc29 | 122 | */ |
gert_lauritsen | 11:18ff088287ea | 123 | unsigned long hextolong(const char *hex); |
gert_lauritsen | 8:4682155753ec | 124 | /** convertes a string to a int |
gert_lauritsen | 8:4682155753ec | 125 | */ |
gert_lauritsen | 11:18ff088287ea | 126 | unsigned int hextoint(const char *hex); |
gert_lauritsen | 9:c8e4339ccc29 | 127 | /** |
gert_lauritsen | 9:c8e4339ccc29 | 128 | */ |
gert_lauritsen | 7:45511c3d2950 | 129 | int EUI64; |
gert_lauritsen | 9:c8e4339ccc29 | 130 | /** COO or FBB |
gert_lauritsen | 9:c8e4339ccc29 | 131 | */ |
gert_lauritsen | 20:070dc2050052 | 132 | char Devicetype[4]; |
gert_lauritsen | 9:c8e4339ccc29 | 133 | /** Gives type of HW |
gert_lauritsen | 9:c8e4339ccc29 | 134 | */ |
gert_lauritsen | 31:c59bc92a047e | 135 | int NPanVisible; //antal pans i nærheden |
gert_lauritsen | 31:c59bc92a047e | 136 | PanVisibleRec PanVisible[5]; //Pans og deres ID |
gert_lauritsen | 31:c59bc92a047e | 137 | PanVisibleRec AktuelPan; //Hvilket pan denne er på |
gert_lauritsen | 31:c59bc92a047e | 138 | |
gert_lauritsen | 9:c8e4339ccc29 | 139 | char HWType[15]; |
gert_lauritsen | 9:c8e4339ccc29 | 140 | /** incomming data |
gert_lauritsen | 9:c8e4339ccc29 | 141 | */ |
gert_lauritsen | 29:6711180763b6 | 142 | ZdatRec In; |
gert_lauritsen | 29:6711180763b6 | 143 | //char Zdata[ZdataSize]; |
gert_lauritsen | 11:18ff088287ea | 144 | /** |
gert_lauritsen | 29:6711180763b6 | 145 | |
gert_lauritsen | 11:18ff088287ea | 146 | */ |
gert_lauritsen | 29:6711180763b6 | 147 | void SletZdata(void); |
gert_lauritsen | 18:10fcddf238c9 | 148 | char LocalID[17]; |
gert_lauritsen | 11:18ff088287ea | 149 | /** |
gert_lauritsen | 11:18ff088287ea | 150 | * indication of incoming data |
gert_lauritsen | 11:18ff088287ea | 151 | */ |
gert_lauritsen | 29:6711180763b6 | 152 | //uint8_t Zdat; |
gert_lauritsen | 11:18ff088287ea | 153 | /** |
gert_lauritsen | 11:18ff088287ea | 154 | * Indicator on that we have got a ack on a packet |
gert_lauritsen | 11:18ff088287ea | 155 | */ |
gert_lauritsen | 26:2a85af491d92 | 156 | uint8_t PacketAck; |
gert_lauritsen | 27:a38b67f5be8f | 157 | /*Wait for ok from radio |
gert_lauritsen | 27:a38b67f5be8f | 158 | */ |
gert_lauritsen | 27:a38b67f5be8f | 159 | bool wait4OK(); |
gert_lauritsen | 27:a38b67f5be8f | 160 | |
gert_lauritsen | 11:18ff088287ea | 161 | int channel, NodeID, EPID,framesize, PanOnline; |
gert_lauritsen | 21:9c5b72a64495 | 162 | char NetNodeID[17]; //a remote node |
gert_lauritsen | 21:9c5b72a64495 | 163 | char NetInfo; //indication that network info is ready |
gert_lauritsen | 17:5a3f81b10a61 | 164 | /** |
gert_lauritsen | 17:5a3f81b10a61 | 165 | */ |
gert_lauritsen | 17:5a3f81b10a61 | 166 | uint8_t ErrorCode; |
gert_lauritsen | 11:18ff088287ea | 167 | /** |
gert_lauritsen | 11:18ff088287ea | 168 | * Reads all available serial bytes until a packet is parsed, an error occurs, or the buffer is empty. |
gert_lauritsen | 11:18ff088287ea | 169 | * You may call <i>xbee</i>.getResponse().isAvailable() after calling this method to determine if |
gert_lauritsen | 11:18ff088287ea | 170 | * a packet is ready, or <i>xbee</i>.getResponse().isError() to determine if |
gert_lauritsen | 11:18ff088287ea | 171 | * a error occurred. |
gert_lauritsen | 11:18ff088287ea | 172 | * <p/> |
gert_lauritsen | 11:18ff088287ea | 173 | * This method should always return quickly since it does not wait for serial data to arrive. |
gert_lauritsen | 11:18ff088287ea | 174 | * You will want to use this method if you are doing other timely stuff in your loop, where |
gert_lauritsen | 11:18ff088287ea | 175 | * a delay would cause problems. |
gert_lauritsen | 11:18ff088287ea | 176 | * NOTE: calling this method resets the current response, so make sure you first consume the |
gert_lauritsen | 11:18ff088287ea | 177 | * current response |
gert_lauritsen | 11:18ff088287ea | 178 | */ |
gert_lauritsen | 11:18ff088287ea | 179 | void readPacket(); |
gert_lauritsen | 11:18ff088287ea | 180 | /**Looks for a packet but dont wait |
gert_lauritsen | 11:18ff088287ea | 181 | */ |
gert_lauritsen | 12:debf76f0c0bf | 182 | void SeePacket(); |
gert_lauritsen | 18:10fcddf238c9 | 183 | /** |
gert_lauritsen | 18:10fcddf238c9 | 184 | * Non blocking check og data. To be used in NON IRQ mode |
gert_lauritsen | 18:10fcddf238c9 | 185 | */ |
gert_lauritsen | 26:2a85af491d92 | 186 | bool Work(); |
gert_lauritsen | 19:78f44233a12f | 187 | char _responseFrameString[MAX_FRAME_DATA_SIZE]; |
gert_lauritsen | 24:5ed5311266b0 | 188 | uint8_t GotFrame; //indicate that a frame has been recieved |
gert_lauritsen | 28:c724a8921f01 | 189 | uint8_t Ok; |
gert_lauritsen | 33:101f953225a6 | 190 | int NackNumber; |
gert_lauritsen | 33:101f953225a6 | 191 | char LastDestination[17]; //hvor er der sidst sendt til |
gert_lauritsen | 11:18ff088287ea | 192 | private: |
gert_lauritsen | 11:18ff088287ea | 193 | uint8_t b; |
gert_lauritsen | 33:101f953225a6 | 194 | |
gert_lauritsen | 11:18ff088287ea | 195 | int SeqNumber; |
gert_lauritsen | 30:f9cdb6f62586 | 196 | char tmpstr[30]; |
gert_lauritsen | 11:18ff088287ea | 197 | // 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 | 198 | |
gert_lauritsen | 29:6711180763b6 | 199 | RawSerial _zbee; |
gert_lauritsen | 20:070dc2050052 | 200 | bool wait4Offline(); |
gert_lauritsen | 20:070dc2050052 | 201 | bool wait4JPAN(); |
gert_lauritsen | 20:070dc2050052 | 202 | bool wait4str(char *p); |
gert_lauritsen | 31:c59bc92a047e | 203 | char *list[30]; |
gert_lauritsen | 30:f9cdb6f62586 | 204 | size_t comma_parse ( char *line, char *list[], size_t size ); |
gert_lauritsen | 11:18ff088287ea | 205 | }; |
gert_lauritsen | 11:18ff088287ea | 206 | |
gert_lauritsen | 11:18ff088287ea | 207 | #endif |