예제 #1
0
        def test_hw_crc8_calculate_msb_xor(self):
            data = 0x0D00C0F0FFFFFF
            dataSize = 56
            poly = 0x1D
            xorOut = 0x8F

            bytes_list = convert_to_msb_list(data, dataSize / 8)
            calc_crc = hw_crc8_calculate(bytes_list, poly, 0x00, xorOut)

            self.assertEqual(calc_crc, 0x90)
예제 #2
0
        def test_hw_crc8_calculate_3_reverse(self):
            data = 0x000300
            dataSize = 24
            poly = 0x1BF

            poly = reverse_number(poly, 8)
            bytes_list = convert_to_lsb_list(data, dataSize / 8)
            calc_crc = hw_crc8_calculate(bytes_list, poly, 0x00, 0x00)
            calc_crc = reverse_number(calc_crc, 8)

            self.assertEqual(calc_crc, 0x50)  ## 80
예제 #3
0
        def test_hw_crc8_calculate_1_reverse(self):
            data = 0x12
            dataSize = 8
            poly = 0xBF

            poly = reverse_number(poly, 8)
            bytes_list = convert_to_lsb_list(data, dataSize / 8)
            calc_crc = hw_crc8_calculate(bytes_list, poly, 0x00, 0x00)
            calc_crc = reverse_number(calc_crc, 8)

            self.assertEqual(calc_crc, 0x3F)  ## 63
예제 #4
0
        def test_hw_crc8_calculate_msb(self):
            data = 0x0D00C0F0FFFFFF
            dataSize = 56
            poly = 0x1D
            xorOut = 0x00

            ## 0x0D -- 0b 0000 1101
            ## 0xB0 -- 0b 1011 0000
            bytes_list = convert_to_msb_list(data, dataSize / 8)
            self.assertEqual(bytes_list[0], 0x0D)

            calc_crc = hw_crc8_calculate(bytes_list, poly, 0x00, xorOut)

            self.assertEqual(calc_crc, 0x1F)
예제 #5
0
        def test_hw_crc8_calculate_param_reflect(self):
            data = 0x030201
            dataSize = 24
            poly = 0x1BF

            msb_bytes_list = convert_to_msb_list(data, dataSize / 8)
            param_crc = hw_crc8_calculate_param(msb_bytes_list, poly, 0x00,
                                                0x00, False, True)
            self.assertEqual(param_crc, 119)

            ## check relation
            reflect_bits_list(msb_bytes_list)
            calc_crc = hw_crc8_calculate(msb_bytes_list, poly, 0x00, 0x00)
            self.assertEqual(param_crc, calc_crc)
예제 #6
0
        def test_hw_crc8_calculate_param_reverse(self):
            data = 0x030201
            dataSize = 24
            poly = 0x1BF

            msb_bytes_list = convert_to_msb_list(data, dataSize / 8)
            param_crc = hw_crc8_calculate_param(msb_bytes_list, poly, 0x00,
                                                0x00, True, False)
            self.assertEqual(param_crc, 68)

            ## check relation
            msb_bytes_list.reverse()
            calc_crc = hw_crc8_calculate(msb_bytes_list, poly, 0x00, 0x00)
            self.assertEqual(param_crc, calc_crc)
예제 #7
0
 def test_hw_crc8_calculate(self):
     bytes_list = [0xFF, 0xFF, 0xFF, 0xFF]
     crc = hw_crc8_calculate(bytes_list, 0xFF, 0x00, 0x00)
     self.assertEqual(crc, 240)