From f2a09928c3c1d406452098cb15f663a62611fc95 Mon Sep 17 00:00:00 2001 From: Bernhard Tittelbach Date: Tue, 24 Sep 2013 19:41:49 +0000 Subject: [PATCH] ++timeout for firmware answer, --bug --- go/door_daemon_zmq/handle_commands.go | 3 +-- go/door_daemon_zmq/main.go | 9 +++++++++ go/door_daemon_zmq/serial_tty.go | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/go/door_daemon_zmq/handle_commands.go b/go/door_daemon_zmq/handle_commands.go index 35c3b02..1595561 100644 --- a/go/door_daemon_zmq/handle_commands.go +++ b/go/door_daemon_zmq/handle_commands.go @@ -57,8 +57,7 @@ func HandleCommand(tokens [][]byte, serial_wr chan string, serial_rd chan [][]by } if err := dch.Checker(tokens); err != nil { - //return error to sender - return nil + return err } serial_wr <- dch.FirmwareChar diff --git a/go/door_daemon_zmq/main.go b/go/door_daemon_zmq/main.go index d943d8d..8d376be 100644 --- a/go/door_daemon_zmq/main.go +++ b/go/door_daemon_zmq/main.go @@ -6,6 +6,7 @@ import ( "fmt" "os" "flag" + "time" //~ "log" ) @@ -59,6 +60,8 @@ func main() { //~ firmware_version := <- serial_rd //~ log.Print("Firmware version:", firmware_version) var next_incoming_serial_is_client_reply bool + timeout_chan := make(chan bool) + defer close(timeout_chan) for { select { case incoming_ser_line, is_notclosed := <- serial_rd: @@ -71,6 +74,11 @@ func main() { } else { os.Exit(1) } + case tv, timeout_notclosed := <- timeout_chan: + if timeout_notclosed && tv && next_incoming_serial_is_client_reply { + next_incoming_serial_is_client_reply = false + cmd_chans.Out() <- [][]byte{[]byte("ERROR"), []byte("No reply from firmware")} + } case incoming_request, ic_notclosed := <- cmd_chans.In(): if ! ic_notclosed {os.Exit(2)} //~ log.Print(incoming_request) @@ -83,6 +91,7 @@ func main() { //~ log.Print(reply) pub_chans.Out() <- incoming_request next_incoming_serial_is_client_reply = true + go func(){time.Sleep(3*time.Second); timeout_chan <- true;}() //~ log.Print("sent reply") } } diff --git a/go/door_daemon_zmq/serial_tty.go b/go/door_daemon_zmq/serial_tty.go index d7fd7a9..89f0b0c 100644 --- a/go/door_daemon_zmq/serial_tty.go +++ b/go/door_daemon_zmq/serial_tty.go @@ -52,7 +52,7 @@ func OpenAndHandleSerial(filename string) (chan string, chan [][]byte, error) { return nil, nil, err } wr := make(chan string) - rd := make(chan [][]byte, 10) + rd := make(chan [][]byte, 20) go serialWriter(wr, serial) go serialReader(rd, serial) return wr, rd, nil -- 1.7.10.4