clean up
This commit is contained in:
1 parent
6354c8d186
commit
7dc80ba645
8 files changed
+42
-24
No files matched your search
@@ -205,7 +205,7 @@ void BLECentral::setDisconnectCallback( disconnect_callback_t fp)
|
||||
/*------------------------------------------------------------------*/
|
||||
/* DISCOVERY
|
||||
*------------------------------------------------------------------*/
|
||||
bool BLECentral::discoverService(BLEUuid uuid, ble_gattc_handle_range_t* hdl_range, uint16_t start_handle)
|
||||
bool BLECentral::discoverService(BLEUuid uuid, uint16_t start_handle)
|
||||
{
|
||||
uuid.begin(); // add uuid128 if needed
|
||||
|
||||
@@ -223,10 +223,7 @@ bool BLECentral::discoverService(BLEUuid uuid, ble_gattc_handle_range_t* hdl_ran
|
||||
if ( (disc_svc.count == 1) && (uuid == disc_svc.services[0].uuid) )
|
||||
{
|
||||
_disc_hdl_range = disc_svc.services[0].handle_range;
|
||||
(*hdl_range) = disc_svc.services[0].handle_range;;
|
||||
|
||||
PRINT_INT(_disc_hdl_range.start_handle);
|
||||
PRINT_INT(_disc_hdl_range.end_handle);
|
||||
LOG_LV1(Discover, "Handle start = %d, end = %d", _disc_hdl_range.start_handle, _disc_hdl_range.end_handle);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -245,8 +242,7 @@ bool BLECentral::discoverCharacteristic(BLECentralCharacteristic& chr)
|
||||
_evt_buf = &disc_chr;
|
||||
_evt_bufsize = sizeof(disc_chr);
|
||||
|
||||
PRINT_INT(_disc_hdl_range.start_handle);
|
||||
PRINT_INT(_disc_hdl_range.end_handle);
|
||||
LOG_LV1(Discover, "Handle start = %d, end = %d", _disc_hdl_range.start_handle, _disc_hdl_range.end_handle);
|
||||
|
||||
VERIFY_STATUS( sd_ble_gattc_characteristics_discover(_conn_hdl, &_disc_hdl_range), false );
|
||||
|
||||
@@ -328,12 +324,15 @@ void BLECentral::_event_handler(ble_evt_t* evt)
|
||||
{
|
||||
ble_gattc_evt_prim_srvc_disc_rsp_t* svc_rsp = &gattc->params.prim_srvc_disc_rsp;
|
||||
|
||||
PRINT_INT(svc_rsp->count);
|
||||
LOG_LV1(Discover, "Service Count: %d", svc_rsp->count);
|
||||
|
||||
// len of the discovered services
|
||||
uint16_t len = sizeof(ble_gattc_evt_prim_srvc_disc_rsp_t) + (svc_rsp->count-1)*sizeof(ble_gattc_service_t);
|
||||
_evt_bufsize = min16(_evt_bufsize, len);
|
||||
COMMENT_OUT (
|
||||
uint16_t len = sizeof(ble_gattc_evt_prim_srvc_disc_rsp_t) + (svc_rsp->count-1)*sizeof(ble_gattc_service_t);
|
||||
_evt_bufsize = min16(_evt_bufsize, len);
|
||||
)
|
||||
|
||||
// Only support 1 service
|
||||
_evt_bufsize = min16(_evt_bufsize, sizeof(ble_gattc_evt_prim_srvc_disc_rsp_t));
|
||||
memcpy(_evt_buf, svc_rsp, _evt_bufsize);
|
||||
}else
|
||||
{
|
||||
@@ -353,7 +352,7 @@ void BLECentral::_event_handler(ble_evt_t* evt)
|
||||
|
||||
if ( _conn_hdl == gattc->conn_handle )
|
||||
{
|
||||
PRINT_INT(chr_rsp->count);
|
||||
LOG_LV1(Discover, "Characteristic Count: %d", chr_rsp->count);
|
||||
if ( (gattc->gatt_status == BLE_GATT_STATUS_SUCCESS) && (chr_rsp->count > 0) )
|
||||
{
|
||||
// TODO support only 1 discovered char now
|
||||
|
||||
@@ -85,8 +85,9 @@ class BLECentral
|
||||
/*------------------------------------------------------------------*/
|
||||
/* GATTC Discovery
|
||||
*------------------------------------------------------------------*/
|
||||
bool discoverService(BLEUuid uuid, ble_gattc_handle_range_t* hdl_range, uint16_t start_handle = 1);
|
||||
bool discoverService(BLEUuid uuid, uint16_t start_handle = 1);
|
||||
bool discoverService(BLECentralService& svc, uint16_t start_handle = 1);
|
||||
|
||||
bool discoverCharacteristic(BLECentralCharacteristic& chr);
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
|
||||
@@ -47,3 +47,8 @@ BLECentralCharacteristic::BLECentralCharacteristic(ble_gattc_char_t* gattc_char)
|
||||
{
|
||||
_chr = (*gattc_char);
|
||||
}
|
||||
|
||||
uint16_t BLECentralCharacteristic::valueHandle()
|
||||
{
|
||||
return _chr.handle_value;
|
||||
}
|
||||
@@ -48,7 +48,8 @@ class BLECentralCharacteristic
|
||||
BLECentralCharacteristic(void);
|
||||
BLECentralCharacteristic(ble_gattc_char_t* gattc_char);
|
||||
|
||||
|
||||
uint16_t valueHandle();;
|
||||
// uint16_t cccdHandle();
|
||||
|
||||
private:
|
||||
ble_gattc_char_t _chr;
|
||||
|
||||
@@ -38,8 +38,6 @@
|
||||
|
||||
void BLECentralService::_init(void)
|
||||
{
|
||||
_hdl_range.start_handle = 1;
|
||||
_hdl_range.end_handle = 0xffff;
|
||||
}
|
||||
|
||||
BLECentralService::BLECentralService(void)
|
||||
@@ -65,5 +63,5 @@ err_t BLECentralService::begin(void)
|
||||
|
||||
bool BLECentralService::discover(uint16_t start_handle)
|
||||
{
|
||||
return Bluefruit.Central.discoverService(uuid, &_hdl_range, start_handle);
|
||||
return Bluefruit.Central.discoverService(uuid, start_handle);
|
||||
}
|
||||
@@ -42,8 +42,6 @@
|
||||
class BLECentralService
|
||||
{
|
||||
protected:
|
||||
ble_gattc_handle_range_t _hdl_range;
|
||||
|
||||
void _init(void);
|
||||
|
||||
public:
|
||||
|
||||
@@ -460,9 +460,7 @@ void adafruit_ble_task(void* arg)
|
||||
|
||||
void AdafruitBluefruit::_ble_handler(ble_evt_t* evt)
|
||||
{
|
||||
#if CFG_DEBUG
|
||||
Serial.printf("[BLE]: %s\n", dbg_ble_event_str(evt->header.evt_id));
|
||||
#endif
|
||||
LOG_LV1(BLE, dbg_ble_event_str(evt->header.evt_id));
|
||||
|
||||
/*------------- BLE Peripheral Events -------------*/
|
||||
switch ( evt->header.evt_id )
|
||||
@@ -635,7 +633,6 @@ COMMENT_OUT(
|
||||
case BLE_GAP_EVT_CONN_SEC_UPDATE:
|
||||
{
|
||||
// Connection is secured aka Paired
|
||||
|
||||
COMMENT_OUT( ble_gap_conn_sec_t* conn_sec = (ble_gap_conn_sec_t*) &evt->evt.gap_evt.params.conn_sec_update.conn_sec; )
|
||||
|
||||
// Previously bonded --> secure by re-connection process
|
||||
|
||||
@@ -55,5 +55,24 @@ bool BLECentralUart::discover(uint16_t start_handle)
|
||||
// Call BLECentralService discover
|
||||
VERIFY( BLECentralService::discover(start_handle) );
|
||||
|
||||
return true;
|
||||
// Discover TXD, RXD characteristics
|
||||
BLECentralCharacteristic chr_temp;
|
||||
while ( Bluefruit.Central.discoverCharacteristic(chr_temp) )
|
||||
{
|
||||
uint16_t uuid16;
|
||||
chr_temp.uuid.get(&uuid16);
|
||||
|
||||
if (uuid16 == 0x0002)
|
||||
{
|
||||
_rxd = chr_temp;
|
||||
}else if (uuid16 == 0x0003)
|
||||
{
|
||||
_txd = chr_temp;
|
||||
|
||||
// TXD has CCCD
|
||||
}
|
||||
}
|
||||
|
||||
// true if both RXD & TXD are found
|
||||
return ( _rxd.valueHandle() && _txd.valueHandle() );
|
||||
}
|
||||
Reference in new issue
Block a user