.
Dependencies: L432KC_SPI_Pey_Lal
Diff: protocol.cpp
- Revision:
- 116:6dfcafa00e42
- Parent:
- 115:156b8234f2de
diff -r 156b8234f2de -r 6dfcafa00e42 protocol.cpp --- a/protocol.cpp Wed May 18 18:07:09 2022 +0000 +++ b/protocol.cpp Mon May 23 12:55:02 2022 +0000 @@ -1,9 +1,10 @@ #include "protocol.h" +#include "toolbox.hpp" char newDataAvailable = 0; -//Bytewise XOR -char calculateChecksum(char command, char* payload, char payloadLength) +//Bytewise XOR checksum +char calculateChecksum(char command, char* payload, char payloadLength) //Use only when receiving frames { char checksum = 0xff; checksum ^= command; @@ -12,6 +13,22 @@ return checksum; } +char calculateChecksum(char *msg) //Use only when emitting speed frames +{ + int i = 0; + char checksum = msg[i++]; + for (; i < 5; i++) + checksum ^= msg[i]; + return checksum; +} + +void encodeMessage(char *msg, float vitesse) +{ + msg[0] = 0xff; + convertFloatToBytes(&vitesse, msg, 1); + msg[5] = calculateChecksum(msg); +} + char receiveState = STATE_START_OF_FRAME; char receiveIndex = 0; char receiveIndexLimit;