Exemplo n.º 1
0
    def test_crcmod_c8d16_revB(self):
        data = NumberMask(0xE3F2, 16)
        inputPoly = NumberMask(0x1F0, 8)
        regInit = 0x0
        xorOut = 0x0
        reverse = True

        revInputPoly = inputPoly.reversed()
        revData = data.reorderedBytes()

        crc_func = crcmod.mkCrcFun(revInputPoly.masterData(),
                                   rev=reverse,
                                   initCrc=regInit,
                                   xorOut=xorOut)
        crcLib = crc_func(revData.toASCII())
        #         print "crc: {:X} {:X}".format( crc, crc2 )

        crcProc = DivisionCRC()
        crcProc.setReversed(reverse)
        crcProc.setXorOutValue(xorOut)
        crcProc.setRegisterInitValue(regInit)
        #         crcProc.setInitCRC( regInit )

        crc = crcProc.calculate3(data, inputPoly)

        #         print "values: {} poly:{:X} init:{:X} xorOut:{:08b} rev:{} crc:{:08b} crcmod:{:08b} crcxor:{:08b}".format( data, inputPoly, regInit, xorOut, reverse, crc, crcLib, crc^crcLib )
        self.assertEqual(crc, crcLib)
Exemplo n.º 2
0
    def test_crcmod_8darc(self):
        data = NumberMask(0x01, 8)
        inputPoly = NumberMask(0x139, 8)
        regInit = 0x0
        xorOut = 0x0

        crc_func = crcmod.predefined.mkCrcFun('crc-8-darc')
        crcLib = crc_func(data.toASCII())

        crcProc = ModCRC()
        crcProc.setReversed()
        crcProc.setRegisterInitValue(regInit)
        crcProc.setXorOutValue(xorOut)

        revData = data.reorderedBytes()

        crc = crcProc.calculate3(revData, inputPoly)

        #         print "crcx: {:b} {:b}".format( crc, crcLib )

        self.assertEqual(crc, crcLib)
Exemplo n.º 3
0
    def test_crcmod_8rev_symm(self):
        data = NumberMask(0xFF, 8)
        inputPoly = NumberMask(0x181, 8)  ## leave symmetric
        regInit = 0x0
        xorOut = 0x0

        crc_func = crcmod.mkCrcFun(inputPoly.masterData(),
                                   initCrc=regInit,
                                   rev=True,
                                   xorOut=xorOut)
        crcLib = crc_func(data.toASCII())

        crcProc = ModCRC()
        crcProc.setReversed()
        crcProc.setRegisterInitValue(regInit)
        crcProc.setXorOutValue(xorOut)

        revData = data.reorderedBytes()
        revPoly = inputPoly.reversed()

        crc = crcProc.calculate3(revData, revPoly)
        #         print "crcx: {:b} {:b}".format( crc, crcLib )
        self.assertEqual(crc, crcLib)
Exemplo n.º 4
0
 def test_reorderedBytes_partialBytes(self):
     data = NumberMask(0xABCDE, 20)
     reordered = data.reorderedBytes()
     self.assertEqual(reordered.dataSize, data.dataSize)
     self.assertEqual(reordered.dataNum, 0xEBC0A)
Exemplo n.º 5
0
 def test_reorderedBytes_fullBytes(self):
     data = NumberMask(0xABCDEF, 24)
     reordered = data.reorderedBytes()
     self.assertEqual(reordered.dataSize, data.dataSize)
     self.assertEqual(reordered.dataNum, 0xEFCDAB)