From b07f14117f5b11ddce087d6a9177587c9438ca65 Mon Sep 17 00:00:00 2001 From: Bernhard Tittelbach Date: Tue, 8 Oct 2013 19:47:09 +0000 Subject: [PATCH] may work but propably won't --- go/r3-eventbroker_zmq/metamovement.go | 31 +++++++++++++++---------------- go/r3-eventbroker_zmq/presence.go | 21 ++++++++++++++------- 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/go/r3-eventbroker_zmq/metamovement.go b/go/r3-eventbroker_zmq/metamovement.go index e61838d..a24d4ed 100644 --- a/go/r3-eventbroker_zmq/metamovement.go +++ b/go/r3-eventbroker_zmq/metamovement.go @@ -46,22 +46,21 @@ func MetaEventRoutine_Movement(ps *pubsub.PubSub, granularity, gran_duration int last_movement2 = ts last_movement3 = ts } - - if last_movement > 0 && ts - last_movement < 3600*6 && ts - last_movement > 3600*3 { - last_movement = 0 - ps.Pub( r3events.SomethingReallyIsMoving{false,99,ts}, "movement") - } - if last_movement1 > 0 && ts - last_movement < 3600*6 && ts - last_movement1 > 120 { - last_movement1 = 0 - ps.Pub( r3events.SomethingReallyIsMoving{false,10,ts}, "movement") - } - if last_movement2 > 0 && ts - last_movement < 3600*6 && ts - last_movement2 > 1800 { - last_movement2 = 0 - ps.Pub( r3events.SomethingReallyIsMoving{false,25,ts}, "movement") - } - if last_movement3 > 0 && ts - last_movement < 3600*6 && ts - last_movement3 > 3600 { - last_movement3 = 0 - ps.Pub( r3events.SomethingReallyIsMoving{false,50,ts}, "movement") + // this sucks..... + if last_movement > 0 && ts - last_movement < 3600*6 { + if ts - last_movement > 3600*3 { + last_movement = 0 + ps.Pub( r3events.SomethingReallyIsMoving{false,99,ts}, "movement") + } else if ts - last_movement > 3600 && last_movement3 > 0 { + last_movement3 = 0 + ps.Pub( r3events.SomethingReallyIsMoving{false,50,ts}, "movement") + } else if ts - last_movement > 1800 && last_movement2 > 0 { + last_movement2 = 0 + ps.Pub( r3events.SomethingReallyIsMoving{false,20,ts}, "movement") + } else if ts - last_movement > 120 && last_movement1 > 0 { + last_movement1 = 0 + ps.Pub( r3events.SomethingReallyIsMoving{false,5,ts}, "movement") + } } } } } \ No newline at end of file diff --git a/go/r3-eventbroker_zmq/presence.go b/go/r3-eventbroker_zmq/presence.go index 1a6f11c..01087ba 100644 --- a/go/r3-eventbroker_zmq/presence.go +++ b/go/r3-eventbroker_zmq/presence.go @@ -12,7 +12,7 @@ import ( func MetaEventRoutine_Presence(ps *pubsub.PubSub, movement_timeout, button_timeout int64) { //~ var last_door_cmd *r3events.DoorCommandEvent var last_presence bool - var last_movement, last_buttonpress, last_frontlock_use int64 + var last_event_indicating_presence, last_frontlock_use int64 var front_locked, front_shut, back_shut bool = true, true, true events_chan := ps.Sub("door", "doorcmd", "buttons", "movement") @@ -25,27 +25,36 @@ func MetaEventRoutine_Presence(ps *pubsub.PubSub, movement_timeout, button_timeo switch evnt := event.(type) { case r3events.SomethingReallyIsMoving: if evnt.Movement { - last_movement = evnt.Ts + //ignore movements that happened just after locking door + if (evnt.Ts - last_event_indicating_presence) > movement_timeout { + new_presence = true + } + last_event_indicating_presence = evnt.Ts } else { - last_movement = 0 - if last_presence { Syslog_.Print("Presence: Mhh, SomethingReallyIsMoving{false} received but presence still true. Quite still a bunch we have here.") } + if last_presence { Syslog_.Printf("Presence: Mhh, SomethingReallyIsMoving{%+v} received but presence still true. Quite still a bunch we have here.", evnt) } + if front_locked && front_shut && back_shut && evnt.Confidence >= 20 && last_event_indicating_presence > 1800 { + new_presence = false + } } case r3events.BoreDoomButtonPressEvent: - last_buttonpress = evnt.Ts new_presence = true + last_event_indicating_presence = evnt.Ts case r3events.DoorCommandEvent: //~ last_door_cmd = &evnt case r3events.DoorLockUpdate: front_locked = evnt.Locked last_frontlock_use = evnt.Ts + last_event_indicating_presence = evnt.Ts case r3events.DoorAjarUpdate: if front_shut == false && evnt.Shut && front_locked && evnt.Ts - last_frontlock_use > 2 { Syslog_.Print("Presence: ignoring frontdoor ajar event, since obviously someone is fooling around with the microswitch while the door is still open") } else { front_shut = evnt.Shut } + last_event_indicating_presence = evnt.Ts case r3events.BackdoorAjarUpdate: back_shut = evnt.Shut + last_event_indicating_presence = evnt.Ts } any_door_unlocked := (front_locked == false) @@ -55,8 +64,6 @@ func MetaEventRoutine_Presence(ps *pubsub.PubSub, movement_timeout, button_timeo //... skip state check .. we had a definite presence event } else if any_door_unlocked || any_door_ajar { new_presence = true - } else if ts - last_movement < movement_timeout || ts - last_buttonpress < button_timeout { - new_presence = true } else { new_presence = false } -- 1.7.10.4