"fmt"
"os"
"flag"
+ "time"
//~ "log"
)
//~ 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:
} 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)
//~ 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")
}
}
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