#include "modbus_params.h" // for modbus parameters structures #include "mbcontroller.h" #include "string.h" #include "esp_log.h" #define MB_PORT_NUM (UART_NUM_1) // Number of UART port used for Modbus connection #define MB_DEV_SPEED (9600) // The communication speed of the UART // Note: Some pins on target chip cannot be assigned for UART communication. // See UART documentation for selected board and target to configure pins using Kconfig. // The number of parameters that intended to be used in the particular control process #define MASTER_MAX_CIDS num_device_parameters // Number of reading of parameters from slave #define MASTER_MAX_RETRY 3 // Timeout to update cid over Modbus #define UPDATE_CIDS_TIMEOUT_MS (500) #define UPDATE_CIDS_TIMEOUT_TICS (UPDATE_CIDS_TIMEOUT_MS / portTICK_PERIOD_MS) // Timeout between polls #define POLL_TIMEOUT_MS (1) #define POLL_TIMEOUT_TICS (POLL_TIMEOUT_MS / portTICK_PERIOD_MS) // The macro to get offset for parameter in the appropriate structure #define HOLD_OFFSET(field) ((uint16_t)(offsetof(holding_reg_params_t, field) + 1)) #define INPUT_OFFSET(field) ((uint16_t)(offsetof(input_reg_params_t, field) + 1)) #define COIL_OFFSET(field) ((uint16_t)(offsetof(coil_reg_params_t, field) + 1)) // Discrete offset macro #define DISCR_OFFSET(field) ((uint16_t)(offsetof(discrete_reg_params_t, field) + 1)) #define STR(fieldname) ((const char*)( fieldname )) // Options can be used as bit masks or parameter limits #define OPTS(min_val, max_val, step_val) { .opt1 = min_val, .opt2 = max_val, .opt3 = step_val } /*串口通讯接口定义*/ #define CONFIG_MB_UART_TXD 0 #define CONFIG_MB_UART_RXD 1 //#define MB_PORT_NUM UART_NUM_1 //#define MB_DEV_SPEED 9600 // Enumeration of modbus device addresses accessed by master device enum { MB_DEVICE_ADDR1 = 1 // Only one slave device used for the test (add other slave addresses here) }; // Enumeration of all supported CIDs for device (used in parameter definition table) enum { CID_INP_DATA_0 = 0, CID_HOLD_DATA_0, CID_INP_DATA_1, CID_HOLD_DATA_1, CID_INP_DATA_2, CID_HOLD_DATA_2, CID_HOLD_TEST_REG, CID_RELAY_P1, CID_RELAY_P2, CID_DISCR_P1, CID_COUNT }; #define USE_MODBUS_OFFICIAL 0 #ifdef __cplusplus extern "C" { #endif /*Modbus总线初始化函数*/ esp_err_t modbus_master_init(void); void master_operation_func(void *arg); static void* master_get_param_data(const mb_parameter_descriptor_t* param_descriptor); #ifdef __cplusplus } #endif