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
Fork of APP4 by
trame.cpp
00001 #include "trame.hpp" 00002 00003 Trame::Trame(PinName _tx, PinName _rx) : 00004 tx(_tx), 00005 rx(_rx) 00006 { 00007 } 00008 00009 void Trame::sendATCommand(const char* command, const char* data, int length) 00010 { 00011 int tmp = length + 4; // length (grandeur du data à envoyer) 4 (API(1), FrameID(1), AT Command(2)) 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] = 0x09; // Type 00018 trm[4] = 0x01; // API 00019 trm[5] = command[0]; 00020 trm[6] = command[1]; 00021 for (int i = 0; i < length; i++) 00022 trm[7+i] = data[i]; //Data 00023 trm[7+length] = crc8(trm, tmp + 3); 00024 00025 Serial xbee(tx, rx); 00026 for (int i = 0; i < tmp + 4; i++) 00027 xbee.putc(trm[i]); //Transmition des donnees 00028 00029 wait(0.01); 00030 delete trm; 00031 } 00032 00033 // Calcul du crc8 00034 unsigned char Trame::crc8(const char* data, int length) 00035 { 00036 unsigned char crc = 0; 00037 for (int i = 3; i < length; i++) 00038 crc += data[i]; 00039 00040 return (0xFF - crc); 00041 } 00042 00043 // fonction de debugage pour afficher toutes les informations sortie de la trame reçue 00044 void Trame::checkTrame(char *data, char check, int length) 00045 { 00046 Serial pc(USBTX, USBRX); 00047 00048 pc.printf("%d : data : ", length); 00049 00050 for (int a = 0; a < length; a++) 00051 { 00052 pc.printf("%x ", data[a]); 00053 } 00054 pc.printf(": check : %x\n\r", check); 00055 }
Generated on Fri Jul 15 2022 02:34:23 by
1.7.2
