diff --git a/net_io.c b/net_io.c index 899c312..6929ba9 100644 --- a/net_io.c +++ b/net_io.c @@ -959,6 +959,7 @@ static char * appendStatsJson(char *p, ",\"local_range\":%u" ",\"local_speed\":%u" ",\"filtered\":%u}" + ",\"altitude_suppressed\":%u" ",\"cpu\":{\"demod\":%llu,\"reader\":%llu,\"background\":%llu}" ",\"tracks\":{\"all\":%u" ",\"single_message\":%u}" @@ -977,6 +978,7 @@ static char * appendStatsJson(char *p, st->cpr_local_range_checks, st->cpr_local_speed_checks, st->cpr_filtered, + st->suppressed_altitude_messages, (unsigned long long)demod_cpu_millis, (unsigned long long)reader_cpu_millis, (unsigned long long)background_cpu_millis, diff --git a/stats.c b/stats.c index fe5e5be..68e7f5f 100644 --- a/stats.c +++ b/stats.c @@ -151,6 +151,7 @@ void display_stats(struct stats *st) { st->cpr_local_speed_checks, st->cpr_filtered); + printf("%u non-ES altitude messages from ES-equipped aircraft ignored\n", st->suppressed_altitude_messages); printf("%u unique aircraft tracks\n", st->unique_aircraft); printf("%u aircraft tracks where only one message was seen\n", st->single_message_aircraft); @@ -325,6 +326,8 @@ void add_stats(const struct stats *st1, const struct stats *st2, struct stats *t target->cpr_local_speed_checks = st1->cpr_local_speed_checks + st2->cpr_local_speed_checks; target->cpr_filtered = st1->cpr_filtered + st2->cpr_filtered; + target->suppressed_altitude_messages = st1->suppressed_altitude_messages + st2->suppressed_altitude_messages; + // aircraft target->unique_aircraft = st1->unique_aircraft + st2->unique_aircraft; target->single_message_aircraft = st1->single_message_aircraft + st2->single_message_aircraft; diff --git a/stats.h b/stats.h index 5a5d71c..fee4d7d 100644 --- a/stats.h +++ b/stats.h @@ -114,6 +114,10 @@ struct stats { unsigned int cpr_local_receiver_relative; unsigned int cpr_filtered; + // number of altitude messages ignored because + // we had a recent DF17/18 altitude + unsigned int suppressed_altitude_messages; + // aircraft: // total "new" aircraft (i.e. not seen in the last 30 or 300s) unsigned int unique_aircraft; diff --git a/track.c b/track.c index efedde3..7465a5a 100644 --- a/track.c +++ b/track.c @@ -483,9 +483,22 @@ struct aircraft *trackUpdateFromMessage(struct modesMessage *mm) a->modeCcount = 0; //....zero the hit count a->modeACflags &= ~MODEAC_MSG_MODEC_HIT; } - a->altitude = mm->altitude; - a->modeC = (mm->altitude + 49) / 100; - a->seenAltitude = now; + + // If we received an altitude in a DF17/18 squitter recently, ignore + // DF0/4/16/20 altitudes as single-bit errors can attribute them to the wrong + // aircraft + if ((a->bFlags & MODES_ACFLAGS_ALTITUDE_VALID) && + (now - a->seenAltitude) < 15000 && + (a->bFlags & MODES_ACFLAGS_LATLON_VALID) && + (now - a->seenLatLon) < 15000 && + mm->msgtype != 17 && + mm->msgtype != 18) { + Modes.stats_current.suppressed_altitude_messages++; + } else { + a->altitude = mm->altitude; + a->modeC = (mm->altitude + 49) / 100; + a->seenAltitude = now; + } } // If a (new) SQUAWK has been received, copy it to the aircraft structure