[hamradio-commits] [dump1090] 190/389: VK1ET : Changes to fixBitErrors()
Matthew Ernisse
mernisse-guest at moszumanska.debian.org
Wed Nov 5 00:19:54 UTC 2014
This is an automated email from the git hooks/post-receive script.
mernisse-guest pushed a commit to branch master
in repository dump1090.
commit 542b94dedbc64a15154199d4dee58c2b4c5f595a
Author: Malcolm Robb <Support at ATTAvionics.com>
Date: Tue May 21 13:40:07 2013 +0100
VK1ET : Changes to fixBitErrors()
1) Reduce complexity of fixBitErrors()
2) Inline flipBits()
3) Remove validation checks that can never occur.
---
dump1090.c | 83 ++++++++++++++++++++++++++++----------------------------------
1 file changed, 37 insertions(+), 46 deletions(-)
diff --git a/dump1090.c b/dump1090.c
index 55dd8b3..887b15b 100644
--- a/dump1090.c
+++ b/dump1090.c
@@ -1328,10 +1328,10 @@ void modesInitErrorInfo() {
}
*/
}
-
-/* Flip a bit, but make sure that the DF field (first 5 bits)
- * is never changed
- */
+//
+// Flip a bit, but make sure that the DF field (first 5 bits)
+// is never changed
+/*
int flipBit(unsigned char *msg, int nbits, int bit) {
int bytepos, mask;
if ((bit < 0) || (bit >= nbits)) {
@@ -1345,50 +1345,41 @@ int flipBit(unsigned char *msg, int nbits, int bit) {
msg[bytepos] ^= mask;
return 1;
}
-
-/* Search syndrome in table and, if an entry is found, flip the necessary
- * bits. Make sure the indices fit into the array, and for 2-bit errors,
- * are different.
- * Return number of fixed bits.
- */
+*/
+// Search syndrome in table and, if an entry is found, flip the necessary
+// bits. Make sure the indices fit into the array, and for 2-bit errors,
+// are different.
+// Return number of fixed bits.
+//
int fixBitErrors(unsigned char *msg, int bits) {
- struct errorinfo *pei;
- struct errorinfo ei;
- int bitpos0, bitpos1, offset, res;
- ei.syndrome = modesChecksum(msg, bits);
- ei.pos0 = -1;
- ei.pos1 = -1;
- pei = bsearch(&ei, bitErrorTable, NERRORINFO,
- sizeof(struct errorinfo), cmpErrorInfo);
- if (pei == NULL) {
- /* Nothing found */
- return 0;
- }
- offset = MODES_LONG_MSG_BITS-bits;
- bitpos0 = pei->pos0;
- bitpos1 = pei->pos1;
- res = 0;
- if (bitpos1 >= 0) { /* two-bit error pattern */
- bitpos0 -= offset;
- bitpos1 -= offset;
- if ((bitpos0 < 0) || (bitpos0 >= bits) ||
- (bitpos1 < 0) || (bitpos1 >= bits)) {
- return res;
- }
- res +=flipBit(msg, bits, bitpos0);
- if (bitpos0 != bitpos1) {
- res += flipBit(msg, bits, bitpos1);
- return res;
- }
- return res;
- } else {
- bitpos0 -= offset;
- if ((bitpos0 < 0) || (bitpos0 >= bits)) {
- return res;
- }
- res += flipBit(msg, bits, bitpos0);
- return res;
+ struct errorinfo *pei;
+ struct errorinfo ei;
+ int bitpos0, bitpos1, offset, res;
+ ei.syndrome = modesChecksum(msg, bits);
+ ei.pos0 = -1;
+ ei.pos1 = -1;
+ pei = bsearch(&ei, bitErrorTable, NERRORINFO,
+ sizeof(struct errorinfo), cmpErrorInfo);
+ if (pei == NULL) {
+ return 0; // No syndrome found
+ }
+ res = 0;
+ offset = MODES_LONG_MSG_BITS-bits;
+ bitpos0 = pei->pos0 - offset;
+ if ((bitpos0 < 0) || (bitpos0 >= bits)) {
+ return 0;
+ }
+ msg[(bitpos0 >> 3)] ^= (1 << (7 - (bitpos0 & 7)));
+ res++;
+ if (pei->pos1 >= 0) { /* two-bit error pattern */
+ bitpos1 = pei->pos1 - offset;
+ if ((bitpos1 < 0) || (bitpos1 >= bits)) {
+ return 0;
}
+ msg[(bitpos1 >> 3)] ^= (1 << (7 - (bitpos1 & 7)));
+ res++;
+ }
+ return res;
}
/* Code for testing the timing: run all possible 1- and 2-bit error
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-hamradio/dump1090.git
More information about the pkg-hamradio-commits
mailing list