From fae53b8d7ffac90be44740824e26e34fff93d614 Mon Sep 17 00:00:00 2001 From: h2zero Date: Wed, 3 Jul 2024 13:11:03 -0600 Subject: [PATCH] Remove asserts from NimBLEDevice. --- src/NimBLEDevice.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/NimBLEDevice.cpp b/src/NimBLEDevice.cpp index 8daa282..a746d38 100644 --- a/src/NimBLEDevice.cpp +++ b/src/NimBLEDevice.cpp @@ -299,7 +299,7 @@ size_t NimBLEDevice::getClientListSize() { /** * @brief Get a reference to a client by connection ID. * @param [in] conn_id The client connection ID to search for. - * @return A pointer to the client object with the spcified connection ID. + * @return A pointer to the client object with the specified connection ID or nullptr. */ /* STATIC */ NimBLEClient* NimBLEDevice::getClientByID(uint16_t conn_id) { @@ -308,7 +308,7 @@ NimBLEClient* NimBLEDevice::getClientByID(uint16_t conn_id) { return (*it); } } - assert(0); + return nullptr; } // getClientByID @@ -806,7 +806,10 @@ void NimBLEDevice::onSync(void) /* Make sure we have proper identity address set (public preferred) */ int rc = ble_hs_util_ensure_addr(0); - assert(rc == 0); + if (rc != 0) { + NIMBLE_LOGE(LOG_TAG, "error ensuring address; rc=%d", rc); + return; + } #ifndef ESP_PLATFORM rc = ble_hs_id_infer_auto(m_own_addr_type, &m_own_addr_type); @@ -918,7 +921,9 @@ void NimBLEDevice::init(const std::string &deviceName) { // Set the device name. rc = ble_svc_gap_device_name_set(deviceName.c_str()); - assert(rc == 0); + if (rc != 0) { + NIMBLE_LOGE(LOG_TAG, "ble_svc_gap_device_name_set() failed; rc=%d", rc); + } ble_store_config_init(); @@ -1248,10 +1253,10 @@ void NimBLEDevice::setCustomGapHandler(gap_event_handler handler) { int rc = ble_gap_event_listener_register(&m_listener, m_customGapHandler, NULL); if(rc == BLE_HS_EALREADY){ NIMBLE_LOGI(LOG_TAG, "Already listening to GAP events."); + } else if (rc != 0) { + NIMBLE_LOGE(LOG_TAG, "ble_gap_event_listener_register: rc=%d %s", rc, NimBLEUtils::returnCodeToString(rc)); } - else{ - assert(rc == 0); - } + } // setCustomGapHandler #endif // CONFIG_BT_ENABLED