import (
"regexp"
- //~ "strconv"
+ "strconv"
"time"
//~ "./brain"
pubsub "github.com/tuxychandru/pubsub"
zmq "github.com/vaughan0/go-zmq"
- "./r3events"
+ r3events "svn.spreadspace.org/realraum/go.svn/r3events"
)
var (
ps.Pub(r3events.DoorLockUpdate{true, ts}, "door")
case "opened":
ps.Pub(r3events.DoorLockUpdate{false, ts}, "door")
- case "manual": //movement
+ case "manual", "manual_movement": //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
+ case "timeout", "timeout_after_open", "timeout_after_close":
+ ps.Pub(r3events.DoorProblemEvent{10, ts}, "door")
case "opening":
case "closing":
default:
parseSocketInputLine_State(lines[1:], ps, ts)
case "Status:":
if len(lines) < 3 { return }
- ps.Pub(r3events.DoorLockUpdate{string(lines[1]) == "closed,", ts}, "door")
+ if len(lines[1]) < 4 { return }
+ ps.Pub(r3events.DoorLockUpdate{string(lines[1])[0:4] != "open", ts}, "door")
ps.Pub(r3events.DoorAjarUpdate{string(lines[len(lines)-1]) == "shut", ts}, "door")
case "Info(card):":
if len(lines) < 3 { return }
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:":
- //~ newphoto, err := strconv.ParseInt(string(lines[1]), 10, 32)
- //~ 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")}
+ case "BackdoorInfo(ajar):":
+ ps.Pub(r3events.BackdoorAjarUpdate{string(lines[len(lines)-1]) == "shut", ts},"door")
+ case "temp0:","temp1:", "temp2:", "temp3:":
+ sensorid, err := strconv.ParseInt(string(lines[0][4]), 10, 32)
+ if err != nil {return }
+ newtemp, err := strconv.ParseFloat(string(lines[1]), 10)
+ if err != nil {return }
+ ps.Pub(r3events.TempSensorUpdate{int(sensorid), newtemp, ts}, "sensors")
+ case "photo0:","photo1:", "photo2:", "photo3:":
+ sensorid, err := strconv.ParseInt(string(lines[0][5]), 10, 32)
+ if err != nil {return }
+ newphoto, err := strconv.ParseInt(string(lines[1]), 10, 32)
+ if err != nil {return }
+ ps.Pub(r3events.IlluminationSensorUpdate{int(sensorid), newphoto, ts}, "sensors")
+ case "rh0:":
+ //~ sensorid, err := strconv.ParseInt(string(lines[0][4]), 10, 32)
+ //~ if err != nil {return }
+ relhumid, err := strconv.ParseInt(string(lines[1]), 10, 32)
+ if err != nil {return }
+ ps.Pub(r3events.RelativeHumiditySensorUpdate{0, int(relhumid), ts}, "sensors")
+ case "dust0:","dust1:","dust2:":
+ sensorid, err := strconv.ParseInt(string(lines[0][4]), 10, 32)
+ if err != nil {return }
+ dustlvl, err := strconv.ParseInt(string(lines[1]), 10, 32)
+ if err != nil {return }
+ ps.Pub(r3events.DustSensorUpdate{int(sensorid), dustlvl, ts}, "sensors")
+ default:
+ evnt, pubsubcat, err := r3events.UnmarshalByteByte2Event(lines)
+ if err == nil {
+ ps.Pub(evnt, pubsubcat)
+ }
}
}