From 75b7936f9e9e2908806594fe9c69d8633ad1bb2d Mon Sep 17 00:00:00 2001 From: Stefano Date: Mon, 13 May 2024 23:25:35 +0200 Subject: [PATCH 1/2] Serial Output Settings --- main/managementinterface.go | 13 ++++++++++ main/network.go | 20 +++++++++++++-- web/plates/js/settings.js | 16 ++++++------ web/plates/settings.html | 51 ++++++++++++++++++++++++++++++------- 4 files changed, 81 insertions(+), 19 deletions(-) diff --git a/main/managementinterface.go b/main/managementinterface.go index 78da10084..9ecd2fd77 100644 --- a/main/managementinterface.go +++ b/main/managementinterface.go @@ -407,6 +407,19 @@ func handleSettingsSetRequest(w http.ResponseWriter, r *http.Request) { case "RadarRange": globalSettings.RadarRange = int(val.(float64)) radarUpdate.SendJSON(globalSettings) + // Serial Management with Capabilities and Baud support + case "SerialOutput": + modelItem := val.(map[string]interface{}) + if(modelItem["DeviceString"]!=nil && len(modelItem["DeviceString"].(string))>0 && + modelItem["Baud"]!=nil && (modelItem["Baud"].(float64))>0){ + dev := modelItem["DeviceString"].(string) + serialOut := globalSettings.SerialOutputs[dev] + serialOut.Baud = int(modelItem["Baud"].(float64)) + serialOut.Capability = uint8(modelItem["Capability"].(float64)) + globalSettings.SerialOutputs[dev]=serialOut + closeSerial(dev) + } + // TODO: This method is obsolete and can be removed case "Baud": if globalSettings.SerialOutputs != nil { for dev, serialOut := range globalSettings.SerialOutputs { diff --git a/main/network.go b/main/network.go index 8945a339f..d0a5cfc7e 100644 --- a/main/network.go +++ b/main/network.go @@ -36,11 +36,13 @@ var netMutex *sync.Mutex // netMutex needs to be locked before acce var totalNetworkMessagesSent uint32 const ( + NETWORK_DISABLED = 0 NETWORK_GDL90_STANDARD = 1 NETWORK_AHRS_FFSIM = 2 NETWORK_AHRS_GDL90 = 4 NETWORK_FLARM_NMEA = 8 NETWORK_POSITION_FFSIM = 16 + NETWORK_RESERVED_FEA32 = 32 dhcp_lease_file = "/var/lib/misc/dnsmasq.leases" dhcp_lease_dir = "/var/lib/misc/" extra_hosts_file = "/etc/stratux-static-hosts.conf" @@ -139,6 +141,8 @@ func serialOutWatcher() { for i := 0; i < 10; i++ { serialDevs = append(serialDevs, fmt.Sprintf("/dev/serialout%d", i)) serialDevs = append(serialDevs, fmt.Sprintf("/dev/serialout_nmea%d", i)) + // Improved Serial Output support for different devices + serialDevs = append(serialDevs, fmt.Sprintf("/dev/ttyUSB%d", i)) } for { @@ -150,7 +154,14 @@ func serialOutWatcher() { // Master is globalSettings.SerialOutputs. Once we connect to one, it will be copied to the active connections map if val, ok := globalSettings.SerialOutputs[serialDev]; !ok { - proto := uint8(NETWORK_GDL90_STANDARD) + // Improved Serial Output support for different devices + // Step 1: Let's the user decide using Web Settings + proto := uint8(NETWORK_DISABLED) + // Step 2: Existing installation with serialout + if strings.Contains(serialDev, "serialout") { + proto = NETWORK_GDL90_STANDARD + } + // Step 3: nmea output if strings.Contains(serialDev, "_nmea") { proto = NETWORK_FLARM_NMEA } @@ -165,13 +176,18 @@ func serialOutWatcher() { } else { config = val if config.Capability == 0 { - config.Capability = NETWORK_GDL90_STANDARD // Fix old serial conns that didn't have protocol set + // Obsolete: using the new Web Settings the user can easily manage and change this + //config.Capability = NETWORK_GDL90_STANDARD // Fix old serial conns that didn't have protocol set } } netMutex.Lock() needsConnect := true + // Disabled Serial Interface + if config.Capability == 0 { + needsConnect = false + } if activeConn, ok := clientConnections[serialDev]; ok { if !activeConn.IsSleeping() { needsConnect = false diff --git a/web/plates/js/settings.js b/web/plates/js/settings.js index 090ee8020..7e1b89f6e 100644 --- a/web/plates/js/settings.js +++ b/web/plates/js/settings.js @@ -282,10 +282,8 @@ function SettingsCtrl($rootScope, $scope, $state, $location, $window, $http) { $scope.rawSettings = angular.toJson(data, true); $scope.visible_serialout = false; if ((settings.SerialOutputs !== undefined) && (settings.SerialOutputs !== null)) { - for (var k in settings.SerialOutputs) { - $scope.Baud = settings.SerialOutputs[k].Baud; + $scope.SerialOutputs = settings.SerialOutputs; $scope.visible_serialout = true; - } } $scope.DarkMode = settings.DarkMode; @@ -441,12 +439,14 @@ function SettingsCtrl($rootScope, $scope, $state, $location, $window, $http) { } } - $scope.updateBaud = function () { - settings["Baud"] = 0; - if ($scope.Baud !== undefined && $scope.Baud !== null) { - settings["Baud"] = parseInt($scope.Baud); + $scope.updateBaud = function (serial) { + { var newsettings = { - "Baud": settings["Baud"] + "SerialOutput": { + "DeviceString": serial.DeviceString, + "Baud": parseInt(serial.Baud), + "Capability": parseInt(serial.Capability) + } }; // console.log(angular.toJson(newsettings)); setSettings(angular.toJson(newsettings)); diff --git a/web/plates/settings.html b/web/plates/settings.html index 0dbd09899..e3b166099 100644 --- a/web/plates/settings.html +++ b/web/plates/settings.html @@ -270,14 +270,6 @@ -
- -
- - -
-
@@ -303,6 +295,47 @@
+ +
+
+
Serial Output Settings
+
+
+ +
+ + + + + + + + + +
+
+
+
+
+
@@ -777,4 +810,4 @@
- \ No newline at end of file + From 4ca8765c1c759b586e2870cbf08789ce6405db90 Mon Sep 17 00:00:00 2001 From: Stefano Date: Sun, 19 May 2024 11:40:18 +0200 Subject: [PATCH 2/2] Serial Output Settings with default NMEA and no new devices discovery --- main/network.go | 8 ++++++-- web/plates/settings.html | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/main/network.go b/main/network.go index d0a5cfc7e..32c74405c 100644 --- a/main/network.go +++ b/main/network.go @@ -142,7 +142,11 @@ func serialOutWatcher() { serialDevs = append(serialDevs, fmt.Sprintf("/dev/serialout%d", i)) serialDevs = append(serialDevs, fmt.Sprintf("/dev/serialout_nmea%d", i)) // Improved Serial Output support for different devices - serialDevs = append(serialDevs, fmt.Sprintf("/dev/ttyUSB%d", i)) + //serialDevs = append(serialDevs, fmt.Sprintf("/dev/ttyUSB%d", i)) // avoid generic ttyUSB0 which may relay on a peripheral symlink + //serialDevs = append(serialDevs, fmt.Sprintf("/dev/prolific%d", i)) + // TODO1: find the right path for USB devices + // TODO2: add into serialConnection structure more detailed mapping function using udevadm info -q property -n {/dev/device} + // TODO3: unify network.go with gps.go serial discovery } for { @@ -177,7 +181,7 @@ func serialOutWatcher() { config = val if config.Capability == 0 { // Obsolete: using the new Web Settings the user can easily manage and change this - //config.Capability = NETWORK_GDL90_STANDARD // Fix old serial conns that didn't have protocol set + config.Capability = NETWORK_GDL90_STANDARD // Fix old serial conns that didn't have protocol set } } diff --git a/web/plates/settings.html b/web/plates/settings.html index e3b166099..865540ae4 100644 --- a/web/plates/settings.html +++ b/web/plates/settings.html @@ -319,7 +319,7 @@