From 0324cc4b1ff85d753bdb784821bf3c4e66152753 Mon Sep 17 00:00:00 2001 From: bradanlane Date: Tue, 27 Oct 2015 10:55:18 -0400 Subject: [PATCH] created new towers details page but its commented out of the WebUI; simple active tower count is added to primary status page; created status web servcie for cases wehre a single instance is needed --- main/managementinterface.go | 12 +++++++ web/index.html | 9 +++-- web/js/main.js | 8 +++++ web/plates/js/status.js | 33 ++++++++++++++--- web/plates/js/towers.js | 70 +++++++++++++++++++++++++++++++++++++ web/plates/js/traffic.js | 2 +- web/plates/status.html | 6 +++- web/plates/towers-help.html | 4 +++ web/plates/towers.html | 33 +++++++++++++++++ 9 files changed, 168 insertions(+), 9 deletions(-) create mode 100644 web/plates/js/towers.js create mode 100644 web/plates/towers-help.html create mode 100644 web/plates/towers.html diff --git a/main/managementinterface.go b/main/managementinterface.go index 7fb54951..813062d9 100644 --- a/main/managementinterface.go +++ b/main/managementinterface.go @@ -101,6 +101,15 @@ func handleStatusWS(conn *websocket.Conn) { } } +// AJAX call - /getStatus. Responds with current global status +// a webservice call for the same data available on the websocket but when only a single update is needed +func handleStatusRequest(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Access-Control-Allow-Origin", "*") + w.Header().Set("Content-Type", "application/json") + statusJSON, _ := json.Marshal(&globalStatus) + fmt.Fprintf(w, "%s\n", statusJSON) +} + // AJAX call - /getSituation. Responds with current situation (lat/lon/gdspeed/track/pitch/roll/heading/etc.) func handleSituationRequest(w http.ResponseWriter, r *http.Request) { w.Header().Set("Access-Control-Allow-Origin", "*") @@ -114,6 +123,8 @@ func handleTowersRequest(w http.ResponseWriter, r *http.Request) { w.Header().Set("Access-Control-Allow-Origin", "*") w.Header().Set("Content-Type", "application/json") towersJSON, _ := json.Marshal(&ADSBTowers) + // for testing purposes, we can return a fixed reply + // towersJSON = []byte(`{"(38.490880,-76.135554)":{"Lat":38.49087953567505,"Lng":-76.13555431365967,"Signal_strength_last_minute":100,"Signal_strength_max":67,"Messages_last_minute":1,"Messages_total":1059},"(38.978698,-76.309276)":{"Lat":38.97869825363159,"Lng":-76.30927562713623,"Signal_strength_last_minute":495,"Signal_strength_max":32,"Messages_last_minute":45,"Messages_total":83},"(39.179285,-76.668413)":{"Lat":39.17928457260132,"Lng":-76.66841268539429,"Signal_strength_last_minute":50,"Signal_strength_max":24,"Messages_last_minute":1,"Messages_total":16},"(39.666309,-74.315300)":{"Lat":39.66630935668945,"Lng":-74.31529998779297,"Signal_strength_last_minute":9884,"Signal_strength_max":35,"Messages_last_minute":4,"Messages_total":134}}`) fmt.Fprintf(w, "%s\n", towersJSON) } @@ -227,6 +238,7 @@ func managementInterface() { s.ServeHTTP(w, req) }) + http.HandleFunc("/getStatus", handleStatusRequest) http.HandleFunc("/getSituation", handleSituationRequest) http.HandleFunc("/getTowers", handleTowersRequest) http.HandleFunc("/getSettings", handleSettingsGetRequest) diff --git a/web/index.html b/web/index.html index 9d022712..2e51ef44 100755 --- a/web/index.html +++ b/web/index.html @@ -58,6 +58,9 @@ + @@ -77,9 +80,9 @@ Status Weather Traffic - GPS/AHRS - Logs Settings diff --git a/web/js/main.js b/web/js/main.js index 3119651f..8151b817 100755 --- a/web/js/main.js +++ b/web/js/main.js @@ -3,6 +3,8 @@ var URL_HOST_BASE = window.location.hostname; var URL_SETTINGS_GET = "http://" + URL_HOST_BASE + "/getSettings"; var URL_SETTINGS_SET = "http://" + URL_HOST_BASE + "/setSettings"; var URL_GPS_GET = "http://" + URL_HOST_BASE + "/getSituation"; +var URL_TOWERS_GET = "http://" + URL_HOST_BASE + "/getTowers" +var URL_STATUS_GET = "http://" + URL_HOST_BASE + "/getStatus" var URL_STATUS_WS = "ws://" + URL_HOST_BASE + "/status" var URL_TRAFFIC_WS = "ws://" + URL_HOST_BASE + "/traffic"; var URL_WEATHER_WS = "ws://" + URL_HOST_BASE + "/weather"; @@ -21,6 +23,12 @@ app.config(function ($stateProvider, $urlRouterProvider) { controller: 'StatusCtrl', reloadOnSearch: false }) +// .state('towers', { +// url: '/towers', +// templateUrl: 'plates/towers.html', +// controller: 'TowersCtrl', +// reloadOnSearch: false +// }) .state('weather', { url: '/weather', templateUrl: 'plates/weather.html', diff --git a/web/plates/js/status.js b/web/plates/js/status.js index 16f61031..d1b113a8 100755 --- a/web/plates/js/status.js +++ b/web/plates/js/status.js @@ -1,8 +1,8 @@ angular.module('appControllers').controller('StatusCtrl', StatusCtrl); // get the main module contollers set -StatusCtrl.$inject = ['$rootScope', '$scope', '$state', '$http']; // Inject my dependencies +StatusCtrl.$inject = ['$rootScope', '$scope', '$state', '$http', '$interval']; // Inject my dependencies // create our controller function with all necessary logic -function StatusCtrl($rootScope, $scope, $state, $http) { +function StatusCtrl($rootScope, $scope, $state, $http, $interval) { $scope.$parent.helppage = 'plates/status-help.html'; @@ -91,6 +91,31 @@ function StatusCtrl($rootScope, $scope, $state, $http) { }); }; + function getTowers() { + // Simple GET request example (note: responce is asynchronous) + $http.get(URL_TOWERS_GET). + then(function (response) { + var towers = angular.fromJson(response.data); + var cnt = 0; + for (var key in towers) { + if (towers[key].Messages_last_minute > 0) { + cnt++; + } + } + $scope.UAT_Towers = cnt; + // $scope.$apply(); + }, function (response) { + $scope.raw_data = "error getting tower data"; + }); + }; + + // periodically get the tower list + var updateTowers = $interval(function () { + // refresh tower count once each 5 seconds (aka polling) + getTowers(); + }, (5 * 1000), 0, false); + + $state.get('home').onEnter = function () { // everything gets handled correctly by the controller }; @@ -99,10 +124,10 @@ function StatusCtrl($rootScope, $scope, $state, $http) { $scope.socket.close(); $scope.socket = null; } + $interval.cancel(updateTowers); }; - // Status Controller tasks setHardwareVisibility(); connect($scope); // connect - opens a socket and listens for messages -}; +}; \ No newline at end of file diff --git a/web/plates/js/towers.js b/web/plates/js/towers.js new file mode 100644 index 00000000..d4bf3e1c --- /dev/null +++ b/web/plates/js/towers.js @@ -0,0 +1,70 @@ +angular.module('appControllers').controller('TowersCtrl', TowersCtrl); // get the main module contollers set +TowersCtrl.$inject = ['$rootScope', '$scope', '$state', '$http', '$interval']; // Inject my dependencies + +// create our controller function with all necessary logic +function TowersCtrl($rootScope, $scope, $state, $http, $interval) { + + $scope.$parent.helppage = 'plates/towers-help.html'; + $scope.data_list = []; + + function dmsString(val) { + return [0 | val, + '° ', + 0 | (val < 0 ? val = -val : val) % 1 * 60, + "' ", + 0 | val * 60 % 1 * 60, + '"'].join(''); + } + + function setTower(obj, new_tower) { + new_tower.lat = dmsString(obj.Lat); + new_tower.lon = dmsString(obj.Lng); + new_tower.signal = obj.Signal_strength_last_minute; + // Signal_strength_max int + // Messages_last_minute uint64 + new_tower.messages = obj.Messages_total; + } + + function loadTowers(data) { + if (($scope === undefined) || ($scope === null)) + return; // we are getting called once after clicking away from the status page + + var towers = data; // it seems the json was already converted to an object list by teh http request + $scope.raw_data = angular.toJson(data, true); + + $scope.data_list.length = 0; // clear array + // we need to use an array so AngularJS can perform sorting; it also means we need to loop to find a tower in the towers set + for (var key in towers) { + if (towers[key].Messages_last_minute > 0) { + var new_tower = {}; + setTower(towers[key], new_tower); + $scope.data_list.push(new_tower); // add to start of array + } + } + // $scope.$apply(); + } + + function getTowers() { + // Simple GET request example (note: responce is asynchronous) + $http.get(URL_TOWERS_GET). + then(function (response) { + loadTowers(response.data); + }, function (response) { + $scope.raw_data = "error getting tower data"; + }); + }; + + var updateTowers = $interval(function () { + // refresh tower list once every 5 seconds (aka polling) + getTowers(); + }, (5 * 1000), 0, false); + + $state.get('towers').onEnter = function () { + // everything gets handled correctly by the controller + }; + + $state.get('towers').onExit = function () { + // stop any interval functions + $interval.cancel(updateTowers); + }; +}; \ No newline at end of file diff --git a/web/plates/js/traffic.js b/web/plates/js/traffic.js index 67453a78..523cf8e9 100755 --- a/web/plates/js/traffic.js +++ b/web/plates/js/traffic.js @@ -23,7 +23,7 @@ function TrafficCtrl($rootScope, $scope, $state, $http, $interval) { function dmsString(val) { return [0 | val, - 'd ', + '° ', 0 | (val < 0 ? val = -val : val) % 1 * 60, "' ", 0 | val * 60 % 1 * 60, diff --git a/web/plates/status.html b/web/plates/status.html index b4a440e1..3a349270 100755 --- a/web/plates/status.html +++ b/web/plates/status.html @@ -49,9 +49,13 @@
{{product_rows}}
--> -
+
 
+
+ + {{UAT_Towers}} +
{{GPS_satellites_locked}} diff --git a/web/plates/towers-help.html b/web/plates/towers-help.html new file mode 100644 index 00000000..dfcd56da --- /dev/null +++ b/web/plates/towers-help.html @@ -0,0 +1,4 @@ +
+

The Towers page provides a list of recent towers which have been received. Each time a new tower is received, it is added to the list. Each time new messages are received from an existing tower, the list is updated. If no messages are received from a tower for 5 minutes, the tower is removed from the list.

+

more details will be added here eventually :-)

+
\ No newline at end of file diff --git a/web/plates/towers.html b/web/plates/towers.html new file mode 100644 index 00000000..abaff5c2 --- /dev/null +++ b/web/plates/towers.html @@ -0,0 +1,33 @@ +
+
+
+ Towers + {{ConnectState}} + {{ConnectState}} +
+
+
+ Tower + Signal + Msgs +
+ +
+
+ {{tower.lat}} {{tower.lon}} + {{tower.signal}} + {{tower.messages}} +
+
+
+
+ \ No newline at end of file