diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2020-04-25 20:54:10 +0200 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2020-04-25 20:54:10 +0200 |
commit | c056e476cfd51ee9ce5679ba06b51a48a1b07a1f (patch) | |
tree | d8a8dbaefc2429373ba75985e0f0006fd97f461a /src/common | |
parent | d1f674cc2c05412ea9fa0de21cab777711c6331a (diff) | |
download | glutte-o-matic-c056e476cfd51ee9ce5679ba06b51a48a1b07a1f.tar.gz glutte-o-matic-c056e476cfd51ee9ce5679ba06b51a48a1b07a1f.tar.bz2 glutte-o-matic-c056e476cfd51ee9ce5679ba06b51a48a1b07a1f.zip |
Add batterycharge to stats
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/Core/main.c | 18 | ||||
-rw-r--r-- | src/common/Core/stats.c | 77 | ||||
-rw-r--r-- | src/common/Core/stats.h | 4 | ||||
-rw-r--r-- | src/common/GPIO/usart.c | 2 | ||||
-rw-r--r-- | src/common/sourcelist.txt | 1 |
5 files changed, 58 insertions, 44 deletions
diff --git a/src/common/Core/main.c b/src/common/Core/main.c index 1321517..aed198b 100644 --- a/src/common/Core/main.c +++ b/src/common/Core/main.c @@ -46,6 +46,7 @@ #include "Core/stats.h" #include "Core/common.h" #include "GPIO/usart.h" +#include "GPIO/batterycharge.h" #include "Core/delay.h" #include "GPIO/temperature.h" #include "GPIO/leds.h" @@ -151,6 +152,9 @@ static void launcher_task(void __attribute__ ((unused))*pvParameters) usart_debug_puts("Analog init\r\n"); analog_init(); + usart_debug_puts("Batterycharge init\r\n"); + batterycharge_init(); + usart_debug_puts("I2C init\r\n"); i2c_init(); @@ -472,11 +476,13 @@ static void gps_monit_task(void __attribute__ ((unused))*pvParameters) { if (last_volt_and_temp_timestamp + 20000 < now) { const float u_bat = analog_measure_12v(); + const uint32_t capacity_bat = batterycharge_retrieve_last_capacity(); + usart_debug("ALIM %d mV\r\n", (int)roundf(1000.0f * u_bat)); stats_voltage(u_bat); if (time_valid && time.tm_min == 0) { - stats_voltage_at_full_hour(time.tm_hour, u_bat); + stats_battery_at_full_hour(time.tm_hour, u_bat, capacity_bat); } if (temperature_valid()) { @@ -718,21 +724,19 @@ static char ccounter_msg[MAX_CCOUNTER_SENTENCE_LEN]; static void read_in_coulomb_counter(void __attribute__ ((unused))*pvParameters) { while (1) { - int ok = usart_get_ccounter_msg(ccounter_msg); + int ok = usart_get_ccounter_msg(ccounter_msg); // times out after 2s if (ok) { size_t len = strlen(ccounter_msg); /* Ignore if \n follows \r or not, as that should never happen, and in any case - * we don't want to send the \r or whatever could come after + * we don't want to send the \r or whatever could come after. */ if (len > 2 && ccounter_msg[len-2] == '\r') { ccounter_msg[len-2] = '\0'; } + + batterycharge_push_message(ccounter_msg); usart_debug_puts_header("CC:", ccounter_msg); } - else { - usart_debug_puts("WARNING: Read from ccounter queue failed\r\n"); - vTaskDelay(5000 / portTICK_PERIOD_MS); - } } } diff --git a/src/common/Core/stats.c b/src/common/Core/stats.c index e3239e3..22b45c8 100644 --- a/src/common/Core/stats.c +++ b/src/common/Core/stats.c @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2019 Matthias P. Braendli, Maximilien Cuony + * Copyright (c) 2020 Matthias P. Braendli, Maximilien Cuony * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -38,9 +38,10 @@ 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]; +static float battery_volt_min = -1.0f; +static float battery_volt_max = -1.0f; +static float battery_volt_hourly[24]; +static uint32_t battery_charge_hourly[24]; #define TEMP_INVALID -128.0f static float temp_min = TEMP_INVALID; static float temp_max = TEMP_INVALID; @@ -51,19 +52,7 @@ static uint64_t max_qso_duration = 0; /* Ideas * - * Version - * Uptime - * Number of beacons - * Ubat min/max/avg - * Temperature min/max/avg - * QRP/QRO time ratio in % - * Number of K, G, D, U, S, R sent - * Number of TX On/Off - * How many times anti-bavard got triggered * Max SWR ratio - * Number of wind generator movements - * Longest QSO duration - * Number of GNSS SVs tracked */ #define STATS_LEN 1024 // also check MAX_MESSAGE_LEN in cw.c @@ -76,8 +65,8 @@ static void clear_stats() num_wind_generator_movements = 0; num_tx_switch = 0; num_antibavard = 0; - battery_min = -1.0f; - battery_max = -1.0f; + battery_volt_min = -1.0f; + battery_volt_max = -1.0f; temp_min = TEMP_INVALID; temp_max = TEMP_INVALID; num_qro = 0; @@ -85,19 +74,23 @@ static void clear_stats() last_tx_on_valid = 0; max_qso_duration = 0; for (int i = 0; i < 24; i++) { - battery_per_hour[i] = -1.0f; + battery_volt_hourly[i] = -1.0f; + } + for (int i = 0; i < 24; i++) { + battery_charge_hourly[i] = 0; } values_valid = 1; } -void stats_voltage_at_full_hour(int hour, float u_bat) +void stats_battery_at_full_hour(int hour, float u_bat, uint32_t capacity_mAh) { if (values_valid == 0) { clear_stats(); } - if (hour > 0 && hour < 24) { - battery_per_hour[hour] = u_bat; + if (hour >= 0 && hour < 24) { + battery_volt_hourly[hour] = u_bat; + battery_charge_hourly[hour] = capacity_mAh; } } @@ -107,15 +100,16 @@ void stats_voltage(float u_bat) clear_stats(); } - if (u_bat < battery_min || battery_min == -1.0f) { - battery_min = u_bat; + if (u_bat < battery_volt_min || battery_volt_min == -1.0f) { + battery_volt_min = u_bat; } - if (u_bat > battery_max || battery_max == -1.0f) { - battery_max = u_bat; + if (u_bat > battery_volt_max || battery_volt_max == -1.0f) { + battery_volt_max = u_bat; } } + void stats_temp(float temp) { if (values_valid == 0) { @@ -236,8 +230,8 @@ const char* stats_build_text(void) return stats_text; } - const int battery_min_decivolt = 10.0f * battery_min; - const int battery_max_decivolt = 10.0f * battery_max; + const int battery_min_decivolt = 10.0f * battery_volt_min; + const int battery_max_decivolt = 10.0f * battery_volt_max; stats_end_ix += snprintf(stats_text + stats_end_ix, STATS_LEN - 1 - stats_end_ix, "U min,max= %dV%01d,%dV%01d\n" @@ -250,19 +244,34 @@ const char* stats_build_text(void) "U heures pleines= "); 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, - " ?"); + if (battery_volt_hourly[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]; - stats_end_ix += snprintf(stats_text + stats_end_ix, STATS_LEN - 1 - stats_end_ix, - " %dV%01d", + const int battery_decivolts = 10.0f * battery_volt_hourly[h]; + stats_end_ix += snprintf( + stats_text + stats_end_ix, STATS_LEN - 1 - stats_end_ix, " %dV%01d", battery_decivolts / 10, battery_decivolts % 10); } } stats_end_ix += snprintf(stats_text + stats_end_ix, STATS_LEN - 1 - stats_end_ix, + "\nCapa heures pleines= "); + + for (int h = 0; h < 24; h++) { + if (battery_charge_hourly[h] == 0) { + stats_end_ix += snprintf(stats_text + stats_end_ix, + STATS_LEN - 1 - stats_end_ix, " ?"); + } + else { + stats_end_ix += snprintf( + stats_text + stats_end_ix, STATS_LEN - 1 - stats_end_ix, " %ld", + battery_charge_hourly[h]); + } + } + + stats_end_ix += snprintf(stats_text + stats_end_ix, STATS_LEN - 1 - stats_end_ix, "\n" "Nbre de commutations eolienne= %d\n", num_wind_generator_movements); diff --git a/src/common/Core/stats.h b/src/common/Core/stats.h index 09f4c17..31d653d 100644 --- a/src/common/Core/stats.h +++ b/src/common/Core/stats.h @@ -1,7 +1,7 @@ /* * The MIT License (MIT) * - * Copyright (c) 2019 Matthias P. Braendli, Maximilien Cuony + * Copyright (c) 2020 Matthias P. Braendli, Maximilien Cuony * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -25,7 +25,7 @@ #pragma once #include <stdint.h> -void stats_voltage_at_full_hour(int hour, float u_bat); +void stats_battery_at_full_hour(int hour, float u_bat, uint32_t capacity_mAh); void stats_voltage(float u_bat); void stats_temp(float temp); diff --git a/src/common/GPIO/usart.c b/src/common/GPIO/usart.c index 6796142..02f2f07 100644 --- a/src/common/GPIO/usart.c +++ b/src/common/GPIO/usart.c @@ -131,7 +131,7 @@ int usart_get_nmea_sentence(char *nmea) { } int usart_get_ccounter_msg(char *msg) { - return xQueueReceive(usart_ccounter_queue, msg, portMAX_DELAY); + return xQueueReceive(usart_ccounter_queue, msg, pdMS_TO_TICKS(2000)); } static void usart_clear_ccounter_buffer(void) { diff --git a/src/common/sourcelist.txt b/src/common/sourcelist.txt index 47526cd..ecdd689 100644 --- a/src/common/sourcelist.txt +++ b/src/common/sourcelist.txt @@ -1,6 +1,7 @@ GPIO/analog.c GPIO/usart.c GPIO/temperature.c +GPIO/batterycharge.c GPS/gps.c GPS/minmea.c Core/common.c |