]> www.average.org Git - loctrkd.git/blobdiff - gps303/termconfig.py
Rename gps303proto to zx303proto
[loctrkd.git] / gps303 / termconfig.py
index eb3150b49a17065aed2fc1d8898bc80ffa4e28b7..4599dc2ed181c1d4a8d463135c295a56a60f53be 100644 (file)
@@ -7,22 +7,21 @@ from struct import pack
 import zmq
 
 from . import common
-from .gps303proto import *
+from .zx303proto import *
 from .zmsg import Bcast, Resp, topic
 
 log = getLogger("gps303/termconfig")
 
 
 def runserver(conf: ConfigParser) -> None:
-    termconfig = common.normconf(conf["termconfig"])
     # Is this https://github.com/zeromq/pyzmq/issues/1627 still not fixed?!
     zctx = zmq.Context()  # type: ignore
     zsub = zctx.socket(zmq.SUB)  # type: ignore
     zsub.connect(conf.get("collector", "publishurl"))
     for proto in (
-        STATUS.PROTO,
-        SETUP.PROTO,
-        POSITION_UPLOAD_INTERVAL.PROTO,
+        proto_name(STATUS),
+        proto_name(SETUP),
+        proto_name(POSITION_UPLOAD_INTERVAL),
     ):
         zsub.setsockopt(zmq.SUBSCRIBE, topic(proto))
     zpush = zctx.socket(zmq.PUSH)  # type: ignore
@@ -43,6 +42,12 @@ def runserver(conf: ConfigParser) -> None:
                 log.error(
                     "%s does not expect externally provided response", msg
                 )
+            if zmsg.imei is not None and conf.has_section(zmsg.imei):
+                termconfig = common.normconf(conf[zmsg.imei])
+            elif conf.has_section("termconfig"):
+                termconfig = common.normconf(conf["termconfig"])
+            else:
+                termconfig = {}
             kwargs = {}
             if isinstance(msg, STATUS):
                 kwargs = {
@@ -71,7 +76,9 @@ def runserver(conf: ConfigParser) -> None:
             zpush.send(resp.packed)
 
     except KeyboardInterrupt:
-        pass
+        zsub.close()
+        zpush.close()
+        zctx.destroy()  # type: ignore
 
 
 if __name__.endswith("__main__"):