add connected(conn_hdl) for prph
This commit is contained in:
6 files changed
+28
-16
No files matched your search
@@ -82,9 +82,9 @@ bool BLECentral::connect(const ble_gap_evt_adv_report_t* adv_report)
|
||||
return connect(&adv_report->peer_addr);
|
||||
}
|
||||
|
||||
bool BLECentral::disconnect(uint16_t conn_handle)
|
||||
bool BLECentral::disconnect(uint16_t conn_hdl)
|
||||
{
|
||||
return ERROR_NONE == sd_ble_gap_disconnect(conn_handle, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
|
||||
return ERROR_NONE == sd_ble_gap_disconnect(conn_hdl, BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -92,9 +92,10 @@ bool BLECentral::disconnect(uint16_t conn_handle)
|
||||
* @param conn_handle
|
||||
* @return
|
||||
*/
|
||||
bool BLECentral::connected(uint16_t conn_handle)
|
||||
bool BLECentral::connected(uint16_t conn_hdl)
|
||||
{
|
||||
return Bluefruit.Gap.connected(conn_handle);
|
||||
BLEConnection* conn = Bluefruit.Gap.getConnection(conn_hdl);
|
||||
return conn && (conn->getRole() == BLE_GAP_ROLE_CENTRAL);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,10 +105,12 @@ bool BLECentral::connected(uint16_t conn_handle)
|
||||
*/
|
||||
bool BLECentral::connected(void)
|
||||
{
|
||||
for (uint8_t conn=0; conn<BLE_MAX_CONN; conn++)
|
||||
for (uint8_t c=0; c<BLE_MAX_CONN; c++)
|
||||
{
|
||||
BLEConnection* conn = Bluefruit.Gap.getConnection(c);
|
||||
|
||||
// skip Peripheral Role handle
|
||||
if ( Bluefruit.Gap.connected(conn) && (Bluefruit.Gap.getRole(conn) == BLE_GAP_ROLE_CENTRAL) )
|
||||
if ( conn && (conn->getRole() == BLE_GAP_ROLE_CENTRAL) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -66,9 +66,9 @@ class BLECentral
|
||||
|
||||
bool connect(const ble_gap_evt_adv_report_t* adv_report);
|
||||
bool connect(const ble_gap_addr_t *peer_addr);
|
||||
bool disconnect(uint16_t conn_handle);
|
||||
bool disconnect(uint16_t conn_hdl);
|
||||
|
||||
bool connected (uint16_t conn_handle); // If connected to a specific peripheral
|
||||
bool connected (uint16_t conn_hdl); // If connected to a specific peripheral
|
||||
bool connected (void); // If connected to any peripherals
|
||||
|
||||
void clearBonds (void);
|
||||
|
||||
@@ -110,6 +110,12 @@ uint16_t BLEGap::getMaxMtu(uint8_t role)
|
||||
return (role == BLE_GAP_ROLE_PERIPH) ? _prph.mtu_max : _central.mtu_max;
|
||||
}
|
||||
|
||||
|
||||
BLEConnection* BLEGap::getConnection(uint16_t conn_hdl)
|
||||
{
|
||||
return ( conn_hdl != BLE_CONN_HANDLE_INVALID ) ?_connection[conn_hdl] : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get current Mac address and its type
|
||||
* @param mac address
|
||||
@@ -157,8 +163,8 @@ bool BLEGap::requestPairing(uint16_t conn_hdl)
|
||||
|
||||
uint8_t BLEGap::getRole(uint16_t conn_hdl)
|
||||
{
|
||||
// return _connection[conn_hdl]->role;
|
||||
return _peers[conn_hdl].role;
|
||||
VERIFY(_connection[conn_hdl], BLE_GAP_ROLE_INVALID);
|
||||
return _connection[conn_hdl]->getRole();
|
||||
}
|
||||
|
||||
uint16_t BLEGap::getPeerName(uint16_t conn_hdl, char* buf, uint16_t bufsize)
|
||||
|
||||
@@ -66,11 +66,7 @@ class BLEGap
|
||||
return _sec_param;
|
||||
}
|
||||
|
||||
BLEConnection* getConnection(uint16_t conn_hdl)
|
||||
{
|
||||
return ( conn_hdl != BLE_CONN_HANDLE_INVALID ) ?_connection[conn_hdl] : NULL;
|
||||
}
|
||||
|
||||
BLEConnection* getConnection(uint16_t conn_hdl);
|
||||
bool connected (uint16_t conn_hdl);
|
||||
bool requestPairing (uint16_t conn_hdl);
|
||||
|
||||
|
||||
@@ -541,6 +541,12 @@ bool AdafruitBluefruit::connected(void)
|
||||
return ( _conn_hdl != BLE_CONN_HANDLE_INVALID );
|
||||
}
|
||||
|
||||
bool AdafruitBluefruit::connected(uint16_t conn_hdl)
|
||||
{
|
||||
BLEConnection* conn = Gap.getConnection(conn_hdl);
|
||||
return conn && (conn->getRole() == BLE_GAP_ROLE_PERIPH);
|
||||
}
|
||||
|
||||
bool AdafruitBluefruit::disconnect(void)
|
||||
{
|
||||
// disconnect if connected
|
||||
|
||||
@@ -154,7 +154,8 @@ class AdafruitBluefruit
|
||||
/*------------------------------------------------------------------*/
|
||||
/* GAP, Connections and Bonding
|
||||
*------------------------------------------------------------------*/
|
||||
bool connected (void);
|
||||
bool connected (void); // connected with any central
|
||||
bool connected (uint16_t conn_hdl); // connected to a specific central
|
||||
bool disconnect (void);
|
||||
|
||||
bool setConnInterval (uint16_t min, uint16_t max);
|
||||
|
||||
Reference in new issue
Block a user