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

Fork of xbee_lib by Tristan Hughes

Committer:
gert_lauritsen
Date:
Thu Jun 05 17:10:37 2014 +0000
Revision:
29:6711180763b6
Parent:
28:c724a8921f01
Child:
30:f9cdb6f62586
?ndret til rawseriel

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