mirror of
https://github.com/iNavFlight/inav-configurator.git
synced 2025-07-14 20:10:11 +03:00
soft and hard serial port lock with watchdog
This commit is contained in:
parent
4ae45333a8
commit
a439456ab9
3 changed files with 75 additions and 10 deletions
10
js/msp.js
10
js/msp.js
|
@ -112,18 +112,26 @@ var MSP = {
|
||||||
mspHelper.processData(this);
|
mspHelper.processData(this);
|
||||||
} else {
|
} else {
|
||||||
console.log('code: ' + this.code + ' - crc failed');
|
console.log('code: ' + this.code + ' - crc failed');
|
||||||
console.log(data);
|
|
||||||
|
|
||||||
this.packet_error++;
|
this.packet_error++;
|
||||||
$('span.packet-error').html(this.packet_error);
|
$('span.packet-error').html(this.packet_error);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Free port
|
||||||
|
*/
|
||||||
|
helper.mspQueue.freeHardLock();
|
||||||
|
|
||||||
// Reset variables
|
// Reset variables
|
||||||
this.message_length_received = 0;
|
this.message_length_received = 0;
|
||||||
this.state = 0;
|
this.state = 0;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
/*
|
||||||
|
* Free port
|
||||||
|
*/
|
||||||
|
helper.mspQueue.freeHardLock();
|
||||||
console.log('Unknown state detected: ' + this.state);
|
console.log('Unknown state detected: ' + this.state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -113,7 +113,8 @@ $(document).ready(function () {
|
||||||
* Flush
|
* Flush
|
||||||
*/
|
*/
|
||||||
helper.mspQueue.flush();
|
helper.mspQueue.flush();
|
||||||
helper.mspQueue.freeSerialPort();
|
helper.mspQueue.freeHardLock();
|
||||||
|
helper.mspQueue.freeSoftLock();
|
||||||
|
|
||||||
serial.disconnect(onClosed);
|
serial.disconnect(onClosed);
|
||||||
MSP.disconnect_cleanup();
|
MSP.disconnect_cleanup();
|
||||||
|
|
|
@ -14,6 +14,10 @@ helper.mspQueue = (function (serial, MSP) {
|
||||||
privateScope.roundtripFilter = new classes.SimpleSmoothFilter(20, 0.996);
|
privateScope.roundtripFilter = new classes.SimpleSmoothFilter(20, 0.996);
|
||||||
privateScope.hardwareRoundtripFilter = new classes.SimpleSmoothFilter(5, 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.targetLoad = 1.5;
|
||||||
privateScope.statusDropFactor = 0.75;
|
privateScope.statusDropFactor = 0.75;
|
||||||
|
|
||||||
|
@ -41,7 +45,40 @@ helper.mspQueue = (function (serial, MSP) {
|
||||||
|
|
||||||
privateScope.queue = [];
|
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
|
* 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 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");
|
helper.eventFrequencyAnalyzer.put("port in use");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -78,7 +115,8 @@ helper.mspQueue = (function (serial, MSP) {
|
||||||
/*
|
/*
|
||||||
* Lock serial port as being in use right now
|
* Lock serial port as being in use right now
|
||||||
*/
|
*/
|
||||||
privateScope.portInUse = true;
|
publicScope.setSoftLock();
|
||||||
|
publicScope.setHardLock();
|
||||||
|
|
||||||
request.timer = setTimeout(function () {
|
request.timer = setTimeout(function () {
|
||||||
console.log('MSP data request timed-out: ' + request.code);
|
console.log('MSP data request timed-out: ' + request.code);
|
||||||
|
@ -110,6 +148,8 @@ helper.mspQueue = (function (serial, MSP) {
|
||||||
*/
|
*/
|
||||||
MSP.putCallback(request);
|
MSP.putCallback(request);
|
||||||
|
|
||||||
|
helper.eventFrequencyAnalyzer.put('message sent');
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Send data to serial port
|
* Send data to serial port
|
||||||
*/
|
*/
|
||||||
|
@ -121,7 +161,7 @@ helper.mspQueue = (function (serial, MSP) {
|
||||||
if (request.onSend) {
|
if (request.onSend) {
|
||||||
request.onSend();
|
request.onSend();
|
||||||
}
|
}
|
||||||
privateScope.portInUse = false;
|
publicScope.freeSoftLock();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -135,10 +175,6 @@ helper.mspQueue = (function (serial, MSP) {
|
||||||
privateScope.queue = [];
|
privateScope.queue = [];
|
||||||
};
|
};
|
||||||
|
|
||||||
publicScope.freeSerialPort = function () {
|
|
||||||
privateScope.portInUse = false;
|
|
||||||
};
|
|
||||||
|
|
||||||
publicScope.put = function (mspRequest) {
|
publicScope.put = function (mspRequest) {
|
||||||
privateScope.queue.push(mspRequest);
|
privateScope.queue.push(mspRequest);
|
||||||
};
|
};
|
||||||
|
@ -182,6 +218,26 @@ helper.mspQueue = (function (serial, MSP) {
|
||||||
publicScope.balancer = function () {
|
publicScope.balancer = function () {
|
||||||
privateScope.currentLoad = privateScope.loadFilter.get();
|
privateScope.currentLoad = privateScope.loadFilter.get();
|
||||||
helper.mspQueue.computeDropRatio();
|
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 () {
|
publicScope.shouldDrop = function () {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue