Skip to content

Commit 9397a49

Browse files
thekurtovich2zero
authored andcommitted
feat(AdvDevice): Add convenience operator to NimBLEAddress
1 parent 17cc7da commit 9397a49

File tree

4 files changed

+11
-20
lines changed

4 files changed

+11
-20
lines changed

src/NimBLEAdvertisedDevice.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,16 @@ bool NimBLEAdvertisedDevice::isLegacyAdvertisement() const {
780780
# endif
781781
} // isLegacyAdvertisement
782782

783+
/**
784+
* @brief Convenience operator to convert this NimBLEAdvertisedDevice to NimBLEAddress representation.
785+
* @details This allows passing NimBLEAdvertisedDevice to functions
786+
* that accept NimBLEAddress and/or or it's methods as a parameter.
787+
*/
788+
NimBLEAdvertisedDevice::operator NimBLEAddress() const {
789+
NimBLEAddress address(getAddress());
790+
return address;
791+
} // operator NimBLEAddress
792+
783793
/**
784794
* @brief Get the payload advertised by the device.
785795
* @return The advertisement payload.

src/NimBLEAdvertisedDevice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ class NimBLEAdvertisedDevice {
9393
uint8_t getSecondaryPhy() const;
9494
uint16_t getPeriodicInterval() const;
9595
# endif
96+
operator NimBLEAddress() const;
9697

9798
const std::vector<uint8_t>& getPayload() const;
9899
const std::vector<uint8_t>::const_iterator begin() const;

src/NimBLEClient.cpp

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -141,22 +141,6 @@ bool NimBLEClient::connect(bool deleteAttributes, bool asyncConnect, bool exchan
141141
return connect(m_peerAddress, deleteAttributes, asyncConnect, exchangeMTU);
142142
} // connect
143143

144-
/**
145-
* @brief Connect to an advertising device.
146-
* @param [in] device The device to connect to.
147-
* @param [in] deleteAttributes If true this will delete any attribute objects this client may already\n
148-
* have created when last connected.
149-
* @param [in] asyncConnect If true, the connection will be made asynchronously and this function will return immediately.\n
150-
* If false, this function will block until the connection is established or the connection attempt times out.
151-
* @param [in] exchangeMTU If true, the client will attempt to exchange MTU with the server after connection.\n
152-
* If false, the client will use the default MTU size and the application will need to call exchangeMTU() later.
153-
* @return true on success.
154-
*/
155-
bool NimBLEClient::connect(const NimBLEAdvertisedDevice* device, bool deleteAttributes, bool asyncConnect, bool exchangeMTU) {
156-
NimBLEAddress address(device->getAddress());
157-
return connect(address, deleteAttributes, asyncConnect, exchangeMTU);
158-
} // connect
159-
160144
/**
161145
* @brief Connect to a BLE Server by address.
162146
* @param [in] address The address of the server.

src/NimBLEClient.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,6 @@ struct NimBLETaskData;
4848
*/
4949
class NimBLEClient {
5050
public:
51-
bool connect(const NimBLEAdvertisedDevice* device,
52-
bool deleteAttributes = true,
53-
bool asyncConnect = false,
54-
bool exchangeMTU = true);
5551
bool connect(const NimBLEAddress& address, bool deleteAttributes = true, bool asyncConnect = false, bool exchangeMTU = true);
5652
bool connect(bool deleteAttributes = true, bool asyncConnect = false, bool exchangeMTU = true);
5753
bool disconnect(uint8_t reason = BLE_ERR_REM_USER_CONN_TERM);

0 commit comments

Comments
 (0)