def unmarshall(bytes, extra=None): buf = ByteBuf(bytes) msg = MessageOnlineCommand() msg.extra = extra msg.flag = buf.read_uint32() msg.encode = buf.read_uint8() msg.content = buf.bytes[buf.index:] return msg
def packet(self): pkt = DownStream.packet() buf = ByteBuf() size = 4 + len(self.content) buf.write_uint8(size) buf.write_uint32(self.sequence) buf.write_bytes(self.content) buf.write_uint16(self.lang) pkt.set_payload(buf.bytes)
def unmarshall(bytes, extra=None): buf = ByteBuf(bytes) s = buf.read_bytes(8) msg = MessageLogin() msg.device_id = ''.join(map(hex, map(ord, s))).replace('0x', '') value = buf.read_uint16() msg.eastwest = (value >> 3) & 1 msg.timezone = (value >> 4) / 100 msg.extra = extra return msg
def unmarshall(bytes,extra=None): import base64 buf = ByteBuf(bytes) msg = MessageGenericMessage() msg.extra = extra msg.type = buf.read_uint8() msg.content = buf.bytes[buf.index:] if msg.type == 4: # 终端状态同步信息 ascii pass else: # 转成 base64 msg.content = base64.b64encode(msg.content) return msg
def packet(self): from packet import NetWorkPacket pkt = NetWorkPacket() buf = ByteBuf() size = 4 + len(self.content) buf.write_uint8(size) buf.write_uint32(self.sequence) buf.write_bytes(self.content) buf.write_uint16(self.lang) pkt.set_payload(buf.bytes) pkt.type = self.Type.value return pkt
def unmarshall(bytes,extra=None): buf = ByteBuf(bytes) s = buf.read_bytes(8) msg = MessageLogin() msg.device_id = ''.join(map(lambda _:'%02x'%_,map(ord,s))) if msg.device_id[0] == '0': msg.device_id = msg.device_id[1:] value = buf.read_uint16() msg.eastwest = (value>>3) & 1 msg.timezone = (value>>4) / 100 msg.extra = extra return msg
def unmarshall(bytes, extra=None): buf = ByteBuf(bytes) msg = MessageGpsLocation() msg.extra = extra msg.location.parse(buf) msg.location_ext.parse(buf) msg.acc = buf.read_uint8() msg.rpt_mode = buf.read_uint8() msg.up_mode = buf.read_uint8() # msg.miles = buf.read_uint32() return msg
def unmarshall(bytes, extra=None): buf = ByteBuf(bytes) msg = MessageAlarmData() msg.extra = extra msg.location.parse(buf) msg.lbs_size = buf.read_uint8() msg.location_ext.parse(buf) # msg.simple_info.parse(buf.read_uint8()) # msg.voltage = buf.read_uint8() # msg.gsm = buf.read_uint8() # msg.alarm = buf.read_uint8() # msg.lang = buf.read_uint8() # msg.miles = buf.read_uint32() return msg
def unmarshall(bytes, extra=None): buf = ByteBuf(bytes) msg = MessageHeartBeat() msg.extra = extra msg.simple_info.parse(buf.read_uint8()) msg.voltage = buf.read_uint8() msg.gsm = buf.read_uint8() msg.lang = buf.read_uint16() return msg
def unmarshall(bytes,extra=None): buf = ByteBuf(bytes) msg = MessageOnlineCommand() msg.extra = extra size = buf.read_uint8() body_size = size - 4 msg.sequence = buf.read_uint32() msg.content = buf.read_bytes(body_size) msg.lang = buf.read_uint16() return msg
def check_size(self, bytes): """计算这个包的大小""" buf = ByteBuf(bytes) self.start_flag = buf.read_bytes(2) if self.start_flag == self.START_FLAG_1: self.fieldsize_width = 1 self.size = buf.read_uint8() if self.start_flag == self.START_FLAG_2: self.fieldsize_width = 2 self.size = buf.read_uint16() self.type = buf.read_uint8() packet_size = self.size + 4 + self.fieldsize_width return packet_size
def unmarshall(bytes, extra=None): buf = ByteBuf(bytes) msg = MessageAddressCNResp() msg.extra = extra return msg
def to_bytes(self): buf = ByteBuf() self.size = 5 + len(self.payload) buf.write_bytes(self.start_flag) if self.fieldsize_width == 1: buf.write_uint8(self.size) if self.fieldsize_width == 2: buf.write_uint16(self.size) buf.write_uint8(self.type) buf.write_bytes(self.payload) buf.write_uint16(self.sequence) crc = self.calc_crc(buf.bytes[2:]) buf.write_uint16(crc) buf.write_bytes(self.stop_flag) return buf.bytes
def unpack(self, bytes): index = 0 buf = ByteBuf(bytes) self.start_flag = buf.read_bytes(2) if self.start_flag == self.START_FLAG_1: self.fieldsize_width = 1 self.size = buf.read_uint8() if self.start_flag == self.START_FLAG_2: self.fieldsize_width = 2 self.size = buf.read_uint16() self.type = buf.read_uint8() # if len(bytes) - 4 - self.fieldsize_width != self.size: # print 'Packet Size Error. ' # return None buf.save() buf.move(len(bytes) - 6) self.sequence = buf.read_uint16() self.crc16 = buf.read_uint16() buf.restore() crc = self.calc_crc(bytes[2:len(bytes) - 4]) if crc != self.crc16: print 'Packet Crc Error.' return None msgcls = MessageClsDict.get(self.type) if not msgcls: print 'Message Type unKnown. value:{}'.format(self.type) return None payload = buf.read_bytes(self.size - 5) msg = msgcls.unmarshall(payload, self) # msg = msgcls.unmarshall(bytes[2+self.fieldsize_width+1, len(bytes)-6]) if not msg: print 'Message unmarshall Error. ', str(msgcls) return None return msg
def unmarshall(bytes,extra=None): buf = ByteBuf(bytes) msg = MessageWifiExtension() msg.extra = extra y = 2000 + buf.read_uint8() m = buf.read_uint8() d = buf.read_uint8() h = buf.read_uint8() M = buf.read_uint8() s = buf.read_uint8() msg.ymdhms = '{}{:02d}{:02d} {:02d}:{:02d}:{:02d}'.format(y, m, d, h, M, s) msg.mcc = buf.read_uint16() msg.mnc = buf.read_uint8() msg.lac = buf.read_uint16() msg.cell_id = tool_format_ci_value( buf.read_bytes(3)) msg.rssi = buf.read_uint8() msg.signal = msg.rssi msg.lac1 = buf.read_uint16() msg.ci1 = tool_format_ci_value( buf.read_bytes(3)) msg.rssi1 = buf.read_uint8() msg.lac2 = buf.read_uint16() msg.ci2 = tool_format_ci_value( buf.read_bytes(3)) msg.rssi2 = buf.read_uint8() msg.lac3 = buf.read_uint16() msg.ci3 = tool_format_ci_value( buf.read_bytes(3)) msg.rssi3 = buf.read_uint8() msg.lac4 = buf.read_uint16() msg.ci4 = tool_format_ci_value( buf.read_bytes(3)) msg.rssi4 = buf.read_uint8() msg.lac5 = buf.read_uint16() msg.ci5 = tool_format_ci_value( buf.read_bytes(3)) msg.rssi5 = buf.read_uint8() msg.lac6 = buf.read_uint16() msg.ci6 = tool_format_ci_value( buf.read_bytes(3)) msg.rssi6 = buf.read_uint8() msg.ahead = buf.read_uint8() msg.wifi_num = buf.read_uint8() for n in range(msg.wifi_num): wd = WifiData() wd.signal = buf.read_uint8() mac = buf.read_bytes(6) wd.mac = tool_format_wifi_mac(mac) msg.wifi_data.append(wd.dict()) # print str(wd) return msg
def unmarshall(bytes, extra=None): buf = ByteBuf(bytes) msg = MessageAudioData() msg.type = buf.read_uint8() # 文件类型 msg.total_size = buf.read_uint32() #文件总长 msg.check = buf.read_uint8() check_data = '' if msg.check == 0: # crc16 check_data = buf.read_uint16() if msg.check == 1: # md5 check_data = buf.read_bytes(16) msg.offset = buf.read_uint32() size = buf.read_uint16() msg.content = buf.read_bytes(size) if msg.type in (0,2): # 录音文件s # msg.flag = buf.read_bytes(6) y = 2000 + buf.read_uint8() m = buf.read_uint8() d = buf.read_uint8() h = buf.read_uint8() M = buf.read_uint8() s = buf.read_uint8() msg.ymdhms = '{}{:02d}{:02d} {:02d}:{:02d}:{:02d}'.format(y, m, d, h, M, s) elif msg.type == 1: #对应 SOS、声控 报警包序列号相同 msg.flag = buf.read_uint16() elif msg.type == 3: msg.flag = buf.read_uint32() msg.sequence = buf.read_uint16() return msg
def unmarshall(bytes, extra=None): buf = ByteBuf(bytes) msg = MessageSerialDownStream() msg.extra = extra return msg
def unmarshall(bytes, extra=None): buf = ByteBuf(bytes) msg = MessageGenericMessage() msg.extra = extra return msg
def unmarshall(bytes, extra=None): buf = ByteBuf(bytes) msg = MessageLbsStationExtension() msg.extra = extra # y = 2000 + buf.read_uint8() # m = buf.read_uint8() # d = buf.read_uint8() # h = buf.read_uint8() # M = buf.read_uint8() # s = buf.read_uint8() # msg.ymdhms = '{}{:02d}{:02d} {:02d}:{:02d}:{:02d}'.format(y, m, d, h, M, s) msg.parse_time(buf) msg.mcc = buf.read_uint16() msg.mnc = buf.read_uint8() msg.lac = buf.read_uint16() msg.cell_id = tool_format_ci_value(buf.read_bytes(3)) msg.rssi = buf.read_uint8() msg.signal = msg.rssi msg.lac1 = buf.read_uint16() msg.ci1 = tool_format_ci_value(buf.read_bytes(3)) msg.rssi1 = buf.read_uint8() msg.lac2 = buf.read_uint16() msg.ci2 = tool_format_ci_value(buf.read_bytes(3)) msg.rssi2 = buf.read_uint8() msg.lac3 = buf.read_uint16() msg.ci3 = tool_format_ci_value(buf.read_bytes(3)) msg.rssi3 = buf.read_uint8() msg.lac4 = buf.read_uint16() msg.ci4 = tool_format_ci_value(buf.read_bytes(3)) msg.rssi4 = buf.read_uint8() msg.lac5 = buf.read_uint16() msg.ci5 = tool_format_ci_value(buf.read_bytes(3)) msg.rssi5 = buf.read_uint8() msg.lac6 = buf.read_uint16() msg.ci6 = tool_format_ci_value(buf.read_bytes(3)) msg.rssi6 = buf.read_uint8() msg.ahead = buf.read_uint8() msg.lang = buf.read_uint16() return msg
def unmarshall(bytes, extra=None): buf = ByteBuf(bytes) msg = MessageOnlineCommand() msg.extra = extra return msg
def unmarshall(bytes, extra=None): buf = ByteBuf(bytes) msg = MessageLbsAddressReq() msg.extra = extra return msg
def unmarshall(bytes, extra=None): buf = ByteBuf(bytes) msg = MessageFenceAlarm() msg.extra = extra return msg
def unmarshall(bytes, extra=None): buf = ByteBuf(bytes) msg = MessageDeviceRespOnlineEN() msg.extra = extra return msg
def unmarshall(bytes, extra=None): buf = ByteBuf(bytes) msg = MessageAdjustTime() msg.extra = extra return msg
def unmarshall(bytes,extra=None): buf = ByteBuf(bytes) msg = MessageLbsAlarmData() msg.extra = extra return msg
def marshall(self): buf = ByteBuf() self.size = 39 + len(self.address) buf.write_uint8(self.size) buf.write_uint32(self.sequence) buf.write_bytes(self.alarmsms) buf.write_bytes('&&') buf.write_bytes(self.address) buf.write_bytes('&&') buf.write_bytes(self.tel) buf.write_bytes('##') return buf.bytes
def unmarshall(bytes, extra=None): buf = ByteBuf(bytes) msg = MessageLbsStationExtension() msg.extra = extra msg.parse_time(buf) msg.mcc = buf.read_uint16() msg.mnc = buf.read_uint8() msg.lac = buf.read_uint16() msg.cell_id = tool_format_ci_value(buf.read_bytes(3)) msg.rssi = buf.read_uint8() msg.signal = msg.rssi msg.lac1 = buf.read_uint16() msg.ci1 = tool_format_ci_value(buf.read_bytes(3)) msg.rssi1 = buf.read_uint8() msg.lac2 = buf.read_uint16() msg.ci2 = tool_format_ci_value(buf.read_bytes(3)) msg.rssi2 = buf.read_uint8() msg.lac3 = buf.read_uint16() msg.ci3 = tool_format_ci_value(buf.read_bytes(3)) msg.rssi3 = buf.read_uint8() msg.lac4 = buf.read_uint16() msg.ci4 = tool_format_ci_value(buf.read_bytes(3)) msg.rssi4 = buf.read_uint8() msg.lac5 = buf.read_uint16() msg.ci5 = tool_format_ci_value(buf.read_bytes(3)) msg.rssi5 = buf.read_uint8() msg.lac6 = buf.read_uint16() msg.ci6 = tool_format_ci_value(buf.read_bytes(3)) msg.rssi6 = buf.read_uint8() return msg