Bugfix in position decoding

If the aircraft lands or takes off, the Lat/Lon valid flags are cleared.
In the original code, this also resulted in any even/odd position
reports in the mm record being discarded  This meant that the code would
require an even and odd position after the change of flight status.

The code had been modified so that any position report in the mm record
is used even if there is a change of flight status. This means there
only needs to be an even or odd after a change of FS, rather than
requiring both even and odd. The result should be earlier decoding of
position.
This commit is contained in:
Malcolm Robb 2013-10-04 11:09:40 +01:00
parent fa004fc38a
commit 64b24ebc29

View file

@ -258,28 +258,29 @@ struct aircraft *interactiveReceiveData(struct modesMessage *mm) {
// if the Aircraft has landed or taken off since the last message, clear the even/odd CPR flags // if the Aircraft has landed or taken off since the last message, clear the even/odd CPR flags
if ((mm->bFlags & MODES_ACFLAGS_AOG_VALID) && ((a->bFlags ^ mm->bFlags) & MODES_ACFLAGS_AOG)) { if ((mm->bFlags & MODES_ACFLAGS_AOG_VALID) && ((a->bFlags ^ mm->bFlags) & MODES_ACFLAGS_AOG)) {
a->bFlags &= ~(MODES_ACFLAGS_LLBOTH_VALID | MODES_ACFLAGS_AOG); a->bFlags &= ~(MODES_ACFLAGS_LLBOTH_VALID | MODES_ACFLAGS_AOG);
}
} else if ( (mm->bFlags & MODES_ACFLAGS_LLEITHER_VALID) // If we've got a new cprlat or cprlon
&& (((mm->bFlags | a->bFlags) & MODES_ACFLAGS_LLEITHER_VALID) == MODES_ACFLAGS_LLBOTH_VALID) ) { if (mm->bFlags & MODES_ACFLAGS_LLEITHER_VALID) {
// If it's a new even/odd raw lat/lon, and we now have both even and odd,decode the CPR
int fflag;
if (mm->bFlags & MODES_ACFLAGS_LLODD_VALID) { if (mm->bFlags & MODES_ACFLAGS_LLODD_VALID) {
fflag = 1;
a->odd_cprlat = mm->raw_latitude; a->odd_cprlat = mm->raw_latitude;
a->odd_cprlon = mm->raw_longitude; a->odd_cprlon = mm->raw_longitude;
a->odd_cprtime = mstime(); a->odd_cprtime = mstime();
} else { } else {
fflag = 0;
a->even_cprlat = mm->raw_latitude; a->even_cprlat = mm->raw_latitude;
a->even_cprlon = mm->raw_longitude; a->even_cprlon = mm->raw_longitude;
a->even_cprtime = mstime(); a->even_cprtime = mstime();
} }
if (((mm->bFlags | a->bFlags) & MODES_ACFLAGS_LLEITHER_VALID) == MODES_ACFLAGS_LLBOTH_VALID) {
// If we now have both even and odd, decode the CPR
// Try relative CPR first // Try relative CPR first
if (decodeCPRrelative(a, fflag, (mm->bFlags & MODES_ACFLAGS_AOG))) { if (decodeCPRrelative(a, (mm->bFlags & MODES_ACFLAGS_LLODD_VALID), (mm->bFlags & MODES_ACFLAGS_AOG))) {
// If it fails then try global if the two data are less than 10 seconds apart // If relative CPR fails then try global if the two data are less than 10 seconds apart
if (abs((int)(a->even_cprtime - a->odd_cprtime)) <= 10000) { if (abs((int)(a->even_cprtime - a->odd_cprtime)) <= 10000) {
decodeCPR(a, fflag, (mm->bFlags & MODES_ACFLAGS_AOG)); decodeCPR(a, (mm->bFlags & MODES_ACFLAGS_LLODD_VALID), (mm->bFlags & MODES_ACFLAGS_AOG));
} }
} }
@ -290,6 +291,7 @@ struct aircraft *interactiveReceiveData(struct modesMessage *mm) {
mm->fLon = a->lon; mm->fLon = a->lon;
} }
} }
}
// Update the aircrafts a->bFlags to reflect the newly received mm->bFlags; // Update the aircrafts a->bFlags to reflect the newly received mm->bFlags;
a->bFlags |= mm->bFlags; a->bFlags |= mm->bFlags;