X-Git-Url: http://www.average.org/gitweb/?p=loctrkd.git;a=blobdiff_plain;f=loctrkd%2Frectifier.py;h=5926377ee76ad4dc5665b72dec551a5e279bc661;hp=47d9d055f8471357d5edb748f580cbaf6be90169;hb=2cf0fd9d215dda17eae4261ab7967367f6aa0028;hpb=456fcc5a8964c84385d34a6687e83ae05ab2ddc3 diff --git a/loctrkd/rectifier.py b/loctrkd/rectifier.py index 47d9d05..5926377 100644 --- a/loctrkd/rectifier.py +++ b/loctrkd/rectifier.py @@ -31,7 +31,7 @@ class QryModule: mnc: int, gsm_cells: List[Tuple[int, int, int]], wifi_aps: List[Tuple[str, int]], - ) -> Tuple[float, float]: + ) -> Tuple[float, float, float]: ... @@ -51,7 +51,9 @@ def runserver(conf: ConfigParser) -> None: zpush = zctx.socket(zmq.PUSH) # type: ignore zpush.connect(conf.get("collector", "listenurl")) zpub = zctx.socket(zmq.PUB) # type: ignore - zpub.connect(conf.get("rectifier", "publishurl")) + oldmask = umask(0o117) + zpub.bind(conf.get("rectifier", "publishurl")) + umask(oldmask) try: while True: @@ -66,20 +68,26 @@ def runserver(conf: ConfigParser) -> None: datetime.fromtimestamp(zmsg.when).astimezone(tz=timezone.utc), msg, ) - rect: Report = msg.rectified() + pmod, rect = msg.rectified() log.debug("rectified: %s", rect) if isinstance(rect, (CoordReport, StatusReport)): - zpub.send(Rept(imei=zmsg.imei, payload=rect.json).packed) + zpub.send( + Rept(imei=zmsg.imei, pmod=pmod, payload=rect.json).packed + ) elif isinstance(rect, HintReport): try: - lat, lon = qry.lookup( + lat, lon, acc = qry.lookup( rect.mcc, rect.mnc, rect.gsm_cells, list((mac, strng) for _, mac, strng in rect.wifi_aps), ) log.debug( - "Approximated lat=%s, lon=%s for %s", lat, lon, rect + "Approximated lat=%s, lon=%s, acc=%s for %s", + lat, + lon, + acc, + rect, ) if proto_needanswer.get(zmsg.proto, False): resp = Resp( @@ -89,23 +97,25 @@ def runserver(conf: ConfigParser) -> None: ) log.debug("Sending reponse %s", resp) zpush.send(resp.packed) + rept = CoordReport( + devtime=rect.devtime, + battery_percentage=rect.battery_percentage, + accuracy=acc, + altitude=None, + speed=None, + direction=None, + latitude=lat, + longitude=lon, + ) + log.debug("Sending report %s", rept) zpub.send( Rept( imei=zmsg.imei, - payload=CoordReport( - devtime=rect.devtime, - battery_percentage=rect.battery_percentage, - accuracy=-1, - altitude=-1, - speed=-1, - direction=-1, - latitude=lat, - longitude=lon, - ).json, + payload=rept.json, ).packed ) except Exception as e: - log.warning( + log.exception( "Lookup for %s rectified as %s resulted in %s", msg, rect,