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

Get number of vacant bytes before calling sd_ble_gatts_hvx()

I my application, I wish to send a large (60 bytes) bulk of data atomically, i.e. either send all or nothing. Assume I cannot increase the MTU.

  • Is it possible to query the number of free bytes the soft device has, so that calling sd_ble_gatts_hvx() will not fail due to NRF_ERROR_RESOURCES?
  • If not, how can I calculate it?  Is it by keeping track of p_ble_evt->evt.gatts_evt.params.hvn_tx_complete.count in the  BLE_GATTS_EVT_HVN_TX_COMPLETE event, subtracting it from the number of internal buffers, and multiplying the result by the characteristic size (set in add_char_params.max_len)?
  • How can I find or configure the number of internal buffers?
  • Is the number of internal buffers shared between Characteristics (i.e. will a notification to another Characteristic reduce the number of free buffers)?

Thanks :)

  • Hi,

    Is it possible to query the number of free bytes the soft device has, so that calling sd_ble_gatts_hvx() will not fail due to NRF_ERROR_RESOURCES?

    No, not directly. (But you can calculate it).

    If not, how can I calculate it?

    Yes, your approach here is correct. It's described here how you can keep track of the packet count.

    How can I find or configure the number of internal buffers?

    You configure it by calling sd_ble_cfg_set. See this link and this post.

    Is the number of internal buffers shared between Characteristics (i.e. will a notification to another Characteristic reduce the number of free buffers)?

    Yes, that is correct.

Related