firmware messages are a pain to parse
authorBernhard Tittelbach <xro@realraum.at>
Thu, 3 Oct 2013 22:18:31 +0000 (22:18 +0000)
committerBernhard Tittelbach <xro@realraum.at>
Thu, 3 Oct 2013 22:18:31 +0000 (22:18 +0000)
go/r3-eventbroker_zmq/sockettoevent.go

index 34454cc..2445c78 100644 (file)
@@ -16,7 +16,7 @@ import (
 var (
        re_presence_    *regexp.Regexp     = regexp.MustCompile("Presence: (yes|no)(?:, (opened|closed), (.+))?")
        re_state_      *regexp.Regexp     = regexp.MustCompile("State: (closed|opened|manual movement|error|reset|timeout after open|timeout after close|opening|closing).*")
-       re_status_      *regexp.Regexp     = regexp.MustCompile("Status: (closed|opened) (closed|opened|manual movement|error|reset|timeout after open|timeout after close|opening|closing) (ajar|shut).*")
+       re_status_      *regexp.Regexp     = regexp.MustCompile("Status: (closed|opened), (closed|opened|manual movement|error|reset|timeout after open|timeout after close|opening|closing), (ajar|shut).*")
        re_infocard_      *regexp.Regexp     = regexp.MustCompile("Info\\(card\\): card\\(([a-fA-F0-9]+)\\) (found|not found).*")
        re_cardid_      *regexp.Regexp     = regexp.MustCompile("card\\(([a-fA-F0-9]+)\\)")
        re_infoajar_      *regexp.Regexp     = regexp.MustCompile("Info\\(ajar\\): door is now (ajar|shut)")
@@ -29,24 +29,24 @@ var (
 
 func parseSocketInputLine_State(lines [][]byte, ps *pubsub.PubSub, ts int64) {
     switch string(lines[0]) {
-        case "closed":
+        case "closed,":
             ps.Pub(r3events.DoorLockUpdate{0, true, ts}, "door")
-        case "opened":
+        case "opened,":
             ps.Pub(r3events.DoorLockUpdate{0, false, ts}, "door")
         case "manual":   //movement
-        case "error":
-        case "reset":
+        case "error,":
+        case "reset,":
             ps.Pub(r3events.DoorLockUpdate{0, true, ts}, "door")
         case "timeout":   //after open | after close
-        case "opening":
-        case "closing":
+        case "opening,":
+        case "closing,":
         default:
+            log.Print("parseSocketInputLine_State: Unexpected State:", lines)
     }
 }
 
 
 func ParseSocketInputLine(lines [][]byte, ps *pubsub.PubSub, keylookup_socket *zmq.Socket) { //, brn *brain.Brain) {
-    var tidbit interface{}
     ts := time.Now().Unix()
     if len(lines) < 1 { return }
     log.Printf("ParseSocketInputLine: %s %s",string(lines[0]), lines[1:])
@@ -56,12 +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 }
-            tidbit = r3events.DoorLockUpdate{0, string(lines[1]) == "closed", ts}
-            //~ brn.Oboite("door", tidbit)
-            ps.Pub(tidbit, "door")
-            tidbit = r3events.DoorAjarUpdate{0, string(lines[len(lines)-2]) == "shut", ts}
-            //~ brn.Oboite("door", tidbit)
-            ps.Pub(tidbit, "door")
+            ps.Pub(r3events.DoorLockUpdate{0, string(lines[1]) == "closed,", ts}, "door")
+            ps.Pub(r3events.DoorAjarUpdate{0, string(lines[len(lines)-1]) == "shut", ts}, "door")
         case "Info(card):":
             if len(lines) < 3 { return }
             if string(lines[2]) != "found" { return }
@@ -78,9 +74,7 @@ func ParseSocketInputLine(lines [][]byte, ps *pubsub.PubSub, keylookup_socket *z
             }
         case "Info(ajar):":
             if len(lines) < 5 { return }
-            tidbit = r3events.DoorAjarUpdate{0, string(lines[4]) == "shut", ts}
-            //~ brn.Oboite("door", tidbit)
-            ps.Pub(tidbit, "door")
+            ps.Pub(r3events.DoorAjarUpdate{0, 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":