Includes library modifications to allow access to AIN_4 (AIN_0 / 5)

Committer:
bryantaylor
Date:
Tue Sep 20 21:26:12 2016 +0000
Revision:
0:eafc3fd41f75
hackathon

Who changed what in which revision?

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