diff --git a/doc/CURRENT-DRAW-MEASUREMENTS b/doc/CURRENT-DRAW-MEASUREMENTS new file mode 100644 index 0000000..0780ef5 --- /dev/null +++ b/doc/CURRENT-DRAW-MEASUREMENTS @@ -0,0 +1,11 @@ +Yaesu FTH-2010 as a radio with 1W output power. All measured on B+ 12V line + + +deep sleep: 1mA +GSM off, sensors off, radio off: 10mA +GSM off, sensors off, radio on receiving: 65mA +GSM off, sensors on, radio on receiving: 80mA +GSM on (idle GPRS/TCP not connected), sensor on, radio on receiving: 94mA +GSM on (idle GPRS/TCP connected 99mA), sensor on, radio on receiving: 99mA +GSM on (comm with network), sensors on, radio on recieving: 125mA +GSM off, sensors on, radio on txing: 650mA \ No newline at end of file diff --git a/doc/eclipse_debugger_launch/ParaMETEO-STM32L476RG.launch b/doc/eclipse_debugger_launch/ParaMETEO-STM32L476RG.launch index 89203d3..c6c6350 100644 --- a/doc/eclipse_debugger_launch/ParaMETEO-STM32L476RG.launch +++ b/doc/eclipse_debugger_launch/ParaMETEO-STM32L476RG.launch @@ -58,6 +58,6 @@ - + diff --git a/include/io.h b/include/io.h index 10a57b9..bf8e69e 100644 --- a/include/io.h +++ b/include/io.h @@ -174,6 +174,17 @@ inline uint8_t io_get_cntrl_vbat_s(void) { return out; } + +inline uint8_t io_get_cntrl_vbat_m(void) { + uint8_t out = 0; + + if ((GPIOB->ODR & GPIO_BSRR_BS0) != 0) { + out = 1; + } + + return out; +} + #else inline uint8_t io_get_cntrl_vbat_s(void) { return 0; diff --git a/include/main.h b/include/main.h index c6c49b7..0fc5aee 100644 --- a/include/main.h +++ b/include/main.h @@ -11,7 +11,7 @@ #include "gsm/sim800_state_t.h" #define SW_VER "EA24" -#define SW_DATE "21072023" +#define SW_DATE "22072023" #define SW_KISS_PROTO "B" #define SYSTICK_TICKS_PER_SECONDS 100 diff --git a/include/packet_tx_handler.h b/include/packet_tx_handler.h index ba820a5..197ab0a 100644 --- a/include/packet_tx_handler.h +++ b/include/packet_tx_handler.h @@ -27,5 +27,6 @@ void packet_tx_handler(const config_data_basic_t * const config_basic, const con void packet_tx_get_current_counters(packet_tx_counter_values_t * out); void packet_tx_set_current_counters(packet_tx_counter_values_t * in); int16_t packet_tx_get_minutes_to_next_wx(void); +void packet_tx_force_gsm_status(void); #endif /* PACKET_TX_HANDLER_H_ */ diff --git a/include/pwr_save.h b/include/pwr_save.h index 2df8f73..e9dbc62 100644 --- a/include/pwr_save.h +++ b/include/pwr_save.h @@ -23,8 +23,8 @@ * | C1 |Running| ON | ON | OFF | ON | * | C2 |Running| OFF | ON | OFF | ON | * | C3 |Running| OFF | ON | ON | ON | - * | M4 |Running| ON | OFF | OFF | OFF | - * | M4a |Running| ON | OFF | ON | OFF | + * | M4 |Running| ON | OFF | OFF | ON | + * | M4a |Running| ON | OFF | ON | ON | * | I5 |Running| OFF | OFF | OFF | OFF | * | L6 | Stop2 | OFF | OFF | ON | OFF | * | L7 | Stop2 | OFF | OFF | OFF | OFF | @@ -123,7 +123,7 @@ int pwr_save_switch_mode_to_m4a(void); void pwr_save_switch_mode_to_i5(void); void pwr_save_switch_mode_to_l6(uint16_t sleep_time); void pwr_save_switch_mode_to_l7(uint16_t sleep_time); -void pwr_save_pooling_handler(const config_data_mode_t * config, const config_data_basic_t * timers, int16_t minutes_to_wx, uint16_t vbatt); // this should be called from 10 seconds pooler +config_data_powersave_mode_t pwr_save_pooling_handler(const config_data_mode_t * config, const config_data_basic_t * timers, int16_t minutes_to_wx, uint16_t vbatt); // this should be called from 10 seconds pooler #endif diff --git a/include/rte_main.h b/include/rte_main.h index a32f5f3..9a12336 100644 --- a/include/rte_main.h +++ b/include/rte_main.h @@ -3,6 +3,7 @@ #define RTE_MAIN_H_ #include +#include "stored_configuration_nvm/config_data.h" extern uint8_t rte_main_reboot_req; @@ -25,4 +26,6 @@ extern uint32_t rte_main_last_sleep_master_time; extern uint8_t rte_main_reset_gsm_modem; +extern config_data_powersave_mode_t rte_main_curret_powersave_mode; + #endif diff --git a/include/station_config_test_wakeup_adc.h b/include/station_config_test_wakeup_adc.h new file mode 100644 index 0000000..d92a051 --- /dev/null +++ b/include/station_config_test_wakeup_adc.h @@ -0,0 +1,338 @@ +/* + * config.h + * + * Created on: 03.07.2017 + * Author: mateusz + */ + +#ifndef STATION_CONFIG_H_ +#define STATION_CONFIG_H_ + +#define _POWERSAVE_NORMAL +//#define _POWERSAVE_AGGRESIVE +//!< --------------------------- +//!< MODES OF OPERATION + +#define _METEO // Enable meteo station + +#define _DIGI // Enable WIDE1-1 digipeater +//#define _DIGI_VISCOUS +//#define _DIGI_ONLY_789 // Limit digipeater to handle only -7, -8 and -9 SSIDs + +#define _GSM // only for ParaMETEO +//#define _GSM_KEEP_MODEM_ALWAYS_ON + +#define _WX_DOUBLE_TRANSMIT + +//!< MODES OF OPERATION +//!< --------------------------- + +/** + * Enable support for Victron VE.Direct protocol. This is independent from wx sensor configuration + */ +//#define _VICTRON + +//!< --------------------------- +//!< WEATHER/METEO CONFIGURATION + +/** + * Three defines below enables or disabled listed communication drivers. Enabling any of then doesn't means + * that these are used as a data source automatically. That shall be set in 'DATA SOURCES CONFIG' section. + */ + +//#define _UMB_MASTER +//#define _DAVIS_SERIAL +#define _MODBUS_RTU // use Modbus RTU slave devices as a external meteo data source. For more configuration + // (slave ids, registers...) please look into MODBUS RTU CONFIGURATION section of this file + +#define _INTERNAL_AS_BACKUP // if defined ParaTNC will switch to internal sensors in case of + // the communication with UMB/Dallas Serial/Modbus external sensors will hang up + + +//#define _DALLAS_AS_TELEM // Use Dallas one-wire thermometer as a 5th telemetry channel + // May be used even if _METEO is not enabled +#define _DALLAS_SPLIT_PIN // Must be enabled for all ParaTNC hardware revisions + +/******** INTERNAL SENSORS CONFIGURATION *****************/ + +//#define _ANEMOMETER_TX20 // Use TX20 as an internal anemometer +#define _ANEMOMETER_ANALOGUE // Use analogue/mechanical (like Davis 6410) as an internal anemometr +#define _ANEMOMETER_PULSES_IN_10SEC_PER_ONE_MS_OF_WINDSPEED 10 + +#define _SENSOR_MS5611 +//#define _SENSOR_BME280 +/******** INTERNAL SENSORS CONFIGURATION *****************/ + + +/******** UMB MASTER CONFIGURATION *****************/ +#define _UMB_SLAVE_ID 1 +#define _UMB_SLAVE_CLASS 8 +#define _UMB_CHANNEL_WINDSPEED 460 +#define _UMB_CHANNEL_WINDGUSTS 440 +#define _UMB_CHANNEL_WINDDIRECTION 580 +#define _UMB_CHANNEL_TEMPERATURE 100 +#define _UMB_CHANNEL_QFE 300 +/******** UMB MASTER CONFIGURATION *****************/ + + +/*************** DATA SOURCES CONFIG ***********************/ +#define _TEMPERATURE_INTERNAL +//#define _TEMPERATURE_UMB +//#define _TEMPERATURE_RTU +//#define _TEMPERATURE_DAVIS +// +#define _PRESSURE_INTERNAL +//#define _PRESSURE_UMB +//#define _PRESSURE_RTU +//#define _PRESSURE_DAVIS +// +//#define _HUMIDITY_INTERNAL +//#define _HUMIDITY_UMB +#define _HUMIDITY_RTU +//#define _HUMIDITY_DAVIS +// +// +#define _WIND_INTERNAL +//#define _WIND_UMB +//#define _WIND_RTU +//#define _WIND_FULL_RTU +//#define _WIND_DAVIS +/*************** DATA SOURCES CONFIG ***********************/ + +//!< WEATHER/METEO CONFIGURATION +//!< --------------------------- + + +//!< ------------------------------------- +//!< BASIC CONFIG - CALLSIGN, LOCATION etc + +//#define _MUTE_RF // TODO: Not yet implemented - This will make station RXonly and disable all data transmission +//#define _MUTE_OWN // TODO: Not yet implemented - This will disable all self-generated packets (wx, telemetry, beacon) + // and switch device to "pure" kiss TNC operation. Packets from PC will be transmitted normally. + +// Coordines should be in APRS decimal format DDDMM.SS for Longitude and DDMM.SS for latitude +#define _CALL "SP8EBC" +#define _SSID 0 +#define _LAT 4948.81 +#define _LATNS 'N' +#define _LON 01903.50 +#define _LONWE 'E' +#define _COMMENT "testing" + +// You can use only one of these below defines to choose symbol. Meteo data are are always transmitted with blue WX symbol +//#define _SYMBOL_DIGI // uncomment if you want digi symbol(green star with D inside) +//#define _SYMBOL_WIDE1_DIGI // uncomment if you want 'little' digi symbol (green star with digit 1 overlaid) +//#define _SYMBOL_HOUSE // uncomment if you want house symbol +//#define _SYMBOL_RXIGATE // uncomment if you want rxigate symbol (black diamond with R) +#define _SYMBOL_IGATE // uncomment if you want igate symol (black diamond with I) +//#define _SYMBOL_SAILBOAT + +// Or you can keep commented all symbol defines and choose custom one based on data from APRS symbols table +//#define _SYMBOL_F '/' +//#define _SYMBOL_S '#' + +// Uncomment one of these two defines to choose what path You want. If you uncommend both of them or +// if you keep both commended path will be completely disabled. CALL-S>AKLPRZ:data +//#define _WIDE1_PATH // CALL-S>AKLPRZ,WIDE1-1:data +//#define _WIDE21_PATH // CALL-S>AKLPRZ,WIDE2-1:data + +// Comment this to disable beacon auto sending during startup (this can be risky if RF feedback occur) +#define _BCN_ON_STARTUP + +#define _WX_INTERVAL 3 // WX packet interval in minutes +#define _BCN_INTERVAL 124 // Own beacon interval in minutes + +#define _PTT_PUSHPULL // Uncomment this if you want PTT line to work as Push-pull instead of Open Drain +#define _SERIAL_BAUDRATE 9600 + +#define _DIGI_VISCOUS_DEALY 2 + +// Transmitting delay +#define _DELAY_BASE 19 // * 50ms. For example setting 10 gives 500msec delay. Maximum value is 20 +//#define _RANDOM_DELAY // adds random delay TO fixed time set by _DELAY_BASE. This additional time can be + // from 100ms up to 1 sec in 100ms steps. Values are drawn from samples going from ADC + // so it is better to use Unsquelched output in radio to provide much more randomness +//After waiting time declared above ParaTNC will check DCD (Data Carrier Detect) flag, which works as some +//kind of semaphore. If radio channel is not occupied by any other transmission TX will be keyed up immediately, +//otherwise software will wait for clear conditions. + +//!< BASIC CONFIG - CALLSIGN, LOCATION etc +//!< ------------------------------------- + +// Few IMPORTANT hints about setting transmit delay properly. +// +// Transmit delay is key parameter to maintain RF network free from packet losses and collisions. If your station will be +// installed on tall object, without any other digi's close to it, you can set _DELAY_BASE to very low value and disable +// _RANDOM_DELAY. If you wanna rather auxiliary station, witch should only fill gap in RF coverage in small area, then +// _DELAY_BASE parameter should be not less than 12 (600msec), the smallest range the higher _DELAY_BASE should be. +// Additionally for gapfillers (auxiliary stations) _RANDOM_DELAY schould be enabled. +// +// This delay will ensure that while other station will be transmitting repeated packets from mobile, Yours will keep +// always quiet and won't jam RF network. This greatly improve DCD based access to channel. Various controllers uses +// various lenght of preamble, some of them produce signal which might be impossible to decode by ParaTNC, so DCD +// is only one part of effective multiaccess to medium. + +//!< ------- +//!< BUTTONS + +#define _BUTTON_ONE_LEFT BUTTON_FUNCTION_SEND_BEACON +#define _BUTTON_TWO_RIGHT BUTTON_FUNCION_RESET_GSM_GPRS + +//!< BUTTONS +//!< ------- + +//!< ------------------------ +//!< MODBUS RTU CONFIGURATION + +// scaling coefficients are used as follows +// +// A * x ^ 2 + B * x + C +// real value = --------------------------- +// D +// +// because of that D cannot be set to zero +// +// scaling for temperature shall be set to get *10 temperature +// as an output of getter / 123 -> 12.3 oC +#define _RTU_SLAVE_SPEED 9600u +#define _RTU_SLAVE_PARITY 0 +#define _RTU_SLAVE_STOP_BITS 2 + +#define _RTU_SLAVE_ID_1 0x01 +#define _RTU_SLAVE_FUNC_1 0x03 +#define _RTU_SLAVE_ADDR_1 0x00 +#define _RTU_SLAVE_LENGHT_1 0x01 +#define _RTU_SLAVE_SCALING_A_1 0 +#define _RTU_SLAVE_SCALING_B_1 1 +#define _RTU_SLAVE_SCALING_C_1 0 +#define _RTU_SLAVE_SCALING_D_1 1 + +#define _RTU_SLAVE_ID_2 0x01 +#define _RTU_SLAVE_FUNC_2 0x03 +#define _RTU_SLAVE_ADDR_2 0x01 +//#define _RTU_SLAVE_LENGHT_2 0x01 +#define _RTU_SLAVE_SCALING_A_2 0 +#define _RTU_SLAVE_SCALING_B_2 1 +#define _RTU_SLAVE_SCALING_C_2 0 +#define _RTU_SLAVE_SCALING_D_2 1 + +#define _RTU_SLAVE_ID_3 0x01 +#define _RTU_SLAVE_FUNC_3 0x03 +#define _RTU_SLAVE_ADDR_3 0x02 +//#define _RTU_SLAVE_LENGHT_3 0x01 +#define _RTU_SLAVE_SCALING_A_3 0 +#define _RTU_SLAVE_SCALING_B_3 1 +#define _RTU_SLAVE_SCALING_C_3 0 +#define _RTU_SLAVE_SCALING_D_3 1 + +#define _RTU_SLAVE_ID_4 0x01 +#define _RTU_SLAVE_FUNC_4 0x03 +#define _RTU_SLAVE_ADDR_4 0x03 +//#define _RTU_SLAVE_LENGHT_4 0x01 +#define _RTU_SLAVE_SCALING_A_4 0 +#define _RTU_SLAVE_SCALING_B_4 1 +#define _RTU_SLAVE_SCALING_C_4 0 +#define _RTU_SLAVE_SCALING_D_4 1 + +#define _RTU_SLAVE_ID_5 0x00 +#define _RTU_SLAVE_FUNC_5 0x00 +#define _RTU_SLAVE_ADDR_5 0x03 +//#define _RTU_SLAVE_LENGHT_4 0x01 +#define _RTU_SLAVE_SCALING_A_5 0 +#define _RTU_SLAVE_SCALING_B_5 1 +#define _RTU_SLAVE_SCALING_C_5 0 +#define _RTU_SLAVE_SCALING_D_5 1 + + +#define _RTU_SLAVE_ID_6 0x00 +#define _RTU_SLAVE_FUNC_6 0x00 +#define _RTU_SLAVE_ADDR_6 0x00 +//#define _RTU_SLAVE_LENGHT_4 0x01 +#define _RTU_SLAVE_SCALING_A_6 0 +#define _RTU_SLAVE_SCALING_B_6 1 +#define _RTU_SLAVE_SCALING_C_6 0 +#define _RTU_SLAVE_SCALING_D_6 1 + +#define _RTU_SLAVE_TEMPERATURE_SOURCE 1 +#define _RTU_SLAVE_HUMIDITY_SOURCE 2 +//#define _RTU_SLAVE_PRESSURE_SOURCE 3 +//#define _RTU_SLAVE_WIND_DIRECTION_SORUCE 4 +//#define _RTU_SLAVE_WIND_SPEED_SOURCE 4 + +//!< MODBUS RTU CONFIGURATION +//!< ------------------------ + +//!< ----------------------- +//!< GSM and APRS-IS and API + +#define _GSM_APN_NAME "internet\0" +#define _GSM_APN_USER "internet\0" +#define _GSM_APN_PASS "internet\0" + +//#define _GSM_API_ENABLE +#define _GSM_API_BASE_URL "http://157.25.103.93:22910/" +#define _GSM_API_STATION_NAME "bielsko" + +#define _GSM_APRSIS_ENABLE +#define _GSM_APRSIS_PASSCODE 23220 +#define _GSM_APRSIS_PORT 14580 +//#define _GSM_APRSIS_ADDRES "euro.aprs2.net\0" +#define _GSM_APRSIS_ADDRES "78.88.56.14\0" + + +//!< GSM and APRS-IS and API +//!< ----------------------- + +//#define ENG1 ENGINEERING1_EARLY_TX_ASSERT | ENGINEERING1_PWRCYCLE_GSM_ON_NOCOMM +#define ENG1 ENGINEERING1_INH_WX_PWR_HNDL +//#define ENG2 ENGINEERING2_POWER_CYCLE_R + +// Do not touch this +#if defined (_SYMBOL_DIGI) && !defined (_SYMBOL_WIDE1_DIGI) && !defined (_SYMBOL_HOUSE) && !defined (_SYMOL_RXIGATE) &&\ + !defined (_SYMBOL_IGATE) +#define _SYMBOL_F '/' +#define _SYMBOL_S '#' +#elif !defined (_SYMBOL_DIGI) && defined (_SYMBOL_WIDE1_DIGI) && !defined (_SYMBOL_HOUSE) && !defined (_SYMOL_RXIGATE) &&\ + !defined (_SYMBOL_IGATE) +#define _SYMBOL_F '1' +#define _SYMBOL_S '#' +#elif !defined (_SYMBOL_DIGI) && !defined (_SYMBOL_WIDE1_DIGI) && defined (_SYMBOL_HOUSE) && !defined (_SYMOL_RXIGATE) &&\ + !defined (_SYMBOL_IGATE) +#define _SYMBOL_F '/' +#define _SYMBOL_S '-' +#elif !defined (_SYMBOL_DIGI) && !defined (_SYMBOL_WIDE1_DIGI) && !defined (_SYMBOL_HOUSE) && defined (_SYMOL_RXIGATE) &&\ + !defined (_SYMBOL_IGATE) +#define _SYMBOL_F 'I' +#define _SYMBOL_S '&' +#elif !defined (_SYMBOL_DIGI) && !defined (_SYMBOL_WIDE1_DIGI) && !defined (_SYMBOL_HOUSE) && !defined (_SYMOL_RXIGATE) &&\ + defined (_SYMBOL_IGATE) +#define _SYMBOL_F 'R' +#define _SYMBOL_S '&' +#elif !defined (_SYMBOL_DIGI) && !defined (_SYMBOL_WIDE1_DIGI) && !defined (_SYMBOL_HOUSE) && !defined (_SYMOL_RXIGATE) &&\ + !defined (_SYMBOL_IGATE) && defined(_SYMBOL_SAILBOAT) +#define _SYMBOL_F '/' +#define _SYMBOL_S 'Y' +#elif !defined (_SYMBOL_F) && !defined (_SYMBOL_S) +#error "Missing symbol configuration in station_config.h" +#elif defined (_SYMBOL_F) && defined (_SYMBOL_S) +#else +#error "Wrong symbol configuration in station_config.h" +#endif +//#if defined (_METEO) && !defined (_DIGI) +//#define _DIGI +//#endif + + +#if defined(_ANEMOMETER_TX20) && defined(_ANEMOMETER_ANALOGUE) +#error "You cannot use two anemometers at once!!!" +#endif + +#if defined(_MOBUS_RTU) && defined(_DAVIS_SERIAL) +#error "You cannot use modbus RTU devices and Davis weather station at once!!!" +#endif + +#if !defined(_ANEMOMETER_TX20) && !defined(_ANEMOMETER_ANALOGUE) && !defined(_UMB_MASTER) && defined(_METEO) +#define _ANEMOMETER_TX20 +#endif + +#endif /* STATION_CONFIG_H_ */ diff --git a/src/aprsis.c b/src/aprsis.c index 2bc2997..7a18894 100644 --- a/src/aprsis.c +++ b/src/aprsis.c @@ -6,12 +6,15 @@ */ #include "aprsis.h" -#include "main.h" -#include "text.h" - #include "etc/aprsis_config.h" +#include "text.h" +#include "aprs/status.h" #include "gsm/sim800c.h" +#include "gsm/sim800c_poolers.h" + +#include "main.h" +#include "rte_main.h" #include #include @@ -84,7 +87,7 @@ const char * aprsis_sucessfull_login = "# logresp\0"; /** * Counter of unsuccessful connects to APRS-IS, to trigger GSM modem reset. * Please note that it works differently that 'aprsis_reset_on_timeout' and - * has nothing to do with a timeouts of already established connection. This + * has nothing to do with a timeout of already established connection. This * counter will trigger GSM modem reset even if no APRS-IS connection has * been established at all. It protects against a situation when GSM modem * is not able to register in cellular network, SIM card is not working for @@ -263,14 +266,14 @@ aprsis_return_t aprsis_connect_and_login(const char * address, uint8_t address_l // if a connection has been ordered to close, but there were severe errors during that if (disconnection_result == SIM800_TCP_CLOSE_UNCERTAIN || - disconnection_result == SIM800_RECEIVING_TIMEOUT || + //disconnection_result == SIM800_RECEIVING_TIMEOUT || aprsis_unsucessfull_conn_counter > APRSIS_FAILED_CONN_ATTEMPTS_TO_RESET_GSM) { - // reset unsuccesfull connection counter back to zero - aprsis_unsucessfull_conn_counter = 0; - // and reset GSM modem gsm_sim800_reset(aprsis_gsm_modem_state); + + // reset unsuccesfull connection counter back to zero + aprsis_unsucessfull_conn_counter = 0; } } @@ -291,13 +294,18 @@ aprsis_return_t aprsis_connect_and_login_default(uint8_t auto_send_beacon) { sim800_return_t aprsis_disconnect(void) { - sim800_return_t out; + sim800_return_t out = SIM800_UNSET; - out = gsm_sim800_tcpip_close(aprsis_serial_port, aprsis_gsm_modem_state, 0); + if (aprsis_connected == 1) { - aprsis_logged = 0; + out = gsm_sim800_tcpip_close(aprsis_serial_port, aprsis_gsm_modem_state, 0); - aprsis_connected = 0; + aprsis_logged = 0; + + aprsis_connected = 0; + + gsm_sim800_poolers_request_engineering(); + } return out; } @@ -334,6 +342,11 @@ void aprsis_check_alive(void) { aprsis_connected = 0; + if (rte_main_curret_powersave_mode != PWSAVE_AGGRESV) { + // send a status message that APRS-IS connectios is gone + status_send_aprsis_timeout(aprsis_unsucessfull_conn_counter); + } + // check if it is intendend to reset GSM modem in case of timeout if (aprsis_reset_on_timeout == 0) { // close connection with force flag as it is uncertain if a remote server @@ -542,6 +555,18 @@ void aprsis_igate_to_aprsis(AX25Msg *msg, const char * callsign_with_ssid) { memcpy(aprsis_packet_tx_buffer + tx_buffer_it, msg->info, payload_ln); + // move iterator forward by payload size + tx_buffer_it += payload_ln; + + // put newline at the end + aprsis_packet_tx_buffer[tx_buffer_it++] = '\r'; + aprsis_packet_tx_buffer[tx_buffer_it++] = '\n'; + + aprsis_packet_tx_message_size = strlen(aprsis_packet_tx_buffer); + + + gsm_sim800_tcpip_async_write((uint8_t *)aprsis_packet_tx_buffer, aprsis_packet_tx_message_size, aprsis_serial_port, aprsis_gsm_modem_state); + } diff --git a/src/io.c b/src/io.c index bbc3320..daa22dc 100644 --- a/src/io.c +++ b/src/io.c @@ -35,9 +35,13 @@ typedef enum io_pool_vbat_r_state_t { #if defined(PARAMETEO) LL_GPIO_InitTypeDef GPIO_InitTypeDef; +//!< coefficient used to convert value read by ADC into battery volage int16_t io_vbat_a_coeff = 0, io_vbat_b_coeff = 0; +//!< lenght of an average buffer #define VBATT_HISTORY_LN 16 + +//!< circular buffer used to calculate average battery voltage static uint16_t io_vbatt_history[VBATT_HISTORY_LN]; static uint8_t io_vbatt_history_it = 0; diff --git a/src/main.c b/src/main.c index ce3bc41..f845ff4 100644 --- a/src/main.c +++ b/src/main.c @@ -576,6 +576,9 @@ int main(int argc, char* argv[]){ io_buttons_init(); } + // get initial powersave mode + rte_main_curret_powersave_mode = main_config_data_mode->powersave; + // initialize all powersaving functions pwr_save_init(main_config_data_mode->powersave); @@ -1130,8 +1133,8 @@ int main(int argc, char* argv[]){ // restart ADCs io_vbat_meas_enable(); - ADCStartConfig(); - DACStartConfig(); +// ADCStartConfig(); +// DACStartConfig(); rte_main_battery_voltage = io_vbat_meas_get(); rte_main_average_battery_voltage = io_vbat_meas_average(rte_main_battery_voltage); @@ -1146,6 +1149,13 @@ int main(int argc, char* argv[]){ ax25_new_msg_rx_flag = 0; main_ax25.dcd = false; + DA_Init(); + ADCStartConfig(); + DACStartConfig(); + AFSK_Init(&main_afsk); + ax25_init(&main_ax25, &main_afsk, 0, message_callback, 0); + TimerConfig(); + main_woken_up = 0; main_set_monitor(1); @@ -1314,7 +1324,7 @@ int main(int argc, char* argv[]){ } } // if modbus rtu master is enabled - else if (main_modbus_rtu_master_enabled == 1) { + else if (main_modbus_rtu_master_enabled == 1 && io_get_cntrl_vbat_m() == 1) { rtu_serial_pool(); } @@ -1568,7 +1578,15 @@ int main(int argc, char* argv[]){ rte_wx_umb_qf = umb_get_current_qf(&rte_wx_umb_context, master_time); } - wx_pool_anemometer(main_config_data_wx_sources, main_config_data_mode, main_config_data_umb, main_config_data_rtu); + #ifdef STM32L471xx + if (io_get_cntrl_vbat_s() == 1) { + #else + if (io_get_5v_isol_sw___cntrl_vbat_s() == 1) { + #endif + // pool anemometer only when power is applied + wx_pool_anemometer(main_config_data_wx_sources, main_config_data_mode, main_config_data_umb, main_config_data_rtu); + } + if (main_davis_serial_enabled == 1) { diff --git a/src/packet_tx_handler.c b/src/packet_tx_handler.c index 1ac1eea..b2a3da3 100644 --- a/src/packet_tx_handler.c +++ b/src/packet_tx_handler.c @@ -546,23 +546,26 @@ void packet_tx_handler(const config_data_basic_t * const config_basic, const con } #ifdef STM32L471xx - // if gsm modem is enabled - if (main_config_data_mode->gsm != 0) { - // if gprs is connected - if (gsm_sim800_gprs_ready == 1) { - // if no gsm status packet has been sent so far - if (packet_tx_gsm_status_sent == 0) { + // if powersave mode allow to sent extensive status messages + if (rte_main_curret_powersave_mode != PWSAVE_AGGRESV) { + // if gsm modem is enabled + if (main_config_data_mode->gsm != 0) { + // if gprs is connected + if (gsm_sim800_gprs_ready == 1) { + // if no gsm status packet has been sent so far + if (packet_tx_gsm_status_sent == 0) { - // send a status - status_send_gsm(); + // send a status + status_send_gsm(); - // network parameters are not queries while APRS-IS connection is pending - // so no sense to send status more than once after the initialization - packet_tx_gsm_status_sent = 1; + // network parameters are not queries while APRS-IS connection is pending + // so no sense to send status more than once after the initialization + packet_tx_gsm_status_sent = 1; + } + } + else { + packet_tx_gsm_status_sent = 0; } - } - else { - packet_tx_gsm_status_sent = 0; } } #endif @@ -617,3 +620,6 @@ int16_t packet_tx_get_minutes_to_next_wx(void) { } } +void packet_tx_force_gsm_status(void) { + packet_tx_gsm_status_sent = 0; +} diff --git a/src/pwr_save.c b/src/pwr_save.c index a7b158d..d125132 100644 --- a/src/pwr_save.c +++ b/src/pwr_save.c @@ -21,6 +21,7 @@ #include "status.h" #include "afsk_pr.h" #include "gsm/sim800c.h" +#include "aprsis.h" #include "rte_main.h" @@ -339,6 +340,9 @@ int pwr_save_switch_mode_to_c1(void) { return 0; } + // disconnect APRS-IS connection if it is established + aprsis_disconnect(); + // turn ON +5V_S (and internal VHF radio module in HW-RevB) io___cntrl_vbat_s_enable(); @@ -380,6 +384,9 @@ void pwr_save_switch_mode_to_c2(void) { return; } + // disconnect APRS-IS connection if it is established + aprsis_disconnect(); + // turn OFF +5V_S (and internal VHF radio module in HW-RevB) io___cntrl_vbat_s_disable(); @@ -455,6 +462,9 @@ int pwr_save_switch_mode_to_m4(void) { return 0; } + // disconnect APRS-IS connection if it is established + aprsis_disconnect(); + // turn ON +5V_S (and internal VHF radio module in HW-RevB) io___cntrl_vbat_s_enable(); @@ -530,6 +540,9 @@ void pwr_save_switch_mode_to_i5(void) { return; } + // disconnect APRS-IS connection if it is established + aprsis_disconnect(); + // turn OFF +5V_S (and internal VHF radio module in HW-RevB) io___cntrl_vbat_s_disable(); @@ -644,6 +657,9 @@ void pwr_save_switch_mode_to_l7(uint16_t sleep_time) { main_set_monitor(26); + // disconnect APRS-IS connection if it is established + aprsis_disconnect(); + // disable ADC used for vbat measurement io_vbat_meas_disable(); @@ -697,7 +713,7 @@ void pwr_save_switch_mode_to_l7(uint16_t sleep_time) { main_set_monitor(25); } -void pwr_save_pooling_handler(const config_data_mode_t * config, const config_data_basic_t * timers, int16_t minutes_to_wx, uint16_t vbatt) { +config_data_powersave_mode_t pwr_save_pooling_handler(const config_data_mode_t * config, const config_data_basic_t * timers, int16_t minutes_to_wx, uint16_t vbatt) { // this function should be called from 10 seconds pooler int reinit_sensors = 0; @@ -764,7 +780,7 @@ void pwr_save_pooling_handler(const config_data_mode_t * config, const config_da // 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; + return psave_mode; } if ((pwr_save_currently_cutoff & CURRENTLY_VBATT_LOW) != 0) { @@ -1046,6 +1062,7 @@ void pwr_save_pooling_handler(const config_data_mode_t * config, const config_da // analog_anemometer_timer_irq(); } + return psave_mode; } uint8_t pwr_save_get_inhibit_pwr_switch_periodic(void) { diff --git a/src/rte_main.c b/src/rte_main.c index 17083a9..e5a7c4b 100644 --- a/src/rte_main.c +++ b/src/rte_main.c @@ -31,5 +31,7 @@ uint16_t rte_main_going_sleep_count = 0; uint32_t rte_main_last_sleep_master_time = 0; uint8_t rte_main_reset_gsm_modem = 0; + +config_data_powersave_mode_t rte_main_curret_powersave_mode; #endif diff --git a/src/wx_handler.c b/src/wx_handler.c index a357dbf..96c029b 100644 --- a/src/wx_handler.c +++ b/src/wx_handler.c @@ -183,14 +183,14 @@ void wx_pool_anemometer(const config_data_wx_sources_t * const config_sources, c int32_t modbus_retval; uint16_t scaled_windspeed = 0; -#ifdef STM32L471xx - if (io_get_cntrl_vbat_c() == 0) { -#else - if (io_get_5v_isol_sw___cntrl_vbat_s() == 0) { -#endif - // inhibit any measurement when power is not applied to sensors - return; - } +//#ifdef STM32L471xx +// if (io_get_cntrl_vbat_c() == 0) { +//#else +// if (io_get_5v_isol_sw___cntrl_vbat_s() == 0) { +//#endif +// // inhibit any measurement when power is not applied to sensors +// return; +// } wx_wind_pool_call_counter++; diff --git a/system/include/aprs/status.h b/system/include/aprs/status.h index 944cb75..3ac43a0 100644 --- a/system/include/aprs/status.h +++ b/system/include/aprs/status.h @@ -18,6 +18,7 @@ void status_send_powersave_cutoff(uint16_t battery_voltage, int8_t vbatt_low, in void status_send_powersave_registers(uint32_t register_last_sleep, uint32_t register_last_wakeup, uint32_t register_counters, uint32_t monitor, uint32_t last_sleep_time); void status_send_gsm(void); +void status_send_aprsis_timeout(uint8_t unsuccessfull_conn_cntr); #endif /* INCLUDE_APRS_STATUS_H_ */ diff --git a/system/src/aprs/status.c b/system/src/aprs/status.c index c73112f..717a75b 100644 --- a/system/src/aprs/status.c +++ b/system/src/aprs/status.c @@ -131,3 +131,18 @@ void status_send_gsm(void){ afsk_txStart(&main_afsk); } + +void status_send_aprsis_timeout(uint8_t unsuccessfull_conn_cntr) { + main_wait_for_tx_complete(); + + // clear buffer + memset(main_own_aprs_msg, 0x00, sizeof(main_own_aprs_msg)); + + // create message buffer + main_own_aprs_msg_len = sprintf(main_own_aprs_msg, ">[APRS-IS timeout][aprsis_unsucessfull_conn_counter: %d]", (int)unsuccessfull_conn_cntr); + + // send message on radio + ax25_sendVia(&main_ax25, main_own_path, main_own_path_ln, main_own_aprs_msg, main_own_aprs_msg_len); + afsk_txStart(&main_afsk); +} + diff --git a/system/src/gsm/sim800c_poolers.c b/system/src/gsm/sim800c_poolers.c index 0fb432c..5188581 100644 --- a/system/src/gsm/sim800c_poolers.c +++ b/system/src/gsm/sim800c_poolers.c @@ -12,6 +12,8 @@ #include "aprsis.h" +#include "packet_tx_handler.h" + #include //!< Set to one externally to request engineering, get one time at startup by default @@ -64,6 +66,9 @@ void gsm_sim800_poolers_one_second(srl_context_t * srl_context, gsm_sim800_state // engineering request is single shot sim800_poolers_request_engineering = 0; + // request + packet_tx_force_gsm_status(); + return; } } @@ -74,3 +79,7 @@ void gsm_sim800_poolers_one_second(srl_context_t * srl_context, gsm_sim800_state } } + +void gsm_sim800_poolers_request_engineering(void) { + sim800_poolers_request_engineering = 1; +}