1 // (c) Bernhard Tittelbach, 2013
12 //~ func StringArrayToByteArray(ss []string) [][]byte {
13 //~ bb := make([][]byte, len(ss))
14 //~ for index, s := range(ss) {
15 //~ bb[index] = []byte(s)
20 // ---------- Main Code -------------
28 fmt.Fprintf(os.Stderr, "Usage: door_daemon_0mq <door tty device>\n")
33 flag.StringVar(&cmd_port_, "cmdport", "tcp://127.0.01:3232", "zmq command socket path")
34 flag.StringVar(&pub_port_, "pubport", "pgm://233.252.1.42:4242", "zmq public/listen socket path")
42 fmt.Fprintf(os.Stderr, "Input file is missing!\n");
47 zmqctx, cmd_chans, pub_chans := ZmqsInit(cmd_port_, pub_port_)
48 defer cmd_chans.Close()
49 defer pub_chans.Close()
52 serial_wr, err := OpenAndHandleSerial(args[0], pub_chans.Out())
53 defer close(serial_wr)
59 //~ firmware_version := <- serial_rd
60 //~ log.Print("Firmware version:", firmware_version)
62 for incoming_request := range cmd_chans.In() {
63 //~ log.Print(incoming_request)
64 reply, err := HandleCommand(incoming_request, pub_chans.Out(), serial_wr)
67 out_msg := [][]byte{[]byte("ERROR"), []byte(err.Error())}
68 cmd_chans.Out() <- out_msg
69 //~ log.Print("sent error")
72 cmd_chans.Out() <- reply
73 //~ log.Print("sent reply")