Nordic stack and drivers for the mbed BLE API

Fork of nRF51822 by Nordic Semiconductor

Committer:
amithy
Date:
Fri Nov 10 01:00:06 2017 +0000
Revision:
639:5aeed2c29513
Parent:
638:c90ae1400bf2
for testing export

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Vincent Coubard 638:c90ae1400bf2 1 /* mbed Microcontroller Library
Vincent Coubard 638:c90ae1400bf2 2 * Copyright (c) 2006-2015 ARM Limited
Vincent Coubard 638:c90ae1400bf2 3 *
Vincent Coubard 638:c90ae1400bf2 4 * Licensed under the Apache License, Version 2.0 (the "License");
Vincent Coubard 638:c90ae1400bf2 5 * you may not use this file except in compliance with the License.
Vincent Coubard 638:c90ae1400bf2 6 * You may obtain a copy of the License at
Vincent Coubard 638:c90ae1400bf2 7 *
Vincent Coubard 638:c90ae1400bf2 8 * http://www.apache.org/licenses/LICENSE-2.0
Vincent Coubard 638:c90ae1400bf2 9 *
Vincent Coubard 638:c90ae1400bf2 10 * Unless required by applicable law or agreed to in writing, software
Vincent Coubard 638:c90ae1400bf2 11 * distributed under the License is distributed on an "AS IS" BASIS,
Vincent Coubard 638:c90ae1400bf2 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Vincent Coubard 638:c90ae1400bf2 13 * See the License for the specific language governing permissions and
Vincent Coubard 638:c90ae1400bf2 14 * limitations under the License.
Vincent Coubard 638:c90ae1400bf2 15 */
Vincent Coubard 638:c90ae1400bf2 16 #include "nRF5xCharacteristicDescriptorDiscoverer.h"
Vincent Coubard 638:c90ae1400bf2 17 #include "nrf_ble_err.h"
Vincent Coubard 638:c90ae1400bf2 18 #include "ble/DiscoveredCharacteristicDescriptor.h"
Vincent Coubard 638:c90ae1400bf2 19
Vincent Coubard 638:c90ae1400bf2 20 nRF5xCharacteristicDescriptorDiscoverer::nRF5xCharacteristicDescriptorDiscoverer() :
Vincent Coubard 638:c90ae1400bf2 21 discoveryRunning() {
Vincent Coubard 638:c90ae1400bf2 22 // nothing to do
Vincent Coubard 638:c90ae1400bf2 23 }
Vincent Coubard 638:c90ae1400bf2 24
Vincent Coubard 638:c90ae1400bf2 25 nRF5xCharacteristicDescriptorDiscoverer::~nRF5xCharacteristicDescriptorDiscoverer() {
Vincent Coubard 638:c90ae1400bf2 26 // nothing to do
Vincent Coubard 638:c90ae1400bf2 27 }
Vincent Coubard 638:c90ae1400bf2 28
Vincent Coubard 638:c90ae1400bf2 29 ble_error_t nRF5xCharacteristicDescriptorDiscoverer::launch(
Vincent Coubard 638:c90ae1400bf2 30 const DiscoveredCharacteristic& characteristic,
Vincent Coubard 638:c90ae1400bf2 31 const CharacteristicDescriptorDiscovery::DiscoveryCallback_t& discoveryCallback,
Vincent Coubard 638:c90ae1400bf2 32 const CharacteristicDescriptorDiscovery::TerminationCallback_t& terminationCallback
Vincent Coubard 638:c90ae1400bf2 33 ) {
Vincent Coubard 638:c90ae1400bf2 34 Gap::Handle_t connHandle = characteristic.getConnectionHandle();
Vincent Coubard 638:c90ae1400bf2 35 // it is ok to deduce that the start handle for descriptors is after
Vincent Coubard 638:c90ae1400bf2 36 // the characteristic declaration and the characteristic value declaration
Vincent Coubard 638:c90ae1400bf2 37 // see BLUETOOTH SPECIFICATION Version 4.2 [Vol 3, Part G] (3.3)
Vincent Coubard 638:c90ae1400bf2 38 Gap::Handle_t descriptorStartHandle = characteristic.getDeclHandle() + 2;
Vincent Coubard 638:c90ae1400bf2 39 Gap::Handle_t descriptorEndHandle = characteristic.getLastHandle();
Vincent Coubard 638:c90ae1400bf2 40
Vincent Coubard 638:c90ae1400bf2 41 // check if there is any descriptor to discover
Vincent Coubard 638:c90ae1400bf2 42 if (descriptorEndHandle < descriptorStartHandle) {
Vincent Coubard 638:c90ae1400bf2 43 CharacteristicDescriptorDiscovery::TerminationCallbackParams_t termParams = {
Vincent Coubard 638:c90ae1400bf2 44 characteristic,
Vincent Coubard 638:c90ae1400bf2 45 BLE_ERROR_NONE
Vincent Coubard 638:c90ae1400bf2 46 };
Vincent Coubard 638:c90ae1400bf2 47 terminationCallback.call(&termParams);
Vincent Coubard 638:c90ae1400bf2 48 return BLE_ERROR_NONE;
Vincent Coubard 638:c90ae1400bf2 49 }
Vincent Coubard 638:c90ae1400bf2 50
Vincent Coubard 638:c90ae1400bf2 51 // check if we can run this discovery
Vincent Coubard 638:c90ae1400bf2 52 if (isConnectionInUse(connHandle)) {
Vincent Coubard 638:c90ae1400bf2 53 return BLE_STACK_BUSY;
Vincent Coubard 638:c90ae1400bf2 54 }
Vincent Coubard 638:c90ae1400bf2 55
Vincent Coubard 638:c90ae1400bf2 56 // get a new discovery slot, if none are available, just return
Vincent Coubard 638:c90ae1400bf2 57 Discovery* discovery = getAvailableDiscoverySlot();
Vincent Coubard 638:c90ae1400bf2 58 if(discovery == NULL) {
Vincent Coubard 638:c90ae1400bf2 59 return BLE_STACK_BUSY;
Vincent Coubard 638:c90ae1400bf2 60 }
Vincent Coubard 638:c90ae1400bf2 61
Vincent Coubard 638:c90ae1400bf2 62 // try to launch the discovery
Vincent Coubard 638:c90ae1400bf2 63 ble_error_t err = gattc_descriptors_discover(connHandle, descriptorStartHandle, descriptorEndHandle);
Vincent Coubard 638:c90ae1400bf2 64 if(!err) {
Vincent Coubard 638:c90ae1400bf2 65 // commit the new discovery to its slot
Vincent Coubard 638:c90ae1400bf2 66 *discovery = Discovery(characteristic, discoveryCallback, terminationCallback);
Vincent Coubard 638:c90ae1400bf2 67 }
Vincent Coubard 638:c90ae1400bf2 68
Vincent Coubard 638:c90ae1400bf2 69 return err;
Vincent Coubard 638:c90ae1400bf2 70 }
Vincent Coubard 638:c90ae1400bf2 71
Vincent Coubard 638:c90ae1400bf2 72 bool nRF5xCharacteristicDescriptorDiscoverer::isActive(const DiscoveredCharacteristic& characteristic) const {
Vincent Coubard 638:c90ae1400bf2 73 for(size_t i = 0; i < MAXIMUM_CONCURRENT_CONNECTIONS_COUNT; ++i) {
Vincent Coubard 638:c90ae1400bf2 74 if(discoveryRunning[i].getCharacteristic() == characteristic) {
Vincent Coubard 638:c90ae1400bf2 75 return true;
Vincent Coubard 638:c90ae1400bf2 76 }
Vincent Coubard 638:c90ae1400bf2 77 }
Vincent Coubard 638:c90ae1400bf2 78 return false;
Vincent Coubard 638:c90ae1400bf2 79 }
Vincent Coubard 638:c90ae1400bf2 80
Vincent Coubard 638:c90ae1400bf2 81 void nRF5xCharacteristicDescriptorDiscoverer::requestTerminate(const DiscoveredCharacteristic& characteristic) {
Vincent Coubard 638:c90ae1400bf2 82 Discovery* discovery = findRunningDiscovery(characteristic);
Vincent Coubard 638:c90ae1400bf2 83 if(discovery) {
Vincent Coubard 638:c90ae1400bf2 84 // call terminate anyway
Vincent Coubard 638:c90ae1400bf2 85 terminate(discovery, BLE_ERROR_NONE);
Vincent Coubard 638:c90ae1400bf2 86 }
Vincent Coubard 638:c90ae1400bf2 87 }
Vincent Coubard 638:c90ae1400bf2 88
Vincent Coubard 638:c90ae1400bf2 89 void nRF5xCharacteristicDescriptorDiscoverer::process(uint16_t connectionHandle, const ble_gattc_evt_desc_disc_rsp_t& descriptors) {
Vincent Coubard 638:c90ae1400bf2 90 Discovery* discovery = findRunningDiscovery(connectionHandle);
Vincent Coubard 638:c90ae1400bf2 91 // the discovery has been removed
Vincent Coubard 638:c90ae1400bf2 92 if(!discovery) {
Vincent Coubard 638:c90ae1400bf2 93 return;
Vincent Coubard 638:c90ae1400bf2 94 }
Vincent Coubard 638:c90ae1400bf2 95
Vincent Coubard 638:c90ae1400bf2 96 for (uint16_t i = 0; i < descriptors.count; ++i) {
Vincent Coubard 638:c90ae1400bf2 97 const ble_gattc_desc_t& desc = descriptors.descs[i];
Vincent Coubard 638:c90ae1400bf2 98 const ble_uuid_t& uuid = desc.uuid;
Vincent Coubard 638:c90ae1400bf2 99
Vincent Coubard 638:c90ae1400bf2 100 if (uuid.type == BLE_UUID_TYPE_BLE) {
Vincent Coubard 638:c90ae1400bf2 101 discovery->process(
Vincent Coubard 638:c90ae1400bf2 102 desc.handle, UUID(uuid.uuid)
Vincent Coubard 638:c90ae1400bf2 103 );
Vincent Coubard 638:c90ae1400bf2 104 } else {
Vincent Coubard 638:c90ae1400bf2 105 // discover attribute infos of the descriptor
Vincent Coubard 638:c90ae1400bf2 106 ble_error_t err = gattc_attr_info_discover(connectionHandle, desc.handle, desc.handle);
Vincent Coubard 638:c90ae1400bf2 107 if (err) {
Vincent Coubard 638:c90ae1400bf2 108 terminate(discovery, err);
Vincent Coubard 638:c90ae1400bf2 109 }
Vincent Coubard 638:c90ae1400bf2 110
Vincent Coubard 638:c90ae1400bf2 111 return;
Vincent Coubard 638:c90ae1400bf2 112 }
Vincent Coubard 638:c90ae1400bf2 113 }
Vincent Coubard 638:c90ae1400bf2 114
Vincent Coubard 638:c90ae1400bf2 115 // prepare the next discovery request (if needed)
Vincent Coubard 638:c90ae1400bf2 116 uint16_t startHandle = descriptors.descs[descriptors.count - 1].handle + 1;
Vincent Coubard 638:c90ae1400bf2 117 uint16_t endHandle = discovery->getCharacteristic().getLastHandle();
Vincent Coubard 638:c90ae1400bf2 118
Vincent Coubard 638:c90ae1400bf2 119 if(startHandle > endHandle) {
Vincent Coubard 638:c90ae1400bf2 120 terminate(discovery, BLE_ERROR_NONE);
Vincent Coubard 638:c90ae1400bf2 121 return;
Vincent Coubard 638:c90ae1400bf2 122 }
Vincent Coubard 638:c90ae1400bf2 123
Vincent Coubard 638:c90ae1400bf2 124 ble_error_t err = gattc_descriptors_discover(connectionHandle, startHandle, endHandle);
Vincent Coubard 638:c90ae1400bf2 125 if(err) {
Vincent Coubard 638:c90ae1400bf2 126 terminate(discovery, err);
Vincent Coubard 638:c90ae1400bf2 127 return;
Vincent Coubard 638:c90ae1400bf2 128 }
Vincent Coubard 638:c90ae1400bf2 129 }
Vincent Coubard 638:c90ae1400bf2 130
Vincent Coubard 638:c90ae1400bf2 131 void nRF5xCharacteristicDescriptorDiscoverer::processAttributeInformation(
Vincent Coubard 638:c90ae1400bf2 132 uint16_t connectionHandle, const ble_gattc_evt_attr_info_disc_rsp_t& infos) {
Vincent Coubard 638:c90ae1400bf2 133 Discovery* discovery = findRunningDiscovery(connectionHandle);
Vincent Coubard 638:c90ae1400bf2 134 // the discovery has been removed
Vincent Coubard 638:c90ae1400bf2 135 if(!discovery) {
Vincent Coubard 638:c90ae1400bf2 136 return;
Vincent Coubard 638:c90ae1400bf2 137 }
Vincent Coubard 638:c90ae1400bf2 138
Vincent Coubard 638:c90ae1400bf2 139 // for all UUIDS found, process the discovery
Vincent Coubard 638:c90ae1400bf2 140 for (uint16_t i = 0; i < infos.count; ++i) {
Vincent Coubard 638:c90ae1400bf2 141 bool use_16bits_uuids = infos.format == BLE_GATTC_ATTR_INFO_FORMAT_16BIT;
Vincent Coubard 638:c90ae1400bf2 142 const ble_gattc_attr_info_t& attr_info = infos.attr_info[i];
Vincent Coubard 638:c90ae1400bf2 143 UUID uuid = use_16bits_uuids ? UUID(attr_info.info.uuid16.uuid) : UUID(attr_info.info.uuid128.uuid128, UUID::LSB);
Vincent Coubard 638:c90ae1400bf2 144 discovery->process(attr_info.handle, uuid);
Vincent Coubard 638:c90ae1400bf2 145 }
Vincent Coubard 638:c90ae1400bf2 146
Vincent Coubard 638:c90ae1400bf2 147 // prepare the next round of descriptors discovery
Vincent Coubard 638:c90ae1400bf2 148 uint16_t startHandle = infos.attr_info[infos.count - 1].handle + 1;
Vincent Coubard 638:c90ae1400bf2 149 uint16_t endHandle = discovery->getCharacteristic().getLastHandle();
Vincent Coubard 638:c90ae1400bf2 150
Vincent Coubard 638:c90ae1400bf2 151 if(startHandle > endHandle) {
Vincent Coubard 638:c90ae1400bf2 152 terminate(discovery, BLE_ERROR_NONE);
Vincent Coubard 638:c90ae1400bf2 153 return;
Vincent Coubard 638:c90ae1400bf2 154 }
Vincent Coubard 638:c90ae1400bf2 155
Vincent Coubard 638:c90ae1400bf2 156 ble_error_t err = gattc_descriptors_discover(connectionHandle, startHandle, endHandle);
Vincent Coubard 638:c90ae1400bf2 157 if(err) {
Vincent Coubard 638:c90ae1400bf2 158 terminate(discovery, err);
Vincent Coubard 638:c90ae1400bf2 159 return;
Vincent Coubard 638:c90ae1400bf2 160 }
Vincent Coubard 638:c90ae1400bf2 161 }
Vincent Coubard 638:c90ae1400bf2 162
Vincent Coubard 638:c90ae1400bf2 163 void nRF5xCharacteristicDescriptorDiscoverer::terminate(uint16_t handle, ble_error_t err) {
Vincent Coubard 638:c90ae1400bf2 164 Discovery* discovery = findRunningDiscovery(handle);
Vincent Coubard 638:c90ae1400bf2 165 // the discovery has already been terminated
Vincent Coubard 638:c90ae1400bf2 166 if(!discovery) {
Vincent Coubard 638:c90ae1400bf2 167 return;
Vincent Coubard 638:c90ae1400bf2 168 }
Vincent Coubard 638:c90ae1400bf2 169
Vincent Coubard 638:c90ae1400bf2 170 terminate(discovery, err);
Vincent Coubard 638:c90ae1400bf2 171 }
Vincent Coubard 638:c90ae1400bf2 172
Vincent Coubard 638:c90ae1400bf2 173 void nRF5xCharacteristicDescriptorDiscoverer::terminate(Discovery* discovery, ble_error_t err) {
Vincent Coubard 638:c90ae1400bf2 174 // temporary copy, user code can try to launch a new discovery in the onTerminate
Vincent Coubard 638:c90ae1400bf2 175 // callback. So, this discovery should not appear in such case.
Vincent Coubard 638:c90ae1400bf2 176 Discovery tmp = *discovery;
Vincent Coubard 638:c90ae1400bf2 177 *discovery = Discovery();
Vincent Coubard 638:c90ae1400bf2 178 tmp.terminate(err);
Vincent Coubard 638:c90ae1400bf2 179 }
Vincent Coubard 638:c90ae1400bf2 180
Vincent Coubard 638:c90ae1400bf2 181 nRF5xCharacteristicDescriptorDiscoverer::Discovery*
Vincent Coubard 638:c90ae1400bf2 182 nRF5xCharacteristicDescriptorDiscoverer::findRunningDiscovery(const DiscoveredCharacteristic& characteristic) {
Vincent Coubard 638:c90ae1400bf2 183 for(size_t i = 0; i < MAXIMUM_CONCURRENT_CONNECTIONS_COUNT; ++i) {
Vincent Coubard 638:c90ae1400bf2 184 if((discoveryRunning[i].getCharacteristic() == characteristic) &&
Vincent Coubard 638:c90ae1400bf2 185 (discoveryRunning[i].isEmpty() == false)) {
Vincent Coubard 638:c90ae1400bf2 186 return &discoveryRunning[i];
Vincent Coubard 638:c90ae1400bf2 187 }
Vincent Coubard 638:c90ae1400bf2 188 }
Vincent Coubard 638:c90ae1400bf2 189 return NULL;
Vincent Coubard 638:c90ae1400bf2 190 }
Vincent Coubard 638:c90ae1400bf2 191
Vincent Coubard 638:c90ae1400bf2 192 nRF5xCharacteristicDescriptorDiscoverer::Discovery*
Vincent Coubard 638:c90ae1400bf2 193 nRF5xCharacteristicDescriptorDiscoverer::findRunningDiscovery(uint16_t handle) {
Vincent Coubard 638:c90ae1400bf2 194 for(size_t i = 0; i < MAXIMUM_CONCURRENT_CONNECTIONS_COUNT; ++i) {
Vincent Coubard 638:c90ae1400bf2 195 if((discoveryRunning[i].getCharacteristic().getConnectionHandle() == handle) &&
Vincent Coubard 638:c90ae1400bf2 196 (discoveryRunning[i].isEmpty() == false)) {
Vincent Coubard 638:c90ae1400bf2 197 return &discoveryRunning[i];
Vincent Coubard 638:c90ae1400bf2 198 }
Vincent Coubard 638:c90ae1400bf2 199 }
Vincent Coubard 638:c90ae1400bf2 200 return NULL;
Vincent Coubard 638:c90ae1400bf2 201 }
Vincent Coubard 638:c90ae1400bf2 202
Vincent Coubard 638:c90ae1400bf2 203 nRF5xCharacteristicDescriptorDiscoverer::Discovery*
Vincent Coubard 638:c90ae1400bf2 204 nRF5xCharacteristicDescriptorDiscoverer::getAvailableDiscoverySlot() {
Vincent Coubard 638:c90ae1400bf2 205 for(size_t i = 0; i < MAXIMUM_CONCURRENT_CONNECTIONS_COUNT; ++i) {
Vincent Coubard 638:c90ae1400bf2 206 if(discoveryRunning[i].isEmpty()) {
Vincent Coubard 638:c90ae1400bf2 207 return &discoveryRunning[i];
Vincent Coubard 638:c90ae1400bf2 208 }
Vincent Coubard 638:c90ae1400bf2 209 }
Vincent Coubard 638:c90ae1400bf2 210 return NULL;
Vincent Coubard 638:c90ae1400bf2 211 }
Vincent Coubard 638:c90ae1400bf2 212
Vincent Coubard 638:c90ae1400bf2 213 bool nRF5xCharacteristicDescriptorDiscoverer::isConnectionInUse(uint16_t connHandle) {
Vincent Coubard 638:c90ae1400bf2 214 return findRunningDiscovery(connHandle) != NULL;
Vincent Coubard 638:c90ae1400bf2 215 }
Vincent Coubard 638:c90ae1400bf2 216
Vincent Coubard 638:c90ae1400bf2 217 ble_error_t nRF5xCharacteristicDescriptorDiscoverer::gattc_descriptors_discover(
Vincent Coubard 638:c90ae1400bf2 218 uint16_t connection_handle, uint16_t start_handle, uint16_t end_handle) {
Vincent Coubard 638:c90ae1400bf2 219
Vincent Coubard 638:c90ae1400bf2 220 ble_gattc_handle_range_t discoveryRange = {
Vincent Coubard 638:c90ae1400bf2 221 start_handle,
Vincent Coubard 638:c90ae1400bf2 222 end_handle
Vincent Coubard 638:c90ae1400bf2 223 };
Vincent Coubard 638:c90ae1400bf2 224 uint32_t err = sd_ble_gattc_descriptors_discover(connection_handle, &discoveryRange);
Vincent Coubard 638:c90ae1400bf2 225
Vincent Coubard 638:c90ae1400bf2 226 switch(err) {
Vincent Coubard 638:c90ae1400bf2 227 case NRF_SUCCESS:
Vincent Coubard 638:c90ae1400bf2 228 return BLE_ERROR_NONE;
Vincent Coubard 638:c90ae1400bf2 229 case BLE_ERROR_INVALID_CONN_HANDLE:
Vincent Coubard 638:c90ae1400bf2 230 return BLE_ERROR_INVALID_PARAM;
Vincent Coubard 638:c90ae1400bf2 231 case NRF_ERROR_INVALID_ADDR:
Vincent Coubard 638:c90ae1400bf2 232 return BLE_ERROR_PARAM_OUT_OF_RANGE;
Vincent Coubard 638:c90ae1400bf2 233 case NRF_ERROR_BUSY:
Vincent Coubard 638:c90ae1400bf2 234 return BLE_STACK_BUSY;
Vincent Coubard 638:c90ae1400bf2 235 default:
Vincent Coubard 638:c90ae1400bf2 236 return BLE_ERROR_UNSPECIFIED;
Vincent Coubard 638:c90ae1400bf2 237 }
Vincent Coubard 638:c90ae1400bf2 238 }
Vincent Coubard 638:c90ae1400bf2 239
Vincent Coubard 638:c90ae1400bf2 240 ble_error_t nRF5xCharacteristicDescriptorDiscoverer::gattc_attr_info_discover(
Vincent Coubard 638:c90ae1400bf2 241 uint16_t connection_handle, uint16_t start_handle, uint16_t end_handle) {
Vincent Coubard 638:c90ae1400bf2 242 ble_gattc_handle_range_t handle_range = { start_handle, end_handle };
Vincent Coubard 638:c90ae1400bf2 243 uint32_t err = sd_ble_gattc_attr_info_discover(connection_handle, &handle_range);
Vincent Coubard 638:c90ae1400bf2 244
Vincent Coubard 638:c90ae1400bf2 245 switch(err) {
Vincent Coubard 638:c90ae1400bf2 246 case NRF_SUCCESS:
Vincent Coubard 638:c90ae1400bf2 247 return BLE_ERROR_NONE;
Vincent Coubard 638:c90ae1400bf2 248 case BLE_ERROR_INVALID_CONN_HANDLE:
Vincent Coubard 638:c90ae1400bf2 249 return BLE_ERROR_INVALID_PARAM;
Vincent Coubard 638:c90ae1400bf2 250 case NRF_ERROR_INVALID_ADDR:
Vincent Coubard 638:c90ae1400bf2 251 return BLE_ERROR_PARAM_OUT_OF_RANGE;
Vincent Coubard 638:c90ae1400bf2 252 case NRF_ERROR_BUSY:
Vincent Coubard 638:c90ae1400bf2 253 return BLE_STACK_BUSY;
Vincent Coubard 638:c90ae1400bf2 254 case NRF_ERROR_INVALID_STATE:
Vincent Coubard 638:c90ae1400bf2 255 return BLE_ERROR_INVALID_STATE;
Vincent Coubard 638:c90ae1400bf2 256 default:
Vincent Coubard 638:c90ae1400bf2 257 return BLE_ERROR_UNSPECIFIED;
Vincent Coubard 638:c90ae1400bf2 258 }
Vincent Coubard 638:c90ae1400bf2 259 }
Vincent Coubard 638:c90ae1400bf2 260
Vincent Coubard 638:c90ae1400bf2 261
Vincent Coubard 638:c90ae1400bf2 262
Vincent Coubard 638:c90ae1400bf2 263 // implementation of nRF5xCharacteristicDescriptorDiscoverer::Discovery
Vincent Coubard 638:c90ae1400bf2 264
Vincent Coubard 638:c90ae1400bf2 265 nRF5xCharacteristicDescriptorDiscoverer::Discovery::Discovery() :
Vincent Coubard 638:c90ae1400bf2 266 characteristic(), onDiscovery(), onTerminate() {
Vincent Coubard 638:c90ae1400bf2 267 }
Vincent Coubard 638:c90ae1400bf2 268
Vincent Coubard 638:c90ae1400bf2 269 nRF5xCharacteristicDescriptorDiscoverer::Discovery::Discovery(
Vincent Coubard 638:c90ae1400bf2 270 const DiscoveredCharacteristic& c, const DiscoveryCallback_t& dCb, const TerminationCallback_t& tCb) :
Vincent Coubard 638:c90ae1400bf2 271 characteristic(c), onDiscovery(dCb), onTerminate(tCb) {
Vincent Coubard 638:c90ae1400bf2 272 }
Vincent Coubard 638:c90ae1400bf2 273
Vincent Coubard 638:c90ae1400bf2 274 void nRF5xCharacteristicDescriptorDiscoverer::Discovery::process(
Vincent Coubard 638:c90ae1400bf2 275 GattAttribute::Handle_t handle, const UUID& uuid) {
Vincent Coubard 638:c90ae1400bf2 276 CharacteristicDescriptorDiscovery::DiscoveryCallbackParams_t params = {
Vincent Coubard 638:c90ae1400bf2 277 characteristic,
Vincent Coubard 638:c90ae1400bf2 278 DiscoveredCharacteristicDescriptor(
Vincent Coubard 638:c90ae1400bf2 279 characteristic.getGattClient(),
Vincent Coubard 638:c90ae1400bf2 280 characteristic.getConnectionHandle(),
Vincent Coubard 638:c90ae1400bf2 281 handle,
Vincent Coubard 638:c90ae1400bf2 282 uuid
Vincent Coubard 638:c90ae1400bf2 283 )
Vincent Coubard 638:c90ae1400bf2 284 };
Vincent Coubard 638:c90ae1400bf2 285 onDiscovery.call(&params);
Vincent Coubard 638:c90ae1400bf2 286 }
Vincent Coubard 638:c90ae1400bf2 287
Vincent Coubard 638:c90ae1400bf2 288 void nRF5xCharacteristicDescriptorDiscoverer::Discovery::terminate(ble_error_t err) {
Vincent Coubard 638:c90ae1400bf2 289 CharacteristicDescriptorDiscovery::TerminationCallbackParams_t params = {
Vincent Coubard 638:c90ae1400bf2 290 characteristic,
Vincent Coubard 638:c90ae1400bf2 291 err
Vincent Coubard 638:c90ae1400bf2 292 };
Vincent Coubard 638:c90ae1400bf2 293
Vincent Coubard 638:c90ae1400bf2 294 onTerminate.call(&params);
Vincent Coubard 638:c90ae1400bf2 295 }
Vincent Coubard 638:c90ae1400bf2 296
Vincent Coubard 638:c90ae1400bf2 297 bool nRF5xCharacteristicDescriptorDiscoverer::Discovery::isEmpty() const {
Vincent Coubard 638:c90ae1400bf2 298 return *this == Discovery();
Vincent Coubard 638:c90ae1400bf2 299 }
Vincent Coubard 638:c90ae1400bf2 300
Vincent Coubard 638:c90ae1400bf2 301 const DiscoveredCharacteristic& nRF5xCharacteristicDescriptorDiscoverer::Discovery::getCharacteristic() const {
Vincent Coubard 638:c90ae1400bf2 302 return characteristic;
Vincent Coubard 638:c90ae1400bf2 303 }