]> www.average.org Git - loctrkd.git/commitdiff
fix zmq subscription topics
authorEugene Crosser <crosser@average.org>
Mon, 9 May 2022 16:27:21 +0000 (18:27 +0200)
committerEugene Crosser <crosser@average.org>
Mon, 9 May 2022 16:27:21 +0000 (18:27 +0200)
gps303/lookaside.py
gps303/termconfig.py
gps303/wsgateway.py
gps303/zmsg.py

index edc899fc8742c5f525eacab7bc21dd3b97265ce9..136ade9aeccf51e836062e8bfb0e83130c9544a4 100644 (file)
@@ -18,8 +18,7 @@ def runserver(conf):
     zctx = zmq.Context()
     zsub = zctx.socket(zmq.SUB)
     zsub.connect(conf.get("collector", "publishurl"))
-    tosub = topic(WIFI_POSITIONING.PROTO)
-    zsub.setsockopt(zmq.SUBSCRIBE, tosub)
+    zsub.setsockopt(zmq.SUBSCRIBE, topic(WIFI_POSITIONING.PROTO))
     zpush = zctx.socket(zmq.PUSH)
     zpush.connect(conf.get("collector", "listenurl"))
 
index 9f9168409d6ddd21b0abf746d2d21ce5eae251c8..b9517f0af80284be60df5a4c4a6ef87bbaa9f9e9 100644 (file)
@@ -17,13 +17,12 @@ def runserver(conf):
     zctx = zmq.Context()
     zsub = zctx.socket(zmq.SUB)
     zsub.connect(conf.get("collector", "publishurl"))
-    for protoname in (
-        "STATUS",
-        "SETUP",
-        "POSITION_UPLOAD_INTERVAL",
+    for proto in (
+        STATUS.PROTO,
+        SETUP.PROTO,
+        POSITION_UPLOAD_INTERVAL.PROTO,
     ):
-        tosub = topic(proto_by_name(protoname))
-        zsub.setsockopt(zmq.SUBSCRIBE, tosub)
+        zsub.setsockopt(zmq.SUBSCRIBE, topic(proto))
     zpush = zctx.socket(zmq.PUSH)
     zpush.connect(conf.get("collector", "listenurl"))
 
index 80926fbceb53b381d067eb2560d82cbeb2aa9aad..00770ebd88032c35f9b9e7172dba3c63233d7434 100644 (file)
@@ -255,22 +255,23 @@ def runserver(conf):
         while True:
             neededsubs = clients.subs()
             for imei in neededsubs - activesubs:
+                log.debug("topics: %s", [tpc.hex() for tpc in [topic(GPS_POSITIONING.PROTO, True, imei), topic(WIFI_POSITIONING.PROTO, False, imei)]])
                 zsub.setsockopt(
                     zmq.SUBSCRIBE,
-                    topic(GPS_POSITIONING.PROTO, True),
+                    topic(GPS_POSITIONING.PROTO, True, imei),
                 )
                 zsub.setsockopt(
                     zmq.SUBSCRIBE,
-                    topic(WIFI_POSITIONING.PROTO, False),
+                    topic(WIFI_POSITIONING.PROTO, False, imei),
                 )
             for imei in activesubs - neededsubs:
                 zsub.setsockopt(
                     zmq.UNSUBSCRIBE,
-                    topic(GPS_POSITIONING.PROTO, True),
+                    topic(GPS_POSITIONING.PROTO, True, imei),
                 )
                 zsub.setsockopt(
                     zmq.UNSUBSCRIBE,
-                    topic(WIFI_POSITIONING.PROTO, False),
+                    topic(WIFI_POSITIONING.PROTO, False, imei),
                 )
             activesubs = neededsubs
             log.debug("Subscribed to: %s", activesubs)
@@ -283,7 +284,10 @@ def runserver(conf):
                 if sk is zsub:
                     while True:
                         try:
-                            zmsg = Bcast(zsub.recv(zmq.NOBLOCK))
+                            buf = zsub.recv(zmq.NOBLOCK)
+                            zmsg = Bcast(buf)
+                            log.debug("zmq packet: %s", buf.hex())
+                            # zmsg = Bcast(zsub.recv(zmq.NOBLOCK))
                             msg = parse_message(zmsg.packet)
                             tosend.append(zmsg)
                             log.debug("Got %s", zmsg)
index 0457685ab05ab6bf6cade6eb466c9ccce3a48946..1fe18123c441739a9891b1433ec8bc276b5c876a 100644 (file)
@@ -80,8 +80,8 @@ class _Zmsg:
 
 
 def topic(proto, is_incoming=True, imei=None):
-    return (
-        pack("BB", is_incoming, proto) + b"" if imei is None else imei.encode()
+    return pack("BB", is_incoming, proto) + (
+        b"" if imei is None else pack("16s", imei.encode())
     )
 
 
@@ -100,8 +100,14 @@ class Bcast(_Zmsg):
     @property
     def packed(self):
         return (
-            pack("BB", int(self.is_incoming), self.proto)
-            + ("0000000000000000" if self.imei is None else self.imei).encode()
+            pack(
+                "BB16s",
+                int(self.is_incoming),
+                self.proto,
+                "0000000000000000"
+                if self.imei is None
+                else self.imei.encode(),
+            )
             + (
                 b"\0\0\0\0\0\0\0\0"
                 if self.when is None
@@ -130,7 +136,12 @@ class Resp(_Zmsg):
     @property
     def packed(self):
         return (
-            ("0000000000000000" if self.imei is None else self.imei.encode())
+            pack(
+                "16s",
+                "0000000000000000"
+                if self.imei is None
+                else self.imei.encode(),
+            )
             + (
                 b"\0\0\0\0\0\0\0\0"
                 if self.when is None