diff --git a/.cproject b/.cproject index ffe5525..4fb3533 100644 --- a/.cproject +++ b/.cproject @@ -262,7 +262,7 @@ - + - + diff --git a/STM32L476_ParaMETEO/makefile b/STM32L476_ParaMETEO/makefile index 7c62800..c40cb5e 100644 --- a/STM32L476_ParaMETEO/makefile +++ b/STM32L476_ParaMETEO/makefile @@ -15,6 +15,7 @@ RM := rm -rf -include system/src/modbus_rtu/subdir.mk -include system/src/http_client/subdir.mk -include system/src/gsm/subdir.mk +-include system/src/dust_sensor/subdir.mk -include system/src/drivers/l4/subdir.mk -include system/src/drivers/subdir.mk -include system/src/diag/subdir.mk diff --git a/STM32L476_ParaMETEO/sources.mk b/STM32L476_ParaMETEO/sources.mk index a6c6c65..09aeb9a 100644 --- a/STM32L476_ParaMETEO/sources.mk +++ b/STM32L476_ParaMETEO/sources.mk @@ -35,6 +35,7 @@ system/src/davis_vantage \ system/src/diag \ system/src/drivers \ system/src/drivers/l4 \ +system/src/dust_sensor \ system/src/gsm \ system/src/http_client \ system/src/modbus_rtu \ diff --git a/STM32L476_ParaMETEO/system/src/davis_vantage/subdir.mk b/STM32L476_ParaMETEO/system/src/davis_vantage/subdir.mk index 5db2f3d..6918645 100644 --- a/STM32L476_ParaMETEO/system/src/davis_vantage/subdir.mk +++ b/STM32L476_ParaMETEO/system/src/davis_vantage/subdir.mk @@ -5,18 +5,15 @@ # Add inputs and outputs from these tool invocations to the build variables C_SRCS += \ ../system/src/davis_vantage/davis.c \ -../system/src/davis_vantage/davis_parsers.c \ -../system/src/davis_vantage/sds011.c +../system/src/davis_vantage/davis_parsers.c OBJS += \ ./system/src/davis_vantage/davis.o \ -./system/src/davis_vantage/davis_parsers.o \ -./system/src/davis_vantage/sds011.o +./system/src/davis_vantage/davis_parsers.o C_DEPS += \ ./system/src/davis_vantage/davis.d \ -./system/src/davis_vantage/davis_parsers.d \ -./system/src/davis_vantage/sds011.d +./system/src/davis_vantage/davis_parsers.d # Each subdirectory must supply rules for building sources it contributes diff --git a/include/api/api.h b/include/api/api.h index 6dca09a..2014123 100644 --- a/include/api/api.h +++ b/include/api/api.h @@ -9,6 +9,7 @@ #define API_H_ void api_init(char * api_base, char * station_name); +void api_calculate_mac(void); void api_send_json_status(void); void api_send_json_measuremenets(void); diff --git a/include/config_data.h b/include/config_data.h index 480a4aa..16768f3 100644 --- a/include/config_data.h +++ b/include/config_data.h @@ -87,6 +87,7 @@ typedef struct __attribute__((aligned (4))) config_data_basic_t { #define ENGINEERING1 (1) #define ENGINEERING1_INH_WX_PWR_HNDL (1 << 1) + #define ENGINEERING1_EARLY_TX_ASSERT (1 << 2) char callsign[7]; @@ -128,7 +129,7 @@ typedef struct __attribute__((aligned (4))) config_data_basic_t { /** * bit0 - must be set to zero to enable this engineering * bit1 - inhibit 'wx_pwr_switch_periodic_handle' - * bit2 - + * bit2 - early_tx_assert * bit3 - * bit4 - * bit5 - @@ -195,6 +196,8 @@ typedef struct __attribute__((aligned (4))) config_data_umb_t { uint16_t channel_temperature; uint16_t channel_qnh; + + uint16_t serial_speed; /** * #define _UMB_CHANNEL_WINDSPEED 460 #define _UMB_CHANNEL_WINDGUSTS 440 diff --git a/include/configuration_handler.h b/include/configuration_handler.h index e4a1d77..e3729ad 100644 --- a/include/configuration_handler.h +++ b/include/configuration_handler.h @@ -39,5 +39,6 @@ configuration_handler_region_t configuration_get_current(uint32_t * size); const uint32_t * configuration_get_address(configuration_handler_region_t region); int configuration_get_inhibit_wx_pwr_handle(void); +int configuration_get_early_tx_assert(void); #endif /* CONFIGURATION_HANDLER_H_ */ diff --git a/include/kiss_communication.h b/include/kiss_communication.h index 60e0bfd..d3a4e90 100644 --- a/include/kiss_communication.h +++ b/include/kiss_communication.h @@ -23,6 +23,8 @@ #define TFEND (uint8_t)0xDC #define TFESC (uint8_t)0xDD + #define NONSTANDARD (uint8_t)0x0F + #define KISS_DATA (uint8_t) 0x00 #define KISS_GET_RUNNING_CONFIG (uint8_t) 0x20 diff --git a/include/main.h b/include/main.h index e912cde..39ef756 100644 --- a/include/main.h +++ b/include/main.h @@ -8,7 +8,7 @@ #include "config_data.h" #define SW_VER "EA16" -#define SW_DATE "19092022" +#define SW_DATE "20092022" #define SW_KISS_PROTO "A" #define SYSTICK_TICKS_PER_SECONDS 100 @@ -37,6 +37,17 @@ #define REGISTER_LAST_SLTIM RTC->BKP6R #endif +typedef enum main_usart_mode_t { + USART_MODE_UNDEF, + USART_MODE_KISS, + USART_MODE_VICTRON, + USART_MODE_DUST_SDS, + USART_MODE_DAVIS, + USART_MODE_MODBUS, + USART_MODE_UMB_MASTER, + USART_MODE_UNINIT +}main_usart_mode_t; + extern uint32_t master_time; extern const config_data_mode_t * main_config_data_mode; diff --git a/src/api.c b/src/api.c index eb76987..79592bd 100644 --- a/src/api.c +++ b/src/api.c @@ -111,6 +111,41 @@ void api_init(const char * api_base, const char * station_name) { memset(api_mac, '0', 32); } + +void api_calculate_mac(void) { + + // iterators used during conversion to hex string after encryption + int i = 0, j = 0; + + memset(api_aes_mac_buffer, 0x00, 16); + memset(api_mac, 0x00, 33); + + api_aes_mac_buffer[0] = (uint8_t)((master_time & 0xFF)); + api_aes_mac_buffer[1] = (uint8_t)((master_time & 0xFF00) >> 8); + api_aes_mac_buffer[2] = (uint8_t)((master_time & 0xFF0000) >> 16); + api_aes_mac_buffer[3] = (uint8_t)((master_time & 0xFF000000) >> 24); + api_aes_mac_buffer[4] = (uint8_t)((rte_main_average_battery_voltage & 0xFF)); + api_aes_mac_buffer[5] = (uint8_t)((rte_main_average_battery_voltage & 0xFF00) >> 8); + api_aes_mac_buffer[6] = (uint8_t)((rte_wx_average_winddirection & 0xFF)); + api_aes_mac_buffer[7] = (uint8_t)((rte_wx_average_winddirection & 0xFF00) >> 8); + api_aes_mac_buffer[8] = (uint8_t)((rte_wx_average_windspeed & 0xFF)); + api_aes_mac_buffer[9] = (uint8_t)((rte_wx_average_windspeed & 0xFF00) >> 8); + api_aes_mac_buffer[10] = (uint8_t)((rte_wx_max_windspeed & 0xFF)); + api_aes_mac_buffer[11] = (uint8_t)((rte_wx_max_windspeed & 0xFF00) >> 8); + api_aes_mac_buffer[12] = (uint8_t)((rte_wx_pm2_5 & 0xFF)); + api_aes_mac_buffer[13] = (uint8_t)((rte_wx_pm2_5 & 0xFF00) >> 8); + api_aes_mac_buffer[14] = (uint8_t)((rte_wx_temperature_average_dallas & 0xFF)); + api_aes_mac_buffer[15] = (uint8_t)((rte_wx_temperature_average_dallas & 0xFF00) >> 8); + + AES_CBC_encrypt_buffer(&api_aes_context, api_aes_mac_buffer, 16); + + for (i = 0; i < 16; i++) { + snprintf(api_mac + j, 3, "%02X", api_aes_mac_buffer[i]); + j += 2; + } + +} + void api_send_json_status(void) { BEGIN PRINT_ALL_STATUS diff --git a/src/configuration_handler.c b/src/configuration_handler.c index 3994a70..1f6685c 100644 --- a/src/configuration_handler.c +++ b/src/configuration_handler.c @@ -42,9 +42,9 @@ #define CONFIG_MODE_PGM_CNTR 0x0 #define CONFIG_MODE_OFSET 0x20 // Current size: 0x10, free: 0x10 -#define CONFIG_BASIC_OFFSET 0x40 // Current size: 0x9C, free: 0x44 +#define CONFIG_BASIC_OFFSET 0x40 // Current size: 0x9D, free: 0x43 #define CONFIG_SOURCES_OFFSET 0x120 // Current size: 0x4, free: 0x1C -#define CONFIG_UMB_OFFSET 0x140 // Current size: 0x10, free: 0x10 +#define CONFIG_UMB_OFFSET 0x140 // Current size: 0x12, free: 0xE #define CONFIG_RTU_OFFSET 0x160 // Current size: 0x54, free: 0x4C #define CONFIG_GSM_OFFSET 0x200 // Current size: 0xF8, #define CONFIG__END__OFFSET 0x300 @@ -827,3 +827,15 @@ int configuration_get_inhibit_wx_pwr_handle(void) { return out; } +int configuration_get_early_tx_assert(void) { + int out = 0; + + if ((main_config_data_basic->engineering1 & ENGINEERING1) == 0) { + if ((main_config_data_basic->engineering1 & ENGINEERING1_EARLY_TX_ASSERT) != 0) { + out = 1; + } + } + + return out; +} + diff --git a/src/kiss_callback.c b/src/kiss_callback.c index ad491e0..6246d1a 100644 --- a/src/kiss_callback.c +++ b/src/kiss_callback.c @@ -19,7 +19,7 @@ uint8_t kiss_async_message_counter = 0; int32_t kiss_callback_get_running_config(uint8_t* input_frame_from_host, uint16_t input_len, uint8_t* response_buffer, uint16_t buffer_size) { - #define CALLBACK_GET_RUNNING_CFG_LN 6 + #define CALLBACK_GET_RUNNING_CFG_LN 7 uint32_t conf_size = 0; @@ -40,14 +40,15 @@ int32_t kiss_callback_get_running_config(uint8_t* input_frame_from_host, uint16_ // construct a response response_buffer[0] = FEND; - response_buffer[1] = CALLBACK_GET_RUNNING_CFG_LN; // message lenght - response_buffer[2] = KISS_RUNNING_CONFIG; - response_buffer[3] = (uint8_t)(current_region & 0xFF); + response_buffer[1] = NONSTANDARD; + response_buffer[2] = CALLBACK_GET_RUNNING_CFG_LN; // message lenght + response_buffer[3] = KISS_RUNNING_CONFIG; + response_buffer[4] = (uint8_t)(current_region & 0xFF); if ((conf_size % KISS_MAX_CONFIG_PAYLOAD_SIZE) == 0) - response_buffer[4] = (uint8_t)(conf_size / KISS_MAX_CONFIG_PAYLOAD_SIZE); + response_buffer[5] = (uint8_t)(conf_size / KISS_MAX_CONFIG_PAYLOAD_SIZE); else - response_buffer[4] = (uint8_t)(conf_size / KISS_MAX_CONFIG_PAYLOAD_SIZE + 1); - response_buffer[5] = FEND; + response_buffer[5] = (uint8_t)(conf_size / KISS_MAX_CONFIG_PAYLOAD_SIZE + 1); + response_buffer[6] = FEND; return CALLBACK_GET_RUNNING_CFG_LN; @@ -98,16 +99,17 @@ int16_t kiss_pool_callback_get_running_config(uint8_t * output_buffer, uint16_t // place KISS header output_buffer[0] = FEND; - output_buffer[1] = config_payload_size + 6; - output_buffer[2] = KISS_RUNNING_CONFIG; - output_buffer[3] = 0xAB; // THIS IS A DATA FRAME, not ACK - output_buffer[4] = kiss_async_message_counter - 1; // frame sequence number + output_buffer[1] = NONSTANDARD; + output_buffer[2] = config_payload_size + 7; + output_buffer[3] = KISS_RUNNING_CONFIG; + output_buffer[4] = 0xAB; // THIS IS A DATA FRAME, not ACK + output_buffer[5] = kiss_async_message_counter - 1; // frame sequence number - memcpy(output_buffer + 5, config_base_address + offset, config_payload_size); + memcpy(output_buffer + 6, config_base_address + offset, config_payload_size); - output_buffer[config_payload_size + 5] = FEND; + output_buffer[config_payload_size + 6] = FEND; - return config_payload_size + 6; + return config_payload_size + 7; } int32_t kiss_callback_get_version_id(uint8_t* input_frame_from_host, uint16_t input_len, uint8_t* response_buffer, uint16_t buffer_size) { @@ -122,27 +124,31 @@ int32_t kiss_callback_get_version_id(uint8_t* input_frame_from_host, uint16_t in // construct a response response_buffer[0] = FEND; - response_buffer[1] = config_payload_size + 4; // message lenght - response_buffer[2] = KISS_VERSION_AND_ID; + response_buffer[1] = NONSTANDARD; + response_buffer[2] = config_payload_size + 5; // message lenght + response_buffer[3] = KISS_VERSION_AND_ID; // string here - response_buffer[config_payload_size + 3] = FEND; + response_buffer[config_payload_size + 4] = FEND; - return config_payload_size + 4; + return config_payload_size + 5; } int32_t kiss_callback_erase_startup(uint8_t* input_frame_from_host, uint16_t input_len, uint8_t* response_buffer, uint16_t buffer_size) { +#define ERASE_STARTUP_LN 6 + configuration_erase_startup_t result = configuration_handler_erase_startup(); // construct a response response_buffer[0] = FEND; - response_buffer[1] = 5; // message lenght - response_buffer[2] = KISS_ERASE_STARTUP_CFG_RESP; - response_buffer[3] = result; - response_buffer[4] = FEND; + response_buffer[1] = NONSTANDARD; + response_buffer[2] = ERASE_STARTUP_LN; // message lenght + response_buffer[3] = KISS_ERASE_STARTUP_CFG_RESP; + response_buffer[4] = result; + response_buffer[5] = FEND; - return 5; + return ERASE_STARTUP_LN; } /** @@ -152,6 +158,8 @@ int32_t kiss_callback_erase_startup(uint8_t* input_frame_from_host, uint16_t inp */ int32_t kiss_callback_program_startup(uint8_t* input_frame_from_host, uint16_t input_len, uint8_t* response_buffer, uint16_t buffer_size) { +#define PROGRAM_STARTUP_LN 6 + /** * The structure of input frame goes like that: * FEND, LN, KISS_PROGRAM_STARTUP_CFG, OFFSET, data, data, (...), FEND @@ -175,10 +183,11 @@ int32_t kiss_callback_program_startup(uint8_t* input_frame_from_host, uint16_t i // construct a response response_buffer[0] = FEND; - response_buffer[1] = 5; // message lenght - response_buffer[2] = KISS_PROGRAM_STARTUP_CFG_RESP; - response_buffer[3] = result; - response_buffer[4] = FEND; + response_buffer[1] = NONSTANDARD; + response_buffer[2] = PROGRAM_STARTUP_LN; // message lenght + response_buffer[3] = KISS_PROGRAM_STARTUP_CFG_RESP; + response_buffer[4] = result; + response_buffer[5] = FEND; - return 5; + return PROGRAM_STARTUP_LN; } diff --git a/src/main.c b/src/main.c index 7d14077..f418185 100644 --- a/src/main.c +++ b/src/main.c @@ -195,6 +195,12 @@ srl_context_t main_wx_srl_ctx; srl_context_t main_gsm_srl_ctx; #endif +// operation mode of USART1 (RS232 on RJ45 socket) +main_usart_mode_t main_usart1_kiss_mode = USART_MODE_UNDEF; + +// operation mode of USART2 (RS485) +main_usart_mode_t main_usart2_wx_mode = USART_MODE_UNDEF; + // a pointer to KISS context srl_context_t* main_kiss_srl_ctx_ptr; @@ -568,7 +574,6 @@ int main(int argc, char* argv[]){ #endif main_target_kiss_baudrate = 9600u; - main_target_wx_baudrate = _SERIAL_BAUDRATE; #if defined(PARAMETEO) @@ -587,89 +592,152 @@ int main(int argc, char* argv[]){ } #endif - + // get target working mode of USART1 if (main_config_data_mode->wx_davis == 1) { - // reinitialize the KISS serial port temporary to davis baudrate - main_target_kiss_baudrate = DAVIS_DEFAULT_BAUDRATE; - - // reset RX state to allow reinitialization with changed baudrate - main_kiss_srl_ctx_ptr->srl_rx_state = SRL_RX_NOT_CONFIG; - - // reinitializing serial hardware to wake up Davis wx station - srl_init(main_kiss_srl_ctx_ptr, USART1, srl_usart1_rx_buffer, RX_BUFFER_1_LN, srl_usart1_tx_buffer, TX_BUFFER_1_LN, main_target_kiss_baudrate, 1); - - srl_switch_timeout(main_kiss_srl_ctx_ptr, SRL_TIMEOUT_ENABLE, 3000); - - davis_init(main_kiss_srl_ctx_ptr); - - // try to wake up the davis base - rte_wx_davis_station_avaliable = (davis_wake_up(DAVIS_BLOCKING_IO) == 0 ? 1 : 0); - - // if davis weather stations is connected to SERIAL port - if (rte_wx_davis_station_avaliable == 1) { - // turn LCD backlight on.. - davis_control_backlight(1); - - // wait for a while - delay_fixed(1000); - - // and then off to let the user know that communication is working - davis_control_backlight(0); - - // disable the KISS modem as the UART will be used for DAVIS wx station - main_kiss_enabled = 0; - - // enable the davis serial protocol client to allow pooling callbacks to be called in main loop. - // This only controls the callback it doesn't mean that the station itself is responding to - // communication. It stays set to one event if Davis station - main_davis_serial_enabled = 1; - - // trigger the rxcheck to get all counter values - davis_trigger_rxcheck_packet(); - - } - else { - // if not revert back to KISS configuration - main_target_kiss_baudrate = 9600u; - main_kiss_srl_ctx_ptr->srl_rx_state = SRL_RX_NOT_CONFIG; - - // initializing UART drvier - srl_init(main_kiss_srl_ctx_ptr, USART1, srl_usart1_rx_buffer, RX_BUFFER_1_LN, srl_usart1_tx_buffer, TX_BUFFER_1_LN, main_target_kiss_baudrate, 1); - srl_init(main_wx_srl_ctx_ptr, USART2, srl_usart2_rx_buffer, RX_BUFFER_2_LN, srl_usart2_tx_buffer, TX_BUFFER_2_LN, main_target_wx_baudrate, 1); - - } + main_usart1_kiss_mode = USART_MODE_DAVIS; } - else if (main_config_data_mode->wx_modbus == 1) { - - rtu_serial_init(&rte_rtu_pool_queue, 1, main_wx_srl_ctx_ptr, main_config_data_rtu); - - main_target_wx_baudrate = main_config_data_rtu->slave_speed; - - // initialize serial ports according to RS485 network configuration for Modbus-RTU - srl_init(main_kiss_srl_ctx_ptr, USART1, srl_usart1_rx_buffer, RX_BUFFER_1_LN, srl_usart1_tx_buffer, TX_BUFFER_1_LN, main_target_kiss_baudrate, 1); - srl_init(main_wx_srl_ctx_ptr, USART2, srl_usart2_rx_buffer, RX_BUFFER_2_LN, srl_usart2_tx_buffer, TX_BUFFER_2_LN, main_target_wx_baudrate, main_config_data_rtu->slave_stop_bits); - srl_switch_tx_delay(main_wx_srl_ctx_ptr, 1); - - // enabling rtu master code - main_modbus_rtu_master_enabled = 1; - - rtu_serial_start(); + else if ((main_config_data_mode->wx_dust_sensor & WX_DUST_SDS011_SERIAL) > 0) { + main_usart1_kiss_mode = USART_MODE_DUST_SDS; + } + else if (main_config_data_mode->victron == 1) { + main_usart1_kiss_mode = USART_MODE_VICTRON; } else { - if ((main_config_data_mode->wx_dust_sensor & WX_DUST_SDS011_SERIAL) > 0) { - srl_init(main_kiss_srl_ctx_ptr, USART1, srl_usart1_rx_buffer, RX_BUFFER_1_LN, srl_usart1_tx_buffer, TX_BUFFER_1_LN, 9600u, 1); - srl_init(main_wx_srl_ctx_ptr, USART2, srl_usart2_rx_buffer, RX_BUFFER_2_LN, srl_usart2_tx_buffer, TX_BUFFER_2_LN, main_target_wx_baudrate, 1); - - // disable kiss as UART will be now used for dust sensor - main_kiss_enabled = 0; - } - else { - // initializing UART drvier - srl_init(main_kiss_srl_ctx_ptr, USART1, srl_usart1_rx_buffer, RX_BUFFER_1_LN, srl_usart1_tx_buffer, TX_BUFFER_1_LN, main_target_kiss_baudrate, 1); - srl_init(main_wx_srl_ctx_ptr, USART2, srl_usart2_rx_buffer, RX_BUFFER_2_LN, srl_usart2_tx_buffer, TX_BUFFER_2_LN, main_target_wx_baudrate, 1); - } + main_usart1_kiss_mode = USART_MODE_KISS; } + // get target working mode for USART2 + if (main_config_data_mode->wx_modbus == 1) { + main_usart2_wx_mode = USART_MODE_MODBUS; + } + else if (main_config_data_mode->wx_umb == 1) { + main_usart2_wx_mode = USART_MODE_UMB_MASTER; + } + else { + main_usart2_wx_mode = USART_MODE_UNINIT; + } + + switch (main_usart1_kiss_mode) { + case USART_MODE_DAVIS: { + // reinitialize the KISS serial port temporary to davis baudrate + main_target_kiss_baudrate = DAVIS_DEFAULT_BAUDRATE; + + // reset RX state to allow reinitialization with changed baudrate + main_kiss_srl_ctx_ptr->srl_rx_state = SRL_RX_NOT_CONFIG; + + // reinitializing serial hardware to wake up Davis wx station + srl_init(main_kiss_srl_ctx_ptr, USART1, srl_usart1_rx_buffer, RX_BUFFER_1_LN, srl_usart1_tx_buffer, TX_BUFFER_1_LN, main_target_kiss_baudrate, 1); + + srl_switch_timeout(main_kiss_srl_ctx_ptr, SRL_TIMEOUT_ENABLE, 3000); + + davis_init(main_kiss_srl_ctx_ptr); + + // try to wake up the davis base + rte_wx_davis_station_avaliable = (davis_wake_up(DAVIS_BLOCKING_IO) == 0 ? 1 : 0); + + // if davis weather stations is connected to SERIAL port + if (rte_wx_davis_station_avaliable == 1) { + // turn LCD backlight on.. + davis_control_backlight(1); + + // wait for a while + delay_fixed(1000); + + // and then off to let the user know that communication is working + davis_control_backlight(0); + + // disable the KISS modem as the UART will be used for DAVIS wx station + main_kiss_enabled = 0; + + // enable the davis serial protocol client to allow pooling callbacks to be called in main loop. + // This only controls the callback it doesn't mean that the station itself is responding to + // communication. It stays set to one event if Davis station + main_davis_serial_enabled = 1; + + // trigger the rxcheck to get all counter values + davis_trigger_rxcheck_packet(); + + } + else { + // if not revert back to KISS configuration + main_target_kiss_baudrate = 9600u; + main_kiss_srl_ctx_ptr->srl_rx_state = SRL_RX_NOT_CONFIG; + + // initializing UART drvier + srl_init(main_kiss_srl_ctx_ptr, USART1, srl_usart1_rx_buffer, RX_BUFFER_1_LN, srl_usart1_tx_buffer, TX_BUFFER_1_LN, main_target_kiss_baudrate, 1); + + main_usart1_kiss_mode = USART_MODE_KISS; + } + break; + } + case USART_MODE_DUST_SDS: { + srl_init(main_kiss_srl_ctx_ptr, USART1, srl_usart1_rx_buffer, RX_BUFFER_1_LN, srl_usart1_tx_buffer, TX_BUFFER_1_LN, 9600u, 1); + + main_kiss_enabled = 0; + + break; + } + case USART_MODE_VICTRON: { + break; + } + case USART_MODE_KISS: { + srl_init(main_kiss_srl_ctx_ptr, USART1, srl_usart1_rx_buffer, RX_BUFFER_1_LN, srl_usart1_tx_buffer, TX_BUFFER_1_LN, main_target_kiss_baudrate, 1); + + main_kiss_enabled = 1; + + break; + } + case USART_MODE_MODBUS: + case USART_MODE_UMB_MASTER: + case USART_MODE_UNINIT: + case USART_MODE_UNDEF: + main_kiss_enabled = 0; + break; + } + + switch (main_usart2_wx_mode) { + case USART_MODE_MODBUS: { + rtu_serial_init(&rte_rtu_pool_queue, 1, main_wx_srl_ctx_ptr, main_config_data_rtu); + + main_target_wx_baudrate = main_config_data_rtu->slave_speed; + + srl_init(main_wx_srl_ctx_ptr, USART2, srl_usart2_rx_buffer, RX_BUFFER_2_LN, srl_usart2_tx_buffer, TX_BUFFER_2_LN, main_target_wx_baudrate, main_config_data_rtu->slave_stop_bits); + srl_switch_tx_delay(main_wx_srl_ctx_ptr, 1); + + // enabling rtu master code + main_modbus_rtu_master_enabled = 1; + + rtu_serial_start(); + + break; + } + case USART_MODE_UMB_MASTER: { + main_target_wx_baudrate = main_config_data_umb->serial_speed; + + srl_init(main_wx_srl_ctx_ptr, USART2, srl_usart2_rx_buffer, RX_BUFFER_2_LN, srl_usart2_tx_buffer, TX_BUFFER_2_LN, main_target_wx_baudrate, 1); + umb_master_init(&rte_wx_umb_context, main_wx_srl_ctx_ptr, main_config_data_umb); + + break; + } + case USART_MODE_DAVIS: + case USART_MODE_DUST_SDS: + case USART_MODE_VICTRON: + case USART_MODE_KISS: + case USART_MODE_UNINIT: + case USART_MODE_UNDEF: + break; + } + +// if (main_config_data_mode->wx_davis == 1) { +// ; +// } +// else if (main_config_data_mode->wx_modbus == 1) { +// ; +// } +// else { +// ; +// } + #if defined(STM32F10X_MD_VL) main_wx_srl_ctx_ptr->te_pin = GPIO_Pin_8; main_wx_srl_ctx_ptr->te_port = GPIOA; @@ -677,7 +745,7 @@ int main(int argc, char* argv[]){ #if defined(STM32L471xx) main_wx_srl_ctx_ptr->te_pin = LL_GPIO_PIN_8; main_wx_srl_ctx_ptr->te_port = GPIOA; - main_wx_srl_ctx_ptr->early_tx_assert = 1; // TODO: move to configuration!! + main_wx_srl_ctx_ptr->early_tx_assert = configuration_get_early_tx_assert(); // TODO: was 1 srl_init(main_gsm_srl_ctx_ptr, USART3, srl_usart3_rx_buffer, RX_BUFFER_3_LN, srl_usart3_tx_buffer, TX_BUFFER_3_LN, 115200, 1); #endif @@ -739,10 +807,10 @@ int main(int argc, char* argv[]){ dallas_init(GPIOC, LL_GPIO_PIN_11, 0x0, &rte_wx_dallas_average); #endif - if (main_config_data_mode->wx_umb == 1) { - // client initialization - umb_master_init(&rte_wx_umb_context, main_wx_srl_ctx_ptr, main_config_data_umb); - } +// if (main_config_data_mode->wx_umb == 1) { +// // client initialization +// umb_master_init(&rte_wx_umb_context, main_wx_srl_ctx_ptr, main_config_data_umb); +// } if ((main_config_data_mode->wx & WX_INTERNAL_SPARKFUN_WIND) == 0) { analog_anemometer_init(main_config_data_mode->wx_anemometer_pulses_constant, 38, 100, 1); diff --git a/src/packet_tx_handler.c b/src/packet_tx_handler.c index f6b5d7f..e0a88df 100644 --- a/src/packet_tx_handler.c +++ b/src/packet_tx_handler.c @@ -162,6 +162,7 @@ void packet_tx_tcp_handler(void) { } // TODO: fixme + api_calculate_mac(); api_send_json_measuremenets(); // clear the bit diff --git a/system/src/davis_vantage/sds011.c b/system/src/dust_sensor/sds011.c similarity index 100% rename from system/src/davis_vantage/sds011.c rename to system/src/dust_sensor/sds011.c