From 985daf336d25adf8995c173a5c8b3073af554eb1 Mon Sep 17 00:00:00 2001 From: Michael Keller Date: Mon, 23 Nov 2020 19:06:33 +0100 Subject: [PATCH] Merge pull request #2287 from haslinghuis/msp_undefined --- src/js/msp.js | 1 - src/js/msp/MSPHelper.js | 14 +++++++++----- src/js/serial_backend.js | 2 +- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/js/msp.js b/src/js/msp.js index a339c214..ac4edea8 100644 --- a/src/js/msp.js +++ b/src/js/msp.js @@ -208,7 +208,6 @@ var MSP = { // message received, store dataview this.dataView = new DataView(this.message_buffer, 0, this.message_length_expected); } else { - console.log(`code: ${this.code} - crc failed`); this.packet_error++; this.crcError = true; this.dataView = new DataView(new ArrayBuffer(0)); diff --git a/src/js/msp/MSPHelper.js b/src/js/msp/MSPHelper.js index 5f0ead04..fec5f420 100644 --- a/src/js/msp/MSPHelper.js +++ b/src/js/msp/MSPHelper.js @@ -275,7 +275,6 @@ MspHelper.prototype.process_data = function(dataHandler) { BF_CONFIG.currentmetertype = data.readU8(); BF_CONFIG.batterycapacity = data.readU16(); } else { - var offset = 0; CURRENT_METER_CONFIGS = []; var current_meter_count = data.readU8(); for (let i = 0; i < current_meter_count; i++) { @@ -1598,13 +1597,16 @@ MspHelper.prototype.process_data = function(dataHandler) { break; } } + } else { + console.log(`code: ${code} - crc failed`); } + // trigger callbacks, cleanup/remove callback after trigger - for (let i = dataHandler.callbacks.length - 1; i >= 0; i--) { // itterating in reverse because we use .splice which modifies array length - if (dataHandler.callbacks[i].code == code) { + for (let i = dataHandler.callbacks.length - 1; i >= 0; i--) { // iterating in reverse because we use .splice which modifies array length + if (dataHandler.callbacks[i]?.code === code) { // save callback reference - var callback = dataHandler.callbacks[i].callback; - var callbackOnError = dataHandler.callbacks[i].callbackOnError; + const callback = dataHandler.callbacks[i].callback; + const callbackOnError = dataHandler.callbacks[i].callbackOnError; // remove timeout clearInterval(dataHandler.callbacks[i].timer); @@ -1614,6 +1616,8 @@ MspHelper.prototype.process_data = function(dataHandler) { if (!crcError || callbackOnError) { // fire callback if (callback) callback({'command': code, 'data': data, 'length': data.byteLength, 'crcError': crcError}); + } else { + console.log(`code: ${code} - crc failed. No callback`); } } } diff --git a/src/js/serial_backend.js b/src/js/serial_backend.js index 2235276f..ac044718 100644 --- a/src/js/serial_backend.js +++ b/src/js/serial_backend.js @@ -822,7 +822,7 @@ function reinitialiseConnection(originatorTab, callback) { if (callback) { callback(); } - }, 100); + }, 200); //TODO: Need to work out how to do a proper reconnect here. // caveat: Timeouts set with `GUI.timeout_add()` are removed on disconnect. } else {