mirror of
https://github.com/espressif/esp-modbus.git
synced 2025-08-04 21:04:25 +02:00
Merge branch 'bugfix/modbus_handle_disabled_comm_modes' into 'main'
fix modbus handling of disabled comm modes See merge request idf/esp-modbus!92
This commit is contained in:
@@ -693,11 +693,23 @@ esp_err_t mbc_serial_master_create(mb_communication_info_t *config, void **ctx)
|
|||||||
|
|
||||||
if (pcomm_info->mode == MB_RTU)
|
if (pcomm_info->mode == MB_RTU)
|
||||||
{
|
{
|
||||||
|
#if ( CONFIG_FMB_COMM_MODE_RTU_EN )
|
||||||
err = mbm_rtu_create(pcomm_info, &pinst);
|
err = mbm_rtu_create(pcomm_info, &pinst);
|
||||||
|
#else
|
||||||
|
ESP_LOGE(TAG, "RTU mode is not enabled in the configuration.");
|
||||||
|
ret = ESP_ERR_NOT_SUPPORTED;
|
||||||
|
goto error;
|
||||||
|
#endif // CONFIG_FMB_COMM_MODE_RTU_EN
|
||||||
}
|
}
|
||||||
else if (pcomm_info->mode == MB_ASCII)
|
else if (pcomm_info->mode == MB_ASCII)
|
||||||
{
|
{
|
||||||
|
#if ( CONFIG_FMB_COMM_MODE_ASCII_EN )
|
||||||
err = mbm_ascii_create(pcomm_info, &pinst);
|
err = mbm_ascii_create(pcomm_info, &pinst);
|
||||||
|
#else
|
||||||
|
ESP_LOGE(TAG, "ASCII mode is not enabled in the configuration.");
|
||||||
|
ret = ESP_ERR_NOT_SUPPORTED;
|
||||||
|
goto error;
|
||||||
|
#endif // CONFIG_FMB_COMM_MODE_ASCII_EN
|
||||||
}
|
}
|
||||||
MB_GOTO_ON_FALSE((err == MB_ENOERR), ESP_ERR_INVALID_STATE, error, TAG,
|
MB_GOTO_ON_FALSE((err == MB_ENOERR), ESP_ERR_INVALID_STATE, error, TAG,
|
||||||
"mb object create returns (0x%x).", (int)err);
|
"mb object create returns (0x%x).", (int)err);
|
||||||
|
@@ -255,11 +255,23 @@ esp_err_t mbc_serial_slave_create(mb_communication_info_t *config, void **ctx)
|
|||||||
// Initialize Modbus stack using mbcontroller parameters
|
// Initialize Modbus stack using mbcontroller parameters
|
||||||
if (pcomm_info->mode == MB_RTU)
|
if (pcomm_info->mode == MB_RTU)
|
||||||
{
|
{
|
||||||
|
#if (CONFIG_FMB_COMM_MODE_RTU_EN)
|
||||||
err = mbs_rtu_create(pcomm_info, &pinst);
|
err = mbs_rtu_create(pcomm_info, &pinst);
|
||||||
|
#else
|
||||||
|
ESP_LOGE(TAG, "RTU mode is not enabled in the configuration.");
|
||||||
|
ret = ESP_ERR_NOT_SUPPORTED;
|
||||||
|
goto error;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else if (pcomm_info->mode == MB_ASCII)
|
else if (pcomm_info->mode == MB_ASCII)
|
||||||
{
|
{
|
||||||
|
#if (CONFIG_FMB_COMM_MODE_ASCII_EN)
|
||||||
err = mbs_ascii_create(pcomm_info, &pinst);
|
err = mbs_ascii_create(pcomm_info, &pinst);
|
||||||
|
#else
|
||||||
|
ESP_LOGE(TAG, "ASCII mode is not enabled in the configuration.");
|
||||||
|
ret = ESP_ERR_NOT_SUPPORTED;
|
||||||
|
goto error;
|
||||||
|
#endif // CONFIG_FMB_COMM_MODE_ASCII_EN
|
||||||
}
|
}
|
||||||
MB_GOTO_ON_FALSE((err == MB_ENOERR), ESP_ERR_INVALID_STATE, error, TAG,
|
MB_GOTO_ON_FALSE((err == MB_ENOERR), ESP_ERR_INVALID_STATE, error, TAG,
|
||||||
"mbs create returns (0x%x).", (int)err);
|
"mbs create returns (0x%x).", (int)err);
|
||||||
@@ -290,4 +302,4 @@ error:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif // #if (CONFIG_FMB_COMM_MODE_ASCII_EN || CONFIG_FMB_COMM_MODE_RTU_EN)
|
@@ -82,10 +82,10 @@ static void mbm_set_dest_addr(mb_base_t *inst, uint8_t dest_addr);
|
|||||||
static uint8_t mbm_get_dest_addr(mb_base_t *inst);
|
static uint8_t mbm_get_dest_addr(mb_base_t *inst);
|
||||||
static void mbm_get_pdu_send_buf(mb_base_t *inst, uint8_t **pbuf);
|
static void mbm_get_pdu_send_buf(mb_base_t *inst, uint8_t **pbuf);
|
||||||
|
|
||||||
#if (MB_MASTER_ASCII_ENABLED || MB_MASTER_RTU_ENABLED)
|
|
||||||
|
|
||||||
typedef struct _port_serial_opts mb_serial_opts_t;
|
typedef struct _port_serial_opts mb_serial_opts_t;
|
||||||
|
|
||||||
|
#if (MB_MASTER_RTU_ENABLED)
|
||||||
|
|
||||||
mb_err_enum_t mbm_rtu_create(mb_serial_opts_t *ser_opts, void **in_out_obj)
|
mb_err_enum_t mbm_rtu_create(mb_serial_opts_t *ser_opts, void **in_out_obj)
|
||||||
{
|
{
|
||||||
MB_RETURN_ON_FALSE((ser_opts && in_out_obj), MB_EINVAL, TAG, "invalid options for the instance.");
|
MB_RETURN_ON_FALSE((ser_opts && in_out_obj), MB_EINVAL, TAG, "invalid options for the instance.");
|
||||||
@@ -139,6 +139,10 @@ error:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* MB_MASTER_RTU_ENABLED */
|
||||||
|
|
||||||
|
#if (MB_MASTER_ASCII_ENABLED)
|
||||||
|
|
||||||
mb_err_enum_t mbm_ascii_create(mb_serial_opts_t *ser_opts, void **in_out_obj)
|
mb_err_enum_t mbm_ascii_create(mb_serial_opts_t *ser_opts, void **in_out_obj)
|
||||||
{
|
{
|
||||||
MB_RETURN_ON_FALSE((ser_opts && in_out_obj), MB_EINVAL, TAG, "invalid options for the instance.");
|
MB_RETURN_ON_FALSE((ser_opts && in_out_obj), MB_EINVAL, TAG, "invalid options for the instance.");
|
||||||
@@ -192,7 +196,7 @@ error:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif /* MB_MASTER_ASCII_ENABLED */
|
||||||
|
|
||||||
#if (CONFIG_FMB_COMM_MODE_TCP_EN)
|
#if (CONFIG_FMB_COMM_MODE_TCP_EN)
|
||||||
|
|
||||||
|
@@ -3,6 +3,7 @@
|
|||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
#include "mb_config.h"
|
||||||
#include "mb_common.h"
|
#include "mb_common.h"
|
||||||
#include "mb_proto.h"
|
#include "mb_proto.h"
|
||||||
#include "mb_func.h"
|
#include "mb_func.h"
|
||||||
@@ -15,6 +16,8 @@
|
|||||||
|
|
||||||
static const char *TAG = "mb_object.slave";
|
static const char *TAG = "mb_object.slave";
|
||||||
|
|
||||||
|
#if (MB_SLAVE_ASCII_ENABLED || MB_SLAVE_RTU_ENABLED || MB_TCP_ENABLED)
|
||||||
|
|
||||||
static mb_fn_handler_t slave_handlers[MB_FUNC_HANDLERS_MAX] =
|
static mb_fn_handler_t slave_handlers[MB_FUNC_HANDLERS_MAX] =
|
||||||
{
|
{
|
||||||
#if MB_FUNC_OTHER_REP_SLAVEID_ENABLED
|
#if MB_FUNC_OTHER_REP_SLAVEID_ENABLED
|
||||||
@@ -73,10 +76,10 @@ mb_err_enum_t mbs_disable(mb_base_t *inst);
|
|||||||
mb_err_enum_t mbs_poll(mb_base_t *inst);
|
mb_err_enum_t mbs_poll(mb_base_t *inst);
|
||||||
mb_err_enum_t mbs_set_slv_id(mb_base_t *inst, uint8_t slv_id, bool is_running, uint8_t const *slv_idstr, uint16_t slv_idstr_len);
|
mb_err_enum_t mbs_set_slv_id(mb_base_t *inst, uint8_t slv_id, bool is_running, uint8_t const *slv_idstr, uint16_t slv_idstr_len);
|
||||||
|
|
||||||
#if (CONFIG_FMB_COMM_MODE_ASCII_EN || CONFIG_FMB_COMM_MODE_RTU_EN)
|
|
||||||
|
|
||||||
typedef struct _port_serial_opts mb_serial_opts_t;
|
typedef struct _port_serial_opts mb_serial_opts_t;
|
||||||
|
|
||||||
|
#if (MB_SLAVE_RTU_ENABLED)
|
||||||
|
|
||||||
mb_err_enum_t mbs_rtu_create(mb_serial_opts_t *ser_opts, void **in_out_obj)
|
mb_err_enum_t mbs_rtu_create(mb_serial_opts_t *ser_opts, void **in_out_obj)
|
||||||
{
|
{
|
||||||
mb_err_enum_t ret = MB_ENOERR;
|
mb_err_enum_t ret = MB_ENOERR;
|
||||||
@@ -124,6 +127,10 @@ error:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* MB_SLAVE_RTU_ENABLED */
|
||||||
|
|
||||||
|
#if (MB_SLAVE_ASCII_ENABLED)
|
||||||
|
|
||||||
mb_err_enum_t mbs_ascii_create(mb_serial_opts_t *ser_opts, void **in_out_obj)
|
mb_err_enum_t mbs_ascii_create(mb_serial_opts_t *ser_opts, void **in_out_obj)
|
||||||
{
|
{
|
||||||
mb_err_enum_t ret = MB_ENOERR;
|
mb_err_enum_t ret = MB_ENOERR;
|
||||||
@@ -170,9 +177,9 @@ error:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif /* MB_SLAVE_ASCII_ENABLED */
|
||||||
|
|
||||||
#if (CONFIG_FMB_COMM_MODE_TCP_EN)
|
#if (MB_TCP_ENABLED)
|
||||||
|
|
||||||
mb_err_enum_t mbs_tcp_create(mb_tcp_opts_t *tcp_opts, void **in_out_obj)
|
mb_err_enum_t mbs_tcp_create(mb_tcp_opts_t *tcp_opts, void **in_out_obj)
|
||||||
{
|
{
|
||||||
@@ -381,3 +388,5 @@ mb_err_enum_t mbs_poll(mb_base_t *inst)
|
|||||||
}
|
}
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif /* (MB_SLAVE_ASCII_ENABLED || MB_SLAVE_RTU_ENABLED || MB_TCP_ENABLED) */
|
Reference in New Issue
Block a user