From f67a31823bf03ee083ab673b2f2eeaec13c9534b Mon Sep 17 00:00:00 2001 From: Matthias Wirth Date: Sat, 19 Oct 2019 22:52:57 +0200 Subject: [PATCH] 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; } }