From 0c28fa6306f252934fe7e2c04522e8540c414387 Mon Sep 17 00:00:00 2001 From: Eugene Crosser Date: Mon, 9 May 2022 21:53:29 +0200 Subject: [PATCH] do not respond to hibernation; minor cleanup --- gps303/collector.py | 20 ++++++++++---------- gps303/gps303proto.py | 1 - gps303/wsgateway.py | 34 ++++++++++++---------------------- 3 files changed, 22 insertions(+), 33 deletions(-) diff --git a/gps303/collector.py b/gps303/collector.py index b8cc379..de65394 100644 --- a/gps303/collector.py +++ b/gps303/collector.py @@ -167,15 +167,6 @@ def runserver(conf): try: msg = zpull.recv(zmq.NOBLOCK) zmsg = Resp(msg) - zpub.send( - Bcast( - is_incoming=False, - proto=proto_of_message(zmsg.packet), - when=zmsg.when, - imei=zmsg.imei, - packet=zmsg.packet, - ).packed - ) tosend.append(zmsg) except zmq.Again: break @@ -210,7 +201,7 @@ def runserver(conf): tostop.append(sk) respmsg = inline_response(packet) if respmsg is not None: - clients.response( + tosend.append( Resp(imei=imei, when=when, packet=respmsg) ) else: @@ -220,6 +211,15 @@ def runserver(conf): poller.unregister(fd) clients.stop(fd) for zmsg in tosend: + zpub.send( + Bcast( + is_incoming=False, + proto=proto_of_message(zmsg.packet), + when=zmsg.when, + imei=zmsg.imei, + packet=zmsg.packet, + ).packed + ) log.debug("Sending to the client: %s", zmsg) clients.response(zmsg) for clntsock, clntaddr in topoll: diff --git a/gps303/gps303proto.py b/gps303/gps303proto.py index 8f4ffcc..e3e7cf1 100755 --- a/gps303/gps303proto.py +++ b/gps303/gps303proto.py @@ -297,7 +297,6 @@ class STATUS(GPS303Pkt): class HIBERNATION(GPS303Pkt): # Server can send to send devicee to sleep PROTO = 0x14 - RESPOND = Respond.INL class RESET(GPS303Pkt): diff --git a/gps303/wsgateway.py b/gps303/wsgateway.py index 2f6811e..d66070e 100644 --- a/gps303/wsgateway.py +++ b/gps303/wsgateway.py @@ -287,28 +287,18 @@ def runserver(conf): zmsg = Bcast(zsub.recv(zmq.NOBLOCK)) msg = parse_message(zmsg.packet, zmsg.is_incoming) log.debug("Got %s with %s", zmsg, msg) - if isinstance(msg, GPS_POSITIONING): - tosend.append( - { - "imei": zmsg.imei, - "timestamp": str(msg.devtime), - "longitude": msg.longitude, - "latitude": msg.latitude, - } - ) - elif isinstance(msg, WIFI_POSITIONING): - tosend.append( - { - "imei": zmsg.imei, - "timestamp": str( - datetime.fromtimestamp( - zmsg.when - ).astimezone(tz=timezone.utc) - ), - "longitude": msg.longitude, - "latitude": msg.latitude, - } - ) + tosend.append( + { + "imei": zmsg.imei, + "timestamp": str( + datetime.fromtimestamp( + zmsg.when + ).astimezone(tz=timezone.utc) + ), + "longitude": msg.longitude, + "latitude": msg.latitude, + } + ) except zmq.Again: break elif sk == tcpfd: -- 2.39.2