Merge branch 'feature/add_slave_id_command_v2' into 'main'

add slave report id command for master and slave (backport v2)

See merge request idf/esp-modbus!97
This commit is contained in:
Alex Lisitsyn committed 2025-02-27 18:36:41 +08:00
commit 877d331b4b
31 files changed
+663 -167

No files matched your search

+5 -3
View File
@@ -133,8 +133,11 @@ struct mb_base_t
mb_trans_base_t *transp_obj;
mb_port_base_t *port_obj;
uint8_t slave_id[MB_FUNC_OTHER_REP_SLAVEID_BUF];
uint16_t slave_id_len;
#if MB_FUNC_OTHER_REP_SLAVEID_ENABLED
uint8_t *pobj_id;
uint16_t obj_id_len;
uint8_t obj_id_chunks;
#endif
mb_delete_fp delete;
mb_enable_fp enable;
@@ -166,7 +169,6 @@ mb_err_enum_t mbs_delete(mb_base_t *inst);
mb_err_enum_t mbs_enable(mb_base_t *inst);
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_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_RTU_EN || CONFIG_FMB_COMM_MODE_ASCII_EN)
+1 -1
View File
@@ -125,7 +125,7 @@ extern "C" {
* how to set this value. It is only used if MB_FUNC_OTHER_REP_SLAVEID_ENABLED
* is set to <code>1</code>.
*/
#define MB_FUNC_OTHER_REP_SLAVEID_BUF (32)
#define MB_FUNC_OTHER_REP_SLAVEID_BUF (CONFIG_FMB_CONTROLLER_SLAVE_ID_MAX_SIZE)
/*! \brief If the <em>Report Slave ID</em> function should be enabled. */
#define MB_FUNC_OTHER_REP_SLAVEID_ENABLED (CONFIG_FMB_CONTROLLER_SLAVE_ID_SUPPORT)
+3 -3
View File
@@ -14,9 +14,9 @@ extern "C" {
typedef struct mb_base_t mb_base_t;
#if MB_FUNC_OTHER_REP_SLAVEID_BUF
mb_exception_t mb_fn_report_slv_id(mb_base_t *inst, uint8_t *frame_ptr,uint16_t *len_buf);
mb_exception_t mbm_fn_report_slv_id(mb_base_t *inst, uint8_t *frame_ptr,uint16_t *len_buf);
#if MB_FUNC_OTHER_REP_SLAVEID_ENABLED
mb_exception_t mbs_fn_report_slave_id(mb_base_t *inst, uint8_t *frame_ptr,uint16_t *len_buf);
mb_exception_t mbm_fn_report_slave_id(mb_base_t *inst, uint8_t *frame_ptr,uint16_t *len_buf);
#endif
#if MB_FUNC_READ_INPUT_ENABLED
+21
View File
@@ -23,6 +23,27 @@ mb_err_enum_t mbm_rq_read_coils(mb_base_t *inst, uint8_t snd_addr, uint16_t coil
mb_err_enum_t mbm_rq_write_coil(mb_base_t *inst, uint8_t snd_addr, uint16_t coil_addr, uint16_t coil_data, uint32_t tout);
mb_err_enum_t mbm_rq_write_multi_coils(mb_base_t *inst, uint8_t snd_addr, uint16_t coil_addr, uint16_t coil_num, uint8_t *data_ptr, uint32_t tout);
#if MB_FUNC_OTHER_REP_SLAVEID_ENABLED
mb_err_enum_t mbm_rq_report_slave_id(mb_base_t *inst, uint8_t slave_addr, uint32_t timeout);
mb_exception_t mbm_fn_report_slave_id(mb_base_t *inst, uint8_t * pframe, uint16_t *usLen);
/*! \ingroup modbus_registers
* \brief The common callback function used to transfer common data as bytes from command buffer in little endian format.
*
* \param pdata A pointer to data in command buffer to be transferred.
* \param address Unused for this function == 0.
* \param bytes Number of bytes the callback function must supply.
*
* \return The function must return one of the following error codes:
* - mb_err_enum_t::MB_ENOERR If no error occurred. In this case a normal
* Modbus response is sent.
* - mb_err_enum_t::MB_ENOREG if can not map the data of the registers
* - mb_err_enum_t::MB_EILLSTATE if can not procceed with data transfer due to critical error
* - mb_err_enum_t::MB_EINVAL if value data can not be transferred
*/
mb_err_enum_t mbc_reg_common_cb(mb_base_t *inst, uint8_t *pdata, uint16_t address, uint16_t bytes);
#endif
#ifdef __cplusplus
}
#endif
+3 -2
View File
@@ -11,8 +11,9 @@
extern "C" {
#endif
mb_err_enum_t mb_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 MB_FUNC_OTHER_REP_SLAVEID_ENABLED
mb_exception_t mbs_fn_report_slave_id(mb_base_t *inst, uint8_t *frame_ptr, uint16_t *plen_buf);
#endif
#ifdef __cplusplus
}
+21 -5
View File
@@ -100,23 +100,39 @@ void mb_util_set_bits(uint8_t *byte_buf, uint16_t bit_offset, uint8_t but_num, u
*/
uint8_t mb_util_get_bits(uint8_t *byte_buf, uint16_t bit_offset, uint8_t but_num);
#if MB_FUNC_OTHER_REP_SLAVEID_ENABLED
/*! \brief Standard function to set slave ID in the modbus object.
*
* This function is used to set the Slave ID array for modbus object.
* This ID can then be read over Modbus.
*
* \param inst - instance pointer to base modbus object
* \param slv_id - slave short address.
* \param slave_id - slave short address.
* \param is_running - true, if the slave is running, false otherwise
* \param slv_idstr - the pointer to slave ID array to set in the modbus object
* \param slv_idstr_len - slave ID array length
* \param pdata - the pointer to slave ID array to set in the modbus object
* \param len - slave ID array length
*
* returns the modbus error code = MB_ENOERR, if set correctly, MB_ENOREG, otherwise
* \endcode
*/
mb_err_enum_t mb_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_slave_id(mb_base_t *inst, uint8_t sl_id, bool is_running, uint8_t const *pdata, uint16_t len);
/*! \brief Standard function to get slave ID from the modbus object.
*
* This function is used to get the Slave ID array for modbus object.
* This ID can then be read over Modbus.
*
* \param inst - instance pointer to base modbus object
* \param pdata - the pointer to store object ID array from the modbus object
* \param[in/out] pdata_len - input length of the allocated pdata array,
* returns the actual length of object id.
* returns the modbus error code = MB_ENOERR, if set correctly,
* MB_ENOREG - if the object ID is not set,
* MB_ENORES - no space to store object ID in the pdata buffer,
* MB_EINVAL - the arguments are not correct
*/
mb_err_enum_t mbs_get_slave_id(mb_base_t *inst, uint8_t *pdata, uint8_t *pdata_len);
#endif
#ifdef __cplusplus
}