Esempio n. 1
0
    def __init__(self, buf, crc):
        rst = bitunpack(
            'u8u10u6u5u1u2u5u3u24u16u16', bytearray(buf), inverse_endian=True)

        print(''.join(['{:08b}'.format(x) for x in bytearray(buf)]))

        self.d = collections.OrderedDict()
        self.d['SOF'] = rst[0]
        self.d['LEN'] = rst[1]
        self.d['VER'] = rst[2]
        self.d['SESSION'] = rst[3]
        self.d['A'] = rst[4]
        self.d['RES0'] = rst[5]
        self.d['PADDING'] = rst[6]
        self.d['ENC'] = rst[7]
        self.d['RES1'] = rst[8]
        self.d['SEQ'] = rst[9]
        self.d['CRC'] = rst[10]

        crc.crcValue = crc.initCrc
        crc.update(buf[:10])
        self.crc_check_passed = (crc.crcValue == self.d['CRC'])

        d = self.d
        print("LEN[%3d] SESSION[%2d] SEQ[%d] CRC[%s] ENC[%d] ACK[%d]" %
              (d['LEN'],
               d['SESSION'],
               d['SEQ'],
               str(crc.crcValue == d['CRC']),
               self.d['ENC'],
               self.d['A']
               )
              )
    def __init__(self, buf, crc):
        rst = bitunpack("u8u10u6u5u1u2u5u3u24u16u16", bytearray(buf), inverse_endian=True)

        print ("".join(["{:08b}".format(x) for x in bytearray(buf)]))

        self.d = collections.OrderedDict()
        self.d["SOF"] = rst[0]
        self.d["LEN"] = rst[1]
        self.d["VER"] = rst[2]
        self.d["SESSION"] = rst[3]
        self.d["A"] = rst[4]
        self.d["RES0"] = rst[5]
        self.d["PADDING"] = rst[6]
        self.d["ENC"] = rst[7]
        self.d["RES1"] = rst[8]
        self.d["SEQ"] = rst[9]
        self.d["CRC"] = rst[10]

        crc.crcValue = crc.initCrc
        crc.update(buf[:10])
        self.crc_check_passed = crc.crcValue == self.d["CRC"]

        d = self.d
        print (
            "LEN[%3d] SESSION[%2d] SEQ[%d] CRC[%s] ENC[%d] ACK[%d]"
            % (d["LEN"], d["SESSION"], d["SEQ"], str(crc.crcValue == d["CRC"]), self.d["ENC"], self.d["A"])
        )
Esempio n. 3
0
 def from_int(cls, pack: int) -> VehicleHistory:
     return cls(*[
         eval(f.type)(it)  # type: ignore
         for f, it in zip(
             fields(cls),
             bitunpack(cls.FMT, pack.to_bytes(byteorder="big", length=2)),
         )
     ])
 def parse_data(self):
     buf = "".join([self.buf[x] for x in range(0, self.header.d["LEN"])])
     self.crc32.crcValue = self.crc32.initCrc
     self.crc32.update(buf[:-4])
     rst = bitunpack("u32", bytearray(buf[-4:]), inverse_endian=True)
     print "CRC32:{}".format(str(self.crc32.crcValue == rst[0]))
     print "data:{}".format(base64.b16encode(buf[HEADER_LEN : self.header.d["LEN"]]))
     print "-------------------------------"
     return (True, self.header.d["LEN"])
Esempio n. 5
0
 def parse_data(self):
     buf = ''.join([self.buf[x]
                    for x in range(0, self.header.d['LEN'])])
     self.crc32.crcValue = self.crc32.initCrc
     self.crc32.update(buf[:-4])
     rst = bitunpack('u32', bytearray(buf[-4:]), inverse_endian=True)
     print 'CRC32:{}'.format(str(self.crc32.crcValue == rst[0]))
     print 'data:{}'.format(base64.b16encode(buf[HEADER_LEN:self.header.d['LEN']]))
     print '-------------------------------'
     return (True, self.header.d['LEN'])