Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Serial Output Settings #281

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions main/managementinterface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Copy link
Owner

@b3nn0 b3nn0 May 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please try to follow the coding style here? No () around if-conditions if it's not needed, spaces around operators, ...

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 {
Expand Down
20 changes: 18 additions & 2 deletions main/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about this.. this is kinda a catch-all for a lot of devices, including stuff that is intended to be a GPS and not a serialout chip..
Unfortunately it's kinda impossible to guess the intention that a user has when plugging in a certain device.. can we maybe somehow filter to only display devices that are not detected as GPS? Also see my general remark though..

}

for {
Expand All @@ -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
}
Expand All @@ -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
Expand Down
16 changes: 8 additions & 8 deletions web/plates/js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down
51 changes: 42 additions & 9 deletions web/plates/settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -270,14 +270,6 @@

</form>
</div>
<div class="form-group reset-flow" ng-class="{ 'section_invisible': (!visible_serialout)}">
<label class="control-label col-xs-5">Serial Output Baudrate</label>
<form name="ppmForm" ng-submit="updateBaud()" novalidate>
<!-- type="number" not supported except on mobile -->
<input class="col-xs-7" type="number" ng-model="Baud" placeholder="integer"
ng-blur="updateBaud()" />
</form>
</div>
<div class="form-group reset-flow">
<label class="control-label col-xs-5">Static IPs</label>
<form name="staticipForm" ng-submit="updatestaticips()" novalidate>
Expand All @@ -303,6 +295,47 @@
</div>
</div>
</div>
<!-- Serial Output Settings -->
<div class="panel-group col-sm-12" ng-class="{ 'section_invisible': (!visible_serialout)}">
<div class="panel panel-default">
<div class="panel-heading">Serial Output Settings</div>
<div class="panel-body">
<div ng-repeat="serial in SerialOutputs">

<div class="form-group reset-flow">
<label class="control-label col-xs-5">{{serial.DeviceString}}</label>
<form name="serialForm" ng-submit="updateBaud(serial)" novalidate>
<!-- type="number" not supported except on mobile -->

<select class="custom-select" ng-model="serial.Baud" ng-blur="updateBaud(serial)">
<option value="1200" ng-selected="serial.Baud.toFixed(0)==1200">1200 Baud</option>
<option value="4800" ng-selected="serial.Baud.toFixed(0)==4800">4800 Baud</option>
<option value="9600" ng-selected="serial.Baud.toFixed(0)==9600">9600 Baud</option>
<option value="19200" ng-selected="serial.Baud.toFixed(0)==19200">19200 Baud</option>
<option value="38400" ng-selected="serial.Baud.toFixed(0)==38400">38400 Baud (DEFAULT)</option>
<option value="57200" ng-selected="serial.Baud.toFixed(0)==57200">57200 Baud</option>
<option value="115200" ng-selected="serial.Baud.toFixed(0)==115200">115200 Baud</option>
</select>


<select class="custom-select" ng-model="serial.Capability" ng-blur="updateBaud(serial)">
<option value="0" ng-selected="serial.Capability.toFixed(0)==0">DISABLED</option>
<option value="1" ng-selected="serial.Capability.toFixed(0)==1">GDL90</option>
<option value="2" ng-selected="serial.Capability.toFixed(0)==2">AHRS_FFSIM</option>
<option value="4" ng-selected="serial.Capability.toFixed(0)==4">AHRS_GDL90</option>
<option value="8" ng-selected="serial.Capability.toFixed(0)==8">FALARM NMEA (DEFAULT)</option>
<option value="16" ng-selected="serial.Capability.toFixed(0)==16">FFSIM</option>
<!--
<option value="32" ng-selected="serial.Capability.toFixed(0)==32">RADIO KTX2</option>
-->
</select>
</form>
</div>
</div>
</div>
</div>
</div>

<!-- WiFi Settings -->
<div class="panel-group col-sm-12">
<div class="panel panel-default">
Expand Down Expand Up @@ -777,4 +810,4 @@ <h4 class="modal-title">WiFi Settings: Canceled</h4>
</div>
</div>
</div>
</div>
</div>