mirror of
https://github.com/nonoo/kappanhang.git
synced 2026-01-18 23:00:16 +01:00
Added flag to show CI-V packet contents to support debugging
At start-up show virtual soundcard info by both name & filesystem location
Updated to always present status lines at bottom of the terminal
Removed milliseconds from time shown on status lines
Reformatted status line showing packet activity to be easier to follow
Adjusted default status update frequency to 150ms to be easier to observe
Restored commented out code for working with single VFO
Added multiple functions to handle BCD <-> human readable values to improve easy of maintenance
Added function to prepare CI-V packets, abstracting this step so that each function no longer
needs to create entire packet. This makes the code much easier to follow and maintaint.
This will also greatly ease effort needed for extending radio features supported
Added/adjusted various comments
Updated some variable names to be less terse to facilitate maintenance
eg "incTS" to "incTuningStep"
Some adjustments to improve readability/ease maintenance in favor of unnecessary optimizations
EG - using formatted prints instead of prints using concatenations
using strings.Repeat instead of loop to build space buffers
abstracted control char strings to variables
Hooks for future functionality
Removed some commented out code blocks
"Trust the repo, Luke!"
90 lines
2.9 KiB
Go
90 lines
2.9 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"strconv"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/pborman/getopt"
|
|
)
|
|
|
|
var (
|
|
verboseLog bool
|
|
quietLog bool
|
|
connectAddress string
|
|
username string
|
|
password string
|
|
civAddress byte
|
|
controllerAddress byte
|
|
serialTCPPort uint16
|
|
enableSerialDevice bool
|
|
rigctldPort uint16
|
|
runCmd string
|
|
runCmdOnSerialPortCreated string
|
|
statusLogInterval time.Duration
|
|
setDataModeOnTx bool
|
|
debugPackets bool
|
|
)
|
|
|
|
func parseArgs() {
|
|
h := getopt.BoolLong("help", 'h', "display help")
|
|
v := getopt.BoolLong("verbose", 'v', "Enable verbose (debug) logging")
|
|
q := getopt.BoolLong("quiet", 'q', "Disable logging")
|
|
a := getopt.StringLong("address", 'a', "IC-705", "Connect to address")
|
|
u := getopt.StringLong("username", 'u', "beer", "Username")
|
|
p := getopt.StringLong("password", 'p', "beerbeer", "Password")
|
|
c := getopt.StringLong("civ-address", 'c', "0xa4", "CI-V address for radio")
|
|
t := getopt.Uint16Long("serial-tcp-port", 't', 4531, "Expose radio's serial port on this TCP port")
|
|
s := getopt.BoolLong("enable-serial-device", 's', "Expose radio's serial port as a virtual serial port")
|
|
r := getopt.Uint16Long("rigctld-port", 'r', 4532, "Use this TCP port for the internal rigctld")
|
|
e := getopt.StringLong("exec", 'e', "", "Exec cmd when connected")
|
|
o := getopt.StringLong("exec-serial", 'o', "socat /tmp/kappanhang-IC-705.pty /tmp/vmware.pty", "Exec cmd when virtual serial port is created, set to - to disable")
|
|
i := getopt.Uint16Long("log-interval", 'i', 150, "Status bar/log interval in milliseconds")
|
|
d := getopt.BoolLong("set-data-tx", 'd', "Automatically enable data mode on TX")
|
|
dp := getopt.BoolLong("debug-packets", 'D', "Show CI-V packets for debugging")
|
|
ca := getopt.StringLong("controller-address", 'z', "0xe0", "Controller address")
|
|
|
|
getopt.Parse()
|
|
|
|
if *h || *a == "" || (*q && *v) {
|
|
fmt.Println(getAboutStr())
|
|
getopt.Usage()
|
|
os.Exit(1)
|
|
}
|
|
|
|
verboseLog = *v
|
|
quietLog = *q
|
|
connectAddress = *a
|
|
username = *u
|
|
password = *p
|
|
|
|
*c = strings.Replace(*c, "0x", "", -1)
|
|
*c = strings.Replace(*c, "0X", "", -1)
|
|
civAddressInt, err := strconv.ParseInt(*c, 16, 64)
|
|
if err != nil {
|
|
fmt.Println("invalid CI-V address: can't parse", *c)
|
|
os.Exit(1)
|
|
}
|
|
civAddress = byte(civAddressInt)
|
|
|
|
*ca = strings.Replace(*ca, "0x", "", -1)
|
|
*ca = strings.Replace(*ca, "0X", "", -1)
|
|
controllerAddressInt, err := strconv.ParseInt(*ca, 16, 64)
|
|
if err != nil {
|
|
fmt.Println("invalid CI-V address for controller: can't parse", *ca)
|
|
os.Exit(1)
|
|
}
|
|
controllerAddress = byte(controllerAddressInt)
|
|
|
|
serialTCPPort = *t
|
|
enableSerialDevice = *s
|
|
rigctldPort = *r
|
|
runCmd = *e
|
|
runCmdOnSerialPortCreated = *o
|
|
statusLogInterval = time.Duration(*i) * time.Millisecond
|
|
setDataModeOnTx = *d
|
|
debugPackets = *dp
|
|
}
|