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,36 +258,38 @@ 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 ((mm->bFlags & MODES_ACFLAGS_AOG_VALID) && ((a->bFlags ^ mm->bFlags) & MODES_ACFLAGS_AOG)) {
a->bFlags &= ~(MODES_ACFLAGS_LLBOTH_VALID | MODES_ACFLAGS_AOG);
}
} else if ( (mm->bFlags & MODES_ACFLAGS_LLEITHER_VALID)
&& (((mm->bFlags | a->bFlags) & MODES_ACFLAGS_LLEITHER_VALID) == MODES_ACFLAGS_LLBOTH_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 we've got a new cprlat or cprlon
if (mm->bFlags & MODES_ACFLAGS_LLEITHER_VALID) {
if (mm->bFlags & MODES_ACFLAGS_LLODD_VALID) {
fflag = 1;
a->odd_cprlat = mm->raw_latitude;
a->odd_cprlon = mm->raw_longitude;
a->odd_cprtime = mstime();
} else {
fflag = 0;
a->even_cprlat = mm->raw_latitude;
a->even_cprlon = mm->raw_longitude;
a->even_cprtime = mstime();
}
// Try relative CPR first
if (decodeCPRrelative(a, fflag, (mm->bFlags & MODES_ACFLAGS_AOG))) {
// If it fails then try global if the two data are less than 10 seconds apart
if (abs((int)(a->even_cprtime - a->odd_cprtime)) <= 10000) {
decodeCPR(a, fflag, (mm->bFlags & MODES_ACFLAGS_AOG));
}
}
//If we sucessfully decoded, back copy the results to mm so that we can print them in list output
if (a->bFlags & MODES_ACFLAGS_LATLON_VALID) {
mm->bFlags |= MODES_ACFLAGS_LATLON_VALID;
mm->fLat = a->lat;
mm->fLon = a->lon;
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
if (decodeCPRrelative(a, (mm->bFlags & MODES_ACFLAGS_LLODD_VALID), (mm->bFlags & MODES_ACFLAGS_AOG))) {
// 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) {
decodeCPR(a, (mm->bFlags & MODES_ACFLAGS_LLODD_VALID), (mm->bFlags & MODES_ACFLAGS_AOG));
}
}
//If we sucessfully decoded, back copy the results to mm so that we can print them in list output
if (a->bFlags & MODES_ACFLAGS_LATLON_VALID) {
mm->bFlags |= MODES_ACFLAGS_LATLON_VALID;
mm->fLat = a->lat;
mm->fLon = a->lon;
}
}
}