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 Jan 10 16:30:36 2014 +0000
Revision:
27:a38b67f5be8f
Parent:
26:2a85af491d92
Child:
28:c724a8921f01
working

Who changed what in which revision?

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