-
Notifications
You must be signed in to change notification settings - Fork 316
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2048 from iNavFlight/dzikuvx-mps-queue-improvements
MSP Queue handling improvements
- Loading branch information
Showing
26 changed files
with
183 additions
and
438 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.