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++)
|
|
|
|
{
|
|
|
|
console.log((ts - map[i].timestamp)/1000);
|
|
|
|
if ((ts - map[i].timestamp)/1000 > time)
|
|
|
|
{
|
|
|
|
map.shift();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2023-12-05 13:14:00 +00:00
|
|
|
}
|
|
|
|
delay = [];
|
|
|
|
doppler = [];
|
|
|
|
timestamp = [];
|
|
|
|
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]);
|
2023-12-05 13:14:00 +00:00
|
|
|
timestamp.push(map[i].timestamp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
output = {
|
|
|
|
timestamp: timestamp,
|
|
|
|
delay: delay,
|
|
|
|
doppler: doppler
|
|
|
|
};
|
|
|
|
} catch (e) {
|
|
|
|
console.error(e.message);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
setInterval(update_data, 100);
|
|
|
|
|
|
|
|
function get_data() {
|
|
|
|
return output;
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports.get_data_detection = get_data;
|