summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSerhii Kostiuk <serhii.o.kostiuk@globallogic.com>2020-07-21 18:35:33 +0300
committerSerhii Kostiuk <serhii.o.kostiuk@globallogic.com>2020-07-21 18:35:33 +0300
commita9a598dab448dd0d062725e2f3a60bcf68c6fe9e (patch)
treefb79077d004c8a986befdb537a337fa1d5dd1d63 /src
parentd520358b3e88ae80af968254b42645c4d9eae604 (diff)
downloadlibmts-io-a9a598dab448dd0d062725e2f3a60bcf68c6fe9e.tar.gz
libmts-io-a9a598dab448dd0d062725e2f3a60bcf68c6fe9e.tar.bz2
libmts-io-a9a598dab448dd0d062725e2f3a60bcf68c6fe9e.zip
Quectel Delta Radio Firmware Upgrade support - libmts-io implementation
Fixed Quectel checksum calculation algorithm to correctly handle odd file sizes.
Diffstat (limited to 'src')
-rw-r--r--src/MTS_IO_QuectelRadio.cpp4
1 files changed, 3 insertions, 1 deletions
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);