routeur done
Dependencies: mbed
Fork of APP4 by
Diff: trame.cpp
- Revision:
- 4:aac38b016952
- Parent:
- 3:350f07072089
diff -r 350f07072089 -r aac38b016952 trame.cpp --- a/trame.cpp Mon Feb 24 15:40:33 2014 +0000 +++ b/trame.cpp Mon Feb 24 19:06:11 2014 +0000 @@ -32,8 +32,8 @@ void Trame::sendTransmitRequest(const char* destination, const char* data, int length) { - int tmp = length + 18; - char* trm = new char[tmp]; + int tmp = length + 14; + char* trm = new char[tmp + 4]; trm[0] = 0x7E; // Delimiter trm[1] = static_cast<char>((tmp >> 8) & 0xFF); // MSB de length @@ -42,20 +42,20 @@ trm[4] = 0x01; // API for (int i = 0; i < 8; i++) trm[5 + i] = destination[i]; //Destination - trm[13] = 0x00; // 16 bits address - trm[14] = 0x00; // 16 bits address + trm[13] = 0xFF; // 16 bits address + trm[14] = 0xFE; // 16 bits address trm[15] = 0x00; // Radius trm[16] = 0x00; // Options for (int i = 0; i < length; i++) trm[17 + i] = data[i]; // Data - trm[17 + length] = crc8(trm, tmp - 1); + trm[17 + length] = crc8(trm, tmp+3); Serial xbee(tx, rx); - for (int i = 0; i < tmp; i++) + for (int i = 0; i < tmp+4; i++) xbee.putc(trm[i]); - + wait(0.01); delete trm; } @@ -63,7 +63,7 @@ unsigned char Trame::crc8(const char* data, int length) { unsigned char crc = 0; - for (int i = 1; i < length; i++) + for (int i = 3; i < length; i++) crc += data[i]; return (0xFF - crc);