prova invio BLE
Dependents: BLE_HeartRate_IDB04A1
Fork of BLE_API by
ble/GattAttribute.h@1161:515032db6feb, 2016-04-06 (annotated)
- Committer:
- vcoubard
- Date:
- Wed Apr 06 19:14:49 2016 +0100
- Revision:
- 1161:515032db6feb
- Parent:
- 1132:6362b7c2fdff
- Child:
- 1179:4ab722f8dca0
Synchronized with git rev 55fde779
Author: Andres Amaya Garcia
Add missing docs and fix doxy warnings in GattAttribute.h
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 | 1161:515032db6feb | 22 | /** |
vcoubard | 1161:515032db6feb | 23 | * Instances of this class encapsulate the data that belongs to a Bluetooth Low |
vcoubard | 1161:515032db6feb | 24 | * Energy attribute. |
vcoubard | 1161:515032db6feb | 25 | */ |
vcoubard | 1131:692ddf04fc42 | 26 | class GattAttribute { |
vcoubard | 1131:692ddf04fc42 | 27 | public: |
vcoubard | 1161:515032db6feb | 28 | /** |
vcoubard | 1161:515032db6feb | 29 | * Type for the handle or ID of the attribute in the ATT table. These are |
vcoubard | 1161:515032db6feb | 30 | * unique and are usually generated by the underlying BLE stack. |
vcoubard | 1161:515032db6feb | 31 | */ |
vcoubard | 1131:692ddf04fc42 | 32 | typedef uint16_t Handle_t; |
vcoubard | 1161:515032db6feb | 33 | /** |
vcoubard | 1161:515032db6feb | 34 | * Define the value of an invalid attribute handle. |
vcoubard | 1161:515032db6feb | 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 | 1161:515032db6feb | 69 | /** |
vcoubard | 1161:515032db6feb | 70 | * Get the attribute's handle in the ATT table. |
vcoubard | 1161:515032db6feb | 71 | * |
vcoubard | 1161:515032db6feb | 72 | * @return The attribute's handle. |
vcoubard | 1161:515032db6feb | 73 | */ |
vcoubard | 1161:515032db6feb | 74 | Handle_t getHandle(void) const { |
vcoubard | 1161:515032db6feb | 75 | return _handle; |
vcoubard | 1161:515032db6feb | 76 | } |
vcoubard | 1161:515032db6feb | 77 | |
vcoubard | 1161:515032db6feb | 78 | /** |
vcoubard | 1161:515032db6feb | 79 | * The UUID of the characteristic that this attribute belongs to. |
vcoubard | 1161:515032db6feb | 80 | * |
vcoubard | 1161:515032db6feb | 81 | * @return The characteristic's UUID. |
vcoubard | 1161:515032db6feb | 82 | */ |
vcoubard | 1161:515032db6feb | 83 | const UUID &getUUID(void) const { |
vcoubard | 1161:515032db6feb | 84 | return _uuid; |
vcoubard | 1161:515032db6feb | 85 | } |
vcoubard | 1161:515032db6feb | 86 | |
vcoubard | 1161:515032db6feb | 87 | /** |
vcoubard | 1161:515032db6feb | 88 | * Get the current length of the attribute value. |
vcoubard | 1161:515032db6feb | 89 | * |
vcoubard | 1161:515032db6feb | 90 | * @return The current length of the attribute value. |
vcoubard | 1161:515032db6feb | 91 | */ |
vcoubard | 1161:515032db6feb | 92 | uint16_t getLength(void) const { |
vcoubard | 1161:515032db6feb | 93 | return _len; |
vcoubard | 1161:515032db6feb | 94 | } |
vcoubard | 1161:515032db6feb | 95 | |
vcoubard | 1161:515032db6feb | 96 | /** |
vcoubard | 1161:515032db6feb | 97 | * Get the maximum length of the attribute value. |
vcoubard | 1161:515032db6feb | 98 | * |
vcoubard | 1161:515032db6feb | 99 | * The maximum length of the attribute value. |
vcoubard | 1161:515032db6feb | 100 | */ |
vcoubard | 1161:515032db6feb | 101 | uint16_t getMaxLength(void) const { |
vcoubard | 1161:515032db6feb | 102 | return _lenMax; |
vcoubard | 1161:515032db6feb | 103 | } |
vcoubard | 1161:515032db6feb | 104 | |
vcoubard | 1161:515032db6feb | 105 | /** |
vcoubard | 1161:515032db6feb | 106 | * Get a pointer to the current length of the attribute value. |
vcoubard | 1161:515032db6feb | 107 | * |
vcoubard | 1161:515032db6feb | 108 | * @return A pointer to the current length of the attribute value. |
vcoubard | 1161:515032db6feb | 109 | */ |
vcoubard | 1161:515032db6feb | 110 | uint16_t *getLengthPtr(void) { |
vcoubard | 1161:515032db6feb | 111 | return &_len; |
vcoubard | 1161:515032db6feb | 112 | } |
vcoubard | 1161:515032db6feb | 113 | |
vcoubard | 1161:515032db6feb | 114 | /** |
vcoubard | 1161:515032db6feb | 115 | * Set the attribute handle. |
vcoubard | 1161:515032db6feb | 116 | * |
vcoubard | 1161:515032db6feb | 117 | * @param[in] id |
vcoubard | 1161:515032db6feb | 118 | * The new attribute handle. |
vcoubard | 1161:515032db6feb | 119 | */ |
vcoubard | 1161:515032db6feb | 120 | void setHandle(Handle_t id) { |
vcoubard | 1161:515032db6feb | 121 | _handle = id; |
vcoubard | 1161:515032db6feb | 122 | } |
vcoubard | 1161:515032db6feb | 123 | |
vcoubard | 1161:515032db6feb | 124 | /** |
vcoubard | 1161:515032db6feb | 125 | * Get a pointer to the attribute value. |
vcoubard | 1161:515032db6feb | 126 | * |
vcoubard | 1161:515032db6feb | 127 | * @return A pointer to the attribute value. |
vcoubard | 1161:515032db6feb | 128 | */ |
vcoubard | 1161:515032db6feb | 129 | uint8_t *getValuePtr(void) { |
vcoubard | 1161:515032db6feb | 130 | return _valuePtr; |
vcoubard | 1161:515032db6feb | 131 | } |
vcoubard | 1161:515032db6feb | 132 | |
vcoubard | 1161:515032db6feb | 133 | /** |
vcoubard | 1161:515032db6feb | 134 | * Check whether the length of the attribute's value can change over time. |
vcoubard | 1161:515032db6feb | 135 | * |
vcoubard | 1161:515032db6feb | 136 | * @return true if the attribute has variable length, false otherwise. |
vcoubard | 1161:515032db6feb | 137 | */ |
vcoubard | 1161:515032db6feb | 138 | bool hasVariableLength(void) const { |
vcoubard | 1161:515032db6feb | 139 | return _hasVariableLen; |
vcoubard | 1161:515032db6feb | 140 | } |
vcoubard | 1131:692ddf04fc42 | 141 | |
vcoubard | 1131:692ddf04fc42 | 142 | private: |
vcoubard | 1161:515032db6feb | 143 | /** |
vcoubard | 1161:515032db6feb | 144 | * Characteristic's UUID. |
vcoubard | 1161:515032db6feb | 145 | */ |
vcoubard | 1161:515032db6feb | 146 | UUID _uuid; |
vcoubard | 1161:515032db6feb | 147 | /** |
vcoubard | 1161:515032db6feb | 148 | * Pointer to the attribute's value. |
vcoubard | 1161:515032db6feb | 149 | */ |
vcoubard | 1131:692ddf04fc42 | 150 | uint8_t *_valuePtr; |
vcoubard | 1161:515032db6feb | 151 | /** |
vcoubard | 1161:515032db6feb | 152 | * Maximum length of the value pointed to by GattAttribute::_valuePtr. |
vcoubard | 1161:515032db6feb | 153 | */ |
vcoubard | 1161:515032db6feb | 154 | uint16_t _lenMax; |
vcoubard | 1161:515032db6feb | 155 | /** |
vcoubard | 1161:515032db6feb | 156 | * Current length of the value pointed to by GattAttribute::_valuePtr. |
vcoubard | 1161:515032db6feb | 157 | */ |
vcoubard | 1161:515032db6feb | 158 | uint16_t _len; |
vcoubard | 1161:515032db6feb | 159 | /** |
vcoubard | 1161:515032db6feb | 160 | * Whether the length of the value can change over time. |
vcoubard | 1161:515032db6feb | 161 | */ |
vcoubard | 1132:6362b7c2fdff | 162 | bool _hasVariableLen; |
vcoubard | 1161:515032db6feb | 163 | /** |
vcoubard | 1161:515032db6feb | 164 | * The attribute's handle in the ATT table. |
vcoubard | 1161:515032db6feb | 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 | 1161:515032db6feb | 174 | #endif /* ifndef __GATT_ATTRIBUTE_H__ */ |