diff options
author | Sven Gothel <[email protected]> | 2020-04-25 21:51:20 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2020-04-25 21:51:20 +0200 |
commit | 1bdde736d5a4c929ca84c48d62b507bd08dd2eb9 (patch) | |
tree | 6af588fa9ca99e6dbfd70f4d36b04d68c9c1d628 | |
parent | 3460be939b76ef3a1895e27afe2dcfa53ff21b3f (diff) |
Utilizing HCI le_connect of HCIComm, resolving the connect lag of 2s
DBTManager::initAdapter: Relying on our HCI connect
- SET_CONNECTABLE := 0, SET_FAST_CONNECTABLE := 0
DBTDevice::le_connect / le_disconnect
- Issuing the HCI le_connect and le_disconnect
- le_disconnect: first HCI then DBTManager disconnect
- Refine peer_mac_type/own_mac_type type -> HCIAddressType,
clarifying different naming scheme compared to BDAddressType.
-rw-r--r-- | api/direct_bt/DBTTypes.hpp | 3 | ||||
-rw-r--r-- | src/direct_bt/DBTDevice.cpp | 19 | ||||
-rw-r--r-- | src/direct_bt/DBTManager.cpp | 4 |
3 files changed, 13 insertions, 13 deletions
diff --git a/api/direct_bt/DBTTypes.hpp b/api/direct_bt/DBTTypes.hpp index e3026657..85603cf5 100644 --- a/api/direct_bt/DBTTypes.hpp +++ b/api/direct_bt/DBTTypes.hpp @@ -255,7 +255,8 @@ namespace direct_bt { * and usual connection latency, interval etc. * </p> */ - uint16_t le_connect(const uint8_t peer_mac_type=HCIADDR_LE_PUBLIC, const uint8_t own_mac_type=HCIADDR_LE_PUBLIC, + uint16_t le_connect(const HCIAddressType peer_mac_type=HCIAddressType::HCIADDR_LE_PUBLIC, + const HCIAddressType own_mac_type=HCIAddressType::HCIADDR_LE_PUBLIC, const uint16_t interval=0x0004, const uint16_t window=0x0004, const uint16_t min_interval=0x000F, const uint16_t max_interval=0x000F, const uint16_t latency=0x0000, const uint16_t supervision_timeout=0x0C80, diff --git a/src/direct_bt/DBTDevice.cpp b/src/direct_bt/DBTDevice.cpp index d2781a0a..d246679f 100644 --- a/src/direct_bt/DBTDevice.cpp +++ b/src/direct_bt/DBTDevice.cpp @@ -136,7 +136,7 @@ void DBTDevice::update(EInfoReport const & data) { addServices(data.getServices()); } -uint16_t DBTDevice::le_connect(uint8_t peer_mac_type, uint8_t own_mac_type, +uint16_t DBTDevice::le_connect(HCIAddressType peer_mac_type, HCIAddressType own_mac_type, uint16_t interval, uint16_t window, uint16_t min_interval, uint16_t max_interval, uint16_t latency, uint16_t supervision_timeout, @@ -150,9 +150,9 @@ uint16_t DBTDevice::le_connect(uint8_t peer_mac_type, uint8_t own_mac_type, #ifdef USE_BT_MGMT DBTManager & mngr = adapter.getManager(); - leConnHandle = mngr.create_connection(adapter.dev_id, address, addressType); + mngr.create_connection(adapter.dev_id, address, addressType); // A NOP -#else +#endif std::shared_ptr<HCISession> session = adapter.getOpenSession(); if( nullptr == session || !session->isOpen() ) { ERR_PRINT("DBTDevice::connect: Not opened"); @@ -170,7 +170,6 @@ uint16_t DBTDevice::le_connect(uint8_t peer_mac_type, uint8_t own_mac_type, } std::shared_ptr<DBTDevice> thisDevice = getSharedInstance(); session->connectedLE(thisDevice); -#endif return leConnHandle; } @@ -181,11 +180,6 @@ void DBTDevice::le_disconnect(const uint8_t reason) { return; } -#ifdef USE_BT_MGMT - DBTManager & mngr = adapter.getManager(); - mngr.disconnect(adapter.dev_id, address, addressType); - -#else std::shared_ptr<HCISession> session = adapter.getOpenSession(); if( nullptr == session || !session->isOpen() ) { DBG_PRINT("DBTDevice::disconnect: Not opened"); @@ -197,8 +191,13 @@ void DBTDevice::le_disconnect(const uint8_t reason) { if( !session->hciComm.le_disconnect(_leConnHandle, reason) ) { DBG_PRINT("DBTDevice::disconnect: handle 0x%X, errno %d %s", _leConnHandle, errno, strerror(errno)); } + +#ifdef USE_BT_MGMT + DBTManager & mngr = adapter.getManager(); + mngr.disconnect(adapter.dev_id, address, addressType); // actual disconnect cmd +#endif + std::shared_ptr<DBTDevice> thisDevice = getSharedInstance(); session->disconnectedLE(thisDevice); -#endif } diff --git a/src/direct_bt/DBTManager.cpp b/src/direct_bt/DBTManager.cpp index c9ae6c05..bbe73a8e 100644 --- a/src/direct_bt/DBTManager.cpp +++ b/src/direct_bt/DBTManager.cpp @@ -177,8 +177,8 @@ bool DBTManager::initAdapter(const uint16_t dev_id, const BTMode btMode) { break; } - setMode(dev_id, MgmtOpcode::SET_CONNECTABLE, 1); - // setMode(dev_id, MgmtOpcode::SET_FAST_CONNECTABLE, 1); // ?? + setMode(dev_id, MgmtOpcode::SET_CONNECTABLE, 0); + setMode(dev_id, MgmtOpcode::SET_FAST_CONNECTABLE, 0); setMode(dev_id, MgmtOpcode::SET_POWERED, 1); return true; |