Updated
Fork of BLE_API by
ble/UUID.h@1183:1589830dbdb7, 2016-04-06 (annotated)
- Committer:
- vcoubard
- Date:
- Wed Apr 06 19:15:36 2016 +0100
- Revision:
- 1183:1589830dbdb7
- Parent:
- 1179:4ab722f8dca0
Synchronized with git rev 44cc6871
Author: Andres Amaya Garcia
Merge branch 'develop' into fix-doxy-warnings
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 __UUID_H__ |
vcoubard | 1131:692ddf04fc42 | 18 | #define __UUID_H__ |
vcoubard | 1131:692ddf04fc42 | 19 | |
vcoubard | 1131:692ddf04fc42 | 20 | #include <stdint.h> |
vcoubard | 1131:692ddf04fc42 | 21 | #include <string.h> |
vcoubard | 1134:d540a48f650d | 22 | #include <algorithm> |
vcoubard | 1131:692ddf04fc42 | 23 | |
vcoubard | 1131:692ddf04fc42 | 24 | #include "blecommon.h" |
vcoubard | 1131:692ddf04fc42 | 25 | |
vcoubard | 1134:d540a48f650d | 26 | /** |
vcoubard | 1183:1589830dbdb7 | 27 | * A trivial converter for single hexadecimal character to an unsigned integer. |
vcoubard | 1183:1589830dbdb7 | 28 | * |
vcoubard | 1183:1589830dbdb7 | 29 | * @param c |
vcoubard | 1183:1589830dbdb7 | 30 | * Hexadecimal character. |
vcoubard | 1183:1589830dbdb7 | 31 | * |
vcoubard | 1183:1589830dbdb7 | 32 | * @return The corresponding value as unsigned integer. |
vcoubard | 1134:d540a48f650d | 33 | */ |
vcoubard | 1134:d540a48f650d | 34 | static uint8_t char2int(char c) { |
vcoubard | 1134:d540a48f650d | 35 | if ((c >= '0') && (c <= '9')) { |
vcoubard | 1134:d540a48f650d | 36 | return c - '0'; |
vcoubard | 1134:d540a48f650d | 37 | } else if ((c >= 'a') && (c <= 'f')) { |
vcoubard | 1134:d540a48f650d | 38 | return c - 'a' + 10; |
vcoubard | 1134:d540a48f650d | 39 | } else if ((c >= 'A') && (c <= 'F')) { |
vcoubard | 1134:d540a48f650d | 40 | return c - 'A' + 10; |
vcoubard | 1134:d540a48f650d | 41 | } else { |
vcoubard | 1134:d540a48f650d | 42 | return 0; |
vcoubard | 1134:d540a48f650d | 43 | } |
vcoubard | 1134:d540a48f650d | 44 | } |
vcoubard | 1134:d540a48f650d | 45 | |
vcoubard | 1183:1589830dbdb7 | 46 | /** |
vcoubard | 1183:1589830dbdb7 | 47 | * An instance of this class represents a Universally Unique Identifier (UUID) |
vcoubard | 1183:1589830dbdb7 | 48 | * in the BLE API. |
vcoubard | 1183:1589830dbdb7 | 49 | */ |
vcoubard | 1131:692ddf04fc42 | 50 | class UUID { |
vcoubard | 1131:692ddf04fc42 | 51 | public: |
vcoubard | 1183:1589830dbdb7 | 52 | /** |
vcoubard | 1183:1589830dbdb7 | 53 | * Enumeration of the possible types of UUIDs in BLE with regards to length. |
vcoubard | 1183:1589830dbdb7 | 54 | */ |
vcoubard | 1131:692ddf04fc42 | 55 | enum UUID_Type_t { |
vcoubard | 1183:1589830dbdb7 | 56 | UUID_TYPE_SHORT = 0, /**< Short 16-bit UUID. */ |
vcoubard | 1183:1589830dbdb7 | 57 | UUID_TYPE_LONG = 1 /**< Full 128-bit UUID. */ |
vcoubard | 1131:692ddf04fc42 | 58 | }; |
vcoubard | 1131:692ddf04fc42 | 59 | |
vcoubard | 1134:d540a48f650d | 60 | /** |
vcoubard | 1183:1589830dbdb7 | 61 | * Enumeration to specify byte ordering of the long version of the UUID. |
vcoubard | 1134:d540a48f650d | 62 | */ |
vcoubard | 1134:d540a48f650d | 63 | typedef enum { |
vcoubard | 1183:1589830dbdb7 | 64 | MSB, /**< Most-significant byte first (at the smallest address) */ |
vcoubard | 1183:1589830dbdb7 | 65 | LSB /**< least-significant byte first (at the smallest address) */ |
vcoubard | 1134:d540a48f650d | 66 | } ByteOrder_t; |
vcoubard | 1134:d540a48f650d | 67 | |
vcoubard | 1183:1589830dbdb7 | 68 | /** |
vcoubard | 1183:1589830dbdb7 | 69 | * Type for a 16-bit UUID. |
vcoubard | 1183:1589830dbdb7 | 70 | */ |
vcoubard | 1131:692ddf04fc42 | 71 | typedef uint16_t ShortUUIDBytes_t; |
vcoubard | 1131:692ddf04fc42 | 72 | |
vcoubard | 1183:1589830dbdb7 | 73 | /** |
vcoubard | 1183:1589830dbdb7 | 74 | * Length of a long UUID in bytes. |
vcoubard | 1183:1589830dbdb7 | 75 | */ |
vcoubard | 1131:692ddf04fc42 | 76 | static const unsigned LENGTH_OF_LONG_UUID = 16; |
vcoubard | 1183:1589830dbdb7 | 77 | /** |
vcoubard | 1183:1589830dbdb7 | 78 | * Type for a 128-bit UUID. |
vcoubard | 1183:1589830dbdb7 | 79 | */ |
vcoubard | 1131:692ddf04fc42 | 80 | typedef uint8_t LongUUIDBytes_t[LENGTH_OF_LONG_UUID]; |
vcoubard | 1131:692ddf04fc42 | 81 | |
vcoubard | 1183:1589830dbdb7 | 82 | /** |
vcoubard | 1183:1589830dbdb7 | 83 | * Maximum length of a string representation of a UUID not including the |
vcoubard | 1183:1589830dbdb7 | 84 | * null termination ('\0'): two characters per |
vcoubard | 1183:1589830dbdb7 | 85 | * byte plus four '-' characters. |
vcoubard | 1183:1589830dbdb7 | 86 | */ |
vcoubard | 1134:d540a48f650d | 87 | static const unsigned MAX_UUID_STRING_LENGTH = LENGTH_OF_LONG_UUID * 2 + 4; |
vcoubard | 1134:d540a48f650d | 88 | |
vcoubard | 1131:692ddf04fc42 | 89 | public: |
vcoubard | 1134:d540a48f650d | 90 | |
vcoubard | 1134:d540a48f650d | 91 | /** |
vcoubard | 1134:d540a48f650d | 92 | * Creates a new 128-bit UUID. |
vcoubard | 1134:d540a48f650d | 93 | * |
vcoubard | 1134:d540a48f650d | 94 | * @note The UUID is a unique 128-bit (16 byte) ID used to identify |
vcoubard | 1134:d540a48f650d | 95 | * different service or characteristics on the BLE device. |
vcoubard | 1134:d540a48f650d | 96 | * |
vcoubard | 1134:d540a48f650d | 97 | * @param stringUUID |
vcoubard | 1134:d540a48f650d | 98 | * The 128-bit (16-byte) UUID as a human readable const-string. |
vcoubard | 1134:d540a48f650d | 99 | * Format: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX |
vcoubard | 1134:d540a48f650d | 100 | * Upper and lower case supported. Hyphens are optional, but only |
vcoubard | 1134:d540a48f650d | 101 | * upto four of them. The UUID is stored internally as a 16 byte |
vcoubard | 1134:d540a48f650d | 102 | * array, LSB (little endian), which is opposite from the string. |
vcoubard | 1134:d540a48f650d | 103 | */ |
vcoubard | 1134:d540a48f650d | 104 | UUID(const char* stringUUID) : type(UUID_TYPE_LONG), baseUUID(), shortUUID(0) { |
vcoubard | 1134:d540a48f650d | 105 | bool nibble = false; |
vcoubard | 1134:d540a48f650d | 106 | uint8_t byte = 0; |
vcoubard | 1134:d540a48f650d | 107 | size_t baseIndex = 0; |
vcoubard | 1134:d540a48f650d | 108 | uint8_t tempUUID[LENGTH_OF_LONG_UUID]; |
vcoubard | 1134:d540a48f650d | 109 | |
vcoubard | 1183:1589830dbdb7 | 110 | /* |
vcoubard | 1183:1589830dbdb7 | 111 | * Iterate through string, abort if NULL is encountered prematurely. |
vcoubard | 1183:1589830dbdb7 | 112 | * Ignore upto four hyphens. |
vcoubard | 1183:1589830dbdb7 | 113 | */ |
vcoubard | 1134:d540a48f650d | 114 | for (size_t index = 0; (index < MAX_UUID_STRING_LENGTH) && (baseIndex < LENGTH_OF_LONG_UUID); index++) { |
vcoubard | 1134:d540a48f650d | 115 | if (stringUUID[index] == '\0') { |
vcoubard | 1183:1589830dbdb7 | 116 | /* Error abort */ |
vcoubard | 1134:d540a48f650d | 117 | break; |
vcoubard | 1134:d540a48f650d | 118 | } else if (stringUUID[index] == '-') { |
vcoubard | 1183:1589830dbdb7 | 119 | /* Ignore hyphen */ |
vcoubard | 1134:d540a48f650d | 120 | continue; |
vcoubard | 1134:d540a48f650d | 121 | } else if (nibble) { |
vcoubard | 1183:1589830dbdb7 | 122 | /* Got second nibble */ |
vcoubard | 1134:d540a48f650d | 123 | byte |= char2int(stringUUID[index]); |
vcoubard | 1134:d540a48f650d | 124 | nibble = false; |
vcoubard | 1134:d540a48f650d | 125 | |
vcoubard | 1183:1589830dbdb7 | 126 | /* Store copy */ |
vcoubard | 1134:d540a48f650d | 127 | tempUUID[baseIndex++] = byte; |
vcoubard | 1134:d540a48f650d | 128 | } else { |
vcoubard | 1183:1589830dbdb7 | 129 | /* Got first nibble */ |
vcoubard | 1134:d540a48f650d | 130 | byte = char2int(stringUUID[index]) << 4; |
vcoubard | 1134:d540a48f650d | 131 | nibble = true; |
vcoubard | 1134:d540a48f650d | 132 | } |
vcoubard | 1134:d540a48f650d | 133 | } |
vcoubard | 1134:d540a48f650d | 134 | |
vcoubard | 1183:1589830dbdb7 | 135 | /* Populate internal variables if string was successfully parsed */ |
vcoubard | 1134:d540a48f650d | 136 | if (baseIndex == LENGTH_OF_LONG_UUID) { |
vcoubard | 1134:d540a48f650d | 137 | setupLong(tempUUID, UUID::MSB); |
vcoubard | 1134:d540a48f650d | 138 | } else { |
vcoubard | 1134:d540a48f650d | 139 | const uint8_t sig[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, |
vcoubard | 1134:d540a48f650d | 140 | 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB }; |
vcoubard | 1134:d540a48f650d | 141 | setupLong(sig, UUID::MSB); |
vcoubard | 1134:d540a48f650d | 142 | } |
vcoubard | 1134:d540a48f650d | 143 | } |
vcoubard | 1134:d540a48f650d | 144 | |
vcoubard | 1131:692ddf04fc42 | 145 | /** |
vcoubard | 1131:692ddf04fc42 | 146 | * Creates a new 128-bit UUID. |
vcoubard | 1131:692ddf04fc42 | 147 | * |
vcoubard | 1183:1589830dbdb7 | 148 | * @param[in] longUUID |
vcoubard | 1183:1589830dbdb7 | 149 | * The 128-bit (16-byte) UUID value. |
vcoubard | 1183:1589830dbdb7 | 150 | * @param[in] order |
vcoubard | 1183:1589830dbdb7 | 151 | * The bit order of the UUID, MSB by default. |
vcoubard | 1183:1589830dbdb7 | 152 | * |
vcoubard | 1131:692ddf04fc42 | 153 | * @note The UUID is a unique 128-bit (16 byte) ID used to identify |
vcoubard | 1131:692ddf04fc42 | 154 | * different service or characteristics on the BLE device. |
vcoubard | 1131:692ddf04fc42 | 155 | */ |
vcoubard | 1134:d540a48f650d | 156 | UUID(const LongUUIDBytes_t longUUID, ByteOrder_t order = UUID::MSB) : type(UUID_TYPE_LONG), baseUUID(), shortUUID(0) { |
vcoubard | 1134:d540a48f650d | 157 | setupLong(longUUID, order); |
vcoubard | 1131:692ddf04fc42 | 158 | } |
vcoubard | 1131:692ddf04fc42 | 159 | |
vcoubard | 1131:692ddf04fc42 | 160 | /** |
vcoubard | 1131:692ddf04fc42 | 161 | * Creates a new 16-bit UUID. |
vcoubard | 1131:692ddf04fc42 | 162 | * |
vcoubard | 1131:692ddf04fc42 | 163 | * For efficiency, and because 16 bytes would take a large chunk of the |
vcoubard | 1131:692ddf04fc42 | 164 | * 27-byte data payload length of the Link Layer, the BLE specification adds |
vcoubard | 1131:692ddf04fc42 | 165 | * two additional UUID formats: 16-bit and 32-bit UUIDs. These shortened |
vcoubard | 1131:692ddf04fc42 | 166 | * formats can be used only with UUIDs that are defined in the Bluetooth |
vcoubard | 1131:692ddf04fc42 | 167 | * specification (listed by the Bluetooth SIG as standard |
vcoubard | 1131:692ddf04fc42 | 168 | * Bluetooth UUIDs). |
vcoubard | 1131:692ddf04fc42 | 169 | * |
vcoubard | 1131:692ddf04fc42 | 170 | * To reconstruct the full 128-bit UUID from the shortened version, insert |
vcoubard | 1131:692ddf04fc42 | 171 | * the 16-bit short value (indicated by xxxx, including leading zeros) into |
vcoubard | 1131:692ddf04fc42 | 172 | * the Bluetooth Base UUID: |
vcoubard | 1131:692ddf04fc42 | 173 | * |
vcoubard | 1131:692ddf04fc42 | 174 | * 0000xxxx-0000-1000-8000-00805F9B34FB |
vcoubard | 1131:692ddf04fc42 | 175 | * |
vcoubard | 1183:1589830dbdb7 | 176 | * @param[in] _shortUUID |
vcoubard | 1183:1589830dbdb7 | 177 | * The short UUID value. |
vcoubard | 1183:1589830dbdb7 | 178 | * |
vcoubard | 1131:692ddf04fc42 | 179 | * @note Shortening is not available for UUIDs that are not derived from the |
vcoubard | 1131:692ddf04fc42 | 180 | * Bluetooth Base UUID. Such non-standard UUIDs are commonly called |
vcoubard | 1131:692ddf04fc42 | 181 | * vendor-specific UUIDs. In these cases, you’ll need to use the full |
vcoubard | 1131:692ddf04fc42 | 182 | * 128-bit UUID value at all times. |
vcoubard | 1131:692ddf04fc42 | 183 | * |
vcoubard | 1183:1589830dbdb7 | 184 | * @note The UUID is a unique 16-bit (2 byte) ID used to identify |
vcoubard | 1183:1589830dbdb7 | 185 | * different service or characteristics on the BLE device. |
vcoubard | 1183:1589830dbdb7 | 186 | * |
vcoubard | 1183:1589830dbdb7 | 187 | * @note We do not yet support 32-bit shortened UUIDs. |
vcoubard | 1131:692ddf04fc42 | 188 | */ |
vcoubard | 1131:692ddf04fc42 | 189 | UUID(ShortUUIDBytes_t _shortUUID) : type(UUID_TYPE_SHORT), baseUUID(), shortUUID(_shortUUID) { |
vcoubard | 1131:692ddf04fc42 | 190 | /* Empty */ |
vcoubard | 1131:692ddf04fc42 | 191 | } |
vcoubard | 1131:692ddf04fc42 | 192 | |
vcoubard | 1183:1589830dbdb7 | 193 | /** |
vcoubard | 1183:1589830dbdb7 | 194 | * Copy constructor. |
vcoubard | 1183:1589830dbdb7 | 195 | * |
vcoubard | 1183:1589830dbdb7 | 196 | * @param[in] source |
vcoubard | 1183:1589830dbdb7 | 197 | * The UUID to copy. |
vcoubard | 1183:1589830dbdb7 | 198 | */ |
vcoubard | 1131:692ddf04fc42 | 199 | UUID(const UUID &source) { |
vcoubard | 1131:692ddf04fc42 | 200 | type = source.type; |
vcoubard | 1131:692ddf04fc42 | 201 | shortUUID = source.shortUUID; |
vcoubard | 1131:692ddf04fc42 | 202 | memcpy(baseUUID, source.baseUUID, LENGTH_OF_LONG_UUID); |
vcoubard | 1131:692ddf04fc42 | 203 | } |
vcoubard | 1131:692ddf04fc42 | 204 | |
vcoubard | 1183:1589830dbdb7 | 205 | /** |
vcoubard | 1183:1589830dbdb7 | 206 | * The empty constructor. |
vcoubard | 1183:1589830dbdb7 | 207 | * |
vcoubard | 1183:1589830dbdb7 | 208 | * @note The type of the resulting UUID instance is UUID_TYPE_SHORT and the |
vcoubard | 1183:1589830dbdb7 | 209 | * value BLE_UUID_UNKNOWN. |
vcoubard | 1183:1589830dbdb7 | 210 | */ |
vcoubard | 1131:692ddf04fc42 | 211 | UUID(void) : type(UUID_TYPE_SHORT), shortUUID(BLE_UUID_UNKNOWN) { |
vcoubard | 1131:692ddf04fc42 | 212 | /* empty */ |
vcoubard | 1131:692ddf04fc42 | 213 | } |
vcoubard | 1131:692ddf04fc42 | 214 | |
vcoubard | 1131:692ddf04fc42 | 215 | /** |
vcoubard | 1183:1589830dbdb7 | 216 | * Fill in a 128-bit UUID; this is useful when the UUID is not known at the |
vcoubard | 1183:1589830dbdb7 | 217 | * time of the object construction. |
vcoubard | 1183:1589830dbdb7 | 218 | * |
vcoubard | 1183:1589830dbdb7 | 219 | * @param[in] longUUID |
vcoubard | 1183:1589830dbdb7 | 220 | * The UUID value to copy. |
vcoubard | 1183:1589830dbdb7 | 221 | * @param[in] order |
vcoubard | 1183:1589830dbdb7 | 222 | * The byte ordering of the UUID at @p longUUID. |
vcoubard | 1131:692ddf04fc42 | 223 | */ |
vcoubard | 1134:d540a48f650d | 224 | void setupLong(const LongUUIDBytes_t longUUID, ByteOrder_t order = UUID::MSB) { |
vcoubard | 1131:692ddf04fc42 | 225 | type = UUID_TYPE_LONG; |
vcoubard | 1134:d540a48f650d | 226 | if (order == UUID::MSB) { |
vcoubard | 1183:1589830dbdb7 | 227 | /* |
vcoubard | 1183:1589830dbdb7 | 228 | * Switch endian. Input is big-endian, internal representation |
vcoubard | 1183:1589830dbdb7 | 229 | * is little endian. |
vcoubard | 1183:1589830dbdb7 | 230 | */ |
vcoubard | 1134:d540a48f650d | 231 | std::reverse_copy(longUUID, longUUID + LENGTH_OF_LONG_UUID, baseUUID); |
vcoubard | 1134:d540a48f650d | 232 | } else { |
vcoubard | 1134:d540a48f650d | 233 | std::copy(longUUID, longUUID + LENGTH_OF_LONG_UUID, baseUUID); |
vcoubard | 1134:d540a48f650d | 234 | } |
vcoubard | 1134:d540a48f650d | 235 | shortUUID = (uint16_t)((baseUUID[13] << 8) | (baseUUID[12])); |
vcoubard | 1131:692ddf04fc42 | 236 | } |
vcoubard | 1131:692ddf04fc42 | 237 | |
vcoubard | 1131:692ddf04fc42 | 238 | public: |
vcoubard | 1183:1589830dbdb7 | 239 | /** |
vcoubard | 1183:1589830dbdb7 | 240 | * Check whether this UUID is short or long. |
vcoubard | 1183:1589830dbdb7 | 241 | * |
vcoubard | 1183:1589830dbdb7 | 242 | * @return UUID_TYPE_SHORT if the UUID is short, UUID_TYPE_LONG otherwise. |
vcoubard | 1183:1589830dbdb7 | 243 | */ |
vcoubard | 1183:1589830dbdb7 | 244 | UUID_Type_t shortOrLong(void) const { |
vcoubard | 1183:1589830dbdb7 | 245 | return type; |
vcoubard | 1183:1589830dbdb7 | 246 | } |
vcoubard | 1183:1589830dbdb7 | 247 | |
vcoubard | 1183:1589830dbdb7 | 248 | /** |
vcoubard | 1183:1589830dbdb7 | 249 | * Get a pointer to the UUID value based on the current UUID type. |
vcoubard | 1183:1589830dbdb7 | 250 | * |
vcoubard | 1183:1589830dbdb7 | 251 | * @return A pointer to the short UUID if the type is set to |
vcoubard | 1183:1589830dbdb7 | 252 | * UUID_TYPE_SHORT. Otherwise, a pointer to the long UUID if the |
vcoubard | 1183:1589830dbdb7 | 253 | * type is set to UUID_TYPE_LONG. |
vcoubard | 1183:1589830dbdb7 | 254 | */ |
vcoubard | 1183:1589830dbdb7 | 255 | const uint8_t *getBaseUUID(void) const { |
vcoubard | 1131:692ddf04fc42 | 256 | if (type == UUID_TYPE_SHORT) { |
vcoubard | 1131:692ddf04fc42 | 257 | return (const uint8_t*)&shortUUID; |
vcoubard | 1131:692ddf04fc42 | 258 | } else { |
vcoubard | 1131:692ddf04fc42 | 259 | return baseUUID; |
vcoubard | 1131:692ddf04fc42 | 260 | } |
vcoubard | 1131:692ddf04fc42 | 261 | } |
vcoubard | 1131:692ddf04fc42 | 262 | |
vcoubard | 1183:1589830dbdb7 | 263 | /** |
vcoubard | 1183:1589830dbdb7 | 264 | * Get the short UUID. |
vcoubard | 1183:1589830dbdb7 | 265 | * |
vcoubard | 1183:1589830dbdb7 | 266 | * @return The short UUID. |
vcoubard | 1183:1589830dbdb7 | 267 | */ |
vcoubard | 1183:1589830dbdb7 | 268 | ShortUUIDBytes_t getShortUUID(void) const { |
vcoubard | 1183:1589830dbdb7 | 269 | return shortUUID; |
vcoubard | 1183:1589830dbdb7 | 270 | } |
vcoubard | 1183:1589830dbdb7 | 271 | |
vcoubard | 1183:1589830dbdb7 | 272 | /** |
vcoubard | 1183:1589830dbdb7 | 273 | * Get the length (in bytes) of the UUID based on its type. |
vcoubard | 1183:1589830dbdb7 | 274 | * |
vcoubard | 1183:1589830dbdb7 | 275 | * @retval sizeof(ShortUUIDBytes_t) if the UUID type is UUID_TYPE_SHORT. |
vcoubard | 1183:1589830dbdb7 | 276 | * @retval LENGTH_OF_LONG_UUID if the UUID type is UUID_TYPE_LONG. |
vcoubard | 1183:1589830dbdb7 | 277 | */ |
vcoubard | 1183:1589830dbdb7 | 278 | uint8_t getLen(void) const { |
vcoubard | 1131:692ddf04fc42 | 279 | return ((type == UUID_TYPE_SHORT) ? sizeof(ShortUUIDBytes_t) : LENGTH_OF_LONG_UUID); |
vcoubard | 1131:692ddf04fc42 | 280 | } |
vcoubard | 1131:692ddf04fc42 | 281 | |
vcoubard | 1183:1589830dbdb7 | 282 | /** |
vcoubard | 1183:1589830dbdb7 | 283 | * Overload == operator to enable UUID comparisons. |
vcoubard | 1183:1589830dbdb7 | 284 | * |
vcoubard | 1183:1589830dbdb7 | 285 | * @param[in] other |
vcoubard | 1183:1589830dbdb7 | 286 | * The other UUID in the comparison. |
vcoubard | 1183:1589830dbdb7 | 287 | * |
vcoubard | 1183:1589830dbdb7 | 288 | * @return true if this == @p other, false otherwise. |
vcoubard | 1183:1589830dbdb7 | 289 | */ |
vcoubard | 1131:692ddf04fc42 | 290 | bool operator== (const UUID &other) const { |
vcoubard | 1131:692ddf04fc42 | 291 | if ((this->type == UUID_TYPE_SHORT) && (other.type == UUID_TYPE_SHORT) && |
vcoubard | 1131:692ddf04fc42 | 292 | (this->shortUUID == other.shortUUID)) { |
vcoubard | 1131:692ddf04fc42 | 293 | return true; |
vcoubard | 1131:692ddf04fc42 | 294 | } |
vcoubard | 1131:692ddf04fc42 | 295 | |
vcoubard | 1131:692ddf04fc42 | 296 | if ((this->type == UUID_TYPE_LONG) && (other.type == UUID_TYPE_LONG) && |
vcoubard | 1131:692ddf04fc42 | 297 | (memcmp(this->baseUUID, other.baseUUID, LENGTH_OF_LONG_UUID) == 0)) { |
vcoubard | 1131:692ddf04fc42 | 298 | return true; |
vcoubard | 1131:692ddf04fc42 | 299 | } |
vcoubard | 1131:692ddf04fc42 | 300 | |
vcoubard | 1131:692ddf04fc42 | 301 | return false; |
vcoubard | 1131:692ddf04fc42 | 302 | } |
vcoubard | 1131:692ddf04fc42 | 303 | |
vcoubard | 1183:1589830dbdb7 | 304 | /** |
vcoubard | 1183:1589830dbdb7 | 305 | * Overload != operator to enable UUID comparisons. |
vcoubard | 1183:1589830dbdb7 | 306 | * |
vcoubard | 1183:1589830dbdb7 | 307 | * @param[in] other |
vcoubard | 1183:1589830dbdb7 | 308 | * The other UUID in the comparison. |
vcoubard | 1183:1589830dbdb7 | 309 | * |
vcoubard | 1183:1589830dbdb7 | 310 | * @return true if this != @p other, false otherwise. |
vcoubard | 1183:1589830dbdb7 | 311 | */ |
vcoubard | 1131:692ddf04fc42 | 312 | bool operator!= (const UUID &other) const { |
vcoubard | 1131:692ddf04fc42 | 313 | return !(*this == other); |
vcoubard | 1131:692ddf04fc42 | 314 | } |
vcoubard | 1131:692ddf04fc42 | 315 | |
vcoubard | 1131:692ddf04fc42 | 316 | private: |
vcoubard | 1183:1589830dbdb7 | 317 | /** |
vcoubard | 1183:1589830dbdb7 | 318 | * The UUID type. Refer to UUID_Type_t. |
vcoubard | 1183:1589830dbdb7 | 319 | */ |
vcoubard | 1183:1589830dbdb7 | 320 | UUID_Type_t type; |
vcoubard | 1183:1589830dbdb7 | 321 | /** |
vcoubard | 1183:1589830dbdb7 | 322 | * The long UUID value. |
vcoubard | 1183:1589830dbdb7 | 323 | */ |
vcoubard | 1183:1589830dbdb7 | 324 | LongUUIDBytes_t baseUUID; |
vcoubard | 1183:1589830dbdb7 | 325 | /** |
vcoubard | 1183:1589830dbdb7 | 326 | * The short UUID value. |
vcoubard | 1183:1589830dbdb7 | 327 | */ |
vcoubard | 1183:1589830dbdb7 | 328 | ShortUUIDBytes_t shortUUID; |
vcoubard | 1131:692ddf04fc42 | 329 | }; |
vcoubard | 1131:692ddf04fc42 | 330 | |
rgrover1 | 710:b2e1a2660ec2 | 331 | #endif // ifndef __UUID_H__ |