mirror of
https://github.com/iNavFlight/inav-configurator.git
synced 2025-07-19 14:25:13 +03:00
Frequency analyzer for MSP frames
This commit is contained in:
parent
d1483e5e26
commit
2c334f6c23
3 changed files with 83 additions and 0 deletions
77
js/eventFrequencyAnalyzer.js
Normal file
77
js/eventFrequencyAnalyzer.js
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
'use s';
|
||||||
|
|
||||||
|
var helper = helper || {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple analyzer that returns frequency of events using 5s buffer
|
||||||
|
* Usage: register periodic events with 'put', then call 'get' to get results
|
||||||
|
*/
|
||||||
|
helper.eventFrequencyAnalyzer = (function () {
|
||||||
|
|
||||||
|
var privateScope = {},
|
||||||
|
publicScope = {},
|
||||||
|
bufferPeriod = 5000;
|
||||||
|
|
||||||
|
privateScope.data = {};
|
||||||
|
privateScope.output = {};
|
||||||
|
privateScope.intervalHandler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Periodically executed aggregation task
|
||||||
|
* @returns {{}|*}
|
||||||
|
*/
|
||||||
|
publicScope.analyze = function () {
|
||||||
|
privateScope.output = {};
|
||||||
|
|
||||||
|
for (var i in privateScope.data) {
|
||||||
|
if (privateScope.data.hasOwnProperty(i)) {
|
||||||
|
privateScope.output[i] = privateScope.data[i] / bufferPeriod * 1000;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
privateScope.data = {};
|
||||||
|
return privateScope.output;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return event list with frequencies
|
||||||
|
* @returns {{}|*}
|
||||||
|
*/
|
||||||
|
publicScope.get = function () {
|
||||||
|
return privateScope.output;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns raw data
|
||||||
|
* @returns {{}|*}
|
||||||
|
*/
|
||||||
|
publicScope.getRaw = function () {
|
||||||
|
return privateScope.data;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Put event into analyzer
|
||||||
|
* @param {object} event
|
||||||
|
*/
|
||||||
|
publicScope.put = function (event) {
|
||||||
|
if (privateScope.data[event]) {
|
||||||
|
privateScope.data[event]++;
|
||||||
|
} else {
|
||||||
|
privateScope.data[event] = 1;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param {number} buffer buffer length in milliseconds
|
||||||
|
*/
|
||||||
|
publicScope.setBufferPeriod = function (buffer) {
|
||||||
|
bufferPeriod = buffer;
|
||||||
|
clearInterval(privateScope.intervalHandler);
|
||||||
|
privateScope.intervalHandler = setInterval(publicScope.analyze, bufferPeriod);
|
||||||
|
};
|
||||||
|
|
||||||
|
privateScope.intervalHandler = setInterval(publicScope.analyze, bufferPeriod);
|
||||||
|
|
||||||
|
return publicScope;
|
||||||
|
})();
|
|
@ -114,6 +114,11 @@ var MSP = {
|
||||||
bufView,
|
bufView,
|
||||||
i;
|
i;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* For debug reasons, check how ofter MSP frames are executed
|
||||||
|
*/
|
||||||
|
helper.eventFrequencyAnalyzer.put(code);
|
||||||
|
|
||||||
// always reserve 6 bytes for protocol overhead !
|
// always reserve 6 bytes for protocol overhead !
|
||||||
if (data) {
|
if (data) {
|
||||||
var size = data.length + 6,
|
var size = data.length + 6,
|
||||||
|
|
|
@ -93,6 +93,7 @@
|
||||||
<script type="text/javascript" src="./tabs/transponder.js"></script>
|
<script type="text/javascript" src="./tabs/transponder.js"></script>
|
||||||
<script type="text/javascript" src="./tabs/osd.js"></script>
|
<script type="text/javascript" src="./tabs/osd.js"></script>
|
||||||
<script type="text/javascript" src="./tabs/profiles.js"></script>
|
<script type="text/javascript" src="./tabs/profiles.js"></script>
|
||||||
|
<script type="text/javascript" src="./js/eventFrequencyAnalyzer.js"></script>
|
||||||
<title></title>
|
<title></title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue