mirror of
https://github.com/iNavFlight/inav-configurator.git
synced 2025-07-25 01:05:12 +03:00
msp queue load
This commit is contained in:
parent
9594880041
commit
083eee3115
7 changed files with 53 additions and 7 deletions
|
@ -2,11 +2,40 @@
|
|||
|
||||
var helper = helper || {};
|
||||
|
||||
//FIXME extract it to separate file
|
||||
var walkingAverageClass = function (maxLength) {
|
||||
|
||||
var table = [],
|
||||
self = {};
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {number} data
|
||||
*/
|
||||
self.put = function (data) {
|
||||
table.push(data);
|
||||
if (table.length > maxLength) {
|
||||
table.shift();
|
||||
}
|
||||
};
|
||||
|
||||
self.getAverage = function () {
|
||||
var sum = table.reduce(function(a, b) { return a + b; });
|
||||
return sum / table.length;
|
||||
};
|
||||
|
||||
return self;
|
||||
};
|
||||
|
||||
helper.mspQueue = (function (serial, MSP) {
|
||||
|
||||
var publicScope = {},
|
||||
privateScope = {};
|
||||
|
||||
privateScope.handlerFrequency = 200;
|
||||
|
||||
privateScope.loadAverage = new walkingAverageClass(privateScope.handlerFrequency);
|
||||
|
||||
privateScope.queue = [];
|
||||
|
||||
privateScope.portInUse = false;
|
||||
|
@ -24,6 +53,8 @@ helper.mspQueue = (function (serial, MSP) {
|
|||
*/
|
||||
publicScope.executor = function () {
|
||||
|
||||
privateScope.loadAverage.put(privateScope.queue.length);
|
||||
|
||||
/*
|
||||
* if port is blocked or there is no connection, do not process the queue
|
||||
*/
|
||||
|
@ -95,7 +126,15 @@ helper.mspQueue = (function (serial, MSP) {
|
|||
return privateScope.queue.length;
|
||||
};
|
||||
|
||||
setInterval(publicScope.executor, 20);
|
||||
/**
|
||||
* 1s MSP load computed as number of messages in a queue in given period
|
||||
* @returns {string}
|
||||
*/
|
||||
publicScope.getLoad = function () {
|
||||
return privateScope.loadAverage.getAverage();
|
||||
};
|
||||
|
||||
setInterval(publicScope.executor, Math.round(1000 / privateScope.handlerFrequency));
|
||||
|
||||
return publicScope;
|
||||
})(serial, MSP);
|
Loading…
Add table
Add a link
Reference in a new issue