--bug, movement, identation
[svn42.git] / r3-netstatus / sockettoevent.go
index 7f0d20c..405dbbf 100644 (file)
@@ -13,7 +13,7 @@ import (
 var (
        re_presence_    *regexp.Regexp     = regexp.MustCompile("Presence: (yes|no)(?:, (opened|closed), (.+))?")
        re_status_      *regexp.Regexp     = regexp.MustCompile("Status: (closed|opened), (opening|waiting|closing|idle), (ajar|shut).*")
-       re_command_      *regexp.Regexp     = regexp.MustCompile("(open|close|toggle) (Card |Phone )?([^ ]+) *")
+       re_command_     *regexp.Regexp     = regexp.MustCompile("(open|close|toggle) (?:(Card|Phone) )?(.+)")
        re_button_      *regexp.Regexp     = regexp.MustCompile("PanicButton|button\\d?")
        re_temp_        *regexp.Regexp     = regexp.MustCompile("temp0: (\\d+\\.\\d+)")
        re_photo_       *regexp.Regexp     = regexp.MustCompile("photo0: (\\d+)")
@@ -59,18 +59,23 @@ type TimeTick struct {
     Ts int64
 }
 
+type MovementSensorUpdate struct {
+    Sensorindex int
+    Ts int64
+}
 
 func ParseSocketInputLine(line string, ps *pubsub.PubSub) { //, brn *brain.Brain) {
-       match_presence := re_presence_.FindStringSubmatch(line)
-       match_status := re_status_.FindStringSubmatch(line)
-       match_command := re_command_.FindStringSubmatch(line)
-       match_button := re_button_.FindStringSubmatch(line)
-       match_temp := re_temp_.FindStringSubmatch(line)
-       match_photo := re_photo_.FindStringSubmatch(line)
+    match_presence := re_presence_.FindStringSubmatch(line)
+    match_status := re_status_.FindStringSubmatch(line)
+    match_command := re_command_.FindStringSubmatch(line)
+    match_button := re_button_.FindStringSubmatch(line)
+    match_temp := re_temp_.FindStringSubmatch(line)
+    match_photo := re_photo_.FindStringSubmatch(line)
 
+    //~ log.Println("ParseSocketInputLine",line)
     var tidbit interface{}
     ts := time.Now().Unix()
-       if match_presence != nil {
+    if match_presence != nil {
         tidbit = PresenceUpdate{match_presence[1] == "yes", ts}
         //~ brn.Oboite("presence", tidbit)
         ps.Pub(tidbit, "presence")
@@ -79,7 +84,7 @@ func ParseSocketInputLine(line string, ps *pubsub.PubSub) { //, brn *brain.Brain
         //~ brn.Oboite("door", tidbit)
         ps.Pub(tidbit, "door")
        } else if match_command != nil {
-        tidbit = DoorCommandEvent{match_status[1], match_status[2], match_status[3], ts}
+        tidbit = DoorCommandEvent{match_command[1], match_command[2], match_command[3], ts}
         //~ brn.Oboite("doorcmd", tidbit)
         ps.Pub(tidbit, "door")
        } else if match_button != nil {
@@ -97,6 +102,9 @@ func ParseSocketInputLine(line string, ps *pubsub.PubSub) { //, brn *brain.Brain
             //~ brn.Oboite("photo0", newphoto)
             ps.Pub(IlluminationSensorUpdate{0, newphoto, ts}, "sensors")
                }
+       } else if line == "movement" {
+        //~ brn.Oboite("movement", ts)
+        ps.Pub(MovementSensorUpdate{0, ts}, "movements")
        }
 }