Fix adaptive gain stats not getting set on stats_current -> zeros

appearing in stats output. Now we have a validity flag for the stats
members where we have to pick one value and not simply sum data.
This commit is contained in:
Oliver Jowett 2021-07-07 20:18:54 +08:00
parent b3172181d5
commit fd8f2d77e1
4 changed files with 41 additions and 26 deletions

View File

@ -399,6 +399,7 @@ static void adaptive_end_of_block()
adaptive_burst_control_update(); adaptive_burst_control_update();
adaptive_range_control_update(); adaptive_range_control_update();
Modes.stats_current.adaptive_valid = true;
unsigned current = Modes.stats_current.adaptive_gain = sdrGetGain(); unsigned current = Modes.stats_current.adaptive_gain = sdrGetGain();
++Modes.stats_current.adaptive_gain_seconds[current < STATS_GAIN_COUNT ? current : STATS_GAIN_COUNT-1]; ++Modes.stats_current.adaptive_gain_seconds[current < STATS_GAIN_COUNT ? current : STATS_GAIN_COUNT-1];
if (adaptive_burst_suppressing) if (adaptive_burst_suppressing)

View File

@ -1859,29 +1859,32 @@ static char * appendStatsJson(char *p,
} }
p = safe_snprintf(p, end, "]"); p = safe_snprintf(p, end, "]");
p = safe_snprintf(p, end, if (st->adaptive_valid) {
",\"adaptive\":" p = safe_snprintf(p, end,
"{\"gain_db\":%.1f" ",\"adaptive\":"
",\"gain_reduced_seconds\":%u" "{\"gain_db\":%.1f"
",\"loud_undecoded\":%u" ",\"gain_reduced_seconds\":%u"
",\"loud_decoded\":%u" ",\"loud_undecoded\":%u"
",\"noise_dbfs\":%.1f" ",\"loud_decoded\":%u"
",\"gain_seconds\":[", ",\"noise_dbfs\":%.1f"
sdrGetGainDb(st->adaptive_gain), ",\"gain_seconds\":[",
st->adaptive_gain_reduced_seconds, sdrGetGainDb(st->adaptive_gain),
st->adaptive_loud_undecoded, st->adaptive_gain_reduced_seconds,
st->adaptive_loud_decoded, st->adaptive_loud_undecoded,
st->adaptive_noise_dbfs); st->adaptive_loud_decoded,
bool first = true; st->adaptive_noise_dbfs);
for (unsigned i = 0; i < STATS_GAIN_COUNT; ++i) { bool first = true;
if (st->adaptive_gain_seconds[i] > 0) { for (unsigned i = 0; i < STATS_GAIN_COUNT; ++i) {
p = safe_snprintf(p, end, "%s[%.1f,%u]", if (st->adaptive_gain_seconds[i] > 0) {
first ? "" : ",", p = safe_snprintf(p, end, "%s[%.1f,%u]",
sdrGetGainDb(i), st->adaptive_gain_seconds[i]); first ? "" : ",",
first = false; sdrGetGainDb(i), st->adaptive_gain_seconds[i]);
first = false;
}
} }
p = safe_snprintf(p, end, "]}");
} }
p = safe_snprintf(p, end, "]}}"); p = safe_snprintf(p, end, "}");
return p; return p;
} }

18
stats.c
View File

@ -115,7 +115,7 @@ void display_stats(struct stats *st) {
st->strong_signal_count); st->strong_signal_count);
} }
if (Modes.adaptive_burst_control || Modes.adaptive_range_control) { if (st->adaptive_valid) {
printf("Adaptive gain:\n" printf("Adaptive gain:\n"
" %5u loud undecoded bursts\n" " %5u loud undecoded bursts\n"
" %5u loud decoded messages\n" " %5u loud decoded messages\n"
@ -315,7 +315,7 @@ void add_stats(const struct stats *st1, const struct stats *st2, struct stats *t
target->start = st2->start; target->start = st2->start;
const struct stats *newer; const struct stats *newer;
if (st1->end > st2->end) { if (st1->end > st2->end || (st1->end == st2->end && st1->start > st2->start)) {
newer = st1; newer = st1;
} else { } else {
newer = st2; newer = st2;
@ -395,11 +395,21 @@ void add_stats(const struct stats *st1, const struct stats *st2, struct stats *t
target->range_histogram[i] = st1->range_histogram[i] + st2->range_histogram[i]; target->range_histogram[i] = st1->range_histogram[i] + st2->range_histogram[i];
// adaptive gain measurements // adaptive gain measurements
target->adaptive_gain = newer->adaptive_gain;
const struct stats *adaptive_best;
if (st1->adaptive_valid && st2->adaptive_valid)
adaptive_best = newer;
else if (st1->adaptive_valid)
adaptive_best = st1;
else
adaptive_best = st2;
target->adaptive_valid = adaptive_best->adaptive_valid;
target->adaptive_gain = adaptive_best->adaptive_gain;
for (unsigned i = 0; i < STATS_GAIN_COUNT; ++i) for (unsigned i = 0; i < STATS_GAIN_COUNT; ++i)
target->adaptive_gain_seconds[i] = st1->adaptive_gain_seconds[i] + st2->adaptive_gain_seconds[i]; target->adaptive_gain_seconds[i] = st1->adaptive_gain_seconds[i] + st2->adaptive_gain_seconds[i];
target->adaptive_gain_reduced_seconds = st1->adaptive_gain_reduced_seconds + st2->adaptive_gain_reduced_seconds; target->adaptive_gain_reduced_seconds = st1->adaptive_gain_reduced_seconds + st2->adaptive_gain_reduced_seconds;
target->adaptive_loud_undecoded = st1->adaptive_loud_undecoded + st2->adaptive_loud_undecoded; target->adaptive_loud_undecoded = st1->adaptive_loud_undecoded + st2->adaptive_loud_undecoded;
target->adaptive_loud_decoded = st1->adaptive_loud_decoded + st2->adaptive_loud_decoded; target->adaptive_loud_decoded = st1->adaptive_loud_decoded + st2->adaptive_loud_decoded;
target->adaptive_noise_dbfs = newer->adaptive_noise_dbfs; target->adaptive_noise_dbfs = adaptive_best->adaptive_noise_dbfs;
} }

View File

@ -132,7 +132,8 @@ struct stats {
// adaptive gain measurements // adaptive gain measurements
#define STATS_GAIN_COUNT 64 #define STATS_GAIN_COUNT 64
unsigned adaptive_gain; // Current gain step in use bool adaptive_valid; // is the following data valid?
int adaptive_gain; // Current gain step in use
uint32_t adaptive_gain_seconds[STATS_GAIN_COUNT]; // Seconds spent at each gain step uint32_t adaptive_gain_seconds[STATS_GAIN_COUNT]; // Seconds spent at each gain step
uint32_t adaptive_gain_reduced_seconds; // Seconds spent at a reduced gain due to burst detection uint32_t adaptive_gain_reduced_seconds; // Seconds spent at a reduced gain due to burst detection
uint32_t adaptive_loud_undecoded; // Total number of loud, undecoded bursts uint32_t adaptive_loud_undecoded; // Total number of loud, undecoded bursts