def compose_u6(self, tk, info): fmt = '!sBBBQ10B' length = len(info) fmt += 'iH%ss' % length value = [b'U', 6, 48, fn.get_seq(tk.sn), tk.sessionID] + tk.fmt_iccid + [int(time.time()), length, info.encode('utf-8')] self.logging.info("u6_mg: %s", value) u6_mg = struct.pack(fmt, *value) return u6_mg
def compose_u4(self, tk): fmt = '!sBBBQ10B' fmt += 'BBiiihBBBBBb' lon, lat = fn.get_lonlat(tk.lon, tk.lat) value = [b'U', 4, 48, fn.get_seq(tk.sn), tk.sessionID] + tk.fmt_iccid + \ [tk.type, tk.bat, tk.ts, lon, lat, tk.alt, tk.speed, tk.course, tk.gps, tk.acc, tk.gsm, tk.temp] self.logging.info("realtime_mg: %s", value) report_mg = struct.pack(fmt, *value) return report_mg
def send_heartbat(self): while True: if options.tracker.get(self.sn): U2 = self.composer.compose_heartbat(fn.get_seq(self.sn), self.iccid_lst_int, options.tracker[self.sn]) self.socket.send(U2) else: break time.sleep(1.8e3)
def compose_stop(self, tk, ts=None): fmt = '!sBBBQ10BBB' fmt += 'iiihBBBBBbBBh' status = 1 ts = ts or int(time.time()) value = [b'U', 5, 48, fn.get_seq(tk.sn), tk.sessionID] + tk.fmt_iccid + \ [1, 24, int(ts), int(tk.lon*100000), int(tk.lat*100000), tk.alt, tk.speed, tk.course, tk.gps, tk.acc, tk.gsm, tk.temp, tk.bat, status, 1] self.logging.info("stop_mg: %s", value) position_mg = struct.pack(fmt, *value) return position_mg
def compose_move(self, tk, lonlats): fmt = '!sBBBQ10BBB' fmt += 'iiihBBBBBbBBh' * len(lonlats) value = [b'U', 5, 48, fn.get_seq(tk.sn), tk.sessionID] + tk.fmt_iccid + [len(lonlats), 24] for i, l in enumerate(lonlats): if i == 0: status = 2 else: status = 0 value += [int(l[2]), int(l[0]), int(l[1]), tk.alt, tk.speed, tk.course, tk.gps, tk.acc, tk.gsm, tk.temp, tk.bat, status, 1] self.logging.info("move_mg: %s", value) position_mg = struct.pack(fmt, *value) return position_mg
def compose_u8(self, tk): t_time = int(time.time()) fmt = '!sBBBQ10B' fmt += 'BBIiihBBBBBbHHIBBI6B' lon, lat = fn.get_lonlat(tk.lon, tk.lat) rxlev = 39 tp = -5 bvg = 3200 epvg = 800 ait = t_time - 100 blet = 3 bler = 88 blets = t_time - 90 blemac = [209, 58, 39, 178, 72, 129] value = [b'U', 8, 48, fn.get_seq(tk.sn), tk.sessionID] + tk.fmt_iccid value += [0, 86, t_time, lon, lat, tk.alt, tk.speed, tk.course, tk.gps, tk.acc, rxlev, tp, bvg, epvg, ait, blet, bler, blets] + blemac self.logging.info("u8_msg: %s", value) u8_mg = struct.pack(fmt, *value) return u8_mg
def mutate(self, info, sn, chg=None, bat=None, temp=None, gsm=None, acc=None): tk = options.tracker.get(sn) def _set_conf(args): for k in args: if args[k] is not None: tk[k] = args[k] if tk: if any([chg, bat, temp, gsm, acc]): options.thread_lock.acquire() list( map(_set_conf, [{ 'chg': chg }, { 'bat': bat }, { 'temp': temp }, { 'acc': acc }])) options.thread_lock.release() u2 = Composer(tk.lon, tk.lat).compose_heartbat(fn.get_seq(sn), fn.fmt_iccid(tk.iccid), tk) options.socket_param.send(u2) code, message = RESPONSE.fmt_response(RESPONSE.OK) else: code, message = RESPONSE.fmt_response(RESPONSE.TRACKER_NOT_EXISTS) return Result(code=code, message=message)
def compose_u7_header(self, tk, l): fmt = '!sBBBQ10BB' value = [b'U', 7, 48, fn.get_seq(tk.sn), tk.sessionID] + tk.fmt_iccid + [l] return value, fmt
def send_config(self): U3 = self.composer.compose_config(fn.get_seq(self.sn), self.iccid_lst_int, int(self.res['sessionID'])) self.socket.send(U3)
def send_login(self): T1 = self.composer.compose_login(fn.get_seq(self.sn), self.sn_lst_int, self.iccid_lst_int) self.socket.send(T1)