update GAP to support multiple connections
This commit is contained in:
1 parent
f649712446
commit
74b032b880
8 files changed
+98
-29
No files matched your search
+11
-3
@@ -2,19 +2,27 @@
|
||||
|
||||
## 0.6.5
|
||||
|
||||
### Core
|
||||
|
||||
- Fix setName() issue
|
||||
- Add Low Level format sketch for filesystem: `libraries/nffs/examples/EraseNffs`
|
||||
- Add SRAM usage when compiling
|
||||
- Reduce Stack size from 3KB to 2KB, and functions dbgStackUsed(), dbgStackTotal() for dynamic stack usage
|
||||
- Updated for latest Bluefruit LE Connect version with RGBW support
|
||||
- Fix #48 SPI & I2C warnings
|
||||
- Change board define from ARDUINO_FEATHER52 to ARDUINO_NRF52_FEATHER (ARDUINO_FEATHER52 still exists for backward comaptiable)
|
||||
- Change pin in hwpwm and hid_camerashutter sketches
|
||||
- Update nffs code to mynewt v1.0.0
|
||||
- Add Realtrace support using Segger Sysview
|
||||
- Add Event recording support using Segger Sysview
|
||||
|
||||
### BLE
|
||||
|
||||
- Updated for latest Bluefruit LE Connect version with RGBW support
|
||||
- Implement Gatt readCharByUuid()
|
||||
- Implement Gap getPeerName()
|
||||
|
||||
### New Examples
|
||||
|
||||
- Add Low Level format sketch for filesystem: `libraries/nffs/examples/EraseNffs`
|
||||
|
||||
## 0.6.0
|
||||
|
||||
### Core
|
||||
|
||||
@@ -183,14 +183,33 @@ bool BLECentral::connect(const ble_gap_evt_adv_report_t* adv_report, uint16_t mi
|
||||
return connect(&adv_report->peer_addr, min_conn_interval, max_conn_interval);
|
||||
}
|
||||
|
||||
bool BLECentral::connected(void)
|
||||
/**
|
||||
* Check if connected to a specific peripheral
|
||||
* @param conn_handle
|
||||
* @return
|
||||
*/
|
||||
bool BLECentral::connected(uint16_t conn_handle)
|
||||
{
|
||||
return (_conn_hdl != BLE_CONN_HANDLE_INVALID);
|
||||
return Bluefruit.Gap.connected(conn_handle);
|
||||
}
|
||||
|
||||
uint16_t BLECentral::connHandle (void)
|
||||
/**
|
||||
* Check if connected to ANY peripherals
|
||||
* @param conn_handle
|
||||
* @return
|
||||
*/
|
||||
bool BLECentral::connected(void)
|
||||
{
|
||||
return _conn_hdl;
|
||||
for (uint8_t conn=0; conn<BLE_GAP_MAX_CONN; conn++)
|
||||
{
|
||||
// skip Peripherl Role handle
|
||||
if (conn != Bluefruit.connHandle() )
|
||||
{
|
||||
if ( Bluefruit.Gap.connected(conn) ) return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void BLECentral::setConnectCallback( connect_callback_t fp)
|
||||
|
||||
@@ -81,8 +81,10 @@ class BLECentral
|
||||
uint16_t min_conn_interval = BLE_GAP_CONN_MIN_INTERVAL_DFLT,
|
||||
uint16_t max_conn_interval = BLE_GAP_CONN_MAX_INTERVAL_DFLT);
|
||||
|
||||
// Check if connected to a specific peripheral
|
||||
bool connected (uint16_t conn_handle);
|
||||
// Check if connected to any peripherals
|
||||
bool connected (void);
|
||||
uint16_t connHandle (void);
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* CALLBACKS
|
||||
|
||||
@@ -38,7 +38,23 @@
|
||||
|
||||
BLEGap::BLEGap(void)
|
||||
{
|
||||
for(int i=0; i<BLE_GAP_MAX_CONN; i++) _txpacket_sem[i] = NULL;
|
||||
varclr(&_peers);
|
||||
}
|
||||
|
||||
bool BLEGap::connected(uint16_t conn_handle)
|
||||
{
|
||||
return _peers[conn_handle].connected;
|
||||
}
|
||||
|
||||
uint8_t BLEGap::getPeerAddr(uint16_t conn_handle, uint8_t addr[6])
|
||||
{
|
||||
memcpy(addr, _peers[conn_handle].addr.addr, BLE_GAP_ADDR_LEN);
|
||||
return _peers[conn_handle].addr.addr_type;
|
||||
}
|
||||
|
||||
ble_gap_addr_t BLEGap::getPeerAddr(uint16_t conn_handle)
|
||||
{
|
||||
return _peers[conn_handle].addr;
|
||||
}
|
||||
|
||||
bool BLEGap::getTxPacket(void)
|
||||
@@ -48,9 +64,9 @@ bool BLEGap::getTxPacket(void)
|
||||
|
||||
bool BLEGap::getTxPacket(uint16_t conn_handle)
|
||||
{
|
||||
VERIFY( (conn_handle < BLE_GAP_MAX_CONN) && (_txpacket_sem[conn_handle] != NULL) );
|
||||
VERIFY( (conn_handle < BLE_GAP_MAX_CONN) && (_peers[conn_handle].txpacket_sem != NULL) );
|
||||
|
||||
return xSemaphoreTake(_txpacket_sem[conn_handle], ms2tick(BLE_GENERIC_TIMEOUT));
|
||||
return xSemaphoreTake(_peers[conn_handle].txpacket_sem, ms2tick(BLE_GENERIC_TIMEOUT));
|
||||
}
|
||||
|
||||
uint16_t BLEGap::getPeerName(char* buf, uint16_t bufsize)
|
||||
@@ -63,33 +79,42 @@ uint16_t BLEGap::getPeerName(uint16_t conn_handle, char* buf, uint16_t bufsize)
|
||||
return Bluefruit.Gatt.readCharByUuid(conn_handle, BLEUuid(BLE_UUID_GAP_CHARACTERISTIC_DEVICE_NAME), buf, bufsize);
|
||||
}
|
||||
|
||||
/**
|
||||
* Event handler
|
||||
* @param evt
|
||||
*/
|
||||
void BLEGap::_eventHandler(ble_evt_t* evt)
|
||||
{
|
||||
// conn handle has fixed offset regardless of event type
|
||||
const uint16_t conn_handle = evt->evt.common_evt.conn_handle;
|
||||
|
||||
gap_peer_t* peer = &_peers[conn_handle];
|
||||
|
||||
switch(evt->header.evt_id)
|
||||
{
|
||||
case BLE_GAP_EVT_CONNECTED:
|
||||
{
|
||||
peer->connected = true;
|
||||
peer->addr = evt->evt.gap_evt.params.connected.peer_addr;
|
||||
|
||||
// Init transmission buffer for notification
|
||||
uint8_t txbuf_max;
|
||||
(void) sd_ble_tx_packet_count_get(conn_handle, &txbuf_max);
|
||||
_txpacket_sem[conn_handle] = xSemaphoreCreateCounting(txbuf_max, txbuf_max);
|
||||
}
|
||||
peer->txpacket_sem = xSemaphoreCreateCounting(txbuf_max, txbuf_max);
|
||||
break;
|
||||
|
||||
case BLE_GAP_EVT_DISCONNECTED:
|
||||
vSemaphoreDelete( _txpacket_sem[conn_handle] );
|
||||
_txpacket_sem[conn_handle] = NULL;
|
||||
peer->connected = false;
|
||||
|
||||
vSemaphoreDelete( peer->txpacket_sem );
|
||||
peer->txpacket_sem = NULL;
|
||||
break;
|
||||
|
||||
case BLE_EVT_TX_COMPLETE:
|
||||
if ( _txpacket_sem[conn_handle] )
|
||||
if ( peer->txpacket_sem )
|
||||
{
|
||||
for(uint8_t i=0; i<evt->evt.common_evt.params.tx_complete.count; i++)
|
||||
{
|
||||
xSemaphoreGive(_txpacket_sem[conn_handle]);
|
||||
xSemaphoreGive(peer->txpacket_sem);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -47,12 +47,17 @@ class BLEGap
|
||||
public:
|
||||
BLEGap(void);
|
||||
|
||||
bool getTxPacket(void);
|
||||
bool getTxPacket(uint16_t conn_handle);
|
||||
bool connected(uint16_t conn_handle);
|
||||
|
||||
uint8_t getPeerAddr(uint16_t conn_handle, uint8_t addr[6]);
|
||||
ble_gap_addr_t getPeerAddr(uint16_t conn_handle);
|
||||
|
||||
uint16_t getPeerName(char* buf, uint16_t bufsize);
|
||||
uint16_t getPeerName(uint16_t conn_handle, char* buf, uint16_t bufsize);
|
||||
|
||||
bool getTxPacket(void);
|
||||
bool getTxPacket(uint16_t conn_handle);
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* INTERNAL USAGE ONLY
|
||||
* Although declare as public, it is meant to be invoked by internal
|
||||
@@ -62,7 +67,15 @@ class BLEGap
|
||||
|
||||
private:
|
||||
// Array of TX Packet semaphore, indexed by connection handle
|
||||
SemaphoreHandle_t _txpacket_sem[BLE_GAP_MAX_CONN];
|
||||
// Peer info where conn_handle serves as index
|
||||
typedef struct {
|
||||
bool connected;
|
||||
ble_gap_addr_t addr;
|
||||
|
||||
SemaphoreHandle_t txpacket_sem;
|
||||
} gap_peer_t;
|
||||
|
||||
gap_peer_t _peers[BLE_GAP_MAX_CONN];
|
||||
};
|
||||
|
||||
#endif /* BLEGAP_H_ */
|
||||
@@ -339,9 +339,14 @@ uint16_t AdafruitBluefruit::connInterval(void)
|
||||
return _conn_interval;
|
||||
}
|
||||
|
||||
ble_gap_addr_t AdafruitBluefruit::peerAddr(void)
|
||||
ble_gap_addr_t AdafruitBluefruit::getPeerAddr(void)
|
||||
{
|
||||
return _peer_addr;
|
||||
return Gap.getPeerAddr(_conn_hdl);
|
||||
}
|
||||
|
||||
uint8_t AdafruitBluefruit::getPeerAddr(uint8_t addr[6])
|
||||
{
|
||||
return Gap.getPeerAddr(_conn_hdl, addr);
|
||||
}
|
||||
|
||||
COMMENT_OUT (
|
||||
@@ -488,7 +493,6 @@ void AdafruitBluefruit::_ble_handler(ble_evt_t* evt)
|
||||
|
||||
_conn_hdl = evt->evt.gap_evt.conn_handle;
|
||||
_conn_interval = para->conn_params.min_conn_interval;
|
||||
_peer_addr = para->peer_addr;
|
||||
|
||||
// Connection interval set by Central is out of preferred range
|
||||
// Try to negotiate with Central using our preferred values
|
||||
@@ -520,7 +524,6 @@ void AdafruitBluefruit::_ble_handler(ble_evt_t* evt)
|
||||
|
||||
_conn_hdl = BLE_CONN_HANDLE_INVALID;
|
||||
_bonded = false;
|
||||
varclr(&_peer_addr);
|
||||
|
||||
if ( _discconnect_cb ) _discconnect_cb(evt->evt.gap_evt.params.disconnected.reason);
|
||||
|
||||
|
||||
@@ -130,7 +130,8 @@ class AdafruitBluefruit
|
||||
bool requestPairing (void);
|
||||
void clearBonds (void);
|
||||
|
||||
ble_gap_addr_t peerAddr(void);
|
||||
ble_gap_addr_t getPeerAddr(void);
|
||||
uint8_t getPeerAddr(uint8_t addr[6]);
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* Callbacks
|
||||
@@ -178,8 +179,6 @@ public: // TODO temporary for bledfu to load bonding data
|
||||
private:
|
||||
ble_gap_sec_params_t _sec_param;
|
||||
|
||||
ble_gap_addr_t _peer_addr;
|
||||
|
||||
COMMENT_OUT(
|
||||
uint8_t _auth_type;
|
||||
char _pin[BLE_GAP_PASSKEY_LEN];
|
||||
|
||||
@@ -131,7 +131,7 @@ static void bledfu_control_wr_authorize_cb(BLECharacteristic& chr, ble_gatts_evt
|
||||
|
||||
if ( !Bluefruit.connPaired() )
|
||||
{
|
||||
peer_data->addr = Bluefruit.peerAddr();
|
||||
peer_data->addr = Bluefruit.getPeerAddr();
|
||||
}else
|
||||
{
|
||||
peer_data->addr = Bluefruit._bond_data.peer_id.id_addr_info;
|
||||
|
||||
Reference in new issue
Block a user