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:
22:e8a8edf8b45c
update og debug

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