\ No newline at end of file
diff --git a/web/js/main.js b/web/js/main.js
index 0c4160aa..916e439f 100755
--- a/web/js/main.js
+++ b/web/js/main.js
@@ -12,67 +12,22 @@ var appControllers = angular.module('appControllers', []);
app.config(function ($stateProvider, $urlRouterProvider) {
- $stateProvider
- .state('home', {
- url: '/',
- templateUrl: 'plates/status.html',
- controller: 'StatusCtrl',
- reloadOnSearch: false
- })
- .state('weather', {
- url: '/weather',
- templateUrl: 'plates/weather.html',
- controller: 'WeatherCtrl',
- reloadOnSearch: false
- })
- .state('traffic', {
- url: '/traffic',
- templateUrl: 'plates/traffic.html',
- controller: 'TrafficCtrl',
- reloadOnSearch: false
- })
- .state('gps', {
- url: '/gps',
- templateUrl: 'plates/gps.html',
- controller: 'GPSCtrl',
- reloadOnSearch: false
- })
- .state('ahrs', {
- url: '/ahrs',
- templateUrl: 'plates/ahrs.html',
- controller: 'AHRSCtrl',
- reloadOnSearch: false
- })
- .state('logs', {
- url: '/logs',
- templateUrl: 'plates/logs.html',
- controller: 'LogsCtrl',
- reloadOnSearch: false
- })
- .state('settings', {
- url: '/settings',
- templateUrl: 'plates/settings.html',
- controller: 'SettingsCtrl',
- reloadOnSearch: false
- });
-
- $urlRouterProvider.otherwise('/');
+ $stateProvider
+ .state('home', { url: '/', templateUrl: 'plates/status.html', controller: 'StatusCtrl', reloadOnSearch: false })
+ .state('weather', { url: '/weather', templateUrl: 'plates/weather.html', controller: 'WeatherCtrl', reloadOnSearch: false })
+ .state('traffic', { url: '/traffic', templateUrl: 'plates/traffic.html', controller: 'TrafficCtrl', reloadOnSearch: false })
+ .state('gps', { url: '/gps', templateUrl: 'plates/gps.html', controller: 'GPSCtrl', reloadOnSearch: false })
+ .state('logs', { url: '/logs', templateUrl: 'plates/logs.html', controller: 'LogsCtrl', reloadOnSearch: false })
+ .state('settings', { url: '/settings', templateUrl: 'plates/settings.html',controller: 'SettingsCtrl', reloadOnSearch: false });
+ $urlRouterProvider.otherwise('/');
});
app.run(function ($transform) {
- window.$transform = $transform;
+ window.$transform = $transform;
});
-/*
-app.config(function ($httpProvider) {
- // We need to setup some parameters for http requests
- // These three lines are all you need for CORS support
- $httpProvider.defaults.useXDomain = true;
- // $httpProvider.defaults.withCredentials = true;
- delete $httpProvider.defaults.headers.common['X-Requested-With'];
-});
-*/
-// For this app we have a MainController for whatever and the nindividual controllers for each page
+
+// For this app we have a MainController for whatever and individual controllers for each page
app.controller('MainCtrl', function ($rootScope, $scope) {
- // any logic global logic
+ // any logic global logic
});
\ No newline at end of file
diff --git a/web/plates/ahrs.html b/web/plates/ahrs.html
deleted file mode 100755
index 9f0ca40b..00000000
--- a/web/plates/ahrs.html
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-
AHRS Status
-
-
-
-
-
-
- this space reserved to display AHRS status
-
-
-
\ No newline at end of file
diff --git a/web/plates/gps.html b/web/plates/gps.html
index f2707c49..08f37572 100755
--- a/web/plates/gps.html
+++ b/web/plates/gps.html
@@ -4,10 +4,10 @@
-
+
- this space reserved to display GPS status
+ this space reserved to display GPS/AHRS status
\ No newline at end of file
diff --git a/web/plates/help.html b/web/plates/help.html
deleted file mode 100755
index f7e4dfc9..00000000
--- a/web/plates/help.html
+++ /dev/null
@@ -1,21 +0,0 @@
-
-
-
-
-
-
-
Help
-
-
-
-
-
-
- this space reserved to display context sensitive help
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/web/plates/js/ahrs.js b/web/plates/js/ahrs.js
deleted file mode 100755
index 7b5201f9..00000000
--- a/web/plates/js/ahrs.js
+++ /dev/null
@@ -1,15 +0,0 @@
-angular.module('appControllers').controller('AHRSCtrl', AHRSCtrl); // get the main module contollers set
-AHRSCtrl.$inject = ['$rootScope', '$scope', '$state', '$http']; // Inject my dependencies
-
-// create our controller function with all necessary logic
-function AHRSCtrl($rootScope, $scope, $state, $http) {
-
- /*
- $state.get('weather').onEnter = function () {
- };
- $state.get('weather').onExit = function () {
- };
- */
-
- // Weather Controller tasks go here
-};
\ No newline at end of file
diff --git a/web/plates/js/settings.js b/web/plates/js/settings.js
index 5ce9bb8d..a9feefb5 100755
--- a/web/plates/js/settings.js
+++ b/web/plates/js/settings.js
@@ -49,7 +49,7 @@ function SettingsCtrl($rootScope, $scope, $state, $http) {
$scope.AHRS_Enabled = settings.AHRS_Enabled;
$scope.DEBUG = settings.DEBUG;
$scope.ReplayLog = settings.ReplayLog;
- $scope.PPM = parseInt(settings.PPM);
+ $scope.PPM = settings.PPM;
// $scope.$apply();
}, function (response) {
$scope.rawSettings = "error setting settings";
@@ -82,9 +82,9 @@ function SettingsCtrl($rootScope, $scope, $state, $http) {
$scope.updateppm = function() {
if (($scope.PPM !== undefined) && ($scope.PPM !== null) && $scope.PPM !== settings["PPM"]) {
- settings["PPM"] = $scope.PPM;
+ settings["PPM"] = parseInt($scope.PPM);
newsettings = {
- "PPM": $scope.PPM
+ "PPM": parseInt($scope.PPM)
};
console.log(angular.toJson(newsettings));
setSettings(angular.toJson(newsettings));
diff --git a/web/plates/js/status.js b/web/plates/js/status.js
index a10b832c..287afc3f 100755
--- a/web/plates/js/status.js
+++ b/web/plates/js/status.js
@@ -11,8 +11,7 @@ function StatusCtrl($rootScope, $scope, $state, $http) {
return; // we are getting called once after clicking away from the status page
if (($scope.socket === undefined) || ($scope.socket === null)) {
- // socket = new WebSocket('ws://' + window.location.hostname + '/control');
- socket = new WebSocket('ws://' + URL_HOST_BASE + '/control');
+ socket = new WebSocket('ws://' + URL_HOST_BASE + '/status');
$scope.socket = socket; // store socket in scope for enter/exit usage
}
diff --git a/web/plates/js/traffic.js b/web/plates/js/traffic.js
index 5f061d00..8263aa3a 100755
--- a/web/plates/js/traffic.js
+++ b/web/plates/js/traffic.js
@@ -1,15 +1,135 @@
angular.module('appControllers').controller('TrafficCtrl', TrafficCtrl); // get the main module contollers set
-TrafficCtrl.$inject = ['$rootScope', '$scope', '$state', '$http']; // Inject my dependencies
+TrafficCtrl.$inject = ['$rootScope', '$scope', '$state', '$http', '$interval']; // Inject my dependencies
// create our controller function with all necessary logic
-function TrafficCtrl($rootScope, $scope, $state, $http) {
+function TrafficCtrl($rootScope, $scope, $state, $http, $interval) {
- /*
- $state.get('weather').onEnter = function () {
- };
- $state.get('weather').onExit = function () {
- };
- */
+ $scope.$parent.helppage = 'plates/traffic-help.html';
+ $scope.traffic = [];
- // Weather Controller tasks go here
+ function utcTimeString(epoc) {
+ var time = "";
+ var val;
+ var d = new Date(epoc);
+ val = d.getUTCHours();
+ time += (val < 10 ? "0" + val : "" + val);
+ val = d.getUTCMinutes();
+ time += ":" + (val < 10 ? "0" + val : "" + val);
+ val = d.getUTCSeconds();
+ time += ":" + (val < 10 ? "0" + val : "" + val);
+ time += "Z";
+ return time;
+ }
+
+ function dmsString(val) {
+ return [0 | val,
+ 'd ',
+ 0 | (val < 0 ? val = -val : val) % 1 * 60,
+ "' ",
+ 0 | val * 60 % 1 * 60,
+ '"'].join('');
+ }
+
+ function setAircraft(obj, new_traffic) {
+ new_traffic.icao_int = obj.Icao_addr;
+ new_traffic.icao = obj.Icao_addr.toString(16).toUpperCase();
+ new_traffic.tail = obj.Tail;
+ new_traffic.lat = dmsString(obj.Lat);
+ new_traffic.lon = dmsString(obj.Lng);
+ var n = Math.round(obj.Alt / 100) * 100;
+ new_traffic.alt = n.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
+ new_traffic.heading = Math.round(obj.Track / 10) * 10;
+ new_traffic.speed = Math.round(obj.Speed / 10) * 10;
+ new_traffic.vspeed = Math.round(obj.Vvel / 100) * 100
+ new_traffic.age = Date.parse(obj.Last_seen);
+ new_traffic.time = utcTimeString(new_traffic.age);
+ // return new_aircraft;
+ }
+
+ function connect($scope) {
+ if (($scope === undefined) || ($scope === null))
+ return; // we are getting called once after clicking away from the status page
+
+ if (($scope.socket === undefined) || ($scope.socket === null)) {
+ socket = new WebSocket('ws://' + URL_HOST_BASE + '/traffic');
+ $scope.socket = socket; // store socket in scope for enter/exit usage
+ }
+
+ $scope.ConnectState = "Not Receiving";
+
+ socket.onopen = function (msg) {
+ $scope.ConnectStyle = "label-success";
+ $scope.ConnectState = "Receiving";
+ };
+
+ socket.onclose = function (msg) {
+ $scope.ConnectStyle = "label-danger";
+ $scope.ConnectState = "Not Receiving";
+ setTimeout(connect, 1000);
+ };
+
+ socket.onerror = function (msg) {
+ $scope.ConnectStyle = "label-danger";
+ $scope.ConnectState = "Problem";
+ };
+
+ socket.onmessage = function (msg) {
+ console.log('Received traffic update.')
+
+ var aircraft = JSON.parse(msg.data);
+ if (aircraft.Position_valid) {
+ $scope.rawTraffic = msg.data;
+ // 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;
+ for (var i = 0, len = $scope.traffic.length; i < len; i++) {
+ if ($scope.traffic[i].icao_int === aircraft.Icao_addr) {
+ setAircraft(aircraft, $scope.traffic[i]);
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ var new_traffic = {};
+ setAircraft(aircraft, new_traffic);
+ $scope.traffic.unshift(new_traffic); // add to start of array
+ }
+ $scope.$apply();
+ }
+ };
+ }
+
+ // perform cleanup every 60 seconds
+ var clearStaleTraffic = $interval(function () {
+ // remove stail aircraft = anything more than 180 seconds without and update
+ var dirty = false;
+ var cutoff = Date.now() - (180 * 1000);
+
+ for (var i = len = $scope.traffic.length; i > 0; i--) {
+ if ($scope.traffic[i - 1].age < cutoff) {
+ $scope.traffic.splice(i - 1, 1);
+ dirty = true;
+ }
+ }
+ if (dirty) {
+ $scope.$apply();
+ }
+ }, (1000 * 60), 0, false);
+
+
+ $state.get('traffic').onEnter = function () {
+ // everything gets handled correctly by the controller
+ };
+
+ $state.get('traffic').onExit = function () {
+ // disconnect from the socket
+ if (($scope.socket !== undefined) && ($scope.socket !== null)) {
+ $scope.socket.close();
+ $scope.socket = null;
+ }
+ // stop stale traffic cleanup
+ $interval.cancel(clearStaleTraffic);
+ };
+
+ // Traffic Controller tasks
+ connect($scope); // connect - opens a socket and listens for messages
};
\ No newline at end of file
diff --git a/web/plates/settings-help.html b/web/plates/settings-help.html
index a4bdbb60..d31dc23b 100755
--- a/web/plates/settings-help.html
+++ b/web/plates/settings-help.html
@@ -6,7 +6,7 @@
Status page.
The Diagnostics section helps with debugging and communicating with the Stratux project contributors via GitHub and the reddit subgroup.
-
+
Toggling Traffic Source adds text for traffic targets within your navigation application. Traffic received via UAT will display u while traffic received via 1090 will display e.
Toggling Record Logs enables logging to a series of files for your Stratux device including data recorded for UAT traffic and weather, 1090 traffic, GPS messages, and AHRS messages. The log files are accessible from the Logs menu available on the left.