1
0
Fork 0
mirror of https://github.com/iNavFlight/inav-configurator.git synced 2025-07-13 19:40:22 +03:00

soft and hard serial port lock with watchdog

This commit is contained in:
Pawel Spychalski (DzikuVx) 2017-01-22 00:02:52 +01:00
parent 4ae45333a8
commit a439456ab9
3 changed files with 75 additions and 10 deletions

View file

@ -112,18 +112,26 @@ var MSP = {
mspHelper.processData(this);
} else {
console.log('code: ' + this.code + ' - crc failed');
console.log(data);
this.packet_error++;
$('span.packet-error').html(this.packet_error);
}
/*
* Free port
*/
helper.mspQueue.freeHardLock();
// Reset variables
this.message_length_received = 0;
this.state = 0;
break;
default:
/*
* Free port
*/
helper.mspQueue.freeHardLock();
console.log('Unknown state detected: ' + this.state);
}
}

View file

@ -113,7 +113,8 @@ $(document).ready(function () {
* Flush
*/
helper.mspQueue.flush();
helper.mspQueue.freeSerialPort();
helper.mspQueue.freeHardLock();
helper.mspQueue.freeSoftLock();
serial.disconnect(onClosed);
MSP.disconnect_cleanup();

View file

@ -14,6 +14,10 @@ helper.mspQueue = (function (serial, MSP) {
privateScope.roundtripFilter = new classes.SimpleSmoothFilter(20, 0.996);
privateScope.hardwareRoundtripFilter = new classes.SimpleSmoothFilter(5, 0.996);
/**
* Target load for MSP queue. When load is above target, throttling might start to appear
* @type {number}
*/
privateScope.targetLoad = 1.5;
privateScope.statusDropFactor = 0.75;
@ -41,7 +45,40 @@ helper.mspQueue = (function (serial, MSP) {
privateScope.queue = [];
privateScope.portInUse = false;
privateScope.softLock = false;
privateScope.hardLock = false;
privateScope.lockMethod = 'soft';
publicScope.setLockMethod = function (method) {
privateScope.lockMethod = method;
};
publicScope.setSoftLock = function () {
privateScope.softLock = new Date().getTime();
};
publicScope.setHardLock = function () {
privateScope.hardLock = new Date().getTime();
};
publicScope.freeSoftLock = function () {
privateScope.softLock = false;
};
publicScope.freeHardLock = function () {
privateScope.hardLock = false;
};
publicScope.isLocked = function () {
if (privateScope.lockMethod === 'soft') {
return privateScope.softLock !== false;
} else {
return privateScope.hardLock !== false;
}
};
/**
* This method is periodically executed and moves MSP request
@ -66,7 +103,7 @@ helper.mspQueue = (function (serial, MSP) {
/*
* if port is blocked or there is no connection, do not process the queue
*/
if (privateScope.portInUse || serial.connectionId === false) {
if (publicScope.isLocked() || serial.connectionId === false) {
helper.eventFrequencyAnalyzer.put("port in use");
return false;
}
@ -78,7 +115,8 @@ helper.mspQueue = (function (serial, MSP) {
/*
* Lock serial port as being in use right now
*/
privateScope.portInUse = true;
publicScope.setSoftLock();
publicScope.setHardLock();
request.timer = setTimeout(function () {
console.log('MSP data request timed-out: ' + request.code);
@ -110,6 +148,8 @@ helper.mspQueue = (function (serial, MSP) {
*/
MSP.putCallback(request);
helper.eventFrequencyAnalyzer.put('message sent');
/*
* Send data to serial port
*/
@ -121,7 +161,7 @@ helper.mspQueue = (function (serial, MSP) {
if (request.onSend) {
request.onSend();
}
privateScope.portInUse = false;
publicScope.freeSoftLock();
}
});
}
@ -135,10 +175,6 @@ helper.mspQueue = (function (serial, MSP) {
privateScope.queue = [];
};
publicScope.freeSerialPort = function () {
privateScope.portInUse = false;
};
publicScope.put = function (mspRequest) {
privateScope.queue.push(mspRequest);
};
@ -182,6 +218,26 @@ helper.mspQueue = (function (serial, MSP) {
publicScope.balancer = function () {
privateScope.currentLoad = privateScope.loadFilter.get();
helper.mspQueue.computeDropRatio();
/*
* Also, check if port lock if hanging. Free is so
*/
var currentTimestamp = new Date().getTime(),
threshold = publicScope.getHardwareRoundtrip() * 4;
if (threshold > 1000) {
threshold = 1000;
}
if (privateScope.softLock !== false && currentTimestamp - privateScope.softLock > threshold) {
privateScope.softLock = false;
helper.eventFrequencyAnalyzer.put('force free soft lock');
}
if (privateScope.hardLock !== false && currentTimestamp - privateScope.hardLock > threshold) {
privateScope.hardLock = false;
helper.eventFrequencyAnalyzer.put('force free hard lock');
}
};
publicScope.shouldDrop = function () {