Merge branch '0.8.x' into develop
This commit is contained in:
commit
bba9ae1d12
45 files changed
+2294
-607
No files matched your search
@@ -35,6 +35,7 @@
|
||||
/**************************************************************************/
|
||||
|
||||
#include "bluefruit.h"
|
||||
#include "utility/bonding.h"
|
||||
|
||||
|
||||
BLEGatt::BLEGatt(void)
|
||||
@@ -49,6 +50,12 @@ uint16_t BLEGatt::readCharByUuid(uint16_t conn_hdl, BLEUuid bleuuid, void* buffe
|
||||
int32_t count = 0;
|
||||
ble_gattc_handle_range_t hdl_range = { .start_handle = start_hdl, .end_handle = end_hdl };
|
||||
|
||||
while( _adamsg.isWaiting() )
|
||||
{
|
||||
// TODO multiple peripherals
|
||||
delay( Bluefruit.connInterval() );
|
||||
}
|
||||
|
||||
_adamsg.begin(true);
|
||||
_adamsg.prepare(buffer, bufsize);
|
||||
|
||||
@@ -68,13 +75,29 @@ uint16_t BLEGatt::readCharByUuid(uint16_t conn_hdl, BLEUuid bleuuid, void* buffe
|
||||
return (count < 0) ? 0 : count;
|
||||
}
|
||||
|
||||
bool BLEGatt::waitForIndicateConfirm(uint16_t conn_hdl)
|
||||
{
|
||||
BLEGap::gap_peer_t* peer = Bluefruit.Gap._get_peer(conn_hdl);
|
||||
|
||||
// hvi confirm semaphore is created on the fly
|
||||
peer->hvc_sem = xSemaphoreCreateBinary();
|
||||
|
||||
xSemaphoreTake(peer->hvc_sem, portMAX_DELAY);
|
||||
|
||||
vSemaphoreDelete(peer->hvc_sem);
|
||||
peer->hvc_sem = NULL;
|
||||
|
||||
return peer->hvc_received;
|
||||
}
|
||||
|
||||
void BLEGatt::_eventHandler(ble_evt_t* evt)
|
||||
{
|
||||
// conn handle has fixed offset regardless of event type
|
||||
const uint16_t evt_conn_hdl = evt->evt.common_evt.conn_handle;
|
||||
const uint16_t evt_id = evt->header.evt_id;
|
||||
|
||||
// Server Service TODO multiple peripherals
|
||||
/*------------- Server service -------------*/
|
||||
// TODO multiple peripherals
|
||||
// if ( evt_conn_hdl == Bluefruit.connHandle() )
|
||||
{
|
||||
if ( evt_id == BLE_GAP_EVT_DISCONNECTED || evt_id == BLE_GAP_EVT_CONNECTED )
|
||||
@@ -92,7 +115,7 @@ void BLEGatt::_eventHandler(ble_evt_t* evt)
|
||||
}
|
||||
}
|
||||
|
||||
// Server Characteristics
|
||||
/*------------- Server Characteristics -------------*/
|
||||
// TODO multiple prph connection
|
||||
if ( evt_conn_hdl == Bluefruit.connHandle() )
|
||||
{
|
||||
@@ -106,11 +129,11 @@ void BLEGatt::_eventHandler(ble_evt_t* evt)
|
||||
case BLE_GATTS_EVT_RW_AUTHORIZE_REQUEST:
|
||||
// Handle has the same offset for read & write request
|
||||
req_handle = evt->evt.gatts_evt.params.authorize_request.request.read.handle;
|
||||
break;
|
||||
break;
|
||||
|
||||
case BLE_GATTS_EVT_WRITE:
|
||||
req_handle = evt->evt.gatts_evt.params.write.handle;
|
||||
break;
|
||||
break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
@@ -119,11 +142,18 @@ void BLEGatt::_eventHandler(ble_evt_t* evt)
|
||||
if ((req_handle != BLE_GATT_HANDLE_INVALID) && (req_handle == chr->handles().value_handle || req_handle == chr->handles().cccd_handle ))
|
||||
{
|
||||
chr->_eventHandler(evt);
|
||||
|
||||
// Save CCCD if paired
|
||||
if ( Bluefruit.connPaired() && (evt_id == BLE_GATTS_EVT_WRITE) && (req_handle == chr->handles().cccd_handle) )
|
||||
{
|
||||
BLEGap::gap_peer_t* peer = Bluefruit.Gap._get_peer(evt_conn_hdl);
|
||||
bond_save_cccd( peer->role, evt_conn_hdl, peer->ediv);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Client Characteristics
|
||||
/*------------- Client Characteristics -------------*/
|
||||
for(int i=0; i<_client.chr_count; i++)
|
||||
{
|
||||
if ( evt_conn_hdl == _client.chr_list[i]->connHandle() )
|
||||
@@ -179,21 +209,47 @@ void BLEGatt::_eventHandler(ble_evt_t* evt)
|
||||
}
|
||||
|
||||
// GATTC Read Characteristic by UUID procedure
|
||||
if ( evt_id == BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP )
|
||||
switch ( evt_id )
|
||||
{
|
||||
ble_gattc_evt_char_val_by_uuid_read_rsp_t* rd_rsp = &evt->evt.gattc_evt.params.char_val_by_uuid_read_rsp;
|
||||
|
||||
if (rd_rsp->count)
|
||||
case BLE_GATTC_EVT_CHAR_VAL_BY_UUID_READ_RSP:
|
||||
{
|
||||
ble_gattc_handle_value_t hdl_value;
|
||||
ble_gattc_evt_char_val_by_uuid_read_rsp_t* rd_rsp = &evt->evt.gattc_evt.params.char_val_by_uuid_read_rsp;
|
||||
|
||||
if ( ERROR_NONE == sd_ble_gattc_evt_char_val_by_uuid_read_rsp_iter(&evt->evt.gattc_evt, &hdl_value) )
|
||||
if (rd_rsp->count)
|
||||
{
|
||||
_adamsg.feed(hdl_value.p_value, rd_rsp->value_len);
|
||||
}
|
||||
ble_gattc_handle_value_t hdl_value;
|
||||
|
||||
_adamsg.complete();
|
||||
if ( ERROR_NONE == sd_ble_gattc_evt_char_val_by_uuid_read_rsp_iter(&evt->evt.gattc_evt, &hdl_value) )
|
||||
{
|
||||
_adamsg.feed(hdl_value.p_value, rd_rsp->value_len);
|
||||
}
|
||||
|
||||
_adamsg.complete();
|
||||
}
|
||||
}
|
||||
|
||||
case BLE_GATTS_EVT_HVC:
|
||||
{
|
||||
LOG_LV2("GATTS", "Confirm received handle = 0x%04X", evt->evt.gatts_evt.params.hvc.handle);
|
||||
BLEGap::gap_peer_t* peer = Bluefruit.Gap._get_peer(evt_conn_hdl);
|
||||
|
||||
if ( peer->hvc_sem ) xSemaphoreGive(peer->hvc_sem);
|
||||
peer->hvc_received = true;
|
||||
}
|
||||
break;
|
||||
|
||||
case BLE_GATTS_EVT_TIMEOUT:
|
||||
{
|
||||
LOG_LV2("GATTS", "Timeout Source = %d", evt->evt.gatts_evt.params.timeout.src);
|
||||
|
||||
BLEGap::gap_peer_t* peer = Bluefruit.Gap._get_peer(evt_conn_hdl);
|
||||
|
||||
if ( peer->hvc_sem ) xSemaphoreGive(peer->hvc_sem);
|
||||
peer->hvc_received = false;
|
||||
}
|
||||
break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user