2023-12-05 13:14:00 +00:00
|
|
|
const http = require('http');
|
|
|
|
|
2024-01-02 11:14:13 +00:00
|
|
|
var time = 300;
|
2023-12-05 13:14:00 +00:00
|
|
|
var map = [];
|
|
|
|
var timestamp = [];
|
|
|
|
var delay = [];
|
|
|
|
var doppler = [];
|
|
|
|
var detection = '';
|
|
|
|
var ts = '';
|
|
|
|
var output = [];
|
|
|
|
const options_timestamp = {
|
|
|
|
host: '127.0.0.1',
|
|
|
|
path: '/api/timestamp',
|
|
|
|
port: 3000
|
|
|
|
};
|
|
|
|
const options_detection = {
|
|
|
|
host: '127.0.0.1',
|
|
|
|
path: '/api/detection',
|
|
|
|
port: 3000
|
|
|
|
};
|
|
|
|
|
|
|
|
function update_data() {
|
|
|
|
|
|
|
|
// check if timestamp is updated
|
|
|
|
http.get(options_timestamp, function(res) {
|
|
|
|
res.setEncoding('utf8');
|
|
|
|
res.on('data', function (body) {
|
|
|
|
if (ts != body)
|
|
|
|
{
|
|
|
|
ts = body;
|
|
|
|
http.get(options_detection, function(res) {
|
|
|
|
let body_map = '';
|
|
|
|
res.setEncoding('utf8');
|
|
|
|
res.on('data', (chunk) => {
|
|
|
|
body_map += chunk;
|
|
|
|
});
|
|
|
|
res.on('end', () => {
|
|
|
|
try {
|
|
|
|
detection = JSON.parse(body_map);
|
|
|
|
map.push(detection);
|
2024-01-02 11:14:13 +00:00
|
|
|
for (i = 0; i < map.length; i++)
|
|
|
|
{
|
|
|
|
if ((ts - map[i].timestamp)/1000 > time)
|
|
|
|
{
|
|
|
|
map.shift();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2023-12-05 13:14:00 +00:00
|
|
|
}
|
|
|
|
delay = [];
|
|
|
|
doppler = [];
|
|
|
|
timestamp = [];
|
2024-03-03 00:40:25 +00:00
|
|
|
snr = [];
|
2023-12-05 13:14:00 +00:00
|
|
|
for (var i = 0; i < map.length; i++)
|
|
|
|
{
|
|
|
|
for (var j = 0; j < map[i].delay.length; j++)
|
|
|
|
{
|
|
|
|
delay.push(map[i].delay[j]);
|
2023-12-07 11:15:04 +00:00
|
|
|
doppler.push(map[i].doppler[j]);
|
2024-03-03 00:40:25 +00:00
|
|
|
snr.push(map[i].snr[j]);
|
2023-12-05 13:14:00 +00:00
|
|
|
timestamp.push(map[i].timestamp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
output = {
|
|
|
|
timestamp: timestamp,
|
|
|
|
delay: delay,
|
2024-03-03 00:40:25 +00:00
|
|
|
doppler: doppler,
|
|
|
|
snr: snr
|
2023-12-05 13:14:00 +00:00
|
|
|
};
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e.message);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
setInterval(update_data, 100);
|
|
|
|
|
|
|
|
function get_data() {
|
|
|
|
return output;
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports.get_data_detection = get_data;
|