From d00ab538cd20c81aed884a9c7bf280277bb6c4c7 Mon Sep 17 00:00:00 2001 From: AvSquirrel Date: Sun, 17 Apr 2016 12:17:11 +0000 Subject: [PATCH] Traffic UI updates from gpsattitude branch --- web/plates/js/traffic.js | 85 ++++++++++++++++++++++---- web/plates/traffic-help.html | 28 +++++---- web/plates/traffic.html | 112 ++++++++++++++++++++++++++++++----- 3 files changed, 190 insertions(+), 35 deletions(-) diff --git a/web/plates/js/traffic.js b/web/plates/js/traffic.js index 56711a74..c15fdf7b 100755 --- a/web/plates/js/traffic.js +++ b/web/plates/js/traffic.js @@ -6,9 +6,10 @@ function TrafficCtrl($rootScope, $scope, $state, $http, $interval) { $scope.$parent.helppage = 'plates/traffic-help.html'; $scope.data_list = []; + $scope.data_list_invalid = []; + - function utcTimeString(epoc) { var time = ""; @@ -23,6 +24,7 @@ function TrafficCtrl($rootScope, $scope, $state, $http, $interval) { time += "Z"; return time; } +/* function dmsString(val) { return [0 | val, @@ -32,17 +34,33 @@ function TrafficCtrl($rootScope, $scope, $state, $http, $interval) { 0 | val * 60 % 1 * 60, '"'].join(''); } +*/ +// chop off seconds for space + function dmsString(val) { + return [0 | val, + '° ', + 0 | (val < 0 ? val = -val : val) % 1 * 60, + "' "].join(''); + } + + function setAircraft(obj, new_traffic) { new_traffic.icao_int = obj.Icao_addr; new_traffic.targettype = obj.TargetType; - new_traffic.signal = obj.SignalLevel.toFixed(2); + new_traffic.signal = obj.SignalLevel; new_traffic.addr_symb ='\u2708'; if (new_traffic.targettype > 3) { new_traffic.addr_symb ='\ud83d\udce1'; } new_traffic.icao = obj.Icao_addr.toString(16).toUpperCase(); new_traffic.tail = obj.Tail; + if (obj.Squawk == 0) { + new_traffic.squawk = "----"; + } else { + new_traffic.squawk = obj.Squawk; + } + new_traffic.addr_type = obj.Addr_type; new_traffic.lat = dmsString(obj.Lat); new_traffic.lon = dmsString(obj.Lng); var n = Math.round(obj.Alt / 25) * 25; @@ -58,8 +76,11 @@ function TrafficCtrl($rootScope, $scope, $state, $http, $interval) { new_traffic.vspeed = Math.round(obj.Vvel / 100) * 100 var timestamp = Date.parse(obj.Timestamp); new_traffic.time = utcTimeString(timestamp); - new_traffic.age = (Math.round(obj.Age * 10)/10).toFixed(1); + new_traffic.age = obj.Age; + new_traffic.ageLastAlt = obj.AgeLastAlt; new_traffic.src = obj.Last_source; // 1=ES, 2=UAT + new_traffic.bearing = Math.round(obj.Bearing); // degrees true + new_traffic.dist = (obj.Distance/1852); // nautical miles // return new_aircraft; } @@ -101,9 +122,11 @@ function TrafficCtrl($rootScope, $scope, $state, $http, $interval) { var message = JSON.parse(msg.data); $scope.raw_data = angular.toJson(msg.data, true); - if (message.Position_valid) { + + // we need to use an array so AngularJS can perform sorting; it also means we need to loop to find an aircraft in the traffic set var found = false; + var foundInvalid = false; for (var i = 0, len = $scope.data_list.length; i < len; i++) { if ($scope.data_list[i].icao_int === message.Icao_addr) { setAircraft(message, $scope.data_list[i]); @@ -111,13 +134,39 @@ function TrafficCtrl($rootScope, $scope, $state, $http, $interval) { break; } } - if (!found) { + + for (var i = 0, len = $scope.data_list_invalid.length; i < len; i++) { + if ($scope.data_list_invalid[i].icao_int === message.Icao_addr) { + setAircraft(message, $scope.data_list_invalid[i]); + foundInvalid = true; + break; + } + } + + if ((!found) && (message.Position_valid)) { var new_traffic = {}; setAircraft(message, new_traffic); - $scope.data_list.unshift(new_traffic); // add to start of array + $scope.data_list.unshift(new_traffic); // add to start of main array if position is valid and removed from the invalid array + for (var i = 0, len = $scope.data_list_invalid.length; i < len; i++) { + if ($scope.data_list_invalid[i].icao_int === message.Icao_addr) { + $scope.data_list_invalid.splice(i, 1); + } + } + + } else if ((!foundInvalid) && (!message.Position_valid)) { + + var new_traffic = {}; + setAircraft(message, new_traffic); + $scope.data_list_invalid.unshift(new_traffic); // otherwise add to start of invalid array } + $scope.$apply(); - } + + + + + + }; } @@ -137,20 +186,23 @@ function TrafficCtrl($rootScope, $scope, $state, $http, $interval) { var tempLocalClock = new Date; $scope.LocalClock = tempLocalClock.toUTCString(); $scope.SecondsFast = (tempClock-tempLocalClock)/1000; + + $scope.GPS_connected = globalStatus.GPS_connected; }, function (response) { // nop }); }, 500, 0, false); - - - + + + // perform cleanup every 10 seconds var clearStaleTraffic = $interval(function () { - // remove stale aircraft = anything more than 59 seconds without an update + // remove stale aircraft = anything more than 59 seconds without a position update var dirty = false; + var dirtyInvalid = false; var cutoff =59; for (var i = len = $scope.data_list.length; i > 0; i--) { @@ -163,6 +215,17 @@ function TrafficCtrl($rootScope, $scope, $state, $http, $interval) { $scope.raw_data = ""; $scope.$apply(); } + + for (var i = len = $scope.data_list_invalid.length; i > 0; i--) { + if (($scope.data_list_invalid[i - 1].age >= cutoff) || ($scope.data_list_invalid[i - 1].ageLastAlt >= cutoff)) { + $scope.data_list_invalid.splice(i - 1, 1); + dirtyInvalid = true; + } + } + if (dirtyInvalid) { + $scope.raw_data = ""; + $scope.$apply(); + } }, (1000 * 10), 0, false); diff --git a/web/plates/traffic-help.html b/web/plates/traffic-help.html index b6122370..e956f64e 100755 --- a/web/plates/traffic-help.html +++ b/web/plates/traffic-help.html @@ -1,17 +1,25 @@
-

The Traffic page provides a list of all aircraft position reports received within the last 60 seconds. Each time a new aircraft is reported, it is added to the list. Each time a new report is received for an existing aircraft, the list is updated. If a report for an aircraft has not been received within the last 60 seconds, the aircraft is removed from the list.

+

The Traffic page provides a list of all aircraft position reports received within the last 60 seconds. Each time a new aircraft is detected, it is added to the list. Each time a new report is received for an existing aircraft, the list is updated. If a valid position for an aircraft has not been received within the last 60 seconds, the aircraft is removed from the list.

For each aircraft, the list includes the following details:

-
\ No newline at end of file diff --git a/web/plates/traffic.html b/web/plates/traffic.html index 4fff4dbf..d7259f90 100755 --- a/web/plates/traffic.html +++ b/web/plates/traffic.html @@ -1,32 +1,38 @@
- Traffic + ADS-B and TIS-B Traffic {{ConnectState}} {{ConnectState}}
- Flight - Speed - Altitude  - Course + Callsign + Speed + Altitude  + Course
  - Location - Power (dB) - Age + Location + Dist (NM) + Bearing + Power (dB) + Fix Age
-
+
- {{aircraft.addr_symb}} {{aircraft.tail}} - {{aircraft.addr_symb}} {{aircraft.icao}} +
+ {{aircraft.addr_symb}} {{aircraft.tail}} + {{aircraft.addr_symb}} [unknown] +
+
{{aircraft.addr_type == 3 ? "TFID" : "ICAO"}}: {{aircraft.icao}}
+
Squawk: 000{{aircraft.squawk}}
{{aircraft.speed}} KTS @@ -39,13 +45,91 @@
  - {{aircraft.lat}} {{aircraft.lon}} - {{aircraft.signal}} + {{aircraft.lat}} {{aircraft.lon}} + {{aircraft.dist.toFixed(1)}} + {{aircraft.bearing}}° + {{aircraft.signal.toFixed(2)}} - {{aircraft.age}}s + {{aircraft.age.toFixed(1)}}s
+ + +
+ +
+
+ Basic Mode S Messages and Other No-Position Traffic +
+
+
+
+ Callsign + Speed + Altitude  + Course +
+
+   + Squawk + Power (dB) + Age +
+
+ +
+
+
+ +
+ {{aircraft.addr_symb}} {{aircraft.tail}} + {{aircraft.addr_symb}} [unknown] +
+
ICAO: {{aircraft.icao}}
+
+ + {{aircraft.speed}} KTS + {{aircraft.alt}} + + {{aircraft.vspeed}} + {{0-aircraft.vspeed}} + + 00{{aircraft.heading}}° +
+
+   + 000{{aircraft.squawk}} + {{aircraft.signal.toFixed(2)}} + + {{aircraft.ageLastAlt.toFixed(1)}}s +
+
+
+ + + +