From efa0aeb83164f4819d771598743df9e831a6000a Mon Sep 17 00:00:00 2001 From: aleks Date: Mon, 9 Aug 2021 13:54:18 +0200 Subject: [PATCH] freemodbus: fix invalid error handling for duplicate param_key --- components/freemodbus/common/include/esp_modbus_master.h | 4 ++-- .../serial_master/modbus_controller/mbc_serial_master.c | 4 +++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/components/freemodbus/common/include/esp_modbus_master.h b/components/freemodbus/common/include/esp_modbus_master.h index 6fae9540be..cfb5034f88 100644 --- a/components/freemodbus/common/include/esp_modbus_master.h +++ b/components/freemodbus/common/include/esp_modbus_master.h @@ -208,7 +208,7 @@ esp_err_t mbc_master_get_cid_info(uint16_t cid, const mb_parameter_descriptor_t* * @return * - esp_err_t ESP_OK - request was successful and value buffer contains * representation of actual parameter data from slave - * - esp_err_t ESP_ERR_INVALID_ARG - invalid argument of function + * - esp_err_t ESP_ERR_INVALID_ARG - invalid argument of function or parameter descriptor * - esp_err_t ESP_ERR_INVALID_RESPONSE - an invalid response from slave * - esp_err_t ESP_ERR_INVALID_STATE - invalid state during data processing or allocation failure * - esp_err_t ESP_ERR_TIMEOUT - operation timed out and no response from slave @@ -229,7 +229,7 @@ esp_err_t mbc_master_get_parameter(uint16_t cid, char* name, uint8_t* value, uin * * @return * - esp_err_t ESP_OK - request was successful and value was saved in the slave device registers - * - esp_err_t ESP_ERR_INVALID_ARG - invalid argument of function + * - esp_err_t ESP_ERR_INVALID_ARG - invalid argument of function or parameter descriptor * - esp_err_t ESP_ERR_INVALID_RESPONSE - an invalid response from slave during processing of parameter * - esp_err_t ESP_ERR_INVALID_STATE - invalid state during data processing or allocation failure * - esp_err_t ESP_ERR_TIMEOUT - operation timed out and no response from slave diff --git a/components/freemodbus/serial_master/modbus_controller/mbc_serial_master.c b/components/freemodbus/serial_master/modbus_controller/mbc_serial_master.c index 1cd9bdcd20..ef0ae39d79 100644 --- a/components/freemodbus/serial_master/modbus_controller/mbc_serial_master.c +++ b/components/freemodbus/serial_master/modbus_controller/mbc_serial_master.c @@ -467,8 +467,9 @@ static esp_err_t mbc_serial_master_get_parameter(uint16_t cid, char* name, // Set the type of parameter found in the table *type = reg_info.param_type; } else { - ESP_LOGD(MB_MASTER_TAG, "%s: The cid(%u) not found in the data dictionary.", + ESP_LOGE(MB_MASTER_TAG, "%s: The cid(%u) not found in the data dictionary.", __FUNCTION__, reg_info.cid); + error = ESP_ERR_INVALID_ARG; } return error; } @@ -509,6 +510,7 @@ static esp_err_t mbc_serial_master_set_parameter(uint16_t cid, char* name, } else { ESP_LOGE(MB_MASTER_TAG, "%s: The requested cid(%u) not found in the data dictionary.", __FUNCTION__, reg_info.cid); + error = ESP_ERR_INVALID_ARG; } return error; }