kopia lustrzana https://github.com/SP8EBC/ParaTNC
rodzic
fe74e93c88
commit
c09d51d90f
|
@ -262,7 +262,7 @@
|
|||
</extensions>
|
||||
</storageModule>
|
||||
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
|
||||
<configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug" cleanCommand="${cross_rm} -rf" description="ParaMETEO" errorParsers="org.eclipse.cdt.core.GASErrorParser;org.eclipse.cdt.core.GmakeErrorParser;org.eclipse.cdt.core.GLDErrorParser;org.eclipse.cdt.core.CWDLocator;org.eclipse.cdt.core.GCCErrorParser" id="ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug.827603628.109360039" name="STM32L476_ParaMETEO" optionalBuildProperties="org.eclipse.cdt.docker.launcher.containerbuild.property.enablement=null,org.eclipse.cdt.docker.launcher.containerbuild.property.volumes=,org.eclipse.cdt.docker.launcher.containerbuild.property.connection=null,org.eclipse.cdt.docker.launcher.containerbuild.property.selectedvolumes=,org.eclipse.cdt.docker.launcher.containerbuild.property.image=null" parent="ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug">
|
||||
<configuration artifactName="${ProjName}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe,org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug" cleanCommand="${cross_rm} -rf" description="ParaMETEO" errorParsers="org.eclipse.cdt.core.GASErrorParser;org.eclipse.cdt.core.GmakeErrorParser;org.eclipse.cdt.core.GLDErrorParser;org.eclipse.cdt.core.CWDLocator;org.eclipse.cdt.core.GCCErrorParser" id="ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug.827603628.109360039" name="STM32L476_ParaMETEO" optionalBuildProperties="org.eclipse.cdt.docker.launcher.containerbuild.property.enablement=null,org.eclipse.cdt.docker.launcher.containerbuild.property.selectedvolumes=,org.eclipse.cdt.docker.launcher.containerbuild.property.volumes=,org.eclipse.cdt.docker.launcher.containerbuild.property.image=null,org.eclipse.cdt.docker.launcher.containerbuild.property.connection=null" parent="ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug">
|
||||
<folderInfo id="ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug.827603628.109360039." name="/" resourcePath="">
|
||||
<toolChain id="ilg.gnuarmeclipse.managedbuild.cross.toolchain.elf.debug.862891746" name="Cross ARM GCC" superClass="ilg.gnuarmeclipse.managedbuild.cross.toolchain.elf.debug">
|
||||
<option id="ilg.gnuarmeclipse.managedbuild.cross.option.optimization.level.1978728687" name="Optimization Level" superClass="ilg.gnuarmeclipse.managedbuild.cross.option.optimization.level" useByScannerDiscovery="true" value="ilg.gnuarmeclipse.managedbuild.cross.option.optimization.level.debug" valueType="enumerated"/>
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
</configuration>
|
||||
<configuration id="ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug.827603628.109360039" name="STM32L476_ParaMETEO">
|
||||
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
|
||||
<provider class="org.eclipse.cdt.core.language.settings.providers.LanguageSettingsGenericProvider" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider" name="CDT User Setting Entries" prefer-non-shared="true"/>
|
||||
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
|
||||
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
|
||||
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
|
||||
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="910025024327584425" id="ilg.gnuarmeclipse.managedbuild.cross.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings Cross ARM" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 \
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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_ */
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
35
src/api.c
35
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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
234
src/main.c
234
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);
|
||||
|
|
|
@ -162,6 +162,7 @@ void packet_tx_tcp_handler(void) {
|
|||
}
|
||||
// TODO: fixme
|
||||
|
||||
api_calculate_mac();
|
||||
api_send_json_measuremenets();
|
||||
|
||||
// clear the bit
|
||||
|
|
Ładowanie…
Reference in New Issue