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: nRF24L01P_Hello_World nRF24L01P
Diff: protocol.cpp
- Revision:
- 5:668dd9395ca5
- Parent:
- 4:5caf9e1dc16c
--- a/protocol.cpp Fri Jan 08 08:51:10 2021 +0000 +++ b/protocol.cpp Fri Apr 16 16:01:03 2021 +0000 @@ -1,22 +1,23 @@ #include "protocol.h" -#include "bufferCirculaire.h" +#include "circularBuffer.h" //------------------------------------------------Encodage/Decodage des trames------------------------------------------------// //!!! La taille de "msg[]" doit être [msgPayloadLength + 6] -int encodeMessage(int msgFunction, int msgPayloadLength, char* msgPayload, char* msg) +void encodeAndSendMessage(int msgFunction, int msgPayloadLength, char* msgPayload) { - int msgLength = 0; - msg[msgLength++] = 0xFE; //Start of Frame - msg[msgLength++] = (char)(msgFunction >> 8); //Message Function MSB - msg[msgLength++] = (char)(msgFunction); //Message Function LSB - msg[msgLength++] = (char)(msgPayloadLength >> 8); //Message Payload Length MSB - msg[msgLength++] = (char)(msgPayloadLength); //Message Payload Length LSB + int msgIndex = 0; + char msg[msgPayloadLength + 6]; + msg[msgIndex++] = 0xFE; //Start of Frame + msg[msgIndex++] = (char)(msgFunction >> 8); //Message Function MSB + msg[msgIndex++] = (char)(msgFunction); //Message Function LSB + msg[msgIndex++] = (char)(msgPayloadLength >> 8); //Message Payload Length MSB + msg[msgIndex++] = (char)(msgPayloadLength); //Message Payload Length LSB int j; for (j = 0 ; j < msgPayloadLength; j++) - msg[msgLength++] = msgPayload[j]; //MessagePayload - msg[msgLength++] = calculateChecksum(msgFunction, msgPayloadLength, msgPayload); //Checksum + msg[msgIndex++] = msgPayload[j]; //MessagePayload + msg[msgIndex++] = calculateChecksum(msgFunction, msgPayloadLength, msgPayload); //Checksum - return msgLength; + cbTxSendMessage(msg, msgPayloadLength + 6); } char calculateChecksum(int msgFunction, int msgPayloadLength, char* msgPayload)