Skip to content

Commit 95466c6

Browse files
h2zerowakwak-koba
andcommitted
Remove type parameter from NimBLEClient::connect()
* The type is available in the NimBLEAddress parameter, no longer needed separately. Co-authored-by: wakwak-koba <[email protected]>
1 parent 48f607f commit 95466c6

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

src/NimBLEClient.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ size_t NimBLEClient::deleteService(const NimBLEUUID &uuid) {
134134
* @return True on success.
135135
*/
136136
bool NimBLEClient::connect(bool deleteAttibutes) {
137-
return connect(m_peerAddress, 0, deleteAttibutes);
137+
return connect(m_peerAddress, deleteAttibutes);
138138
}
139139

140140
/**
@@ -146,7 +146,7 @@ bool NimBLEClient::connect(bool deleteAttibutes) {
146146
*/
147147
bool NimBLEClient::connect(NimBLEAdvertisedDevice* device, bool deleteAttibutes) {
148148
NimBLEAddress address(device->getAddress());
149-
return connect(address, 0, deleteAttibutes);
149+
return connect(address, deleteAttibutes);
150150
}
151151

152152

@@ -158,7 +158,7 @@ bool NimBLEClient::connect(NimBLEAdvertisedDevice* device, bool deleteAttibutes)
158158
* have created and clears the vectors after successful connection.
159159
* @return True on success.
160160
*/
161-
bool NimBLEClient::connect(const NimBLEAddress &address, uint8_t type, bool deleteAttibutes) {
161+
bool NimBLEClient::connect(const NimBLEAddress &address, bool deleteAttibutes) {
162162
NIMBLE_LOGD(LOG_TAG, ">> connect(%s)", address.toString().c_str());
163163

164164
if(!NimBLEDevice::m_synced) {
@@ -175,16 +175,22 @@ bool NimBLEClient::connect(const NimBLEAddress &address, uint8_t type, bool dele
175175
return false;
176176
}
177177

178-
int rc = 0;
179-
m_peerAddress = address;
178+
if(address == NimBLEAddress("")) {
179+
NIMBLE_LOGE(LOG_TAG, "Invalid peer address;(NULL)");
180+
return false;
181+
} else if(m_peerAddress != address) {
182+
m_peerAddress = address;
183+
}
180184

181185
ble_addr_t peerAddrt;
182-
memcpy(&peerAddrt.val, address.getNative(),6);
183-
peerAddrt.type = address.getType();
186+
memcpy(&peerAddrt.val, m_peerAddress.getNative(),6);
187+
peerAddrt.type = m_peerAddress.getType();
184188

185189
ble_task_data_t taskData = {this, xTaskGetCurrentTaskHandle(), 0, nullptr};
186190
m_pTaskData = &taskData;
187191

192+
int rc = 0;
193+
188194
/* Try to connect the the advertiser. Allow 30 seconds (30000 ms) for
189195
* timeout (default value of m_connectTimeout).
190196
* Loop on BLE_HS_EBUSY if the scan hasn't stopped yet.

src/NimBLEClient.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ class NimBLEAdvertisedDevice;
3939
class NimBLEClient {
4040
public:
4141
bool connect(NimBLEAdvertisedDevice* device, bool deleteAttibutes = true);
42-
bool connect(const NimBLEAddress &address, uint8_t type = BLE_ADDR_PUBLIC,
43-
bool deleteAttibutes = true);
42+
bool connect(const NimBLEAddress &address, bool deleteAttibutes = true);
4443
bool connect(bool deleteAttibutes = true);
4544
int disconnect(uint8_t reason = BLE_ERR_REM_USER_CONN_TERM);
4645
NimBLEAddress getPeerAddress();

src/NimBLEDevice.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ void NimBLEDevice::stopAdvertising() {
138138
* @brief Creates a new client object and maintains a list of all client objects
139139
* each client can connect to 1 peripheral device.
140140
* @param [in] peerAddress An optional peer address that is copied to the new client
141-
* object, allows for calling connect() without providing a device or address.
141+
* object, allows for calling NimBLEClient::connect(bool) without a device or address parameter.
142142
* @return A reference to the new client object.
143143
*/
144144
#if defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL)

0 commit comments

Comments
 (0)