VK1ET: Shorten CRC calculation

We don't need to include the CRC itself one bit at a time. This shortens
the loop count by 24 iterations, so should be much faster
This commit is contained in:
Malcolm Robb 2013-05-21 12:54:34 +01:00
parent f33a7090b0
commit 640d63a0d1

View file

@ -1115,16 +1115,19 @@ uint32_t modesChecksum(unsigned char *msg, int bits) {
uint32_t * pCRCTable = &modes_checksum_table[offset]; uint32_t * pCRCTable = &modes_checksum_table[offset];
int j; int j;
// We don't really need to include the checksum itself
bits -= 24;
for(j = 0; j < bits; j++) { for(j = 0; j < bits; j++) {
if ((j & 7) == 0) if ((j & 7) == 0)
{theByte = *msg++; rem = (rem << 8) | theByte;} theByte = *msg++;
// If bit is set, xor with corresponding table entry. // If bit is set, xor with corresponding table entry.
if (theByte & 0x80) {crc ^= *pCRCTable;} if (theByte & 0x80) {crc ^= *pCRCTable;}
pCRCTable++; pCRCTable++;
theByte = theByte << 1; theByte = theByte << 1;
} }
return ((crc ^ rem) & 0x00FFFFFF); // 24 bit checksum. rem = (msg[0] << 16) | (msg[1] << 8) | msg[2]; // message checksum
return ((crc ^ rem) & 0x00FFFFFF); // 24 bit checksum syndrome.
} }
// //
// Given the Downlink Format (DF) of the message, return the message length in bits. // Given the Downlink Format (DF) of the message, return the message length in bits.