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

Length of sd_ble_gatts_sys_attr_get

According to the device manager the length in bytes returned by sd_ble_gatts_sys_attr_get() is: ((ATTR_SIZE * (CCCD_COUNT + 1) + CRC) * 4)

When I call sd_ble_gatts_sys_attr_get with p_sys_attr_data = NULL the returned length is 92.

How can the above formula give 92 as a result knowing that ATTR_SIZE = 6 and CRC = 2

I am using SD 7.1.0.

Parents
  • I think you've misread the defines. The first define is to sum the size of a system attribute, and the next one is for word-aligning the buffer. There is no "* 4" in the calculation of the byte size, only for word-alignment.

    This is the formula taken from SDK v7.2.0:

    (DM_GATT_ATTR_SIZE * (DM_GATT_CCCD_COUNT+1 )) + DM_GATT_CRC_SIZE
    

    Where the defines are:

    #define DM_GATT_ATTR_SIZE            6
    #define DM_GATT_CRC_SIZE             2
    

    You get back 92 bytes from sd_ble_gatts_sys_attr_get(). Strip away the CRC:

    DM_GATT_ATTR_SIZE * (CCCD_COUNT+1) = 92 - DM_GATT_CRC_SIZE = 90 bytes
    

    Now calculate the rest:

    (CCCD_COUNT + 1) = 90 / 6 = 15
    

    Your CCCD_COUNT is 14.

    What (most likely) has confused you is this calculation:

    #define DM_GATT_SERVER_ATTR_MAX_SIZE sizeof(uint32_t) *  CEIL_DIV(DM_GATT_ATTR_TOTAL_SIZE, sizeof(uint32_t))
    

    This sequence is just a rounding operation to ensure that the buffer is word-aligned. Input 22, and you get 24 back for instance.

    Cheers, Håkon

  • Anyone happens to know why we have to add 1 to the CCCD_COUNT?

Reply Children
No Data
Related