components/freemodbus/tcp_master/modbus_controller/mbc_tcp_master.c
// Get parameter data for corresponding characteristic
Get parameter data for corresponding characteristic
Get parameter data for corresponding characteristic
static esp_err_t mbc_tcp_master_get_parameter(uint16_t cid, char* name, uint8_t* value, uint8_t *type)
{
    MB_MASTER_CHECK((name != NULL), ESP_ERR_INVALID_ARG, "mb incorrect descriptor.");
    MB_MASTER_CHECK((type != NULL), ESP_ERR_INVALID_ARG, "type pointer is incorrect.");
    esp_err_t error = ESP_ERR_INVALID_RESPONSE;
    mb_param_request_t request ;
    mb_parameter_descriptor_t reg_info = { 0 };
    uint8_t param_buffer[PARAM_MAX_SIZE] = { 0 };
    error = mbc_tcp_master_set_request(name, MB_PARAM_READ, &request, &reg_info);
    if ((error == ESP_OK) && (cid == reg_info.cid)) {
        error = mbc_tcp_master_send_request(&request, &param_buffer[0]);
        if (error == ESP_OK) {
            if (value != NULL) {
                error = mbc_tcp_master_set_param_data((void*)value, (void*)&param_buffer[0],
                                                    reg_info.param_type, reg_info.param_size);
                MB_MASTER_CHECK((error == ESP_OK), ESP_ERR_INVALID_STATE, "fail to set parameter data.");
            }
            ESP_LOGD(MB_MASTER_TAG, "%s: Good response for get cid(%u) = %s",
                                    __FUNCTION__, (int)reg_info.cid, (char*)esp_err_to_name(error));
        } else {
            ESP_LOGD(MB_MASTER_TAG, "%s: Bad response to get cid(%u) = %s",
                                            __FUNCTION__, reg_info.cid, (char*)esp_err_to_name(error));
        }
        *type = reg_info.param_type;
    } else {
        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;
}
static esp_err_t mbc_tcp_master_get_parameter ( uint16_t cid , char * name , uint8_t * value , uint8_t * type ) { MB_MASTER_CHECK ( ( name != NULL ) , ESP_ERR_INVALID_ARG , " " ) ; MB_MASTER_CHECK ( ( type != NULL ) , ESP_ERR_INVALID_ARG , " " ) ; esp_err_t error = ESP_ERR_INVALID_RESPONSE ; mb_param_request_t request ; mb_parameter_descriptor_t reg_info = { 0 } ; uint8_t param_buffer [ PARAM_MAX_SIZE ] = { 0 } ; error = mbc_tcp_master_set_request ( name , MB_PARAM_READ , & request , & reg_info ) ; if ( ( error == ESP_OK ) && ( cid == reg_info . cid ) ) { error = mbc_tcp_master_send_request ( & request , & param_buffer [ 0 ] ) ; if ( error == ESP_OK ) { if ( value != NULL ) { error = mbc_tcp_master_set_param_data ( ( void * ) value , ( void * ) & param_buffer [ 0 ] , reg_info . param_type , reg_info . param_size ) ; MB_MASTER_CHECK ( ( error == ESP_OK ) , ESP_ERR_INVALID_STATE , " " ) ; } ESP_LOGD ( MB_MASTER_TAG , " " , __FUNCTION__ , ( int ) reg_info . cid , ( char * ) esp_err_to_name ( error ) ) ; } else { ESP_LOGD ( MB_MASTER_TAG , " " , __FUNCTION__ , reg_info . cid , ( char * ) esp_err_to_name ( error ) ) ; } * type = reg_info . param_type ; } else { ESP_LOGE ( MB_MASTER_TAG , " " , __FUNCTION__ , reg_info . cid ) ; error = ESP_ERR_INVALID_ARG ; } return error ; }
Get parameter data for corresponding characteristic
Get parameter data for corresponding characteristic
// If data pointer is NULL then we don't need to set value (it is still in the cache of cid) // Set the type of parameter found in the table