From a9a598dab448dd0d062725e2f3a60bcf68c6fe9e Mon Sep 17 00:00:00 2001 From: Serhii Kostiuk Date: Tue, 21 Jul 2020 18:35:33 +0300 Subject: Quectel Delta Radio Firmware Upgrade support - libmts-io implementation Fixed Quectel checksum calculation algorithm to correctly handle odd file sizes. --- src/MTS_IO_QuectelRadio.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/MTS_IO_QuectelRadio.cpp b/src/MTS_IO_QuectelRadio.cpp index 22fa92f..39c0601 100644 --- a/src/MTS_IO_QuectelRadio.cpp +++ b/src/MTS_IO_QuectelRadio.cpp @@ -981,8 +981,10 @@ uint16_t QuectelRadio::getQuectelChecksum(const void* data, size_t nBytes) { for (size_t i = 0; i < nBytes; i += 2) { // If the number of the characters is odd, set the last character as the high 8 bit, and the low 8 bit as 0, // and then use an XOR operator to calculate the checksum. + bool bHasLowByte = (i + 1 < nBytes); + uint8_t high = castData[i]; - uint8_t low = (i < nBytes) ? (castData[i+1]) : (0); + uint8_t low = bHasLowByte ? (castData[i+1]) : (0); uint16_t iFragment = bytesToUint16(high, low); updateQuectelChecksum(iChecksum, iFragment); -- cgit v1.2.3