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

Updating the value pointer for a BLE_GATTS_VLOC_USER characteristic

Hello!

I have a characteristic defined to be in user memory by the BLE_GATTS_VLOC_USER flag.

The initial length is 0 and the initial value pointer is NULL.

Now I want my characteristic to dynamically point to different places in my application memory.

For this I tried using the sd_ble_gatts_value_set function like following

// update itemdata characteristic
ble_gatts_value_t item_data = {.len = active_data_item->size, .offset = 0, .p_value = (uint8_t *)active_data_item->address};
ret_code_t set_value_result = sd_ble_gatts_value_set(m_gds.conn_handle, m_gds.generic_data_itemdata_char_handles.value_handle, &item_data);
APP_ERROR_CHECK(set_value_result);

When trying to update the characteristic I noticed that the length of my characteristic changes when reading the characteristic after setting the value, but not the value itself.

The value itself always seems to stay static and not point to any of my new data I assign.

When changing the characteristic to BLE_GATTS_VLOC_STACK everything works as expected.

But I'd rather have the characteristic values in my own memory, without having a duplicate in the SoftDevice stack

What am I missing?

I am using SDK 15.3.0 in this project

Thanks in advance

Michael!

Edit: Fixed a confusing sentence...

Parents
  • Hi Mikoay, 

    I don't think you can use NULL as the p_value when declaring the characteristic. 
    This is the description in ble_gatts_attr_t about p_value:

    Please note that if the @ref BLE_GATTS_VLOC_USER value location is selected in the attribute metadata, this will have to point to a buffer
    that remains valid through the lifetime of the attribute.

  • If I assign a value which is not NULL for initialization it doesn't change the behavior.
    Also, there doesn't seem to be any NULL check when creating the characteristic. I've been able to use NULL without a problem.

    But that's not what I'm trying to do.

    I'd like to update where the characteristic points to.


    So when initializing my characteristic points to variable A in my app memory.
    After the user interacts with the device in some way this changes and now my characteristic should point to variable B.

    I expect to be able to update where the characteristic points to by using the method I mentioned above but this does not work.

    How do I change where my characteristic points to? If that is possible

  • No, that wouldn't work. You need to provide a valid buffer when declaring the characteristic. And when you call sd_ble_gatts_value_set() the softdevice simply does a memcpy(). So it's not possible to change the buffer location after you declare the characteristic. 

    I'm not sure why you don't receive any error when providing NULL pointer as the value of the characteristic. 

  • My initial characteristic length is 0, so maybe that's why there is no error being thrown by the internal memcpy, I'd guess

    So when using BLE_GATTS_VLOC_USER  there is now way to update the value pointer, right?
    Could this maybe be added in the future? Or give us the ability to pass a pointer to a pointer so we can change where it points to in my memory?

    For now I'll just keep using BLE_GATTS_VLOC_STACK I guess.

    Thanks for your help!

Reply
  • My initial characteristic length is 0, so maybe that's why there is no error being thrown by the internal memcpy, I'd guess

    So when using BLE_GATTS_VLOC_USER  there is now way to update the value pointer, right?
    Could this maybe be added in the future? Or give us the ability to pass a pointer to a pointer so we can change where it points to in my memory?

    For now I'll just keep using BLE_GATTS_VLOC_STACK I guess.

    Thanks for your help!

Children
No Data
Related