components/freemodbus/tcp_master/modbus_controller/mbc_tcp_master.c
// Set parameter value for characteristic selected by name and cid
Set parameter value for characteristic selected by name and cid
Set parameter value for characteristic selected by name and cid
static esp_err_t mbc_tcp_master_set_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((value != NULL), ESP_ERR_INVALID_ARG, "value pointer is incorrect.");
    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_WRITE, &request, &reg_info);
    if ((error == ESP_OK) && (cid == reg_info.cid)) {
        error = mbc_tcp_master_set_param_data((void*)&param_buffer[0], (void*)value,
                                                reg_info.param_type, reg_info.param_size);
        MB_MASTER_CHECK((error == ESP_OK), ESP_ERR_INVALID_STATE, "failure to set parameter data.");
        error = mbc_tcp_master_send_request(&request, &param_buffer[0]);
        if (error == ESP_OK) {
            ESP_LOGD(MB_MASTER_TAG, "%s: Good response for set cid(%u) = %s",
                                    __FUNCTION__, (int)reg_info.cid, (char*)esp_err_to_name(error));
        } else {
            ESP_LOGD(MB_MASTER_TAG, "%s: Bad response to set 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 requested 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_set_parameter ( uint16_t cid , char * name , uint8_t * value , uint8_t * type ) { MB_MASTER_CHECK ( ( name != NULL ) , ESP_ERR_INVALID_ARG , " " ) ; MB_MASTER_CHECK ( ( value != 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_WRITE , & request , & reg_info ) ; if ( ( error == ESP_OK ) && ( cid == reg_info . cid ) ) { error = mbc_tcp_master_set_param_data ( ( void * ) & param_buffer [ 0 ] , ( void * ) value , reg_info . param_type , reg_info . param_size ) ; MB_MASTER_CHECK ( ( error == ESP_OK ) , ESP_ERR_INVALID_STATE , " " ) ; error = mbc_tcp_master_send_request ( & request , & param_buffer [ 0 ] ) ; if ( error == ESP_OK ) { 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 ; }
Set parameter value for characteristic selected by name and cid
Set parameter value for characteristic selected by name and cid
// Transfer value of characteristic into parameter buffer // Send request to write characteristic data // Set the type of parameter found in the table