X-Git-Url: http://average.org/gitweb/?a=blobdiff_plain;f=gps303%2Ftermconfig.py;h=771f988f038dc6785d7d34a5ff1b1164db476beb;hb=5fb0153ac3c0d8b0986575aa23f6f33a17512031;hp=10c6286d544a76722a707a0cd0cdc73ad3e884ea;hpb=ecb31fcdc354471235ba44edbad3b24a6bded905;p=loctrkd.git diff --git a/gps303/termconfig.py b/gps303/termconfig.py index 10c6286..771f988 100644 --- a/gps303/termconfig.py +++ b/gps303/termconfig.py @@ -6,22 +6,19 @@ 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")) for protoname in ( - "SUPERVISION", "STATUS", - "RESET", - "WHITELIST_TOTAL", - "PROHIBIT_LBS", "SETUP", "POSITION_UPLOAD_INTERVAL", ): @@ -41,8 +38,32 @@ 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()) + 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": termconfig.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.Out(**kwargs).packed) log.debug("Response: %s", resp) zpush.send(resp.packed)