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
tostop.append(sk)
respmsg = inline_response(packet)
if respmsg is not None:
- clients.response(
+ tosend.append(
Resp(imei=imei, when=when, packet=respmsg)
)
else:
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:
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: