Пример #1
0
    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)
            msg.parse_time(buf)

        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
Пример #2
0
 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
Пример #3
0
 def unmarshall(bytes, extra=None):
     buf = ByteBuf(bytes)
     msg = MessageGpsLocation()
     msg.extra = extra
     msg.location.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
Пример #4
0
    def unmarshall(bytes, extra=None):
        buf = ByteBuf(bytes)
        msg = MessageLbsAlarmData()
        msg.extra = extra
        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()

        return msg
Пример #5
0
 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
Пример #6
0
 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
Пример #7
0
    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
Пример #8
0
 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
Пример #9
0
 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
Пример #10
0
    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
Пример #11
0
    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
Пример #12
0
    def unmarshall(bytes, extra=None):
        buf = ByteBuf(bytes)
        msg = MessageFenceAlarm()
        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.fence_id = buf.read_uint8()

        msg.miles = buf.read_uint32()
        return msg
Пример #13
0
    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