mirror of
https://github.com/h2zero/esp-nimble-cpp.git
synced 2024-11-22 13:10:55 +01:00
Add last error function to client.
This commit is contained in:
parent
d041a089e6
commit
7a82067177
2 changed files with 21 additions and 0 deletions
|
@ -63,6 +63,7 @@ NimBLEClient::NimBLEClient(const NimBLEAddress &peerAddress) : m_peerAddress(pee
|
|||
m_deleteCallbacks = false;
|
||||
m_pTaskData = nullptr;
|
||||
m_connEstablished = false;
|
||||
m_lastErr = 0;
|
||||
|
||||
m_pConnParams.scan_itvl = 16; // Scan interval in 0.625ms units (NimBLE Default)
|
||||
m_pConnParams.scan_window = 16; // Scan window in 0.625ms units (NimBLE Default)
|
||||
|
@ -252,6 +253,8 @@ bool NimBLEClient::connect(const NimBLEAddress &address, bool deleteAttibutes) {
|
|||
|
||||
} while (rc == BLE_HS_EBUSY);
|
||||
|
||||
m_lastErr = rc;
|
||||
|
||||
if(rc != 0) {
|
||||
m_pTaskData = nullptr;
|
||||
return false;
|
||||
|
@ -274,6 +277,7 @@ bool NimBLEClient::connect(const NimBLEAddress &address, bool deleteAttibutes) {
|
|||
return false;
|
||||
|
||||
} else if(taskData.rc != 0){
|
||||
m_lastErr = taskData.rc;
|
||||
NIMBLE_LOGE(LOG_TAG, "Connection failed; status=%d %s",
|
||||
taskData.rc,
|
||||
NimBLEUtils::returnCodeToString(taskData.rc));
|
||||
|
@ -315,6 +319,7 @@ bool NimBLEClient::secureConnection() {
|
|||
|
||||
int rc = NimBLEDevice::startSecurity(m_conn_id);
|
||||
if(rc != 0){
|
||||
m_lastErr = rc;
|
||||
m_pTaskData = nullptr;
|
||||
return false;
|
||||
}
|
||||
|
@ -323,6 +328,7 @@ bool NimBLEClient::secureConnection() {
|
|||
} while (taskData.rc == (BLE_HS_ERR_HCI_BASE + BLE_ERR_PINKEY_MISSING) && retryCount--);
|
||||
|
||||
if(taskData.rc != 0){
|
||||
m_lastErr = taskData.rc;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -373,6 +379,7 @@ int NimBLEClient::disconnect(uint8_t reason) {
|
|||
}
|
||||
|
||||
NIMBLE_LOGD(LOG_TAG, "<< disconnect()");
|
||||
m_lastErr = rc;
|
||||
return rc;
|
||||
} // disconnect
|
||||
|
||||
|
@ -535,6 +542,7 @@ int NimBLEClient::getRssi() {
|
|||
if(rc != 0) {
|
||||
NIMBLE_LOGE(LOG_TAG, "Failed to read RSSI error code: %d, %s",
|
||||
rc, NimBLEUtils::returnCodeToString(rc));
|
||||
m_lastErr = rc;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -673,11 +681,13 @@ bool NimBLEClient::retrieveServices(const NimBLEUUID *uuid_filter) {
|
|||
|
||||
if (rc != 0) {
|
||||
NIMBLE_LOGE(LOG_TAG, "ble_gattc_disc_all_svcs: rc=%d %s", rc, NimBLEUtils::returnCodeToString(rc));
|
||||
m_lastErr = rc;
|
||||
return false;
|
||||
}
|
||||
|
||||
// wait until we have all the services
|
||||
ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
|
||||
m_lastErr = taskData.rc;
|
||||
|
||||
if(taskData.rc == 0){
|
||||
NIMBLE_LOGD(LOG_TAG, "<< retrieveServices");
|
||||
|
@ -1159,6 +1169,15 @@ std::string NimBLEClient::toString() {
|
|||
} // toString
|
||||
|
||||
|
||||
/**
|
||||
* @brief Get the last error code reported by the NimBLE host
|
||||
* @return int, the NimBLE error code.
|
||||
*/
|
||||
int NimBLEClient::getLastError() {
|
||||
return m_lastErr;
|
||||
} // getLastError
|
||||
|
||||
|
||||
void NimBLEClientCallbacks::onConnect(NimBLEClient* pClient) {
|
||||
NIMBLE_LOGD("NimBLEClientCallbacks", "onConnect: default");
|
||||
}
|
||||
|
|
|
@ -71,6 +71,7 @@ public:
|
|||
void setDataLen(uint16_t tx_octets);
|
||||
void discoverAttributes();
|
||||
NimBLEConnInfo getConnInfo();
|
||||
int getLastError();
|
||||
|
||||
private:
|
||||
NimBLEClient(const NimBLEAddress &peerAddress);
|
||||
|
@ -88,6 +89,7 @@ private:
|
|||
bool retrieveServices(const NimBLEUUID *uuid_filter = nullptr);
|
||||
|
||||
NimBLEAddress m_peerAddress;
|
||||
int m_lastErr;
|
||||
uint16_t m_conn_id;
|
||||
bool m_connEstablished;
|
||||
bool m_deleteCallbacks;
|
||||
|
|
Loading…
Reference in a new issue