Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of nRF51822 by
source/nRF5xCharacteristicDescriptorDiscoverer.h@544:9e3d053ad4ec, 2016-01-11 (annotated)
- Committer:
- vcoubard
- Date:
- Mon Jan 11 10:19:04 2016 +0000
- Revision:
- 544:9e3d053ad4ec
- Parent:
- 543:53215259c0d2
Synchronized with git rev dc2dfb0a
Author: Vincent Coubard
Add status parameter in terminateCharacteristicDiscovery function.
Fix terminate discovery (the replacement of the discovery was done after
the call to terminate).
When searching for a running discovery, dismiss results where the
characteristic is equal to the default characteristic value
Add Discovery::operator!=
Add support of DiscoveredCharacteristic last handle in the characteristic
discovery process
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
vcoubard | 542:1bf9c597f44f | 1 | /* mbed Microcontroller Library |
vcoubard | 542:1bf9c597f44f | 2 | * Copyright (c) 2006-2015 ARM Limited |
vcoubard | 542:1bf9c597f44f | 3 | * |
vcoubard | 542:1bf9c597f44f | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
vcoubard | 542:1bf9c597f44f | 5 | * you may not use this file except in compliance with the License. |
vcoubard | 542:1bf9c597f44f | 6 | * You may obtain a copy of the License at |
vcoubard | 542:1bf9c597f44f | 7 | * |
vcoubard | 542:1bf9c597f44f | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
vcoubard | 542:1bf9c597f44f | 9 | * |
vcoubard | 542:1bf9c597f44f | 10 | * Unless required by applicable law or agreed to in writing, software |
vcoubard | 542:1bf9c597f44f | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
vcoubard | 542:1bf9c597f44f | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
vcoubard | 542:1bf9c597f44f | 13 | * See the License for the specific language governing permissions and |
vcoubard | 542:1bf9c597f44f | 14 | * limitations under the License. |
vcoubard | 542:1bf9c597f44f | 15 | */ |
vcoubard | 542:1bf9c597f44f | 16 | |
vcoubard | 542:1bf9c597f44f | 17 | #ifndef __NRF_CHARACTERISTIC_DESCRIPTOR_DISCOVERY_H__ |
vcoubard | 542:1bf9c597f44f | 18 | #define __NRF_CHARACTERISTIC_DESCRIPTOR_DISCOVERY_H__ |
vcoubard | 542:1bf9c597f44f | 19 | |
vcoubard | 542:1bf9c597f44f | 20 | #include "ble/Gap.h" |
vcoubard | 542:1bf9c597f44f | 21 | #include "ble/DiscoveredCharacteristic.h" |
vcoubard | 542:1bf9c597f44f | 22 | #include "ble/CharacteristicDescriptorDiscovery.h" |
vcoubard | 542:1bf9c597f44f | 23 | #include "ble/GattClient.h" |
vcoubard | 542:1bf9c597f44f | 24 | #include "ble_gattc.h" |
vcoubard | 542:1bf9c597f44f | 25 | |
vcoubard | 542:1bf9c597f44f | 26 | /** |
vcoubard | 542:1bf9c597f44f | 27 | * @brief Manage the discovery of Characteristic descriptors |
vcoubard | 542:1bf9c597f44f | 28 | * @details is a bridge beetween BLE API and nordic stack regarding Characteristic |
vcoubard | 542:1bf9c597f44f | 29 | * Descriptor discovery. The BLE API can launch, monitorate and ask for termination |
vcoubard | 542:1bf9c597f44f | 30 | * of a discovery. The nordic stack will provide new descriptors and indicate when |
vcoubard | 542:1bf9c597f44f | 31 | * the discovery is done |
vcoubard | 542:1bf9c597f44f | 32 | */ |
vcoubard | 542:1bf9c597f44f | 33 | class nRF5xCharacteristicDescriptorDiscoverer |
vcoubard | 542:1bf9c597f44f | 34 | { |
vcoubard | 542:1bf9c597f44f | 35 | typedef CharacteristicDescriptorDiscovery::DiscoveryCallback_t DiscoveryCallback_t; |
vcoubard | 542:1bf9c597f44f | 36 | typedef CharacteristicDescriptorDiscovery::TerminationCallback_t TerminationCallback_t; |
vcoubard | 542:1bf9c597f44f | 37 | |
vcoubard | 542:1bf9c597f44f | 38 | public: |
vcoubard | 542:1bf9c597f44f | 39 | nRF5xCharacteristicDescriptorDiscoverer(size_t concurrentConnectionsCount = 3); |
vcoubard | 542:1bf9c597f44f | 40 | |
vcoubard | 542:1bf9c597f44f | 41 | ~nRF5xCharacteristicDescriptorDiscoverer(); |
vcoubard | 542:1bf9c597f44f | 42 | |
vcoubard | 542:1bf9c597f44f | 43 | /** |
vcoubard | 542:1bf9c597f44f | 44 | * Launch a new characteristic descriptor discovery for a given |
vcoubard | 542:1bf9c597f44f | 45 | * DiscoveredCharacteristic. |
vcoubard | 542:1bf9c597f44f | 46 | * @note: this will be called by BLE API side |
vcoubard | 542:1bf9c597f44f | 47 | */ |
vcoubard | 542:1bf9c597f44f | 48 | ble_error_t launch( |
vcoubard | 542:1bf9c597f44f | 49 | const DiscoveredCharacteristic& characteristic, |
vcoubard | 542:1bf9c597f44f | 50 | const DiscoveryCallback_t& callback, |
vcoubard | 542:1bf9c597f44f | 51 | const TerminationCallback_t& terminationCallback |
vcoubard | 542:1bf9c597f44f | 52 | ); |
vcoubard | 542:1bf9c597f44f | 53 | |
vcoubard | 542:1bf9c597f44f | 54 | /** |
vcoubard | 542:1bf9c597f44f | 55 | * @brief indicate if a characteristic descriptor discovery is active for a |
vcoubard | 542:1bf9c597f44f | 56 | * given DiscoveredCharacteristic |
vcoubard | 542:1bf9c597f44f | 57 | * @note: this will be called by BLE API side |
vcoubard | 542:1bf9c597f44f | 58 | */ |
vcoubard | 542:1bf9c597f44f | 59 | bool isActive(const DiscoveredCharacteristic& characteristic) const; |
vcoubard | 542:1bf9c597f44f | 60 | |
vcoubard | 542:1bf9c597f44f | 61 | /** |
vcoubard | 542:1bf9c597f44f | 62 | * @brief reauest the termination of characteristic descriptor discovery |
vcoubard | 542:1bf9c597f44f | 63 | * for a give DiscoveredCharacteristic |
vcoubard | 542:1bf9c597f44f | 64 | * @note: this will be called by BLE API side |
vcoubard | 542:1bf9c597f44f | 65 | */ |
vcoubard | 542:1bf9c597f44f | 66 | void requestTerminate(const DiscoveredCharacteristic& characteristic); |
vcoubard | 542:1bf9c597f44f | 67 | |
vcoubard | 542:1bf9c597f44f | 68 | /** |
vcoubard | 542:1bf9c597f44f | 69 | * @brief process descriptors discovered from the nordic stack |
vcoubard | 542:1bf9c597f44f | 70 | */ |
vcoubard | 542:1bf9c597f44f | 71 | void process(uint16_t handle, const ble_gattc_evt_desc_disc_rsp_t& descriptors); |
vcoubard | 542:1bf9c597f44f | 72 | |
vcoubard | 542:1bf9c597f44f | 73 | /** |
vcoubard | 542:1bf9c597f44f | 74 | * @brief Called by the nordic stack when the discovery is over. |
vcoubard | 542:1bf9c597f44f | 75 | */ |
vcoubard | 543:53215259c0d2 | 76 | void terminate(uint16_t handle, ble_error_t err); |
vcoubard | 542:1bf9c597f44f | 77 | |
vcoubard | 542:1bf9c597f44f | 78 | private: |
vcoubard | 542:1bf9c597f44f | 79 | nRF5xCharacteristicDescriptorDiscoverer(const nRF5xCharacteristicDescriptorDiscoverer&); |
vcoubard | 542:1bf9c597f44f | 80 | nRF5xCharacteristicDescriptorDiscoverer& operator=(const nRF5xCharacteristicDescriptorDiscoverer&); |
vcoubard | 542:1bf9c597f44f | 81 | |
vcoubard | 542:1bf9c597f44f | 82 | struct Discovery { |
vcoubard | 542:1bf9c597f44f | 83 | Discovery() : characteristic(), onDiscovery(), onTerminate() { } |
vcoubard | 542:1bf9c597f44f | 84 | |
vcoubard | 542:1bf9c597f44f | 85 | Discovery(const DiscoveredCharacteristic& c, const DiscoveryCallback_t& dCb, const TerminationCallback_t& tCb) : |
vcoubard | 542:1bf9c597f44f | 86 | characteristic(c), |
vcoubard | 542:1bf9c597f44f | 87 | onDiscovery(dCb), |
vcoubard | 542:1bf9c597f44f | 88 | onTerminate(tCb) { |
vcoubard | 542:1bf9c597f44f | 89 | } |
vcoubard | 542:1bf9c597f44f | 90 | |
vcoubard | 542:1bf9c597f44f | 91 | DiscoveredCharacteristic characteristic; |
vcoubard | 542:1bf9c597f44f | 92 | DiscoveryCallback_t onDiscovery; |
vcoubard | 542:1bf9c597f44f | 93 | TerminationCallback_t onTerminate; |
vcoubard | 542:1bf9c597f44f | 94 | |
vcoubard | 542:1bf9c597f44f | 95 | void process(GattAttribute::Handle_t handle, const UUID& uuid) { |
vcoubard | 542:1bf9c597f44f | 96 | CharacteristicDescriptorDiscovery::DiscoveryCallbackParams_t params = { |
vcoubard | 542:1bf9c597f44f | 97 | characteristic, |
vcoubard | 542:1bf9c597f44f | 98 | DiscoveredCharacteristicDescriptor( |
vcoubard | 542:1bf9c597f44f | 99 | characteristic.getGattClient(), |
vcoubard | 542:1bf9c597f44f | 100 | characteristic.getConnectionHandle(), |
vcoubard | 542:1bf9c597f44f | 101 | handle, |
vcoubard | 542:1bf9c597f44f | 102 | uuid |
vcoubard | 542:1bf9c597f44f | 103 | ) |
vcoubard | 542:1bf9c597f44f | 104 | }; |
vcoubard | 542:1bf9c597f44f | 105 | onDiscovery.call(¶ms); |
vcoubard | 542:1bf9c597f44f | 106 | } |
vcoubard | 542:1bf9c597f44f | 107 | |
vcoubard | 543:53215259c0d2 | 108 | void terminate(ble_error_t err) { |
vcoubard | 542:1bf9c597f44f | 109 | CharacteristicDescriptorDiscovery::TerminationCallbackParams_t params = { |
vcoubard | 543:53215259c0d2 | 110 | characteristic, |
vcoubard | 543:53215259c0d2 | 111 | err |
vcoubard | 542:1bf9c597f44f | 112 | }; |
vcoubard | 542:1bf9c597f44f | 113 | onTerminate.call(¶ms); |
vcoubard | 542:1bf9c597f44f | 114 | } |
vcoubard | 542:1bf9c597f44f | 115 | |
vcoubard | 542:1bf9c597f44f | 116 | friend bool operator==(const Discovery& lhs, const Discovery& rhs) { |
vcoubard | 542:1bf9c597f44f | 117 | return lhs.characteristic == rhs.characteristic && |
vcoubard | 542:1bf9c597f44f | 118 | lhs.onDiscovery == rhs.onDiscovery && |
vcoubard | 544:9e3d053ad4ec | 119 | lhs.onTerminate == rhs.onTerminate; |
vcoubard | 544:9e3d053ad4ec | 120 | } |
vcoubard | 544:9e3d053ad4ec | 121 | |
vcoubard | 544:9e3d053ad4ec | 122 | friend bool operator!=(const Discovery& lhs, const Discovery& rhs) { |
vcoubard | 544:9e3d053ad4ec | 123 | return !(lhs == rhs); |
vcoubard | 542:1bf9c597f44f | 124 | } |
vcoubard | 542:1bf9c597f44f | 125 | }; |
vcoubard | 542:1bf9c597f44f | 126 | |
vcoubard | 542:1bf9c597f44f | 127 | Discovery* findRunningDiscovery(const DiscoveredCharacteristic& characteristic); |
vcoubard | 542:1bf9c597f44f | 128 | Discovery* findRunningDiscovery(const DiscoveredCharacteristic& characteristic) const; |
vcoubard | 542:1bf9c597f44f | 129 | Discovery* findRunningDiscovery(uint16_t handle); |
vcoubard | 542:1bf9c597f44f | 130 | void removeDiscovery(Discovery* discovery); |
vcoubard | 542:1bf9c597f44f | 131 | Discovery* getAvailableDiscoverySlot(); |
vcoubard | 542:1bf9c597f44f | 132 | bool isConnectionInUse(uint16_t connHandle); |
vcoubard | 543:53215259c0d2 | 133 | static ble_error_t gattc_descriptors_discover(uint16_t connection_handle, uint16_t start_handle, uint16_t end_handle); |
vcoubard | 543:53215259c0d2 | 134 | |
vcoubard | 542:1bf9c597f44f | 135 | |
vcoubard | 542:1bf9c597f44f | 136 | size_t maximumConcurrentConnectionsCount; |
vcoubard | 542:1bf9c597f44f | 137 | Discovery *discoveryRunning; |
vcoubard | 542:1bf9c597f44f | 138 | }; |
vcoubard | 542:1bf9c597f44f | 139 | |
vcoubard | 542:1bf9c597f44f | 140 | #endif /*__NRF_CHARACTERISTIC_DESCRIPTOR_DISCOVERY_H__*/ |