Prefer to use global CPR decoding where possible.
There is a danger in always using relative decoding where possible. If there is an undetected error in the first pair of messages received, then global CPR decoding will give a bad position, and subsequent relative decoding will just walk around near that bad position even though many error-free pairs of odd/even messages may have been received. The first pair of position messages also tends to be the most error-prone, as they are usually received at the extreme edge of receiver range. (I see this happen at least once a day in practice) So, instead, prefer to use global decoding when we have sufficiently recent data. With recent data this should always be as good as relative decoding, and it avoids getting stuck with bad data for long periods of time. If we don't have enough recent data for a global solution, fall back to relative decoding.
This commit is contained in:
parent
a82df07c0c
commit
661246d347
3 changed files with 24 additions and 22 deletions
13
mode_s.c
13
mode_s.c
|
|
@ -2014,11 +2014,8 @@ double cprDlonFunction(double lat, int fflag, int surface) {
|
|||
//
|
||||
// A few remarks:
|
||||
// 1) 131072 is 2^17 since CPR latitude and longitude are encoded in 17 bits.
|
||||
// 2) We assume that we always received the odd packet as last packet for
|
||||
// simplicity. This may provide a position that is less fresh of a few
|
||||
// seconds.
|
||||
//
|
||||
void decodeCPR(struct aircraft *a, int fflag, int surface) {
|
||||
int decodeCPR(struct aircraft *a, int fflag, int surface) {
|
||||
double AirDlat0 = (surface ? 90.0 : 360.0) / 60.0;
|
||||
double AirDlat1 = (surface ? 90.0 : 360.0) / 59.0;
|
||||
double lat0 = a->even_cprlat;
|
||||
|
|
@ -2044,7 +2041,8 @@ void decodeCPR(struct aircraft *a, int fflag, int surface) {
|
|||
surface_rlat = Modes.fUserLat;
|
||||
surface_rlon = Modes.fUserLon;
|
||||
} else {
|
||||
return;
|
||||
// No local reference, give up
|
||||
return (-1);
|
||||
}
|
||||
rlat0 += floor(surface_rlat / 90.0) * 90.0; // Move from 1st quadrant to our quadrant
|
||||
rlat1 += floor(surface_rlat / 90.0) * 90.0;
|
||||
|
|
@ -2054,7 +2052,8 @@ void decodeCPR(struct aircraft *a, int fflag, int surface) {
|
|||
}
|
||||
|
||||
// Check that both are in the same latitude zone, or abort.
|
||||
if (cprNLFunction(rlat0) != cprNLFunction(rlat1)) return;
|
||||
if (cprNLFunction(rlat0) != cprNLFunction(rlat1))
|
||||
return (-1);
|
||||
|
||||
// Compute ni and the Longitude Index "m"
|
||||
if (fflag) { // Use odd packet.
|
||||
|
|
@ -2080,6 +2079,8 @@ void decodeCPR(struct aircraft *a, int fflag, int surface) {
|
|||
a->seenLatLon = a->seen;
|
||||
a->timestampLatLon = a->timestamp;
|
||||
a->bFlags |= (MODES_ACFLAGS_LATLON_VALID | MODES_ACFLAGS_LATLON_REL_OK);
|
||||
|
||||
return 0;
|
||||
}
|
||||
//
|
||||
//=========================================================================
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue