From aa2b205481302434dbae09dd51483f4538236fa4 Mon Sep 17 00:00:00 2001 From: Matthias Wirth Date: Fri, 18 Oct 2019 21:02:12 +0200 Subject: [PATCH 1/2] Fix update_position being called when neither CPR changed When we have ADS-B CPRs and get for example a MLAT synthetic CPR, don't call updatePosition as this messes up the position state. --- track.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/track.c b/track.c index bd34c1a..3b6bd1d 100644 --- a/track.c +++ b/track.c @@ -898,6 +898,8 @@ 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) @@ -1123,6 +1125,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 @@ -1131,6 +1134,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)) { @@ -1182,8 +1186,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); } From f67a31823bf03ee083ab673b2f2eeaec13c9534b Mon Sep 17 00:00:00 2001 From: Matthias Wirth Date: Sat, 19 Oct 2019 22:52:57 +0200 Subject: [PATCH 2/2] use accept_data for setting position_valid Check the return value from accept_data to determine if we want to use the decoded position. Avoid a position from local CPR with a synthetic MLAT message being used when the position may still be valid and either odd or even CPR already stale allowing the MLAT CPR to be used. Set the position expiration correctly for global surface CPR, the previous code could have an up to 50 second old CPR being used, which would result in combine_validity setting an expiry time for the position only 10 seconds in the future. --- track.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/track.c b/track.c index 3b6bd1d..d4c981d 100644 --- a/track.c +++ b/track.c @@ -543,8 +543,12 @@ static void updatePosition(struct aircraft *a, struct modesMessage *mm) // Nonfatal, try again later. Modes.stats_current.cpr_global_skipped++; } else { - Modes.stats_current.cpr_global_ok++; - combine_validity(&a->position_valid, &a->cpr_even_valid, &a->cpr_odd_valid); + if (accept_data(&a->position_valid, mm->source)) { + Modes.stats_current.cpr_global_ok++; + } else { + Modes.stats_current.cpr_global_skipped++; + location_result = -2; + } } } @@ -552,17 +556,12 @@ static void updatePosition(struct aircraft *a, struct modesMessage *mm) if (location_result == -1) { location_result = doLocalCPR(a, mm, &new_lat, &new_lon, &new_nic, &new_rc); - if (location_result < 0) { - Modes.stats_current.cpr_local_skipped++; - } else { + if (location_result == 0 && accept_data(&a->position_valid, mm->source)) { Modes.stats_current.cpr_local_ok++; mm->cpr_relative = 1; - - if (mm->cpr_odd) { - a->position_valid = a->cpr_odd_valid; - } else { - a->position_valid = a->cpr_even_valid; - } + } else { + Modes.stats_current.cpr_local_skipped++; + location_result = -1; } }