]> www.average.org Git - loctrkd.git/blobdiff - gps303/termconfig.py
Use config from the config file to config
[loctrkd.git] / gps303 / termconfig.py
index 10c6286d544a76722a707a0cd0cdc73ad3e884ea..4bf148bb9a6a76378947d8f70efd7b63d22d6ae8 100644 (file)
@@ -6,13 +6,14 @@ from struct import pack
 import zmq
 
 from . import common
-from .gps303proto import parse_message, proto_by_name
+from .gps303proto import *
 from .zmsg import Bcast, Resp
 
 log = getLogger("gps303/termconfig")
 
 
 def runserver(conf):
+    termconfig = common.normconf(conf["termconfig"])
     zctx = zmq.Context()
     zsub = zctx.socket(zmq.SUB)
     zsub.connect(conf.get("collector", "publishurl"))
@@ -41,8 +42,28 @@ def runserver(conf):
                 datetime.fromtimestamp(zmsg.when).astimezone(tz=timezone.utc),
                 msg,
             )
-            # TODO get data from the config
-            resp = Resp(imei=zmsg.imei, packet=msg.response())
+            kwargs = {}
+            if isinstance(msg, STATUS):
+                kwargs = {
+                    "upload_interval": termconf.get(
+                        "statusintervalminutes", 25
+                    )
+                }
+            elif isinstance(msg, SETUP):
+                for key in (
+                    "uploadintervalseconds",
+                    "binaryswitch",
+                    "alarms",
+                    "dndtimeswitch",
+                    "dndtimes",
+                    "gpstimeswitch",
+                    "gpstimestart",
+                    "gpstimestop",
+                    "phonenumbers",
+                ):
+                    if key in termconfig:
+                        kwargs[key] = termconfig[key]
+            resp = Resp(imei=zmsg.imei, packet=msg.response(**kwargs))
             log.debug("Response: %s", resp)
             zpush.send(resp.packed)