From: Bernhard Tittelbach Date: Sat, 5 Oct 2013 00:35:19 +0000 (+0000) Subject: DoorProblemEvent and unmarshall and global pubsub categories X-Git-Url: https://git.realraum.at/?a=commitdiff_plain;h=281827cdf431aec452bd1dc942a24c766a38efcb;p=svn42.git DoorProblemEvent and unmarshall and global pubsub categories --- diff --git a/go/r3-eventbroker_zmq/r3events/basicevents.go b/go/r3-eventbroker_zmq/r3events/basicevents.go index e1dacc6..73776cb 100644 --- a/go/r3-eventbroker_zmq/r3events/basicevents.go +++ b/go/r3-eventbroker_zmq/r3events/basicevents.go @@ -25,6 +25,11 @@ type DoorCommandEvent struct { Ts int64 } +type DoorProblemEvent struct { + Severity int + Ts int64 +} + 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 66799c7..830ff6b 100644 --- a/go/r3-eventbroker_zmq/r3events/marshal_events.go +++ b/go/r3-eventbroker_zmq/r3events/marshal_events.go @@ -26,47 +26,63 @@ func MarshalEvent2ByteByte(event_interface interface{}) (data [][]byte, err erro return } -func UnmarshalByteByte2Event(data [][]byte) (event interface{}, err error) { +func UnmarshalByteByte2Event(data [][]byte) (event interface{}, category string, err error) { if len(data) != 2 { - return nil, errors.New("not a r3event message") + return nil, "", errors.New("not a r3event message") } switch string(data[0]) { case "DoorLockUpdate": - event = new(DoorLockUpdate) - err = json.Unmarshal(data[1],event) + event = DoorLockUpdate{} + err = json.Unmarshal(data[1],&event) + category = "door" case "DoorAjarUpdate": - event := new(DoorAjarUpdate) - err = json.Unmarshal(data[1], event) + event := DoorAjarUpdate{} + err = json.Unmarshal(data[1], &event) + category = "door" case "BackdoorAjarUpdate": - event := new(DoorAjarUpdate) - err = json.Unmarshal(data[1], event) + event := DoorAjarUpdate{} + err = json.Unmarshal(data[1], &event) + category = "door" case "DoorCommandEvent": - event := new(DoorCommandEvent) - err = json.Unmarshal(data[1], event) + event := DoorCommandEvent{} + err = json.Unmarshal(data[1], &event) + category = "door" + case "DoorProblemEvent": + event := DoorProblemEvent{} + err = json.Unmarshal(data[1], &event) + category = "door" case "BoreDoomButtonPressEvent": - event := new(BoreDoomButtonPressEvent) - err = json.Unmarshal(data[1], event) + event := BoreDoomButtonPressEvent{} + err = json.Unmarshal(data[1], &event) + category = "buttons" case "TempSensorUpdate": - event := new(TempSensorUpdate) - err = json.Unmarshal(data[1], event) + event := TempSensorUpdate{} + err = json.Unmarshal(data[1], &event) + category = "sensors" case "IlluminationSensorUpdate": - event := new(IlluminationSensorUpdate) - err = json.Unmarshal(data[1], event) + event := IlluminationSensorUpdate{} + err = json.Unmarshal(data[1], &event) + category = "sensors" case "TimeTick": - event := new(TimeTick) - err = json.Unmarshal(data[1], event) + event := TimeTick{} + err = json.Unmarshal(data[1], &event) + category = "time" case "MovementSensorUpdate": - event := new(MovementSensorUpdate) - err = json.Unmarshal(data[1], event) + event := MovementSensorUpdate{} + err = json.Unmarshal(data[1], &event) + category = "movement" case "PresenceUpdate": - event := new(PresenceUpdate) - err = json.Unmarshal(data[1], event) + event := PresenceUpdate{} + err = json.Unmarshal(data[1], &event) + category = "presence" case "SomethingReallyIsMoving": - event := new(SomethingReallyIsMoving) - err = json.Unmarshal(data[1], event) + event := SomethingReallyIsMoving{} + err = json.Unmarshal(data[1], &event) + category = "movement" default: event = nil err = errors.New("cannot unmarshal unknown type") + category = "" } return } diff --git a/go/r3-eventbroker_zmq/sockettoevent.go b/go/r3-eventbroker_zmq/sockettoevent.go index 2ebcc76..5287683 100644 --- a/go/r3-eventbroker_zmq/sockettoevent.go +++ b/go/r3-eventbroker_zmq/sockettoevent.go @@ -34,9 +34,11 @@ func parseSocketInputLine_State(lines [][]byte, ps *pubsub.PubSub, ts int64) { ps.Pub(r3events.DoorLockUpdate{false, ts}, "door") case "manual": //movement case "error": + ps.Pub(r3events.DoorProblemEvent{100, ts}, "door") case "reset": ps.Pub(r3events.DoorLockUpdate{true, ts}, "door") case "timeout": //after open | after close + ps.Pub(r3events.DoorProblemEvent{10, ts}, "door") case "opening": case "closing": default: @@ -81,18 +83,11 @@ func ParseSocketInputLine(lines [][]byte, ps *pubsub.PubSub, keylookup_socket *z //~ if err == nil { //~ ps.Pub(r3events.IlluminationSensorUpdate{0, newphoto, ts}, "sensors") //~ } - case "IlluminationSensorUpdate","TempSensorUpdate": - //try decode r3event - evnt, err := r3events.UnmarshalByteByte2Event(lines) - if err == nil {ps.Pub(evnt, "sensors")} - case "MovementSensorUpdate" : - //try decode r3event - evnt, err := r3events.UnmarshalByteByte2Event(lines) - if err == nil {ps.Pub(evnt, "movement")} - case "BoreDoomButtonPressEvent" : - //try decode r3event - evnt, err := r3events.UnmarshalByteByte2Event(lines) - if err == nil {ps.Pub(evnt, "buttons")} + default: + evnt, pubsubcat, err := r3events.UnmarshalByteByte2Event(lines) + if err == nil { + ps.Pub(evnt, pubsubcat) + } } } diff --git a/go/r3-netstatus/sockettoevent.go b/go/r3-netstatus/sockettoevent.go index 463838c..7165ac6 100644 --- a/go/r3-netstatus/sockettoevent.go +++ b/go/r3-netstatus/sockettoevent.go @@ -4,51 +4,11 @@ package main import ( pubsub "github.com/tuxychandru/pubsub" - //~ "bufio" - //~ "time" - //~ "./brain" - //~ "net" - "encoding/json" r3events "svn.spreadspace.org/realraum/go.svn/r3-eventbroker_zmq/r3events" ) -func ParseZMQr3Event(lines [][]byte, ps *pubsub.PubSub) { //, brn *brain.Brain) { - //Debug_.Printf("ParseZMQr3Event: len: %d lines: %s", len(lines), lines) - if len(lines) != 2 { - return - } - switch string(lines[0]) { - case "PresenceUpdate": - evnt := new(r3events.PresenceUpdate) - err := json.Unmarshal(lines[1],evnt) - if err == nil {ps.Pub(*evnt, "presence")} - case "IlluminationSensorUpdate" : - evnt := new(r3events.IlluminationSensorUpdate) - err := json.Unmarshal(lines[1],evnt) - if err == nil {ps.Pub(*evnt, "sensors")} - case "TempSensorUpdate" : - evnt := new(r3events.TempSensorUpdate) - err := json.Unmarshal(lines[1],evnt) - if err == nil {ps.Pub(*evnt, "sensors")} - case "MovementSensorUpdate" : - evnt := new(r3events.MovementSensorUpdate) - err := json.Unmarshal(lines[1],evnt) - if err == nil {ps.Pub(*evnt, "movement")} - case "BoreDoomButtonPressEvent" : - evnt := new(r3events.BoreDoomButtonPressEvent) - err := json.Unmarshal(lines[1],evnt) - if err == nil {ps.Pub(*evnt, "buttons")} - case "DoorLockUpdate" : - evnt := new(r3events.DoorLockUpdate) - err := json.Unmarshal(lines[1],evnt) - if err == nil {ps.Pub(*evnt, "door")} - case "DoorAjarUpdate" : - evnt := new(r3events.DoorAjarUpdate) - err := json.Unmarshal(lines[1],evnt) - if err == nil {ps.Pub(*evnt, "door")} - case "DoorCommandEvent" : - evnt := new(r3events.DoorCommandEvent) - err := json.Unmarshal(lines[1],evnt) - if err == nil {ps.Pub(*evnt, "door")} - } +func ParseZMQr3Event(lines [][]byte, ps *pubsub.PubSub) { + evnt, pubsubcat, err := r3events.UnmarshalByteByte2Event(lines) + if err != nil { return } + ps.Pub(evnt, pubsubcat) }