def test_hw_crc16_calculate_msb_xor(self): data = 0x0D00C0F0FFFFFF dataSize = 56 poly = 0x1D xorOut = 0x8F bytes_list = convert_to_msb_list(data, dataSize / 8) calc_crc = hw_crc16_calculate(bytes_list, poly, 0x00, xorOut) self.assertEqual(calc_crc, 52960)
def test_hw_crc16_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_crc16_calculate(bytes_list, poly, 0x00, 0x00) calc_crc = reverse_number(calc_crc, 8) self.assertEqual(calc_crc, 189) ## 80
def test_hw_crc16_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_crc16_calculate(bytes_list, poly, 0x00, 0x00) calc_crc = reverse_number(calc_crc, 8) self.assertEqual(calc_crc, 21)
def test_hw_crc16_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_crc16_calculate(bytes_list, poly, 0x00, xorOut) self.assertEqual(calc_crc, 52847)
def test_hw_crc16_calculate_param_reflect(self): data = 0x030201 dataSize = 24 poly = 0x1BF msb_bytes_list = convert_to_msb_list(data, dataSize / 8) param_crc = hw_crc16_calculate_param(msb_bytes_list, poly, 0x00, 0x00, False, True) self.assertEqual(param_crc, 12084) ## check relation reflect_bits_list(msb_bytes_list) calc_crc = hw_crc16_calculate(msb_bytes_list, poly, 0x00, 0x00) self.assertEqual(param_crc, calc_crc)
def test_hw_crc16_calculate_param_reverse(self): data = 0x030201 dataSize = 24 poly = 0x1BF msb_bytes_list = convert_to_msb_list(data, dataSize / 8) param_crc = hw_crc16_calculate_param(msb_bytes_list, poly, 0x00, 0x00, True, False) self.assertEqual(param_crc, 15082) ## check relation msb_bytes_list.reverse() calc_crc = hw_crc16_calculate(msb_bytes_list, poly, 0x00, 0x00) self.assertEqual(param_crc, calc_crc)
def test_hw_crc16_calculate(self): bytes_list = [0xFF, 0xFF, 0xFF, 0xFF] crc = hw_crc16_calculate(bytes_list, 0xFF, 0x00, 0x00) self.assertEqual(crc, 3915)