kopia lustrzana https://github.com/SP8EBC/ParaTNC
modbus rtu getters improved, rtu configuration moved to separate header, wx_handlers modified
rodzic
b4ca1ee5bd
commit
ccb9ec8431
|
@ -5,7 +5,7 @@
|
|||
#include "drivers/serial.h"
|
||||
|
||||
#define SW_VER "DF08"
|
||||
#define SW_DATE "20092020"
|
||||
#define SW_DATE "30092020"
|
||||
|
||||
#define SYSTICK_TICKS_PER_SECONDS 100
|
||||
#define SYSTICK_TICKS_PERIOD 10
|
||||
|
|
|
@ -28,9 +28,11 @@
|
|||
#endif
|
||||
|
||||
#ifdef _MODBUS_RTU
|
||||
#include "modbus_rtu/rtu_configuration.h"
|
||||
#include "modbus_rtu/rtu_register_data_t.h"
|
||||
#include "modbus_rtu/rtu_exception_t.h"
|
||||
#include "modbus_rtu/rtu_getters.h"
|
||||
#include "modbus_rtu/rtu_pool_queue_t.h"
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -112,6 +114,7 @@ extern davis_loop_t rte_wx_davis_loop_content;
|
|||
extern rtu_exception_t rte_wx_last_modbus_exception;
|
||||
extern uint32_t rte_wx_last_modbus_rx_error_timestamp;
|
||||
extern uint32_t rte_wx_last_modbus_exception_timestamp;
|
||||
extern rtu_pool_queue_t rte_wx_rtu_pool_queue;
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -163,9 +163,6 @@ uint16_t buffer_len = 0;
|
|||
umb_retval_t main_umb_retval = UMB_UNINITIALIZED;
|
||||
#endif
|
||||
|
||||
#ifdef _MODBUS_RTU
|
||||
rtu_pool_queue_t main_rtu_pool_queue;
|
||||
#endif
|
||||
|
||||
char after_tx_lock;
|
||||
|
||||
|
@ -343,7 +340,7 @@ int main(int argc, char* argv[]){
|
|||
|
||||
#elif (defined(PARATNC_HWREV_B) || defined(PARATNC_HWREV_C)) && defined(_MODBUS_RTU)
|
||||
|
||||
rtu_serial_init(&main_rtu_pool_queue);
|
||||
rtu_serial_init(&rte_wx_rtu_pool_queue);
|
||||
|
||||
main_target_wx_baudrate = _RTU_SLAVE_SPEED;
|
||||
|
||||
|
@ -697,7 +694,7 @@ int main(int argc, char* argv[]){
|
|||
// if modbus rtu master is enabled
|
||||
if (main_modbus_rtu_master_enabled == 1) {
|
||||
#ifdef _MODBUS_RTU
|
||||
rtu_serial_pool(&main_rtu_pool_queue, main_wx_srl_ctx_ptr);
|
||||
rtu_serial_pool(&rte_wx_rtu_pool_queue, main_wx_srl_ctx_ptr);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -80,6 +80,7 @@ davis_loop_t rte_wx_davis_loop_content;
|
|||
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;
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -17,6 +17,11 @@
|
|||
|
||||
#include "station_config.h"
|
||||
|
||||
#ifdef _MODBUS_RTU
|
||||
#include "modbus_rtu/rtu_getters.h"
|
||||
#include "modbus_rtu/rtu_return_values.h"
|
||||
#endif
|
||||
|
||||
#include "delay.h"
|
||||
#include "telemetry.h"
|
||||
#include "main.h"
|
||||
|
@ -41,7 +46,18 @@ void wx_get_all_measurements(void) {
|
|||
int32_t return_value = 0;
|
||||
float pressure_average_sum = 0.0f;
|
||||
|
||||
#if (defined _METEO && defined _SENSOR_MS5611)
|
||||
#if defined(_UMB_MASTER) && !defined(_DAVIS_SERIAL) && !defined(_MODBUS_RTU)
|
||||
if (rte_wx_umb_qf == UMB_QF_FULL) {
|
||||
rte_wx_temperature_average_dallas_valid = umb_get_temperature();
|
||||
rte_wx_pressure_valid = umb_get_qfe();
|
||||
}
|
||||
#endif
|
||||
|
||||
#if !defined(_UMB_MASTER) && !defined(_DAVIS_SERIAL) && defined(_MODBUS_RTU)
|
||||
// modbus rtu
|
||||
#endif
|
||||
|
||||
#if (!defined(_UMB_MASTER) && !defined(_DAVIS_SERIAL) && !defined(_MODBUS_RTU) && defined (_SENSOR_MS5611)) || (defined (_SENSOR_MS5611) && defined(_INTERNAL_AS_BACKUP))
|
||||
// quering MS5611 sensor for temperature
|
||||
return_value = ms5611_get_temperature(&rte_wx_temperature_ms, &rte_wx_ms5611_qf);
|
||||
|
||||
|
@ -52,7 +68,7 @@ void wx_get_all_measurements(void) {
|
|||
|
||||
#endif
|
||||
|
||||
#if (defined _METEO && defined _SENSOR_BME280)
|
||||
#if (!defined(_UMB_MASTER) && !defined(_DAVIS_SERIAL) && !defined(_MODBUS_RTU) && defined (_SENSOR_BME280)) || (defined (_SENSOR_BME280) && defined(_INTERNAL_AS_BACKUP))
|
||||
// reading raw values
|
||||
return_value = bme280_read_raw_data(bme280_data_buffer);
|
||||
|
||||
|
@ -111,8 +127,7 @@ void wx_get_all_measurements(void) {
|
|||
}
|
||||
#endif
|
||||
|
||||
#if defined _METEO || defined _DALLAS_AS_TELEM
|
||||
|
||||
#if (!defined(_UMB_MASTER) && !defined(_DAVIS_SERIAL) && !defined(_MODBUS_RTU)) || defined(_INTERNAL_AS_BACKUP) || defined (_DALLAS_AS_TELEM)
|
||||
// quering dallas DS12B20 thermometer for current temperature
|
||||
rte_wx_temperature_dallas = dallas_query(&rte_wx_current_dallas_qf);
|
||||
|
||||
|
@ -172,7 +187,7 @@ void wx_get_all_measurements(void) {
|
|||
wx_inhibit_slew_rate_check = 0;
|
||||
#endif
|
||||
|
||||
#if (defined _METEO) && (defined _SENSOR_MS5611)
|
||||
#if (!defined(_UMB_MASTER) && !defined(_DAVIS_SERIAL) && !defined(_MODBUS_RTU) && defined (_SENSOR_MS5611)) || (defined (_SENSOR_MS5611) && defined(_INTERNAL_AS_BACKUP))
|
||||
// quering MS5611 sensor for pressure
|
||||
return_value = ms5611_get_pressure(&rte_wx_pressure, &rte_wx_ms5611_qf);
|
||||
|
||||
|
@ -215,12 +230,7 @@ void wx_get_all_measurements(void) {
|
|||
|
||||
#endif
|
||||
|
||||
#if defined(_UMB_MASTER)
|
||||
if (rte_wx_umb_qf == UMB_QF_FULL) {
|
||||
rte_wx_temperature_average_dallas_valid = umb_get_temperature();
|
||||
rte_wx_pressure_valid = umb_get_qfe();
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void wx_pool_dht22(void) {
|
||||
|
@ -264,30 +274,53 @@ void wx_pool_anemometer(void) {
|
|||
short i = 0;
|
||||
uint8_t average_ln;
|
||||
|
||||
#ifdef _MODBUS_RTU
|
||||
int32_t modbus_retval;
|
||||
#endif
|
||||
|
||||
wx_wind_pool_call_counter++;
|
||||
|
||||
uint16_t scaled_windspeed = 0;
|
||||
|
||||
// internal sensors
|
||||
#if defined(_ANEMOMETER_ANALOGUE) && !defined(_UMB_MASTER) && !defined(_MODBUS_RTU) || (defined(_INTERNAL_AS_BACKUP) && defined(_ANEMOMETER_ANALOGUE))
|
||||
// this windspeed is scaled * 10. Example: 0.2 meters per second is stored as 2
|
||||
scaled_windspeed = analog_anemometer_get_ms_from_pulse(rte_wx_windspeed_pulses);
|
||||
#endif
|
||||
|
||||
#ifdef defined(_ANEMOMETER_TX20) && !defined(_UMB_MASTER) && !defined(_MODBUS_RTU) || (defined(_INTERNAL_AS_BACKUP) && defined(_ANEMOMETER_TX20))
|
||||
scaled_windspeed = tx20_get_scaled_windspeed();
|
||||
rte_wx_winddirection_last = tx20_get_wind_direction();
|
||||
#endif
|
||||
|
||||
#if defined(_UMB_MASTER)
|
||||
rte_wx_average_winddirection = umb_get_winddirection();
|
||||
rte_wx_average_windspeed = umb_get_windspeed();
|
||||
rte_wx_max_windspeed = umb_get_windgusts();
|
||||
#else
|
||||
|
||||
#ifdef _ANEMOMETER_ANALOGUE
|
||||
// this windspeed is scaled * 10. Example: 0.2 meters per second is stored as 2
|
||||
scaled_windspeed = analog_anemometer_get_ms_from_pulse(rte_wx_windspeed_pulses);
|
||||
#ifdef _MODBUS_RTU
|
||||
// get the value from modbus registers
|
||||
modbus_retval = rtu_get_wind_speed(&scaled_windspeed);
|
||||
|
||||
// check if this value has been processed w/o errors
|
||||
if (modbus_retval == MODBUS_RET_OK || modbus_retval == MODBUS_RET_DEGRADED) {
|
||||
// if yes continue to further processing
|
||||
modbus_retval = rtu_get_wind_direction(&rte_wx_winddirection_last);
|
||||
|
||||
}
|
||||
|
||||
// the second IF to check if the return value was the same for wind direction
|
||||
if (modbus_retval != MODBUS_RET_OK && modbus_retval != MODBUS_RET_DEGRADED) {
|
||||
// if the value is not available (like modbus is not configured as a source
|
||||
// for wind data) get the value from internal sensors..
|
||||
#ifdef _INTERNAL_AS_BACKUP
|
||||
// .. if they are configured
|
||||
scaled_windspeed = analog_anemometer_get_ms_from_pulse(rte_wx_windspeed_pulses);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef _ANEMOMETER_TX20
|
||||
scaled_windspeed = tx20_get_scaled_windspeed();
|
||||
rte_wx_winddirection_last = tx20_get_wind_direction();
|
||||
#endif
|
||||
|
||||
#ifdef _MODBUS_RTU
|
||||
|
||||
#endif
|
||||
|
||||
// check how many times before the pool function was called
|
||||
if (wx_wind_pool_call_counter < WIND_AVERAGE_LEN) {
|
||||
// if it was called less time than a length of buffers, the average length
|
||||
|
@ -363,7 +396,21 @@ void wx_pool_anemometer(void) {
|
|||
if (rte_wx_average_winddirection < 0)
|
||||
rte_wx_average_winddirection += 360;
|
||||
|
||||
#ifdef _ANEMOMETER_ANALOGUE
|
||||
#if defined (_MODBUS_RTU)
|
||||
if (modbus_retval == MODBUS_RET_OK) {
|
||||
rte_wx_wind_qf = AN_WIND_QF_FULL;
|
||||
}
|
||||
else if (modbus_retval == MODBUS_RET_DEGRADED) {
|
||||
rte_wx_wind_qf = AN_WIND_QF_DEGRADED;
|
||||
}
|
||||
else {
|
||||
#ifdef _INTERNAL_AS_BACKUP
|
||||
rte_wx_wind_qf = analog_anemometer_get_qf();
|
||||
#else
|
||||
rte_wx_wind_qf = AN_WIND_QF_NOT_AVALIABLE;
|
||||
#endif
|
||||
}
|
||||
#elif defined(_ANEMOMETER_ANALOGUE)
|
||||
rte_wx_wind_qf = analog_anemometer_get_qf();
|
||||
#else
|
||||
rte_wx_wind_qf = AN_WIND_QF_UNKNOWN;
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* rtu_configuration.h
|
||||
*
|
||||
* Created on: 30.09.2020
|
||||
* Author: mateusz
|
||||
*/
|
||||
|
||||
#ifndef INCLUDE_MODBUS_RTU_RTU_CONFIGURATION_H_
|
||||
#define INCLUDE_MODBUS_RTU_RTU_CONFIGURATION_H_
|
||||
|
||||
#define RTU_GETTERS_F1_NAME rte_wx_modbus_rtu_f1
|
||||
#define RTU_GETTERS_F2_NAME rte_wx_modbus_rtu_f2
|
||||
#define RTU_GETTERS_F3_NAME rte_wx_modbus_rtu_f3
|
||||
#define RTU_GETTERS_F4_NAME rte_wx_modbus_rtu_f4
|
||||
|
||||
#define RTU_POOL_QUEUE_LENGHT 4
|
||||
|
||||
#define MODBUS_RTU_MAX_REGISTERS_AT_ONCE 8 // according to RTU standard 125
|
||||
|
||||
#define RTU_MAXIMUM_DATA_LN 64
|
||||
|
||||
#define RTU_MAXIMUM_VALUE_AGE 600000
|
||||
|
||||
#endif /* INCLUDE_MODBUS_RTU_RTU_CONFIGURATION_H_ */
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
#define RTU_MAXIMUM_DATA_LN 64
|
||||
#include "rtu_configuration.h"
|
||||
|
||||
typedef struct rtu_frame_t {
|
||||
uint8_t address;
|
||||
|
|
|
@ -8,10 +8,7 @@
|
|||
#ifndef INCLUDE_MODBUS_RTU_RTU_GETTERS_H_
|
||||
#define INCLUDE_MODBUS_RTU_RTU_GETTERS_H_
|
||||
|
||||
#define RTU_GETTERS_F1_NAME rte_wx_modbus_rtu_f1
|
||||
#define RTU_GETTERS_F2_NAME rte_wx_modbus_rtu_f2
|
||||
#define RTU_GETTERS_F3_NAME rte_wx_modbus_rtu_f3
|
||||
#define RTU_GETTERS_F4_NAME rte_wx_modbus_rtu_f4
|
||||
#include <stdint.h>
|
||||
|
||||
int32_t rtu_get_temperature(float* out);
|
||||
int32_t rtu_get_pressure(float* out);
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
#define RTU_POOL_QUEUE_LENGHT 4
|
||||
#include "modbus_rtu/rtu_configuration.h"
|
||||
|
||||
/**
|
||||
* This type stores the queue of RTU functions to be queued
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
#define MODBUS_RTU_MAX_REGISTERS_AT_ONCE 8 // according to RTU standard 125
|
||||
#include "modbus_rtu/rtu_configuration.h"
|
||||
|
||||
typedef struct __attribute__((packed)) rtu_register_data {
|
||||
|
||||
|
@ -22,6 +22,8 @@ typedef struct __attribute__((packed)) rtu_register_data {
|
|||
|
||||
uint16_t registers_values[MODBUS_RTU_MAX_REGISTERS_AT_ONCE];
|
||||
|
||||
//uint32_t last_update_timestamp;
|
||||
|
||||
}rtu_register_data_t;
|
||||
|
||||
#endif /* INCLUDE_MODBUS_RTU_RTU_REGISTER_DATA_T_H_ */
|
||||
|
|
|
@ -15,5 +15,6 @@
|
|||
#define MODBUS_RET_REQUEST_GEN_ERR 3
|
||||
#define MODBUS_RET_GOT_EXCEPTION 4
|
||||
#define MODBUS_RET_NOT_AVALIABLE 5
|
||||
#define MODBUS_RET_DEGRADED 6
|
||||
|
||||
#endif /* INCLUDE_MODBUS_RTU_RTU_RETURN_VALUES_H_ */
|
||||
|
|
|
@ -8,8 +8,14 @@
|
|||
|
||||
#include "station_config.h"
|
||||
|
||||
#include "rtu_getters.h"
|
||||
#include "rtu_return_values.h"
|
||||
#include "modbus_rtu/rtu_getters.h"
|
||||
#include "modbus_rtu/rtu_return_values.h"
|
||||
#include "modbus_rtu/rtu_register_data_t.h"
|
||||
|
||||
#include "modbus_rtu/rtu_configuration.h"
|
||||
|
||||
#include "rte_wx.h"
|
||||
#include "main.h"
|
||||
|
||||
int32_t rtu_get_temperature(float* out) {
|
||||
|
||||
|
@ -21,6 +27,9 @@ int32_t rtu_get_temperature(float* out) {
|
|||
|
||||
uint16_t scaling_a, scaling_b, scaling_c, scaling_d;
|
||||
|
||||
// the timestamp of last update of the register value
|
||||
uint32_t last_update_timestam = 0;
|
||||
|
||||
#ifdef _RTU_SLAVE_TEMPERATURE_SOURCE
|
||||
#if (_RTU_SLAVE_TEMPERATURE_SOURCE == 1)
|
||||
source = &RTU_GETTERS_F1_NAME;
|
||||
|
@ -28,24 +37,28 @@ int32_t rtu_get_temperature(float* out) {
|
|||
scaling_b = _RTU_SLAVE_SCALING_B_1;
|
||||
scaling_c = _RTU_SLAVE_SCALING_C_1;
|
||||
scaling_d = _RTU_SLAVE_SCALING_D_1;
|
||||
last_update_timestam = rte_wx_rtu_pool_queue.last_call_to_function[0];
|
||||
#elif (_RTU_SLAVE_TEMPERATURE_SOURCE == 2)
|
||||
source = &RTU_GETTERS_F2_NAME;
|
||||
scaling_a = _RTU_SLAVE_SCALING_A_2;
|
||||
scaling_b = _RTU_SLAVE_SCALING_B_2;
|
||||
scaling_c = _RTU_SLAVE_SCALING_C_2;
|
||||
scaling_d = _RTU_SLAVE_SCALING_D_2;
|
||||
last_update_timestam = rte_wx_rtu_pool_queue.last_call_to_function[1];
|
||||
#elif (_RTU_SLAVE_TEMPERATURE_SOURCE == 3)
|
||||
source = &RTU_GETTERS_F3_NAME;
|
||||
scaling_a = _RTU_SLAVE_SCALING_A_3;
|
||||
scaling_b = _RTU_SLAVE_SCALING_B_3;
|
||||
scaling_c = _RTU_SLAVE_SCALING_C_3;
|
||||
scaling_d = _RTU_SLAVE_SCALING_D_3;
|
||||
last_update_timestam = rte_wx_rtu_pool_queue.last_call_to_function[2];
|
||||
#elif (_RTU_SLAVE_TEMPERATURE_SOURCE == 4)
|
||||
source = &RTU_GETTERS_F4_NAME;
|
||||
scaling_a = _RTU_SLAVE_SCALING_A_4;
|
||||
scaling_b = _RTU_SLAVE_SCALING_B_4;
|
||||
scaling_c = _RTU_SLAVE_SCALING_C_4;
|
||||
scaling_d = _RTU_SLAVE_SCALING_D_4;
|
||||
last_update_timestam = rte_wx_rtu_pool_queue.last_call_to_function[3];
|
||||
#else
|
||||
#error "Wrong Modbus Configuration"
|
||||
#endif
|
||||
|
@ -65,7 +78,14 @@ int32_t rtu_get_temperature(float* out) {
|
|||
) /
|
||||
scaling_d;
|
||||
|
||||
retval = MODBUS_RET_OK;
|
||||
// check when the value has been updated
|
||||
if (main_get_master_time() - last_update_timestam > RTU_MAXIMUM_VALUE_AGE) {
|
||||
retval = MODBUS_RET_DEGRADED;
|
||||
}
|
||||
else {
|
||||
retval = MODBUS_RET_OK;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return retval;
|
||||
|
@ -81,6 +101,9 @@ int32_t rtu_get_pressure(float* out) {
|
|||
|
||||
uint16_t scaling_a, scaling_b, scaling_c, scaling_d;
|
||||
|
||||
// the timestamp of last update of the register value
|
||||
uint32_t last_update_timestam = 0;
|
||||
|
||||
#ifdef _RTU_SLAVE_PRESSURE_SOURCE
|
||||
#if (_RTU_SLAVE_PRESSURE_SOURCE == 1)
|
||||
source = &RTU_GETTERS_F1_NAME;
|
||||
|
@ -88,24 +111,28 @@ int32_t rtu_get_pressure(float* out) {
|
|||
scaling_b = _RTU_SLAVE_SCALING_B_1;
|
||||
scaling_c = _RTU_SLAVE_SCALING_C_1;
|
||||
scaling_d = _RTU_SLAVE_SCALING_D_1;
|
||||
last_update_timestam = rte_wx_rtu_pool_queue.last_call_to_function[0];
|
||||
#elif (_RTU_SLAVE_PRESSURE_SOURCE == 2)
|
||||
source = &RTU_GETTERS_F2_NAME;
|
||||
scaling_a = _RTU_SLAVE_SCALING_A_2;
|
||||
scaling_b = _RTU_SLAVE_SCALING_B_2;
|
||||
scaling_c = _RTU_SLAVE_SCALING_C_2;
|
||||
scaling_d = _RTU_SLAVE_SCALING_D_2;
|
||||
last_update_timestam = rte_wx_rtu_pool_queue.last_call_to_function[1];
|
||||
#elif (_RTU_SLAVE_PRESSURE_SOURCE == 3)
|
||||
source = &RTU_GETTERS_F3_NAME;
|
||||
scaling_a = _RTU_SLAVE_SCALING_A_3;
|
||||
scaling_b = _RTU_SLAVE_SCALING_B_3;
|
||||
scaling_c = _RTU_SLAVE_SCALING_C_3;
|
||||
scaling_d = _RTU_SLAVE_SCALING_D_3;
|
||||
last_update_timestam = rte_wx_rtu_pool_queue.last_call_to_function[2];
|
||||
#elif (_RTU_SLAVE_PRESSURE_SOURCE == 4)
|
||||
source = &RTU_GETTERS_F4_NAME;
|
||||
scaling_a = _RTU_SLAVE_SCALING_A_4;
|
||||
scaling_b = _RTU_SLAVE_SCALING_B_4;
|
||||
scaling_c = _RTU_SLAVE_SCALING_C_4;
|
||||
scaling_d = _RTU_SLAVE_SCALING_D_4;
|
||||
last_update_timestam = rte_wx_rtu_pool_queue.last_call_to_function[3];
|
||||
#else
|
||||
#error "Wrong Modbus Configuration"
|
||||
#endif
|
||||
|
@ -125,7 +152,13 @@ int32_t rtu_get_pressure(float* out) {
|
|||
) /
|
||||
scaling_d;
|
||||
|
||||
retval = MODBUS_RET_OK;
|
||||
// check when the value has been updated
|
||||
if (main_get_master_time() - last_update_timestam > RTU_MAXIMUM_VALUE_AGE) {
|
||||
retval = MODBUS_RET_DEGRADED;
|
||||
}
|
||||
else {
|
||||
retval = MODBUS_RET_OK;
|
||||
}
|
||||
}
|
||||
|
||||
return retval;
|
||||
|
@ -141,6 +174,9 @@ int32_t rtu_get_wind_direction(uint16_t* out) {
|
|||
|
||||
uint16_t scaling_a, scaling_b, scaling_c, scaling_d;
|
||||
|
||||
// the timestamp of last update of the register value
|
||||
uint32_t last_update_timestam = 0;
|
||||
|
||||
#ifdef _RTU_SLAVE_WIND_DIRECTION_SORUCE
|
||||
#if (_RTU_SLAVE_WIND_DIRECTION_SORUCE == 1)
|
||||
source = &RTU_GETTERS_F1_NAME;
|
||||
|
@ -148,24 +184,28 @@ int32_t rtu_get_wind_direction(uint16_t* out) {
|
|||
scaling_b = _RTU_SLAVE_SCALING_B_1;
|
||||
scaling_c = _RTU_SLAVE_SCALING_C_1;
|
||||
scaling_d = _RTU_SLAVE_SCALING_D_1;
|
||||
last_update_timestam = rte_wx_rtu_pool_queue.last_call_to_function[0];
|
||||
#elif (_RTU_SLAVE_WIND_DIRECTION_SORUCE == 2)
|
||||
source = &RTU_GETTERS_F2_NAME;
|
||||
scaling_a = _RTU_SLAVE_SCALING_A_2;
|
||||
scaling_b = _RTU_SLAVE_SCALING_B_2;
|
||||
scaling_c = _RTU_SLAVE_SCALING_C_2;
|
||||
scaling_d = _RTU_SLAVE_SCALING_D_2;
|
||||
last_update_timestam = rte_wx_rtu_pool_queue.last_call_to_function[1];
|
||||
#elif (_RTU_SLAVE_WIND_DIRECTION_SORUCE == 3)
|
||||
source = &RTU_GETTERS_F3_NAME;
|
||||
scaling_a = _RTU_SLAVE_SCALING_A_3;
|
||||
scaling_b = _RTU_SLAVE_SCALING_B_3;
|
||||
scaling_c = _RTU_SLAVE_SCALING_C_3;
|
||||
scaling_d = _RTU_SLAVE_SCALING_D_3;
|
||||
last_update_timestam = rte_wx_rtu_pool_queue.last_call_to_function[2];
|
||||
#elif (_RTU_SLAVE_WIND_DIRECTION_SORUCE == 4)
|
||||
source = &RTU_GETTERS_F4_NAME;
|
||||
scaling_a = _RTU_SLAVE_SCALING_A_4;
|
||||
scaling_b = _RTU_SLAVE_SCALING_B_4;
|
||||
scaling_c = _RTU_SLAVE_SCALING_C_4;
|
||||
scaling_d = _RTU_SLAVE_SCALING_D_4;
|
||||
last_update_timestam = rte_wx_rtu_pool_queue.last_call_to_function[3];
|
||||
#else
|
||||
#error "Wrong Modbus Configuration"
|
||||
#endif
|
||||
|
@ -185,7 +225,13 @@ int32_t rtu_get_wind_direction(uint16_t* out) {
|
|||
) /
|
||||
scaling_d;
|
||||
|
||||
retval = MODBUS_RET_OK;
|
||||
// check when the value has been updated
|
||||
if (main_get_master_time() - last_update_timestam > RTU_MAXIMUM_VALUE_AGE) {
|
||||
retval = MODBUS_RET_DEGRADED;
|
||||
}
|
||||
else {
|
||||
retval = MODBUS_RET_OK;
|
||||
}
|
||||
}
|
||||
|
||||
return retval;
|
||||
|
@ -201,6 +247,9 @@ int32_t rtu_get_wind_speed(uint16_t* out) {
|
|||
|
||||
uint16_t scaling_a, scaling_b, scaling_c, scaling_d;
|
||||
|
||||
// the timestamp of last update of the register value
|
||||
uint32_t last_update_timestam = 0;
|
||||
|
||||
#ifdef _RTU_SLAVE_WIND_SPEED_SOURCE
|
||||
#if (_RTU_SLAVE_WIND_SPEED_SOURCE == 1)
|
||||
source = &RTU_GETTERS_F1_NAME;
|
||||
|
@ -208,24 +257,28 @@ int32_t rtu_get_wind_speed(uint16_t* out) {
|
|||
scaling_b = _RTU_SLAVE_SCALING_B_1;
|
||||
scaling_c = _RTU_SLAVE_SCALING_C_1;
|
||||
scaling_d = _RTU_SLAVE_SCALING_D_1;
|
||||
last_update_timestam = rte_wx_rtu_pool_queue.last_call_to_function[0];
|
||||
#elif (_RTU_SLAVE_WIND_SPEED_SOURCE == 2)
|
||||
source = &RTU_GETTERS_F2_NAME;
|
||||
scaling_a = _RTU_SLAVE_SCALING_A_2;
|
||||
scaling_b = _RTU_SLAVE_SCALING_B_2;
|
||||
scaling_c = _RTU_SLAVE_SCALING_C_2;
|
||||
scaling_d = _RTU_SLAVE_SCALING_D_2;
|
||||
last_update_timestam = rte_wx_rtu_pool_queue.last_call_to_function[1];
|
||||
#elif (_RTU_SLAVE_WIND_SPEED_SOURCE == 3)
|
||||
source = &RTU_GETTERS_F3_NAME;
|
||||
scaling_a = _RTU_SLAVE_SCALING_A_3;
|
||||
scaling_b = _RTU_SLAVE_SCALING_B_3;
|
||||
scaling_c = _RTU_SLAVE_SCALING_C_3;
|
||||
scaling_d = _RTU_SLAVE_SCALING_D_3;
|
||||
last_update_timestam = rte_wx_rtu_pool_queue.last_call_to_function[2];
|
||||
#elif (_RTU_SLAVE_WIND_SPEED_SOURCE == 4)
|
||||
source = &RTU_GETTERS_F4_NAME;
|
||||
scaling_a = _RTU_SLAVE_SCALING_A_4;
|
||||
scaling_b = _RTU_SLAVE_SCALING_B_4;
|
||||
scaling_c = _RTU_SLAVE_SCALING_C_4;
|
||||
scaling_d = _RTU_SLAVE_SCALING_D_4;
|
||||
last_update_timestam = rte_wx_rtu_pool_queue.last_call_to_function[3];
|
||||
#else
|
||||
#error "Wrong Modbus Configuration"
|
||||
#endif
|
||||
|
@ -245,7 +298,13 @@ int32_t rtu_get_wind_speed(uint16_t* out) {
|
|||
) /
|
||||
scaling_d;
|
||||
|
||||
retval = MODBUS_RET_OK;
|
||||
// check when the value has been updated
|
||||
if (main_get_master_time() - last_update_timestam > RTU_MAXIMUM_VALUE_AGE) {
|
||||
retval = MODBUS_RET_DEGRADED;
|
||||
}
|
||||
else {
|
||||
retval = MODBUS_RET_OK;
|
||||
}
|
||||
}
|
||||
|
||||
return retval;
|
||||
|
@ -261,6 +320,9 @@ int32_t rtu_get_humidity(int8_t* out) {
|
|||
|
||||
uint16_t scaling_a, scaling_b, scaling_c, scaling_d;
|
||||
|
||||
// the timestamp of last update of the register value
|
||||
uint32_t last_update_timestam = 0;
|
||||
|
||||
#ifdef _RTU_SLAVE_HUMIDITY_SOURCE
|
||||
#if (_RTU_SLAVE_HUMIDITY_SOURCE == 1)
|
||||
source = &RTU_GETTERS_F1_NAME;
|
||||
|
@ -268,24 +330,28 @@ int32_t rtu_get_humidity(int8_t* out) {
|
|||
scaling_b = _RTU_SLAVE_SCALING_B_1;
|
||||
scaling_c = _RTU_SLAVE_SCALING_C_1;
|
||||
scaling_d = _RTU_SLAVE_SCALING_D_1;
|
||||
last_update_timestam = rte_wx_rtu_pool_queue.last_call_to_function[0];
|
||||
#elif (_RTU_SLAVE_HUMIDITY_SOURCE == 2)
|
||||
source = &RTU_GETTERS_F2_NAME;
|
||||
scaling_a = _RTU_SLAVE_SCALING_A_2;
|
||||
scaling_b = _RTU_SLAVE_SCALING_B_2;
|
||||
scaling_c = _RTU_SLAVE_SCALING_C_2;
|
||||
scaling_d = _RTU_SLAVE_SCALING_D_2;
|
||||
last_update_timestam = rte_wx_rtu_pool_queue.last_call_to_function[1];
|
||||
#elif (_RTU_SLAVE_HUMIDITY_SOURCE == 3)
|
||||
source = &RTU_GETTERS_F3_NAME;
|
||||
scaling_a = _RTU_SLAVE_SCALING_A_3;
|
||||
scaling_b = _RTU_SLAVE_SCALING_B_3;
|
||||
scaling_c = _RTU_SLAVE_SCALING_C_3;
|
||||
scaling_d = _RTU_SLAVE_SCALING_D_3;
|
||||
last_update_timestam = rte_wx_rtu_pool_queue.last_call_to_function[2];
|
||||
#elif (_RTU_SLAVE_HUMIDITY_SOURCE == 4)
|
||||
source = &RTU_GETTERS_F4_NAME;
|
||||
scaling_a = _RTU_SLAVE_SCALING_A_4;
|
||||
scaling_b = _RTU_SLAVE_SCALING_B_4;
|
||||
scaling_c = _RTU_SLAVE_SCALING_C_4;
|
||||
scaling_d = _RTU_SLAVE_SCALING_D_4;
|
||||
last_update_timestam = rte_wx_rtu_pool_queue.last_call_to_function[3];
|
||||
#else
|
||||
#error "Wrong Modbus Configuration"
|
||||
#endif
|
||||
|
@ -305,7 +371,13 @@ int32_t rtu_get_humidity(int8_t* out) {
|
|||
) /
|
||||
scaling_d;
|
||||
|
||||
retval = MODBUS_RET_OK;
|
||||
// check when the value has been updated
|
||||
if (main_get_master_time() - last_update_timestam > RTU_MAXIMUM_VALUE_AGE) {
|
||||
retval = MODBUS_RET_DEGRADED;
|
||||
}
|
||||
else {
|
||||
retval = MODBUS_RET_OK;
|
||||
}
|
||||
}
|
||||
|
||||
return retval;
|
||||
|
|
Ładowanie…
Reference in New Issue