Improve DF field error correction speed
Use bitmasks to speed up the detection of valid and invalid ICAO DF field types.
This commit is contained in:
parent
8d65abd317
commit
c81498a0d0
27
dump1090.c
27
dump1090.c
|
@ -1977,18 +1977,25 @@ void detectModeS(uint16_t *m, uint32_t mlen) {
|
||||||
if (msglen > i) {msglen = i;}
|
if (msglen > i) {msglen = i;}
|
||||||
else if (msglen < i) {msglen = 0;}
|
else if (msglen < i) {msglen = 0;}
|
||||||
|
|
||||||
|
//
|
||||||
|
// If we guessed at any of the bits in the DF type field, then look to see if our guess was sensible.
|
||||||
|
// Do this by looking to see if the original guess results in the DF type being one of the ICAO defined
|
||||||
|
// message types. If it isn't then toggle the guessed bit and see if this new value is ICAO defined.
|
||||||
|
// if the new value is ICAO defined, then update it in our message.
|
||||||
if ((msglen) && (errorsTy == 1) && (theErrs & 0x78)) {
|
if ((msglen) && (errorsTy == 1) && (theErrs & 0x78)) {
|
||||||
// We guessed at one of the message type bits. See if our guess is "likely"
|
// We guessed at one (and only one) of the message type bits. See if our guess is "likely"
|
||||||
// to be correct by comparing the DF against a list of known good DF's
|
// to be correct by comparing the DF against a list of known good DF's
|
||||||
int DF = ((theByte = msg[0]) >> 3) & 0x1f;
|
int thisDF = ((theByte = msg[0]) >> 3) & 0x1f;
|
||||||
if ( (DF != 0) && (DF != 4) && (DF != 5) && (DF != 11)
|
uint32_t validDFbits = 0x017F0831; // One bit per 32 possible DF's. Set bits 0,4,5,11,16.17.18.19,20,21,22,24
|
||||||
&& (DF != 16) && (DF != 17) && (DF != 18) && (DF != 19) && (DF != 20) && (DF != 21) && (DF != 22) && (DF != 24) ) {
|
uint32_t thisDFbit = (1 << thisDF);
|
||||||
// Other DF values are probably errors. Toggle the bit we guessed at and see if the resultant DF is more likely
|
if (0 == (validDFbits & thisDFbit)) {
|
||||||
theByte ^= theErrs;
|
// The current DF is not ICAO defined, so is probably an errors.
|
||||||
DF = (theByte >> 3) & 0x1f;
|
// Toggle the bit we guessed at and see if the resultant DF is more likely
|
||||||
// if this DF any more likely??
|
theByte ^= theErrs;
|
||||||
if ( (DF == 0) || (DF == 4) || (DF == 5) || (DF == 11)
|
thisDF = (theByte >> 3) & 0x1f;
|
||||||
|| (DF == 16) || (DF == 17) || (DF == 18) || (DF == 19) || (DF == 20) || (DF == 21) || (DF == 22) || (DF == 24) ) {
|
thisDFbit = (1 << thisDF);
|
||||||
|
// if this DF any more likely?
|
||||||
|
if (validDFbits & thisDFbit) {
|
||||||
// Yep, more likely, so update the main message
|
// Yep, more likely, so update the main message
|
||||||
msg[0] = theByte;
|
msg[0] = theByte;
|
||||||
Modes.stat_DF_Type_Corrected++;
|
Modes.stat_DF_Type_Corrected++;
|
||||||
|
|
Loading…
Reference in a new issue