Remove type parameter from NimBLEClient::connect()

* The type is available in the NimBLEAddress parameter, no longer needed separately.

Co-authored-by: wakwak-koba <wakwak-koba@users.noreply.github.com>
This commit is contained in:
h2zero 2020-07-30 10:09:27 -06:00 committed by h2zero
parent b901eeb1e5
commit 73cec7a92a
3 changed files with 16 additions and 11 deletions

View file

@ -134,7 +134,7 @@ size_t NimBLEClient::deleteService(const NimBLEUUID &uuid) {
* @return True on success. * @return True on success.
*/ */
bool NimBLEClient::connect(bool deleteAttibutes) { bool NimBLEClient::connect(bool deleteAttibutes) {
return connect(m_peerAddress, 0, deleteAttibutes); return connect(m_peerAddress, deleteAttibutes);
} }
/** /**
@ -146,7 +146,7 @@ bool NimBLEClient::connect(bool deleteAttibutes) {
*/ */
bool NimBLEClient::connect(NimBLEAdvertisedDevice* device, bool deleteAttibutes) { bool NimBLEClient::connect(NimBLEAdvertisedDevice* device, bool deleteAttibutes) {
NimBLEAddress address(device->getAddress()); NimBLEAddress address(device->getAddress());
return connect(address, 0, deleteAttibutes); return connect(address, deleteAttibutes);
} }
@ -158,7 +158,7 @@ bool NimBLEClient::connect(NimBLEAdvertisedDevice* device, bool deleteAttibutes)
* have created and clears the vectors after successful connection. * have created and clears the vectors after successful connection.
* @return True on success. * @return True on success.
*/ */
bool NimBLEClient::connect(const NimBLEAddress &address, uint8_t type, bool deleteAttibutes) { bool NimBLEClient::connect(const NimBLEAddress &address, bool deleteAttibutes) {
NIMBLE_LOGD(LOG_TAG, ">> connect(%s)", address.toString().c_str()); NIMBLE_LOGD(LOG_TAG, ">> connect(%s)", address.toString().c_str());
if(!NimBLEDevice::m_synced) { if(!NimBLEDevice::m_synced) {
@ -175,16 +175,22 @@ bool NimBLEClient::connect(const NimBLEAddress &address, uint8_t type, bool dele
return false; return false;
} }
int rc = 0; if(address == NimBLEAddress("")) {
NIMBLE_LOGE(LOG_TAG, "Invalid peer address;(NULL)");
return false;
} else if(m_peerAddress != address) {
m_peerAddress = address; m_peerAddress = address;
}
ble_addr_t peerAddrt; ble_addr_t peerAddrt;
memcpy(&peerAddrt.val, address.getNative(),6); memcpy(&peerAddrt.val, m_peerAddress.getNative(),6);
peerAddrt.type = address.getType(); peerAddrt.type = m_peerAddress.getType();
ble_task_data_t taskData = {this, xTaskGetCurrentTaskHandle(), 0, nullptr}; ble_task_data_t taskData = {this, xTaskGetCurrentTaskHandle(), 0, nullptr};
m_pTaskData = &taskData; m_pTaskData = &taskData;
int rc = 0;
/* Try to connect the the advertiser. Allow 30 seconds (30000 ms) for /* Try to connect the the advertiser. Allow 30 seconds (30000 ms) for
* timeout (default value of m_connectTimeout). * timeout (default value of m_connectTimeout).
* Loop on BLE_HS_EBUSY if the scan hasn't stopped yet. * Loop on BLE_HS_EBUSY if the scan hasn't stopped yet.

View file

@ -38,10 +38,9 @@ class NimBLEAdvertisedDevice;
*/ */
class NimBLEClient { class NimBLEClient {
public: public:
bool connect(NimBLEAdvertisedDevice* device, bool deleteAttibutes = true);
bool connect(const NimBLEAddress &address, uint8_t type = BLE_ADDR_PUBLIC,
bool deleteAttibutes = true);
bool connect(bool deleteAttibutes = true); bool connect(bool deleteAttibutes = true);
bool connect(NimBLEAdvertisedDevice* device, bool deleteAttibutes = true);
bool connect(const NimBLEAddress &address, bool deleteAttibutes = true);
int disconnect(uint8_t reason = BLE_ERR_REM_USER_CONN_TERM); int disconnect(uint8_t reason = BLE_ERR_REM_USER_CONN_TERM);
NimBLEAddress getPeerAddress(); NimBLEAddress getPeerAddress();
void setPeerAddress(const NimBLEAddress &address); void setPeerAddress(const NimBLEAddress &address);

View file

@ -138,7 +138,7 @@ void NimBLEDevice::stopAdvertising() {
* @brief Creates a new client object and maintains a list of all client objects * @brief Creates a new client object and maintains a list of all client objects
* each client can connect to 1 peripheral device. * each client can connect to 1 peripheral device.
* @param [in] peerAddress An optional peer address that is copied to the new client * @param [in] peerAddress An optional peer address that is copied to the new client
* object, allows for calling connect() without providing a device or address. * object, allows for calling NimBLEClient::connect(bool) without a device or address parameter.
* @return A reference to the new client object. * @return A reference to the new client object.
*/ */
#if defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL) #if defined(CONFIG_BT_NIMBLE_ROLE_CENTRAL)