diff --git a/include/aprsis.h b/include/aprsis.h index a1374c0..613240d 100644 --- a/include/aprsis.h +++ b/include/aprsis.h @@ -11,16 +11,20 @@ #include "drivers/serial.h" #include "gsm/sim800c_tcpip.h" -#define APRSIS_OK 0 -#define APRSIS_NOT_CONFIGURED 1 -#define APRSIS_WRONG_STATE 2 -#define APRSIS_ALREADY_CONNECTED 3 + + +typedef enum aprsis_return { + APRSIS_OK = 0, + APRSIS_NOT_CONFIGURED = 1, + APRSIS_WRONG_STATE = 2, + APRSIS_ALREADY_CONNECTED = 3 +}aprsis_return_t; extern uint8_t aprsis_connected; void aprsis_init(srl_context_t * context, gsm_sim800_state_t * gsm_modem_state, char * callsign, uint8_t ssid, uint32_t passcode, char * default_server, uint16_t default_port); -uint8_t aprsis_connect_and_login(char * address, uint8_t address_ln, uint16_t port); -uint8_t aprsis_connect_and_login_default(void); +aprsis_return_t aprsis_connect_and_login(char * address, uint8_t address_ln, uint16_t port); +aprsis_return_t aprsis_connect_and_login_default(void); void aprsis_disconnect(void); void aprsis_receive_callback(srl_context_t* srl_context); void aprsis_check_alive(void); diff --git a/include/station_config_target_hw.h b/include/station_config_target_hw.h index d1981cd..89f2175 100644 --- a/include/station_config_target_hw.h +++ b/include/station_config_target_hw.h @@ -8,22 +8,5 @@ #ifndef STATION_CONFIG_TARGET_HW_H_ #define STATION_CONFIG_TARGET_HW_H_ -//#define PARATNC_HWREV_A -//#define PARATNC_HWREV_B -//#define PARATNC_HWREV_C -#ifndef PARAMETEO -#define PARAMETEO -#endif - -#ifdef PARAMETEO -// // those defines and an undef are only required for shitty Eclipse indexer to see anything from STM32L471xx target - #undef STM32F10X_MD_VL - #ifndef STM32L471xx - #define STM32L471xx - #endif - #ifndef USE_FULL_LL_DRIVER - #define USE_FULL_LL_DRIVER - #endif -#endif #endif /* STATION_CONFIG_TARGET_HW_H_ */ diff --git a/src/api.c b/src/api.c index 3ae477c..b16f522 100644 --- a/src/api.c +++ b/src/api.c @@ -81,6 +81,8 @@ static void api_construct_url_status(api_endpoint_t endpoint) { static void api_callback(uint16_t http_code, char * content, uint16_t content_lenght) { + http_client_close(); + } diff --git a/src/aprsis.c b/src/aprsis.c index 3f0bf9f..ce31b7c 100644 --- a/src/aprsis.c +++ b/src/aprsis.c @@ -75,7 +75,12 @@ void aprsis_init(srl_context_t * context, gsm_sim800_state_t * gsm_modem_state, aprsis_passcode = (int32_t)passcode; - sprintf(aprsis_callsign_with_ssid, "%s-%d", callsign, ssid); + if (ssid != 0) { + sprintf(aprsis_callsign_with_ssid, "%s-%d", callsign, ssid); + } + else { + sprintf(aprsis_callsign_with_ssid, "%s", callsign); + } memset(aprsis_login_string, 0x00, 0x40); @@ -91,7 +96,7 @@ void aprsis_init(srl_context_t * context, gsm_sim800_state_t * gsm_modem_state, } -uint8_t aprsis_connect_and_login(char * address, uint8_t address_ln, uint16_t port) { +aprsis_return_t aprsis_connect_and_login(char * address, uint8_t address_ln, uint16_t port) { // this function has blocking io uint8_t out = APRSIS_WRONG_STATE; @@ -181,7 +186,7 @@ uint8_t aprsis_connect_and_login(char * address, uint8_t address_ln, uint16_t po } -uint8_t aprsis_connect_and_login_default(void) { +aprsis_return_t aprsis_connect_and_login_default(void) { return aprsis_connect_and_login(aprsis_default_server_address, aprsis_default_server_address_ln, aprsis_default_server_port); } diff --git a/src/io.c b/src/io.c index ac4775e..e442f2e 100644 --- a/src/io.c +++ b/src/io.c @@ -79,29 +79,19 @@ void io_pwr_init(void) { GPIO_InitTypeDef GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; - #if (defined PARATNC_HWREV_A || defined PARATNC_HWREV_B) - GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD; - #elif (defined PARATNC_HWREV_C) GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; - #else - #error ("Hardware Revision not chosen.") - #endif GPIO_Init(GPIOB, &GPIO_InitStructure); - #if (defined PARATNC_HWREV_C) // +12V PWR_CNTRL GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; GPIO_Init(GPIOA, &GPIO_InitStructure); - #endif wx_pwr_state = WX_PWR_OFF; GPIO_ResetBits(GPIOB, GPIO_Pin_8); - #if (defined PARATNC_HWREV_C) // +12V_SW PWR_CNTRL GPIO_ResetBits(GPIOA, GPIO_Pin_6); - #endif #endif diff --git a/src/main.c b/src/main.c index d9cd54f..5896e3c 100644 --- a/src/main.c +++ b/src/main.c @@ -119,6 +119,23 @@ #define CONFIG_SECOND_FAIL_RESTORING (1 << 4) #define CONFIG_SECOND_CRC_OK (1 << 5) +/** + * A foreword about '#define' mess. This software is indented to run on at least two + * different hardware platform. First which is ParaTNC basing on STM32F100 and second + * ParaMETEO using STM32L476. In future more platforms may appear. Like ParaTNC2 which + * will be a ParaMETEO without battery charging and in form factor similar to ParaTNC. + * + * To obtain such compatibility a lot of #defines and different makefiles has to be used. + * Some parts of the code are 'included' per target CPU basis, as are independent from + * target platform either directly (like handling serial port or GPIO configuration), or + * as a result of an assumption that all target plaforms with STML476 will have GSM modem. + * + * Some platforms had or may have in the future few hadware revisions. ParaTNC had + * revisions A, B and C. Currently A and B are abandoned an assumption is that all ParaTNC + * builds applies to C. A choose of hardware revision is done in file 'station_config_target_hw.h' + * which is currently empty + */ + // ----- main() --------------------------------------------------------------- // Sample pragmas to cope with warnings. Please note the related line at diff --git a/src/packet_tx_handler.c b/src/packet_tx_handler.c index 215413d..9588bca 100644 --- a/src/packet_tx_handler.c +++ b/src/packet_tx_handler.c @@ -104,6 +104,8 @@ inline void packet_tx_multi_per_call_handler(void) { void packet_tx_tcp_handler(void) { #ifdef STM32L471xx + uint8_t result = 0; + if ((packet_tx_trigger_tcp & APRSIS_TRIGGER_METEO) != 0) { // send APRS-IS frame, if APRS-IS is not connected this function will return immediately aprsis_send_wx_frame(rte_wx_average_windspeed, rte_wx_max_windspeed, rte_wx_average_winddirection, rte_wx_temperature_average_external_valid, rte_wx_pressure_valid, rte_wx_humidity_valid); @@ -147,9 +149,11 @@ void packet_tx_tcp_handler(void) { packet_tx_trigger_tcp ^= API_TRIGGER_METEO; } else if ((packet_tx_trigger_tcp & RECONNECT_APRSIS) != 0) { - aprsis_connect_and_login_default(); + result = aprsis_connect_and_login_default(); - packet_tx_trigger_tcp ^= RECONNECT_APRSIS; + if (result == APRSIS_OK) { + packet_tx_trigger_tcp ^= RECONNECT_APRSIS; + } } #endif } diff --git a/src/wx_pwr_switch.c b/src/wx_pwr_switch.c index fe4271f..f2beab1 100644 --- a/src/wx_pwr_switch.c +++ b/src/wx_pwr_switch.c @@ -76,7 +76,7 @@ void wx_pwr_switch_case_off_parameteo() { } void wx_pwr_switch_case_off_paratnc() { -#if (defined PARATNC_HWREV_C) +#if (defined STM32F10X_MD_VL) // Turn on the +12V_SW voltage GPIO_SetBits(GPIOA, GPIO_Pin_6); #endif diff --git a/system/include/http_client/http_client.h b/system/include/http_client/http_client.h index 772fe3a..b1d8be4 100644 --- a/system/include/http_client/http_client.h +++ b/system/include/http_client/http_client.h @@ -50,6 +50,7 @@ extern uint16_t http_client_max_content_ln; void http_client_init(gsm_sim800_state_t * state, srl_context_t * serial_context, uint8_t ignore_content_on_http_error); uint8_t http_client_async_get(char * url, uint8_t url_ln, uint16_t response_ln_limit, uint8_t force_disconnect_on_busy, http_client_response_available_t callback_on_response); uint8_t http_client_async_post(char * url, uint8_t url_ln, char * data_to_post, uint16_t data_ln, uint8_t force_disconnect_on_busy, http_client_response_available_t callback_on_response); +void http_client_close(void); char * http_client_get_server_response(); uint16_t http_client_get_latest_http_code(); diff --git a/system/src/gsm/sim800c_tcpip.c b/system/src/gsm/sim800c_tcpip.c index 76fe115..eee3d85 100644 --- a/system/src/gsm/sim800c_tcpip.c +++ b/system/src/gsm/sim800c_tcpip.c @@ -238,6 +238,9 @@ void gsm_sim800_tcpip_close(srl_context_t * srl_context, gsm_sim800_state_t * st // wait for OK to be received srl_receive_data_with_callback(srl_context, gsm_sim800_escape_terminating_callback); + // start timeout calculation + srl_context->srl_rx_timeout_calc_started = 1; + // wait for it to finish srl_wait_for_rx_completion_or_timeout(srl_context, & receive_result); diff --git a/system/src/http_client/http_client.c b/system/src/http_client/http_client.c index 355c618..b7c2ebc 100644 --- a/system/src/http_client/http_client.c +++ b/system/src/http_client/http_client.c @@ -382,6 +382,10 @@ uint8_t http_client_async_post(char * url, uint8_t url_ln, char * data_to_post, return out; } +void http_client_close(void) { + gsm_sim800_tcpip_close(http_client_deticated_serial_context, http_client_deticated_sim800_state, 1); + +} char * http_client_get_server_response() { return 0;