From 4a3becd1b79e55c19f21a13ad42103baf3e32ab3 Mon Sep 17 00:00:00 2001 From: Matthias Wirth Date: Mon, 29 Jul 2019 19:51:41 +0200 Subject: [PATCH] add support to display SkyView978 json file --- default | 4 ++ html/index.html | 2 + html/planeObject.js | 3 ++ html/script.js | 110 +++++++++++++++++++++++++++++++------------- html/style.css | 20 ++------ tar1090.sh | 32 +++++++++++-- 6 files changed, 118 insertions(+), 53 deletions(-) diff --git a/default b/default index b47c8c0..4f7f85a 100644 --- a/default +++ b/default @@ -1,2 +1,6 @@ INTERVAL=10 HISTORY_SIZE=360 +# Change to yes to enable UAT/978 display in tar1090 +ENABLE_978=no +# If running dump978-fa on another computer, modify the IP-address as appropriate. +URL_978="http://127.0.0.1/skyview978" diff --git a/html/index.html b/html/index.html index 9c284ce..8b3bbe7 100644 --- a/html/index.html +++ b/html/index.html @@ -264,6 +264,8 @@
ADS-B
+
+
UAT
MLAT
diff --git a/html/planeObject.js b/html/planeObject.js index bd4eed3..84a7ca3 100644 --- a/html/planeObject.js +++ b/html/planeObject.js @@ -8,6 +8,7 @@ function PlaneObject(icao) { this.squawk = null; this.selected = false; this.category = null; + this.uat = false; // Basic location information this.altitude = null; @@ -305,6 +306,8 @@ PlaneObject.prototype.getDataSource = function() { if (this.position_from_mlat) { return 'mlat'; } + if (this.uat) + return 'uat'; // Not MLAT, but position reported - ADSB or variants if (this.position != null) { diff --git a/html/script.js b/html/script.js index e2b137c..145ab81 100644 --- a/html/script.js +++ b/html/script.js @@ -19,6 +19,7 @@ var customAltitudeColors = true; var loadtime = "loadtime"; var HistoryChunks = false; var refresh; +var enable_uat = false; var SpecialSquawks = { '7500' : { cssClass: 'squawk7500', markerColor: 'rgb(255, 85, 85)', text: 'Aircraft Hijacking' }, @@ -43,6 +44,7 @@ var SitePosition = null; var LastReceiverTimestamp = 0; var StaleReceiverCount = 0; var FetchPending = null; +var FetchPendingUAT = null; var MessageCountHistory = []; var MessageRate = 0; @@ -54,22 +56,38 @@ var layers; // piaware vs flightfeeder var isFlightFeeder = false; -function processReceiverUpdate(data, locOnly) { +function processReceiverUpdate(data, locOnly, uat) { + // Loop through all the planes in the data packet var now = data.now; var acs = data.aircraft; - // Detect stats reset - if (MessageCountHistory.length > 0 && MessageCountHistory[MessageCountHistory.length-1].messages > data.messages) { - MessageCountHistory = [{'time' : MessageCountHistory[MessageCountHistory.length-1].time, - 'messages' : 0}]; - } + // Note this is only present in the history jsons + if (data.uat_978 && data.uat_978 == "true") + uat = true; - // Note the message count in the history - MessageCountHistory.push({ 'time' : now, 'messages' : data.messages}); - // .. and clean up any old values - if ((now - MessageCountHistory[0].time) > 30) - MessageCountHistory.shift(); + if (!uat) { + // Detect stats reset + if (MessageCountHistory.length > 0 && MessageCountHistory[MessageCountHistory.length-1].messages > data.messages) { + MessageCountHistory = [{'time' : MessageCountHistory[MessageCountHistory.length-1].time, + 'messages' : 0}]; + } + + // Note the message count in the history + MessageCountHistory.push({ 'time' : now, 'messages' : data.messages}); + // .. and clean up any old values + if ((now - MessageCountHistory[0].time) > 30) + MessageCountHistory.shift(); + + if (MessageCountHistory.length > 1) { + var message_time_delta = MessageCountHistory[MessageCountHistory.length-1].time - MessageCountHistory[0].time; + var message_count_delta = MessageCountHistory[MessageCountHistory.length-1].messages - MessageCountHistory[0].messages; + if (message_time_delta > 0) + MessageRate = message_count_delta / message_time_delta; + } else { + MessageRate = null; + } + } for (var j=0; j < acs.length; j++) { var ac = acs[j]; @@ -88,6 +106,9 @@ function processReceiverUpdate(data, locOnly) { plane.filter = PlaneFilter; plane.tr = PlaneRowTemplate.cloneNode(true); + if (uat && ac.type && ac.type.substring(0,4) == "adsb") + plane.uat = true; + if (hex[0] === '~') { // Non-ICAO address plane.tr.cells[0].textContent = hex.substring(1); @@ -142,6 +163,12 @@ function fetchData() { return; } + if (enable_uat) { + FetchPendingUAT = $.ajax({ url: '/chunks/978.json', + timeout: 5000, + cache: false, + dataType: 'json' }); + } FetchPending = $.ajax({ url: 'data/aircraft.json', timeout: 5000, cache: false, @@ -168,6 +195,12 @@ function fetchData() { refreshClock(new Date(now * 1000)); processReceiverUpdate(data); + if (enable_uat) { + FetchPendingUAT.done(function(data) { + processReceiverUpdate(data, false, true); + }); + } + // update timestamps, visibility, history track for all planes - not only those updated for (var i = 0; i < PlanesOrdered.length; ++i) { var plane = PlanesOrdered[i]; @@ -409,6 +442,8 @@ function initialize() { ).done(function(data) { HistoryChunks = true; PositionHistorySize = data.chunks; + enable_uat = (data.enable_uat == "true"); + console.log("UAT/978 enabled!"); initialize_map(); start_load_history(); }).fail(function() { @@ -481,11 +516,11 @@ function load_history_chunk(i) { dataType: 'json' }) - .done(function(data) { + .done(function(json) { $("#loader_progress").attr('value',HistoryItemsReturned); - for (var i in data.files) { - PositionHistoryBuffer.push(data.files[i]); + for (var i in json.files) { + PositionHistoryBuffer.push(json.files[i]); } HistoryItemsReturned++; @@ -513,7 +548,7 @@ function end_load_history() { //console.log("Done loading history"); if (PositionHistoryBuffer.length > 0) { - var now, last=0; + var now=0, last=0, uat_last=0; // Sort history by timestamp console.log("Sorting history"); @@ -521,30 +556,41 @@ function end_load_history() { // Process history for (var h = 0; h < PositionHistoryBuffer.length; ++h) { - now = PositionHistoryBuffer[h].now; + var data = PositionHistoryBuffer[h]; + var uat = false; + if (data.uat_978 && data.uat_978 == "true") + uat = true; + + + now = data.now; if (h%100==99) console.log("Applying history " + (h + 1) + "/" + PositionHistoryBuffer.length + " at: " + now); - processReceiverUpdate(PositionHistoryBuffer[h], true); + processReceiverUpdate(data, true); // update track //console.log("Updating tracks at: " + now); for (var i = 0; i < PlanesOrdered.length; ++i) { var plane = PlanesOrdered[i]; - plane.updateTrack(now, last); + plane.updateTrack(now, uat ? uat_last : last); } - if(h%180 == 49) { + if(false) { for (var i = 0; i < PlanesOrdered.length; ++i) { var plane = PlanesOrdered[i]; - plane.updateTick(now, last); + plane.updateTick(now, uat ? uat_last : last); } refreshTableInfo(); reaper(); } - last = now; - LastReceiverTimestamp = last; + if (uat) { + uat_last = now; + } else { + last = now; + LastReceiverTimestamp = last; + } + } // Final pass to update all planes to their latest state @@ -971,14 +1017,6 @@ function refreshPageTitle() { // Refresh the detail window about the plane function refreshSelected() { - if (MessageCountHistory.length > 1) { - var message_time_delta = MessageCountHistory[MessageCountHistory.length-1].time - MessageCountHistory[0].time; - var message_count_delta = MessageCountHistory[MessageCountHistory.length-1].messages - MessageCountHistory[0].messages; - if (message_time_delta > 0) - MessageRate = message_count_delta / message_time_delta; - } else { - MessageRate = null; - } refreshPageTitle(); @@ -1086,7 +1124,9 @@ function refreshSelected() { $('#selected_follow').css('font-weight', 'normal'); } } - if (selected.getDataSource() === "adsb_icao") { + if (selected.uat) { + $('#selected_source').text("UAT"); + } else if (selected.getDataSource() === "adsb_icao") { $('#selected_source').text("ADS-B"); } else if (selected.getDataSource() === "tisb_trackfile" || selected.getDataSource() === "tisb_icao" || selected.getDataSource() === "tisb_other") { $('#selected_source').text("TIS-B"); @@ -1270,7 +1310,9 @@ function refreshHighlighted() { $('#higlighted_icaotype').text("n/a"); } - if (highlighted.getDataSource() === "adsb_icao") { + if (selected.uat) { + $('#highlighted_source').text("UAT"); + } else if (highlighted.getDataSource() === "adsb_icao") { $('#highlighted_source').text("ADS-B"); } else if (highlighted.getDataSource() === "tisb_trackfile" || highlighted.getDataSource() === "tisb_icao" || highlighted.getDataSource() === "tisb_other") { $('#highlighted_source').text("TIS-B"); @@ -1333,7 +1375,9 @@ function refreshTableInfo() { ++TrackedAircraftPositions; } - if (tableplane.getDataSource() === "adsb_icao") { + if (tableplane.uat) { + classes += " uat"; + } else if (tableplane.getDataSource() === "adsb_icao") { classes += " vPosition"; } else if (tableplane.getDataSource() === "tisb_trackfile" || tableplane.getDataSource() === "tisb_icao" || tableplane.getDataSource() === "tisb_other") { classes += " tisb"; diff --git a/html/style.css b/html/style.css index 21168fa..4cf92cf 100644 --- a/html/style.css +++ b/html/style.css @@ -223,8 +223,9 @@ div#loader { z-index: 99; position: absolute; left: 0; top: 0; bottom: 0; right: text-transform: uppercase; } -.vPosition { background-color: #E5F6FC; } -.mlat { background-color: #FDF2E5; } +.vPosition { background-color: #D5E6EC; } +.mlat { background-color: #ffe8bd; } +.uat { background-color: #B5F0E6; } .other { background-color: #CCD5F8; } .tisb { background-color: #FFF3B8; } .squawk7500 { font-weight: bold; background-color: #ff5555; } @@ -578,21 +579,6 @@ select.error, textarea.error, input.error { -webkit-border-radius: 4px; } -#adsbLegendBox { - background-color: #E5F6FC; -} - -#mlatLegendBox { - background-color: #FDF2E5; -} - -#otherLegendBox { - background-color: #E6E6E6; -} - -#tisbLegendBox { - background-color: #CCD5DF; -} .legendTitle { line-height: 19px; diff --git a/tar1090.sh b/tar1090.sh index bd9a3fe..682f22c 100755 --- a/tar1090.sh +++ b/tar1090.sh @@ -21,16 +21,25 @@ fi while true do cd $dir + rm -f $dir/*.gz + rm -f $dir/*.json if ! cp $SOURCE/receiver.json chunks.json then sleep 60 continue fi - sed -i -e "s/history\" : [0-9]*/chunks\" : $actual_chunks/" chunks.json + if [[ $ENABLE_978 == "yes" ]]; then + sed -i -e "s?history\" : [0-9]*?chunks\" : $actual_chunks, \"enable_uat\" : \"true\"?" chunks.json + else + sed -i -e "s/history\" : [0-9]*/chunks\" : $actual_chunks/" chunks.json + fi i=0 j=0 + + sleep 2; + while true do sleep $INTERVAL & @@ -44,15 +53,24 @@ do fi sed -i -e '$a,' history_$((i%$CS)).json + if [[ $ENABLE_978 == "yes" ]]; then + cp $dir/978.json $dir/978_history_$((i%$CS)).json + sed -i -e 's/,"now":/,"uat_978":"true","now":/' -e '$a,' 978_history_$((i%$CS)).json + fi + + if [[ $((i%6)) == 5 ]] then - sed -e '1i{ "files" : [' -e '$a]}' -e '$d' history_*.json | gzip -1 > temp.gz + sed -e '1i{ "files" : [' -e '$a]}' -e '$d' *history_*.json | gzip -1 > temp.gz mv temp.gz chunk_$j.gz rm -f latest_*.json chunk_$(($actual_chunks - 1)).gz else cp history_$((i%$CS)).json latest_$((i%6)).json - sed -e '1i{ "files" : [' -e '$a]}' -e '$d' latest_*.json | gzip -1 > temp.gz + if [[ $ENABLE_978 == "yes" ]]; then + cp 978_history_$((i%$CS)).json 978_latest_$((i%6)).json + fi + sed -e '1i{ "files" : [' -e '$a]}' -e '$d' *latest_*.json | gzip -1 > temp.gz mv temp.gz chunk_$(($actual_chunks - 1)).gz fi @@ -80,6 +98,14 @@ do sleep 5 done & +while [[ $ENABLE_978 == "yes" ]] +do + sleep 1 & + wget -T 2 -q -O $dir/978.tmp $URL_978/data/aircraft.json + mv $dir/978.tmp $dir/978.json + wait +done & + wait exit 0