mirror of
https://github.com/iNavFlight/inav-configurator.git
synced 2025-07-22 07:45:16 +03:00
Extract mspDeduplicationQueue to separate file
This commit is contained in:
parent
2156090a0d
commit
040b0cec52
6 changed files with 55 additions and 41 deletions
|
@ -18,6 +18,7 @@ const ProgrammingPid = require('./../programmingPid');
|
|||
const Safehome = require('./../safehome');
|
||||
const { FwApproach } = require('./../fwApproach');
|
||||
const Waypoint = require('./../waypoint');
|
||||
const mspDeduplicationQueue = require('./mspDeduplicationQueue');
|
||||
|
||||
var mspHelper = (function () {
|
||||
var self = {};
|
||||
|
@ -1622,7 +1623,7 @@ var mspHelper = (function () {
|
|||
}
|
||||
|
||||
//remove message from queue as received
|
||||
mspQueue.removeMessage(dataHandler.code);
|
||||
mspDeduplicationQueue.remove(dataHandler.code);
|
||||
|
||||
// remove object from array
|
||||
dataHandler.callbacks.splice(i, 1);
|
||||
|
|
41
js/msp/mspDeduplicationQueue.js
Normal file
41
js/msp/mspDeduplicationQueue.js
Normal file
|
@ -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;
|
|
@ -27,6 +27,7 @@ const BOARD = require('./boards');
|
|||
const jBox = require('./libraries/jBox/jBox.min');
|
||||
const groundstation = require('./groundstation');
|
||||
const ltmDecoder = require('./ltmDecoder');
|
||||
const mspDeduplicationQueue = require('./msp/mspDeduplicationQueue');
|
||||
|
||||
var SerialBackend = (function () {
|
||||
|
||||
|
@ -239,7 +240,7 @@ var SerialBackend = (function () {
|
|||
mspQueue.flush();
|
||||
mspQueue.freeHardLock();
|
||||
mspQueue.freeSoftLock();
|
||||
mspQueue.flushMessages();
|
||||
mspDeduplicationQueue.flush();
|
||||
|
||||
CONFIGURATOR.connection.disconnect(privateScope.onClosed);
|
||||
MSP.disconnect_cleanup();
|
||||
|
@ -377,7 +378,7 @@ var SerialBackend = (function () {
|
|||
mspQueue.flush();
|
||||
mspQueue.freeHardLock();
|
||||
mspQueue.freeSoftLock();
|
||||
mspQueue.flushMessages();
|
||||
mspDeduplicationQueue.flush();
|
||||
CONFIGURATOR.connection.emptyOutputBuffer();
|
||||
|
||||
$('div.connect_controls a').click(); // disconnect
|
||||
|
|
|
@ -5,6 +5,7 @@ const MSPCodes = require('./msp/MSPCodes');
|
|||
const SimpleSmoothFilter = require('./simple_smooth_filter');
|
||||
const PidController = require('./pid_controller');
|
||||
const eventFrequencyAnalyzer = require('./eventFrequencyAnalyzer');
|
||||
const mspDeduplicationQueue = require('./msp/mspDeduplicationQueue');
|
||||
|
||||
var mspQueue = function () {
|
||||
|
||||
|
@ -42,38 +43,6 @@ var mspQueue = function () {
|
|||
privateScope.removeCallback = null;
|
||||
privateScope.putCallback = null;
|
||||
|
||||
/**
|
||||
* This is the list of all messages that are currently in queue, including being already dispatched via radio and waiting for response
|
||||
*/
|
||||
privateScope.messagesInQueue = [];
|
||||
|
||||
//Store new code in the queue
|
||||
publicScope.storeMessage = function (code) {
|
||||
privateScope.messagesInQueue.push(code);
|
||||
};
|
||||
|
||||
//Remove code from the queue
|
||||
publicScope.removeMessage = function (code) {
|
||||
var index = privateScope.messagesInQueue.indexOf(code);
|
||||
if (index > -1) {
|
||||
privateScope.messagesInQueue.splice(index, 1);
|
||||
}
|
||||
};
|
||||
|
||||
//List all messages in the queue
|
||||
publicScope.getMessages = function () {
|
||||
return privateScope.messagesInQueue;
|
||||
};
|
||||
|
||||
//Check if message is in the queue
|
||||
publicScope.isMessageInQueue = function (code) {
|
||||
return privateScope.messagesInQueue.indexOf(code) > -1;
|
||||
};
|
||||
|
||||
publicScope.flushMessages = function () {
|
||||
privateScope.messagesInQueue = [];
|
||||
};
|
||||
|
||||
publicScope.computeDropRatio = function () {
|
||||
privateScope.dropRatio = privateScope.loadPidController.run(publicScope.getLoad());
|
||||
};
|
||||
|
@ -196,7 +165,7 @@ var mspQueue = function () {
|
|||
|
||||
request.timer = setTimeout(function () {
|
||||
console.log('MSP data request timed-out: ' + request.code);
|
||||
publicScope.removeMessage(request.code);
|
||||
mspDeduplicationQueue.remove(request.code);
|
||||
/*
|
||||
* Remove current callback
|
||||
*/
|
||||
|
@ -262,19 +231,19 @@ var mspQueue = function () {
|
|||
|
||||
console.log('Received message ', mspRequest.code);
|
||||
|
||||
const isMessageInQueue = publicScope.isMessageInQueue(mspRequest.code);
|
||||
const isMessageInQueue = mspDeduplicationQueue.check(mspRequest.code);
|
||||
|
||||
if (isMessageInQueue) {
|
||||
console.log('Message already in queue: ' + mspRequest.code);
|
||||
return false;
|
||||
}
|
||||
|
||||
publicScope.storeMessage(mspRequest.code);
|
||||
|
||||
if (privateScope.queueLocked === true) {
|
||||
return false;
|
||||
}
|
||||
|
||||
mspDeduplicationQueue.put(mspRequest.code);
|
||||
|
||||
privateScope.queue.push(mspRequest);
|
||||
return true;
|
||||
};
|
||||
|
|
|
@ -13,6 +13,7 @@ const { globalSettings } = require('./../js/globalSettings');
|
|||
const CliAutoComplete = require('./../js/CliAutoComplete');
|
||||
const { ConnectionType } = require('./../js/connection/connection');
|
||||
const jBox = require('./../js/libraries/jBox/jBox.min');
|
||||
const mspDeduplicationQueue = require('./msp/mspDeduplicationQueue');
|
||||
|
||||
TABS.cli = {
|
||||
lineDelayMs: 50,
|
||||
|
@ -94,7 +95,7 @@ TABS.cli.initialize = function (callback) {
|
|||
|
||||
// Flush MSP queue as well as all MSP registered callbacks
|
||||
mspQueue.flush();
|
||||
mspQueue.flushMessages();
|
||||
mspDeduplicationQueue.flush();
|
||||
MSP.callbacks_cleanup();
|
||||
|
||||
self.outputHistory = "";
|
||||
|
|
|
@ -22,6 +22,7 @@ const mspQueue = require('./../js/serial_queue');
|
|||
const mspHelper = require('./../js/msp/MSPHelper');
|
||||
const STM32 = require('./../js/protocols/stm32');
|
||||
const STM32DFU = require('./../js/protocols/stm32usbdfu');
|
||||
const mspDeduplicationQueue = require('./msp/mspDeduplicationQueue');
|
||||
|
||||
TABS.firmware_flasher = {};
|
||||
TABS.firmware_flasher.initialize = function (callback) {
|
||||
|
@ -780,7 +781,7 @@ TABS.firmware_flasher.closeTempConnection = function() {
|
|||
mspQueue.flush();
|
||||
mspQueue.freeHardLock();
|
||||
mspQueue.freeSoftLock();
|
||||
mspQueue.flushMessages();
|
||||
mspDeduplicationQueue.flush();
|
||||
CONFIGURATOR.connection.emptyOutputBuffer();
|
||||
|
||||
CONFIGURATOR.connectionValid = false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue