Add disconnect overload to take NimBLEConnInfo reference. (#162)

* NimBLEConnInfo - Note that the connection handle is the same as the connection id in the comment for getConnHandle()

* NimBLEServer - int disconnect(const NimBLEConnInfo&) helper method
This commit is contained in:
cmorganBE 2024-06-08 12:06:57 -04:00 committed by GitHub
parent 2447af6a4d
commit f36929963d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 12 additions and 1 deletions

View file

@ -22,7 +22,7 @@ public:
/** @brief Gets the ID address of the connected peer */ /** @brief Gets the ID address of the connected peer */
NimBLEAddress getIdAddress() const { return NimBLEAddress(m_desc.peer_id_addr); } NimBLEAddress getIdAddress() const { return NimBLEAddress(m_desc.peer_id_addr); }
/** @brief Gets the connection handle of the connected peer */ /** @brief Gets the connection handle (also known as the connection id) of the connected peer */
uint16_t getConnHandle() const { return m_desc.conn_handle; } uint16_t getConnHandle() const { return m_desc.conn_handle; }
/** @brief Gets the connection interval for this connection (in 1.25ms units) */ /** @brief Gets the connection interval for this connection (in 1.25ms units) */

View file

@ -252,6 +252,15 @@ int NimBLEServer::disconnect(uint16_t connId, uint8_t reason) {
return rc; return rc;
} // disconnect } // disconnect
/**
* @brief Disconnect the specified client with optional reason.
* @param [in] connInfo Connection of the client to disconnect.
* @param [in] reason code for disconnecting.
* @return NimBLE host return code.
*/
int NimBLEServer::disconnect(const NimBLEConnInfo &connInfo, uint8_t reason) {
return disconnect(connInfo.getConnHandle(), reason);
} // disconnect
#if !CONFIG_BT_NIMBLE_EXT_ADV || defined(_DOXYGEN_) #if !CONFIG_BT_NIMBLE_EXT_ADV || defined(_DOXYGEN_)
/** /**

View file

@ -69,6 +69,8 @@ public:
NimBLEService* getServiceByHandle(uint16_t handle); NimBLEService* getServiceByHandle(uint16_t handle);
int disconnect(uint16_t connID, int disconnect(uint16_t connID,
uint8_t reason = BLE_ERR_REM_USER_CONN_TERM); uint8_t reason = BLE_ERR_REM_USER_CONN_TERM);
int disconnect(const NimBLEConnInfo &connInfo,
uint8_t reason = BLE_ERR_REM_USER_CONN_TERM);
void updateConnParams(uint16_t conn_handle, void updateConnParams(uint16_t conn_handle,
uint16_t minInterval, uint16_t maxInterval, uint16_t minInterval, uint16_t maxInterval,
uint16_t latency, uint16_t timeout); uint16_t latency, uint16_t timeout);