From 12e146db301d057bd59de4aa3909c9504f232212 Mon Sep 17 00:00:00 2001 From: Nonoo Date: Sun, 1 Nov 2020 16:08:34 +0100 Subject: [PATCH] Auto rerun command if the TCP serial port client disconnects --- README.md | 4 +++- args.go | 3 +++ main.go | 1 + runcmd.go | 5 +++++ serialtcpsrv.go | 5 +++++ 5 files changed, 17 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ac29419..6419e8b 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/args.go b/args.go index a7e9988..1ab72e5 100644 --- a/args.go +++ b/args.go @@ -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 } diff --git a/main.go b/main.go index 5db6b65..f2e57d0 100644 --- a/main.go +++ b/main.go @@ -133,6 +133,7 @@ func main() { } stopCmd() + stopSerialPortCmd() audio.deinit() serialTCPSrv.deinit() serialPort.deinit() diff --git a/runcmd.go b/runcmd.go index 015f1b0..62f6afe 100644 --- a/runcmd.go +++ b/runcmd.go @@ -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 } } diff --git a/serialtcpsrv.go b/serialtcpsrv.go index d93e696..117f3f0 100644 --- a/serialtcpsrv.go +++ b/serialtcpsrv.go @@ -103,6 +103,11 @@ func (s *serialTCPSrvStruct) loop() { s.disconnectClient() log.Print("client ", s.client.RemoteAddr().String(), " disconnected") + + if !disableReRunCmd { + stopCmd() + startCmdIfNeeded() + } } }