]> www.average.org Git - loctrkd.git/blobdiff - gps303/termconfig.py
fix zmq subscription topics
[loctrkd.git] / gps303 / termconfig.py
index 4bf148bb9a6a76378947d8f70efd7b63d22d6ae8..b9517f0af80284be60df5a4c4a6ef87bbaa9f9e9 100644 (file)
@@ -7,7 +7,7 @@ import zmq
 
 from . import common
 from .gps303proto import *
-from .zmsg import Bcast, Resp
+from .zmsg import Bcast, Resp, topic
 
 log = getLogger("gps303/termconfig")
 
@@ -17,17 +17,12 @@ def runserver(conf):
     zctx = zmq.Context()
     zsub = zctx.socket(zmq.SUB)
     zsub.connect(conf.get("collector", "publishurl"))
-    for protoname in (
-        "SUPERVISION",
-        "STATUS",
-        "RESET",
-        "WHITELIST_TOTAL",
-        "PROHIBIT_LBS",
-        "SETUP",
-        "POSITION_UPLOAD_INTERVAL",
+    for proto in (
+        STATUS.PROTO,
+        SETUP.PROTO,
+        POSITION_UPLOAD_INTERVAL.PROTO,
     ):
-        topic = pack("B", proto_by_name(protoname))
-        zsub.setsockopt(zmq.SUBSCRIBE, topic)
+        zsub.setsockopt(zmq.SUBSCRIBE, topic(proto))
     zpush = zctx.socket(zmq.PUSH)
     zpush.connect(conf.get("collector", "listenurl"))
 
@@ -42,10 +37,14 @@ def runserver(conf):
                 datetime.fromtimestamp(zmsg.when).astimezone(tz=timezone.utc),
                 msg,
             )
+            if msg.RESPOND is not Respond.EXT:
+                log.error(
+                    "%s does not expect externally provided response", msg
+                )
             kwargs = {}
             if isinstance(msg, STATUS):
                 kwargs = {
-                    "upload_interval": termconf.get(
+                    "upload_interval": termconfig.get(
                         "statusintervalminutes", 25
                     )
                 }
@@ -63,7 +62,9 @@ def runserver(conf):
                 ):
                     if key in termconfig:
                         kwargs[key] = termconfig[key]
-            resp = Resp(imei=zmsg.imei, packet=msg.response(**kwargs))
+            resp = Resp(
+                imei=zmsg.imei, when=zmsg.when, packet=msg.Out(**kwargs).packed
+            )
             log.debug("Response: %s", resp)
             zpush.send(resp.packed)