diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2019-07-05 10:19:49 +0200 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2019-07-05 10:19:49 +0200 |
commit | 1a5b10d91cdb36a521c7affa300f30bca679a90f (patch) | |
tree | dbc21b5da8dcd61f6f5e73821f0bbf84e60984a4 | |
parent | 497a16df708dd8316e658f17127f589e08984547 (diff) | |
download | glutte-o-matic-1a5b10d91cdb36a521c7affa300f30bca679a90f.tar.gz glutte-o-matic-1a5b10d91cdb36a521c7affa300f30bca679a90f.tar.bz2 glutte-o-matic-1a5b10d91cdb36a521c7affa300f30bca679a90f.zip |
stats: add GNSS SV and QRP percentage. Also use derived time
-rw-r--r-- | src/common/Core/main.c | 15 | ||||
-rw-r--r-- | src/common/Core/stats.c | 42 | ||||
-rw-r--r-- | src/common/Core/stats.h | 4 |
3 files changed, 54 insertions, 7 deletions
diff --git a/src/common/Core/main.c b/src/common/Core/main.c index b43463a..02fb94c 100644 --- a/src/common/Core/main.c +++ b/src/common/Core/main.c @@ -381,7 +381,6 @@ static void audio_callback(void __attribute__ ((unused))*context, int select_buf } timestamp_last_audio_callback = timestamp_now(); - } static struct tm gps_time; @@ -547,6 +546,8 @@ static void exercise_fsm(void __attribute__ ((unused))*pvParameters) int last_discrim_u = 0; int last_wind_generator_ok = 0; + uint64_t last_qrp_stats_updated = timestamp_now(); + fsm_input.humidity = 0; fsm_input.temp = 15; fsm_input.swr_high = 0; @@ -558,6 +559,14 @@ static void exercise_fsm(void __attribute__ ((unused))*pvParameters) pio_set_fsm_signals(&fsm_input); + const uint64_t now = timestamp_now(); + + // QRP/QRO doesn't change too often, updating every 10s is good enough + if (last_qrp_stats_updated + 10000 < now) { + stats_qrp(fsm_input.qrp); + last_qrp_stats_updated = now; + } + if (last_sq != fsm_input.sq) { last_sq = fsm_input.sq; usart_debug("In SQ %d\r\n", last_sq); @@ -617,7 +626,9 @@ static void exercise_fsm(void __attribute__ ((unused))*pvParameters) struct tm time = {0}; int time_valid = local_time(&time); - // TODO use derived too? + if (!time_valid) { + time_valid = local_derived_time(&time); + } if (time_valid) { fsm_input.send_stats = (time.tm_hour == 22) ? 1 : 0; } diff --git a/src/common/Core/stats.c b/src/common/Core/stats.c index b38d99d..1ef74b6 100644 --- a/src/common/Core/stats.c +++ b/src/common/Core/stats.c @@ -34,6 +34,9 @@ static int num_beacons_sent = 0; static int num_wind_generator_movements = 0; static int num_tx_switch = 0; static int num_antibavard = 0; +static int num_sv_used = 0; +static int num_qro = 0; +static int num_qrp = 0; static float battery_min = -1.0f; static float battery_max = -1.0f; static float battery_per_hour[24]; @@ -71,6 +74,8 @@ static void clear_stats() battery_max = -1.0f; temp_min = -1.0f; temp_max = -1.0f; + num_qro = 0; + num_qrp = 0; for (int i = 0; i < 24; i++) { battery_per_hour[i] = -1.0f; } @@ -118,6 +123,20 @@ void stats_temp(float temp) } } +void stats_qrp(int is_qrp) +{ + if (values_valid == 0) { + clear_stats(); + } + + if (is_qrp) { + num_qrp++; + } + else { + num_qro++; + } +} + void stats_wind_generator_moved() { if (values_valid == 0) { @@ -154,6 +173,15 @@ void stats_anti_bavard_triggered() num_antibavard++; } +void stats_num_gnss_sv(int num_sv) +{ + if (values_valid == 0) { + clear_stats(); + } + + num_sv_used = num_sv; +} + const char* stats_build_text(void) { struct tm time = {0}; @@ -185,11 +213,13 @@ const char* stats_build_text(void) stats_end_ix += snprintf(stats_text + stats_end_ix, STATS_LEN - 1 - stats_end_ix, "Version= %s\n" "Uptime= %dj%dh%dm\n" - "U min,max= %dV%01d,%dV%01d\n" , + "U min,max= %dV%01d,%dV%01d\n" + "Temps QRP= %d%%\n", vc_get_version(), uptime_j, uptime_h, uptime_m, battery_min_decivolt / 10, battery_min_decivolt % 10, - battery_max_decivolt / 10, battery_max_decivolt % 10); + battery_max_decivolt / 10, battery_max_decivolt % 10, + 100 * num_qrp / (num_qrp + num_qro)); stats_end_ix += snprintf(stats_text + stats_end_ix, STATS_LEN - 1 - stats_end_ix, "U heures pleines=\n"); @@ -197,7 +227,7 @@ const char* stats_build_text(void) for (int h = 0; h < 24; h++) { if (battery_per_hour[h] == -1.0f) { stats_end_ix += snprintf(stats_text + stats_end_ix, STATS_LEN - 1 - stats_end_ix, - " ? "); + " ?"); } else { const int battery_decivolts = 10.0f * battery_per_hour[h]; @@ -217,13 +247,15 @@ const char* stats_build_text(void) "Temp min,max= %dC%01d,%dC%01d\n" "Nbre de balises= %d\n" "Nbre de TX ON/OFF= %d\n" - "Nbre anti-bavard= %d\n", + "Nbre anti-bavard= %d\n" + "Sat GPS= %d\n", num_wind_generator_movements, temp_min_decidegree / 10, temp_min_decidegree % 10, temp_max_decidegree / 10, temp_max_decidegree % 10, num_beacons_sent, num_tx_switch, - num_antibavard + num_antibavard, + num_sv_used ); values_valid = 0; diff --git a/src/common/Core/stats.h b/src/common/Core/stats.h index 06e1515..1897d1e 100644 --- a/src/common/Core/stats.h +++ b/src/common/Core/stats.h @@ -33,5 +33,9 @@ void stats_wind_generator_moved(void); void stats_beacon_sent(void); void stats_tx_switched(void); void stats_anti_bavard_triggered(void); +void stats_num_gnss_sv(int num_sv); + +// Must be called in regular intervals +void stats_qrp(int is_qrp); const char* stats_build_text(void); |