From 3e4ab77bf84006702d3c1b14a2a579733e5ecd4e Mon Sep 17 00:00:00 2001 From: Martin Hebnes Pedersen Date: Sun, 31 Oct 2021 10:34:13 +0100 Subject: [PATCH] serial-tnc: New baudrate config fields This deprecates the serial_tnc.baudrate option. The documentation for this field was incorrect, and the name was confusing. The field is replaced by serial_tnc.hbaud and serial_tnc.serial_baud. Backwards compatibility is maintained. Closes #279 The wl2k-go upgrade also resolves #293 --- cfg/config.go | 18 +++++++++++++----- cfg/example_config.json | 3 ++- config.go | 7 +++++++ connect.go | 7 +++++-- go.mod | 2 +- go.sum | 4 ++-- 6 files changed, 30 insertions(+), 11 deletions(-) diff --git a/cfg/config.go b/cfg/config.go index 1a361251..d2cd93d6 100644 --- a/cfg/config.go +++ b/cfg/config.go @@ -204,8 +204,15 @@ type SerialTNCConfig struct { // Serial port (e.g. /dev/ttyUSB0 or COM1). Path string `json:"path"` - // Baudrate for the serial port (e.g. 57600). - Baudrate int `json:"baudrate"` + // SerialBaud is the serial port's baudrate (e.g. 57600). + SerialBaud int `json:"serial_baud"` + + // HBaud is the the packet connection's baudrate (1200 or 9600). + HBaud int `json:"hbaud"` + + // Baudrate of the packet connection. + // Deprecated: Use HBaud instead. + BaudrateLegacy int `json:"baudrate,omitempty"` // Type of TNC (currently only 'kenwood'). Type string `json:"type"` @@ -265,9 +272,10 @@ var DefaultConfig = Config{ }, }, SerialTNC: SerialTNCConfig{ - Path: "/dev/ttyUSB0", - Baudrate: 9600, - Type: "Kenwood", + Path: "/dev/ttyUSB0", + SerialBaud: 9600, + HBaud: 1200, + Type: "Kenwood", }, Winmor: WinmorConfig{ Addr: "localhost:8500", diff --git a/cfg/example_config.json b/cfg/example_config.json index a6271c2c..d9939f7f 100644 --- a/cfg/example_config.json +++ b/cfg/example_config.json @@ -23,7 +23,8 @@ }, "serial-tnc": { "path": "/dev/ttyUSB0", - "baudrate": 9600, + "hbaud": 1200, + "serial_baud": 9600, "type": "Kenwood" }, "winmor": { diff --git a/config.go b/config.go index ae1f95b2..4196410a 100644 --- a/config.go +++ b/config.go @@ -15,6 +15,7 @@ import ( "strings" "github.com/la5nta/pat/cfg" + "github.com/la5nta/pat/internal/debug" ) func LoadConfig(cfgPath string, fallback cfg.Config) (config cfg.Config, err error) { @@ -62,6 +63,12 @@ func LoadConfig(cfgPath string, fallback cfg.Config) (config cfg.Config, err err config.FormsPath = strings.ReplaceAll(config.FormsPath, "\\", "/") } + // Compatibility for the old baudrate field for serial-tnc + if v := config.SerialTNC.BaudrateLegacy; v != 0 && config.SerialTNC.HBaud == 0 { + debug.Printf("Legacy serial_tnc.baudrate config detected (%d). Translating to serial_tnc.hbaud.", v) + config.SerialTNC.HBaud = v + config.SerialTNC.BaudrateLegacy = 0 + } return config, nil } diff --git a/connect.go b/connect.go index e49f437f..f4274044 100644 --- a/connect.go +++ b/connect.go @@ -87,8 +87,11 @@ func Connect(connectStr string) (success bool) { url.Host = config.AX25.Port case MethodSerialTNC: url.Host = config.SerialTNC.Path - if config.SerialTNC.Baudrate > 0 { - url.Params.Set("hbaud", fmt.Sprint(config.SerialTNC.Baudrate)) + if hbaud := config.SerialTNC.HBaud; hbaud > 0 { + url.Params.Set("hbaud", fmt.Sprint(hbaud)) + } + if sbaud := config.SerialTNC.SerialBaud; sbaud > 0 { + url.Params.Set("serial_baud", fmt.Sprint(sbaud)) } } } diff --git a/go.mod b/go.mod index e40c1935..1c293cf0 100644 --- a/go.mod +++ b/go.mod @@ -12,7 +12,7 @@ require ( github.com/gorilla/websocket v1.4.2 github.com/harenber/ptc-go/pactor/v2 v2.0.0-20201106165819-10108cccf409 github.com/howeyc/gopass v0.0.0-20190910152052-7cb4b85ec19c - github.com/la5nta/wl2k-go v0.7.5 + github.com/la5nta/wl2k-go v0.8.0 github.com/mattn/go-runewidth v0.0.13 // indirect github.com/microcosm-cc/bluemonday v1.0.16 github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 diff --git a/go.sum b/go.sum index 361304d5..e43a75b6 100644 --- a/go.sum +++ b/go.sum @@ -37,8 +37,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/la5nta/wl2k-go v0.7.3/go.mod h1:rTQaxPiAFD3pWGWN8Lh+BskN3Fpii84GoVwpTHNiCjE= -github.com/la5nta/wl2k-go v0.7.5 h1:u8QBMcoTuMxtQ51elQPLB0n7LleItGsIXxCZKxRp3qE= -github.com/la5nta/wl2k-go v0.7.5/go.mod h1:m/O3yYdsWhPdM1K/nAXqqioWRQGJwgKO7D8pEk6AQeY= +github.com/la5nta/wl2k-go v0.8.0 h1:ARd83z7Mj/adcjtZiqJUUvO4ffK2+nbnyn8xkAuC5OY= +github.com/la5nta/wl2k-go v0.8.0/go.mod h1:m/O3yYdsWhPdM1K/nAXqqioWRQGJwgKO7D8pEk6AQeY= github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU= github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=