Ts int64
}
+type DoorProblemEvent struct {
+ Severity int
+ Ts int64
+}
+
type BoreDoomButtonPressEvent struct {
Ts int64
}
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
}
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:
//~ 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)
+ }
}
}
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)
}