++timeout for firmware answer, --bug
authorBernhard Tittelbach <xro@realraum.at>
Tue, 24 Sep 2013 19:41:49 +0000 (19:41 +0000)
committerBernhard Tittelbach <xro@realraum.at>
Tue, 24 Sep 2013 19:41:49 +0000 (19:41 +0000)
go/door_daemon_zmq/handle_commands.go
go/door_daemon_zmq/main.go
go/door_daemon_zmq/serial_tty.go

index 35c3b02..1595561 100644 (file)
@@ -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
index d943d8d..8d376be 100644 (file)
@@ -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")
                  }
         }
index d7fd7a9..89f0b0c 100644 (file)
@@ -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