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