kappanhang/args.go

74 lines
2.2 KiB
Go
Raw Normal View History

2020-10-16 17:13:46 +02:00
package main
import (
2020-10-26 08:39:12 +01:00
"fmt"
2020-10-16 17:13:46 +02:00
"os"
"strconv"
"strings"
2020-10-28 10:15:13 +01:00
"time"
2020-10-16 17:13:46 +02:00
"github.com/pborman/getopt"
)
2020-10-26 09:09:30 +01:00
var verboseLog bool
var quietLog bool
2020-10-16 17:13:46 +02:00
var connectAddress string
2020-11-05 23:13:46 +01:00
var username string
var password string
2020-11-09 09:54:50 +01:00
var civAddress byte
2020-10-25 16:15:39 +01:00
var serialTCPPort uint16
2020-10-25 21:12:59 +01:00
var enableSerialDevice bool
2020-11-08 20:48:39 +01:00
var rigctldPort uint16
var runCmd string
var runCmdOnSerialPortCreated string
2020-10-28 10:15:13 +01:00
var statusLogInterval time.Duration
2020-12-21 08:57:06 +01:00
var setDataModeOnTx bool
2020-10-16 17:13:46 +02:00
func parseArgs() {
h := getopt.BoolLong("help", 'h', "display help")
2020-10-26 09:09:30 +01:00
v := getopt.BoolLong("verbose", 'v', "Enable verbose (debug) logging")
q := getopt.BoolLong("quiet", 'q', "Disable logging")
2020-10-16 17:13:46 +02:00
a := getopt.StringLong("address", 'a', "IC-705", "Connect to address")
2020-11-05 23:13:46 +01:00
u := getopt.StringLong("username", 'u', "beer", "Username")
p := getopt.StringLong("password", 'p', "beerbeer", "Password")
c := getopt.StringLong("civ-address", 'c', "0xa4", "CI-V address")
t := getopt.Uint16Long("serial-tcp-port", 't', 4531, "Expose radio's serial port on this TCP port")
2020-10-25 21:12:59 +01:00
s := getopt.BoolLong("enable-serial-device", 's', "Expose radio's serial port as a virtual serial port")
2020-11-08 20:48:39 +01:00
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', 100, "Status bar/log interval in milliseconds")
2020-12-21 08:57:06 +01:00
d := getopt.BoolLong("set-data-tx", 'd', "Automatically enable data mode on TX")
2020-10-16 17:13:46 +02:00
getopt.Parse()
if *h || *a == "" || (*q && *v) {
2020-10-26 08:39:12 +01:00
fmt.Println(getAboutStr())
2020-10-16 17:13:46 +02:00
getopt.Usage()
os.Exit(1)
}
2020-10-26 09:09:30 +01:00
verboseLog = *v
quietLog = *q
2020-10-16 17:13:46 +02:00
connectAddress = *a
2020-11-05 23:13:46 +01:00
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)
2020-10-25 16:15:39 +01:00
serialTCPPort = *t
2020-10-25 21:12:59 +01:00
enableSerialDevice = *s
2020-11-08 20:48:39 +01:00
rigctldPort = *r
runCmd = *e
runCmdOnSerialPortCreated = *o
2020-10-28 10:15:13 +01:00
statusLogInterval = time.Duration(*i) * time.Millisecond
2020-12-21 08:57:06 +01:00
setDataModeOnTx = *d
2020-10-16 17:13:46 +02:00
}