X-Git-Url: http://www.average.org/gitweb/?a=blobdiff_plain;f=gps303%2Ftermconfig.py;h=eb3150b49a17065aed2fc1d8898bc80ffa4e28b7;hb=380ccd781fef5b1ee98e9660c748c8955d3bf40e;hp=1ab65ce937004f8bfeb5c2c99feef2934b190d76;hpb=602261422a9c34a1ac5ecde75ad87dde7fea6d8c;p=loctrkd.git diff --git a/gps303/termconfig.py b/gps303/termconfig.py index 1ab65ce..eb3150b 100644 --- a/gps303/termconfig.py +++ b/gps303/termconfig.py @@ -1,5 +1,6 @@ """ For when responding to the terminal is not trivial """ +from configparser import ConfigParser from datetime import datetime, timezone from logging import getLogger from struct import pack @@ -7,28 +8,24 @@ import zmq from . import common from .gps303proto import * -from .zmsg import Bcast, Resp +from .zmsg import Bcast, Resp, topic log = getLogger("gps303/termconfig") -def runserver(conf): +def runserver(conf: ConfigParser) -> None: termconfig = common.normconf(conf["termconfig"]) - zctx = zmq.Context() - zsub = zctx.socket(zmq.SUB) + # 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 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) - zpush = zctx.socket(zmq.PUSH) + zsub.setsockopt(zmq.SUBSCRIBE, topic(proto)) + zpush = zctx.socket(zmq.PUSH) # type: ignore zpush.connect(conf.get("collector", "listenurl")) try: @@ -42,6 +39,10 @@ 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 = { @@ -63,7 +64,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)