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..32c74405c 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,12 @@ 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)) // 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 { @@ -150,7 +158,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,6 +180,7 @@ func serialOutWatcher() { } else { 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 } } @@ -172,6 +188,10 @@ func serialOutWatcher() { 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..865540ae4 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 +