mini code pour xbee
Dependencies: mbed ConfigFile EthernetInterface WebSocketClient mbed-rtos
Fork of app4Coordo by
Diff: main.cpp
- Revision:
- 6:2ab1318e2b02
- Parent:
- 5:bf1d3d99cfe9
- Child:
- 7:891d50fe1ee5
diff -r bf1d3d99cfe9 -r 2ab1318e2b02 main.cpp --- a/main.cpp Tue Feb 25 04:35:11 2014 +0000 +++ b/main.cpp Tue Feb 25 15:15:11 2014 +0000 @@ -1,5 +1,6 @@ #include "mbed.h" #include <string> +#include <sstream> #include "ConfigFile.h" #include "EthernetInterface.h" #include "Websocket.h" @@ -18,6 +19,7 @@ char dataBuf[20]; int dataBuf_i; bool trame_ready; +string panID; // Ethernet interface EthernetInterface eth; @@ -46,6 +48,8 @@ */ if (cfg.getValue(key1, &value[0], sizeof(value))) { + std::stringstream panID_s(value); + panID_s >> panID; pc.printf("'%s'='%s'\n\r", key1, value); } @@ -75,6 +79,70 @@ reset = 0; wait_ms(400); reset = 1; + wait(4); + int panID_size; + int panID_array[8]; + int i; + long int panID_d; + panID_size = panID.length(); //vérifie si le panID est pair ou impair + if(panID_size%2 != 0) + { + panID_size++; + panID = "0" + panID; + } + + panID_d = strtol(panID.c_str(),NULL,16); //converti le panID en chiffre + for(i=0;i<panID_size/2;i++) + { + panID_array[i] = panID_d%256; //decoupe en packet de 8 bytes (2 characteres) + panID_d = panID_d >> 8; + + + } + i--; //i est incrémentré une fois de trop dans le for avant de sortir de la boucle + + + //construction des 3 trames pour changer le panID + char size = panID_size/2 + 0x04; //length + 0x04 + char checkSum = 0; + xbee.putc(0x7E); // start delimeter + xbee.putc(0x00); // length + xbee.putc(size); // length + xbee.putc(0x09); // frame type : AT command queue + xbee.putc(0x47); // frame ID + xbee.putc(0x49); //AT command : (ID) + xbee.putc(0x44); //AT command : (ID) + checkSum = checkSum + 0x09 + 0x47 + 0x49 + 0x44; + while(i>=0) + { + pc.printf(" \n\r valeur = %d",panID_array[i]); + xbee.putc(panID_array[i]); + checkSum += panID_array[i]; + i--; + } + checkSum = 0xff - checkSum; + xbee.putc(checkSum); // checksum + pc.printf("\n\r %d %x", checkSum,checkSum); + + xbee.putc(0x7E); // start delimeter + xbee.putc(0x00); // length + xbee.putc(0x04); // length + xbee.putc(0x09); // frame type : AT command queue + xbee.putc(0x49); // frame ID + xbee.putc(0x57); //AT command : (WR) + xbee.putc(0x52); //AT command : (WR) + xbee.putc(0x04); //checksum + + + xbee.putc(0x7E); // start delimeter + xbee.putc(0x00); // length + xbee.putc(0x04); // length + xbee.putc(0x09); // frame type : AT command + xbee.putc(0x4A); // frame ID + xbee.putc(0x41); //AT command : (AC) + xbee.putc(0x43); //AT command : (AC) + xbee.putc(0x28); //checksum + } void xbee_receive()