Add truth display to ddmap if enabled in config

This commit is contained in:
30hours 2024-02-11 14:24:23 +00:00
parent 0e16141eda
commit db6d9656cf
2 changed files with 76 additions and 6 deletions

View file

@ -69,6 +69,25 @@ app.get('/api/iqdata', (req, res) => {
app.get('/api/config', (req, res) => { app.get('/api/config', (req, res) => {
res.send(config); res.send(config);
}); });
app.get('/api/adsb2dd', (req, res) => {
if (config.truth.adsb.enabled == true) {
const api_url = "http://adsb2dd.30hours.dev/api/dd";
const api_query =
api_url +
"?rx=" + config.location.rx.latitude + "," +
config.location.rx.longitude + "," +
config.location.rx.altitude +
"&tx=" + config.location.tx.latitude + "," +
config.location.tx.longitude + "," +
config.location.tx.altitude +
"&fc=" + (config.capture.fs / 1000000) +
"&server=" + "http://" + config.truth.adsb.ip;
res.send(api_query);
}
else {
res.status(400).end();
}
});
// stash API // stash API
app.get('/stash/map', (req, res) => { app.get('/stash/map', (req, res) => {

View file

@ -8,6 +8,8 @@ var range_y = [];
// setup API // setup API
var urlTimestamp; var urlTimestamp;
var urlDetection; var urlDetection;
var urlAdsb;
var urlConfig;
if (isLocalHost) { if (isLocalHost) {
urlTimestamp = '//' + host + ':3000/api/timestamp'; urlTimestamp = '//' + host + ':3000/api/timestamp';
} else { } else {
@ -23,10 +25,29 @@ if (isLocalHost) {
} else { } else {
urlMap = '//' + host + urlMap; urlMap = '//' + host + urlMap;
} }
if (isLocalHost) {
urlAdsb = '//' + host + ':3000/api/adsb2dd';
} else {
urlAdsb = '//' + host + '/api/adsb2dd';
}
if (isLocalHost) {
urlConfig = '//' + host + ':3000/api/config';
} else {
urlConfig = '//' + host + '/api/config';
}
urlTimestamp = urlTimestamp + '?timestamp=' + Date.now(); urlTimestamp = urlTimestamp + '?timestamp=' + Date.now();
urlDetection = urlDetection + '?timestamp=' + Date.now(); urlDetection = urlDetection + '?timestamp=' + Date.now();
urlMap = urlMap + '?timestamp=' + Date.now(); urlMap = urlMap + '?timestamp=' + Date.now();
// get truth flag
var isTruth = false;
var configData = $.getJSON(urlConfig, function () { })
.done(function (data_config) {
if (data_config.truth.adsb.enabled === true) {
isTruth = true;
}
});
// setup plotly // setup plotly
var layout = { var layout = {
autosize: true, autosize: true,
@ -65,7 +86,8 @@ var layout = {
ticksuffix: ' ', ticksuffix: ' ',
autosize: false, autosize: false,
categoryorder: "total descending" categoryorder: "total descending"
} },
showlegend: false
}; };
var config = { var config = {
responsive: true, responsive: true,
@ -82,6 +104,7 @@ var data = [
} }
]; ];
var detection = []; var detection = [];
var adsb = {};
Plotly.newPlot('data', data, layout, config); Plotly.newPlot('data', data, layout, config);
@ -101,6 +124,23 @@ var intervalId = window.setInterval(function () {
detection = data_detection; detection = data_detection;
}); });
// get ADS-B data if enabled in config
if (isTruth) {
var adsbData = $.getJSON(urlAdsb, function () { })
.done(function (data_adsb) {
adsb['delay'] = [];
adsb['doppler'] = [];
adsb['flight'] = [];
for (const aircraft in data_adsb) {
if ('doppler' in data_adsb[aircraft]) {
adsb['delay'].push(data_adsb[aircraft]['delay'])
adsb['doppler'].push(data_adsb[aircraft]['doppler'])
adsb['flight'].push(data_adsb[aircraft]['flight'])
}
}
});
}
// get new map data // get new map data
var apiData = $.getJSON(urlMap, function () { }) var apiData = $.getJSON(urlMap, function () { })
.done(function (data) { .done(function (data) {
@ -136,17 +176,28 @@ var intervalId = window.setInterval(function () {
opacity: 0.6 opacity: 0.6
} }
}; };
var trace3 = {
x: adsb.delay,
y: adsb.doppler,
mode: 'markers',
type: 'scatter',
marker: {
size: 16,
opacity: 0.6
}
};
var data_trace = [trace1, trace2]; var data_trace = [trace1, trace2, trace3];
Plotly.newPlot('data', data_trace, layout, config); Plotly.newPlot('data', data_trace, layout, config);
} }
// case update plot // case update plot
else { else {
var trace_update = { var trace_update = {
x: [data.delay, detection.delay], x: [data.delay, detection.delay, adsb.delay],
y: [data.doppler, detection.doppler], y: [data.doppler, detection.doppler, adsb.doppler],
z: [data.data, []], z: [data.data, [], []],
zmax: [Math.max(13, data.maxPower), []] zmax: [Math.max(13, data.maxPower), [], []],
text: [[], [], adsb.flight]
}; };
Plotly.update('data', trace_update); Plotly.update('data', trace_update);
} }