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

sd_ble_gatts_value_set with const data

Hi

When implementing some characteristic handling i noticed, that in the newer softdevices the function "sd_ble_gatts_value_set" has changed to the following declaration: uint32_t sd_ble_gatts_value_set(uint16_t conn_handle, uint16_t handle, ble_gatts_value_t *p_value);

In the structure ble_gatts_value_t the member p_value points to the data to be written. As the type of p_value is "uint8_t *" i got a warning when using the function with a pointer to a constnant value. I ignored that by casting the pointer to (uint8_t *) because i assuemd, that when using the sturcture in sd_ble_gatts_value_set the data space won't be written. This actually work on target without a problem.

Yesterday i found out, that when this is used with serialization it is a problem. The serialization implementation of sd_ble_gatts_value_set somehow tries to write to the area the the p_value pointer points at. I did a quick fix for the probelm by copy the constant data into RAM anf us this area on the call of sd_ble_gatts_value_set.

I'm now not sure what is the right way to use sd_ble_gatts_value_set. If not necessairy i would prefere not to copy a value everytime it needs to be set. From my opinion the serialization should behave as much as possible like the softdevice itself.

How do you use the "sd_ble_gatts_value_set" function with constant data? Can the behavior of the serialisation be fixed to be equal to the softdevice?

Regards Adrian

Parents
  • I'm not sure if the softdevice really writes to this structure on sd_ble_gatts_value_set. The type ble_gatts_value_t is used for writing values and reading values. But it makes only sense that the region is written when reading values.

    I personaly prefered the old API without this structure ble_gatts_value_t where it was possible to write constant values. As a consequence of the new API I'm forced to copy the value to RAM before calling sd_ble_gatts_value_set.

Reply
  • I'm not sure if the softdevice really writes to this structure on sd_ble_gatts_value_set. The type ble_gatts_value_t is used for writing values and reading values. But it makes only sense that the region is written when reading values.

    I personaly prefered the old API without this structure ble_gatts_value_t where it was possible to write constant values. As a consequence of the new API I'm forced to copy the value to RAM before calling sd_ble_gatts_value_set.

Children
No Data
Related