Merge pull request #2287 from haslinghuis/msp_undefined
parent
6e58ae3bb7
commit
985daf336d
|
@ -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));
|
||||
|
|
|
@ -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`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue