bugfix in powersaving, wrong handling voltage between cutoff and low level, sending battery voltage with startup beacon

pull/7/head
Mateusz Lubecki 2022-04-09 16:48:11 +02:00
rodzic ed5897d09b
commit da68fd3c4b
8 zmienionych plików z 54 dodań i 13 usunięć

Wyświetl plik

@ -6,7 +6,7 @@
#include "config_data.h"
#define SW_VER "EA05"
#define SW_DATE "08042022"
#define SW_DATE "09042022"
#define SYSTICK_TICKS_PER_SECONDS 100
#define SYSTICK_TICKS_PERIOD 10

Wyświetl plik

@ -465,7 +465,7 @@ int main(int argc, char* argv[]){
#endif
#if defined(STM32L471xx)
#if defined(PARAMETEO)
// initialize all powersaving functions
pwr_save_init(main_config_data_mode->powersave);
@ -589,9 +589,10 @@ int main(int argc, char* argv[]){
main_target_wx_baudrate = _SERIAL_BAUDRATE;
#if defined(STM32L471xx)
#if defined(PARAMETEO)
// swtich power to M4. turn on sensors but keep GSM modem turned off
pwr_save_switch_mode_to_m4();
#endif
// if Victron VE-direct protocol is enabled set the baudrate to the 19200u
@ -866,7 +867,7 @@ int main(int argc, char* argv[]){
led_control_led1_upper(false);
led_control_led2_bottom(false);
#if defined(STM32L471xx)
#if defined(PARAMETEO)
rte_main_battery_voltage = io_vbat_meas_get();
pwr_save_switch_mode_to_c0();
@ -918,7 +919,12 @@ int main(int argc, char* argv[]){
#endif
if (main_config_data_basic-> beacon_at_bootup == 1) {
beacon_send_own();
#if defined(PARAMETEO)
beacon_send_own(rte_main_battery_voltage);
#else
beacon_send_own(0);
#endif
}
// Infinite loop
@ -1209,12 +1215,14 @@ int main(int argc, char* argv[]){
rte_main_trigger_wx_packet = 0;
}
#ifdef STM32L471xx
#ifdef PARAMETEO
// inhibit any power save switching when modem transmits data
if (!main_afsk.sending) {
pwr_save_pooling_handler(main_config_data_mode, main_config_data_basic, packet_tx_get_minutes_to_next_wx(), rte_main_battery_voltage);
}
#endif
#ifdef STM32L471xx
if (main_config_data_mode->gsm == 1) {
retval = aprsis_connect_and_login(TEST_IP, strlen(TEST_IP), 14580);

Wyświetl plik

@ -126,7 +126,7 @@ void packet_tx_handler(const config_data_basic_t * const config_basic, const con
packet_tx_multi_per_call_handler();
beacon_send_own();
beacon_send_own(0);
packet_tx_beacon_counter = 0;

Wyświetl plik

@ -77,6 +77,17 @@ static void pwr_save_lock_rtc_backup_regs(void) {
PWR->CR1 &= (0xFFFFFFFF ^ PWR_CR1_DBP);
}
static void pwr_save_clear_powersave_idication_bits() {
// unlock access to backup registers
pwr_save_unclock_rtc_backup_regs();
// clear all previous powersave indication bits
REGISTER &= (0xFFFFFFFF ^ ALL_STATES_BITMASK);
// lock access to backup
pwr_save_lock_rtc_backup_regs();
}
/**
* This function initializes everything related to power saving features
* including programming Flash memory option bytes
@ -537,23 +548,35 @@ void pwr_save_pooling_handler(const config_data_mode_t * config, const config_da
vbatt = 0xFFFFu;
}
// check if battery voltage is below low voltage level
if (vbatt <= pwr_save_aggressive_powersave_voltage) {
// if battery voltage is low swtich to aggressive powersave mode
pwr_save_currently_cutoff |= CURRENTLY_VBATT_LOW;
psave_mode = PWSAVE_AGGRESV;
}
else if (vbatt <= pwr_save_cutoff_voltage && (pwr_save_currently_cutoff & CURRENTLY_CUTOFF) == 0) {
else {
pwr_save_currently_cutoff &= (0xFF ^ CURRENTLY_VBATT_LOW);
}
if (vbatt <= pwr_save_cutoff_voltage && ((pwr_save_currently_cutoff & CURRENTLY_CUTOFF) == 0)) {
// if the battery voltage is below cutoff level and the ParaMETEO controller is currently not cut off
pwr_save_currently_cutoff |= CURRENTLY_CUTOFF;
// clear all previous powersave indication bits as we want to go sleep being already in L7 state
pwr_save_clear_powersave_idication_bits();
// go sleep immediately and periodically check if battery has been charged above restore level
pwr_save_switch_mode_to_l7(60 * PWR_SAVE_CUTOFF_SLEEP_TIME_IN_MINUTES);
return;
}
else if (vbatt <= pwr_save_startup_restore_voltage && (pwr_save_currently_cutoff & CURRENTLY_CUTOFF) != 0) {
else if (vbatt <= pwr_save_startup_restore_voltage && ((pwr_save_currently_cutoff & CURRENTLY_CUTOFF) != 0)) {
// clear all previous powersave indication bits as we want to go sleep being already in L7 state
pwr_save_clear_powersave_idication_bits();
// if the ParaMETEO is cutted off currently but battery hasn't been charged above restore voltage
pwr_save_switch_mode_to_l7(60 * PWR_SAVE_CUTOFF_SLEEP_TIME_IN_MINUTES);
@ -561,7 +584,7 @@ void pwr_save_pooling_handler(const config_data_mode_t * config, const config_da
}
else {
// if battery level is above restore voltage and aggressive powersave voltage
pwr_save_currently_cutoff = 0;
pwr_save_currently_cutoff &= (0xFF ^ CURRENTLY_CUTOFF);
}
// get current counter values

Wyświetl plik

@ -15,7 +15,7 @@ extern "C"
{
#endif
void beacon_send_own(void);
void beacon_send_own(uint16_t voltage);
void beacon_send_on_startup(void);
void beacon_send_from_user_content(uint16_t content_ln, char* content_ptr);

Wyświetl plik

@ -27,6 +27,8 @@
#define HTTP_CLIENT_RET_TCPIP_BSY 2
#define HTTP_CLIENT_RET_WRONG_URL 3
typedef void(*http_client_response_available_t)(uint16_t http_code, char * content, uint16_t content_lenght);
/**
* HTTP code returned by the latest query. It is zeroed after each successful call to async
* function. This indicate that a request is currently in progress. Negative values means some

Wyświetl plik

@ -14,9 +14,14 @@
#include <stdio.h>
void beacon_send_own(void) {
void beacon_send_own(uint16_t voltage) {
main_wait_for_tx_complete();
main_own_aprs_msg_len = sprintf(main_own_aprs_msg, "=%s%c%c%s%c%c %s", main_string_latitude, main_config_data_basic->n_or_s, main_symbol_f, main_string_longitude, main_config_data_basic->e_or_w, main_symbol_s, main_config_data_basic->comment);
if (voltage == 0) {
main_own_aprs_msg_len = sprintf(main_own_aprs_msg, "=%s%c%c%s%c%c %s", main_string_latitude, main_config_data_basic->n_or_s, main_symbol_f, main_string_longitude, main_config_data_basic->e_or_w, main_symbol_s, main_config_data_basic->comment);
}
else {
main_own_aprs_msg_len = sprintf(main_own_aprs_msg, "=%s%c%c%s%c%c %s Vbatt %dV", main_string_latitude, main_config_data_basic->n_or_s, main_symbol_f, main_string_longitude, main_config_data_basic->e_or_w, main_symbol_s, main_config_data_basic->comment, (int)voltage);
}
main_own_aprs_msg[main_own_aprs_msg_len] = 0;
ax25_sendVia(&main_ax25, main_own_path, main_own_path_ln, main_own_aprs_msg, main_own_aprs_msg_len);
after_tx_lock = 1;

Wyświetl plik

@ -181,6 +181,9 @@ uint8_t http_client_rx_done_callback(uint8_t current_data, const uint8_t * const
case HEADER_END: {
http_client_response_header_processing = 0;
// set current offset to save a place
http_client_content_start_index = rx_bytes_counter + 1;
break;
}