Skip to content

Commit

Permalink
Merge pull request #2048 from iNavFlight/dzikuvx-mps-queue-improvements
Browse files Browse the repository at this point in the history
MSP Queue handling improvements
  • Loading branch information
DzikuVx authored Apr 27, 2024
2 parents 0a3fbae + 7ed032a commit 04f4b92
Show file tree
Hide file tree
Showing 26 changed files with 183 additions and 438 deletions.
3 changes: 0 additions & 3 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,6 @@ <h2 class="groundstation-telemetry__header" data-i18n="gsTelemetry"></h2>
<div>
<span id="hardware-roundtrip"> </span>
</div>
<div>
<span id="drop-rate"> </span>
</div>
<div>
<span data-i18n="statusbar_arming_flags"></span> <span class="arming-flags">-</span>
</div>
Expand Down
4 changes: 3 additions & 1 deletion js/connection/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,10 @@ class Connection {
getTimeout() {
if (this._bitrate >= 57600) {
return 3000;
} else {
} if (this._bitrate >= 19200) {
return 4000;
} else {
return 6000;
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions js/gui.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const Switchery = require('./libraries/switchery/switchery')
const MSP = require('./msp');
const FC = require('./fc');
const interval = require('./intervals');
const mspBalancedInterval = require('./msp_balanced_interval');
const { scaleRangeInt } = require('./helpers');
const i18n = require('./localization');

Expand Down Expand Up @@ -94,7 +93,6 @@ GUI_control.prototype.tab_switch_cleanup = function (callback) {
MSP.callbacks_cleanup(); // we don't care about any old data that might or might not arrive

interval.killAll(['global_data_refresh', 'msp-load-update', 'ltm-connection-check']);
mspBalancedInterval.flush();

if (this.active_tab) {
TABS[this.active_tab].cleanup(callback);
Expand Down
8 changes: 7 additions & 1 deletion js/msp.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

const MSPCodes = require('./msp/MSPCodes')
const mspQueue = require('./serial_queue');
const eventFrequencyAnalyzer = require('./eventFrequencyAnalyzer');
const timeout = require('./timeouts');

/**
*
Expand Down Expand Up @@ -265,7 +267,9 @@ var MSP = {
/*
* Free port
*/
mspQueue.freeHardLock();
timeout.add('delayedFreeHardLock', function() {
mspQueue.freeHardLock();
}, 10);

// Reset variables
this.message_length_received = 0;
Expand Down Expand Up @@ -301,6 +305,8 @@ var MSP = {
var checksum;
var ii;

eventFrequencyAnalyzer.put('MPS ' + code);

if (!protocolVersion) {
protocolVersion = this.protocolVersion;
}
Expand Down
13 changes: 12 additions & 1 deletion js/msp/MSPHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ const ProgrammingPid = require('./../programmingPid');
const Safehome = require('./../safehome');
const { FwApproach } = require('./../fwApproach');
const Waypoint = require('./../waypoint');
const mspDeduplicationQueue = require('./mspDeduplicationQueue');
const mspStatistics = require('./mspStatistics');

var mspHelper = (function () {
var self = {};
Expand Down Expand Up @@ -1618,9 +1620,17 @@ var mspHelper = (function () {
*/
if (dataHandler.callbacks[i]) {
mspQueue.putRoundtrip(new Date().getTime() - dataHandler.callbacks[i].createdOn);
mspQueue.putHardwareRoundtrip(new Date().getTime() - dataHandler.callbacks[i].sentOn);

const hardwareRountrip = new Date().getTime() - dataHandler.callbacks[i].sentOn;

mspQueue.putHardwareRoundtrip(hardwareRountrip);

mspStatistics.add(dataHandler.code, hardwareRountrip);
}

//remove message from queue as received
mspDeduplicationQueue.remove(dataHandler.code);

// remove object from array
dataHandler.callbacks.splice(i, 1);

Expand Down Expand Up @@ -3065,6 +3075,7 @@ var mspHelper = (function () {
};

self._getSetting = function (name) {
console.log("Getting setting " + name);
if (FC.SETTINGS[name]) {
return Promise.resolve(FC.SETTINGS[name]);
}
Expand Down
41 changes: 41 additions & 0 deletions js/msp/mspDeduplicationQueue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'use strict';

/**
* This module is a queue for deduplication of MSP requests.
* We do not want to process the same request multiple times unless response is received.
* This improves wireless handling and lower amount of data that is put on the air
*/
var mspDeduplicationQueue = function() {

let publicScope = {},
privateScope = {};

privateScope.queue = [];

publicScope.put = function(item) {
privateScope.queue.push(item);
};

publicScope.remove = function(item) {
const index = privateScope.queue.indexOf(item);
if (index > -1) {
privateScope.queue.splice(index, 1);
}
};

publicScope.check = function(item) {
return privateScope.queue.includes(item);
};

publicScope.flush = function() {
privateScope.queue = [];
};

publicScope.get = function() {
return privateScope.queue;
};

return publicScope;
}();

module.exports = mspDeduplicationQueue;
39 changes: 39 additions & 0 deletions js/msp/mspStatistics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use strict';

var mspStatistics = function() {

let publicScope = {},
privateScope = {};

privateScope.statistics = {};


publicScope.add = function(code, duration) {
if (!privateScope.statistics[code]) {
privateScope.statistics[code] = {
ctime: new Date().getTime(),
count: 0,
duration: 0,
average: 0,
callsPerSecond: 0
};
}
privateScope.statistics[code].count++;
privateScope.statistics[code].duration += duration;
privateScope.statistics[code].average = privateScope.statistics[code].duration / privateScope.statistics[code].count;
privateScope.statistics[code].callsPerSecond = privateScope.statistics[code].count / ((new Date().getTime() - privateScope.statistics[code].ctime) / 1000);
};

publicScope.get = function() {
return privateScope.statistics;
};

publicScope.reset = function() {
privateScope.statistics = {};
};

return publicScope;

}();

module.exports = mspStatistics;
75 changes: 0 additions & 75 deletions js/msp_balanced_interval.js

This file was deleted.

5 changes: 0 additions & 5 deletions js/periodicStatusUpdater.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,6 @@ const mspQueue = require('./serial_queue');

if (!stoppped && GUI.active_tab != 'cli') {

if (mspQueue.shouldDropStatus()) {
return;
}


MSP.send_message(MSPCodes.MSP_SENSOR_STATUS, false, false);
MSP.send_message(MSPCodes.MSPV2_INAV_STATUS, false, false);
MSP.send_message(MSPCodes.MSP_ACTIVEBOXES, false, false);
Expand Down
Loading

0 comments on commit 04f4b92

Please sign in to comment.