I recently started using the gatt queue as a mechanism to buffer and send HVX notifications. At times our system may produce asynchronous notification events faster than the bluetooth link can process them. Instead of implementing scheduled retries, its convenient to utilize the GATT queue mechanism that is demonstrated in the various GATT client examples.
A small issue was discovered in the processing of the return code from sd_ble_gatts_hvx. Unlike the other sd_ble_gatts_** functions, this function may also return NRF_ERROR_RESOURCES, which is effectively the same as NRF_ERROR_BUSY. Without any modifications, the GATT queue module will produce an error log every time an HVX (notification) is unable to be sent, AND the HVX is dropped. This behavior does not fit the intended purpose of the GATT queue, therefore I suggest modifying the err_code checking after sd_ble_gatts_hvx to convert the NRF_ERROR_RESOURCES error to be NRF_ERROR_BUSY.
Here are the diffs for my changes:
diff --git a/components/ble/nrf_ble_gq/nrf_ble_gq.c b/components/ble/nrf_ble_gq/nrf_ble_gq.c index 9ef131c..f9ade8c 100644 --- a/components/ble/nrf_ble_gq/nrf_ble_gq.c +++ b/components/ble/nrf_ble_gq/nrf_ble_gq.c @@ -260,6 +260,10 @@ static void queue_process(nrf_queue_t const * const p_queue, uint16_t conn_handl { err_code = NRF_ERROR_DATA_SIZE; } + if (err_code == NRF_ERROR_RESOURCES) + { + err_code = NRF_ERROR_BUSY; + } } break; default: @@ -387,7 +391,10 @@ static bool request_process(nrf_ble_gq_req_t const * const p_req, uint16_t conn_ { err_code = NRF_ERROR_DATA_SIZE; } - + if (err_code == NRF_ERROR_RESOURCES) + { + err_code = NRF_ERROR_BUSY; + } } break; default: