Skip to content
This repository has been archived by the owner on Aug 1, 2020. It is now read-only.
/ readsb Public archive

Commit

Permalink
Merge pull request #19 from wiedehopf/cpr_fix
Browse files Browse the repository at this point in the history
Some improvements for position updating / CPR handling
  • Loading branch information
Mictronics committed Oct 19, 2019
2 parents 18527a4 + 1aa5315 commit 033eb5a
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions track.c
Original file line number Diff line number Diff line change
Expand Up @@ -516,11 +516,19 @@ static void updatePosition(struct aircraft *a, struct modesMessage *mm) {
fprintf(stderr, "global CPR failure (invalid) for (%06X).\n", a->addr);
#endif
// Global CPR failed because the position produced implausible results.
// This is bad data. Discard both odd and even messages and wait for a fresh pair.
// Also disable aircraft-relative positions until we have a new good position (but don't discard the
// recorded position itself)
// This is bad data. In case the previously decoded (current)
// position is incorrect, reduce the 70 second expires timer by 25
// seconds, so repeated failures will lead to invalidation of the
// current position and a new position can be determined. Without
// this a bad current position might block valid new positions for
// up to a minute due to the speed check.

Modes.stats_current.cpr_global_bad++;
a->cpr_odd_valid.source = a->cpr_even_valid.source = a->position_valid.source = SOURCE_INVALID;

a->cpr_odd_valid.expires -= 25;
a->cpr_even_valid.expires -= 25;
a->position_valid.expires -= 25;


return;
} else if (location_result == -1) {
Expand Down Expand Up @@ -806,6 +814,7 @@ static int altitude_to_feet(int raw, altitude_unit_t unit) {

struct aircraft *trackUpdateFromMessage(struct modesMessage *mm) {
struct aircraft *a;
unsigned int cpr_new = 0;

if (mm->msgtype == 32) {
// Mode A/C, just count it (we ignore SPI)
Expand Down Expand Up @@ -1014,6 +1023,7 @@ struct aircraft *trackUpdateFromMessage(struct modesMessage *mm) {
a->cpr_even_lat = mm->cpr_lat;
a->cpr_even_lon = mm->cpr_lon;
compute_nic_rc_from_message(mm, a, &a->cpr_even_nic, &a->cpr_even_rc);
cpr_new = 1;
}

// CPR, odd
Expand All @@ -1022,6 +1032,7 @@ struct aircraft *trackUpdateFromMessage(struct modesMessage *mm) {
a->cpr_odd_lat = mm->cpr_lat;
a->cpr_odd_lon = mm->cpr_lon;
compute_nic_rc_from_message(mm, a, &a->cpr_odd_nic, &a->cpr_odd_rc);
cpr_new = 1;
}

if (mm->accuracy.sda_valid && accept_data(&a->sda_valid, mm->source)) {
Expand Down Expand Up @@ -1073,8 +1084,8 @@ struct aircraft *trackUpdateFromMessage(struct modesMessage *mm) {
combine_validity(&a->altitude_geom_valid, &a->altitude_baro_valid, &a->geom_delta_valid);
}

// If we've got a new cprlat or cprlon
if (mm->cpr_valid) {
// If we've got a new cpr_odd or cpr_even
if (cpr_new) {
updatePosition(a, mm);
}

Expand Down

0 comments on commit 033eb5a

Please sign in to comment.