aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2019-07-05 11:16:06 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2019-07-05 11:16:06 +0200
commit42502fc14501d7726b4f96b58326be035db324c4 (patch)
tree7487c12d255277889892aab18afa4e71e3d0d027
parent1a5b10d91cdb36a521c7affa300f30bca679a90f (diff)
downloadglutte-o-matic-42502fc14501d7726b4f96b58326be035db324c4.tar.gz
glutte-o-matic-42502fc14501d7726b4f96b58326be035db324c4.tar.bz2
glutte-o-matic-42502fc14501d7726b4f96b58326be035db324c4.zip
Stats: add QSO duration, avoid calling build_text all the time
-rw-r--r--src/README.md6
-rw-r--r--src/common/Core/fsm.c8
-rw-r--r--src/common/Core/main.c6
-rw-r--r--src/common/Core/stats.c44
-rw-r--r--src/common/Core/stats.h2
5 files changed, 56 insertions, 10 deletions
diff --git a/src/README.md b/src/README.md
index 188bd89..f6733e7 100644
--- a/src/README.md
+++ b/src/README.md
@@ -41,6 +41,12 @@ Debug avec OpenOCD et GDB
load
continue
+Debug simulateur avec GDB
+=========================
+
+ handle SIGUSR1 nostop noignore noprint
+ handle SIG34 nostop noignore noprint
+
Analyse statique avec clang
===========================
diff --git a/src/common/Core/fsm.c b/src/common/Core/fsm.c
index 4daf568..a41ee0e 100644
--- a/src/common/Core/fsm.c
+++ b/src/common/Core/fsm.c
@@ -525,8 +525,11 @@ void fsm_update() {
if (fsm_in.cw_psk_done) {
balise_message_clear();
+ // The exercise_fsm loop needs to see a 1 to 0 transition on cw_psk_trigger
+ // so that it considers the STATS2 message.
fsm_out.cw_psk_trigger = 0;
if (current_state == FSM_BALISE_STATS1) {
+ fsm_out.msg = NULL;
next_state = FSM_BALISE_STATS2;
}
else {
@@ -540,7 +543,10 @@ void fsm_update() {
fsm_out.msg_frequency = 588;
fsm_out.cw_dit_duration = -3; // PSK125
- fsm_out.msg = stats_build_text();
+ // All predecessor states must NULL the fsm_out.msg field!
+ if (fsm_out.msg == NULL) {
+ fsm_out.msg = stats_build_text();
+ }
fsm_out.cw_psk_trigger = 1;
if (fsm_in.cw_psk_done) {
diff --git a/src/common/Core/main.c b/src/common/Core/main.c
index 02fb94c..f4125d1 100644
--- a/src/common/Core/main.c
+++ b/src/common/Core/main.c
@@ -651,13 +651,14 @@ static void exercise_fsm(void __attribute__ ((unused))*pvParameters)
pio_set_tx(fsm_out.tx_on);
if (fsm_out.tx_on != last_tx_on) {
- stats_tx_switched();
+ stats_tx_switched(fsm_out.tx_on);
last_tx_on = fsm_out.tx_on;
}
pio_set_mod_off(!fsm_out.modulation);
// Add message to CW generator only on rising edge of trigger
- if (fsm_out.cw_psk_trigger && !cw_last_trigger) {
+ if (fsm_out.cw_psk_trigger && !cw_last_trigger && fsm_out.msg != NULL) {
+ fprintf(stderr, "TRIG CW %s\n", fsm_out.msg);
const int success = cw_psk_push_message(fsm_out.msg, fsm_out.cw_dit_duration, fsm_out.msg_frequency);
if (!success) {
usart_debug_puts("cw_psk_push_message failed");
@@ -666,7 +667,6 @@ static void exercise_fsm(void __attribute__ ((unused))*pvParameters)
leds_turn_on(LED_ORANGE);
}
cw_last_trigger = fsm_out.cw_psk_trigger;
-
}
}
diff --git a/src/common/Core/stats.c b/src/common/Core/stats.c
index 1ef74b6..9a14076 100644
--- a/src/common/Core/stats.c
+++ b/src/common/Core/stats.c
@@ -43,6 +43,10 @@ static float battery_per_hour[24];
static float temp_min = -1.0f;
static float temp_max = -1.0f;
+static int last_tx_on_valid = 0;
+static uint64_t last_tx_on = 0;
+static uint64_t max_qso_duration = 0;
+
/* Ideas
*
* Version
@@ -76,6 +80,8 @@ static void clear_stats()
temp_max = -1.0f;
num_qro = 0;
num_qrp = 0;
+ last_tx_on_valid = 0;
+ max_qso_duration = 0;
for (int i = 0; i < 24; i++) {
battery_per_hour[i] = -1.0f;
}
@@ -155,13 +161,26 @@ void stats_beacon_sent()
num_beacons_sent++;
}
-void stats_tx_switched()
+void stats_tx_switched(int tx_on)
{
if (values_valid == 0) {
clear_stats();
}
num_tx_switch++;
+
+ if (tx_on) {
+ last_tx_on = timestamp_now();
+ fprintf(stderr, "TX on at %lu\n", last_tx_on);
+ last_tx_on_valid = 1;
+ }
+ else if (last_tx_on_valid) {
+ const uint64_t qso_duration = timestamp_now() - last_tx_on;
+ fprintf(stderr, "TX off with dur=%lu\n", qso_duration);
+ if (qso_duration > max_qso_duration) {
+ max_qso_duration = qso_duration;
+ }
+ }
}
void stats_anti_bavard_triggered()
@@ -212,17 +231,23 @@ 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"
+ "Uptime= %dj%dh%dm\n",
+ vc_get_version(),
+ uptime_j, uptime_h, uptime_m);
+
+ if (values_valid == 0) {
+ return stats_text;
+ }
+
+ stats_end_ix += snprintf(stats_text + stats_end_ix, STATS_LEN - 1 - stats_end_ix,
"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,
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");
+ "U heures pleines= ");
for (int h = 0; h < 24; h++) {
if (battery_per_hour[h] == -1.0f) {
@@ -242,12 +267,20 @@ const char* stats_build_text(void)
const int temp_min_decidegree = 10.0f * temp_min;
const int temp_max_decidegree = 10.0f * temp_max;
+ uint64_t qso_duration = max_qso_duration;
+ int qso_duration_h = qso_duration / (3600 * 1000);
+ qso_duration -= qso_duration_h * ( 3600 * 1000);
+ int qso_duration_m = qso_duration / (60 * 1000);
+ qso_duration -= qso_duration_m * (60 * 1000);
+ int qso_duration_s = qso_duration / (1000);
+
stats_end_ix += snprintf(stats_text + stats_end_ix, STATS_LEN - 1 - stats_end_ix,
"Nbre de commutations eolienne= %d\n"
"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"
+ "QSO le plus long= %dh%dm%ds\n"
"Sat GPS= %d\n",
num_wind_generator_movements,
temp_min_decidegree / 10, temp_min_decidegree % 10,
@@ -255,6 +288,7 @@ const char* stats_build_text(void)
num_beacons_sent,
num_tx_switch,
num_antibavard,
+ qso_duration_h, qso_duration_m, qso_duration_s,
num_sv_used
);
diff --git a/src/common/Core/stats.h b/src/common/Core/stats.h
index 1897d1e..09f4c17 100644
--- a/src/common/Core/stats.h
+++ b/src/common/Core/stats.h
@@ -31,7 +31,7 @@ void stats_voltage(float u_bat);
void stats_temp(float temp);
void stats_wind_generator_moved(void);
void stats_beacon_sent(void);
-void stats_tx_switched(void);
+void stats_tx_switched(int tx_on);
void stats_anti_bavard_triggered(void);
void stats_num_gnss_sv(int num_sv);