From 39a41339d2ce0cc3bbbe4d270377e4e698631c1e Mon Sep 17 00:00:00 2001 From: Bernhard Tittelbach Date: Sat, 24 Aug 2013 20:01:40 +0000 Subject: [PATCH] --bug, movement, identation --- r3-netstatus/main.go | 20 ++++++++++---------- r3-netstatus/make_deploy.zsh | 3 ++- r3-netstatus/sockettoevent.go | 26 +++++++++++++++++--------- 3 files changed, 29 insertions(+), 20 deletions(-) diff --git a/r3-netstatus/main.go b/r3-netstatus/main.go index 8851c74..abec0c1 100644 --- a/r3-netstatus/main.go +++ b/r3-netstatus/main.go @@ -10,15 +10,15 @@ import ( ) type SpaceState struct { - present bool - buttonpress_until int64 + present bool + buttonpress_until int64 door_locked bool door_shut bool } var ( presence_socket_path_ string - xmpp_presence_events_chan_ chan interface{} + xmpp_presence_events_chan_ chan interface{} xmpp_login_ struct {jid string; pass string} xmpp_bot_authstring_ string xmpp_state_save_dir_ string @@ -27,11 +27,11 @@ var ( //------- func init() { - flag.StringVar(&xmpp_login_.jid, "xjid", "realrauminfo@realraum.at/Tuer", "XMPP Bot Login JID") - flag.StringVar(&xmpp_login_.pass, "xpass", "", "XMPP Bot Login Password") - flag.StringVar(&xmpp_bot_authstring_, "xbotauth", "", "String that user use to authenticate themselves to the bot") - flag.StringVar(&presence_socket_path_,"presencesocket", "/var/run/tuer/presence.socket", "Path to presence socket") - flag.StringVar(&xmpp_state_save_dir_,"xstatedir","/flash/var/lib/r3netstatus/", "Directory to save XMPP bot state in") + flag.StringVar(&xmpp_login_.jid, "xjid", "realrauminfo@realraum.at/Tuer", "XMPP Bot Login JID") + flag.StringVar(&xmpp_login_.pass, "xpass", "", "XMPP Bot Login Password") + flag.StringVar(&xmpp_bot_authstring_, "xbotauth", "", "String that user use to authenticate themselves to the bot") + flag.StringVar(&presence_socket_path_,"presencesocket", "/var/run/tuer/presence.socket", "Path to presence socket") + flag.StringVar(&xmpp_state_save_dir_,"xstatedir","/flash/var/lib/r3netstatus/", "Directory to save XMPP bot state in") flag.Parse() } @@ -49,11 +49,11 @@ func EventToXMPP(ps *pubsub.PubSub, xmpp_presence_events_chan_ chan <- interface xmpp_presence_events_chan_ <- r3xmppbot.XMPPPresenceEvent{Present: present, Who: who, DoorLock: locked, DoorShut: shut, Button: false} case DoorCommandEvent: who = event.Who - xmpp_presence_events_chan_ <- fmt.Sprintln("DoorCommandEvent",event) + xmpp_presence_events_chan_ <- fmt.Sprintln("DoorCommand: ",event.Command, "using", event.Using, "by", event.Who, event.Ts) case DoorStatusUpdate: locked = event.Locked shut = event.Shut - xmpp_presence_events_chan_ <- fmt.Sprintln("DoorStatusUpdate",event) + xmpp_presence_events_chan_ <- fmt.Sprintln("DoorStatus locked:",event.Locked, "shut:", event.Shut, event.Ts) case ButtonPressUpdate: xmpp_presence_events_chan_ <- r3xmppbot.XMPPPresenceEvent{Present: present, Who: who, DoorLock: locked, DoorShut: shut, Button: true} } diff --git a/r3-netstatus/make_deploy.zsh b/r3-netstatus/make_deploy.zsh index 35e93e5..3cc441c 100644 --- a/r3-netstatus/make_deploy.zsh +++ b/r3-netstatus/make_deploy.zsh @@ -1,6 +1,7 @@ #!/bin/zsh +export GO386=387 go-linux-386 clean #go-linux-386 build #strip ${PWD:t} go-linux-386 build -ldflags "-s" -rsync -v ${PWD:t} wuzzler.realraum.at:/flash/tuer/ \ No newline at end of file +rsync -v ${PWD:t} wuzzler.realraum.at:/flash/tuer/ diff --git a/r3-netstatus/sockettoevent.go b/r3-netstatus/sockettoevent.go index 7f0d20c..405dbbf 100644 --- a/r3-netstatus/sockettoevent.go +++ b/r3-netstatus/sockettoevent.go @@ -13,7 +13,7 @@ import ( var ( re_presence_ *regexp.Regexp = regexp.MustCompile("Presence: (yes|no)(?:, (opened|closed), (.+))?") re_status_ *regexp.Regexp = regexp.MustCompile("Status: (closed|opened), (opening|waiting|closing|idle), (ajar|shut).*") - re_command_ *regexp.Regexp = regexp.MustCompile("(open|close|toggle) (Card |Phone )?([^ ]+) *") + re_command_ *regexp.Regexp = regexp.MustCompile("(open|close|toggle) (?:(Card|Phone) )?(.+)") re_button_ *regexp.Regexp = regexp.MustCompile("PanicButton|button\\d?") re_temp_ *regexp.Regexp = regexp.MustCompile("temp0: (\\d+\\.\\d+)") re_photo_ *regexp.Regexp = regexp.MustCompile("photo0: (\\d+)") @@ -59,18 +59,23 @@ type TimeTick struct { Ts int64 } +type MovementSensorUpdate struct { + Sensorindex int + Ts int64 +} func ParseSocketInputLine(line string, ps *pubsub.PubSub) { //, brn *brain.Brain) { - match_presence := re_presence_.FindStringSubmatch(line) - match_status := re_status_.FindStringSubmatch(line) - match_command := re_command_.FindStringSubmatch(line) - match_button := re_button_.FindStringSubmatch(line) - match_temp := re_temp_.FindStringSubmatch(line) - match_photo := re_photo_.FindStringSubmatch(line) + match_presence := re_presence_.FindStringSubmatch(line) + match_status := re_status_.FindStringSubmatch(line) + match_command := re_command_.FindStringSubmatch(line) + match_button := re_button_.FindStringSubmatch(line) + match_temp := re_temp_.FindStringSubmatch(line) + match_photo := re_photo_.FindStringSubmatch(line) + //~ log.Println("ParseSocketInputLine",line) var tidbit interface{} ts := time.Now().Unix() - if match_presence != nil { + if match_presence != nil { tidbit = PresenceUpdate{match_presence[1] == "yes", ts} //~ brn.Oboite("presence", tidbit) ps.Pub(tidbit, "presence") @@ -79,7 +84,7 @@ func ParseSocketInputLine(line string, ps *pubsub.PubSub) { //, brn *brain.Brain //~ brn.Oboite("door", tidbit) ps.Pub(tidbit, "door") } else if match_command != nil { - tidbit = DoorCommandEvent{match_status[1], match_status[2], match_status[3], ts} + tidbit = DoorCommandEvent{match_command[1], match_command[2], match_command[3], ts} //~ brn.Oboite("doorcmd", tidbit) ps.Pub(tidbit, "door") } else if match_button != nil { @@ -97,6 +102,9 @@ func ParseSocketInputLine(line string, ps *pubsub.PubSub) { //, brn *brain.Brain //~ brn.Oboite("photo0", newphoto) ps.Pub(IlluminationSensorUpdate{0, newphoto, ts}, "sensors") } + } else if line == "movement" { + //~ brn.Oboite("movement", ts) + ps.Pub(MovementSensorUpdate{0, ts}, "movements") } } -- 1.7.10.4