}
}
-func main() {
+func main() {
cmd_chans, sub_chans := ZmqsInit(cmd_port_, sub_port_)
defer cmd_chans.Close()
defer sub_chans.Close()
user_input_chan := make(chan [][]byte, 1)
go LineReader(user_input_chan, os.Stdin)
defer os.Stdin.Close()
-
+
for {
select {
case input, input_open := (<- user_input_chan):
}
//close only on panic, otherwise leave open:
defer func(){ if r:= recover(); r != nil { cmd_ctx.Close(); panic(r) } }()
-
+
pub_ctx, err := zmq.NewContext()
if err != nil {
panic(err)
}
defer func() { if r:= recover(); r != nil { pub_ctx.Close(); panic(r) } }()
-
+
cmd_sock, err := cmd_ctx.Socket(zmq.Req)
if err != nil {
panic(err)
if err = pub_sock.Bind(sub_port); err != nil {
panic(err)
}
-
+
cmd_chans = cmd_sock.Channels()
pub_chans = cmd_sock.Channels()
go zmqsHandleError(cmd_chans, pub_chans)
if len(tokens) < 1 {
return nil, errors.New("No Command to handle")
}
-
+
dch, present := cmdToDoorCmdHandler[string(tokens[0])]
if ! present {
return nil, errors.New("Unknown Command")
//return error to sender
return nil, err
}
-
+
topub <- tokens
serial_wr <- dch.FirmwareChar
fw_reply := <- serial_rd
usage()
os.Exit(1);
}
-
- cmd_chans, pub_chans := ZmqsInit(cmd_port_, pub_port_)
-
+
+ cmd_chans, pub_chans := ZmqsInit(cmd_port_, pub_port_)
+
serial_wr, serial_rd, err := OpenAndHandleSerial(args[0], pub_chans.Out())
if err != nil {
close(serial_wr)
panic(err)
}
-
+
serial_wr <- "f"
firmware_version := <- serial_rd
log.Print("Firmware version:", firmware_version)
log.Print(err)
} else {
cmd_chans.Out() <- reply
- }
+ }
}
}
}
//close only on panic, otherwise leave open:
defer func(){ if r:= recover(); r != nil { cmd_ctx.Close(); panic(r) } }()
-
+
pub_ctx, err := zmq.NewContext()
if err != nil {
panic(err)
}
defer func() { if r:= recover(); r != nil { pub_ctx.Close(); panic(r) } }()
-
+
cmd_sock, err := cmd_ctx.Socket(zmq.Rep)
if err != nil {
panic(err)
if err = pub_sock.Bind(pub_port); err != nil { // "tcp://*:5556"
panic(err)
}
-
+
cmd_chans = cmd_sock.Channels()
pub_chans = cmd_sock.Channels()
go zmqsHandleError(cmd_chans, pub_chans)