fdsf
Fork of nRF51822 by
source/nRF5xCharacteristicDescriptorDiscoverer.h@542:1bf9c597f44f, 2016-01-11 (annotated)
- Committer:
- vcoubard
- Date:
- Mon Jan 11 10:19:02 2016 +0000
- Revision:
- 542:1bf9c597f44f
- Child:
- 543:53215259c0d2
Synchronized with git rev e15d59a7
Author: Vincent Coubard
Add Characteristic Descriptor Discovery implementation
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 | 542:1bf9c597f44f | 76 | void terminate(uint16_t handle); |
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 | 542:1bf9c597f44f | 108 | void terminate() { |
vcoubard | 542:1bf9c597f44f | 109 | CharacteristicDescriptorDiscovery::TerminationCallbackParams_t params = { |
vcoubard | 542:1bf9c597f44f | 110 | characteristic |
vcoubard | 542:1bf9c597f44f | 111 | }; |
vcoubard | 542:1bf9c597f44f | 112 | onTerminate.call(¶ms); |
vcoubard | 542:1bf9c597f44f | 113 | } |
vcoubard | 542:1bf9c597f44f | 114 | |
vcoubard | 542:1bf9c597f44f | 115 | friend bool operator==(const Discovery& lhs, const Discovery& rhs) { |
vcoubard | 542:1bf9c597f44f | 116 | return lhs.characteristic == rhs.characteristic && |
vcoubard | 542:1bf9c597f44f | 117 | lhs.onDiscovery == rhs.onDiscovery && |
vcoubard | 542:1bf9c597f44f | 118 | lhs.onTerminate == lhs.onTerminate; |
vcoubard | 542:1bf9c597f44f | 119 | } |
vcoubard | 542:1bf9c597f44f | 120 | }; |
vcoubard | 542:1bf9c597f44f | 121 | |
vcoubard | 542:1bf9c597f44f | 122 | Discovery* findRunningDiscovery(const DiscoveredCharacteristic& characteristic); |
vcoubard | 542:1bf9c597f44f | 123 | Discovery* findRunningDiscovery(const DiscoveredCharacteristic& characteristic) const; |
vcoubard | 542:1bf9c597f44f | 124 | Discovery* findRunningDiscovery(uint16_t handle); |
vcoubard | 542:1bf9c597f44f | 125 | void removeDiscovery(Discovery* discovery); |
vcoubard | 542:1bf9c597f44f | 126 | Discovery* getAvailableDiscoverySlot(); |
vcoubard | 542:1bf9c597f44f | 127 | bool isConnectionInUse(uint16_t connHandle); |
vcoubard | 542:1bf9c597f44f | 128 | |
vcoubard | 542:1bf9c597f44f | 129 | size_t maximumConcurrentConnectionsCount; |
vcoubard | 542:1bf9c597f44f | 130 | Discovery *discoveryRunning; |
vcoubard | 542:1bf9c597f44f | 131 | }; |
vcoubard | 542:1bf9c597f44f | 132 | |
vcoubard | 542:1bf9c597f44f | 133 | #endif /*__NRF_CHARACTERISTIC_DESCRIPTOR_DISCOVERY_H__*/ |