Pinned to some recent date
features/FEATURE_BLE/ble/GattAttribute.h@0:fb7af294d5d9, 2016-11-17 (annotated)
- Committer:
- Simon Cooksey
- Date:
- Thu Nov 17 16:43:53 2016 +0000
- Revision:
- 0:fb7af294d5d9
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Simon Cooksey |
0:fb7af294d5d9 | 1 | /* mbed Microcontroller Library |
Simon Cooksey |
0:fb7af294d5d9 | 2 | * Copyright (c) 2006-2013 ARM Limited |
Simon Cooksey |
0:fb7af294d5d9 | 3 | * |
Simon Cooksey |
0:fb7af294d5d9 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
Simon Cooksey |
0:fb7af294d5d9 | 5 | * you may not use this file except in compliance with the License. |
Simon Cooksey |
0:fb7af294d5d9 | 6 | * You may obtain a copy of the License at |
Simon Cooksey |
0:fb7af294d5d9 | 7 | * |
Simon Cooksey |
0:fb7af294d5d9 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Simon Cooksey |
0:fb7af294d5d9 | 9 | * |
Simon Cooksey |
0:fb7af294d5d9 | 10 | * Unless required by applicable law or agreed to in writing, software |
Simon Cooksey |
0:fb7af294d5d9 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
Simon Cooksey |
0:fb7af294d5d9 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Simon Cooksey |
0:fb7af294d5d9 | 13 | * See the License for the specific language governing permissions and |
Simon Cooksey |
0:fb7af294d5d9 | 14 | * limitations under the License. |
Simon Cooksey |
0:fb7af294d5d9 | 15 | */ |
Simon Cooksey |
0:fb7af294d5d9 | 16 | |
Simon Cooksey |
0:fb7af294d5d9 | 17 | #ifndef __GATT_ATTRIBUTE_H__ |
Simon Cooksey |
0:fb7af294d5d9 | 18 | #define __GATT_ATTRIBUTE_H__ |
Simon Cooksey |
0:fb7af294d5d9 | 19 | |
Simon Cooksey |
0:fb7af294d5d9 | 20 | #include "UUID.h" |
Simon Cooksey |
0:fb7af294d5d9 | 21 | |
Simon Cooksey |
0:fb7af294d5d9 | 22 | /** |
Simon Cooksey |
0:fb7af294d5d9 | 23 | * Instances of this class encapsulate the data that belongs to a Bluetooth Low |
Simon Cooksey |
0:fb7af294d5d9 | 24 | * Energy attribute. |
Simon Cooksey |
0:fb7af294d5d9 | 25 | */ |
Simon Cooksey |
0:fb7af294d5d9 | 26 | class GattAttribute { |
Simon Cooksey |
0:fb7af294d5d9 | 27 | public: |
Simon Cooksey |
0:fb7af294d5d9 | 28 | /** |
Simon Cooksey |
0:fb7af294d5d9 | 29 | * Type for the handle or ID of the attribute in the ATT table. These are |
Simon Cooksey |
0:fb7af294d5d9 | 30 | * unique and are usually generated by the underlying BLE stack. |
Simon Cooksey |
0:fb7af294d5d9 | 31 | */ |
Simon Cooksey |
0:fb7af294d5d9 | 32 | typedef uint16_t Handle_t; |
Simon Cooksey |
0:fb7af294d5d9 | 33 | /** |
Simon Cooksey |
0:fb7af294d5d9 | 34 | * Define the value of an invalid attribute handle. |
Simon Cooksey |
0:fb7af294d5d9 | 35 | */ |
Simon Cooksey |
0:fb7af294d5d9 | 36 | static const Handle_t INVALID_HANDLE = 0x0000; |
Simon Cooksey |
0:fb7af294d5d9 | 37 | |
Simon Cooksey |
0:fb7af294d5d9 | 38 | public: |
Simon Cooksey |
0:fb7af294d5d9 | 39 | /** |
Simon Cooksey |
0:fb7af294d5d9 | 40 | * @brief Creates a new GattAttribute using the specified |
Simon Cooksey |
0:fb7af294d5d9 | 41 | * UUID, value length, and inital value. |
Simon Cooksey |
0:fb7af294d5d9 | 42 | * |
Simon Cooksey |
0:fb7af294d5d9 | 43 | * @param[in] uuid |
Simon Cooksey |
0:fb7af294d5d9 | 44 | * The UUID to use for this attribute. |
Simon Cooksey |
0:fb7af294d5d9 | 45 | * @param[in] valuePtr |
Simon Cooksey |
0:fb7af294d5d9 | 46 | * The memory holding the initial value. |
Simon Cooksey |
0:fb7af294d5d9 | 47 | * @param[in] len |
Simon Cooksey |
0:fb7af294d5d9 | 48 | * The length in bytes of this attribute's value. |
Simon Cooksey |
0:fb7af294d5d9 | 49 | * @param[in] maxLen |
Simon Cooksey |
0:fb7af294d5d9 | 50 | * The max length in bytes of this attribute's value. |
Simon Cooksey |
0:fb7af294d5d9 | 51 | * @param[in] hasVariableLen |
Simon Cooksey |
0:fb7af294d5d9 | 52 | * Whether the attribute's value length changes overtime. |
Simon Cooksey |
0:fb7af294d5d9 | 53 | * |
Simon Cooksey |
0:fb7af294d5d9 | 54 | * @section EXAMPLE |
Simon Cooksey |
0:fb7af294d5d9 | 55 | * |
Simon Cooksey |
0:fb7af294d5d9 | 56 | * @code |
Simon Cooksey |
0:fb7af294d5d9 | 57 | * |
Simon Cooksey |
0:fb7af294d5d9 | 58 | * // UUID = 0x2A19, Min length 2, Max len = 2 |
Simon Cooksey |
0:fb7af294d5d9 | 59 | * GattAttribute attr = GattAttribute(0x2A19, &someValue, 2, 2); |
Simon Cooksey |
0:fb7af294d5d9 | 60 | * |
Simon Cooksey |
0:fb7af294d5d9 | 61 | * @endcode |
Simon Cooksey |
0:fb7af294d5d9 | 62 | */ |
Simon Cooksey |
0:fb7af294d5d9 | 63 | GattAttribute(const UUID &uuid, uint8_t *valuePtr = NULL, uint16_t len = 0, uint16_t maxLen = 0, bool hasVariableLen = true) : |
Simon Cooksey |
0:fb7af294d5d9 | 64 | _uuid(uuid), _valuePtr(valuePtr), _lenMax(maxLen), _len(len), _hasVariableLen(hasVariableLen), _handle() { |
Simon Cooksey |
0:fb7af294d5d9 | 65 | /* Empty */ |
Simon Cooksey |
0:fb7af294d5d9 | 66 | } |
Simon Cooksey |
0:fb7af294d5d9 | 67 | |
Simon Cooksey |
0:fb7af294d5d9 | 68 | public: |
Simon Cooksey |
0:fb7af294d5d9 | 69 | /** |
Simon Cooksey |
0:fb7af294d5d9 | 70 | * Get the attribute's handle in the ATT table. |
Simon Cooksey |
0:fb7af294d5d9 | 71 | * |
Simon Cooksey |
0:fb7af294d5d9 | 72 | * @return The attribute's handle. |
Simon Cooksey |
0:fb7af294d5d9 | 73 | */ |
Simon Cooksey |
0:fb7af294d5d9 | 74 | Handle_t getHandle(void) const { |
Simon Cooksey |
0:fb7af294d5d9 | 75 | return _handle; |
Simon Cooksey |
0:fb7af294d5d9 | 76 | } |
Simon Cooksey |
0:fb7af294d5d9 | 77 | |
Simon Cooksey |
0:fb7af294d5d9 | 78 | /** |
Simon Cooksey |
0:fb7af294d5d9 | 79 | * The UUID of the characteristic that this attribute belongs to. |
Simon Cooksey |
0:fb7af294d5d9 | 80 | * |
Simon Cooksey |
0:fb7af294d5d9 | 81 | * @return The characteristic's UUID. |
Simon Cooksey |
0:fb7af294d5d9 | 82 | */ |
Simon Cooksey |
0:fb7af294d5d9 | 83 | const UUID &getUUID(void) const { |
Simon Cooksey |
0:fb7af294d5d9 | 84 | return _uuid; |
Simon Cooksey |
0:fb7af294d5d9 | 85 | } |
Simon Cooksey |
0:fb7af294d5d9 | 86 | |
Simon Cooksey |
0:fb7af294d5d9 | 87 | /** |
Simon Cooksey |
0:fb7af294d5d9 | 88 | * Get the current length of the attribute value. |
Simon Cooksey |
0:fb7af294d5d9 | 89 | * |
Simon Cooksey |
0:fb7af294d5d9 | 90 | * @return The current length of the attribute value. |
Simon Cooksey |
0:fb7af294d5d9 | 91 | */ |
Simon Cooksey |
0:fb7af294d5d9 | 92 | uint16_t getLength(void) const { |
Simon Cooksey |
0:fb7af294d5d9 | 93 | return _len; |
Simon Cooksey |
0:fb7af294d5d9 | 94 | } |
Simon Cooksey |
0:fb7af294d5d9 | 95 | |
Simon Cooksey |
0:fb7af294d5d9 | 96 | /** |
Simon Cooksey |
0:fb7af294d5d9 | 97 | * Get the maximum length of the attribute value. |
Simon Cooksey |
0:fb7af294d5d9 | 98 | * |
Simon Cooksey |
0:fb7af294d5d9 | 99 | * The maximum length of the attribute value. |
Simon Cooksey |
0:fb7af294d5d9 | 100 | */ |
Simon Cooksey |
0:fb7af294d5d9 | 101 | uint16_t getMaxLength(void) const { |
Simon Cooksey |
0:fb7af294d5d9 | 102 | return _lenMax; |
Simon Cooksey |
0:fb7af294d5d9 | 103 | } |
Simon Cooksey |
0:fb7af294d5d9 | 104 | |
Simon Cooksey |
0:fb7af294d5d9 | 105 | /** |
Simon Cooksey |
0:fb7af294d5d9 | 106 | * Get a pointer to the current length of the attribute value. |
Simon Cooksey |
0:fb7af294d5d9 | 107 | * |
Simon Cooksey |
0:fb7af294d5d9 | 108 | * @return A pointer to the current length of the attribute value. |
Simon Cooksey |
0:fb7af294d5d9 | 109 | */ |
Simon Cooksey |
0:fb7af294d5d9 | 110 | uint16_t *getLengthPtr(void) { |
Simon Cooksey |
0:fb7af294d5d9 | 111 | return &_len; |
Simon Cooksey |
0:fb7af294d5d9 | 112 | } |
Simon Cooksey |
0:fb7af294d5d9 | 113 | |
Simon Cooksey |
0:fb7af294d5d9 | 114 | /** |
Simon Cooksey |
0:fb7af294d5d9 | 115 | * Set the attribute handle. |
Simon Cooksey |
0:fb7af294d5d9 | 116 | * |
Simon Cooksey |
0:fb7af294d5d9 | 117 | * @param[in] id |
Simon Cooksey |
0:fb7af294d5d9 | 118 | * The new attribute handle. |
Simon Cooksey |
0:fb7af294d5d9 | 119 | */ |
Simon Cooksey |
0:fb7af294d5d9 | 120 | void setHandle(Handle_t id) { |
Simon Cooksey |
0:fb7af294d5d9 | 121 | _handle = id; |
Simon Cooksey |
0:fb7af294d5d9 | 122 | } |
Simon Cooksey |
0:fb7af294d5d9 | 123 | |
Simon Cooksey |
0:fb7af294d5d9 | 124 | /** |
Simon Cooksey |
0:fb7af294d5d9 | 125 | * Get a pointer to the attribute value. |
Simon Cooksey |
0:fb7af294d5d9 | 126 | * |
Simon Cooksey |
0:fb7af294d5d9 | 127 | * @return A pointer to the attribute value. |
Simon Cooksey |
0:fb7af294d5d9 | 128 | */ |
Simon Cooksey |
0:fb7af294d5d9 | 129 | uint8_t *getValuePtr(void) { |
Simon Cooksey |
0:fb7af294d5d9 | 130 | return _valuePtr; |
Simon Cooksey |
0:fb7af294d5d9 | 131 | } |
Simon Cooksey |
0:fb7af294d5d9 | 132 | |
Simon Cooksey |
0:fb7af294d5d9 | 133 | /** |
Simon Cooksey |
0:fb7af294d5d9 | 134 | * Check whether the length of the attribute's value can change over time. |
Simon Cooksey |
0:fb7af294d5d9 | 135 | * |
Simon Cooksey |
0:fb7af294d5d9 | 136 | * @return true if the attribute has variable length, false otherwise. |
Simon Cooksey |
0:fb7af294d5d9 | 137 | */ |
Simon Cooksey |
0:fb7af294d5d9 | 138 | bool hasVariableLength(void) const { |
Simon Cooksey |
0:fb7af294d5d9 | 139 | return _hasVariableLen; |
Simon Cooksey |
0:fb7af294d5d9 | 140 | } |
Simon Cooksey |
0:fb7af294d5d9 | 141 | |
Simon Cooksey |
0:fb7af294d5d9 | 142 | private: |
Simon Cooksey |
0:fb7af294d5d9 | 143 | /** |
Simon Cooksey |
0:fb7af294d5d9 | 144 | * Characteristic's UUID. |
Simon Cooksey |
0:fb7af294d5d9 | 145 | */ |
Simon Cooksey |
0:fb7af294d5d9 | 146 | UUID _uuid; |
Simon Cooksey |
0:fb7af294d5d9 | 147 | /** |
Simon Cooksey |
0:fb7af294d5d9 | 148 | * Pointer to the attribute's value. |
Simon Cooksey |
0:fb7af294d5d9 | 149 | */ |
Simon Cooksey |
0:fb7af294d5d9 | 150 | uint8_t *_valuePtr; |
Simon Cooksey |
0:fb7af294d5d9 | 151 | /** |
Simon Cooksey |
0:fb7af294d5d9 | 152 | * Maximum length of the value pointed to by GattAttribute::_valuePtr. |
Simon Cooksey |
0:fb7af294d5d9 | 153 | */ |
Simon Cooksey |
0:fb7af294d5d9 | 154 | uint16_t _lenMax; |
Simon Cooksey |
0:fb7af294d5d9 | 155 | /** |
Simon Cooksey |
0:fb7af294d5d9 | 156 | * Current length of the value pointed to by GattAttribute::_valuePtr. |
Simon Cooksey |
0:fb7af294d5d9 | 157 | */ |
Simon Cooksey |
0:fb7af294d5d9 | 158 | uint16_t _len; |
Simon Cooksey |
0:fb7af294d5d9 | 159 | /** |
Simon Cooksey |
0:fb7af294d5d9 | 160 | * Whether the length of the value can change over time. |
Simon Cooksey |
0:fb7af294d5d9 | 161 | */ |
Simon Cooksey |
0:fb7af294d5d9 | 162 | bool _hasVariableLen; |
Simon Cooksey |
0:fb7af294d5d9 | 163 | /** |
Simon Cooksey |
0:fb7af294d5d9 | 164 | * The attribute's handle in the ATT table. |
Simon Cooksey |
0:fb7af294d5d9 | 165 | */ |
Simon Cooksey |
0:fb7af294d5d9 | 166 | Handle_t _handle; |
Simon Cooksey |
0:fb7af294d5d9 | 167 | |
Simon Cooksey |
0:fb7af294d5d9 | 168 | private: |
Simon Cooksey |
0:fb7af294d5d9 | 169 | /* Disallow copy and assignment. */ |
Simon Cooksey |
0:fb7af294d5d9 | 170 | GattAttribute(const GattAttribute &); |
Simon Cooksey |
0:fb7af294d5d9 | 171 | GattAttribute& operator=(const GattAttribute &); |
Simon Cooksey |
0:fb7af294d5d9 | 172 | }; |
Simon Cooksey |
0:fb7af294d5d9 | 173 | |
Simon Cooksey |
0:fb7af294d5d9 | 174 | #endif /* ifndef __GATT_ATTRIBUTE_H__ */ |