diff --git a/api/detection.js b/api/detection.js new file mode 100644 index 0000000..b4ab1b8 --- /dev/null +++ b/api/detection.js @@ -0,0 +1,78 @@ +const http = require('http'); + +var nCpi = 100; +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); + if (map.length > nCpi) { + map.shift(); + } + 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]); + doppler.push(map[i].delay[j]); + 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; \ No newline at end of file diff --git a/api/maxhold.js b/api/maxhold.js index e3b1425..5ec303e 100644 --- a/api/maxhold.js +++ b/api/maxhold.js @@ -6,12 +6,12 @@ var maxhold = ''; var timestamp = ''; const options_timestamp = { host: '127.0.0.1', - path: '/timestamp', + path: '/api/timestamp', port: 3000 }; const options_map = { host: '127.0.0.1', - path: '/map', + path: '/api/map', port: 3000 }; @@ -74,4 +74,4 @@ function get_data() { return maxhold; }; -module.exports.get_data = get_data; \ No newline at end of file +module.exports.get_data_map = get_data; \ No newline at end of file diff --git a/api/server.js b/api/server.js index 991a6e9..8a0cfd6 100644 --- a/api/server.js +++ b/api/server.js @@ -2,8 +2,8 @@ const express = require('express'); const dgram = require('dgram'); const net = require("net"); -var maxhold = require('./maxhold.js'); -module.exports = Object.assign({}, maxhold) +var data_map = require('./maxhold.js'); +var data_detection = require('./detection.js'); // constants const PORT = 3000; @@ -28,20 +28,23 @@ app.use(function(req, res, next) { app.get('/', (req, res) => { res.send('Hello World'); }); -app.get('/map', (req, res) => { +app.get('/api/map', (req, res) => { res.send(map); }); -app.get('/detection', (req, res) => { +app.get('/api/detection', (req, res) => { res.send(detection); }); -app.get('/timestamp', (req, res) => { +app.get('/api/timestamp', (req, res) => { res.send(timestamp); }); -app.get('/timing', (req, res) => { +app.get('/api/timing', (req, res) => { res.send(timing); }); -app.get('/maxhold', (req, res) => { - res.send(maxhold.get_data()); +app.get('/stash/map', (req, res) => { + res.send(data_map.get_data_map()); +}); +app.get('/stash/detection', (req, res) => { + res.send(data_detection.get_data_detection()); }); // read state of capture app.get('/capture', (req, res) => { diff --git a/html/display/detection/index.html b/html/display/detection/index.html new file mode 100644 index 0000000..35b717d --- /dev/null +++ b/html/display/detection/index.html @@ -0,0 +1,99 @@ + + + + +
+ + + + + + + + +