SP8EBC-ParaTNC/src/rte_wx.c

124 wiersze
3.6 KiB
C
Czysty Zwykły widok Historia

2019-01-26 17:02:19 +00:00
/*
* rte_wx.c
*
* Created on: 26.01.2019
* Author: mateusz
*/
2019-01-26 22:18:25 +00:00
#include <rte_wx.h>
#include <wx_handler.h>
#include "main.h"
2019-01-26 17:02:19 +00:00
2020-09-29 20:46:31 +00:00
2019-01-26 17:02:19 +00:00
float rte_wx_temperature_dallas = 0.0f, rte_wx_temperature_dallas_valid = 0.0f;
float rte_wx_temperature_dalls_slew_rate = 0.0f;
float rte_wx_temperature_average_dallas_valid = 0.0f;
float rte_wx_temperature_min_dallas_valid = 0.0f, rte_wx_temperature_max_dallas_valid = 0.0f;
float rte_wx_temperature_ms = 0.0f, rte_wx_temperature_ms_valid = 0.0f;
2019-01-26 17:02:19 +00:00
float rte_wx_pressure = 0.0f, rte_wx_pressure_valid = 0.0f;
float rte_wx_pressure_history[PRESSURE_AVERAGE_LN];
uint8_t rte_wx_pressure_it;
2019-01-26 17:02:19 +00:00
2019-12-27 21:07:24 +00:00
uint16_t rte_wx_windspeed_pulses = 0;
uint16_t rte_wx_windspeed[WIND_AVERAGE_LEN];
uint8_t rte_wx_windspeed_it = 0;
uint16_t rte_wx_winddirection[WIND_AVERAGE_LEN];
uint8_t rte_wx_winddirection_it = 0;
uint16_t rte_wx_winddirection_last = 0;
uint16_t rte_wx_average_windspeed = 0;
uint16_t rte_wx_max_windspeed = 0;
int16_t rte_wx_average_winddirection = 0;
2019-12-27 21:07:24 +00:00
2020-06-24 16:45:06 +00:00
int8_t rte_wx_humidity = 0, rte_wx_humidity_valid = 0;
uint8_t rte_wx_tx20_excessive_slew_rate = 0;
2019-01-26 17:02:19 +00:00
dht22Values rte_wx_dht, rte_wx_dht_valid; // quality factor inside this structure
dallas_qf_t rte_wx_current_dallas_qf, rte_wx_error_dallas_qf = DALLAS_QF_UNKNOWN;
dallas_average_t rte_wx_dallas_average;
#ifdef _SENSOR_MS5611
ms5611_qf_t rte_wx_ms5611_qf = MS5611_QF_UNKNOWN;
#endif
#ifdef _SENSOR_BME280
bme280_qf_t rte_wx_bme280_qf = BME280_QF_UKNOWN;
#endif
analog_wind_qf_t rte_wx_wind_qf = AN_WIND_QF_UNKNOWN;
2019-01-26 17:02:19 +00:00
#ifdef _UMB_MASTER
umb_frame_t rte_wx_umb;
2020-03-07 18:13:24 +00:00
umb_context_t rte_wx_umb_context;
2020-03-20 21:53:24 +00:00
uint8_t rte_wx_umb_last_status = 0;
int16_t rte_wx_umb_channel_values[UMB_CHANNELS_STORAGE_CAPAC][2]; // first dimension stores the channel number and the second one
2020-04-10 20:54:30 +00:00
// stores the value in 0.1 incremenets
#endif
2020-04-10 20:54:30 +00:00
umb_qf_t rte_wx_umb_qf = UMB_QF_UNITIALIZED;
2020-09-20 12:13:24 +00:00
uint8_t rte_wx_davis_station_avaliable = 0;
uint8_t rte_wx_davis_loop_packet_avaliable = 0;
davis_loop_t rte_wx_davis_loop_content;
#ifdef _MODBUS_RTU
#if defined(_RTU_SLAVE_ID_1) && (_RTU_SLAVE_FUNC_1 == 0x03 || _RTU_SLAVE_FUNC_1 == 0x04)
2020-09-29 20:46:31 +00:00
rtu_register_data_t RTU_GETTERS_F1_NAME;
2020-09-20 12:13:24 +00:00
#endif
#if defined(_RTU_SLAVE_ID_2) && (_RTU_SLAVE_FUNC_2 == 0x03 || _RTU_SLAVE_FUNC_2 == 0x04)
2020-09-29 20:46:31 +00:00
rtu_register_data_t RTU_GETTERS_F2_NAME;
2020-09-20 12:13:24 +00:00
#endif
#if defined(_RTU_SLAVE_ID_3) && (_RTU_SLAVE_FUNC_3 == 0x03 || _RTU_SLAVE_FUNC_3 == 0x04)
2020-09-29 20:46:31 +00:00
rtu_register_data_t RTU_GETTERS_F3_NAME;
2020-09-20 12:13:24 +00:00
#endif
#if defined(_RTU_SLAVE_ID_4) && (_RTU_SLAVE_FUNC_4 == 0x03 || _RTU_SLAVE_FUNC_4 == 0x04)
2020-09-29 20:46:31 +00:00
rtu_register_data_t RTU_GETTERS_F4_NAME;
2020-09-20 12:13:24 +00:00
#endif
#if defined(_RTU_SLAVE_ID_5) && (_RTU_SLAVE_FUNC_5 == 0x03 || _RTU_SLAVE_FUNC_5 == 0x04)
rtu_register_data_t RTU_GETTERS_F5_NAME;
#endif
#if defined(_RTU_SLAVE_ID_6) && (_RTU_SLAVE_FUNC_6 == 0x03 || _RTU_SLAVE_FUNC_6 == 0x04)
rtu_register_data_t RTU_GETTERS_F6_NAME;
#endif
2020-09-28 19:50:06 +00:00
rtu_exception_t rte_wx_last_modbus_exception;
uint32_t rte_wx_last_modbus_exception_timestamp;
uint32_t rte_wx_last_modbus_rx_error_timestamp;
rtu_pool_queue_t rte_wx_rtu_pool_queue;
2020-09-28 19:50:06 +00:00
2020-09-20 12:13:24 +00:00
#endif
void rte_wx_init(void) {
int i = 0;
2019-01-26 17:02:19 +00:00
for (; i < WIND_AVERAGE_LEN; i++) {
rte_wx_windspeed[i] = 0;
rte_wx_winddirection[i] = 0;
}
rte_wx_pressure_it = 0;
for (i = 0; i < 4; i++) {
rte_wx_pressure_history[i] = 0.0f;
}
2020-10-09 20:08:08 +00:00
#ifdef _MODBUS_RTU
2020-09-28 19:50:06 +00:00
rte_wx_last_modbus_exception_timestamp = 0;
rte_wx_last_modbus_rx_error_timestamp = 0;
rte_wx_last_modbus_exception = RTU_EXCEPTION_OK;
2020-10-09 20:08:08 +00:00
#endif
}
void rte_wx_update_last_measuremenet_timers(uint16_t parameter_type) {
if (parameter_type == RTE_WX_MEASUREMENT_WIND)
wx_last_good_wind_time = master_time;
else if (parameter_type == RTE_WX_MEASUREMENT_TEMPERATURE)
wx_last_good_temperature_time = master_time;
2020-08-10 21:54:18 +00:00
else {
;
}
}