Пример #1
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
Пример #2
0
 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)
Пример #3
0
 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
Пример #4
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
Пример #5
0
 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
Пример #6
0
 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
Пример #7
0
    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
Пример #8
0
    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
Пример #9
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
Пример #10
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
Пример #11
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
Пример #12
0
 def unmarshall(bytes, extra=None):
     buf = ByteBuf(bytes)
     msg = MessageAddressCNResp()
     msg.extra = extra
     return msg
Пример #13
0
 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
Пример #14
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
Пример #15
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
Пример #16
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)
     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
Пример #17
0
 def unmarshall(bytes, extra=None):
     buf = ByteBuf(bytes)
     msg = MessageSerialDownStream()
     msg.extra = extra
     return msg
Пример #18
0
 def unmarshall(bytes, extra=None):
     buf = ByteBuf(bytes)
     msg = MessageGenericMessage()
     msg.extra = extra
     return msg
Пример #19
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
Пример #20
0
 def unmarshall(bytes, extra=None):
     buf = ByteBuf(bytes)
     msg = MessageOnlineCommand()
     msg.extra = extra
     return msg
Пример #21
0
 def unmarshall(bytes, extra=None):
     buf = ByteBuf(bytes)
     msg = MessageLbsAddressReq()
     msg.extra = extra
     return msg
Пример #22
0
    def unmarshall(bytes, extra=None):
        buf = ByteBuf(bytes)
        msg = MessageFenceAlarm()
        msg.extra = extra

        return msg
Пример #23
0
 def unmarshall(bytes, extra=None):
     buf = ByteBuf(bytes)
     msg = MessageDeviceRespOnlineEN()
     msg.extra = extra
     return msg
Пример #24
0
 def unmarshall(bytes, extra=None):
     buf = ByteBuf(bytes)
     msg = MessageAdjustTime()
     msg.extra = extra
     return msg
Пример #25
0
 def unmarshall(bytes,extra=None):
     buf = ByteBuf(bytes)
     msg = MessageLbsAlarmData()
     msg.extra = extra
     return msg
Пример #26
0
 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
Пример #27
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