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>
|
2020-04-04 21:09:00 +00:00
|
|
|
#include <wx_handler.h>
|
|
|
|
#include "main.h"
|
2019-01-26 17:02:19 +00:00
|
|
|
|
2022-06-08 16:58:26 +00:00
|
|
|
/**
|
|
|
|
* A little word of explanataion:
|
|
|
|
* -> rte_wx_temperature_external_xxxxxx - these are default temperature readings provided
|
|
|
|
* by a sensor of choice. It might be dallas, modbus-rtu or other
|
|
|
|
*
|
|
|
|
* -> rte_wx_temperature_inernal_xxxxx - this is always a temperature measured by inernal pressure and/or
|
|
|
|
* humidity sensor. The intension here is to monitor how hot the
|
|
|
|
* controller internally
|
|
|
|
*
|
|
|
|
*/
|
2020-09-29 20:46:31 +00:00
|
|
|
|
2022-11-02 19:48:41 +00:00
|
|
|
float rte_wx_temperature_average_external_valid = 0.0f; //<! This name should be refactored
|
2021-04-09 10:43:38 +00:00
|
|
|
float rte_wx_temperature_internal = 0.0f, rte_wx_temperature_internal_valid = 0.0f;
|
2019-01-26 17:02:19 +00:00
|
|
|
float rte_wx_pressure = 0.0f, rte_wx_pressure_valid = 0.0f;
|
2020-03-06 19:24:20 +00:00
|
|
|
float rte_wx_pressure_history[PRESSURE_AVERAGE_LN];
|
|
|
|
uint8_t rte_wx_pressure_it;
|
2019-01-26 17:02:19 +00:00
|
|
|
|
2022-04-29 14:29:37 +00:00
|
|
|
#if defined(STM32L471xx)
|
|
|
|
/**
|
|
|
|
* These values are scaled * 10. As for now 'rte_wx_temperature_average_dallas'
|
2022-05-31 11:31:39 +00:00
|
|
|
* is rescaled version of 'rte_wx_temperature_average_external_valid'. Some of
|
|
|
|
* values are redundant as for now. Normally 'rte_wx_temperature_external'
|
|
|
|
* stores the temperature measured by the sensor of choice (like dallas), which are
|
2022-06-08 16:58:26 +00:00
|
|
|
* then used to send APRS meteo packets. In normal circumstances they might be more
|
|
|
|
* sensors which are measuring temperature. Values below are used by API client
|
|
|
|
* to POST them directly into Meteo System backend, which accepts more than one
|
|
|
|
* source of temperature at once
|
2022-04-29 14:29:37 +00:00
|
|
|
*/
|
|
|
|
int16_t rte_wx_temperature_average_dallas = 0;
|
|
|
|
int16_t rte_wx_temperature_average_pt = 0;
|
2022-05-31 11:31:39 +00:00
|
|
|
int16_t rte_wx_temperature_average_modbus = 0;
|
2022-04-29 14:29:37 +00:00
|
|
|
int16_t rte_wx_temperature_average_internal = 0;
|
|
|
|
uint16_t rte_wx_pressure_average = 0;
|
2022-09-18 18:44:41 +00:00
|
|
|
#endif
|
2022-06-09 13:00:26 +00:00
|
|
|
uint16_t rte_wx_pm10 = 0; // 2.5um
|
|
|
|
uint16_t rte_wx_pm2_5 = 0; // 1um
|
2022-09-18 18:44:41 +00:00
|
|
|
|
2022-04-29 14:29:37 +00:00
|
|
|
int16_t rte_wx_average_winddirection = 0;
|
|
|
|
uint16_t rte_wx_average_windspeed = 0;
|
|
|
|
uint16_t rte_wx_max_windspeed = 0;
|
|
|
|
|
2019-12-27 21:07:24 +00:00
|
|
|
uint16_t rte_wx_windspeed_pulses = 0;
|
2020-01-04 13:15:33 +00:00
|
|
|
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;
|
2020-02-01 22:20:17 +00:00
|
|
|
uint16_t rte_wx_winddirection_last = 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;
|
2020-06-21 21:11:16 +00:00
|
|
|
|
2020-03-23 20:41:01 +00:00
|
|
|
dallas_qf_t rte_wx_current_dallas_qf, rte_wx_error_dallas_qf = DALLAS_QF_UNKNOWN;
|
2022-10-20 07:06:54 +00:00
|
|
|
float_average_t rte_wx_dallas_average;
|
2020-07-25 19:49:24 +00:00
|
|
|
ms5611_qf_t rte_wx_ms5611_qf = MS5611_QF_UNKNOWN;
|
|
|
|
bme280_qf_t rte_wx_bme280_qf = BME280_QF_UKNOWN;
|
2020-07-28 06:31:12 +00:00
|
|
|
analog_wind_qf_t rte_wx_wind_qf = AN_WIND_QF_UNKNOWN;
|
2023-11-01 22:10:51 +00:00
|
|
|
uint8_t rte_wx_humidity_available = 0;
|
2019-01-26 17:02:19 +00:00
|
|
|
|
2020-09-07 21:25:58 +00:00
|
|
|
|
2020-02-23 06:50:22 +00:00
|
|
|
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
|
|
|
|
umb_qf_t rte_wx_umb_qf = UMB_QF_UNITIALIZED;
|
2020-02-23 06:50:22 +00:00
|
|
|
|
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;
|
|
|
|
|
2020-01-04 13:15:33 +00:00
|
|
|
void rte_wx_init(void) {
|
|
|
|
int i = 0;
|
2019-01-26 17:02:19 +00:00
|
|
|
|
2020-01-04 13:15:33 +00:00
|
|
|
for (; i < WIND_AVERAGE_LEN; i++) {
|
|
|
|
rte_wx_windspeed[i] = 0;
|
|
|
|
rte_wx_winddirection[i] = 0;
|
|
|
|
}
|
2020-03-06 19:24:20 +00:00
|
|
|
|
|
|
|
rte_wx_pressure_it = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
rte_wx_pressure_history[i] = 0.0f;
|
|
|
|
}
|
2020-10-30 12:02:07 +00:00
|
|
|
|
2020-01-04 13:15:33 +00:00
|
|
|
}
|
2020-04-04 21:09:00 +00:00
|
|
|
|
|
|
|
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 {
|
|
|
|
;
|
|
|
|
}
|
2020-04-04 21:09:00 +00:00
|
|
|
}
|
2020-11-05 21:52:37 +00:00
|
|
|
|
|
|
|
void rte_wx_reset_last_measuremenet_timers(uint16_t parameter_type) {
|
|
|
|
if (parameter_type == RTE_WX_MEASUREMENT_WIND)
|
|
|
|
wx_last_good_wind_time = 0xFFFFFFFF;
|
|
|
|
else if (parameter_type == RTE_WX_MEASUREMENT_TEMPERATURE)
|
|
|
|
wx_last_good_temperature_time = 0xFFFFFFFF;
|
|
|
|
else {
|
|
|
|
;
|
|
|
|
}
|
|
|
|
}
|