Skip to content

Commit

Permalink
serial-tnc: New baudrate config fields
Browse files Browse the repository at this point in the history
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
  • Loading branch information
martinhpedersen committed Oct 31, 2021
1 parent d7cc80b commit 3e4ab77
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 11 deletions.
18 changes: 13 additions & 5 deletions cfg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion cfg/example_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
},
"serial-tnc": {
"path": "/dev/ttyUSB0",
"baudrate": 9600,
"hbaud": 1200,
"serial_baud": 9600,
"type": "Kenwood"
},
"winmor": {
Expand Down
7 changes: 7 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}

Expand Down
7 changes: 5 additions & 2 deletions connect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit 3e4ab77

Please sign in to comment.