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

Fork of xbee_lib by Tristan Hughes

Committer:
gert_lauritsen
Date:
Sun Oct 20 20:22:19 2013 +0000
Revision:
22:e8a8edf8b45c
Parent:
21:9c5b72a64495
Child:
23:8a7329b46e95
Sidste tilretninger

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