Merge branch 'bugfix/freemodbus_fix_zero_based_reg_address_in_iterator' into 'master'

freemodbus: fix mb zero based reg address

See merge request espressif/esp-idf!12422
This commit is contained in:
Michael (XIAO Xufeng) 2021-02-26 08:13:59 +00:00
commit 60dfb09122
2 changed files with 3 additions and 3 deletions

View File

@ -62,7 +62,7 @@ static mb_descr_entry_t* mbc_slave_find_reg_descriptor(mb_param_type_t type, uin
if ((addr >= it->start_offset) if ((addr >= it->start_offset)
&& (it->p_data) && (it->p_data)
&& (regs >= 1) && (regs >= 1)
&& ((addr + regs) <= (it->start_offset + reg_size + 1)) && ((addr + regs) <= (it->start_offset + reg_size))
&& (reg_size >= 1)) { && (reg_size >= 1)) {
return it; return it;
} }

View File

@ -118,7 +118,8 @@ void app_main(void)
reg_area.type = MB_PARAM_HOLDING; // Set type of register area reg_area.type = MB_PARAM_HOLDING; // Set type of register area
reg_area.start_offset = MB_REG_HOLDING_START_AREA0; // Offset of register area in Modbus protocol reg_area.start_offset = MB_REG_HOLDING_START_AREA0; // Offset of register area in Modbus protocol
reg_area.address = (void*)&holding_reg_params.holding_data0; // Set pointer to storage instance reg_area.address = (void*)&holding_reg_params.holding_data0; // Set pointer to storage instance
reg_area.size = sizeof(float) << 2; // Set the size of register storage instance // Set the size of register storage instance = 150 holding registers
reg_area.size = (size_t)(HOLD_OFFSET(holding_data4) - HOLD_OFFSET(test_regs));
ESP_ERROR_CHECK(mbc_slave_set_descriptor(reg_area)); ESP_ERROR_CHECK(mbc_slave_set_descriptor(reg_area));
reg_area.type = MB_PARAM_HOLDING; // Set type of register area reg_area.type = MB_PARAM_HOLDING; // Set type of register area
reg_area.start_offset = MB_REG_HOLDING_START_AREA1; // Offset of register area in Modbus protocol reg_area.start_offset = MB_REG_HOLDING_START_AREA1; // Offset of register area in Modbus protocol
@ -132,7 +133,6 @@ void app_main(void)
reg_area.address = (void*)&input_reg_params.input_data0; reg_area.address = (void*)&input_reg_params.input_data0;
reg_area.size = sizeof(float) << 2; reg_area.size = sizeof(float) << 2;
ESP_ERROR_CHECK(mbc_slave_set_descriptor(reg_area)); ESP_ERROR_CHECK(mbc_slave_set_descriptor(reg_area));
// Initialization of Input Registers area
reg_area.type = MB_PARAM_INPUT; reg_area.type = MB_PARAM_INPUT;
reg_area.start_offset = MB_REG_INPUT_START_AREA1; reg_area.start_offset = MB_REG_INPUT_START_AREA1;
reg_area.address = (void*)&input_reg_params.input_data4; reg_area.address = (void*)&input_reg_params.input_data4;