The reliability of the CRC16

 3r31415. 3r3-31. Not so long ago, on duty, I ran into a rather interesting problem.
 3r31415.
 3r31415. We have a device that performs intensive exchange on the internal RS485 bus, the number of packets passing is of the order of several thousand per second, each packet has a length of 7 bytes, two of which are designed to store the CRC16 checksum in its CMS version (polynomial = 0x8005 starting value = 0xFFFF). Reception is carried out in the FIFO-buffer, which is shifted upward with the displacement after receiving each subsequent byte. An indicator of the receipt of a real packet is the fact that its checksum coincides with the value transmitted in the packet itself. No headers or additional parameters.
 3r31415.
 3r31415. The problem was the following - periodically, approximately once every 5 minutes, during data transmission, a packet was skipped, the data of which gave a burst of data for one of the channels, and most often the burst occurred to the same value. At first we looked in the direction of physical collisions, but the case turned out to be different - from time to time the buffer where the data was collected appeared to be a packet consisting of the end of the previous packet and the beginning of the next, and the checksum of such a combined packet turned out to be correct. That is, there is a checksum collision: the packet does not make sense, but gives the correct checksum.
 3r31415.
 3r31415. Naturally, the error was already at the system design level, since the packets did not have any headers, the introduction of an additional byte header reduced the number of errors to an undetectable level, but this seemed to me a little. I decided to check how different types of 16-bit checksums differ from each other in real conditions. Actually, this article.
 3r31415.
 3r31415. For comparison, I chose several of the most commonly used 16-bit checksums with different polynomials, starting values, and a bit arrival mechanism. The amounts I selected are summarized in the following table: 3r3-31403.  3r31415. 3r33873.  3r31415. 3r33985.  3r31415. 3r3993. 3r3888. Designation 3r3-31011. 3r3994.  3r31415. 3r3993. 3r3888. Polynomial [/b] 3r3994.  3r31415. 3r3993. 3r3888. Init [/b] 3r3994.  3r31415. 3r3993. 3r3888. RefIn [/b] 3r3994.  3r31415. 3r3993. 3r3888. RefOut [/b] 3r3994.  3r31415. 3r3993. 3r3888. XorOut [/b] 3r3994.  3r31415. 3r3996.  3r31415. 3r33985.  3r31415. 3r3993. CMS 3r3994.  3r31415. 3r3993. 0x8005 3r3994.  3r31415. 3r3993. 0xFFFF
 3r31415. 3r3993. false
 3r31415. 3r3993. false
 3r31415. 3r3993. 0x0000 3r3994.  3r31415. 3r3996.  3r31415. 3r33985.  3r31415. 3r3993. CCITT 3r3994.  3r31415. 3r3993. 0x1021 3r3994.  3r31415. 3r3993. 0xFFFF
 3r31415. 3r3993. false
 3r31415. 3r3993. false
 3r31415. 3r3993. 0x0000 3r3994.  3r31415. 3r3996.  3r31415. 3r33985.  3r31415. 3r3993. AUG-CCITT
 3r31415. 3r3993. 0x1021 3r3994.  3r31415. 3r3993. 0x1D0F
 3r31415. 3r3993. false
 3r31415. 3r3993. false
 3r31415. 3r3993. 0x0000 3r3994.  3r31415. 3r3996.  3r31415. 3r33985.  3r31415. 3r3993. BYPASS 3r3994.  3r31415. 3r3993. 0x8005 3r3994.  3r31415. 3r3993. 0x0000 3r3994.  3r31415. 3r3993. false
 3r31415. 3r3993. false
 3r31415. 3r3993. 0x0000 3r3994.  3r31415. 3r3996.  3r31415. 3r33985.  3r31415. 3r3993. CDMA2000 3r3994.  3r31415. 3r3993. 0xC867 3r3994.  3r31415. 3r3993. 0xFFFF
 3r31415. 3r3993. false
 3r31415. 3r3993. false
 3r31415. 3r3993. 0x0000 3r3994.  3r31415. 3r3996.  3r31415. 3r33985.  3r31415. 3r3993. DDS-110 3r3994.  3r31415. 3r3993. 0x8005 3r3994.  3r31415. 3r3993. 0x800D
 3r31415. 3r3993. false
 3r31415. 3r3993. false
 3r31415. 3r3993. 0x0000 3r3994.  3r31415. 3r3996.  3r31415. 3r33985.  3r31415. 3r3993. DECT-X 3r3994.  3r31415. 3r3993. 0x0589
 3r31415. 3r3993. 0x0000 3r3994.  3r31415. 3r3993. false
 3r31415. 3r3993. false
 3r31415. 3r3993. 0x0000 3r3994.  3r31415. 3r3996.  3r31415. 3r33985.  3r31415. 3r3993. EN-13757 3r3994.  3r31415. 3r3993. 0x3D65 3r3994.  3r31415. 3r3993. 0x0000 3r3994.  3r31415. 3r3993. false
 3r31415. 3r3993. false
 3r31415. 3r3993. 0xFFFF
 3r31415. 3r3996.  3r31415. 3r33985.  3r31415. 3r3993. Modbus 3r3994.  3r31415. 3r3993. 0x8005 3r3994.  3r31415. 3r3993. 0xFFFF
 3r31415. 3r3993. true
 3r31415. 3r3993. true
 3r31415. 3r3993. 0x0000 3r3994.  3r31415. 3r3996.  3r31415. 3r33985.  3r31415. 3r3993. T10-DIF
 3r31415. 3r3993. 0x8BB7
 3r31415. 3r3993. 0x0000 3r3994.  3r31415. 3r3993. false
 3r31415. 3r3993. false
 3r31415. 3r3993. 0x0000 3r3994.  3r31415. 3r3996.  3r31415. 3r33985.  3r31415. 3r3993. TELEDISK 3r3994.  3r31415. 3r3993. 0xA097 3r3994.  3r31415. 3r3993. 0x0000 3r3994.  3r31415. 3r3993. false
 3r31415. 3r3993. false
 3r31415. 3r3993. 0x0000 3r3994.  3r31415. 3r3996.  3r31415. 3r33985.  3r31415. 3r3993. XMODEM
 3r31415. 3r3993. 0x1021 3r3994.  3r31415. 3r3993. 0x0000 3r3994.  3r31415. 3r3993. false
 3r31415. 3r3993. false
 3r31415. 3r3993. 0x0000 3r3994.  3r31415. 3r3996.  3r31415. 3r3998.
 3r31415. In this case:
 3r31415.
 3r31415. 3r33333.  3r31415. 3r33386. RefIn - the order in which bits are received from the data buffer: false - starting from the most significant bit (MSB first), true - LSB first; 3r33333.  3r31415. 3r33386. RefOut - flag to invert the order of bits on the output: true - to invert. 3r33333.  3r31415. 3r3333391.
 3r31415. When emulating packet damage, I implemented the following models:
 3r31415.
 3r31415. 3r33333.  3r31415. 3r33386. 3r3888. Shuffle: [/b] filling a random number of bytes in the packet with random values ​​
 3r31415. 3r33386. 3r3888. Bit shift: [/b] shift random bytes in packet left
 3r31415. 3r33386. 3r3888. Roll packet: 3r3011011. ring shift bytes in packet left
 3r31415. 3r33386. 3r3888. Right shift: [/b] packet shift to the right by one byte, 0xFF is added to the left (transmission goes via UART) 3r-3389.  3r31415. 3r33386. 3r3888. Left shift: [/b] packet shift to the left by one byte, 0xFF is added to the right
 3r31415. 3r33386. 3r3888. Fill zeros: [/b] filling a random number of bytes in a packet with 0x00 bytes (all zeros) 3r3333389.  3r31415. 3r33386. 3r3888. Fill ones: [/b] filling a random number of bytes in a packet with 0xFF bytes (all units) 3r-3333.  3r31415. 3r33386. 3r3888. Byte injection: [/b] inserting a random byte in a packet in a random place, the bytes behind the inserted one shift in the direction of the tail 3r3333389.  3r31415. 3r33386. 3r3888. Single bit: [/b] damage to a single random bit
 3r31415. 3r3333391.
 3r31415. Then the program generated 10?00?000 packages randomly, each of them carried out the above operations, after which the checksums of the original and upgraded packages were compared. Packages that did not change during conversion were discarded. If the checksum matches, an error has been logged.
 3r31415.
 3r31415. As a result, the following table was obtained with the number of errors: 3r3-31403.  3r31415. 3r33873.  3r31415. 3r33985.  3r31415. 3r3993. 3r3888. Designation 3r3-31011. 3r3994.  3r31415. 3r3993. 3r3888. Shuffle [/b] 3r3994.  3r31415. 3r3993. 3r3888. Bit shift [/b] 3r3994.  3r31415. 3r3993. 3r3888. Roll packet [/b] 3r3994.  3r31415. 3r3993. 3r3888. Right shift [/b] 3r3994.  3r31415. 3r3993. 3r3888. Left shift [/b] 3r3994.  3r31415. 3r3993. 3r3888. Fill zeros [/b] 3r3994.  3r31415. 3r3993. 3r3888. Fill ones [/b] 3r3994.  3r31415. 3r3993. 3r3888. Byte injection [/b] 3r3994.  3r31415. 3r3993. 3r3888. Sum [/b] 3r3994.  3r31415. 3r3996.  3r31415. 3r33985.  3r31415. 3r3993. CMS 3r3994.  3r31415. 3r3993. 5101 3r3994.  3r31415. 3r3993. 3874 3r3994.  3r31415. 3r3993. 2937 3r3994.  3r31415. 3r3993. 1439 3r3994.  3r31415. 3r3993. 1688 3r3994.  3r31415. 3r3993. 3970 3r3994.  3r31415. 3r3993. 4010 3r3994.  3r31415. 3r3993. 1080
 3r31415. 3r3993. 24099 3r3994.  3r31415. 3r3996.  3r31415. 3r33985.  3r31415. 3r3993. CCITT 3r3994.  3r31415. 3r3993. 2012 3r3994.  3r31415. 3r3993. 1127 3r3994.  3r31415. 3r3993. 3320 3r3994.  3r31415. 3r3993. 1494 3r3994.  3r31415. 3r3993. 1486 3r3994.  3r31415. 3r3993. 1063 3r3994.  3r31415. 3r3993. 1096 3r3994.  3r31415. 3r3993. 1130 3r3994.  3r31415. 3r3993. 12728 3r3994.  3r31415. 3r3996.  3r31415. 3r33985.  3r31415. 3r3993. AUG-CCITT
 3r31415. 3r3993. 2012 3r3994.  3r31415. 3r3993. 1127 3r3994.  3r31415. 3r3993. 3320 3r3994.  3r31415. 3r3993. 1494 3r3994.  3r31415. 3r3993. 1486 3r3994.  3r31415. 3r3993. 1063 3r3994.  3r31415. 3r3993. 1096 3r3994.  3r31415. 3r3993. 1130 3r3994.  3r31415. 3r3993. 12728 3r3994.  3r31415. 3r3996.  3r31415. 3r33985.  3r31415. 3r3993. BYPASS 3r3994.  3r31415. 3r3993. 5101 3r3994.  3r31415. 3r3993. 3874 3r3994.  3r31415. 3r3993. 2937 3r3994.  3r31415. 3r3993. 1439 3r3994.  3r31415. 3r3993. 1688 3r3994.  3r31415. 3r3993. 3970 3r3994.  3r31415. 3r3993. 4010 3r3994.  3r31415. 3r3993. 1080
 3r31415. 3r3993. 24099 3r3994.  3r31415. 3r3996.  3r31415. 3r33985.  3r31415. 3r3993. CDMA2000 3r3994.  3r31415. 3r3993. 1368 3r3994.  3r31415. 3r3993. 1025 3r3994.  3r31415. 3r3993. 1946 3r3994.  3r31415. 3r3993. 1462 3r3994.  3r31415. 3r3993. 1678 3r3994.  3r31415. 3r3993. 1043 3r3994.  3r31415. 3r3993. 1028 3r3994.  3r31415. 3r3993. 1112 3r3994.  3r31415. 3r3993. 10662 3r3994.  3r31415. 3r3996.  3r31415. 3r33985.  3r31415. 3r3993. DDS-110 3r3994.  3r31415. 3r3993. 5101 3r3994.  3r31415. 3r3993. 3874 3r3994.  3r31415. 3r3993. 2937 3r3994.  3r31415. 3r3993. 1439 3r3994.  3r31415. 3r3993. 1688 3r3994.  3r31415. 3r3993. 3970 3r3994.  3r31415. 3r3993. 4010 3r3994.  3r31415. 3r3993. 1080
 3r31415. 3r3993. 24099 3r3994.  3r31415. 3r3996.  3r31415. 3r33985.  3r31415. 3r3993. DECT-X 3r3994.  3r31415. 3r3993. 1432 3r3994.  3r31415. 3r3993. 1189 3r3994.  3r31415. 3r3993. 5915 3r3994.  3r31415. 3r3993. 1779 3r3994.  3r31415. 3r3993. 1580 3r3994.  3r31415. 3r3993. 1215 3r3994.  3r31415. 3r3993. 1209 3r3994.  3r31415. 3r3993. 1093 3r3994.  3r31415. 3r3993. 15412 3r3994.  3r31415. 3r3996.  3r31415. 3r33985.  3r31415. 3r3993. EN-13757 3r3994.  3r31415. 3r3993. 1281 3r3994.  3r31415. 3r3993. 2209 3r3994.  3r31415. 3r3993. 3043 3r3994.  3r31415. 3r3993. 1520 3r3994.  3r31415. 3r3993. 1528 3r3994.  3r31415. 3r3993. 2193 3r3994.  3r31415. 3r3993. 2187 3r3994.  3r31415. 3r3993. 1039 3r3994.  3r31415. 3r3993. 15000 3r3994.  3r31415. 3r3996.  3r31415. 3r33985.  3r31415. 3r3993. Modbus 3r3994.  3r31415. 3r3993. 5090 3r3994.  3r31415. 3r3993. 3888 3r3994.  3r31415. 3r3993. 3086 3r3994.  3r31415. 3r3993. 1282 3r3994.  3r31415. 3r3993. 1582 3r3994.  3r31415. 3r3993. 3947 3r3994.  3r31415. 3r3993. 3897 3r3994.  3r31415. 3r3993. 1073 3r3994.  3r31415. 3r3993. 23845 3r3994.  3r31415. 3r3996.  3r31415. 3r33985.  3r31415. 3r3993. T10-DIF
 3r31415. 3r3993. 1390 3r3994.  3r31415. 3r3993. 922 3r3994.  3r31415. 3r3993. 1424 3r3994.  3r31415. 3r3993. 1421 3r3994.  3r31415. 3r3993. 1630 3r3994.  3r31415. 3r3993. 994 3r3994.  3r31415. 3r3993. 938 3r3994.  3r31415. 3r3993. 1093 3r3994.  3r31415. 3r3993. 9812 3r3994.  3r31415. 3r3996.  3r31415. 3r33985.  3r31415. 3r3993. TELEDISK 3r3994.  3r31415. 3r3993. 1394 3r3994.  3r31415. 3r3993. 1049 3r3994.  3r31415. 3r3993. 5398 3r3994.  3r31415. 3r3993. 1451 3r3994.  3r31415. 3r3993. 1512 3r3994.  3r31415. 3r3993. 1096 3r3994.  3r31415. 3r3993. 1066 3r3994.  3r31415. 3r3993. 1065 3r3994.  3r31415. 3r3993. 14031 3r3994.  3r31415. 3r3996.  3r31415. 3r33985.  3r31415. 3r3993. XMODEM
 3r31415. 3r3993. 2012 3r3994.  3r31415. 3r3993. 1127 3r3994.  3r31415. 3r3993. 3320 3r3994.  3r31415. 3r3993. 1494 3r3994.  3r31415. 3r3993. 1486 3r3994.  3r31415. 3r3993. 1063 3r3994.  3r31415. 3r3993. 1096 3r3994.  3r31415. 3r3993. 1130 3r3994.  3r31415. 3r3993. 12728 3r3994.  3r31415. 3r3996.  3r31415. 3r3998.
 3r31415. Obviously, the starting value of the algorithm does not affect the result, which is logical, the starting value gives us only a different value of the checksum, but the calculation mechanism itself does not change. Therefore, I excluded these checksums from further consideration. Similarly, it does not make sense to consider errors in single bits, all checksums coped with this without error, which, in fact, was required of them during creation.
 3r31415.
 3r31415. Well, the final table of the quality of the checksum, without taking into account duplicate algorithms: 3r3-31403.  3r31415. 3r33873.  3r31415. 3r33985.  3r31415. 3r3993. 3r3888. Designation 3r3-31011. 3r3994.  3r31415. 3r3993. 3r3888. Number of collisions [/b] 3r3994.  3r31415. 3r3993. 3r3888. Place [/b] 3r3994.  3r31415. 3r3996.  3r31415. 3r33985.  3r31415. 3r3993. CMS 3r3994.  3r31415. 3r3993. 24099 3r3994.  3r31415. 3r3993. 8 3r3994.  3r31415. 3r3996.  3r31415. 3r33985.  3r31415. 3r3993. CCITT 3r3994.  3r31415. 3r3993. 12728 3r3994.  3r31415. 3r3993. 3 3r3994.  3r31415. 3r3996.  3r31415. 3r33985.  3r31415. 3r3993. CDMA2000 3r3994.  3r31415. 3r3993. 10662 3r3994.  3r31415. 3r3993. 2 3r3994.  3r31415. 3r3996.  3r31415. 3r33985.  3r31415. 3r3993. DECT-X 3r3994.  3r31415. 3r3993. 15412 3r3994.  3r31415. 3r3993. 6 3r3994.  3r31415. 3r3996.  3r31415. 3r33985.  3r31415. 3r3993. EN-13757 3r3994.  3r31415. 3r3993. 15000 3r3994.  3r31415. 3r3993. 5 3r3994.  3r31415. 3r3996.  3r31415. 3r33985.  3r31415. 3r3993. Modbus 3r3994.  3r31415. 3r3993. 23845 3r3994.  3r31415. 3r3993. 7 3r3994.  3r31415. 3r3996.  3r31415. 3r33985.  3r31415. 3r3993. T10-DIF
 3r31415. 3r3993. 9812 3r3994.  3r31415. 3r3993. 1 3r3994.  3r31415. 3r3996.  3r31415. 3r33985.  3r31415. 3r3993. TELEDISK 3r3994.  3r31415. 3r3993. 14031 3r3994.  3r31415. 3r3993. 4 3r3994.  3r31415. 3r3996.  3r31415. 3r3998.
 3r31415. The rest of the conclusions leave readers. From myself, I note only that the number of units in the checksum polynom has a certain influence on the results. But this is just my personal subjective opinion. I would be glad to hear other explanations.
 3r31415.
 3r31415. The source code of the program is given below.
 3r31415.
 3r31415.
Source code 3r3-31011.
#include
3r31415. #include
3r31415. #include
3r31415. #include
3r31415. #include
3r31415. #include
3r31415. 3r31415. #define PACKET_LEN (7)
#define NUM_OF_CYCLES (100000) 3r3141415. 3r31415. static unsigned char reverse_table[16]= 3r31415. {3r31415. 0x? 0x? 0x? 0xC, 0x? 0xA, 0x? 0xE,
0x? 0x? 0x? 0xD, 0x? 0xB, 0x? 0xF
}; 3r31415. 3r31415. uint8_t reverse_bits (uint8_t byte)
{3r31415. //Reverse the top and bottom nibble then swap them. 3r31415. return (reverse_table[byte & 0b1111]4) | reverse_table[byte 4]; 3r31415.} 3r31415. 3r31415. uint16_t reverse_word (uint16_t word)
{3r31415. return ((reverse_bits (word & 0xFF) 8) | reverse_bits (word 8)); 3r31415.} 3r31415. 3r31415. uint16_t crc16_common (uint8_t * data, uint8_t len, uint16_t poly, uint16_t init,
uint16_t doXor, bool refIn, bool refOut)
{3r31415. uint8_t y; 3r31415. uint16_t crc; 3r31415. 3r31415. crc = init; 3r31415. while (len--)
{3r31415. if (refIn) 3r31415. crc = ((uint16_t) reverse_bits (* data ++) 8) ^ crc; 3r31415. else
crc = ((uint16_t) * data ++ 8) ^ crc; 3r31415. for (y = 0; y < 8; y++)
{
if (crc & 0x8000)
crc = (crc 1) ^ poly;
else
crc = crc 1;
3) (refOut) 3r31415. crc = reverse_word (crc); 3r31415. return ({{. 3 ^ ^ ^ ^ ^)));; r 14); 0x102? 0xFFFF, 0x000? false, false); 3r31415.} 3r31414. 3r31415. Uint16_t crc16_bypass (uint8_t * data, uint8_t len) 3r?31515. {3r31415. ;
}
Uint16_t crc16_xmodem (uint8_t * data, uint8_t len) 3n3r31415. {
Return; (uint8_t * data, uint8_t len)
{
return crc16_common (data, len, 0xA 09? 0x000? 0x000? false, false); 3r31415.} 3r31415. 3r31415. uint16_t crc16_augccitt (uint8_t * data, uint8_t len)
{3r31415. return crc16_common (data, len, 0x102? 0x1d0f, 0x000? false, false); 3r31415.} 3r31415. 3r31415. uint16_t crc16_cdma2000 (uint8_t * data, uint8_t len) 3r31415. {3r31415. return crc16_common (data, len, 0xc86? 0xffff, 0x000? false, false); 3r31415.} 3r31415. 3r31415. uint16_t crc16_dds110 (uint8_t * data, uint8_t len) 3r31415. {3r31415. return crc16_common (data, len, 0x800? 0x800d, 0x000? false, false); 3r31415.} 3r31415. 3r31415. uint16_t crc16_dect (uint8_t * data, uint8_t len) 3r31415. {3r31415. return crc16_common (data, len, 0x058? 0x000? 0x000? false, false); 3r31415.} 3r31415. 3r31415. uint16_t crc16_en13757 (uint8_t * data, uint8_t len) 3r31415. {3r31415. return crc16_common (data, len, 0x3d6? 0x000? 0xffff, false, false); 3r31415.} 3r31415. 3r31415. uint16_t crc16_t10dif (uint8_t * data, uint8_t len) 3r31415. {3r31415. return crc16_common (data, len, 0x8bb? 0x000? 0x000? false, false); 3r31415.} 3r31415. 3r31415. uint16_t crc16_cms (uint8_t * data, uint8_t len) 3r31415. {3r31415. return crc16_common (data, len, 0x800? 0xFFFF, 0x000? false, false); 3r31415.} 3r31415. 3r31415. uint16_t crc16_modbus (uint8_t * data, uint8_t len) 3r31415. {3r31415. return crc16_common (data, len, 0x800? 0xFFFF, 0x000? true, true); 3r31415.} 3r31415. 3r31415. bool compare_buf (uint8_t * buf? uint8_t * buf2)
{3r31415. uint8_t x; 3r31415. 3r31415. for (x = 0; x < PACKET_LEN; x++)
{
if (buf1[x]5.! = buf2[x]) affection affection: aracans, aracans, aracans, aracans, aracans, etc. {
For (j = 0; j < 10; j++)
{
Rnd = (uint16_t) rand (); 3r3r151415. If (rnd% 7 == 0)
Buf[i]^ = (1 (rnd% 8)) ;
}
}
return compare_buf (buf, copy);
}
bool method_bitshift (uint8_t * buf)
{
uint8_t x, i, j;.
uint8_t copy[PACKET_LEN].3r31415. 3r31415. Memcpy (copy, buf, PACKET_LEN); 3r31415. 3r31415. X = (uint8_t) (rand ()% PACKET_LEN) + 1;
five. for (j = 0; j < x; j++)
{
i = (uint8_t) (rand ()% PACKET_LEN); 3r3141415. if (buf[i]== 0)
buf[i]= 0x01;[PACKET_LEN]? i.e. ; 3r31415. Uint8_t copy[PACKET_LEN]; 3r31415.
Memcpy (copy, buf, PACKET_LEN);
X = (uint8_t) (rand ()% (PACKET_LIsAr 314155. X = (uint8_t) (rand () (PACKET_L) = 3) 3 = 3141415. 0; j3r31265. {3r31415. Temp = buf[0]; 3r31415. For (i = 0; i 3r31230. Buf[i]= Buf[byte 4]w. (buf, copy); 3r31415.} 3r31415. 3r31415. bool method_shiftright (uint8_t * buf) 3r31415. {3r31415. uint8_t i; 3r31415. uint8_t co py[PACKET_LEN]; 3r31415.
memcpy (copy, buf, PACKET_LEN); 3r31415. 3r31415. for (i = 0; i < PACKET_LEN - 1; i++)
buf[i + 1]= buf[i];
buf[0]= 0xff;.
return compare_buf (buf, copy);
}
bool method_shiftleft (uint8_t * buf. ) 3r31415. {3r31415. Uint8_t i; 3r31415. Uint8_t copy[PACKET_LEN]; 3r???r31415. 3r31415. Buf[PACKET_LEN - 1]= 0xff; 3r31415. 3r31415. Return compare_buf (buf, copy); 3r31415.[PACKET_LEN]; 3r314153; 3r31415. memcpy (copy, buf, PACKET_LEN); 3r31415. 3-331415. x = (uint8_t) (rand ()%) PACKET_LEN + 1; 3; 3 (3) 31415. = (uint8_t) (rand ()% PACKET_LEN); 3r3r15415. if (buf[i]! = 0x00)
buf[i]= 0x00;
else
buf[i]= 0xFF; 3r31415.} 3r31415. 3r31415. return compare_buf (buf, copy); 3r31415.} 3r31415. 3r31415. bool method_one (uint8_t * buf)
{3r31415. uint8_t x, i, j; 3r31415. uint8_t copy[PACKET_LEN]; 3r31415. 3r31415. memcpy (copy, buf, PACKET_LEN); 3r31415. 3r31415. x = (uint8_t) (rand ()% PACKET_LEN) + 1; 3r31415. for (j = 0; j < x; j++)
{
i = (uint8_t) (rand ()% PACKET_LEN); 3r31415. if (buf[i]! = 0xFF) 3r3r151415. buf[i]= 0kkft4kFF, 2x2x2) 3x31415. w2w2d3d3d3d3d3d3d3d3d3d3d3d3dr3d3dr3dr3dr3dr3dr3dr3dr3dr3dr3dr3dr3dr3dr3dr3dr3dr3dr3dr3dr3dr3dr3dr3dr3rr3dr3dr3dr3rr3dr3dr3dr3dr3dr3dr3dr3dr3dr3dr3dr3dr3rrrrrrr ” ; 3r31415. 3r31415. Memcpy (copy, buf, PACKET_LEN); 3r31415. 3r31415. X = (uint8_t) (rand ()% PACKET_LEN); 3r31415. For (i = = PACKET_LEN - 1), and i), and i), and i), and i will be the same, i will be the same, i will be the same i, and i). Managers {
Buf[i]= Buf[i - 1]; 3r31415.} 3r31415. Buf[x]= (Uint8_t) rand (); 3r3r151415. ? 3r31415. uint8_t * buf)
{
uint8_t x;
x = (uint8_t) (rand ()% (PACKET_LEN * 8));
buf w2w2623. ^ = (8) (x% 8)); 3r31415. 3r31415. return true; 3r31415.} 3r31415. 3r31415. typedef struct 3r31415. {3r31415. uint16_t crc1; 3r31415. uint16_t crc2; 3r31415. uint32_t errors; 3r31415. uint16_t (* fn) (uint8_t * data, uint8_t len); 3r31415. char name[32]; 3r31415.} tCRC; 3r31415. 3r31415. typedef struct 3r31415. {3r31415. bool (* fn) (uint8_t * buf); 3r31415. char name[32]; 3r31415.} tMethod; 3r31415. 3r31415. static tMethod methods[]= 3r31415. {3r31415. {method_shuffle, "Shuffle"}, 3r31415. {method_bitshift, "Bit shift"},
{method_packetroll, "Roll packet"},
{method_shiftright, "Right shift"},
{method_shiftleft, "Left shift"},
{method_zero, "Fill zeros"},
{method_one, "Fill ones"}, 3r31415. {method_injection, "Byte injection"}, 3r31415. {method_single, "Single bit"}
}; 3r31415. 3r31415. static tCRC crcs[]= 3r31415. {3r31415. {? ? ? crc16_cms, "CMS"},
{? ? ? crc16_ccitt, "CCITT"}, 3r31414. {? ? ? crc16_augccitt, "AUG-CCITT"},
{? ? ? crc16_bypass, "BYPASS"},
{? ? ? crc16_cdma200? "CDMA2000"}, 3r31415. {? ? ? crc16_dds11? "DDS-110"}, 3r31414. {? ? ? crc16_dect, "DECT-X"},
{? ? ? crc16_en1375? "EN-13757"},
{? ? ? crc16_modbus, "Modbus"}, 3r3141415. {? ? ? crc16_t10dif, "T10-DIF"},
{? ? ? crc16_teledisk, "TELEDISK"},
{? ? ? crc16_xmodem, "XMODEM"}
}; 3r31415. 3r31415. int main (int argc, char * argv[])
{3r31415. uint32_t num_of_cycle; 3r31415. uint32_t num_of_sums; 3r31415. uint8_t packet[PACKET_LEN]; 3r31415. uint8_t i; 3r31415. uint8_t m; 3r31415. //uint8_t buf[8]= {0x1? 0x1? 0x1? 0x1? 0x1? 0x1? 0x1? 0x17}; 3r31415. 3r31415. srand (time (NULL)); 3r31415. 3r31415. printf ("------------------------- CRC16 comparison -------------------- ----- n "); 3r31415. 3r31415. num_of_sums = sizeof (crcs) /sizeof (tCRC); 3r31415. for (m = 0; m3r31362. {
printf ("r% s: n", methods[m].name); 3r31415. 3r3r151415. for i = 0; i 3r31391. {
crcs w2w2w6. 1?115. cr (w = 3 = 0;
}
For (num_of_cycle = 0; num_of_cycle < NUM_OF_CYCLES; num_of_cycle++)
{
For (i = 0; i 3r31372. Packet[i]= (Uint8_t) rand); 3333333333333333723. i 3r31391. crcs[i].crc1 = crcs[i].n (3 packet) i < num_of_sums; i++)
{
crcs[i]rc2 = crcs[i].fn (packet, PACKET_LEN); 3r31415.}
If (num_of_cycle% 1000 == 0)
Printf ("r% .2f %%", (float) num_of_cycle /NUM_OF_CYCLES * 100); 3r3r???.} 3r31415. 3r31415. for (i = 0; i < num_of_sums; i++)
printf ("r% 20s:% 10dn", crcs[i].name, crcs[i].errors); 3r3141415.} 3r31415. 3r3141515 return); 3r31415. 3r31415.
3r3-331403.  3r31415. 3r31411. 3r31411.
 3r31415. As a result, in the next version of the product for the internal bus, the CCITT checksum was chosen, mostly because its implementation was available in the hardware of the microcontroller used. 3r31411. 3r31415. 3r31415.
3r31415. 3r31411. 3r31415. 3r31415. 3r31415. 3r31415.
+ 0 -

Add comment