High level Bluetooth Low Energy API and radio abstraction layer
Fork of BLE_API by
ble/DiscoveredCharacteristic.h@913:690bea02c431, 2015-11-26 (annotated)
- Committer:
- rgrover1
- Date:
- Thu Nov 26 12:52:03 2015 +0000
- Revision:
- 913:690bea02c431
- Parent:
- 912:f728aa46e7df
- Child:
- 929:918d93d409c1
Synchronized with git rev 4ca38f96
Author: Rohit Grover
Merge branch 'master' of https://github.com/iriark01/ble into iriark01-master
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rgrover1 | 716:11b41f651697 | 1 | /* mbed Microcontroller Library |
rgrover1 | 716:11b41f651697 | 2 | * Copyright (c) 2006-2013 ARM Limited |
rgrover1 | 716:11b41f651697 | 3 | * |
rgrover1 | 716:11b41f651697 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
rgrover1 | 716:11b41f651697 | 5 | * you may not use this file except in compliance with the License. |
rgrover1 | 716:11b41f651697 | 6 | * You may obtain a copy of the License at |
rgrover1 | 716:11b41f651697 | 7 | * |
rgrover1 | 716:11b41f651697 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
rgrover1 | 716:11b41f651697 | 9 | * |
rgrover1 | 716:11b41f651697 | 10 | * Unless required by applicable law or agreed to in writing, software |
rgrover1 | 716:11b41f651697 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
rgrover1 | 716:11b41f651697 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
rgrover1 | 716:11b41f651697 | 13 | * See the License for the specific language governing permissions and |
rgrover1 | 716:11b41f651697 | 14 | * limitations under the License. |
rgrover1 | 716:11b41f651697 | 15 | */ |
rgrover1 | 716:11b41f651697 | 16 | |
rgrover1 | 716:11b41f651697 | 17 | #ifndef __DISCOVERED_CHARACTERISTIC_H__ |
rgrover1 | 716:11b41f651697 | 18 | #define __DISCOVERED_CHARACTERISTIC_H__ |
rgrover1 | 716:11b41f651697 | 19 | |
rgrover1 | 716:11b41f651697 | 20 | #include "UUID.h" |
rgrover1 | 716:11b41f651697 | 21 | #include "Gap.h" |
rgrover1 | 716:11b41f651697 | 22 | #include "GattAttribute.h" |
rgrover1 | 716:11b41f651697 | 23 | #include "GattClient.h" |
rgrover1 | 716:11b41f651697 | 24 | |
rgrover1 | 716:11b41f651697 | 25 | /** |
rgrover1 | 716:11b41f651697 | 26 | * Structure for holding information about the service and the characteristics |
rgrover1 | 716:11b41f651697 | 27 | * found during the discovery process. |
rgrover1 | 716:11b41f651697 | 28 | */ |
rgrover1 | 716:11b41f651697 | 29 | class DiscoveredCharacteristic { |
rgrover1 | 716:11b41f651697 | 30 | public: |
rgrover1 | 716:11b41f651697 | 31 | struct Properties_t { |
rgrover1 | 913:690bea02c431 | 32 | uint8_t _broadcast :1; /**< Broadcasting the value permitted. */ |
rgrover1 | 716:11b41f651697 | 33 | uint8_t _read :1; /**< Reading the value permitted. */ |
rgrover1 | 716:11b41f651697 | 34 | uint8_t _writeWoResp :1; /**< Writing the value with Write Command permitted. */ |
rgrover1 | 716:11b41f651697 | 35 | uint8_t _write :1; /**< Writing the value with Write Request permitted. */ |
rgrover1 | 716:11b41f651697 | 36 | uint8_t _notify :1; /**< Notications of the value permitted. */ |
rgrover1 | 716:11b41f651697 | 37 | uint8_t _indicate :1; /**< Indications of the value permitted. */ |
rgrover1 | 716:11b41f651697 | 38 | uint8_t _authSignedWrite :1; /**< Writing the value with Signed Write Command permitted. */ |
rgrover1 | 716:11b41f651697 | 39 | |
rgrover1 | 716:11b41f651697 | 40 | public: |
rgrover1 | 716:11b41f651697 | 41 | bool broadcast(void) const {return _broadcast; } |
rgrover1 | 716:11b41f651697 | 42 | bool read(void) const {return _read; } |
rgrover1 | 716:11b41f651697 | 43 | bool writeWoResp(void) const {return _writeWoResp; } |
rgrover1 | 716:11b41f651697 | 44 | bool write(void) const {return _write; } |
rgrover1 | 716:11b41f651697 | 45 | bool notify(void) const {return _notify; } |
rgrover1 | 716:11b41f651697 | 46 | bool indicate(void) const {return _indicate; } |
rgrover1 | 716:11b41f651697 | 47 | bool authSignedWrite(void) const {return _authSignedWrite;} |
rgrover1 | 716:11b41f651697 | 48 | |
rgrover1 | 716:11b41f651697 | 49 | private: |
rgrover1 | 913:690bea02c431 | 50 | operator uint8_t() const; /* Disallow implicit conversion into an integer. */ |
rgrover1 | 913:690bea02c431 | 51 | operator unsigned() const; /* Disallow implicit conversion into an integer. */ |
rgrover1 | 716:11b41f651697 | 52 | }; |
rgrover1 | 716:11b41f651697 | 53 | |
rgrover1 | 716:11b41f651697 | 54 | /** |
rgrover1 | 716:11b41f651697 | 55 | * Structure for holding information about the service and the characteristics |
rgrover1 | 716:11b41f651697 | 56 | * found during the discovery process. |
rgrover1 | 716:11b41f651697 | 57 | */ |
rgrover1 | 716:11b41f651697 | 58 | struct DiscoveredDescriptor { |
rgrover1 | 716:11b41f651697 | 59 | GattAttribute::Handle_t handle; /**< Descriptor Handle. */ |
rgrover1 | 716:11b41f651697 | 60 | UUID uuid; /**< Descriptor UUID. */ |
rgrover1 | 716:11b41f651697 | 61 | }; |
rgrover1 | 716:11b41f651697 | 62 | |
rgrover1 | 716:11b41f651697 | 63 | /** |
rgrover1 | 716:11b41f651697 | 64 | * Callback type for when a characteristic descriptor is found during descriptor- |
rgrover1 | 716:11b41f651697 | 65 | * discovery. The receiving function is passed in a pointer to a |
rgrover1 | 716:11b41f651697 | 66 | * DiscoveredDescriptor object which will remain valid for the lifetime |
rgrover1 | 716:11b41f651697 | 67 | * of the callback. Memory for this object is owned by the BLE_API eventing |
rgrover1 | 716:11b41f651697 | 68 | * framework. The application can safely make a persistent shallow-copy of |
rgrover1 | 716:11b41f651697 | 69 | * this object in order to work with the characteristic beyond the callback. |
rgrover1 | 716:11b41f651697 | 70 | */ |
rgrover1 | 716:11b41f651697 | 71 | typedef void (*DescriptorCallback_t)(const DiscoveredDescriptor *); |
rgrover1 | 716:11b41f651697 | 72 | |
rgrover1 | 716:11b41f651697 | 73 | /** |
rgrover1 | 716:11b41f651697 | 74 | * Initiate (or continue) a read for the value attribute, optionally at a |
rgrover1 | 913:690bea02c431 | 75 | * given offset. If the characteristic or descriptor to be read is longer |
rgrover1 | 716:11b41f651697 | 76 | * than ATT_MTU - 1, this function must be called multiple times with |
rgrover1 | 716:11b41f651697 | 77 | * appropriate offset to read the complete value. |
rgrover1 | 716:11b41f651697 | 78 | * |
rgrover1 | 913:690bea02c431 | 79 | * @return BLE_ERROR_NONE if a read has been initiated, or |
rgrover1 | 716:11b41f651697 | 80 | * BLE_ERROR_INVALID_STATE if some internal state about the connection is invalid, or |
rgrover1 | 913:690bea02c431 | 81 | * BLE_STACK_BUSY if some client procedure is already in progress, or |
rgrover1 | 716:11b41f651697 | 82 | * BLE_ERROR_OPERATION_NOT_PERMITTED due to the characteristic's properties. |
rgrover1 | 716:11b41f651697 | 83 | */ |
rgrover1 | 716:11b41f651697 | 84 | ble_error_t read(uint16_t offset = 0) const; |
rgrover1 | 716:11b41f651697 | 85 | |
rgrover1 | 716:11b41f651697 | 86 | /** |
rgrover1 | 716:11b41f651697 | 87 | * Perform a write without response procedure. |
rgrover1 | 716:11b41f651697 | 88 | * |
rgrover1 | 716:11b41f651697 | 89 | * @param length |
rgrover1 | 716:11b41f651697 | 90 | * The amount of data being written. |
rgrover1 | 716:11b41f651697 | 91 | * @param value |
rgrover1 | 716:11b41f651697 | 92 | * The bytes being written. |
rgrover1 | 716:11b41f651697 | 93 | * |
rgrover1 | 716:11b41f651697 | 94 | * @note It is important to note that a write without response will generate |
rgrover1 | 716:11b41f651697 | 95 | * an onDataSent() callback when the packet has been transmitted. There |
rgrover1 | 716:11b41f651697 | 96 | * will be a BLE-stack specific limit to the number of pending |
rgrover1 | 716:11b41f651697 | 97 | * writeWoResponse operations; the user may want to use the onDataSent() |
rgrover1 | 716:11b41f651697 | 98 | * callback for flow-control. |
rgrover1 | 716:11b41f651697 | 99 | * |
rgrover1 | 913:690bea02c431 | 100 | * @retval BLE_ERROR_NONE Successfully started the Write procedure, or |
rgrover1 | 716:11b41f651697 | 101 | * BLE_ERROR_INVALID_STATE if some internal state about the connection is invalid, or |
rgrover1 | 913:690bea02c431 | 102 | * BLE_STACK_BUSY if some client procedure is already in progress, or |
rgrover1 | 716:11b41f651697 | 103 | * BLE_ERROR_NO_MEM if there are no available buffers left to process the request, or |
rgrover1 | 716:11b41f651697 | 104 | * BLE_ERROR_OPERATION_NOT_PERMITTED due to the characteristic's properties. |
rgrover1 | 716:11b41f651697 | 105 | */ |
rgrover1 | 716:11b41f651697 | 106 | ble_error_t writeWoResponse(uint16_t length, const uint8_t *value) const; |
rgrover1 | 716:11b41f651697 | 107 | |
rgrover1 | 716:11b41f651697 | 108 | /** |
rgrover1 | 716:11b41f651697 | 109 | * Initiate a GATT Characteristic Descriptor Discovery procedure for descriptors within this characteristic. |
rgrover1 | 716:11b41f651697 | 110 | * |
rgrover1 | 716:11b41f651697 | 111 | * @param callback |
rgrover1 | 716:11b41f651697 | 112 | * @param matchingUUID |
rgrover1 | 913:690bea02c431 | 113 | * Filter for descriptors. Defaults to wildcard which will discover all descriptors. |
rgrover1 | 716:11b41f651697 | 114 | * |
rgrover1 | 716:11b41f651697 | 115 | * @return BLE_ERROR_NONE if descriptor discovery is launched successfully; else an appropriate error. |
rgrover1 | 716:11b41f651697 | 116 | */ |
rgrover1 | 716:11b41f651697 | 117 | ble_error_t discoverDescriptors(DescriptorCallback_t callback, const UUID &matchingUUID = UUID::ShortUUIDBytes_t(BLE_UUID_UNKNOWN)) const; |
rgrover1 | 716:11b41f651697 | 118 | |
rgrover1 | 716:11b41f651697 | 119 | /** |
rgrover1 | 716:11b41f651697 | 120 | * Perform a write procedure. |
rgrover1 | 716:11b41f651697 | 121 | * |
rgrover1 | 716:11b41f651697 | 122 | * @param length |
rgrover1 | 716:11b41f651697 | 123 | * The amount of data being written. |
rgrover1 | 716:11b41f651697 | 124 | * @param value |
rgrover1 | 716:11b41f651697 | 125 | * The bytes being written. |
rgrover1 | 716:11b41f651697 | 126 | * |
rgrover1 | 716:11b41f651697 | 127 | * @note It is important to note that a write will generate |
rgrover1 | 716:11b41f651697 | 128 | * an onDataWritten() callback when the peer acknowledges the request. |
rgrover1 | 716:11b41f651697 | 129 | * |
rgrover1 | 913:690bea02c431 | 130 | * @retval BLE_ERROR_NONE Successfully started the Write procedure, or |
rgrover1 | 716:11b41f651697 | 131 | * BLE_ERROR_INVALID_STATE if some internal state about the connection is invalid, or |
rgrover1 | 913:690bea02c431 | 132 | * BLE_STACK_BUSY if some client procedure is already in progress, or |
rgrover1 | 716:11b41f651697 | 133 | * BLE_ERROR_NO_MEM if there are no available buffers left to process the request, or |
rgrover1 | 716:11b41f651697 | 134 | * BLE_ERROR_OPERATION_NOT_PERMITTED due to the characteristic's properties. |
rgrover1 | 716:11b41f651697 | 135 | */ |
rgrover1 | 716:11b41f651697 | 136 | ble_error_t write(uint16_t length, const uint8_t *value) const; |
rgrover1 | 716:11b41f651697 | 137 | |
rgrover1 | 716:11b41f651697 | 138 | void setupLongUUID(UUID::LongUUIDBytes_t longUUID) { |
rgrover1 | 716:11b41f651697 | 139 | uuid.setupLong(longUUID); |
rgrover1 | 716:11b41f651697 | 140 | } |
rgrover1 | 716:11b41f651697 | 141 | |
rgrover1 | 716:11b41f651697 | 142 | public: |
rgrover1 | 741:d6dceefb844e | 143 | const UUID& getUUID(void) const { |
rgrover1 | 741:d6dceefb844e | 144 | return uuid; |
rgrover1 | 716:11b41f651697 | 145 | } |
rgrover1 | 716:11b41f651697 | 146 | |
rgrover1 | 716:11b41f651697 | 147 | const Properties_t& getProperties(void) const { |
rgrover1 | 716:11b41f651697 | 148 | return props; |
rgrover1 | 716:11b41f651697 | 149 | } |
rgrover1 | 716:11b41f651697 | 150 | |
rgrover1 | 716:11b41f651697 | 151 | const GattAttribute::Handle_t& getDeclHandle(void) const { |
rgrover1 | 716:11b41f651697 | 152 | return declHandle; |
rgrover1 | 716:11b41f651697 | 153 | } |
rgrover1 | 716:11b41f651697 | 154 | const GattAttribute::Handle_t& getValueHandle(void) const { |
rgrover1 | 716:11b41f651697 | 155 | return valueHandle; |
rgrover1 | 716:11b41f651697 | 156 | } |
rgrover1 | 716:11b41f651697 | 157 | |
rgrover1 | 716:11b41f651697 | 158 | public: |
rgrover1 | 716:11b41f651697 | 159 | DiscoveredCharacteristic() : gattc(NULL), |
rgrover1 | 716:11b41f651697 | 160 | uuid(UUID::ShortUUIDBytes_t(0)), |
rgrover1 | 716:11b41f651697 | 161 | props(), |
rgrover1 | 716:11b41f651697 | 162 | declHandle(GattAttribute::INVALID_HANDLE), |
rgrover1 | 716:11b41f651697 | 163 | valueHandle(GattAttribute::INVALID_HANDLE) { |
rgrover1 | 716:11b41f651697 | 164 | /* empty */ |
rgrover1 | 716:11b41f651697 | 165 | } |
rgrover1 | 716:11b41f651697 | 166 | |
rgrover1 | 716:11b41f651697 | 167 | protected: |
rgrover1 | 716:11b41f651697 | 168 | GattClient *gattc; |
rgrover1 | 716:11b41f651697 | 169 | |
rgrover1 | 716:11b41f651697 | 170 | protected: |
rgrover1 | 716:11b41f651697 | 171 | UUID uuid; |
rgrover1 | 716:11b41f651697 | 172 | Properties_t props; |
rgrover1 | 716:11b41f651697 | 173 | GattAttribute::Handle_t declHandle; |
rgrover1 | 716:11b41f651697 | 174 | GattAttribute::Handle_t valueHandle; |
rgrover1 | 716:11b41f651697 | 175 | |
rgrover1 | 716:11b41f651697 | 176 | Gap::Handle_t connHandle; |
rgrover1 | 716:11b41f651697 | 177 | }; |
rgrover1 | 716:11b41f651697 | 178 | |
rgrover1 | 716:11b41f651697 | 179 | #endif /*__DISCOVERED_CHARACTERISTIC_H__*/ |