Auto rerun command if the TCP serial port client disconnects

This commit is contained in:
Nonoo 2020-11-01 16:08:34 +01:00
parent 04605ac53f
commit 12e146db30
5 changed files with 17 additions and 1 deletions

View file

@ -68,7 +68,9 @@ After it is connected and logged in:
connects it to kappanhang's TCP serial port server. You can specify a custom
command with the `-r` command line argument. Running any command can be
disabled with `-r -`. The command is only executed once, as the TCP serial
port server will stay on even if the RS-BA1 server disconnects.
port server will stay on even if the RS-BA1 server disconnects. If the TCP
serial port client disconnects (rigctld hangs) then the command will be
automatically restarted. This can be disabled with the `-e`.
3085 is the model number of the Icom IC-705. `rigctld` will connect to
kappanhang's TCP serial port server, and waits connections on it's default

View file

@ -13,6 +13,7 @@ var connectAddress string
var serialTCPPort uint16
var enableSerialDevice bool
var runCmd string
var disableReRunCmd bool
var runCmdOnSerialPortCreated string
var statusLogInterval time.Duration
@ -23,6 +24,7 @@ func parseArgs() {
t := getopt.Uint16Long("serial-tcp-port", 'p', 4533, "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.StringLong("run", 'r', "rigctld -m 3085 -r :4533", "Exec cmd when connected, set to - to disable")
e := getopt.BoolLong("disable-rerun", 'e', "Disable re-execing the cmd on TCP serial port disconnect")
o := getopt.StringLong("run-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")
@ -39,6 +41,7 @@ func parseArgs() {
serialTCPPort = *t
enableSerialDevice = *s
runCmd = *r
disableReRunCmd = *e
runCmdOnSerialPortCreated = *o
statusLogInterval = time.Duration(*i) * time.Millisecond
}

View file

@ -133,6 +133,7 @@ func main() {
}
stopCmd()
stopSerialPortCmd()
audio.deinit()
serialTCPSrv.deinit()
serialPort.deinit()

View file

@ -56,10 +56,15 @@ func stopCmd() {
if err := startedCmd.Process.Kill(); err != nil {
log.Error("failed to stop cmd ", runCmd, ": ", err)
}
startedCmd = nil
}
}
func stopSerialPortCmd() {
if serialPortStartedCmd != nil {
if err := serialPortStartedCmd.Process.Kill(); err != nil {
log.Error("failed to stop cmd ", runCmdOnSerialPortCreated, ": ", err)
}
serialPortStartedCmd = nil
}
}

View file

@ -103,6 +103,11 @@ func (s *serialTCPSrvStruct) loop() {
s.disconnectClient()
log.Print("client ", s.client.RemoteAddr().String(), " disconnected")
if !disableReRunCmd {
stopCmd()
startCmdIfNeeded()
}
}
}