A libery to connect to telegesis zigbee module. Bassed on implemtation of XBEE
Fork of xbee_lib by
telegesis.cpp@24:5ed5311266b0, 2013-11-12 (annotated)
- Committer:
- gert_lauritsen
- Date:
- Tue Nov 12 09:19:52 2013 +0000
- Revision:
- 24:5ed5311266b0
- Parent:
- 23:8a7329b46e95
- Child:
- 25:31120552e53c
latest update
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gert_lauritsen | 7:45511c3d2950 | 1 | #include "telegesis.h" |
gert_lauritsen | 14:dcf2390f89e2 | 2 | #define CR 0x0D |
gert_lauritsen | 14:dcf2390f89e2 | 3 | #define LF 0x0A |
gert_lauritsen | 18:10fcddf238c9 | 4 | //#define IRQCtrl |
tristanjph | 0:2656fb225c5d | 5 | |
gert_lauritsen | 18:10fcddf238c9 | 6 | zigbee::zigbee(PinName tx, PinName rx): _zbee(tx, rx) |
gert_lauritsen | 18:10fcddf238c9 | 7 | { |
tristanjph | 0:2656fb225c5d | 8 | _tx = tx; |
tristanjph | 0:2656fb225c5d | 9 | _rx = rx; |
gert_lauritsen | 18:10fcddf238c9 | 10 | _zbee.baud(19200); |
gert_lauritsen | 18:10fcddf238c9 | 11 | #ifdef IRQCtrl |
gert_lauritsen | 18:10fcddf238c9 | 12 | _zbee.attach(this, &zigbee::SeePacket, Serial::RxIrq); |
gert_lauritsen | 18:10fcddf238c9 | 13 | #endif |
tristanjph | 0:2656fb225c5d | 14 | } |
tristanjph | 0:2656fb225c5d | 15 | |
gert_lauritsen | 7:45511c3d2950 | 16 | zigbee::~zigbee() |
tristanjph | 0:2656fb225c5d | 17 | { |
tristanjph | 0:2656fb225c5d | 18 | } |
tristanjph | 0:2656fb225c5d | 19 | |
gert_lauritsen | 18:10fcddf238c9 | 20 | void zigbee::Work() { |
gert_lauritsen | 24:5ed5311266b0 | 21 | //read and waits for the packet |
gert_lauritsen | 24:5ed5311266b0 | 22 | Timer t; |
gert_lauritsen | 24:5ed5311266b0 | 23 | t.reset(); |
gert_lauritsen | 24:5ed5311266b0 | 24 | t.start(); |
gert_lauritsen | 24:5ed5311266b0 | 25 | b=0; |
gert_lauritsen | 24:5ed5311266b0 | 26 | while((b!=CR) & (t.read_ms() < 1000)) |
gert_lauritsen | 24:5ed5311266b0 | 27 | if (_zbee.readable()) SeePacket(); |
gert_lauritsen | 24:5ed5311266b0 | 28 | t.stop(); |
gert_lauritsen | 24:5ed5311266b0 | 29 | //if (_zbee.readable()) readPacket(); |
gert_lauritsen | 18:10fcddf238c9 | 30 | } |
gert_lauritsen | 18:10fcddf238c9 | 31 | |
gert_lauritsen | 20:070dc2050052 | 32 | bool zigbee::wait4str(char *p) //joinpan |
gert_lauritsen | 20:070dc2050052 | 33 | { |
gert_lauritsen | 20:070dc2050052 | 34 | Timer t; |
gert_lauritsen | 20:070dc2050052 | 35 | t.reset(); |
gert_lauritsen | 20:070dc2050052 | 36 | t.start(); |
gert_lauritsen | 20:070dc2050052 | 37 | while ((strstr(_responseFrameString,p)==0) & (t.read_ms() < 5000)) readPacket(); |
gert_lauritsen | 20:070dc2050052 | 38 | t.stop(); |
gert_lauritsen | 20:070dc2050052 | 39 | return (strstr(_responseFrameString,p)>0); |
gert_lauritsen | 20:070dc2050052 | 40 | } |
gert_lauritsen | 20:070dc2050052 | 41 | |
gert_lauritsen | 20:070dc2050052 | 42 | |
gert_lauritsen | 20:070dc2050052 | 43 | bool zigbee::wait4JPAN() //joinpan |
gert_lauritsen | 20:070dc2050052 | 44 | { |
gert_lauritsen | 20:070dc2050052 | 45 | Timer t; |
gert_lauritsen | 20:070dc2050052 | 46 | t.reset(); |
gert_lauritsen | 20:070dc2050052 | 47 | t.start(); |
gert_lauritsen | 20:070dc2050052 | 48 | readPacket(); |
gert_lauritsen | 20:070dc2050052 | 49 | while ((strstr(_responseFrameString,"JPAN")==0) & (t.read_ms() < 5000)) readPacket(); |
gert_lauritsen | 20:070dc2050052 | 50 | t.stop(); |
gert_lauritsen | 20:070dc2050052 | 51 | return (strstr(_responseFrameString,"JPAN")>0); |
gert_lauritsen | 20:070dc2050052 | 52 | } |
gert_lauritsen | 20:070dc2050052 | 53 | |
gert_lauritsen | 20:070dc2050052 | 54 | |
gert_lauritsen | 20:070dc2050052 | 55 | bool zigbee::wait4Offline() |
gert_lauritsen | 20:070dc2050052 | 56 | { |
gert_lauritsen | 20:070dc2050052 | 57 | Timer t; |
gert_lauritsen | 20:070dc2050052 | 58 | t.reset(); |
gert_lauritsen | 20:070dc2050052 | 59 | t.start(); |
gert_lauritsen | 20:070dc2050052 | 60 | readPacket(); |
gert_lauritsen | 20:070dc2050052 | 61 | while ((PanOnline>0) & (t.read_ms() < 3000)) readPacket(); |
gert_lauritsen | 20:070dc2050052 | 62 | t.stop(); |
gert_lauritsen | 20:070dc2050052 | 63 | return PanOnline; |
gert_lauritsen | 20:070dc2050052 | 64 | } |
gert_lauritsen | 20:070dc2050052 | 65 | |
gert_lauritsen | 20:070dc2050052 | 66 | |
gert_lauritsen | 18:10fcddf238c9 | 67 | bool zigbee::wait4OK() |
gert_lauritsen | 18:10fcddf238c9 | 68 | { |
gert_lauritsen | 12:debf76f0c0bf | 69 | Timer t; |
gert_lauritsen | 12:debf76f0c0bf | 70 | t.reset(); |
gert_lauritsen | 18:10fcddf238c9 | 71 | t.start(); |
gert_lauritsen | 11:18ff088287ea | 72 | readPacket(); |
gert_lauritsen | 18:10fcddf238c9 | 73 | while ((strstr(_responseFrameString,"OK")==0) & (t.read_ms() < 500)) readPacket(); |
gert_lauritsen | 20:070dc2050052 | 74 | t.stop(); |
gert_lauritsen | 20:070dc2050052 | 75 | return (strstr(_responseFrameString,"OK")>0); |
gert_lauritsen | 11:18ff088287ea | 76 | } |
tristanjph | 0:2656fb225c5d | 77 | |
gert_lauritsen | 11:18ff088287ea | 78 | int zigbee::GetSerial() |
gert_lauritsen | 18:10fcddf238c9 | 79 | { |
gert_lauritsen | 11:18ff088287ea | 80 | /** comes with something like this |
gert_lauritsen | 18:10fcddf238c9 | 81 | Telegesis ETRX357-LRS |
gert_lauritsen | 18:10fcddf238c9 | 82 | R305C |
gert_lauritsen | 18:10fcddf238c9 | 83 | 000D6F0000D5F06A |
gert_lauritsen | 18:10fcddf238c9 | 84 | OK |
gert_lauritsen | 18:10fcddf238c9 | 85 | */ |
gert_lauritsen | 11:18ff088287ea | 86 | _zbee.printf("ATI\r"); |
gert_lauritsen | 22:e8a8edf8b45c | 87 | wait4str("Telegesis"); |
gert_lauritsen | 11:18ff088287ea | 88 | sscanf(_responseFrameString,"Telegesis %s",HWType); |
gert_lauritsen | 18:10fcddf238c9 | 89 | readPacket(); |
gert_lauritsen | 18:10fcddf238c9 | 90 | readPacket(); |
gert_lauritsen | 18:10fcddf238c9 | 91 | strcpy(LocalID,_responseFrameString); //vi lægger den bare over i stringformat. Så kan man altid senere convertere |
gert_lauritsen | 20:070dc2050052 | 92 | wait4OK(); |
gert_lauritsen | 18:10fcddf238c9 | 93 | // LocalID=hextoint(_responseFrameString); |
gert_lauritsen | 18:10fcddf238c9 | 94 | // wait_ms(5); |
tristanjph | 0:2656fb225c5d | 95 | return 1; |
tristanjph | 0:2656fb225c5d | 96 | } |
tristanjph | 0:2656fb225c5d | 97 | |
gert_lauritsen | 18:10fcddf238c9 | 98 | int zigbee::SetKey(char* key) |
gert_lauritsen | 18:10fcddf238c9 | 99 | { |
gert_lauritsen | 18:10fcddf238c9 | 100 | /** |
gert_lauritsen | 18:10fcddf238c9 | 101 | S09: the link key. Write the same 128-bit number (32 hexadecimal characters) into every device |
gert_lauritsen | 15:8d4990362a80 | 102 | |
gert_lauritsen | 18:10fcddf238c9 | 103 | S0A: security configuration. You must set bit 4 in the coordinator, and set bit 8 in all other devices. |
gert_lauritsen | 18:10fcddf238c9 | 104 | For more security set bit 2 also in the coordinator. The devices ignore the bits that are not relevant |
gert_lauritsen | 18:10fcddf238c9 | 105 | for them, so it is easiest to just set bits 8, 4, and 2 in all devices which gives S0A=0114. |
gert_lauritsen | 18:10fcddf238c9 | 106 | */ |
gert_lauritsen | 18:10fcddf238c9 | 107 | char psw[50]; |
gert_lauritsen | 15:8d4990362a80 | 108 | sprintf(psw,"ATS09=%s;password\r",key); |
gert_lauritsen | 15:8d4990362a80 | 109 | _zbee.printf(psw); |
gert_lauritsen | 18:10fcddf238c9 | 110 | wait4OK(); |
gert_lauritsen | 15:8d4990362a80 | 111 | _zbee.printf("ATS0A=0114;password\r"); |
tristanjph | 0:2656fb225c5d | 112 | return 1; |
tristanjph | 0:2656fb225c5d | 113 | } |
tristanjph | 0:2656fb225c5d | 114 | |
tristanjph | 0:2656fb225c5d | 115 | |
tristanjph | 0:2656fb225c5d | 116 | |
gert_lauritsen | 7:45511c3d2950 | 117 | void zigbee::RecieveData(char *data_buf, int numchar) |
tristanjph | 1:c3d9bdcb0b03 | 118 | { |
tristanjph | 1:c3d9bdcb0b03 | 119 | int count=0; |
tristanjph | 2:cb627ea9b817 | 120 | if(numchar == 0) { |
tristanjph | 2:cb627ea9b817 | 121 | numchar = sizeof(data_buf); |
tristanjph | 2:cb627ea9b817 | 122 | } |
gert_lauritsen | 18:10fcddf238c9 | 123 | |
tristanjph | 1:c3d9bdcb0b03 | 124 | while(numchar!=count) { |
gert_lauritsen | 11:18ff088287ea | 125 | if(_zbee.readable()) { |
gert_lauritsen | 11:18ff088287ea | 126 | *data_buf = _zbee.getc(); |
tristanjph | 3:682615a0717e | 127 | data_buf+=1; |
tristanjph | 3:682615a0717e | 128 | count++; |
tristanjph | 1:c3d9bdcb0b03 | 129 | } |
tristanjph | 1:c3d9bdcb0b03 | 130 | |
tristanjph | 1:c3d9bdcb0b03 | 131 | } |
tristanjph | 2:cb627ea9b817 | 132 | } |
tristanjph | 1:c3d9bdcb0b03 | 133 | |
gert_lauritsen | 12:debf76f0c0bf | 134 | int zigbee::Reset() |
gert_lauritsen | 12:debf76f0c0bf | 135 | { |
gert_lauritsen | 12:debf76f0c0bf | 136 | _zbee.printf("ATZ\r"); |
gert_lauritsen | 12:debf76f0c0bf | 137 | wait4OK(); |
gert_lauritsen | 12:debf76f0c0bf | 138 | return 1; |
gert_lauritsen | 12:debf76f0c0bf | 139 | } |
gert_lauritsen | 12:debf76f0c0bf | 140 | |
gert_lauritsen | 7:45511c3d2950 | 141 | int zigbee::ATI() |
gert_lauritsen | 7:45511c3d2950 | 142 | { |
gert_lauritsen | 12:debf76f0c0bf | 143 | GetSerial(); |
gert_lauritsen | 7:45511c3d2950 | 144 | return 1; |
gert_lauritsen | 7:45511c3d2950 | 145 | } |
gert_lauritsen | 7:45511c3d2950 | 146 | |
gert_lauritsen | 7:45511c3d2950 | 147 | |
gert_lauritsen | 7:45511c3d2950 | 148 | int zigbee::PingOut() |
gert_lauritsen | 18:10fcddf238c9 | 149 | { |
gert_lauritsen | 18:10fcddf238c9 | 150 | //just return a OK (sends it ID out out the pan) |
gert_lauritsen | 11:18ff088287ea | 151 | _zbee.printf("AT+ANNCE\r"); |
gert_lauritsen | 12:debf76f0c0bf | 152 | wait4OK(); |
gert_lauritsen | 7:45511c3d2950 | 153 | return 1; |
gert_lauritsen | 7:45511c3d2950 | 154 | } |
gert_lauritsen | 7:45511c3d2950 | 155 | |
gert_lauritsen | 7:45511c3d2950 | 156 | |
gert_lauritsen | 7:45511c3d2950 | 157 | int zigbee::PanScan() |
gert_lauritsen | 18:10fcddf238c9 | 158 | { |
gert_lauritsen | 18:10fcddf238c9 | 159 | // |
gert_lauritsen | 11:18ff088287ea | 160 | _zbee.printf("AT+PANSCAN\r"); |
gert_lauritsen | 7:45511c3d2950 | 161 | return 1; |
gert_lauritsen | 7:45511c3d2950 | 162 | } |
gert_lauritsen | 7:45511c3d2950 | 163 | |
gert_lauritsen | 7:45511c3d2950 | 164 | |
gert_lauritsen | 7:45511c3d2950 | 165 | int zigbee::Establish_Network() |
gert_lauritsen | 18:10fcddf238c9 | 166 | { |
gert_lauritsen | 18:10fcddf238c9 | 167 | // |
gert_lauritsen | 11:18ff088287ea | 168 | _zbee.printf("AT+EN\r"); |
gert_lauritsen | 20:070dc2050052 | 169 | wait4JPAN(); |
gert_lauritsen | 20:070dc2050052 | 170 | wait4OK(); |
tristanjph | 2:cb627ea9b817 | 171 | return 1; |
tristanjph | 2:cb627ea9b817 | 172 | } |
tristanjph | 3:682615a0717e | 173 | |
gert_lauritsen | 7:45511c3d2950 | 174 | |
gert_lauritsen | 20:070dc2050052 | 175 | int zigbee::LeaveNetwork() |
gert_lauritsen | 20:070dc2050052 | 176 | { |
gert_lauritsen | 20:070dc2050052 | 177 | _zbee.printf("AT+DASSL\r"); |
gert_lauritsen | 20:070dc2050052 | 178 | wait4OK(); |
gert_lauritsen | 20:070dc2050052 | 179 | wait4Offline(); |
gert_lauritsen | 20:070dc2050052 | 180 | return 1; |
gert_lauritsen | 20:070dc2050052 | 181 | } |
gert_lauritsen | 20:070dc2050052 | 182 | |
gert_lauritsen | 7:45511c3d2950 | 183 | int zigbee::JoinNetwork() |
gert_lauritsen | 7:45511c3d2950 | 184 | { |
gert_lauritsen | 11:18ff088287ea | 185 | _zbee.printf("AT+JN\r"); |
gert_lauritsen | 7:45511c3d2950 | 186 | return 1; |
gert_lauritsen | 7:45511c3d2950 | 187 | } |
gert_lauritsen | 7:45511c3d2950 | 188 | |
gert_lauritsen | 7:45511c3d2950 | 189 | int zigbee::ScanNetwork() |
gert_lauritsen | 7:45511c3d2950 | 190 | { |
gert_lauritsen | 11:18ff088287ea | 191 | _zbee.printf("AT+SN\r"); |
gert_lauritsen | 7:45511c3d2950 | 192 | return 1; |
gert_lauritsen | 7:45511c3d2950 | 193 | } |
gert_lauritsen | 7:45511c3d2950 | 194 | |
gert_lauritsen | 7:45511c3d2950 | 195 | int zigbee::NetworkInfo() |
gert_lauritsen | 7:45511c3d2950 | 196 | { |
gert_lauritsen | 7:45511c3d2950 | 197 | //Return something like this "+N=COO,12,-11,29F0,55C0E0DCE605C522" |
gert_lauritsen | 11:18ff088287ea | 198 | _zbee.printf("AT+N\r"); |
gert_lauritsen | 20:070dc2050052 | 199 | wait4OK(); |
gert_lauritsen | 7:45511c3d2950 | 200 | return 1; |
gert_lauritsen | 7:45511c3d2950 | 201 | } |
gert_lauritsen | 7:45511c3d2950 | 202 | |
gert_lauritsen | 9:c8e4339ccc29 | 203 | int zigbee::UniCast(char *adr,char *payload) //Ascii mode with null terminated string |
gert_lauritsen | 7:45511c3d2950 | 204 | { |
gert_lauritsen | 11:18ff088287ea | 205 | _zbee.printf("AT+UCAST:%s=%s\r",adr,payload); |
gert_lauritsen | 21:9c5b72a64495 | 206 | // printf("AT+UCAST:%s=%s\r",adr,payload); |
gert_lauritsen | 12:debf76f0c0bf | 207 | // _zbee.scanf ("UCAST:%X,%X=%s ",&EUI64,&framesize,Zdata); |
gert_lauritsen | 7:45511c3d2950 | 208 | return 1; |
gert_lauritsen | 7:45511c3d2950 | 209 | } |
gert_lauritsen | 7:45511c3d2950 | 210 | |
gert_lauritsen | 9:c8e4339ccc29 | 211 | int zigbee::UniCastb(char *adr,char *payload, char payloadSize) //sends data in binary format |
gert_lauritsen | 7:45511c3d2950 | 212 | { |
gert_lauritsen | 11:18ff088287ea | 213 | _zbee.printf("AT+UCASTB:%X,%s\r",adr,payloadSize); |
gert_lauritsen | 12:debf76f0c0bf | 214 | //_zbee.scanf ("%*s"); |
gert_lauritsen | 7:45511c3d2950 | 215 | return 1; |
gert_lauritsen | 7:45511c3d2950 | 216 | } |
gert_lauritsen | 7:45511c3d2950 | 217 | |
gert_lauritsen | 12:debf76f0c0bf | 218 | //-----------------------Handle incoming data------------------------------ |
tristanjph | 3:682615a0717e | 219 | |
gert_lauritsen | 11:18ff088287ea | 220 | unsigned long zigbee::hextolong(const char *hex) |
gert_lauritsen | 7:45511c3d2950 | 221 | { |
gert_lauritsen | 7:45511c3d2950 | 222 | //return 32 bit |
gert_lauritsen | 7:45511c3d2950 | 223 | unsigned long result = 0; |
gert_lauritsen | 7:45511c3d2950 | 224 | while (*hex) { //så længe det ikke er null |
gert_lauritsen | 7:45511c3d2950 | 225 | if (*hex >= '0' && *hex <= '9') |
gert_lauritsen | 7:45511c3d2950 | 226 | result += (*hex - '0'); |
gert_lauritsen | 7:45511c3d2950 | 227 | else if (*hex >= 'A' && *hex <= 'F') |
gert_lauritsen | 7:45511c3d2950 | 228 | result += (*hex - 'A' +10); |
gert_lauritsen | 7:45511c3d2950 | 229 | else if (*hex >= 'a' && *hex <= 'f') |
gert_lauritsen | 7:45511c3d2950 | 230 | result += (*hex - 'a'+ 10); |
gert_lauritsen | 7:45511c3d2950 | 231 | |
gert_lauritsen | 12:debf76f0c0bf | 232 | if (*++hex) //if the neext isn't a null |
gert_lauritsen | 7:45511c3d2950 | 233 | result <<= 4; |
gert_lauritsen | 7:45511c3d2950 | 234 | } |
gert_lauritsen | 7:45511c3d2950 | 235 | return result; |
gert_lauritsen | 7:45511c3d2950 | 236 | } |
gert_lauritsen | 7:45511c3d2950 | 237 | |
gert_lauritsen | 7:45511c3d2950 | 238 | |
gert_lauritsen | 11:18ff088287ea | 239 | unsigned int zigbee::hextoint(const char *hex) |
gert_lauritsen | 7:45511c3d2950 | 240 | { |
gert_lauritsen | 7:45511c3d2950 | 241 | //return 16 bit |
gert_lauritsen | 7:45511c3d2950 | 242 | unsigned int result = 0; |
gert_lauritsen | 7:45511c3d2950 | 243 | while (*hex) { //så længe det ikke er null |
gert_lauritsen | 7:45511c3d2950 | 244 | if (*hex >= '0' && *hex <= '9') |
gert_lauritsen | 7:45511c3d2950 | 245 | result += (*hex - '0'); |
gert_lauritsen | 7:45511c3d2950 | 246 | else if (*hex >= 'A' && *hex <= 'F') |
gert_lauritsen | 7:45511c3d2950 | 247 | result += (*hex - 'A' +10); |
gert_lauritsen | 7:45511c3d2950 | 248 | else if (*hex >= 'a' && *hex <= 'f') |
gert_lauritsen | 7:45511c3d2950 | 249 | result += (*hex - 'a'+ 10); |
gert_lauritsen | 7:45511c3d2950 | 250 | |
gert_lauritsen | 12:debf76f0c0bf | 251 | if (*++hex) //if the neext isn't a null |
gert_lauritsen | 7:45511c3d2950 | 252 | result <<= 4; |
gert_lauritsen | 7:45511c3d2950 | 253 | } |
gert_lauritsen | 7:45511c3d2950 | 254 | return result; |
gert_lauritsen | 7:45511c3d2950 | 255 | } |
gert_lauritsen | 7:45511c3d2950 | 256 | //--------------------------------------------------------------- |
gert_lauritsen | 18:10fcddf238c9 | 257 | #ifdef IRQCtrl |
gert_lauritsen | 18:10fcddf238c9 | 258 | void zigbee::readPacket() |
gert_lauritsen | 18:10fcddf238c9 | 259 | { |
gert_lauritsen | 11:18ff088287ea | 260 | //read and waits for the packet |
gert_lauritsen | 12:debf76f0c0bf | 261 | Timer t; |
gert_lauritsen | 12:debf76f0c0bf | 262 | t.reset(); |
gert_lauritsen | 18:10fcddf238c9 | 263 | t.start(); |
gert_lauritsen | 18:10fcddf238c9 | 264 | while ((GotFrame==0) & (t.read_ms() < 500)) {} |
gert_lauritsen | 18:10fcddf238c9 | 265 | t.stop(); |
gert_lauritsen | 18:10fcddf238c9 | 266 | GotFrame=0; |
gert_lauritsen | 18:10fcddf238c9 | 267 | } |
gert_lauritsen | 7:45511c3d2950 | 268 | |
gert_lauritsen | 18:10fcddf238c9 | 269 | #endif |
gert_lauritsen | 11:18ff088287ea | 270 | |
gert_lauritsen | 18:10fcddf238c9 | 271 | void zigbee::SeePacket() |
gert_lauritsen | 18:10fcddf238c9 | 272 | { |
gert_lauritsen | 18:10fcddf238c9 | 273 | char *p; |
gert_lauritsen | 18:10fcddf238c9 | 274 | static uint8_t _pos; |
gert_lauritsen | 12:debf76f0c0bf | 275 | b = _zbee.getc(); |
gert_lauritsen | 20:070dc2050052 | 276 | if ((b!=CR) & (b!=LF)) { |
gert_lauritsen | 20:070dc2050052 | 277 | _responseFrameString[_pos]=b; |
gert_lauritsen | 20:070dc2050052 | 278 | _pos=(_pos+1) % MAX_FRAME_DATA_SIZE; |
gert_lauritsen | 20:070dc2050052 | 279 | } |
gert_lauritsen | 12:debf76f0c0bf | 280 | if (b==CR) { |
gert_lauritsen | 18:10fcddf238c9 | 281 | // memcpy(&_responseFrameString,&_responseFrameData,_pos); |
gert_lauritsen | 18:10fcddf238c9 | 282 | GotFrame=1; |
gert_lauritsen | 18:10fcddf238c9 | 283 | _responseFrameString[_pos]=0; //Nul terminate |
gert_lauritsen | 18:10fcddf238c9 | 284 | _pos=0; |
gert_lauritsen | 23:8a7329b46e95 | 285 | // printf(_responseFrameString); |
gert_lauritsen | 18:10fcddf238c9 | 286 | if (strstr(_responseFrameString,"+UCAST:")) { //returns on that we have sendt something |
gert_lauritsen | 18:10fcddf238c9 | 287 | //Do something |
gert_lauritsen | 18:10fcddf238c9 | 288 | } else if (strstr(_responseFrameString,"UCAST:")) { //checke for incoming UCAST data |
gert_lauritsen | 18:10fcddf238c9 | 289 | //if (sscanf (_responseFrameString,"UCAST:%X,%X=%s ",&EUI64,&framesize,Zdata)>0) |
gert_lauritsen | 21:9c5b72a64495 | 290 | p=strstr(_responseFrameString,"UCAST:"); |
gert_lauritsen | 21:9c5b72a64495 | 291 | p=p+6; |
gert_lauritsen | 21:9c5b72a64495 | 292 | strncpy(NetNodeID,p,16); |
gert_lauritsen | 21:9c5b72a64495 | 293 | NetNodeID[16]=0; |
gert_lauritsen | 21:9c5b72a64495 | 294 | Zdat=1; |
gert_lauritsen | 18:10fcddf238c9 | 295 | p=strstr(_responseFrameString,"="); |
gert_lauritsen | 18:10fcddf238c9 | 296 | if (p) { |
gert_lauritsen | 18:10fcddf238c9 | 297 | p++; |
gert_lauritsen | 18:10fcddf238c9 | 298 | strcpy(Zdata,p); |
gert_lauritsen | 18:10fcddf238c9 | 299 | Zdat=1; |
gert_lauritsen | 18:10fcddf238c9 | 300 | } |
gert_lauritsen | 18:10fcddf238c9 | 301 | } |
gert_lauritsen | 18:10fcddf238c9 | 302 | if (strstr(_responseFrameString,"LeftPAN:")) PanOnline=0; //Local node has left the Pan |
gert_lauritsen | 18:10fcddf238c9 | 303 | if (strstr(_responseFrameString,"LostPAN:")) PanOnline=0; //Local node has left the Pan |
gert_lauritsen | 18:10fcddf238c9 | 304 | if (strstr(_responseFrameString,"ERROR:")) { |
gert_lauritsen | 18:10fcddf238c9 | 305 | p=strstr(_responseFrameString,":"); |
gert_lauritsen | 18:10fcddf238c9 | 306 | p++; //P indholder nu SEQ nummer |
gert_lauritsen | 17:5a3f81b10a61 | 307 | ErrorCode=hextoint(p); |
gert_lauritsen | 18:10fcddf238c9 | 308 | } |
gert_lauritsen | 18:10fcddf238c9 | 309 | |
gert_lauritsen | 18:10fcddf238c9 | 310 | if (strstr(_responseFrameString,"NEWNODE:")) { //NEWNODE: <NodeID>,<EUI64>,<Parent NodeID> |
gert_lauritsen | 18:10fcddf238c9 | 311 | //new node on the pan |
gert_lauritsen | 20:070dc2050052 | 312 | p=strstr(_responseFrameString,"NEWNODE:"); |
gert_lauritsen | 21:9c5b72a64495 | 313 | p=p+13; NetInfo=1; |
gert_lauritsen | 20:070dc2050052 | 314 | strncpy(NetNodeID,p,16); |
gert_lauritsen | 18:10fcddf238c9 | 315 | } |
gert_lauritsen | 11:18ff088287ea | 316 | |
gert_lauritsen | 18:10fcddf238c9 | 317 | if ((strstr(_responseFrameString,"OK")>0) & (strstr(_responseFrameString,"TOKDUMP")==0) ) { |
gert_lauritsen | 18:10fcddf238c9 | 318 | //if (ScriptState) ConnectScript(); |
gert_lauritsen | 18:10fcddf238c9 | 319 | //Ok=1; Cmd=0; LineNo=0; |
gert_lauritsen | 18:10fcddf238c9 | 320 | } |
gert_lauritsen | 20:070dc2050052 | 321 | if (strstr(_responseFrameString,"FFD:")) { |
gert_lauritsen | 20:070dc2050052 | 322 | //FFD:000D6F00026C5BEA,0000 |
gert_lauritsen | 20:070dc2050052 | 323 | p=strstr(_responseFrameString,"FFD:"); |
gert_lauritsen | 20:070dc2050052 | 324 | p=p+4; NetInfo=1; |
gert_lauritsen | 20:070dc2050052 | 325 | strncpy(NetNodeID,p,16); |
gert_lauritsen | 20:070dc2050052 | 326 | } |
gert_lauritsen | 18:10fcddf238c9 | 327 | if (strstr(_responseFrameString,"+N=")) { |
gert_lauritsen | 20:070dc2050052 | 328 | // sscanf (_responseFrameString,"+N=%s,%d,%d,%4X,",Devicetype,&channel,&NodeID,&EPID); |
gert_lauritsen | 20:070dc2050052 | 329 | p=strstr(_responseFrameString,"+N="); |
gert_lauritsen | 20:070dc2050052 | 330 | p=p+3; |
gert_lauritsen | 20:070dc2050052 | 331 | strncpy(Devicetype,p,3); |
gert_lauritsen | 20:070dc2050052 | 332 | Devicetype[3]=0; //null termination |
gert_lauritsen | 18:10fcddf238c9 | 333 | } |
gert_lauritsen | 18:10fcddf238c9 | 334 | if (strstr(_responseFrameString,"ACK")) { // |
gert_lauritsen | 24:5ed5311266b0 | 335 | //PacketAck=1; |
gert_lauritsen | 18:10fcddf238c9 | 336 | p=strstr(_responseFrameString,":"); |
gert_lauritsen | 18:10fcddf238c9 | 337 | p++; //P indholder nu SEQ nummer |
gert_lauritsen | 12:debf76f0c0bf | 338 | SeqNumber=hextoint(p); |
gert_lauritsen | 18:10fcddf238c9 | 339 | } |
gert_lauritsen | 18:10fcddf238c9 | 340 | if (strstr(_responseFrameString,"NAK")) { |
gert_lauritsen | 18:10fcddf238c9 | 341 | PacketAck=0; |
gert_lauritsen | 18:10fcddf238c9 | 342 | p=strstr(_responseFrameString,":"); |
gert_lauritsen | 18:10fcddf238c9 | 343 | p++; //P indholder nu SEQ nummer |
gert_lauritsen | 18:10fcddf238c9 | 344 | SeqNumber=hextoint(p); |
gert_lauritsen | 18:10fcddf238c9 | 345 | } |
gert_lauritsen | 18:10fcddf238c9 | 346 | if (strstr(_responseFrameString,"SEQ")) { // |
gert_lauritsen | 18:10fcddf238c9 | 347 | PacketAck=1; |
gert_lauritsen | 18:10fcddf238c9 | 348 | p=strstr(_responseFrameString,":"); |
gert_lauritsen | 18:10fcddf238c9 | 349 | p++; //P indholder nu SEQ nummer |
gert_lauritsen | 12:debf76f0c0bf | 350 | SeqNumber=hextoint(p); |
gert_lauritsen | 18:10fcddf238c9 | 351 | } |
gert_lauritsen | 18:10fcddf238c9 | 352 | } |
gert_lauritsen | 11:18ff088287ea | 353 | } |
gert_lauritsen | 18:10fcddf238c9 | 354 | |
gert_lauritsen | 18:10fcddf238c9 | 355 | //-----------------------NON IRQ mode -------------------------------------------------------------------- |
gert_lauritsen | 18:10fcddf238c9 | 356 | #ifndef IRQCtrl |
gert_lauritsen | 18:10fcddf238c9 | 357 | void zigbee::readPacket() |
gert_lauritsen | 18:10fcddf238c9 | 358 | { |
gert_lauritsen | 18:10fcddf238c9 | 359 | //read and waits for the packet |
gert_lauritsen | 19:78f44233a12f | 360 | Timer t; |
gert_lauritsen | 19:78f44233a12f | 361 | t.reset(); |
gert_lauritsen | 19:78f44233a12f | 362 | t.start(); |
gert_lauritsen | 19:78f44233a12f | 363 | b=0; |
gert_lauritsen | 19:78f44233a12f | 364 | while((b!=CR) & (t.read_ms() < 1000)) |
gert_lauritsen | 18:10fcddf238c9 | 365 | if (_zbee.readable()) SeePacket(); |
gert_lauritsen | 19:78f44233a12f | 366 | t.stop(); |
gert_lauritsen | 18:10fcddf238c9 | 367 | } |
gert_lauritsen | 18:10fcddf238c9 | 368 | |
gert_lauritsen | 20:070dc2050052 | 369 | #endif |