This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to change value of descriptor?

Hello,

I've generated code via latest BDS and nRF51 SDK 10 plugin, and everything works OK, beside "desciptor" change. When I execute function to set value of descriptor:

ble_control_register_data_descriptor_set(&service_struct, &control_register_data_descriptor);

it returns "NRF_ERROR_INVALID_PARAM" and descriptor remain unchanged. I've checked arguments of the function and they match to declaration. in similar way, line above, I'm using also generated function for change related characteristic value:

ble_mug_control_register_data_set(&service_struct, &control_register_data);

and it works.

I can add that I'm calling this functions inside write event:

static void on_write(ble_service_t * p_service, ble_gatts_evt_write_t * p_ble_evt)

of other characteristic - I want achieve such behavior, that when client write "characteristic 1", then in "on_write", value of "characteristic 2" is evaluated as well as descriptor related to this characteristic.

I've prepared example, based on SDK10 example "experimental_bluetoothds_template", full source: experimental_bluetoothds_template_COPY.zip

www.filedropper.com/experimentalbluetoothdstemplatecopy

ble_service.c:114-118 contain code related to update descriptor value:

ble_service_control_register_data_new_descriptor_t descriptor;
uint8_t data = 0x88;
descriptor.control_register_data.size = 1;
descriptor.control_register_data.p_data = &data;
ble_service_control_register_data_new_descriptor_set(p_service, &descriptor);

Is there something I've missed, is impossible to change descriptor value in such scenario or there is other way to do this?

Parents
  • Inside ble_service_control_register_data_new_descriptor_set we find

    return sd_ble_gatts_value_set(p_service->conn_handle, p_service->control_register_data_new_descriptor_handles.value_handle, &gatts_value);
    

    The attribute handle we use here (second parameter) is never set. It is given to us here In ble_service_init :

    err_code = descriptor_add(BLE_GATT_HANDLE_INVALID, &control_register_data_new_descriptor, &descr_handle);
    

    But descr handle is not saved to p_service->control_register_data_new_descriptor_handles.value_handle, &gatts_value.

    I am not sure if this is a bug in BDS or the Nordic Plugin. Try replacing this in ble_service_init

    err_code = descriptor_add(BLE_GATT_HANDLE_INVALID, &control_register_data_new_descriptor, &descr_handle);
    

    with this:

    err_code = descriptor_add(BLE_GATT_HANDLE_INVALID, &control_register_data_new_descriptor, &(p_service->control_register_data_new_descriptor_handles.value_handle));
    

    Now we pass the attribute handle of the service struct, and the function descriptor_add will save the handle for us.

    PS: Try to avoid naming your descriptors "New descriptor". It is very confusing to read the generated code :)

  • Regarding name "New descriptor", it was generated by BDS. Originally defined name was just "descriptor". Maybe this also have to be fixed in BDS plugin.

Reply Children
No Data
Related