Hi,
I am using S130 on an nRF51822 with SDK v12.3. I want to handle the different error codes that could result from calling sd_ble_gatts_hvx and retry later.
Firstly, there's a couple of error codes that I'm not understanding. ble_gatts.h describes BLE_ERROR_INVALID_CONN_HANDLE and NRF_ERROR_INVALID_STATE as follows:
* @retval ::BLE_ERROR_INVALID_CONN_HANDLE Invalid Connection Handle. * @retval ::NRF_ERROR_INVALID_STATE Invalid Connection State or notifications and/or indications not enabled in the CCCD.
What does 'Invalid Connection State' mean in this case? Which one of these would I receive if I have disconnected? I would expect to obtain BLE_ERROR_INVALID_CONN_HANDLE if I am disconnected. I was thinking maybe I get NRF_ERROR_INVALID_STATE if I have initiated a disconnection but it hasn't finished yet, and BLE_ERROR_INVALID_CONN_HANDLE if I am disconnected.
Another pair of error codes I can't quite differentiate is NRF_ERROR_BUSY and BLE_ERROR_NO_TX_PACKETS, which are are described in ble_gatts.h as follows:
* @retval ::NRF_ERROR_BUSY Procedure already in progress. * @retval ::BLE_ERROR_NO_TX_PACKETS No available application packets for this connection, applies only to notifications.
I found this S120 question which states that BLE layers are allowed to only queue one TX packet per connection, so NRF_ERROR_BUSY signals that another packet can't be queued. I don't know whether this applies to S130, and furthermore I don't see when BLE_ERROR_NO_TX_PACKETS would be returned if this is the case. My question is: under what situations would each of these error codes be returned?
Lastly, when I get these I would prefer to retry in response to a TX_COMPLETE event instead of a timer: I think this is possible, so that if I get NRF_ERROR_BUSY or BLE_ERROR_NO_TX_PACKETS I can expect a TX_COMPLETE event 100% of the time (except possibly when I disconnect or notifications are disabled instead), is that correct?
Edit: I found this diagram for S130 that shows a different behavior that what is described in the S120 question I linked. Still that leaves me with the question of under what circumstances is NRF_ERROR_BUSY returned.