From 6a113878616269d4c0db96139006203c9e1946a2 Mon Sep 17 00:00:00 2001 From: Oliver Jowett Date: Thu, 4 Feb 2021 16:33:26 +0800 Subject: [PATCH] Collect stats on messages received by DF type --- mode_s.c | 3 +++ net_io.c | 12 ++++++++++-- stats.c | 9 ++++++++- stats.h | 2 ++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/mode_s.c b/mode_s.c index 5cd9612..f2e7095 100644 --- a/mode_s.c +++ b/mode_s.c @@ -2142,6 +2142,9 @@ void useModesMessage(struct modesMessage *mm) { struct aircraft *a; ++Modes.stats_current.messages_total; + if (mm->msgtype >= 0 && mm->msgtype < 32) { + ++Modes.stats_current.messages_by_df[mm->msgtype]; + } // Track aircraft state a = trackUpdateFromMessage(mm); diff --git a/net_io.c b/net_io.c index 7636087..d482998 100644 --- a/net_io.c +++ b/net_io.c @@ -1791,7 +1791,7 @@ static char * appendStatsJson(char *p, ",\"tracks\":{\"all\":%u" ",\"single_message\":%u" ",\"unreliable\":%u}" - ",\"messages\":%u}", + ",\"messages\":%u", st->cpr_surface, st->cpr_airborne, st->cpr_global_ok, @@ -1813,7 +1813,15 @@ static char * appendStatsJson(char *p, st->unique_aircraft, st->single_message_aircraft, st->unreliable_aircraft, - st->messages_total); + st->messages_total); + + for (i = 0; i < 32; ++i) { + if (i == 0) + p = safe_snprintf(p, end, ",\"messages_by_df\":[%u", st->messages_by_df[i]); + else + p = safe_snprintf(p, end, ",%u", st->messages_by_df[i]); + } + p = safe_snprintf(p, end, "]}"); } return p; diff --git a/stats.c b/stats.c index 3cfaa94..d433746 100644 --- a/stats.c +++ b/stats.c @@ -125,9 +125,14 @@ void display_stats(struct stats *st) { printf(" %8u accepted with %d-bit error repaired\n", st->remote_accepted[j], j); } - printf("%u total usable messages\n", + printf("%8u total usable messages\n", st->messages_total); + for (unsigned i = 0; i < 32; ++i) { + if (st->messages_by_df[i]) + printf(" %8u DF%u messages\n", st->messages_by_df[i], i); + } + printf("%8u surface position messages received\n" "%8u airborne position messages received\n" "%8u global CPR attempts with valid positions\n" @@ -310,6 +315,8 @@ void add_stats(const struct stats *st1, const struct stats *st2, struct stats *t // total messages: target->messages_total = st1->messages_total + st2->messages_total; + for (i = 0; i < 32; ++i) + target->messages_by_df[i] = st1->messages_by_df[i] + st2->messages_by_df[i]; // CPR decoding: target->cpr_surface = st1->cpr_surface + st2->cpr_surface; diff --git a/stats.h b/stats.h index bd06bb0..1935b12 100644 --- a/stats.h +++ b/stats.h @@ -94,6 +94,8 @@ struct stats { // total messages: uint32_t messages_total; + // .. divided by DF + uint32_t messages_by_df[32]; // CPR decoding: unsigned int cpr_surface;