Hi,
i have a question regarding the USART NUS error handler.
In my setup, two Nordic BLE Chips are communicating via the USART service.
One chip is acting as a central unit, the other as a peripheral. The central is the the one sending cyclic messages, the peripheral is only receiving.
If the Peripheral chip looses power or is out of range which is a valid scenario, the Central is running into the NUS error handler.
See the code below:
static void nus_error_handler(uint32_t nrf_error) {
APP_ERROR_HANDLER(nrf_error);
}
static void nus_c_init(void) {
ret_code_t err_code;
ble_nus_c_init_t init;
init.evt_handler = ble_nus_c_evt_handler;
init.error_handler = nus_error_handler;
init.p_gatt_queue = &m_ble_gatt_queue;
err_code = ble_nus_c_init(&m_ble_nus_c, &init);
APP_ERROR_CHECK(err_code);
}
void appl_txble_callback(uint8_t *Data, uint16_t Length, uint8_t bleChannel) {
ret_code_t ret_val = NRF_SUCCESS;
if (m_ble_gatt_queue.p_conn_handles[bleChannel] !=
BLE_CONN_HANDLE_INVALID)
{
do {
ret_val = ble_nus_c_string_send(&m_ble_nus_c, Data, Length);
if(ret_val == NRF_SUCCESS)
{
nrf_gpio_pin_toggle(LED_MESSAGE_TOGGLE);
}
if ((ret_val != NRF_SUCCESS) && (ret_val != NRF_ERROR_RESOURCES)) {
NRF_LOG_ERROR("Failed sending NUS message. Error 0x%x. ", ret_val);
APP_ERROR_CHECK(ret_val);
} else {
ret_val = NRF_ERROR_SVC_HANDLER_MISSING;
}
} while (ret_val == NRF_ERROR_RESOURCES);
}
}
In the described scenario the Central unit will throw an nus error, thus invoking the callback "nus_error_handler" with the error code 19 NRF_ERROR_RESOURCES.
I am unsure how to handle the error in the callback, since i only get the error code in the handler, without any context of the error.
What handling would be intented? No context is known, thus it is possible to have another source of the error as the described case.
Is there an API to distinguish between the channel on which the error occured, or to shut the channel down? Altering the GATT Queue variable m_ble_gatt_queue does not seems correct.
Thanks for your help!
Jan