mirror of
https://github.com/h2zero/esp-nimble-cpp.git
synced 2024-12-23 03:20:46 +01:00
91210b8610
Refactor attributes to reduce code duplication and improve maintainability. * Add attribute base classes to provide common code. * Add const where possible to functions and parameters. * `NimBLECharacteristic::notify` no longer takes a `bool is_notification` parameter, instead `indicate()` should be called to send indications. * `NimBLECharacteristic::indicate` now takes the same parameters as `notify`. * `NimBLECharacteristicCallbacks` and `NimBLEDescriptorCallbacks` methods now take `const NimBLEConnInfo&` instead of non-const. * `NimBLECharacteristic::onNotify` callback removed as unnecessary, the library does not call notify without app input. * `NimBLERemoteCharacteristic::getRemoteService` now returns a `const NimBLERemoteService*` instead of non-const. * Add NimBLEUUID constructor that takes a reference to `ble_uuid_any_t`. * `NimBLERemoteService::getCharacteristics` now returns a `const std::vector<NimBLERemoteCharacteristic*>&` instead of non-const `std::vector<NimBLERemoteCharacteristic*>*` * `NimBLERemoteService::getValue` now returns `NimBLEAttValue` instead of `std::string` * `NimBLEService::getCharacteristics` now returns a `const std::vector<NimBLECharacteristic*>&` instead of a copy of std::vector<NimBLECharacteristic *>. * Remove const requirement for NimBLEConnInfo parameter in callbacks. Const is unnecessary as the data can't be changed by application code. * Change NimBLERemoteCharacteristic::getRemoteService to return const pointer.
66 lines
2.5 KiB
C++
66 lines
2.5 KiB
C++
#ifndef NIMBLECONNINFO_H_
|
|
#define NIMBLECONNINFO_H_
|
|
|
|
#if defined(CONFIG_NIMBLE_CPP_IDF)
|
|
# include "host/ble_gap.h"
|
|
#else
|
|
# include "nimble/nimble/host/include/host/ble_gap.h"
|
|
#endif
|
|
|
|
#include "NimBLEAddress.h"
|
|
|
|
/**
|
|
* @brief Connection information.
|
|
*/
|
|
class NimBLEConnInfo {
|
|
public:
|
|
/** @brief Gets the over-the-air address of the connected peer */
|
|
NimBLEAddress getAddress() const { return NimBLEAddress(m_desc.peer_ota_addr); }
|
|
|
|
/** @brief Gets the ID address of the connected peer */
|
|
NimBLEAddress getIdAddress() const { return NimBLEAddress(m_desc.peer_id_addr); }
|
|
|
|
/** @brief Gets the connection handle (also known as the connection id) of the connected peer */
|
|
uint16_t getConnHandle() const { return m_desc.conn_handle; }
|
|
|
|
/** @brief Gets the connection interval for this connection (in 1.25ms units) */
|
|
uint16_t getConnInterval() const { return m_desc.conn_itvl; }
|
|
|
|
/** @brief Gets the supervision timeout for this connection (in 10ms units) */
|
|
uint16_t getConnTimeout() const { return m_desc.supervision_timeout; }
|
|
|
|
/** @brief Gets the allowable latency for this connection (unit = number of intervals) */
|
|
uint16_t getConnLatency() const { return m_desc.conn_latency; }
|
|
|
|
/** @brief Gets the maximum transmission unit size for this connection (in bytes) */
|
|
uint16_t getMTU() const { return ble_att_mtu(m_desc.conn_handle); }
|
|
|
|
/** @brief Check if we are in the master role in this connection */
|
|
bool isMaster() const { return (m_desc.role == BLE_GAP_ROLE_MASTER); }
|
|
|
|
/** @brief Check if we are in the slave role in this connection */
|
|
bool isSlave() const { return (m_desc.role == BLE_GAP_ROLE_SLAVE); }
|
|
|
|
/** @brief Check if we are connected to a bonded peer */
|
|
bool isBonded() const { return (m_desc.sec_state.bonded == 1); }
|
|
|
|
/** @brief Check if the connection in encrypted */
|
|
bool isEncrypted() const { return (m_desc.sec_state.encrypted == 1); }
|
|
|
|
/** @brief Check if the the connection has been authenticated */
|
|
bool isAuthenticated() const { return (m_desc.sec_state.authenticated == 1); }
|
|
|
|
/** @brief Gets the key size used to encrypt the connection */
|
|
uint8_t getSecKeySize() const { return m_desc.sec_state.key_size; }
|
|
|
|
private:
|
|
friend class NimBLEServer;
|
|
friend class NimBLEClient;
|
|
friend class NimBLECharacteristic;
|
|
friend class NimBLEDescriptor;
|
|
|
|
ble_gap_conn_desc m_desc{};
|
|
NimBLEConnInfo(){};
|
|
NimBLEConnInfo(ble_gap_conn_desc desc) { m_desc = desc; }
|
|
};
|
|
#endif
|