From 30abcb82eec7dd2ccd2cc96e50e190fe52940171 Mon Sep 17 00:00:00 2001 From: bradanlane Date: Tue, 6 Oct 2015 18:31:20 -0400 Subject: [PATCH] add OwnshipModeS to UI and maintain consistent format for storage; also tweaked 'settings' page field validation --- main/gen_gdl90.go | 9 +- main/managementinterface.go | 15 +-- web/plates/js/settings.js | 187 ++++++++++++++++++---------------- web/plates/js/status.js | 2 +- web/plates/js/weather.js | 2 + web/plates/settings-help.html | 38 ++++--- web/plates/settings.html | 19 ++-- 7 files changed, 153 insertions(+), 119 deletions(-) diff --git a/main/gen_gdl90.go b/main/gen_gdl90.go index f3f84659..55715356 100644 --- a/main/gen_gdl90.go +++ b/main/gen_gdl90.go @@ -177,9 +177,10 @@ func makeOwnshipReport() bool { msg[1] = 0x01 // Alert status, address type. - msg[2] = byte((globalSettings.OwnshipModeS >> 16) & 0xFF) // Mode S address. - msg[3] = byte((globalSettings.OwnshipModeS >> 8) & 0xFF) // Mode S address. - msg[4] = byte(globalSettings.OwnshipModeS & 0xFF) // Mode S address. + code, _ := hex.DecodeString(globalSettings.OwnshipModeS) + msg[2] = code[0] // Mode S address. + msg[3] = code[1] // Mode S address. + msg[4] = code[2] // Mode S address. tmp := makeLatLng(mySituation.Lat) msg[5] = tmp[0] // Latitude. @@ -684,7 +685,7 @@ type settings struct { DEBUG bool ReplayLog bool // Startup only option. Cannot be changed during runtime. PPM int - OwnshipModeS int32 + OwnshipModeS string WatchList string } diff --git a/main/managementinterface.go b/main/managementinterface.go index ac9c82ff..0bd56b48 100644 --- a/main/managementinterface.go +++ b/main/managementinterface.go @@ -2,12 +2,13 @@ package main import ( "encoding/json" + "encoding/hex" + "strings" "fmt" "golang.org/x/net/websocket" "io" "log" "net/http" - "strconv" "time" ) @@ -159,15 +160,17 @@ func handleSettingsSetRequest(w http.ResponseWriter, r *http.Request) { globalSettings.WatchList = val.(string) case "OwnshipModeS": // Expecting a hex string less than 6 characters (24 bits) long. - hexc := val.(string) - if len(hexc) > 6 { // Too long. + if len(val.(string)) > 6 { // Too long. continue } - i, err := strconv.ParseInt(hexc, 16, 32) - if err != nil { // Number not valid. + vals := strings.ToUpper(val.(string)) + hexn, _ := hex.DecodeString(vals) + hexs := strings.ToUpper(hex.EncodeToString(hexn)) + if vals != hexs { // Number not valid. + log.Printf("handleSettingsSetRequest:OwnshipModeS: %s != %s\n", vals, hexs) continue } - globalSettings.OwnshipModeS = int32(i) + globalSettings.OwnshipModeS = vals default: log.Printf("handleSettingsSetRequest:json: unrecognized key:%s\n", key) } diff --git a/web/plates/js/settings.js b/web/plates/js/settings.js index eae325c7..a3e560eb 100755 --- a/web/plates/js/settings.js +++ b/web/plates/js/settings.js @@ -4,95 +4,108 @@ SettingsCtrl.$inject = ['$rootScope', '$scope', '$state', '$http']; // Inject my // create our controller function with all necessary logic function SettingsCtrl($rootScope, $scope, $state, $http) { - $scope.$parent.helppage = 'plates/settings-help.html'; - - var toggles = ['UAT_Enabled', 'ES_Enabled', 'GPS_Enabled', 'AHRS_Enabled', 'DEBUG', 'ReplayLog']; // DEBUG is 'DspTrafficSrc' - var settings = {}; - for (i = 0; i < toggles.length; i++) { - settings[toggles[i]] = undefined; - } + $scope.$parent.helppage = 'plates/settings-help.html'; + + var toggles = ['UAT_Enabled', 'ES_Enabled', 'GPS_Enabled', 'AHRS_Enabled', 'DEBUG', 'ReplayLog']; // DEBUG is 'DspTrafficSrc' + var settings = {}; + for (i = 0; i < toggles.length; i++) { + settings[toggles[i]] = undefined; + } function loadSettings(data) { - settings = angular.fromJson(data); - $scope.rawSettings = angular.toJson(data, true); - $scope.UAT_Enabled = settings.UAT_Enabled; - $scope.ES_Enabled = settings.ES_Enabled; - $scope.GPS_Enabled = settings.GPS_Enabled; - $scope.AHRS_Enabled = settings.AHRS_Enabled; - $scope.DEBUG = settings.DEBUG; - $scope.ReplayLog = settings.ReplayLog; - $scope.PPM = settings.PPM; - $scope.WatchList = settings.WatchList; + settings = angular.fromJson(data); + // consider using angular.extend() + $scope.rawSettings = angular.toJson(data, true); + $scope.UAT_Enabled = settings.UAT_Enabled; + $scope.ES_Enabled = settings.ES_Enabled; + $scope.GPS_Enabled = settings.GPS_Enabled; + $scope.AHRS_Enabled = settings.AHRS_Enabled; + $scope.DEBUG = settings.DEBUG; + $scope.ReplayLog = settings.ReplayLog; + $scope.PPM = settings.PPM; + $scope.WatchList = settings.WatchList; + $scope.OwnshipModeS = settings.OwnshipModeS; } + + function getSettings() { + // Simple GET request example (note: responce is asynchronous) + $http.get(URL_SETTINGS_GET). + then(function (response) { + loadSettings(response.data); + // $scope.$apply(); + }, function (response) { + $scope.rawSettings = "error getting settings"; + for (i = 0; i < toggles.length; i++) { + settings[toggles[i]] = false; + } + + }); + }; + + function setSettings(msg) { + // Simple POST request example (note: responce is asynchronous) + $http.post(URL_SETTINGS_SET, msg). + then(function (response) { + loadSettings(response.data); + // $scope.$apply(); + }, function (response) { + $scope.rawSettings = "error setting settings"; + for (i = 0; i < toggles.length; i++) { + settings[toggles[i]] = false; + } + + }); + } + + getSettings(); + + $scope.$watchGroup(toggles, function (newValues, oldValues, scope) { + var newsettings = {} + var dirty = false; + for (i = 0; i < newValues.length; i++) { + if ((newValues[i] !== undefined) && (settings[toggles[i]] !== undefined)) { + if (newValues[i] !== settings[toggles[i]]) { + settings[toggles[i]] = newValues[i]; + newsettings[toggles[i]] = newValues[i]; + dirty = true; + }; + } + } + if (dirty) { + // console.log(angular.toJson(newsettings)); + setSettings(angular.toJson(newsettings)); + } + }); + + $scope.updateppm = function () { + if (($scope.PPM !== undefined) && ($scope.PPM !== null) && ($scope.PPM !== settings["PPM"])) { + settings["PPM"] = parseInt($scope.PPM); + newsettings = { + "PPM": parseInt($scope.PPM) + }; + // console.log(angular.toJson(newsettings)); + setSettings(angular.toJson(newsettings)); + } + }; - function getSettings() { - // Simple GET request example (note: responce is asynchronous) - $http.get(URL_SETTINGS_GET). - then(function (response) { - loadSettings (response.data); - // $scope.$apply(); - }, function (response) { - $scope.rawSettings = "error getting settings"; - for (i = 0; i < toggles.length; i++) { - settings[toggles[i]] = false; - } - - }); - }; - - function setSettings(msg) { - // Simple POST request example (note: responce is asynchronous) - $http.post(URL_SETTINGS_SET, msg). - then(function (response) { - loadSettings (response.data); - // $scope.$apply(); - }, function (response) { - $scope.rawSettings = "error setting settings"; - for (i = 0; i < toggles.length; i++) { - settings[toggles[i]] = false; - } - - }); - } - - getSettings(); - - $scope.$watchGroup(toggles, function (newValues, oldValues, scope) { - var newsettings = {} - var dirty = false; - for (i = 0; i < newValues.length; i++) { - if ((newValues[i] !== undefined) && (settings[toggles[i]] !== undefined)) { - if (newValues[i] !== settings[toggles[i]]) { - settings[toggles[i]] = newValues[i]; - newsettings[toggles[i]] = newValues[i]; - dirty = true; - }; - } - } - if (dirty) { - console.log(angular.toJson(newsettings)); - setSettings(angular.toJson(newsettings)); - } - }); - - $scope.updatewatchlist = function() { - if (($scope.WatchList !== undefined) && ($scope.WatchList !== null) && $scope.WatchList !== settings["WatchList"]) { - settings["WatchList"] = $scope.WatchList.toUpperCase(); - newsettings = { - "WatchList": $scope.WatchList.toUpperCase() - }; - console.log(angular.toJson(newsettings)); - setSettings(angular.toJson(newsettings)); - } - }; - $scope.updateppm = function() { - if (($scope.PPM !== undefined) && ($scope.PPM !== null) && $scope.PPM !== settings["PPM"]) { - settings["PPM"] = parseInt($scope.PPM); - newsettings = { - "PPM": parseInt($scope.PPM) - }; - console.log(angular.toJson(newsettings)); - setSettings(angular.toJson(newsettings)); - } - }; + $scope.updatewatchlist = function () { + if ($scope.WatchList !== settings["WatchList"]) { + settings["WatchList"] = $scope.WatchList.toUpperCase(); + newsettings = { + "WatchList": $scope.WatchList.toUpperCase() + }; + // console.log(angular.toJson(newsettings)); + setSettings(angular.toJson(newsettings)); + } + }; + $scope.updatemodes = function () { + if ($scope.OwnshipModeS !== settings["OwnshipModeS"]) { + settings["OwnshipModeS"] = $scope.OwnshipModeS.toUpperCase(); + newsettings = { + "OwnshipModeS": $scope.OwnshipModeS.toUpperCase() + }; + // console.log(angular.toJson(newsettings)); + setSettings(angular.toJson(newsettings)); + } + }; }; \ No newline at end of file diff --git a/web/plates/js/status.js b/web/plates/js/status.js index 4f9504e5..95c18870 100755 --- a/web/plates/js/status.js +++ b/web/plates/js/status.js @@ -24,7 +24,7 @@ function StatusCtrl($rootScope, $scope, $state, $http) { socket.onclose = function (msg) { // $scope.ConnectStyle = "label-danger"; - $scope.ConnectState = "Closed"; + $scope.ConnectState = "Disconnected"; $scope.$apply(); setTimeout(connect, 1000); }; diff --git a/web/plates/js/weather.js b/web/plates/js/weather.js index e3875c55..43538f9a 100755 --- a/web/plates/js/weather.js +++ b/web/plates/js/weather.js @@ -10,6 +10,8 @@ function WeatherCtrl($rootScope, $scope, $state, $http, $interval) { $scope.$parent.helppage = 'plates/weather-help.html'; $scope.data_list = []; $scope.watch_list = []; + $scope.data_count = 0; + $scope.watch_count = 0; function updateWatchList() { $scope.watching = CONF_WATCHLIST; diff --git a/web/plates/settings-help.html b/web/plates/settings-help.html index aa2270ae..61e04a2a 100755 --- a/web/plates/settings-help.html +++ b/web/plates/settings-help.html @@ -1,20 +1,28 @@
-

The Settings page provides both control and configuration of your Stratux device.

+

The Settings page provides both control and configuration of your Stratux device.

-

Use the toggles in the Hardware section to control which devices are active.

-

NOTE: Only hardware toggled on here, will appear on the - Status page.

+

Use the toggles in the Hardware section to control which devices are active.

+

NOTE: Only hardware toggled on here, will appear on the + Status page.

-

The Diagnostics section helps with debugging and communicating with the Stratux project contributors via GitHub and the reddit subgroup. -

+

The Diagnostics section helps with debugging and communicating with the Stratux project contributors via GitHub and the reddit subgroup. +

-

The Configuration section lets you adjust the default operation of your Stratux device.

- +

The Configuration section lets you adjust the default operation of your Stratux device.

+
\ No newline at end of file diff --git a/web/plates/settings.html b/web/plates/settings.html index 52a2204b..62f60b16 100755 --- a/web/plates/settings.html +++ b/web/plates/settings.html @@ -56,17 +56,24 @@
Configuration
- -
+ + - +
-
+ - + +
+
+
+ +
+ +
@@ -75,7 +82,7 @@