- zmsg = Bcast(zsub.recv())
- log.debug(
- "%s IMEI %s from %s at %s: %s",
- "I" if zmsg.is_incoming else "O",
- zmsg.imei,
- zmsg.peeraddr,
- datetime.fromtimestamp(zmsg.when).astimezone(tz=timezone.utc),
- zmsg.packet.hex(),
- )
- stow(
- is_incoming=zmsg.is_incoming,
- peeraddr=str(zmsg.peeraddr),
- when=zmsg.when,
- imei=zmsg.imei,
- proto=zmsg.proto,
- packet=zmsg.packet,
- )
+ events = poller.poll(1000)
+ for sk, fl in events:
+ if sk is zraw:
+ while True:
+ try:
+ zmsg = Bcast(zraw.recv(zmq.NOBLOCK))
+ except zmq.Again:
+ break
+ log.debug(
+ "%s IMEI %s from %s at %s: %s",
+ "I" if zmsg.is_incoming else "O",
+ zmsg.imei,
+ zmsg.peeraddr,
+ datetime.fromtimestamp(zmsg.when).astimezone(
+ tz=timezone.utc
+ ),
+ zmsg.packet.hex(),
+ )
+ stow(
+ is_incoming=zmsg.is_incoming,
+ peeraddr=str(zmsg.peeraddr),
+ when=zmsg.when,
+ imei=zmsg.imei,
+ proto=zmsg.proto,
+ packet=zmsg.packet,
+ )
+ elif sk is zrep:
+ while True:
+ try:
+ rept = Rept(zrep.recv(zmq.NOBLOCK))
+ except zmq.Again:
+ break
+ data = loads(rept.payload)
+ log.debug("R IMEI %s %s", rept.imei, data)
+ if data.pop("type") == "location":
+ data["imei"] = rept.imei
+ stowloc(**data)
+
+ else:
+ log.error("Event %s on unknown socket %s", fl, sk)