diff --git a/main/traffic.go b/main/traffic.go index d3047f44..daa01a45 100644 --- a/main/traffic.go +++ b/main/traffic.go @@ -13,6 +13,7 @@ import ( "bufio" "encoding/hex" "encoding/json" + //"log" "math" "net" "strconv" @@ -106,7 +107,14 @@ func sendTrafficUpdates() { defer trafficMutex.Unlock() cleanupOldEntries() var msg []byte - for _, ti := range traffic { // TO-DO: Limit number of aircraft in traffic message. ForeFlight chokes at ~1000-2000 messages depending on iDevice RAM. Practical limit likely around 500-1000 aircraft + for icao, ti := range traffic { // TO-DO: Limit number of aircraft in traffic message. ForeFlight 7.5 chokes at ~1000-2000 messages depending on iDevice RAM. Practical limit likely around ~500 aircraft without filtering. + ti.Age = stratuxClock.Time.Sub(ti.Last_seen).Seconds() + traffic[icao] = ti + //log.Printf("Traffic age of %X is %f seconds\n",icao,ti.Age) + if ti.Age > 2 { // if nothing polls an inactive ti, it won't push to the webUI, and its Age won't update. + tiJSON, _ := json.Marshal(&ti) + trafficUpdate.Send(tiJSON) + } if ti.Position_valid && ti.Age < 6 { // ... but don't pass stale data to the EFB. TO-DO: Coast old traffic? Need to determine how FF, WingX, etc deal with stale targets. msg = append(msg, makeTrafficReportMsg(ti)...) } @@ -117,7 +125,7 @@ func sendTrafficUpdates() { } } -// Send update to attached client. +// Send update to attached JSON client. func registerTrafficUpdate(ti TrafficInfo) { if !ti.Position_valid { // Don't send unless a valid position exists. return @@ -377,7 +385,7 @@ func parseDownlinkReport(s string) { ti.Last_source = TRAFFIC_SOURCE_UAT ti.Last_seen = stratuxClock.Time - ti.Age = 0 + //ti.Age = 0 // Parse tail number, if available. if msg_type == 1 || msg_type == 3 { // Need "MS" portion of message. @@ -563,7 +571,7 @@ func esListen() { // Update "last seen" (any type of message, as long as the ICAO addr can be parsed). ti.Last_source = TRAFFIC_SOURCE_1090ES ti.Last_seen = stratuxClock.Time - ti.Age = 0 + //ti.Age = 0 ti.addr_type = 0 //FIXME: ADS-B with ICAO address. Not recognized by ForeFlight. ti.emitter_category = 0x01 //FIXME. "Light" @@ -591,6 +599,11 @@ KOSH, once every five minutes. Inputs are ICAO 24-bit hex code, tail number (8 chars max), relative altitude in feet, groundspeed in knots, and bearing offset from 0 deg initial position. + +Traffic on headings 150-240 (bearings 060-150) is intentionally suppressed from updating to allow +for testing of EFB and webUI response. Additionally, the "on ground" flag is set for headings 240-270, +and speed invalid flag is set for headings 135-150 to allow testing of response to those conditions. + */ func updateDemoTraffic(icao uint32, tail string, relAlt float32, gs float64, offset int32) { var ti TrafficInfo @@ -620,7 +633,10 @@ func updateDemoTraffic(icao uint32, tail string, relAlt float32, gs float64, off ti.Alt = int32(mySituation.Alt + relAlt) ti.Track = uint16(hdg) ti.Speed = uint16(gs) - if hdg > 100 && hdg < 150 { + if hdg >= 240 && hdg < 270 { + ti.OnGround = true + } + if hdg > 135 && hdg < 150 { ti.Speed_valid = false } else { ti.Speed_valid = true @@ -629,13 +645,13 @@ func updateDemoTraffic(icao uint32, tail string, relAlt float32, gs float64, off ti.Tail = tail // "DEMO1234" ti.Timestamp = time.Now() ti.Last_seen = stratuxClock.Time - ti.Age = hdg / 1000 + //ti.Age = math.Floor(ti.Age) + hdg / 1000 ti.Last_source = 1 if icao%7 == 1 { // make some of the traffic UAT sourced ti.Last_source = 2 } - if hdg < 120 || hdg > 240 { + if hdg < 150 || hdg > 240 { // now insert this into the traffic map... trafficMutex.Lock() defer trafficMutex.Unlock() diff --git a/web/plates/js/status.js b/web/plates/js/status.js index c0d57652..593a2562 100755 --- a/web/plates/js/status.js +++ b/web/plates/js/status.js @@ -59,7 +59,7 @@ function StatusCtrl($rootScope, $scope, $state, $http, $interval) { $scope.Clock = clockString; var tempLocalClock = new Date; $scope.LocalClock = tempLocalClock.toUTCString(); - $scope.SecondsFast = (tempClock-tempLocalClock)/1000; + $scope.SecondsFast = (Math.round(tempClock-tempLocalClock)/1000).toFixed(2); var uptime = status.Uptime; diff --git a/web/plates/js/traffic.js b/web/plates/js/traffic.js index 1503bf9a..8ebce0a8 100755 --- a/web/plates/js/traffic.js +++ b/web/plates/js/traffic.js @@ -52,25 +52,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 = obj.Age; + new_traffic.age = (Math.round(obj.Age * 10)/10).toFixed(1); new_traffic.src = obj.Last_source; // 1=ES, 2=UAT // return new_aircraft; } -/* - function getStratuxTime() { - // Simple GET request example (note: response is asynchronous) - $http.get(URL_STATUS_GET). - then(function (response) { - globalStatus = angular.fromJson(response.data); - $scope.UptimeClock = globalStatus.UptimeClock; - $scope.Clock = globalStatus.Clock; - $scope.LocalClock = new Date(); - }, function (response) { - // nop - }); - }; -*/ - + function connect($scope) { if (($scope === undefined) || ($scope === null)) @@ -155,15 +141,14 @@ function TrafficCtrl($rootScope, $scope, $state, $http, $interval) { - - // perform cleanup every 60 seconds + // perform cleanup every 10 seconds var clearStaleTraffic = $interval(function () { - // remove stale aircraft = anything more than 180 seconds without an update + // remove stale aircraft = anything more than 60 seconds without an update var dirty = false; - var cutoff = Date.now() - (180 * 1000); + var cutoff =60; for (var i = len = $scope.data_list.length; i > 0; i--) { - if ($scope.data_list[i - 1].age < cutoff) { + if ($scope.data_list[i - 1].age > cutoff) { $scope.data_list.splice(i - 1, 1); dirty = true; } @@ -172,7 +157,7 @@ function TrafficCtrl($rootScope, $scope, $state, $http, $interval) { $scope.raw_data = ""; $scope.$apply(); } - }, (1000 * 60), 0, false); + }, (1000 * 10), 0, false); $state.get('traffic').onEnter = function () { diff --git a/web/plates/status-help.html b/web/plates/status-help.html index 17662e08..8ec44d6d 100755 --- a/web/plates/status-help.html +++ b/web/plates/status-help.html @@ -1,17 +1,14 @@
The Status page provides an overview of your Stratux device.
-The current state of you device is shown at th top - Connected
in green or Disconected
in red.
The current state of you device is shown at the top - Connected
in green or Disconected
in red.
Depending on the hardware you have installed in your Stratux, you will have status for the following:
+Depending on the hardware you have installed in your Stratux, status messages will be shown for the following:
NOTE: This page only shows devices you have installed and turned on (via the Settings page.
+Devices must be manually enabled on the Settings page.
-The Messages section gives you details for messages received. There are statistics for the rolling average for the past 60 seconds as well as the peak average.
-For GPS and AHRS you can view the number of satellites being received and if AHRS is configured and operating.
-The Status page also gives you an indication of how long your Stratux devices has been operating since you turned it on, as well as reporting the on-board temperature sensor of the Raspberry Pi.
+Additional statistics include the number of detected software-defined radios (SDRs), number of current DHCP network clients, uptime, temperature of the Raspberry Pi CPU, and the current clock settings on both the Raspberry Pi and the device / browser used to view this page.
The Traffic page provides a list of recent aircraft received. 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 is not received for 3 minutes (180 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 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.
For each aircraft, the list includes the following details:
NOTE: When this page becomes active (aka it is selected from the menu) it will display only new traffic. Older traffic and existing traffic will not appear until their next report.
+Stratux Clock and Device Clock are the UTC timestamps reported by the Stratux and by the web browser on your mobile device, respectively.