kopia lustrzana https://github.com/SP8EBC/ParaTNC
global Modbus RTU related stuff moved to separate RTE file, couting successfull RTU queries
rodzic
e31373d01a
commit
69d257fafd
|
@ -16,6 +16,7 @@ C_SRCS += \
|
|||
../src/packet_tx_handler.c \
|
||||
../src/rte_main.c \
|
||||
../src/rte_pv.c \
|
||||
../src/rte_rtu.c \
|
||||
../src/rte_wx.c \
|
||||
../src/wx_handler.c
|
||||
|
||||
|
@ -32,6 +33,7 @@ OBJS += \
|
|||
./src/packet_tx_handler.o \
|
||||
./src/rte_main.o \
|
||||
./src/rte_pv.o \
|
||||
./src/rte_rtu.o \
|
||||
./src/rte_wx.o \
|
||||
./src/wx_handler.o
|
||||
|
||||
|
@ -48,6 +50,7 @@ C_DEPS += \
|
|||
./src/packet_tx_handler.d \
|
||||
./src/rte_main.d \
|
||||
./src/rte_pv.d \
|
||||
./src/rte_rtu.d \
|
||||
./src/rte_wx.d \
|
||||
./src/wx_handler.d
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include "drivers/serial.h"
|
||||
|
||||
#define SW_VER "DF09"
|
||||
#define SW_DATE "29102020"
|
||||
#define SW_DATE "30102020"
|
||||
|
||||
#define SYSTICK_TICKS_PER_SECONDS 100
|
||||
#define SYSTICK_TICKS_PERIOD 10
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* rte_rtu.h
|
||||
*
|
||||
* Created on: Oct 30, 2020
|
||||
* Author: mateusz
|
||||
*/
|
||||
|
||||
#ifndef RTE_RTU_H_
|
||||
#define RTE_RTU_H_
|
||||
|
||||
#include "station_config.h"
|
||||
|
||||
#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
|
||||
|
||||
extern uint8_t rte_rtu_number_of_serial_io_errors;
|
||||
|
||||
extern uint16_t rte_rtu_number_of_serial_successfull_comm;
|
||||
|
||||
#ifdef _MODBUS_RTU
|
||||
|
||||
#if defined(_RTU_SLAVE_ID_1) && (_RTU_SLAVE_FUNC_1 == 0x03 || _RTU_SLAVE_FUNC_1 == 0x04)
|
||||
extern rtu_register_data_t RTU_GETTERS_F1_NAME;
|
||||
#endif
|
||||
|
||||
#if defined(_RTU_SLAVE_ID_2) && (_RTU_SLAVE_FUNC_2 == 0x03 || _RTU_SLAVE_FUNC_2 == 0x04)
|
||||
extern rtu_register_data_t RTU_GETTERS_F2_NAME;
|
||||
#endif
|
||||
|
||||
#if defined(_RTU_SLAVE_ID_3) && (_RTU_SLAVE_FUNC_3 == 0x03 || _RTU_SLAVE_FUNC_3 == 0x04)
|
||||
extern rtu_register_data_t RTU_GETTERS_F3_NAME;
|
||||
#endif
|
||||
|
||||
#if defined(_RTU_SLAVE_ID_4) && (_RTU_SLAVE_FUNC_4 == 0x03 || _RTU_SLAVE_FUNC_4 == 0x04)
|
||||
extern rtu_register_data_t RTU_GETTERS_F4_NAME;
|
||||
#endif
|
||||
|
||||
#if defined(_RTU_SLAVE_ID_5) && (_RTU_SLAVE_FUNC_5 == 0x03 || _RTU_SLAVE_FUNC_5 == 0x04)
|
||||
extern 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)
|
||||
extern rtu_register_data_t RTU_GETTERS_F6_NAME;
|
||||
#endif
|
||||
|
||||
extern rtu_exception_t rte_rtu_last_modbus_exception;
|
||||
extern uint32_t rte_rtu_last_modbus_rx_error_timestamp;
|
||||
extern uint32_t rte_rtu_last_modbus_exception_timestamp;
|
||||
extern rtu_pool_queue_t rte_rtu_pool_queue;
|
||||
|
||||
#endif
|
||||
|
||||
void rte_rtu_init(void);
|
||||
|
||||
#endif /* RTE_RTU_H_ */
|
|
@ -27,14 +27,6 @@
|
|||
#include "drivers/bme280.h"
|
||||
#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
|
||||
|
||||
|
||||
#define WIND_AVERAGE_LEN 18
|
||||
|
||||
|
@ -93,38 +85,6 @@ extern uint8_t rte_wx_davis_station_avaliable;
|
|||
extern uint8_t rte_wx_davis_loop_packet_avaliable;
|
||||
extern 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)
|
||||
extern rtu_register_data_t RTU_GETTERS_F1_NAME;
|
||||
#endif
|
||||
|
||||
#if defined(_RTU_SLAVE_ID_2) && (_RTU_SLAVE_FUNC_2 == 0x03 || _RTU_SLAVE_FUNC_2 == 0x04)
|
||||
extern rtu_register_data_t RTU_GETTERS_F2_NAME;
|
||||
#endif
|
||||
|
||||
#if defined(_RTU_SLAVE_ID_3) && (_RTU_SLAVE_FUNC_3 == 0x03 || _RTU_SLAVE_FUNC_3 == 0x04)
|
||||
extern rtu_register_data_t RTU_GETTERS_F3_NAME;
|
||||
#endif
|
||||
|
||||
#if defined(_RTU_SLAVE_ID_4) && (_RTU_SLAVE_FUNC_4 == 0x03 || _RTU_SLAVE_FUNC_4 == 0x04)
|
||||
extern rtu_register_data_t RTU_GETTERS_F4_NAME;
|
||||
#endif
|
||||
|
||||
#if defined(_RTU_SLAVE_ID_5) && (_RTU_SLAVE_FUNC_5 == 0x03 || _RTU_SLAVE_FUNC_5 == 0x04)
|
||||
extern 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)
|
||||
extern rtu_register_data_t RTU_GETTERS_F6_NAME;
|
||||
#endif
|
||||
|
||||
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
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
|
|
14
src/main.c
14
src/main.c
|
@ -34,6 +34,7 @@
|
|||
#include "rte_wx.h"
|
||||
#include "rte_pv.h"
|
||||
#include "rte_main.h"
|
||||
#include "rte_rtu.h"
|
||||
|
||||
#ifdef _METEO
|
||||
#include <wx_handler.h>
|
||||
|
@ -237,6 +238,10 @@ int main(int argc, char* argv[]){
|
|||
RCC->APB1ENR &= (0xFFFFFFFF ^ (RCC_APB1ENR_PWREN | RCC_APB1ENR_BKPEN));
|
||||
PWR->CR &= (0xFFFFFFFF ^ PWR_CR_DBP);
|
||||
|
||||
// initializing variables & arrays in rte_wx
|
||||
rte_wx_init();
|
||||
rte_rtu_init();
|
||||
|
||||
#if defined _RANDOM_DELAY
|
||||
// configuring a default delay value
|
||||
delay_set(_DELAY_BASE, 1);
|
||||
|
@ -352,7 +357,7 @@ int main(int argc, char* argv[]){
|
|||
|
||||
#elif (defined(PARATNC_HWREV_B) || defined(PARATNC_HWREV_C)) && defined(_MODBUS_RTU)
|
||||
|
||||
rtu_serial_init(&rte_wx_rtu_pool_queue);
|
||||
rtu_serial_init(&rte_rtu_pool_queue);
|
||||
|
||||
main_target_wx_baudrate = _RTU_SLAVE_SPEED;
|
||||
|
||||
|
@ -427,9 +432,6 @@ int main(int argc, char* argv[]){
|
|||
// initialize Watchdog output
|
||||
Configure_GPIO(GPIOA,12,GPPP_OUTPUT_50MHZ);
|
||||
|
||||
// initializing variables & arrays in rte_wx
|
||||
rte_wx_init();
|
||||
|
||||
// initializing the digipeater configuration
|
||||
digi_init();
|
||||
|
||||
|
@ -716,7 +718,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(&rte_wx_rtu_pool_queue, main_wx_srl_ctx_ptr);
|
||||
rtu_serial_pool(&rte_rtu_pool_queue, main_wx_srl_ctx_ptr);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -741,7 +743,7 @@ int main(int argc, char* argv[]){
|
|||
|
||||
if (rte_main_trigger_modbus_status == 1) {
|
||||
#ifdef _MODBUS_RTU
|
||||
rtu_serial_get_status_string(&rte_wx_rtu_pool_queue, main_own_aprs_msg, MAIN_OWN_APRS_MSG_LN, &main_own_aprs_msg_len);
|
||||
rtu_serial_get_status_string(&rte_rtu_pool_queue, main_own_aprs_msg, MAIN_OWN_APRS_MSG_LN, &main_own_aprs_msg_len);
|
||||
#endif
|
||||
ax25_sendVia(&main_ax25, main_own_path, main_own_path_ln, main_own_aprs_msg, main_own_aprs_msg_len);
|
||||
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* rte_rtu.c
|
||||
*
|
||||
* Created on: Oct 30, 2020
|
||||
* Author: mateusz
|
||||
*/
|
||||
|
||||
#include <rte_rtu.h>
|
||||
|
||||
/**
|
||||
* This counts the consecutive serial I/O errors to trigger the modbur-rtu status frame
|
||||
*/
|
||||
uint8_t rte_rtu_number_of_serial_io_errors = 0;
|
||||
|
||||
uint16_t rte_rtu_number_of_serial_successfull_comm = 0;
|
||||
|
||||
#ifdef _MODBUS_RTU
|
||||
|
||||
#if defined(_RTU_SLAVE_ID_1) && (_RTU_SLAVE_FUNC_1 == 0x03 || _RTU_SLAVE_FUNC_1 == 0x04)
|
||||
rtu_register_data_t RTU_GETTERS_F1_NAME;
|
||||
#endif
|
||||
|
||||
#if defined(_RTU_SLAVE_ID_2) && (_RTU_SLAVE_FUNC_2 == 0x03 || _RTU_SLAVE_FUNC_2 == 0x04)
|
||||
rtu_register_data_t RTU_GETTERS_F2_NAME;
|
||||
#endif
|
||||
|
||||
#if defined(_RTU_SLAVE_ID_3) && (_RTU_SLAVE_FUNC_3 == 0x03 || _RTU_SLAVE_FUNC_3 == 0x04)
|
||||
rtu_register_data_t RTU_GETTERS_F3_NAME;
|
||||
#endif
|
||||
|
||||
#if defined(_RTU_SLAVE_ID_4) && (_RTU_SLAVE_FUNC_4 == 0x03 || _RTU_SLAVE_FUNC_4 == 0x04)
|
||||
rtu_register_data_t RTU_GETTERS_F4_NAME;
|
||||
#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
|
||||
|
||||
rtu_exception_t rte_rtu_last_modbus_exception;
|
||||
uint32_t rte_rtu_last_modbus_exception_timestamp;
|
||||
uint32_t rte_rtu_last_modbus_rx_error_timestamp;
|
||||
rtu_pool_queue_t rte_rtu_pool_queue;
|
||||
|
||||
#endif
|
||||
|
||||
void rte_rtu_init(void) {
|
||||
#ifdef _MODBUS_RTU
|
||||
rte_rtu_last_modbus_exception_timestamp = 0;
|
||||
rte_rtu_last_modbus_rx_error_timestamp = 0;
|
||||
rte_rtu_last_modbus_exception = RTU_EXCEPTION_OK;
|
||||
#endif
|
||||
}
|
39
src/rte_wx.c
39
src/rte_wx.c
|
@ -59,39 +59,6 @@ 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)
|
||||
rtu_register_data_t RTU_GETTERS_F1_NAME;
|
||||
#endif
|
||||
|
||||
#if defined(_RTU_SLAVE_ID_2) && (_RTU_SLAVE_FUNC_2 == 0x03 || _RTU_SLAVE_FUNC_2 == 0x04)
|
||||
rtu_register_data_t RTU_GETTERS_F2_NAME;
|
||||
#endif
|
||||
|
||||
#if defined(_RTU_SLAVE_ID_3) && (_RTU_SLAVE_FUNC_3 == 0x03 || _RTU_SLAVE_FUNC_3 == 0x04)
|
||||
rtu_register_data_t RTU_GETTERS_F3_NAME;
|
||||
#endif
|
||||
|
||||
#if defined(_RTU_SLAVE_ID_4) && (_RTU_SLAVE_FUNC_4 == 0x03 || _RTU_SLAVE_FUNC_4 == 0x04)
|
||||
rtu_register_data_t RTU_GETTERS_F4_NAME;
|
||||
#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
|
||||
|
||||
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
|
||||
|
||||
void rte_wx_init(void) {
|
||||
int i = 0;
|
||||
|
||||
|
@ -105,11 +72,7 @@ void rte_wx_init(void) {
|
|||
for (i = 0; i < 4; i++) {
|
||||
rte_wx_pressure_history[i] = 0.0f;
|
||||
}
|
||||
#ifdef _MODBUS_RTU
|
||||
rte_wx_last_modbus_exception_timestamp = 0;
|
||||
rte_wx_last_modbus_rx_error_timestamp = 0;
|
||||
rte_wx_last_modbus_exception = RTU_EXCEPTION_OK;
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void rte_wx_update_last_measuremenet_timers(uint16_t parameter_type) {
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "wx_handler.h"
|
||||
|
||||
#include <rte_wx.h>
|
||||
#include <rte_rtu.h>
|
||||
#include <math.h>
|
||||
#include <stm32f10x.h>
|
||||
#include "drivers/_dht22.h"
|
||||
|
@ -44,6 +45,8 @@ void wx_get_all_measurements(void) {
|
|||
int8_t j = 0;
|
||||
int32_t i = 0;
|
||||
int32_t return_value = 0;
|
||||
int8_t not_avaliable = 0;
|
||||
int8_t degraded = 0;
|
||||
float pressure_average_sum = 0.0f;
|
||||
|
||||
#if defined(_UMB_MASTER) && !defined(_DAVIS_SERIAL) && !defined(_MODBUS_RTU)
|
||||
|
@ -55,9 +58,9 @@ void wx_get_all_measurements(void) {
|
|||
|
||||
#if !defined(_UMB_MASTER) && !defined(_DAVIS_SERIAL) && defined(_MODBUS_RTU)
|
||||
// modbus rtu
|
||||
rtu_get_temperature(&rte_wx_temperature_average_dallas_valid);
|
||||
rtu_get_humidity(&rte_wx_humidity_valid);
|
||||
rtu_get_pressure(&rte_wx_pressure_valid);
|
||||
return_value = rtu_get_temperature(&rte_wx_temperature_average_dallas_valid);
|
||||
return_value = rtu_get_humidity(&rte_wx_humidity_valid);
|
||||
return_value = rtu_get_pressure(&rte_wx_pressure_valid);
|
||||
#endif
|
||||
|
||||
#if (!defined(_UMB_MASTER) && !defined(_DAVIS_SERIAL) && !defined(_MODBUS_RTU) && defined (_SENSOR_MS5611)) || (defined (_SENSOR_MS5611) && defined(_INTERNAL_AS_BACKUP))
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
#define RTU_GETTERS_F5_NAME rte_wx_modbus_rtu_f5
|
||||
#define RTU_GETTERS_F6_NAME rte_wx_modbus_rtu_f6
|
||||
|
||||
#define RTU_NUMBER_OF_ERRORS_TO_TRIG_STATUS 24
|
||||
#define RTU_NUMBER_OF_ERRORS_TO_TRIG_STATUS 25
|
||||
|
||||
#define RTU_POOL_QUEUE_LENGHT 6
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include "modbus_rtu/rtu_configuration.h"
|
||||
|
||||
#include "rte_wx.h"
|
||||
#include "rte_rtu.h"
|
||||
#include "main.h"
|
||||
|
||||
int32_t rtu_get_temperature(float* out) {
|
||||
|
@ -38,42 +39,42 @@ 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_successfull_call_to_function[0];
|
||||
last_update_timestam = rte_rtu_pool_queue.last_successfull_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_successfull_call_to_function[1];
|
||||
last_update_timestam = rte_rtu_pool_queue.last_successfull_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_successfull_call_to_function[2];
|
||||
last_update_timestam = rte_rtu_pool_queue.last_successfull_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_successfull_call_to_function[3];
|
||||
last_update_timestam = rte_rtu_pool_queue.last_successfull_call_to_function[3];
|
||||
#elif (_RTU_SLAVE_TEMPERATURE_SOURCE == 5)
|
||||
source = &RTU_GETTERS_F5_NAME;
|
||||
scaling_a = _RTU_SLAVE_SCALING_A_5;
|
||||
scaling_b = _RTU_SLAVE_SCALING_B_5;
|
||||
scaling_c = _RTU_SLAVE_SCALING_C_5;
|
||||
scaling_d = _RTU_SLAVE_SCALING_D_5;
|
||||
last_update_timestam = rte_wx_rtu_pool_queue.last_successfull_call_to_function[4];
|
||||
last_update_timestam = rte_rtu_pool_queue.last_successfull_call_to_function[4];
|
||||
#elif (_RTU_SLAVE_TEMPERATURE_SOURCE == 6)
|
||||
source = &RTU_GETTERS_F6_NAME;
|
||||
scaling_a = _RTU_SLAVE_SCALING_A_6;
|
||||
scaling_b = _RTU_SLAVE_SCALING_B_6;
|
||||
scaling_c = _RTU_SLAVE_SCALING_C_6;
|
||||
scaling_d = _RTU_SLAVE_SCALING_D_6;
|
||||
last_update_timestam = rte_wx_rtu_pool_queue.last_successfull_call_to_function[5];
|
||||
last_update_timestam = rte_rtu_pool_queue.last_successfull_call_to_function[5];
|
||||
#else
|
||||
#error "Wrong Modbus Configuration"
|
||||
#endif
|
||||
|
@ -90,7 +91,7 @@ int32_t rtu_get_temperature(float* out) {
|
|||
retval = MODBUS_RET_NOT_AVALIABLE;
|
||||
}
|
||||
else {
|
||||
if (main_get_master_time() - rte_wx_last_modbus_rx_error_timestamp < RTU_MAXIMUM_VALUE_AGE) {
|
||||
if (main_get_master_time() - rte_rtu_last_modbus_rx_error_timestamp < RTU_MAXIMUM_VALUE_AGE) {
|
||||
retval = MODBUS_RET_DEGRADED;
|
||||
}
|
||||
else {
|
||||
|
@ -133,42 +134,42 @@ 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_successfull_call_to_function[0];
|
||||
last_update_timestam = rte_rtu_pool_queue.last_successfull_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_successfull_call_to_function[1];
|
||||
last_update_timestam = rte_rtu_pool_queue.last_successfull_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_successfull_call_to_function[2];
|
||||
last_update_timestam = rte_rtu_pool_queue.last_successfull_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_successfull_call_to_function[3];
|
||||
last_update_timestam = rte_rtu_pool_queue.last_successfull_call_to_function[3];
|
||||
#elif (_RTU_SLAVE_PRESSURE_SOURCE == 5)
|
||||
source = &RTU_GETTERS_F5_NAME;
|
||||
scaling_a = _RTU_SLAVE_SCALING_A_5;
|
||||
scaling_b = _RTU_SLAVE_SCALING_B_5;
|
||||
scaling_c = _RTU_SLAVE_SCALING_C_5;
|
||||
scaling_d = _RTU_SLAVE_SCALING_D_5;
|
||||
last_update_timestam = rte_wx_rtu_pool_queue.last_successfull_call_to_function[4];
|
||||
last_update_timestam = rte_rtu_pool_queue.last_successfull_call_to_function[4];
|
||||
#elif (_RTU_SLAVE_PRESSURE_SOURCE == 6)
|
||||
source = &RTU_GETTERS_F6_NAME;
|
||||
scaling_a = _RTU_SLAVE_SCALING_A_6;
|
||||
scaling_b = _RTU_SLAVE_SCALING_B_6;
|
||||
scaling_c = _RTU_SLAVE_SCALING_C_6;
|
||||
scaling_d = _RTU_SLAVE_SCALING_D_6;
|
||||
last_update_timestam = rte_wx_rtu_pool_queue.last_successfull_call_to_function[5];
|
||||
last_update_timestam = rte_rtu_pool_queue.last_successfull_call_to_function[5];
|
||||
#else
|
||||
#error "Wrong Modbus Configuration"
|
||||
#endif
|
||||
|
@ -185,7 +186,7 @@ int32_t rtu_get_pressure(float* out) {
|
|||
retval = MODBUS_RET_NOT_AVALIABLE;
|
||||
}
|
||||
else {
|
||||
if (main_get_master_time() - rte_wx_last_modbus_rx_error_timestamp < RTU_MAXIMUM_VALUE_AGE) {
|
||||
if (main_get_master_time() - rte_rtu_last_modbus_rx_error_timestamp < RTU_MAXIMUM_VALUE_AGE) {
|
||||
retval = MODBUS_RET_DEGRADED;
|
||||
}
|
||||
else {
|
||||
|
@ -227,42 +228,42 @@ 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_successfull_call_to_function[0];
|
||||
last_update_timestam = rte_rtu_pool_queue.last_successfull_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_successfull_call_to_function[1];
|
||||
last_update_timestam = rte_rtu_pool_queue.last_successfull_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_successfull_call_to_function[2];
|
||||
last_update_timestam = rte_rtu_pool_queue.last_successfull_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_successfull_call_to_function[3];
|
||||
last_update_timestam = rte_rtu_pool_queue.last_successfull_call_to_function[3];
|
||||
#elif (_RTU_SLAVE_WIND_DIRECTION_SORUCE == 5)
|
||||
source = &RTU_GETTERS_F5_NAME;
|
||||
scaling_a = _RTU_SLAVE_SCALING_A_5;
|
||||
scaling_b = _RTU_SLAVE_SCALING_B_5;
|
||||
scaling_c = _RTU_SLAVE_SCALING_C_5;
|
||||
scaling_d = _RTU_SLAVE_SCALING_D_5;
|
||||
last_update_timestam = rte_wx_rtu_pool_queue.last_successfull_call_to_function[4];
|
||||
last_update_timestam = rte_rtu_pool_queue.last_successfull_call_to_function[4];
|
||||
#elif (_RTU_SLAVE_WIND_DIRECTION_SORUCE == 6)
|
||||
source = &RTU_GETTERS_F6_NAME;
|
||||
scaling_a = _RTU_SLAVE_SCALING_A_6;
|
||||
scaling_b = _RTU_SLAVE_SCALING_B_6;
|
||||
scaling_c = _RTU_SLAVE_SCALING_C_6;
|
||||
scaling_d = _RTU_SLAVE_SCALING_D_6;
|
||||
last_update_timestam = rte_wx_rtu_pool_queue.last_successfull_call_to_function[5];
|
||||
last_update_timestam = rte_rtu_pool_queue.last_successfull_call_to_function[5];
|
||||
#else
|
||||
#error "Wrong Modbus Configuration"
|
||||
#endif
|
||||
|
@ -279,7 +280,7 @@ int32_t rtu_get_wind_direction(uint16_t* out) {
|
|||
retval = MODBUS_RET_NOT_AVALIABLE;
|
||||
}
|
||||
else {
|
||||
if (main_get_master_time() - rte_wx_last_modbus_rx_error_timestamp < RTU_MAXIMUM_VALUE_AGE) {
|
||||
if (main_get_master_time() - rte_rtu_last_modbus_rx_error_timestamp < RTU_MAXIMUM_VALUE_AGE) {
|
||||
retval = MODBUS_RET_DEGRADED;
|
||||
}
|
||||
else {
|
||||
|
@ -321,42 +322,42 @@ 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_successfull_call_to_function[0];
|
||||
last_update_timestam = rte_rtu_pool_queue.last_successfull_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_successfull_call_to_function[1];
|
||||
last_update_timestam = rte_rtu_pool_queue.last_successfull_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_successfull_call_to_function[2];
|
||||
last_update_timestam = rte_rtu_pool_queue.last_successfull_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_successfull_call_to_function[3];
|
||||
last_update_timestam = rte_rtu_pool_queue.last_successfull_call_to_function[3];
|
||||
#elif (_RTU_SLAVE_WIND_SPEED_SOURCE == 5)
|
||||
source = &RTU_GETTERS_F5_NAME;
|
||||
scaling_a = _RTU_SLAVE_SCALING_A_5;
|
||||
scaling_b = _RTU_SLAVE_SCALING_B_5;
|
||||
scaling_c = _RTU_SLAVE_SCALING_C_5;
|
||||
scaling_d = _RTU_SLAVE_SCALING_D_5;
|
||||
last_update_timestam = rte_wx_rtu_pool_queue.last_successfull_call_to_function[4];
|
||||
last_update_timestam = rte_rtu_pool_queue.last_successfull_call_to_function[4];
|
||||
#elif (_RTU_SLAVE_WIND_SPEED_SOURCE == 6)
|
||||
source = &RTU_GETTERS_F6_NAME;
|
||||
scaling_a = _RTU_SLAVE_SCALING_A_6;
|
||||
scaling_b = _RTU_SLAVE_SCALING_B_6;
|
||||
scaling_c = _RTU_SLAVE_SCALING_C_6;
|
||||
scaling_d = _RTU_SLAVE_SCALING_D_6;
|
||||
last_update_timestam = rte_wx_rtu_pool_queue.last_successfull_call_to_function[5];
|
||||
last_update_timestam = rte_rtu_pool_queue.last_successfull_call_to_function[5];
|
||||
#else
|
||||
#error "Wrong Modbus Configuration"
|
||||
#endif
|
||||
|
@ -373,7 +374,7 @@ int32_t rtu_get_wind_speed(uint16_t* out) {
|
|||
retval = MODBUS_RET_NOT_AVALIABLE;
|
||||
}
|
||||
else {
|
||||
if (main_get_master_time() - rte_wx_last_modbus_rx_error_timestamp < RTU_MAXIMUM_VALUE_AGE) {
|
||||
if (main_get_master_time() - rte_rtu_last_modbus_rx_error_timestamp < RTU_MAXIMUM_VALUE_AGE) {
|
||||
retval = MODBUS_RET_DEGRADED;
|
||||
}
|
||||
else {
|
||||
|
@ -414,42 +415,42 @@ int32_t rtu_get_wind_gusts(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_successfull_call_to_function[0];
|
||||
last_update_timestam = rte_rtu_pool_queue.last_successfull_call_to_function[0];
|
||||
#elif (_RTU_SLAVE_WIND_GUSTS_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_successfull_call_to_function[1];
|
||||
last_update_timestam = rte_rtu_pool_queue.last_successfull_call_to_function[1];
|
||||
#elif (_RTU_SLAVE_WIND_GUSTS_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_successfull_call_to_function[2];
|
||||
last_update_timestam = rte_rtu_pool_queue.last_successfull_call_to_function[2];
|
||||
#elif (_RTU_SLAVE_WIND_GUSTS_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_successfull_call_to_function[3];
|
||||
last_update_timestam = rte_rtu_pool_queue.last_successfull_call_to_function[3];
|
||||
#elif (_RTU_SLAVE_WIND_GUSTS_SOURCE == 5)
|
||||
source = &RTU_GETTERS_F5_NAME;
|
||||
scaling_a = _RTU_SLAVE_SCALING_A_5;
|
||||
scaling_b = _RTU_SLAVE_SCALING_B_5;
|
||||
scaling_c = _RTU_SLAVE_SCALING_C_5;
|
||||
scaling_d = _RTU_SLAVE_SCALING_D_5;
|
||||
last_update_timestam = rte_wx_rtu_pool_queue.last_successfull_call_to_function[4];
|
||||
last_update_timestam = rte_rtu_pool_queue.last_successfull_call_to_function[4];
|
||||
#elif (_RTU_SLAVE_WIND_GUSTS_SOURCE == 6)
|
||||
source = &RTU_GETTERS_F6_NAME;
|
||||
scaling_a = _RTU_SLAVE_SCALING_A_6;
|
||||
scaling_b = _RTU_SLAVE_SCALING_B_6;
|
||||
scaling_c = _RTU_SLAVE_SCALING_C_6;
|
||||
scaling_d = _RTU_SLAVE_SCALING_D_6;
|
||||
last_update_timestam = rte_wx_rtu_pool_queue.last_successfull_call_to_function[5];
|
||||
last_update_timestam = rte_rtu_pool_queue.last_successfull_call_to_function[5];
|
||||
#else
|
||||
#error "Wrong Modbus Configuration"
|
||||
#endif
|
||||
|
@ -466,7 +467,7 @@ int32_t rtu_get_wind_gusts(uint16_t* out) {
|
|||
retval = MODBUS_RET_NOT_AVALIABLE;
|
||||
}
|
||||
else {
|
||||
if (main_get_master_time() - rte_wx_last_modbus_rx_error_timestamp < RTU_MAXIMUM_VALUE_AGE) {
|
||||
if (main_get_master_time() - rte_rtu_last_modbus_rx_error_timestamp < RTU_MAXIMUM_VALUE_AGE) {
|
||||
retval = MODBUS_RET_DEGRADED;
|
||||
}
|
||||
else {
|
||||
|
@ -508,28 +509,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_successfull_call_to_function[0];
|
||||
last_update_timestam = rte_rtu_pool_queue.last_successfull_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_successfull_call_to_function[1];
|
||||
last_update_timestam = rte_rtu_pool_queue.last_successfull_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_successfull_call_to_function[2];
|
||||
last_update_timestam = rte_rtu_pool_queue.last_successfull_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_successfull_call_to_function[3];
|
||||
last_update_timestam = rte_rtu_pool_queue.last_successfull_call_to_function[3];
|
||||
#else
|
||||
#error "Wrong Modbus Configuration"
|
||||
#endif
|
||||
|
@ -546,7 +547,7 @@ int32_t rtu_get_humidity(int8_t* out) {
|
|||
retval = MODBUS_RET_NOT_AVALIABLE;
|
||||
}
|
||||
else {
|
||||
if (main_get_master_time() - rte_wx_last_modbus_rx_error_timestamp < RTU_MAXIMUM_VALUE_AGE) {
|
||||
if (main_get_master_time() - rte_rtu_last_modbus_rx_error_timestamp < RTU_MAXIMUM_VALUE_AGE) {
|
||||
retval = MODBUS_RET_DEGRADED;
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include "main.h"
|
||||
#include "rte_wx.h"
|
||||
#include "rte_main.h"
|
||||
#include "rte_rtu.h"
|
||||
|
||||
#include "station_config.h"
|
||||
|
||||
|
@ -77,12 +78,6 @@ uint16_t rtu_serial_previous_crc = 0xFFFF;
|
|||
*/
|
||||
uint8_t rtu_waiting_for_slave_addr = 0x1;
|
||||
|
||||
/**
|
||||
* This counts the consecutive serial I/O errors to trigger the modbur-rtu status frame
|
||||
*/
|
||||
uint8_t rtu_number_of_serial_io_errors = 0;
|
||||
|
||||
|
||||
/**
|
||||
* The callback for stream CRC calculation
|
||||
*/
|
||||
|
@ -205,13 +200,22 @@ int32_t rtu_serial_pool(rtu_pool_queue_t* queue, srl_context_t* serial_context)
|
|||
|
||||
uint8_t output_data_lenght = 0;
|
||||
|
||||
// if there were any serial I/O error
|
||||
if (rte_rtu_number_of_serial_io_errors > 0) {
|
||||
|
||||
// check how many serial I/O erros have been detected so far
|
||||
if (rtu_number_of_serial_io_errors >= RTU_NUMBER_OF_ERRORS_TO_TRIG_STATUS) {
|
||||
if ((rte_rtu_number_of_serial_io_errors % RTU_NUMBER_OF_ERRORS_TO_TRIG_STATUS) == 0) {
|
||||
// set the status trigger
|
||||
rte_main_trigger_modbus_status = 1;
|
||||
|
||||
// reset the counter
|
||||
rtu_number_of_serial_io_errors = 0;
|
||||
// increment the error counter artificially to protect sending status in the loop
|
||||
rte_rtu_number_of_serial_io_errors++;
|
||||
|
||||
// stupid workaround. If there is a lot of I/O errors reset the controller
|
||||
if (rte_rtu_number_of_serial_io_errors == (RTU_NUMBER_OF_ERRORS_TO_TRIG_STATUS * 4)) {
|
||||
rte_main_reboot_req = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (queue->it >= RTU_POOL_QUEUE_LENGHT) {
|
||||
|
@ -348,7 +352,7 @@ int32_t rtu_serial_pool(rtu_pool_queue_t* queue, srl_context_t* serial_context)
|
|||
serial_context->srl_rx_buf_pointer,
|
||||
serial_context->srl_rx_bytes_counter,
|
||||
((rtu_register_data_t*)queue->function_parameter[queue->it]),
|
||||
&rte_wx_last_modbus_exception);
|
||||
&rte_rtu_last_modbus_exception);
|
||||
}
|
||||
else {
|
||||
retval = MODBUS_RET_WRONG_FUNCTION;
|
||||
|
@ -364,7 +368,7 @@ int32_t rtu_serial_pool(rtu_pool_queue_t* queue, srl_context_t* serial_context)
|
|||
}
|
||||
else if (result == MODBUS_RET_GOT_EXCEPTION) {
|
||||
// in case of an excetpion store the current timestamp
|
||||
rte_wx_last_modbus_exception_timestamp = main_get_master_time();
|
||||
rte_rtu_last_modbus_exception_timestamp = main_get_master_time();
|
||||
|
||||
// switch the state to inter-frame silence period
|
||||
rtu_pool = RTU_POOL_WAIT_AFTER_RECEIVE;
|
||||
|
@ -377,6 +381,8 @@ int32_t rtu_serial_pool(rtu_pool_queue_t* queue, srl_context_t* serial_context)
|
|||
// get current time to start the inter-frame delay
|
||||
rtu_time_of_last_succs_receive = main_get_master_time();
|
||||
|
||||
rte_rtu_number_of_serial_successfull_comm++;
|
||||
|
||||
// Close the serial port. This is a part of the stupid workaround of the problem
|
||||
// with a serial port which leads to receiving a lot of idle frames of unknown origin
|
||||
// and corrupting some part of data at the begining of some Modbus-RTU frames
|
||||
|
@ -387,7 +393,7 @@ int32_t rtu_serial_pool(rtu_pool_queue_t* queue, srl_context_t* serial_context)
|
|||
// in case of any error during data reception or the serial driver have fallen into unknown & unexpected
|
||||
// state
|
||||
else {
|
||||
rte_wx_last_modbus_rx_error_timestamp = main_get_master_time();
|
||||
rte_rtu_last_modbus_rx_error_timestamp = main_get_master_time();
|
||||
|
||||
rtu_pool = RTU_POOL_RECEIVE_ERROR;
|
||||
|
||||
|
@ -412,7 +418,7 @@ int32_t rtu_serial_pool(rtu_pool_queue_t* queue, srl_context_t* serial_context)
|
|||
rtu_pool = RTU_POOL_IDLE;
|
||||
|
||||
// increasing the global counter of io errors
|
||||
rtu_number_of_serial_io_errors++;
|
||||
rte_rtu_number_of_serial_io_errors++;
|
||||
|
||||
// icrease the error counter for this queue element
|
||||
queue->number_of_errors[queue->it] = queue->number_of_errors[queue->it] + 1;
|
||||
|
@ -453,15 +459,14 @@ int32_t rtu_serial_get_status_string(rtu_pool_queue_t* queue, char* out, uint16_
|
|||
memset(out, 0x00, out_buffer_ln);
|
||||
#ifdef _MODBUS_RTU
|
||||
|
||||
string_ln = snprintf(out, out_buffer_ln, "MT %d, LRET %d, LSRT %d, NSE %d, NOE1 %d, NOE2 %d, NOE3 %d, NOE4 %d",
|
||||
string_ln = snprintf(out, out_buffer_ln, ">MT %X, LRET %X, LSRT %X, NSSC %X, NSE %X",
|
||||
main_get_master_time(),
|
||||
rte_wx_last_modbus_rx_error_timestamp,
|
||||
rte_rtu_last_modbus_rx_error_timestamp,
|
||||
rtu_time_of_last_succs_receive,
|
||||
rtu_number_of_serial_io_errors,
|
||||
queue->number_of_errors[0],
|
||||
queue->number_of_errors[1],
|
||||
queue->number_of_errors[2],
|
||||
queue->number_of_errors[3]);
|
||||
(int)rte_rtu_number_of_serial_successfull_comm,
|
||||
(int)rte_rtu_number_of_serial_io_errors);
|
||||
|
||||
*generated_string_ln = (uint8_t) string_ln;
|
||||
#endif
|
||||
return retval;
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue