pub_port_ string
keylookup_addr_ string
brain_listen_addr_ string
+ door_cmd_addr_ string
use_syslog_ bool
enable_debuglog_ bool
)
}
func init() {
+ flag.StringVar(&door_cmd_addr_, "doorcmdaddr", "ipc:///run/tuer/door_cmd.ipc", "zmq door event publish addr")
flag.StringVar(&doorsub_addr_, "doorsubaddr", "tcp://torwaechter.realraum.at:4242", "zmq door event publish addr")
flag.StringVar(&sensorssub_port_, "sensorsubport", "tcp://*:4243", "zmq public/listen socket addr for incoming sensor data")
flag.StringVar(&pub_port_, "pubport", "tcp://*:4244", "zmq port publishing consodilated events")
go MetaEventRoutine_Movement(ps, 10, 20, 10)
go MetaEventRoutine_Presence(ps)
+ // --- get update on most recent status ---
+ answ := ZmqsAskQuestionsAndClose(zmqctx, door_cmd_addr_, [][][]byte{[][]byte{[]byte("status")}})
+ for _, a := range(answ) {
+ ParseSocketInputLine(a, ps, keylookup_socket)
+ }
+
publish_these_events_chan := ps.Sub("door", "doorcmd", "presence", "sensors", "buttons", "movement")
for {
select {
)
func MetaEventRoutine_Presence(ps *pubsub.PubSub) {
- //~ var last_door_cmd *DoorCommandEvent
+ //~ var last_door_cmd *r3events.DoorCommandEvent
var last_presence bool
var last_movement, last_buttonpress int64
var front_locked, front_shut, back_shut bool = true, true, true
defer ps.Unsub(events_chan, "door", "doorcmd", "buttons", "movement")
for event := range(events_chan) {
- //~ Debug_.Printf("Presence: %s - %s", event, doorstatemap)
+ Debug_.Printf("Presence prior: %t : %T %+v", last_presence, event, event)
new_presence := last_presence
ts := time.Now().Unix()
switch evnt := event.(type) {
case r3events.BoreDoomButtonPressEvent:
last_buttonpress = evnt.Ts
new_presence = true
- //~ case DoorCommandEvent:
+ case r3events.DoorCommandEvent:
//~ last_door_cmd = &evnt
case r3events.DoorLockUpdate:
front_locked = evnt.Locked
back_shut = evnt.Shut
}
- any_door_unlocked := ! front_locked
+ any_door_unlocked := (front_locked == false)
any_door_ajar := ! (front_shut && back_shut)
if new_presence != last_presence {
return parts
}
+func ZmqsAskQuestionsAndClose(ctx *zmq.Context, addr string, questions [][][]byte) [][][]byte {
+ if len(addr) == 0 || ctx == nil { return nil }
+
+ req_sock, err := ctx.Socket(zmq.Req)
+ if err != nil {
+ return nil
+ }
+ defer req_sock.Close()
+
+ if err = req_sock.Connect(addr); err != nil {
+ return nil
+ }
+
+ rv := make([][][]byte, len(questions))
+ for index, q := range(questions) {
+ rv[index] = ZmqsRequestAnswer(req_sock, q)
+ }
+ return rv
+}
+
func LookupCardIdNick(s *zmq.Socket, hexbytes []byte) (string, error) {
answ := ZmqsRequestAnswer(s, [][]byte{hexbytes})
if len(answ) == 0 {