diff --git a/track.c b/track.c index dd1b0d0..22eba28 100644 --- a/track.c +++ b/track.c @@ -940,8 +940,15 @@ struct aircraft *trackUpdateFromMessage(struct modesMessage *mm) a->geom_rate = mm->geom_rate; } - if (mm->airground != AG_INVALID && accept_data(&a->airground_valid, mm->source)) { - a->airground = mm->airground; + if (mm->airground != AG_INVALID) { + // If our current state is UNCERTAIN, accept new data as normal + // If our current state is certain but new data is not, only accept the uncertain state if the certain data has gone stale + if (mm->airground != AG_UNCERTAIN || + (mm->airground == AG_UNCERTAIN && !trackDataFresh(&a->airground_valid))) { + if (accept_data(&a->airground_valid, mm->source)) { + a->airground = mm->airground; + } + } } if (mm->callsign_valid && accept_data(&a->callsign_valid, mm->source)) { diff --git a/track.h b/track.h index 3d7475c..e52fefc 100644 --- a/track.h +++ b/track.h @@ -259,6 +259,12 @@ static inline int trackDataValid(const data_validity *v) return (v->source != SOURCE_INVALID && messageNow() < v->expires); } +/* is this bit of data fresh? */ +static inline int trackDataFresh(const data_validity *v) +{ + return (v->source != SOURCE_INVALID && messageNow() < v->stale); +} + /* what's the age of this data, in milliseconds? */ static inline uint64_t trackDataAge(const data_validity *v) {