1
0
Fork 0
mirror of https://github.com/iNavFlight/inav-configurator.git synced 2025-07-14 20:10:11 +03:00

Compute and verify the LTM checksum

This commit is contained in:
Pawel Spychalski (DzikuVx) 2024-03-06 21:36:12 +01:00
parent 742176d7eb
commit 16b097cf8e

View file

@ -154,7 +154,7 @@ helper.ltmDecoder = (function () {
privateScope.receiverIndex = 0; privateScope.receiverIndex = 0;
privateScope.serialBuffer = []; privateScope.serialBuffer = [];
privateScope.protocolState = LTM_STATE_MSGTYPE; privateScope.protocolState = LTM_STATE_MSGTYPE;
console.log('privateScope.protocolState: LTM_STATE_MSGTYPE', 'will expext frame ' + privateScope.frameType, 'expected length: ' + privateScope.frameLength); console.log('protocolState: LTM_STATE_MSGTYPE', 'will expext frame ' + privateScope.frameType, 'expected length: ' + privateScope.frameLength);
} }
return; return;
@ -167,6 +167,20 @@ helper.ltmDecoder = (function () {
/* /*
* If YES, check checksum and execute data processing * If YES, check checksum and execute data processing
*/ */
let checksum = 0;
for (let i = 0; i < privateScope.serialBuffer.length; i++) {
checksum ^= privateScope.serialBuffer[i];
}
if (checksum != data) {
console.log('LTM checksum error, frame type: ' + privateScope.frameType + ' rejected');
privateScope.protocolState = LTM_STATE_IDLE;
privateScope.serialBuffer = [];
privateScope.receiverIndex = 0;
return;
}
if (privateScope.frameType == 'A') { if (privateScope.frameType == 'A') {
TELEMETRY.pitch = privateScope.readInt(0); TELEMETRY.pitch = privateScope.readInt(0);
TELEMETRY.roll = privateScope.readInt(2); TELEMETRY.roll = privateScope.readInt(2);