refactor service discovery
This commit is contained in:
1 parent
dbf858e3f2
commit
0beff63269
6 files changed
+14
-14
No files matched your search
@@ -229,27 +229,25 @@ void BLECentral::setDisconnectCallback( disconnect_callback_t fp)
|
||||
/*------------------------------------------------------------------*/
|
||||
/* DISCOVERY
|
||||
*------------------------------------------------------------------*/
|
||||
bool BLECentral::discoverService(BLEUuid uuid, uint16_t start_handle)
|
||||
bool BLECentral::discoverService(BLECentralService& svc, uint16_t start_handle)
|
||||
{
|
||||
uuid.begin(); // add uuid128 if needed
|
||||
|
||||
ble_gattc_evt_prim_srvc_disc_rsp_t disc_svc;
|
||||
|
||||
_evt_buf = &disc_svc;
|
||||
_evt_bufsize = sizeof(disc_svc);
|
||||
|
||||
VERIFY_STATUS( sd_ble_gattc_primary_services_discover(_conn_hdl, start_handle, &uuid._uuid), false );
|
||||
VERIFY_STATUS( sd_ble_gattc_primary_services_discover(_conn_hdl, start_handle, &svc.uuid._uuid), false );
|
||||
|
||||
// wait for discovery event: timeout or has no data
|
||||
if ( !xSemaphoreTake(_evt_sem, BLE_CENTRAL_TIMEOUT) || (_evt_bufsize == 0) ) return false;
|
||||
|
||||
// Check the discovered UUID with input one
|
||||
if ( (disc_svc.count == 1) && (uuid == disc_svc.services[0].uuid) )
|
||||
if ( (disc_svc.count == 1) && (svc.uuid == disc_svc.services[0].uuid) )
|
||||
{
|
||||
_disc_hdl_range = disc_svc.services[0].handle_range;
|
||||
LOG_LV1(Discover, "[SVC] Found 0x%04X, Handle start = %d, end = %d", uuid._uuid.uuid, _disc_hdl_range.start_handle, _disc_hdl_range.end_handle);
|
||||
LOG_LV1(Discover, "[SVC] Found 0x%04X, Handle start = %d, end = %d", disc_svc.services[0].uuid.uuid, _disc_hdl_range.start_handle, _disc_hdl_range.end_handle);
|
||||
|
||||
_disc_hdl_range.start_handle++; // increase for next discovery
|
||||
_disc_hdl_range.start_handle++; // increase for characteristic discovery
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -90,7 +90,7 @@ class BLECentral
|
||||
/*------------------------------------------------------------------*/
|
||||
/* GATTC Discovery
|
||||
*------------------------------------------------------------------*/
|
||||
bool discoverService(BLEUuid uuid, uint16_t start_handle = 1);
|
||||
bool discoverService(BLECentralService& svc, uint16_t start_handle = 1);
|
||||
uint8_t discoverCharacteristic(BLECentralCharacteristic* chr[], uint8_t count);
|
||||
|
||||
|
||||
|
||||
@@ -67,9 +67,9 @@ err_t BLECentralService::begin(void)
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
bool BLECentralService::discover(uint16_t start_handle)
|
||||
bool BLECentralService::discover(void)
|
||||
{
|
||||
VERIFY( Bluefruit.Central.discoverService(uuid, start_handle) );
|
||||
VERIFY( Bluefruit.Central.discoverService(*this) );
|
||||
_discovered = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -56,9 +56,11 @@ class BLECentralService
|
||||
|
||||
virtual err_t begin(void);
|
||||
|
||||
virtual bool discover(uint16_t start_handle = 1);
|
||||
virtual bool discover (void);
|
||||
bool discovered(void);
|
||||
virtual void disconnect(void);
|
||||
|
||||
friend class BLECentral;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -69,10 +69,10 @@ void BLECentralUart::setRxCallback( rx_callback_t fp)
|
||||
_rx_cb = fp;
|
||||
}
|
||||
|
||||
bool BLECentralUart::discover(uint16_t start_handle)
|
||||
bool BLECentralUart::discover(void)
|
||||
{
|
||||
// Call BLECentralService discover
|
||||
VERIFY( BLECentralService::discover(start_handle) );
|
||||
VERIFY( BLECentralService::discover() );
|
||||
_discovered = false;
|
||||
|
||||
// Discover TXD, RXD characteristics
|
||||
|
||||
@@ -52,7 +52,7 @@ class BLECentralUart : public BLECentralService, public Stream
|
||||
BLECentralUart(uint16_t fifo_depth = BLE_UART_DEFAULT_FIFO_DEPTH);
|
||||
|
||||
virtual err_t begin(void);
|
||||
virtual bool discover(uint16_t start_handle = 1);
|
||||
virtual bool discover(void);
|
||||
virtual void disconnect(void);
|
||||
|
||||
bool enableNotify(void);
|
||||
|
||||
Reference in new issue
Block a user