The documentation for setting up the characteristics is very thin - its no better than what one can read in the h-files. This method
sd_ble_gatts_characteristic_add(uint16_t service_handle, ble_gatts_char_md_t const *p_char_md, ble_gatts_attr_t const *p_attr_char_value, ble_gatts_char_handles_t *p_handles)
requires the population of the ble_gatts_char_md_t and ble_gatts_attr_t structures. Of these two structures, the part that is most vague is the specification of initial values, initial lengths, and maximum lengths and what these lengths have to cover in the .ble_gatts_attr_t structure.
The first question about the lengths and maximum lengths, does that mean just data? Do the max lengths given by
- #define BLE_GATTS_FIX_ATTR_LEN_MAX (510)
- #define BLE_GATTS_VAR_ATTR_LEN_MAX (512)
mean just data or do they include protocol overhead?
If I have a static value like a DIS characteristic and the actual value of the data is 16 bytes, what is the size of max_value? Is it also 16 bytes?
If I am indicating or notifying a characteristic, does that affect the max_value? If the characteristic can be written, what do I have to take into consideration?
I have one situation where the characteristics are only used as a tunnel.. The first characteristic is never read or written and I use it just to notify data in fragments. The data being notified is a persistent application buffer that may be much longer than the maximum attribute length but it remains in scope for the duration of the app. There is no need to 'place' that value or any part of it in the service table. Can I use BLE_GATTS_VLOC_USER in this case and take up zero space in the service table? Does my buffer have to hold overhead or just data? Will SoftDevice overwrite any data in this buffer (which would be a disaster)? I am not sure what BLE_GATTS_VLOC_USER requires. Do I simply provide space for SoftDevice to use it as it sees fit an my application has to keep its hand off it, or does it allow me to use sections of that data buffer for the notification that CANNOT BE ALTERED?
The second characteristic in this service supports both writes and indications. These are much smaller in size but again, the values written and values indicated are created by and used by the application only. The values written or indicated do not need to be persisted in the service table. How do I handle this case?
In general, I do not know how these sizes and buffers are used and how I can most efficiently (take least memory and minimize the service tables) do my task. I don't know if SoftDevice alters these buffers or whether the sizes have to account for protocol overhead (which probably means SoftDevice freely writes to these buffers. I do have a problem of running out of service table space when I start adding a few standard GATT services like the DIS and Battery Service. But currently everything is using BLE_GATTS_VLOC_STACK.
I wish this were clearly documented so I wouldn't have to ask.
Note that I cannot use any SDK because these services are prototypes and there is no support for them (yet). If they get accepted into BT-SIG, there may be support in the future.