From ff481dd327ea2ad42e83b7f4273bd85194ee0d8a Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 30 Mar 2017 00:44:47 +0700 Subject: [PATCH] clean up --- libraries/Bluefruit52Lib/src/BLECentral.h | 6 ----- .../Bluefruit52Lib/src/BLECentralService.cpp | 2 +- libraries/Bluefruit52Lib/src/BLEDiscovery.cpp | 24 +++++++++---------- libraries/Bluefruit52Lib/src/BLEDiscovery.h | 10 ++++++-- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/libraries/Bluefruit52Lib/src/BLECentral.h b/libraries/Bluefruit52Lib/src/BLECentral.h index 3b1b7a5d..09674fa4 100644 --- a/libraries/Bluefruit52Lib/src/BLECentral.h +++ b/libraries/Bluefruit52Lib/src/BLECentral.h @@ -88,12 +88,6 @@ class BLECentral bool getTxPacket(uint32_t ms); - /*------------------------------------------------------------------*/ - /* GATTC Discovery - *------------------------------------------------------------------*/ - - - /*------------------------------------------------------------------*/ /* CALLBACKS *------------------------------------------------------------------*/ diff --git a/libraries/Bluefruit52Lib/src/BLECentralService.cpp b/libraries/Bluefruit52Lib/src/BLECentralService.cpp index 10cd0f92..89068129 100644 --- a/libraries/Bluefruit52Lib/src/BLECentralService.cpp +++ b/libraries/Bluefruit52Lib/src/BLECentralService.cpp @@ -70,7 +70,7 @@ bool BLECentralService::begin(void) bool BLECentralService::discover(uint16_t conn_handle) { - VERIFY( Bluefruit.Discovery.discoverService(conn_handle, *this) ); + VERIFY( Bluefruit.Discovery._discoverService(conn_handle, *this) ); _discovered = true; return true; } diff --git a/libraries/Bluefruit52Lib/src/BLEDiscovery.cpp b/libraries/Bluefruit52Lib/src/BLEDiscovery.cpp index e13ee78f..d7e34f2d 100644 --- a/libraries/Bluefruit52Lib/src/BLEDiscovery.cpp +++ b/libraries/Bluefruit52Lib/src/BLEDiscovery.cpp @@ -40,8 +40,8 @@ BLEDiscovery::BLEDiscovery(void) { - _disc_hdl_range.start_handle = 1; - _disc_hdl_range.end_handle = 0xffff; + _hdl_range.start_handle = 1; + _hdl_range.end_handle = 0xffff; _evt_sem = NULL; _evt_buf = NULL; @@ -61,7 +61,7 @@ bool BLEDiscovery::begun(void) return (_evt_sem != NULL); } -bool BLEDiscovery::discoverService(uint16_t conn_handle, BLECentralService& svc, uint16_t start_handle) +bool BLEDiscovery::_discoverService(uint16_t conn_handle, BLECentralService& svc, uint16_t start_handle) { ble_gattc_evt_prim_srvc_disc_rsp_t disc_svc; @@ -76,10 +76,10 @@ bool BLEDiscovery::discoverService(uint16_t conn_handle, BLECentralService& svc, // Check the discovered UUID with input one 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", disc_svc.services[0].uuid.uuid, _disc_hdl_range.start_handle, _disc_hdl_range.end_handle); + _hdl_range = disc_svc.services[0].handle_range; + LOG_LV1(Discover, "[SVC] Found 0x%04X, Handle start = %d, end = %d", disc_svc.services[0].uuid.uuid, _hdl_range.start_handle, _hdl_range.end_handle); - _disc_hdl_range.start_handle++; // increase for characteristic discovery + _hdl_range.start_handle++; // increase for characteristic discovery return true; } @@ -97,16 +97,16 @@ uint8_t BLEDiscovery::discoverCharacteristic(uint16_t conn_handle, BLECentralCha _evt_buf = &disc_chr; _evt_bufsize = sizeof(disc_chr); - LOG_LV1(Discover, "[CHR] Handle start = %d, end = %d", _disc_hdl_range.start_handle, _disc_hdl_range.end_handle); + LOG_LV1(Discover, "[CHR] Handle start = %d, end = %d", _hdl_range.start_handle, _hdl_range.end_handle); - VERIFY_STATUS( sd_ble_gattc_characteristics_discover(conn_handle, &_disc_hdl_range), found ); + VERIFY_STATUS( sd_ble_gattc_characteristics_discover(conn_handle, &_hdl_range), found ); // wait for discovery event: timeout or has no data // Assume only 1 characteristic discovered each if ( !xSemaphoreTake(_evt_sem, BLE_CENTRAL_TIMEOUT) || (_evt_bufsize == 0) || (disc_chr.count == 0) ) break; // increase handle range for next discovery - _disc_hdl_range.start_handle = disc_chr.chars[0].handle_value + 1; + _hdl_range.start_handle = disc_chr.chars[0].handle_value + 1; // Look for matched uuid for (uint8_t i=0; idescs[result-1].handle; + _hdl_range.start_handle = disc_desc->descs[result-1].handle; } return result; diff --git a/libraries/Bluefruit52Lib/src/BLEDiscovery.h b/libraries/Bluefruit52Lib/src/BLEDiscovery.h index f73d4a2c..2433a84d 100644 --- a/libraries/Bluefruit52Lib/src/BLEDiscovery.h +++ b/libraries/Bluefruit52Lib/src/BLEDiscovery.h @@ -46,7 +46,7 @@ class BLEDiscovery { private: - ble_gattc_handle_range_t _disc_hdl_range; + ble_gattc_handle_range_t _hdl_range; void* _evt_buf; uint16_t _evt_bufsize; @@ -60,8 +60,14 @@ class BLEDiscovery void begin(void); bool begun(void); - bool discoverService(uint16_t conn_handle, BLECentralService& svc, uint16_t start_handle = 1); uint8_t discoverCharacteristic(uint16_t conn_handle, BLECentralCharacteristic* chr[], uint8_t count); + + /*------------------------------------------------------------------*/ + /* INTERNAL USAGE ONLY + * Although declare as public, it is meant to be invoked by internal + * code. User should not call these directly + *------------------------------------------------------------------*/ + bool _discoverService(uint16_t conn_handle, BLECentralService& svc, uint16_t start_handle = 1); uint16_t _discoverDescriptor(uint16_t conn_handle, ble_gattc_evt_desc_disc_rsp_t* disc_desc, uint16_t max_count); friend class AdafruitBluefruit;