From af071138a31d96a71c86e5ac1e286b7d3873d4f1 Mon Sep 17 00:00:00 2001 From: Sandeep Mistry Date: Fri, 7 Apr 2017 15:59:25 -0400 Subject: [PATCH 1/2] Revert "Jira 857, BLEPeripheral::connected() always returns false, git 444" This reverts commit a2df1795ac275ac48485329dc0697ab2324715bf. --- libraries/CurieBLE/src/BLEPeripheral.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libraries/CurieBLE/src/BLEPeripheral.cpp b/libraries/CurieBLE/src/BLEPeripheral.cpp index 2bcee466..5bd0f1ec 100644 --- a/libraries/CurieBLE/src/BLEPeripheral.cpp +++ b/libraries/CurieBLE/src/BLEPeripheral.cpp @@ -146,8 +146,7 @@ BLECentral BLEPeripheral::central(void) bool BLEPeripheral::connected(void) { - BLEDevice centralBle = BLE.central(); - return centralBle.connected(); + return BLE.connected(); } void BLEPeripheral::init() From 4efc6977fc80507bae6135fcdb59c12bad187423 Mon Sep 17 00:00:00 2001 From: Sandeep Mistry Date: Fri, 7 Apr 2017 16:19:10 -0400 Subject: [PATCH 2/2] Correct value of BLE.connected() Now it will check: - if in peripheral mode and if a central is connected - if in central mode and if a peripheral is connected --- .../src/internal/BLEDeviceManager.cpp | 37 ++++++++++++++++--- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/libraries/CurieBLE/src/internal/BLEDeviceManager.cpp b/libraries/CurieBLE/src/internal/BLEDeviceManager.cpp index ed00e863..6afd9827 100644 --- a/libraries/CurieBLE/src/internal/BLEDeviceManager.cpp +++ b/libraries/CurieBLE/src/internal/BLEDeviceManager.cpp @@ -171,18 +171,43 @@ void BLEDeviceManager::end() bool BLEDeviceManager::connected(const BLEDevice *device) const { - bt_conn_t* conn = bt_conn_lookup_addr_le(device->bt_le_address()); bool retval = false; - //pr_debug(LOG_MODULE_BLE, "%s-%d: add-%s", __FUNCTION__, __LINE__, device->address().c_str()); - if (NULL != conn) + + if (BLEUtils::isLocalBLE(*device)) { - //pr_debug(LOG_MODULE_BLE, "%s-%d: state-%d", __FUNCTION__, __LINE__,conn->state); - if (conn->state == BT_CONN_CONNECTED) + // first check if in peripheral mode and a central is connected + if (BLEUtils::macAddressValid(_peer_central)) { retval = true; } - bt_conn_unref(conn); + else // next check if in central mode and connected to any peripherals + { + for (int i = 0; i < BLE_MAX_CONN_CFG; i++) + { + if (BLEUtils::macAddressValid(_peer_peripheral[i])) + { + retval = true; + break; + } + } + } + } + else + { + bt_conn_t* conn = bt_conn_lookup_addr_le(device->bt_le_address()); + + //pr_debug(LOG_MODULE_BLE, "%s-%d: add-%s", __FUNCTION__, __LINE__, device->address().c_str()); + if (NULL != conn) + { + //pr_debug(LOG_MODULE_BLE, "%s-%d: state-%d", __FUNCTION__, __LINE__,conn->state); + if (conn->state == BT_CONN_CONNECTED) + { + retval = true; + } + bt_conn_unref(conn); + } } + return retval; }