From 249d93932e3e23e8f08adef1d7fd471a383fe8d0 Mon Sep 17 00:00:00 2001 From: EmanuelFeru Date: Sun, 1 Dec 2019 17:46:48 +0100 Subject: [PATCH] Fixed checksum Fixed a bug when requesting negative speed in the checksum calculation due to data type. --- 02_Arduino/hoverserial/hoverserial.ino | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/02_Arduino/hoverserial/hoverserial.ino b/02_Arduino/hoverserial/hoverserial.ino index ba63ad9..d6908c3 100644 --- a/02_Arduino/hoverserial/hoverserial.ino +++ b/02_Arduino/hoverserial/hoverserial.ino @@ -91,8 +91,8 @@ void Receive() { // Check for new data availability in the Serial buffer if (HoverSerial.available()) { - incomingByte = HoverSerial.read(); // Read the incoming byte - bufStartFrame = ((uint16_t)(incomingBytePrev) << 8) + incomingByte; // Construct the start marker + incomingByte = HoverSerial.read(); // Read the incoming byte + bufStartFrame = ((uint16_t)(incomingBytePrev) << 8) + incomingByte; // Construct the start frame } else { return; @@ -118,8 +118,8 @@ void Receive() // Check if we reached the end of the package if (idx == sizeof(SerialFeedback)) { uint16_t checksum; - checksum = NewFeedback.start ^ NewFeedback.cmd1 ^ NewFeedback.cmd2 ^ NewFeedback.speedR ^ NewFeedback.speedL - ^ NewFeedback.speedR_meas ^ NewFeedback.speedL_meas ^ NewFeedback.batVoltage ^ NewFeedback.boardTemp; + checksum = (uint16_t)(NewFeedback.start ^ NewFeedback.cmd1 ^ NewFeedback.cmd2 ^ NewFeedback.speedR ^ NewFeedback.speedL + ^ NewFeedback.speedR_meas ^ NewFeedback.speedL_meas ^ NewFeedback.batVoltage ^ NewFeedback.boardTemp); // Check validity of the new data if (NewFeedback.start == START_FRAME && checksum == NewFeedback.checksum) {