experimental bugfix for backup/restore failing under certain conditions

10.3.x-maintenance
cTn 2014-12-05 10:24:20 +01:00
parent 21e414f4b3
commit e87c0ca4ee
1 changed files with 23 additions and 13 deletions

View File

@ -531,28 +531,38 @@ var MSP = {
bufView[5] = bufView[3] ^ bufView[4]; // checksum bufView[5] = bufView[3] ^ bufView[4]; // checksum
} }
// utilizing callback/timeout system for all commands // dev version 0.57 code below got recently changed due to the fact that queueing same MSP codes was unsupported
// and was causing trouble while backup/restoring configurations
// watch out if the recent change create any inconsistencies and then adjust accordingly
var obj = {'code': code, 'requestBuffer': bufferOut, 'callback': (callback_msp) ? callback_msp : false, 'timer': false};
var requestExists = false;
for (var i = 0; i < MSP.callbacks.length; i++) { for (var i = 0; i < MSP.callbacks.length; i++) {
if (MSP.callbacks[i].code == code) { if (MSP.callbacks[i].code == code) {
// request already exist // request already exist, we will just attach
return false; // skips the code below requestExists = true;
break;
} }
} }
var obj = {'code': code, 'requestBuffer': bufferOut, 'callback': (callback_msp) ? callback_msp : false}; if (!requestExists) {
obj.timer = setInterval(function () { obj.timer = setInterval(function () {
console.log('MSP data request timed-out: ' + code); console.log('MSP data request timed-out: ' + code);
serial.send(bufferOut, false); serial.send(bufferOut, false);
}, 1000); // we should be able to define timeout in the future }, 1000); // we should be able to define timeout in the future
}
MSP.callbacks.push(obj); MSP.callbacks.push(obj);
// always send messages with data payload (even when there is a message already in the queue)
if (data || !requestExists) {
serial.send(bufferOut, function (sendInfo) { serial.send(bufferOut, function (sendInfo) {
if (sendInfo.bytesSent == bufferOut.length) { if (sendInfo.bytesSent == bufferOut.length) {
if (callback_sent) callback_sent(); if (callback_sent) callback_sent();
} }
}); });
}
return true; return true;
}, },