Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed PowerControl
Fork of Projet_S5 by
trame.cpp
00001 #include "trame.h" 00002 00003 Trame::Trame(PinName _tx, PinName _rx) : 00004 tx(_tx), 00005 rx(_rx) 00006 { 00007 } 00008 00009 void Trame::sendTransmitRequest(const char* destination, const char* data, int length) 00010 { 00011 int tmp = length + 14; // length (grandeur du data à envoyer) 14 (API(1), FrameID(1), MAC(8), 16bit(2), Radius(1), Options(1)) 00012 char* trm = new char[tmp + 4]; // 4 (Delimiter(1), Length(2), Checksum(1)) 00013 00014 trm[0] = 0x7E; // Delimiter 00015 trm[1] = static_cast<char>((tmp >> 8) & 0xFF); // MSB de length 00016 trm[2] = static_cast<char>(tmp & 0xFF); // LSB length 00017 trm[3] = 0x10; // Type 00018 trm[4] = 0x01; // API 00019 for (int i = 0; i < 8; i++) 00020 trm[5 + i] = destination[i]; //Destination 00021 trm[13] = 0xFF; // 16 bits address 00022 trm[14] = 0xFE; // 16 bits address 00023 trm[15] = 0x00; // Radius 00024 trm[16] = 0x00; // Options 00025 00026 for (int i = 0; i < length; i++) 00027 trm[17 + i] = data[i]; // Data 00028 00029 trm[17 + length] = crc8(trm, tmp + 3); 00030 00031 Serial xbee(tx, rx); 00032 for (int i = 0; i < tmp + 4; i++) 00033 xbee.putc(trm[i]); 00034 00035 wait(0.01); 00036 delete trm; 00037 } 00038 00039 unsigned char Trame::crc8(const char* data, int length) 00040 { 00041 unsigned char crc = 0; 00042 for (int i = 3; i < length; i++) 00043 crc += data[i]; 00044 00045 return (0xFF - crc); 00046 }
Generated on Thu Jul 14 2022 10:43:20 by
