from getopt import getopt
from logging import getLogger
from sys import argv
+from time import time
import zmq
from . import common
zpush.connect(conf.get("collector", "listenurl"))
if len(args) < 2:
- raise ValueError("Too few args, need IMEI and command min: " + str(args))
+ raise ValueError(
+ "Too few args, need IMEI and command min: " + str(args)
+ )
imei = args[0]
cmd = args[1]
args = args[2:]
for arg in args:
k, v = arg.split("=")
kwargs[k] = v
- resp = Resp(imei=imei, packet=cls.Out(**kwargs).packed)
+ resp = Resp(imei=imei, when=time(), packet=cls.Out(**kwargs).packed)
log.debug("Response: %s", resp)
zpush.send(resp.packed)
Bcast(
is_incoming=False,
proto=proto_of_message(zmsg.packet),
+ when=zmsg.when,
imei=zmsg.imei,
packet=zmsg.packet,
).packed
respmsg = inline_response(packet)
if respmsg is not None:
clients.response(
- Resp(imei=imei, packet=respmsg)
+ Resp(imei=imei, when=when, packet=respmsg)
)
else:
log.debug("Stray event: %s on socket %s", fl, sk)
)
resp = Resp(
imei=zmsg.imei,
+ when=zmsg.when, # not the current time, but the original!
packet=msg.Out(latitude=lat, longitude=lon).packed,
)
log.debug("Response for lat=%s, lon=%s: %s", lat, lon, resp)
):
if key in termconfig:
kwargs[key] = termconfig[key]
- resp = Resp(imei=zmsg.imei, packet=msg.Out(**kwargs).packed)
+ resp = Resp(
+ imei=zmsg.imei, when=zmsg.when, packet=msg.Out(**kwargs).packed
+ )
log.debug("Response: %s", resp)
zpush.send(resp.packed)
@property
def packed(self):
return (
- "0000000000000000" if self.imei is None else self.imei.encode()
- ) + (
+ ("0000000000000000" if self.imei is None else self.imei.encode())
+ + (
b"\0\0\0\0\0\0\0\0"
if self.when is None
else pack("!d", self.when)
- ) + self.packet
+ )
+ + self.packet
+ )
def decode(self, buffer):
self.imei = buffer[:16].decode()