124 lines
3.9 KiB
Go
124 lines
3.9 KiB
Go
// Package config verwaltet das Laden und Parsen der TOML-Konfigurationsdateien
|
|
// für den Server-Daemon und alle angeschlossenen GUI-Clients.
|
|
package config
|
|
|
|
import (
|
|
"os"
|
|
"github.com/BurntSushi/toml"
|
|
)
|
|
|
|
// ADS1115Module definiert die Hardware-Parameter und Kanal-Labels einer ADC-Platine.
|
|
type ADS1115Module struct {
|
|
Address string `toml:"address"`
|
|
Labels []string `toml:"labels"` // Genau 4 Beschriftungen für die Kanäle A0 bis A3
|
|
}
|
|
|
|
// RigHardwareSettings definiert die Parameter für das CAT-Interface des Transceivers.
|
|
type RigHardwareSettings struct {
|
|
Type string `toml:"type"` // Z.B. "FT897"
|
|
Port string `toml:"port"` // Z.B. "/dev/ttyUSB0"
|
|
Baud int `toml:"baud"` // Z.B. 38400
|
|
}
|
|
|
|
// RotorHardwareSettings definiert die Parameter für das serielle Protokoll des Rotors.
|
|
type RotorHardwareSettings struct {
|
|
Type string `toml:"type"` // Z.B. "ProSistel" oder "SPID"
|
|
Port string `toml:"port"` // Z.B. "/dev/ttyUSB1"
|
|
Baud int `toml:"baud"` // Z.B. 9600
|
|
}
|
|
|
|
// ServerSettings definiert die Netzwerkparameter des Server-Daemons.
|
|
type ServerSettings struct {
|
|
ListenAddress string `toml:"listen_address"`
|
|
HardwareRig RigHardwareSettings `toml:"hardware_rig"` // ERWEITERUNG für Yaesu
|
|
HardwareRotor RotorHardwareSettings `toml:"hardware_rotor"` // ERWEITERUNG für ProSistel/SPID
|
|
Modules []ADS1115Module `toml:"modules"` // Korrekt innerhalb der server-Sektion platziert
|
|
}
|
|
|
|
// ServerConfig bündelt alle Konfigurationseinstellungen des Servers.
|
|
type ServerConfig struct {
|
|
Server ServerSettings `toml:"server"`
|
|
}
|
|
|
|
// RotorSettings definiert die hardware- und systemspezifischen Parameter eines Rotors (Client-Sicht).
|
|
type RotorSettings struct {
|
|
Type string `toml:"type"` // Z.B. "G-5500", "Spid", "Sat-Rotor"
|
|
Port string `toml:"port"` // Z.B. "/dev/ttyUSB0" oder "I2C"
|
|
HomeAzimuth float64 `toml:"home_azimuth"` // Standard-Richtung für Azimut (z.B. 180.0 für Süd)
|
|
HomeElevation float64 `toml:"home_elevation"` // Standard-Richtung für Elevation (z.B. 0.0)
|
|
}
|
|
|
|
// ClientSettings definiert die Verbindungsparameter für die Fyne-GUIs.
|
|
type ClientSettings struct {
|
|
ServerAddress string `toml:"server_address"`
|
|
StationName string `toml:"station_name"`
|
|
RefreshRateMs int `toml:"refresh_rate_ms"`
|
|
Rotor RotorSettings `toml:"rotor"` // Rotorspezifische Einstellungen
|
|
}
|
|
|
|
// ClientConfig bündelt alle Konfigurationseinstellungen des GUI-Clients.
|
|
type ClientConfig struct {
|
|
Client ClientSettings `toml:"client"`
|
|
}
|
|
|
|
// LoadServerConfig lädt die Konfiguration für den Server-Daemon aus einer TOML-Datei.
|
|
func LoadServerConfig(path string) (*ServerConfig, error) {
|
|
cfg := &ServerConfig{
|
|
Server: ServerSettings{
|
|
ListenAddress: "0.0.0.0:50051",
|
|
HardwareRig: RigHardwareSettings{
|
|
Type: "Dummy",
|
|
Port: "Simulation",
|
|
Baud: 4800,
|
|
},
|
|
HardwareRotor: RotorHardwareSettings{
|
|
Type: "Dummy",
|
|
Port: "Simulation",
|
|
Baud: 9600,
|
|
},
|
|
Modules: []ADS1115Module{
|
|
{
|
|
Address: "0x48",
|
|
Labels: []string{"Kanal 1", "Kanal 2", "Kanal 3", "Kanal 4"},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
if _, err := os.Stat(path); os.IsNotExist(err) {
|
|
return cfg, nil
|
|
}
|
|
|
|
if _, err := toml.DecodeFile(path, cfg); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return cfg, nil
|
|
}
|
|
|
|
// LoadClientConfig lädt die Konfiguration für die GUI-Clients aus einer TOML-Datei.
|
|
func LoadClientConfig(path string) (*ClientConfig, error) {
|
|
cfg := &ClientConfig{
|
|
Client: ClientSettings{
|
|
ServerAddress: "127.0.0.1:50051",
|
|
StationName: "DL-UNKNOWN",
|
|
RefreshRateMs: 250,
|
|
Rotor: RotorSettings{
|
|
Type: "Standard",
|
|
Port: "Simulation",
|
|
HomeAzimuth: 180.0, // Standardmäßig Süden
|
|
HomeElevation: 0.0, // Standardmäßig Horizont
|
|
},
|
|
},
|
|
}
|
|
|
|
if _, err := os.Stat(path); os.IsNotExist(err) {
|
|
return cfg, nil
|
|
}
|
|
|
|
if _, err := toml.DecodeFile(path, cfg); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return cfg, nil
|
|
}
|