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