From 640d63a0d1472a3965f6f11dba70423dc5fb1f2b Mon Sep 17 00:00:00 2001 From: Malcolm Robb Date: Tue, 21 May 2013 12:54:34 +0100 Subject: [PATCH] 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 --- dump1090.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/dump1090.c b/dump1090.c index 9098987..55c5baf 100644 --- a/dump1090.c +++ b/dump1090.c @@ -1115,16 +1115,19 @@ uint32_t modesChecksum(unsigned char *msg, int bits) { uint32_t * pCRCTable = &modes_checksum_table[offset]; int j; + // We don't really need to include the checksum itself + bits -= 24; for(j = 0; j < bits; j++) { if ((j & 7) == 0) - {theByte = *msg++; rem = (rem << 8) | theByte;} + theByte = *msg++; // If bit is set, xor with corresponding table entry. if (theByte & 0x80) {crc ^= *pCRCTable;} pCRCTable++; 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.