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

Some improvements for position updating / CPR handling #19

Merged
merged 2 commits into from
Oct 19, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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