Track CPR encoding type directly rather than inferring it from airground.

(airground can change even while airborne if SPI/Alert status gets set)
This commit is contained in:
Oliver Jowett 2016-10-02 00:16:29 +01:00
parent 617a71e36b
commit 52fe01c860
4 changed files with 31 additions and 12 deletions

12
track.c
View file

@ -260,7 +260,7 @@ static int doGlobalCPR(struct aircraft *a, struct modesMessage *mm, uint64_t now
{
int result;
int fflag = mm->cpr_odd;
int surface = (mm->airground == AG_GROUND);
int surface = (mm->cpr_type == CPR_SURFACE);
*nuc = (a->cpr_even_nuc < a->cpr_odd_nuc ? a->cpr_even_nuc : a->cpr_odd_nuc); // worst of the two positions
@ -341,7 +341,7 @@ static int doLocalCPR(struct aircraft *a, struct modesMessage *mm, uint64_t now,
double range_limit = 0;
int result;
int fflag = mm->cpr_odd;
int surface = (mm->airground == AG_GROUND);
int surface = (mm->cpr_type == CPR_SURFACE);
*nuc = mm->cpr_nucp;
@ -426,7 +426,7 @@ static void updatePosition(struct aircraft *a, struct modesMessage *mm, uint64_t
unsigned new_nuc = 0;
int surface;
surface = (mm->airground == AG_GROUND);
surface = (mm->cpr_type == CPR_SURFACE);
if (surface) {
++Modes.stats_current.cpr_surface;
@ -446,7 +446,7 @@ static void updatePosition(struct aircraft *a, struct modesMessage *mm, uint64_t
// If we have enough recent data, try global CPR
if (trackDataValid(&a->cpr_odd_valid) && trackDataValid(&a->cpr_even_valid) &&
a->cpr_odd_valid.source == a->cpr_even_valid.source &&
a->cpr_odd_airground == a->cpr_even_airground &&
a->cpr_odd_type == a->cpr_even_type &&
time_between(a->cpr_odd_valid.updated, a->cpr_even_valid.updated) <= max_elapsed) {
location_result = doGlobalCPR(a, mm, now, &new_lat, &new_lon, &new_nuc);
@ -607,7 +607,7 @@ struct aircraft *trackUpdateFromMessage(struct modesMessage *mm)
// CPR, even
if (mm->cpr_valid && !mm->cpr_odd && accept_data(&a->cpr_even_valid, mm->source, now)) {
a->cpr_even_airground = mm->airground;
a->cpr_even_type = mm->cpr_type;
a->cpr_even_lat = mm->cpr_lat;
a->cpr_even_lon = mm->cpr_lon;
a->cpr_even_nuc = mm->cpr_nucp;
@ -615,7 +615,7 @@ struct aircraft *trackUpdateFromMessage(struct modesMessage *mm)
// CPR, odd
if (mm->cpr_valid && mm->cpr_odd && accept_data(&a->cpr_odd_valid, mm->source, now)) {
a->cpr_odd_airground = mm->airground;
a->cpr_odd_type = mm->cpr_type;
a->cpr_odd_lat = mm->cpr_lat;
a->cpr_odd_lon = mm->cpr_lon;
a->cpr_odd_nuc = mm->cpr_nucp;