diff --git a/api/server.js b/api/server.js index 6fa9423..a2f3f63 100644 --- a/api/server.js +++ b/api/server.js @@ -7,6 +7,7 @@ const PORT = 3000; const HOST = '0.0.0.0'; var map = ''; var detection = ''; +var timestamp = ''; var data = ''; var capture = false; @@ -29,6 +30,9 @@ app.get('/map', (req, res) => { app.get('/detection', (req, res) => { res.send(detection); }); +app.get('/timestamp', (req, res) => { + res.send(timestamp); +}); // read state of capture app.get('/capture', (req, res) => { res.send(capture); @@ -77,3 +81,18 @@ const server_detection = net.createServer((socket)=>{ }) }); server_detection.listen(3002); + +// tcp listener timestamp +const server_timestamp = net.createServer((socket)=>{ + socket.write("Hello From Server!") + socket.on("data",(msg)=>{ + data = data + msg.toString(); + console.log('EOF'); + timestamp = data; + data = ''; + }); + socket.on("close",()=>{ + console.log("Connection closed."); + }) +}); +server_timestamp.listen(4000); diff --git a/config/config.yml b/config/config.yml index 0a14636..5b495af 100644 --- a/config/config.yml +++ b/config/config.yml @@ -31,6 +31,7 @@ network: api: 3000 map: 3001 detect: 3002 + timestamp: 4000 save: iq: true diff --git a/config/radar4.yml b/config/radar4.yml index 22074b7..9255be7 100644 --- a/config/radar4.yml +++ b/config/radar4.yml @@ -31,6 +31,7 @@ network: api: 3000 map: 3001 detection: 3002 + timestamp: 4000 save: iq: true diff --git a/html/plot.js b/html/plot.js index 2ca309d..99350a0 100644 --- a/html/plot.js +++ b/html/plot.js @@ -2,6 +2,7 @@ var timestamp = -1; var nRows = 3; var nCols = 3; var host = window.location.hostname; +var timestamp = ''; var isLocalHost = (host === "localhost" || host === "127.0.0.1" || host === "192.168.0.112"); @@ -12,6 +13,13 @@ if (isLocalHost) { urlMap = '//' + host + '/api/map?timestamp=' + Date.now(); } +var urlTimestamp = ''; +if (isLocalHost) { + urlTimestamp = '//' + host + ':3000/timestamp?timestamp=' + Date.now(); +} else { + urlTimestamp = '//' + host + '/api/timestamp?timestamp=' + Date.now(); +} + var data = [ { z: [[0, 0, 0], [0, 0, 0], [0, 0, 0]], @@ -58,78 +66,94 @@ var config = { Plotly.newPlot('ddmap', data, layout, config); var intervalId = window.setInterval(function () { - var apiData = $.getJSON(urlMap, function () { }) + + // check if timestamp is updated + var timestampData = $.get(urlTimestamp, function () { }) .done(function (data) { + if (timestamp != data) { + timestamp = data; + // get new map data + var apiData = $.getJSON(urlMap, function () { }) + .done(function (data) { + // case draw new plot + if (data.nRows != nRows || data.nCols != nCols) { + nRows = data.nRows; + nCols = data.nCols; - // case draw new plot - if (data.nRows != nRows || data.nCols != nCols) { - nRows = data.nRows; - nCols = data.nCols; + data = [ + { + z: data.data, + x: data.delay, + y: data.doppler, + colorscale: 'Jet', + zauto: false, + zmin: 0, + zmax: Math.max(13, data.maxPower), + type: 'heatmap' + } + ]; + layout = { + autosize: false, + margin: { + l: 50, + r: 50, + b: 50, + t: 50, + pad: 0 + }, + width: document.getElementById('ddmap').offsetWidth, + height: document.getElementById('ddmap').offsetHeight, + plot_bgcolor: "rgba(0,0,0,0)", + paper_bgcolor: "rgba(0,0,0,0)", + annotations: [], + displayModeBar: false, + xaxis: { + title: { + text: 'Bistatic Range (km)', + font: { + size: 24 + } + }, + ticks: '', + side: 'bottom' + }, + yaxis: { + title: { + text: 'Bistatic Doppler (Hz)', + font: { + size: 24 + } + }, + ticks: '', + ticksuffix: ' ', + autosize: false, + categoryorder: "total descending" + } + }; + Plotly.newPlot('ddmap', data, layout, { displayModeBar: false }); + } + else { + data_update = + { + 'z': [data.data], + 'zmax': Math.max(13, data.maxPower) + }; + layout_update = { + }; + Plotly.update('ddmap', data_update, layout_update, { displayModeBar: false }); + } - data = [ - { - z: data.data, - x: data.delay, - y: data.doppler, - colorscale: 'Jet', - zauto: false, - zmin: 0, - zmax: Math.max(13, data.maxPower), - type: 'heatmap' - } - ]; - layout = { - autosize: false, - margin: { - l: 50, - r: 50, - b: 50, - t: 50, - pad: 0 - }, - width: document.getElementById('ddmap').offsetWidth, - height: document.getElementById('ddmap').offsetHeight, - plot_bgcolor: "rgba(0,0,0,0)", - paper_bgcolor: "rgba(0,0,0,0)", - annotations: [], - displayModeBar: false, - xaxis: { - title: { - text: 'Bistatic Range (km)', - font: { - size: 24 - } - }, - ticks: '', - side: 'bottom' - }, - yaxis: { - title: { - text: 'Bistatic Doppler (Hz)', - font: { - size: 24 - } - }, - ticks: '', - ticksuffix: ' ', - autosize: false, - categoryorder: "total descending" - } - }; - Plotly.newPlot('ddmap', data, layout, { displayModeBar: false }); + }) + + .fail(function () { + console.log('API Fail'); + }) + + .always(function () { + + }); } - else { - data_update = - { - 'z': [data.data], - 'zmax': Math.max(13, data.maxPower) - }; - layout_update = { - }; - Plotly.update('ddmap', data_update, layout_update, { displayModeBar: false }); - } - }) .fail(function () { @@ -139,4 +163,5 @@ var intervalId = window.setInterval(function () { .always(function () { }); + }, 500); diff --git a/src/blah2.cpp b/src/blah2.cpp index 47318ad..28d90a8 100644 --- a/src/blah2.cpp +++ b/src/blah2.cpp @@ -93,22 +93,28 @@ int main(int argc, char **argv) fftw_plan_with_nthreads(4); // setup socket - uint16_t port_map, port_detection; + uint16_t port_map, port_detection, port_timestamp; std::string ip; tree["network"]["ports"]["map"] >> port_map; tree["network"]["ports"]["detection"] >> port_detection; + tree["network"]["ports"]["timestamp"] >> port_timestamp; tree["network"]["ip"] >> ip; asio::io_service io_service; asio::ip::tcp::socket socket_map(io_service); asio::ip::tcp::socket socket_detection(io_service); + asio::ip::tcp::socket socket_timestamp(io_service); asio::ip::tcp::endpoint endpoint_map; asio::ip::tcp::endpoint endpoint_detection; + asio::ip::tcp::endpoint endpoint_timestamp; endpoint_map = asio::ip::tcp::endpoint( asio::ip::address::from_string(ip), port_map); endpoint_detection = asio::ip::tcp::endpoint( asio::ip::address::from_string(ip), port_detection); + endpoint_timestamp = asio::ip::tcp::endpoint( + asio::ip::address::from_string(ip), port_timestamp); socket_map.connect(endpoint_map); socket_detection.connect(endpoint_detection); + socket_timestamp.connect(endpoint_timestamp); asio::error_code err; std::string subdata; uint32_t MTU = 1024; @@ -228,6 +234,12 @@ int main(int argc, char **argv) auto t7 = std::chrono::high_resolution_clock::now(); double delta_t7 = std::chrono::duration(t7-t0).count(); std::cout << "CPI time (ms): " << delta_t7 << std::endl; + + // output CPI timestamp for updating data + auto t0_duration = t0.time_since_epoch(); + auto t0_ms = std::chrono::duration_cast(t0_duration).count(); + std::string t0_string = std::to_string(t0_ms); + socket_timestamp.write_some(asio::buffer(t0_string, 100), err); } } });