share mb commands with mbcontroller IDFGH-9305

This commit is contained in:
aleks
2023-02-03 14:34:18 +01:00
parent 3f6537fc94
commit 79301c36b7
4 changed files with 33 additions and 23 deletions

View File

@ -43,10 +43,10 @@ set(srcs
"common/esp_modbus_master_serial.c"
"common/esp_modbus_slave_serial.c")
set(include_dirs common/include)
set(include_dirs port common/include modbus/include)
set(priv_include_dirs common port modbus modbus/ascii modbus/functions
modbus/rtu modbus/tcp modbus/include)
set(priv_include_dirs port common modbus modbus/ascii modbus/functions
modbus/rtu modbus/tcp)
list(APPEND priv_include_dirs serial_slave/port serial_slave/modbus_controller
serial_master/port serial_master/modbus_controller

View File

@ -9,14 +9,17 @@
#include "driver/uart.h" // for UART types
#include "port.h"
#include "mbproto.h"
#ifdef __cplusplus
extern "C" {
#endif
#if __has_include("esp_check.h")
#include "esp_check.h"
#include "esp_log.h"
#define MB_RETURN_ON_FALSE(a, err_code, tag, format, ...) ESP_RETURN_ON_FALSE(a, err_code, tag, format __VA_OPT__(,) __VA_ARGS__)
#else

View File

@ -94,12 +94,14 @@ typedef struct {
mb_param_perms_t access; /*!< Access permissions based on mode */
} mb_parameter_descriptor_t;
/**
typedef enum eMbCommands_t mb_function_codes_t;
/**<
* @brief Modbus register request type structure
*/
typedef struct {
uint8_t slave_addr; /*!< Modbus slave address */
uint8_t command; /*!< Modbus command to send */
mb_function_codes_t command; /*!< Modbus command to send */
uint16_t reg_start; /*!< Modbus start register */
uint16_t reg_size; /*!< Modbus number of registers */
} mb_param_request_t;

View File

@ -45,24 +45,29 @@ PR_BEGIN_EXTERN_C
#define MB_ADDRESS_BROADCAST ( 0 ) /*! Modbus broadcast address. */
#define MB_ADDRESS_MIN ( 1 ) /*! Smallest possible slave address. */
#define MB_ADDRESS_MAX ( 247 ) /*! Biggest possible slave address. */
#define MB_FUNC_NONE ( 0 )
#define MB_FUNC_READ_COILS ( 1 )
#define MB_FUNC_READ_DISCRETE_INPUTS ( 2 )
#define MB_FUNC_WRITE_SINGLE_COIL ( 5 )
#define MB_FUNC_WRITE_MULTIPLE_COILS ( 15 )
#define MB_FUNC_READ_HOLDING_REGISTER ( 3 )
#define MB_FUNC_READ_INPUT_REGISTER ( 4 )
#define MB_FUNC_WRITE_REGISTER ( 6 )
#define MB_FUNC_WRITE_MULTIPLE_REGISTERS ( 16 )
#define MB_FUNC_READWRITE_MULTIPLE_REGISTERS ( 23 )
#define MB_FUNC_DIAG_READ_EXCEPTION ( 7 )
#define MB_FUNC_DIAG_DIAGNOSTIC ( 8 )
#define MB_FUNC_DIAG_GET_COM_EVENT_CNT ( 11 )
#define MB_FUNC_DIAG_GET_COM_EVENT_LOG ( 12 )
#define MB_FUNC_OTHER_REPORT_SLAVEID ( 17 )
#define MB_FUNC_ERROR ( 128u )
typedef enum eMbCommands_t
{
MB_FUNC_NONE = ( 0 ),
MB_FUNC_READ_COILS = ( 1 ),
MB_FUNC_READ_DISCRETE_INPUTS = ( 2 ),
MB_FUNC_WRITE_SINGLE_COIL = ( 5 ),
MB_FUNC_WRITE_MULTIPLE_COILS = ( 15 ),
MB_FUNC_READ_HOLDING_REGISTER = ( 3 ),
MB_FUNC_READ_INPUT_REGISTER = ( 4 ),
MB_FUNC_WRITE_REGISTER = ( 6 ),
MB_FUNC_WRITE_MULTIPLE_REGISTERS = ( 16 ),
MB_FUNC_READWRITE_MULTIPLE_REGISTERS =( 23 ),
MB_FUNC_DIAG_READ_EXCEPTION = ( 7 ),
MB_FUNC_DIAG_DIAGNOSTIC = ( 8 ),
MB_FUNC_DIAG_GET_COM_EVENT_CNT = ( 11 ),
MB_FUNC_DIAG_GET_COM_EVENT_LOG = ( 12 ),
MB_FUNC_OTHER_REPORT_SLAVEID = ( 17 ),
MB_FUNC_ERROR = ( 128u )
} eMBCommands;
/* ----------------------- Type definitions ---------------------------------*/
typedef enum
typedef enum
{
MB_EX_NONE = 0x00,
MB_EX_ILLEGAL_FUNCTION = 0x01,