From 957f71721b04698dd588ffc8dc2ed10775050451 Mon Sep 17 00:00:00 2001 From: Bernhard Tittelbach Date: Wed, 2 Oct 2013 22:54:37 +0000 Subject: [PATCH] door daemon command 'log' --- go/door_daemon_zmq/handle_commands.go | 6 +++--- go/door_daemon_zmq/main.go | 31 ++++++++++++++++++++++--------- go/door_daemon_zmq/serial_tty.go | 1 + go/r3-eventbroker_zmq/main.go | 10 ++++++++++ go/r3-eventbroker_zmq/make_deploy.zsh | 4 ++-- 5 files changed, 38 insertions(+), 14 deletions(-) diff --git a/go/door_daemon_zmq/handle_commands.go b/go/door_daemon_zmq/handle_commands.go index 0cfee8d..33db54e 100644 --- a/go/door_daemon_zmq/handle_commands.go +++ b/go/door_daemon_zmq/handle_commands.go @@ -15,7 +15,7 @@ var cmdToDoorCmdHandler = map[string]DoorCmdHandler { "open": DoorCmdHandler{ checkCmdDoorControl, "o"}, "close": DoorCmdHandler{ checkCmdDoorControl, "c"}, "toggle": DoorCmdHandler{ checkCmdDoorControl, "t"}, - "status": DoorCmdHandler{ checkCmdStatus, "s"}, + "status": DoorCmdHandler{ checkCmdNoArgs, "s"}, } // ---------- Command Handling Code ------------- @@ -39,9 +39,9 @@ func checkCmdDoorControl(tokens [][]byte) (error) { return nil } -func checkCmdStatus(tokens [][]byte) (error) { +func checkCmdNoArgs(tokens [][]byte) (error) { if len(tokens) != 1 { - return errors.New("status command does not accept arguments") + return errors.New("command does not accept arguments") } return nil } diff --git a/go/door_daemon_zmq/main.go b/go/door_daemon_zmq/main.go index e295c4e..3ff5657 100644 --- a/go/door_daemon_zmq/main.go +++ b/go/door_daemon_zmq/main.go @@ -26,7 +26,7 @@ var ( pub_port_ string door_tty_path_ string use_syslog_ bool - syslog_ *log.Logger + Syslog_ *log.Logger ) func usage() { @@ -57,10 +57,10 @@ func main() { if use_syslog_ { var logerr error - syslog_, logerr = syslog.NewLogger(syslog.LOG_INFO | syslog.LOG_LOCAL1, 0) + Syslog_, logerr = syslog.NewLogger(syslog.LOG_INFO | syslog.LOG_LOCAL1, 0) if logerr != nil { panic(logerr) } - syslog_.Print("started") - defer syslog_.Print("exiting") + Syslog_.Print("started") + defer Syslog_.Print("exiting") } //~ serial_wr <- "f" @@ -73,15 +73,15 @@ func main() { select { case incoming_ser_line, is_notclosed := <- serial_rd: if is_notclosed { - //~ if syslog_ != nil { syslog_.Print(ByteArrayToString(incoming_ser_line)) } - if syslog_ != nil { syslog_.Printf("%s",incoming_ser_line) } + //~ if Syslog_ != nil { Syslog_.Print(ByteArrayToString(incoming_ser_line)) } + if Syslog_ != nil { Syslog_.Printf("%s",incoming_ser_line) } if next_incoming_serial_is_client_reply { next_incoming_serial_is_client_reply = false cmd_chans.Out() <- incoming_ser_line } pub_chans.Out() <- incoming_ser_line } else { - syslog_.Print("serial device disappeared, exiting") + Syslog_.Print("serial device disappeared, exiting") os.Exit(1) } case tv, timeout_notclosed := <- timeout_chan: @@ -91,10 +91,23 @@ func main() { } case incoming_request, ic_notclosed := <- cmd_chans.In(): if ! ic_notclosed { - syslog_.Print("zmq socket died, exiting") + Syslog_.Print("zmq socket died, exiting") os.Exit(2) } - if syslog_ != nil { syslog_.Printf("%s",incoming_request) } + if string(incoming_request[0]) == "log" { + if len(incoming_request) < 2 { + cmd_chans.Out() <- [][]byte{[]byte("ERROR"), []byte("argument missing")} + continue + } + if Syslog_ == nil { + cmd_chans.Out() <- [][]byte{[]byte("ERROR"), []byte("syslog logging not enabled")} + continue + } + Syslog_.Printf("Log: %s",incoming_request[1:]) + cmd_chans.Out() <- [][]byte{[]byte("Ok")} + continue + } + if Syslog_ != nil { Syslog_.Printf("%s",incoming_request) } if err := HandleCommand(incoming_request, serial_wr, serial_rd); err != nil { out_msg := [][]byte{[]byte("ERROR"), []byte(err.Error())} cmd_chans.Out() <- out_msg diff --git a/go/door_daemon_zmq/serial_tty.go b/go/door_daemon_zmq/serial_tty.go index ea246ca..48afd33 100644 --- a/go/door_daemon_zmq/serial_tty.go +++ b/go/door_daemon_zmq/serial_tty.go @@ -11,6 +11,7 @@ import ( "log" ) + // ---------- Serial TTY Code ------------- func openTTY(name string) (*os.File, error) { diff --git a/go/r3-eventbroker_zmq/main.go b/go/r3-eventbroker_zmq/main.go index dbd35eb..6d1a5cd 100644 --- a/go/r3-eventbroker_zmq/main.go +++ b/go/r3-eventbroker_zmq/main.go @@ -53,6 +53,10 @@ func main() { defer pub_out_socket.Close() defer keylookup_socket.Close() + if sub_in_chans == nil || pub_out_socket == nil || keylookup_socket == nil { + panic("zmq sockets must not be nil !!") + } + if use_syslog_ { var logerr error Syslog_, logerr = syslog.NewLogger(syslog.LOG_INFO | (18<<3), 0) @@ -69,6 +73,12 @@ func main() { go MetaEventRoutine_Movement(ps, 10, 20, 10) go MetaEventRoutine_Presence(ps) + for xx := range(sub_in_chans.In()) { + log.Print(xx) + Syslog_.Print(xx) + } + + for { log.Print("for loop") select { diff --git a/go/r3-eventbroker_zmq/make_deploy.zsh b/go/r3-eventbroker_zmq/make_deploy.zsh index 746215b..a890077 100644 --- a/go/r3-eventbroker_zmq/make_deploy.zsh +++ b/go/r3-eventbroker_zmq/make_deploy.zsh @@ -1,7 +1,7 @@ #!/bin/zsh export GO386=387 export CGO_ENABLED=1 -go-linux-386 clean +go clean #go-linux-386 build #strip ${PWD:t} -go-linux-386 build -ldflags "-s" && rsync -v ${PWD:t} wuzzler.realraum.at:/flash/tuer/ +go build -ldflags "-s" && rsync -v ${PWD:t} wuzzler.realraum.at:/flash/tuer/ -- 1.7.10.4