From 32e541606ccaafd806025db48b2faecf1f34a912 Mon Sep 17 00:00:00 2001 From: lianggao Date: Wed, 29 Mar 2017 09:19:45 +0800 Subject: [PATCH] Jira 714 Find the limits of the number of Services and Characteristics Make the BLE support more characteristics and services by separate the service registration Changed files BLEProfileManager.cpp - Remove register all service at same time BLEProfileManager.h - Change the comments BLEServiceImp.cpp - Add the register service after update the characteristic --- .../src/internal/BLEProfileManager.cpp | 31 +++++-------------- .../CurieBLE/src/internal/BLEProfileManager.h | 2 +- .../CurieBLE/src/internal/BLEServiceImp.cpp | 6 +++- 3 files changed, 13 insertions(+), 26 deletions(-) diff --git a/libraries/CurieBLE/src/internal/BLEProfileManager.cpp b/libraries/CurieBLE/src/internal/BLEProfileManager.cpp index aba7981b..762d1e36 100644 --- a/libraries/CurieBLE/src/internal/BLEProfileManager.cpp +++ b/libraries/CurieBLE/src/internal/BLEProfileManager.cpp @@ -241,8 +241,6 @@ int BLEProfileManager::serviceCount(const BLEDevice &bledevice) const int BLEProfileManager::registerProfile(BLEDevice &bledevice) { - int ret = 0; - bt_gatt_attr_t *start; BleStatus err_code = BLE_STATUS_SUCCESS; @@ -288,35 +286,20 @@ int BLEProfileManager::registerProfile(BLEDevice &bledevice) { BLEServiceImp *service = node->value; start = _attr_base + _attr_index; - service->updateProfile(start, _attr_index); - node = node->next; - } - -#if 0 - // Start debug - int i; - - for (i = 0; i < _attr_index; i++) { + err_code = service->updateProfile(start, _attr_index); + if (BLE_STATUS_SUCCESS != err_code) { - pr_info(LOG_MODULE_APP, "gatt-: i %d, type %d, u16 0x%x", - i, - _attr_base[i].uuid->type, - BT_UUID_16(_attr_base[i].uuid)->val); + break; } + node = node->next; } - delay(1000); - // End for debug -#endif - - ret = bt_gatt_register(_attr_base, - _attr_index); - pr_debug(LOG_MODULE_APP, "%s: ret, %d,_attr_index-%d", __FUNCTION__, ret, _attr_index); - if (0 == ret) + // Will not regiter the profile if ARC registered any profile + if (_attr_index > 0) { _profile_registered = true; } - return ret; + return err_code; } void BLEProfileManager::clearProfile(BLEServiceLinkNodeHeader* serviceHeader) diff --git a/libraries/CurieBLE/src/internal/BLEProfileManager.h b/libraries/CurieBLE/src/internal/BLEProfileManager.h index 1c05fc99..a7656361 100644 --- a/libraries/CurieBLE/src/internal/BLEProfileManager.h +++ b/libraries/CurieBLE/src/internal/BLEProfileManager.h @@ -65,7 +65,7 @@ class BLEProfileManager{ * * @param[in] bledevice The BLE Device * - * @return int std C errno + * @return int BLE errno @BleStatus * * @note none */ diff --git a/libraries/CurieBLE/src/internal/BLEServiceImp.cpp b/libraries/CurieBLE/src/internal/BLEServiceImp.cpp index d5d7afe6..862b58ed 100644 --- a/libraries/CurieBLE/src/internal/BLEServiceImp.cpp +++ b/libraries/CurieBLE/src/internal/BLEServiceImp.cpp @@ -120,6 +120,7 @@ int BLEServiceImp::updateProfile(bt_gatt_attr_t *attr_start, int& index) int base_index = index; int offset = 0; int counter = 0; + int ret = 0; start->uuid = BLEServiceImp::getPrimayUuid(); start->perm = BT_GATT_PERM_READ; start->read = bt_gatt_attr_read_service; @@ -139,7 +140,10 @@ int BLEServiceImp::updateProfile(bt_gatt_attr_t *attr_start, int& index) counter += offset; node = node->next; } - return counter; + ret = bt_gatt_register(attr_start, + counter); + + return errorno_to_ble_status(ret); } int BLEServiceImp::getAttributeCount()