Ejemplo n.º 1
0
def test_algorithm_checks(algorithm_name):
    """Check the result of every algorithm against its recorded check-word"""
    check_word = crcengine.get_algorithm_params(algorithm_name, True)["check"]
    crc_alg = crcengine.new(algorithm_name)
    assert crc_alg(
        b"123456789") == check_word, "Check CRC mismatch for {}".format(
            algorithm_name)
Ejemplo n.º 2
0
def crc16_xmodem():
    return crcengine.new('crc16-xmodem')
Ejemplo n.º 3
0
def crc16_kermit():
    return crcengine.new('crc16-kermit')
Ejemplo n.º 4
0
def crc32():
    return crcengine.new('crc32')
Ejemplo n.º 5
0
def test_crc32_bzip2():
    crc32_bzip2 = crcengine.new('crc32-bzip2')
    assert crc32_bzip2(b'A') == 0x81B02D8B
    assert crc32_bzip2(b'123456789') == 0xFC891918
Ejemplo n.º 6
0
import socket
import crcengine

HOST = '127.0.0.1'  # The server's hostname or IP address
PORT = 65432        # The port used by the server
crcAlg = crcengine.new('crc16-modbus')


def calcCrc (data):
    return crcAlg(data)

def makebuff(s:str):
    bts = bytearray(s,'ascii')
    l = len(bts)
    buff = bytearray(3)
    buff[0]=255
    buff[1]=255
    buff[2]=l
    buff.extend(bts)
    crc = calcCrc(bts)
    crcb = crc.to_bytes(2, byteorder='little')
    print ("crc = {}  [{}, {}]".format(crc, crcb[0], crcb[1]))
    buff.extend(crcb)
    return buff

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
    s.connect((HOST, PORT))
    txt = "Saying hello"
    while str != "q":
        buff = makebuff (txt)
        s.sendall(buff)
Ejemplo n.º 7
0
def test_crc8_autosar():
    crc8 = crcengine.new("crc8-autosar")
    assert crc8(b"123456789") == 0xDF
Ejemplo n.º 8
0
def test_crc8_autosar():
    crc8 = crcengine.new('crc8-autosar')
    assert crc8(b'123456789') == 0xdf
Ejemplo n.º 9
0
def crc16_autosar():
    return crcengine.new("crc16-autosar")
Ejemplo n.º 10
0
def test_crc8():
    crc8 = crcengine.new("crc8")
    assert crc8(b"123456789") == 0xBC
Ejemplo n.º 11
0
def crc16_xmodem():
    return crcengine.new("crc16-xmodem")
Ejemplo n.º 12
0
def crc16_kermit():
    return crcengine.new("crc16-kermit")
Ejemplo n.º 13
0
def crc32():
    return crcengine.new("crc32")
Ejemplo n.º 14
0
def crc16_autosar():
    return crcengine.new('crc16-autosar')
Ejemplo n.º 15
0
def test_crc8_bluetooth():
    crc8 = crcengine.new("crc8-bluetooth")
    assert crc8(b"123456789") == 0x26
Ejemplo n.º 16
0
def test_crc8():
    crc8 = crcengine.new('crc8')
    assert crc8(b'123456789') == 0xbc
Ejemplo n.º 17
0
import crcengine

if __name__ == '__main__':
    params = crcengine.get_algorithm_params('crc32')
    crcengine.generate_code(params, 'out/')
    crcengine.generate_code('crc16-xmodem', 'out/')
    filename = "out/crc16_xmodem.c"
    print("Created {} with the following content:")
    with open(filename, "r") as f:
        file = f.read()
        print(file)
    available = crcengine.algorithms_available()
    print("\nThe following algorithms are available")
    print(", ".join(available))

    data = b"123456789"
    crc16x = crcengine.new("crc16-xmodem")
    result = crc16x.calculate(data)
    print("\nThe crc16-xmodem of {} is 0x{:x}".format(data.decode("ascii"),
                                                      result))
Ejemplo n.º 18
0
def test_crc8_bluetooth():
    crc8 = crcengine.new('crc8-bluetooth')
    assert crc8(b'123456789') == 0x26
Ejemplo n.º 19
0
def test_crc32_bzip2():
    crc32_bzip2 = crcengine.new("crc32-bzip2")
    assert crc32_bzip2(b"A") == 0x81B02D8B
    assert crc32_bzip2(b"123456789") == 0xFC891918