From: Bernhard Tittelbach Date: Fri, 4 Oct 2013 17:22:16 +0000 (+0000) Subject: rename PanicButton to BoreDooomButton and eliminate door id X-Git-Url: https://git.realraum.at/?a=commitdiff_plain;h=a8e0651d52192d208758ae9a59e21af313685da4;p=svn42.git rename PanicButton to BoreDooomButton and eliminate door id --- diff --git a/go/r3-eventbroker_zmq/presence.go b/go/r3-eventbroker_zmq/presence.go index be7b12f..c8553e2 100644 --- a/go/r3-eventbroker_zmq/presence.go +++ b/go/r3-eventbroker_zmq/presence.go @@ -10,16 +10,11 @@ import ( //~ "log" ) -type doorstate struct { - locked bool - shut bool -} - func MetaEventRoutine_Presence(ps *pubsub.PubSub) { //~ var last_door_cmd *DoorCommandEvent var last_presence bool var last_movement, last_buttonpress int64 - doorstatemap := make(map[int]doorstate,1) + var front_locked, front_shut, back_shut bool = true, true, true events_chan := ps.Sub("door", "doorcmd", "buttons", "movement") defer ps.Unsub(events_chan, "door", "doorcmd", "buttons", "movement") @@ -35,23 +30,21 @@ func MetaEventRoutine_Presence(ps *pubsub.PubSub) { } else { last_movement = 0 } - case r3events.ButtonPressUpdate: + case r3events.BoreDoomButtonPressEvent: last_buttonpress = evnt.Ts new_presence = true //~ case DoorCommandEvent: //~ last_door_cmd = &evnt case r3events.DoorLockUpdate: - doorstatemap[evnt.DoorID]=doorstate{locked:evnt.Locked, shut:doorstatemap[evnt.DoorID].shut} + front_locked = evnt.Locked case r3events.DoorAjarUpdate: - doorstatemap[evnt.DoorID]=doorstate{locked:doorstatemap[evnt.DoorID].locked, shut:evnt.Shut} + front_shut = evnt.Shut + case r3events.BackdoorAjarUpdate: + back_shut = evnt.Shut } - any_door_unlocked := false - any_door_ajar := false - for _, ds := range(doorstatemap) { - if ds.locked == false {any_door_unlocked = true } - if ds.shut == false {any_door_ajar = true } - } + any_door_unlocked := ! front_locked + any_door_ajar := ! (front_shut && back_shut) if new_presence != last_presence { //... skip state check .. we had a definite presence event diff --git a/go/r3-eventbroker_zmq/r3events/basicevents.go b/go/r3-eventbroker_zmq/r3events/basicevents.go index e5fa2dc..e1dacc6 100644 --- a/go/r3-eventbroker_zmq/r3events/basicevents.go +++ b/go/r3-eventbroker_zmq/r3events/basicevents.go @@ -4,13 +4,16 @@ package r3events type DoorLockUpdate struct { - DoorID int Locked bool Ts int64 } type DoorAjarUpdate struct { - DoorID int + Shut bool + Ts int64 +} + +type BackdoorAjarUpdate struct { Shut bool Ts int64 } @@ -22,8 +25,7 @@ type DoorCommandEvent struct { Ts int64 } -type ButtonPressUpdate struct { - Buttonindex int +type BoreDoomButtonPressEvent struct { Ts int64 } diff --git a/go/r3-eventbroker_zmq/r3events/marshal_events.go b/go/r3-eventbroker_zmq/r3events/marshal_events.go index dd23d53..66799c7 100644 --- a/go/r3-eventbroker_zmq/r3events/marshal_events.go +++ b/go/r3-eventbroker_zmq/r3events/marshal_events.go @@ -37,11 +37,14 @@ func UnmarshalByteByte2Event(data [][]byte) (event interface{}, err error) { case "DoorAjarUpdate": event := new(DoorAjarUpdate) err = json.Unmarshal(data[1], event) + case "BackdoorAjarUpdate": + event := new(DoorAjarUpdate) + err = json.Unmarshal(data[1], event) case "DoorCommandEvent": event := new(DoorCommandEvent) err = json.Unmarshal(data[1], event) - case "ButtonPressUpdate": - event := new(ButtonPressUpdate) + case "BoreDoomButtonPressEvent": + event := new(BoreDoomButtonPressEvent) err = json.Unmarshal(data[1], event) case "TempSensorUpdate": event := new(TempSensorUpdate) diff --git a/go/r3-eventbroker_zmq/sockettoevent.go b/go/r3-eventbroker_zmq/sockettoevent.go index 6c245b4..6511ff0 100644 --- a/go/r3-eventbroker_zmq/sockettoevent.go +++ b/go/r3-eventbroker_zmq/sockettoevent.go @@ -30,13 +30,13 @@ var ( func parseSocketInputLine_State(lines [][]byte, ps *pubsub.PubSub, ts int64) { switch string(lines[0]) { case "closed": - ps.Pub(r3events.DoorLockUpdate{0, true, ts}, "door") + ps.Pub(r3events.DoorLockUpdate{true, ts}, "door") case "opened": - ps.Pub(r3events.DoorLockUpdate{0, false, ts}, "door") + ps.Pub(r3events.DoorLockUpdate{false, ts}, "door") case "manual": //movement case "error": case "reset": - ps.Pub(r3events.DoorLockUpdate{0, true, ts}, "door") + ps.Pub(r3events.DoorLockUpdate{true, ts}, "door") case "timeout": //after open | after close case "opening": case "closing": @@ -56,8 +56,8 @@ func ParseSocketInputLine(lines [][]byte, ps *pubsub.PubSub, keylookup_socket *z parseSocketInputLine_State(lines[1:], ps, ts) case "Status:": if len(lines) < 3 { return } - ps.Pub(r3events.DoorLockUpdate{0, string(lines[1]) == "closed,", ts}, "door") - ps.Pub(r3events.DoorAjarUpdate{0, string(lines[len(lines)-1]) == "shut", ts}, "door") + ps.Pub(r3events.DoorLockUpdate{string(lines[1]) == "closed,", ts}, "door") + ps.Pub(r3events.DoorAjarUpdate{string(lines[len(lines)-1]) == "shut", ts}, "door") case "Info(card):": if len(lines) < 3 { return } if string(lines[2]) != "found" { return } @@ -74,7 +74,7 @@ func ParseSocketInputLine(lines [][]byte, ps *pubsub.PubSub, keylookup_socket *z } case "Info(ajar):": if len(lines) < 5 { return } - ps.Pub(r3events.DoorAjarUpdate{0, string(lines[4]) == "shut", ts}, "door") + ps.Pub(r3events.DoorAjarUpdate{string(lines[4]) == "shut", ts}, "door") case "open", "close", "toggle", "reset": ps.Pub(r3events.DoorCommandEvent{string(lines[0]), string(lines[1]), string(lines[2]), ts},"doorcmd") case "photo0": @@ -91,7 +91,7 @@ func ParseSocketInputLine(lines [][]byte, ps *pubsub.PubSub, keylookup_socket *z //try decode r3event evnt, err := r3events.UnmarshalByteByte2Event(lines) if err == nil {ps.Pub(evnt, "movement")} - case "ButtonPressUpdate" : + case "BoreDoomButtonPressEvent" : //try decode r3event evnt, err := r3events.UnmarshalByteByte2Event(lines) if err == nil {ps.Pub(evnt, "buttons")} @@ -110,7 +110,7 @@ func MakeTimeTick(ps *pubsub.PubSub) { //~ match_photo := re_photo_.FindStringSubmatch(line) //~ if match_button != nil { //~ // brn.Oboite("button0", ts) - //~ ps.Pub(ButtonPressUpdate{0, ts}, "buttons") + //~ ps.Pub(BoreDoomButtonPressEvent{0, ts}, "buttons") //~ } else if match_temp != nil { //~ newtemp, err := strconv.ParseFloat((match_temp[1]), 32) //~ if err == nil { diff --git a/go/r3-netstatus/main.go b/go/r3-netstatus/main.go index f387789..a2917a5 100644 --- a/go/r3-netstatus/main.go +++ b/go/r3-netstatus/main.go @@ -70,7 +70,7 @@ func EventToXMPP(ps *pubsub.PubSub, xmpp_presence_events_chan_ chan <- interface var present, locked, shut bool = false, true, true var last_buttonpress int64 = 0 var who string - button_msg := "The button has been pressed ! Propably someone is bored and in need of company ! ;-)" + button_msg := "Dooom ! The button has been pressed ! Propably someone is bored and in need of company ! ;-)" present_status := r3xmppbot.XMPPStatusEvent{r3xmppbot.ShowOnline,"Somebody is present"} notpresent_status := r3xmppbot.XMPPStatusEvent{r3xmppbot.ShowNotAvailabe,"Nobody is here"} button_status := r3xmppbot.XMPPStatusEvent{r3xmppbot.ShowFreeForChat, "The button has been pressed :-)"} @@ -101,7 +101,7 @@ func EventToXMPP(ps *pubsub.PubSub, xmpp_presence_events_chan_ chan <- interface case r3events.DoorAjarUpdate: shut = event.Shut xmpp_presence_events_chan_ <- r3xmppbot.XMPPMsgEvent{Msg: composeMessage(present, locked, shut, who, event.Ts), DistributeLevel: r3xmppbot.R3DebugInfo, RememberAsStatus: true} - case r3events.ButtonPressUpdate: + case r3events.BoreDoomButtonPressEvent: xmpp_presence_events_chan_ <- r3xmppbot.XMPPMsgEvent{Msg: button_msg, DistributeLevel: r3xmppbot.R3OnlineOnlyInfo} xmpp_presence_events_chan_ <- button_status last_buttonpress = event.Ts diff --git a/go/r3-netstatus/sockettoevent.go b/go/r3-netstatus/sockettoevent.go index 8782177..d3ffd22 100644 --- a/go/r3-netstatus/sockettoevent.go +++ b/go/r3-netstatus/sockettoevent.go @@ -35,8 +35,8 @@ func ParseZMQr3Event(lines [][]byte, ps *pubsub.PubSub) { //, brn *brain.Brain) evnt := new(r3events.MovementSensorUpdate) err := json.Unmarshal(lines[1],evnt) if err == nil {ps.Pub(*evnt, "movement")} - case "ButtonPressUpdate" : - evnt := new(r3events.ButtonPressUpdate) + case "BoreDoomButtonPressEvent" : + evnt := new(r3events.BoreDoomButtonPressEvent) err := json.Unmarshal(lines[1],evnt) if err == nil {ps.Pub(*evnt, "buttons")} case "DoorLockUpdate" : diff --git a/go/r3-netstatus/webstatus.go b/go/r3-netstatus/webstatus.go index 489d770..4ebfbfb 100644 --- a/go/r3-netstatus/webstatus.go +++ b/go/r3-netstatus/webstatus.go @@ -87,9 +87,9 @@ func EventToWeb(ps *pubsub.PubSub) { case r3events.DoorLockUpdate: spaceapidata.MergeInSensor(spaceapi.MakeDoorLockSensor("TorwaechterLock", "Türschloß", event.Locked)) publishStateToWeb() - case r3events.ButtonPressUpdate: + case r3events.BoreDoomButtonPressEvent: statusstate.buttonpress_until = event.Ts + 3600 - spaceapidata.AddSpaceEvent("PanicButton", "check-in", "The button has been pressed") + spaceapidata.AddSpaceEvent("BoreDOOMButton", "check-in", "The button has been pressed") publishStateToWeb() case r3events.TempSensorUpdate: spaceapidata.MergeInSensor(spaceapi.MakeTempCSensor("Temp0","Decke", event.Value))