当前位置: 首页>>代码示例>>Python>>正文


Python crcmod.mkCrcFun方法代码示例

本文整理汇总了Python中crcmod.mkCrcFun方法的典型用法代码示例。如果您正苦于以下问题:Python crcmod.mkCrcFun方法的具体用法?Python crcmod.mkCrcFun怎么用?Python crcmod.mkCrcFun使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在crcmod的用法示例。


在下文中一共展示了crcmod.mkCrcFun方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _check_crc

# 需要导入模块: import crcmod [as 别名]
# 或者: from crcmod import mkCrcFun [as 别名]
def _check_crc (self, address, binary):
		'''
		Compares the CRC of the local binary to the one calculated by the
		bootloader.
		'''
		# Check the CRC
		crc_data = self._get_crc_internal_flash(address, len(binary))

		# Now interpret the returned bytes as the CRC
		crc_bootloader = struct.unpack('<I', crc_data[0:4])[0]

		# Calculate the CRC locally
		crc_function = crcmod.mkCrcFun(0x104c11db7, initCrc=0, xorOut=0xFFFFFFFF)
		crc_loader = crc_function(binary, 0)

		if crc_bootloader != crc_loader:
			raise TockLoaderException('Error: CRC check failed. Expected: 0x{:04x}, Got: 0x{:04x}'.format(crc_loader, crc_bootloader))
		else:
			logging.info('CRC check passed. Binaries successfully loaded.') 
开发者ID:tock,项目名称:tockloader,代码行数:21,代码来源:bootloader_serial.py

示例2: test_known_answers

# 需要导入模块: import crcmod [as 别名]
# 或者: from crcmod import mkCrcFun [as 别名]
def test_known_answers(self):
        for crcfun_params, v in self.known_answers:
            crcfun = mkCrcFun(*crcfun_params)
            self.assertEqual(crcfun('',0), 0, "Wrong answer for CRC parameters %s, input ''" % (crcfun_params,))
            for i, msg in enumerate(self.test_messages):
                self.assertEqual(crcfun(msg), v[i], "Wrong answer for CRC parameters %s, input '%s'" % (crcfun_params,msg))
                self.assertEqual(crcfun(msg[4:], crcfun(msg[:4])), v[i], "Wrong answer for CRC parameters %s, input '%s'" % (crcfun_params,msg))
                self.assertEqual(crcfun(msg[-1:], crcfun(msg[:-1])), v[i], "Wrong answer for CRC parameters %s, input '%s'" % (crcfun_params,msg)) 
开发者ID:cedricp,项目名称:ddt4all,代码行数:10,代码来源:test.py

示例3: mkPredefinedCrcFun

# 需要导入模块: import crcmod [as 别名]
# 或者: from crcmod import mkCrcFun [as 别名]
def mkPredefinedCrcFun(crc_name):
    definition = _get_definition_by_name(crc_name)
    return crcmod.mkCrcFun(poly=definition['poly'], initCrc=definition['init'], rev=definition['reverse'], xorOut=definition['xor_out'])


# crcmod.predefined.mkCrcFun is an alias for crcmod.predefined.mkPredefinedCrcFun 
开发者ID:cedricp,项目名称:ddt4all,代码行数:8,代码来源:predefined.py

示例4: test_compare_crc32

# 需要导入模块: import crcmod [as 别名]
# 或者: from crcmod import mkCrcFun [as 别名]
def test_compare_crc32(self):
        """The binascii module has a 32-bit CRC function that is used in a wide range
        of applications including the checksum used in the ZIP file format.
        This test compares the CRC-32 implementation of this crcmod module to
        that of binascii.crc32."""
        # The following function should produce the same result as
        # self.reference_crc32 which is derived from binascii.crc32.
        crc32 = mkCrcFun(g32,0,1,0xFFFFFFFF)

        for msg in self.test_messages:
            self.assertEqual(crc32(msg), self.reference_crc32(msg)) 
开发者ID:cedricp,项目名称:ddt4all,代码行数:13,代码来源:test.py

示例5: test_compare_poly

# 需要导入模块: import crcmod [as 别名]
# 或者: from crcmod import mkCrcFun [as 别名]
def test_compare_poly(self):
        """Compare various CRCs of this crcmod module to a pure
        polynomial-based implementation."""
        for crcfun_params, crc_poly_fun in self.test_poly_crcs:
            # The following function should produce the same result as
            # the associated polynomial CRC function.
            crcfun = mkCrcFun(*crcfun_params)

            for msg in self.test_messages:
                self.assertEqual(crcfun(msg), crc_poly_fun(msg)) 
开发者ID:cedricp,项目名称:ddt4all,代码行数:12,代码来源:test.py

示例6: crc16

# 需要导入模块: import crcmod [as 别名]
# 或者: from crcmod import mkCrcFun [as 别名]
def crc16(input_data):
    import crcmod
    crc16_func = crcmod.mkCrcFun(0x18005, initCrc=0x0000, xorOut=0b1111111111111111, rev=True)
    crc16 = crc16_func(bytearray(input_data))
    hex(crc16)
    return data([crc16 & 0xff, (crc16 >> 8) & 0xff]) 
开发者ID:tinyfpga,项目名称:TinyUSB,代码行数:8,代码来源:test_usbcore.py

示例7: _crc16

# 需要导入模块: import crcmod [as 别名]
# 或者: from crcmod import mkCrcFun [as 别名]
def _crc16(self, data):
        
        crc16 = crcmod.mkCrcFun(0x11021, rev=True, initCrc=0x4C49)
        checkSum = crc16(data)
        return checkSum 
开发者ID:ryan-brazeal-ufl,项目名称:OpenPyLivox,代码行数:7,代码来源:openpylivox.py

示例8: _crc32

# 需要导入模块: import crcmod [as 别名]
# 或者: from crcmod import mkCrcFun [as 别名]
def _crc32(self, data):
        
        crc32 = crcmod.mkCrcFun(0x104C11DB7, rev=True, initCrc=0x564F580A, xorOut=0xFFFFFFFF)
        checkSum = crc32(data)
        return checkSum 
开发者ID:ryan-brazeal-ufl,项目名称:OpenPyLivox,代码行数:7,代码来源:openpylivox.py

示例9: add_msdu

# 需要导入模块: import crcmod [as 别名]
# 或者: from crcmod import mkCrcFun [as 别名]
def add_msdu(self, msdu, msdu_len=-1):
        # Default msdu len
        if msdu_len == -1:
            msdu_len = len(msdu)

        mpdu_len = msdu_len + len(self.dot11hdr) + 4  # msdu + mac80211 + FCS

        if mpdu_len % 4 != 0:
            padding = "\x00" * (4 - (mpdu_len % 4))  # Align to 4 octets
        else:
            padding = ""
        mpdu_len <<= 4
        crc_fun = crcmod.mkCrcFun(0b100000111, rev=True, initCrc=0x00, xorOut=0xFF)

        crc = crc_fun(struct.pack('<H', mpdu_len))
        maccrc = dot11crc(str(self.dot11hdr / msdu))
        delim_sig = 0x4E

        #print('a-mpdu: len %d crc %02x delim %02x' % (mpdu_len >> 4, crc, delim_sig))
        #hexdump(maccrc)
        ampdu_header = struct.pack('<HBB', mpdu_len, crc, delim_sig)
        #hexdump(ampdu_header)

        self.data = self.data / ampdu_header / self.dot11hdr / msdu / maccrc / padding

        self.num_subframes += 1 
开发者ID:rpp0,项目名称:aggr-inject,代码行数:28,代码来源:packets.py

示例10: probe_response

# 需要导入模块: import crcmod [as 别名]
# 或者: from crcmod import mkCrcFun [as 别名]
def probe_response():
    rt = RadioTap(len=18, present='Flags+Rate+Channel+dBm_AntSignal+Antenna', notdecoded='\x00\x6c' + get_frequency(CHANNEL) + '\xc0\x00\xc0\x01\x00\x00')
    beacon_packet = Dot11(subtype=5, addr1='ff:ff:ff:ff:ff:ff', addr2="be:da:de:ad:be:ef", addr3="be:da:de:ad:be:ef", SC=0x3060) \
                    / Dot11ProbeResp(timestamp=time.time(), beacon_interval=0x0064, cap=0x2104) \
                    / Dot11Elt(ID='SSID', info="injected SSID") \
                    / Dot11Elt(ID='Rates', info=AP_RATES) \
                    / Dot11Elt(ID='DSset', info=chr(1))

    # Update sequence number
    beacon_packet.SC = 0x3060

    mpdu_len = len(beacon_packet) + 4

    if mpdu_len % 4 != 0:
        padding = "\x00" * (4 - (mpdu_len % 4))  # Align to 4 octets
    else:
        padding = ""
    mpdu_len <<= 4
    crc_fun = crcmod.mkCrcFun(0b100000111, rev=True, initCrc=0x00, xorOut=0xFF)

    crc = crc_fun(struct.pack('<H', mpdu_len))
    maccrc = dot11crc(str(beacon_packet))
    delim_sig = 0x4E

    #print('a-mpdu: len %d crc %02x delim %02x' % (mpdu_len >> 4, crc, delim_sig))
    #hexdump(maccrc)
    ampdu_header = struct.pack('<HBB', mpdu_len, crc, delim_sig)
    #hexdump(ampdu_header)

    data = ampdu_header / beacon_packet / maccrc / padding
    data /= "\x00\x00\x20\x4e" * 8
    data = str(data)

    return data 
开发者ID:rpp0,项目名称:aggr-inject,代码行数:36,代码来源:packets.py

示例11: __init__

# 需要导入模块: import crcmod [as 别名]
# 或者: from crcmod import mkCrcFun [as 别名]
def __init__(self, filehandle: BinaryIO):
        self.filehandle = filehandle
        self.bufsize = 2048  # adjust as needed
        self.buffer = b""
        self.spaceleft = self.bufsize
        """
        Calculate the CRC16 CCITT checksum of *data*.
        
        (CRC16 CCITT: start 0xFFFF, poly 0x1021)
        same as:
        
        crcmod.mkCrcFun( 0x11021, initCrc=0xFFFF, xorOut=0x0000, rev=False)
        """
        self.crc16 = crcmod.predefined.Crc("crc-ccitt-false") 
开发者ID:sid5432,项目名称:pyOTDR,代码行数:16,代码来源:parts.py

示例12: crc16_ccitt

# 需要导入模块: import crcmod [as 别名]
# 或者: from crcmod import mkCrcFun [as 别名]
def crc16_ccitt(data):
    """
    Calculate the CRC16 CCITT checksum of *data*.
    
    (CRC16 CCITT: start 0xFFFF, poly 0x1021)
    same as:
    
    crcmod.mkCrcFun( 0x11021, initCrc=0xFFFF, xorOut=0x0000, rev=False)
    """
    crc16 = crcmod.predefined.mkCrcFun("crc-ccitt-false")
    digest = crc16(data)
    return digest 
开发者ID:sid5432,项目名称:pyOTDR,代码行数:14,代码来源:test_cksum.py

示例13: ssid_packet

# 需要导入模块: import crcmod [as 别名]
# 或者: from crcmod import mkCrcFun [as 别名]
def ssid_packet():
    ap_mac = '00:00:00:00:00:00'
    rt = RadioTap(len=18, present='Flags+Rate+Channel+dBm_AntSignal+Antenna', notdecoded='\x00\x6c' + get_frequency(CHANNEL) + '\xc0\x00\xc0\x01\x00\x00')
    beacon_packet = Dot11(subtype=8, addr1='ff:ff:ff:ff:ff:ff', addr2=ap_mac, addr3=ap_mac) \
                 / Dot11Beacon(cap=0x2105)                                                           \
                 / Dot11Elt(ID='SSID', info="injected SSID")                                         \
                 / Dot11Elt(ID='Rates', info=AP_RATES)                                               \
                 / Dot11Elt(ID='DSset', info=chr(CHANNEL))

    # Update sequence number
    beacon_packet.SC = 0x3060

    # Update timestamp
    beacon_packet[Dot11Beacon].timestamp = time.time()

    mpdu_len = len(beacon_packet) + 4

    if mpdu_len % 4 != 0:
        padding = "\x00" * (4 - (mpdu_len % 4))  # Align to 4 octets
    else:
        padding = ""
    mpdu_len <<= 4
    crc_fun = crcmod.mkCrcFun(0b100000111, rev=True, initCrc=0x00, xorOut=0xFF)

    crc = crc_fun(struct.pack('<H', mpdu_len))
    maccrc = dot11crc(str(beacon_packet))
    delim_sig = 0x4E

    #print('a-mpdu: len %d crc %02x delim %02x' % (mpdu_len >> 4, crc, delim_sig))
    #hexdump(maccrc)
    ampdu_header = struct.pack('<HBB', mpdu_len, crc, delim_sig)
    #hexdump(ampdu_header)

    data = ampdu_header / beacon_packet / maccrc / padding
    data /= "\x00\x00\x20\x4e" * 8
    data = str(data)

    return data


# 802.11 Probe Response
# TODO: Fix me; duplicate code 
开发者ID:rpp0,项目名称:aggr-inject,代码行数:44,代码来源:packets.py


注:本文中的crcmod.mkCrcFun方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。