BA / SerialCom

Fork of OmniWheels by Gustav Atmel

Committer:
gustavatmel
Date:
Tue May 01 15:47:08 2018 +0000
Revision:
1:9c5af431a1f1
sdf

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gustavatmel 1:9c5af431a1f1 1 /* mbed Microcontroller Library
gustavatmel 1:9c5af431a1f1 2 * Copyright (c) 2006-2013 ARM Limited
gustavatmel 1:9c5af431a1f1 3 *
gustavatmel 1:9c5af431a1f1 4 * Licensed under the Apache License, Version 2.0 (the "License");
gustavatmel 1:9c5af431a1f1 5 * you may not use this file except in compliance with the License.
gustavatmel 1:9c5af431a1f1 6 * You may obtain a copy of the License at
gustavatmel 1:9c5af431a1f1 7 *
gustavatmel 1:9c5af431a1f1 8 * http://www.apache.org/licenses/LICENSE-2.0
gustavatmel 1:9c5af431a1f1 9 *
gustavatmel 1:9c5af431a1f1 10 * Unless required by applicable law or agreed to in writing, software
gustavatmel 1:9c5af431a1f1 11 * distributed under the License is distributed on an "AS IS" BASIS,
gustavatmel 1:9c5af431a1f1 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
gustavatmel 1:9c5af431a1f1 13 * See the License for the specific language governing permissions and
gustavatmel 1:9c5af431a1f1 14 * limitations under the License.
gustavatmel 1:9c5af431a1f1 15 */
gustavatmel 1:9c5af431a1f1 16
gustavatmel 1:9c5af431a1f1 17 #ifndef MBED_UUID_H__
gustavatmel 1:9c5af431a1f1 18 #define MBED_UUID_H__
gustavatmel 1:9c5af431a1f1 19
gustavatmel 1:9c5af431a1f1 20 #include <stddef.h>
gustavatmel 1:9c5af431a1f1 21 #include <stdint.h>
gustavatmel 1:9c5af431a1f1 22 #include <string.h>
gustavatmel 1:9c5af431a1f1 23 #include <algorithm>
gustavatmel 1:9c5af431a1f1 24
gustavatmel 1:9c5af431a1f1 25 #include "blecommon.h"
gustavatmel 1:9c5af431a1f1 26
gustavatmel 1:9c5af431a1f1 27 /**
gustavatmel 1:9c5af431a1f1 28 * @file
gustavatmel 1:9c5af431a1f1 29 * @addtogroup ble
gustavatmel 1:9c5af431a1f1 30 * @{
gustavatmel 1:9c5af431a1f1 31 * @addtogroup common
gustavatmel 1:9c5af431a1f1 32 * @{
gustavatmel 1:9c5af431a1f1 33 */
gustavatmel 1:9c5af431a1f1 34
gustavatmel 1:9c5af431a1f1 35 /**
gustavatmel 1:9c5af431a1f1 36 * Convert a character containing an hexadecimal digit into an unsigned integer.
gustavatmel 1:9c5af431a1f1 37 *
gustavatmel 1:9c5af431a1f1 38 * @param[in] c Hexadecimal digit in a character representation.
gustavatmel 1:9c5af431a1f1 39 *
gustavatmel 1:9c5af431a1f1 40 * @return The corresponding value as unsigned integer.
gustavatmel 1:9c5af431a1f1 41 */
gustavatmel 1:9c5af431a1f1 42 static uint8_t char2int(char c)
gustavatmel 1:9c5af431a1f1 43 {
gustavatmel 1:9c5af431a1f1 44 if ((c >= '0') && (c <= '9')) {
gustavatmel 1:9c5af431a1f1 45 return c - '0';
gustavatmel 1:9c5af431a1f1 46 } else if ((c >= 'a') && (c <= 'f')) {
gustavatmel 1:9c5af431a1f1 47 return c - 'a' + 10;
gustavatmel 1:9c5af431a1f1 48 } else if ((c >= 'A') && (c <= 'F')) {
gustavatmel 1:9c5af431a1f1 49 return c - 'A' + 10;
gustavatmel 1:9c5af431a1f1 50 } else {
gustavatmel 1:9c5af431a1f1 51 return 0;
gustavatmel 1:9c5af431a1f1 52 }
gustavatmel 1:9c5af431a1f1 53 }
gustavatmel 1:9c5af431a1f1 54
gustavatmel 1:9c5af431a1f1 55 /**
gustavatmel 1:9c5af431a1f1 56 * Representation of a Universally Unique Identifier (UUID).
gustavatmel 1:9c5af431a1f1 57 *
gustavatmel 1:9c5af431a1f1 58 * UUIDs are 128-bit wide numbers used to identify data type and elements in
gustavatmel 1:9c5af431a1f1 59 * many layers of the Bluetooth specification.
gustavatmel 1:9c5af431a1f1 60 *
gustavatmel 1:9c5af431a1f1 61 * Two representations of UUIDS exist:
gustavatmel 1:9c5af431a1f1 62 * - 16-bit UUIDs: Shortened representation of the 128 bit UUID
gustavatmel 1:9c5af431a1f1 63 * 0000xxxx-0000-1000-8000-00805F9B34FB where xxxx is the 16 bit UUID.
gustavatmel 1:9c5af431a1f1 64 * Values of those UUIDs are defined by the Bluetooth body. The short
gustavatmel 1:9c5af431a1f1 65 * representation saves bandwidth during protocol transactions.
gustavatmel 1:9c5af431a1f1 66 * - 128-bit UUIDs: Complete representation of a UUID. They are commonly
gustavatmel 1:9c5af431a1f1 67 * used for user defined UUID.
gustavatmel 1:9c5af431a1f1 68 *
gustavatmel 1:9c5af431a1f1 69 * This class acts as an adapter over these two kinds of UUIDs to allow
gustavatmel 1:9c5af431a1f1 70 * indiscriminate use of both forms in Mbed BLE APIs.
gustavatmel 1:9c5af431a1f1 71 *
gustavatmel 1:9c5af431a1f1 72 * @note 32-bit UUID representation is not supported currently.
gustavatmel 1:9c5af431a1f1 73 */
gustavatmel 1:9c5af431a1f1 74 class UUID {
gustavatmel 1:9c5af431a1f1 75 public:
gustavatmel 1:9c5af431a1f1 76
gustavatmel 1:9c5af431a1f1 77 /**
gustavatmel 1:9c5af431a1f1 78 * Enumeration of the types of UUIDs.
gustavatmel 1:9c5af431a1f1 79 */
gustavatmel 1:9c5af431a1f1 80 enum UUID_Type_t {
gustavatmel 1:9c5af431a1f1 81 /**
gustavatmel 1:9c5af431a1f1 82 * 16-bit wide UUID representation.
gustavatmel 1:9c5af431a1f1 83 */
gustavatmel 1:9c5af431a1f1 84 UUID_TYPE_SHORT = 0,
gustavatmel 1:9c5af431a1f1 85
gustavatmel 1:9c5af431a1f1 86 /**
gustavatmel 1:9c5af431a1f1 87 * 128-bit wide UUID representation.
gustavatmel 1:9c5af431a1f1 88 */
gustavatmel 1:9c5af431a1f1 89 UUID_TYPE_LONG = 1
gustavatmel 1:9c5af431a1f1 90 };
gustavatmel 1:9c5af431a1f1 91
gustavatmel 1:9c5af431a1f1 92 /**
gustavatmel 1:9c5af431a1f1 93 * Enumeration of byte ordering.
gustavatmel 1:9c5af431a1f1 94 *
gustavatmel 1:9c5af431a1f1 95 * It is used to construct 128-byte UUIDs.
gustavatmel 1:9c5af431a1f1 96 */
gustavatmel 1:9c5af431a1f1 97 typedef enum {
gustavatmel 1:9c5af431a1f1 98 /**
gustavatmel 1:9c5af431a1f1 99 * Most significant byte first (at the smallest address).
gustavatmel 1:9c5af431a1f1 100 */
gustavatmel 1:9c5af431a1f1 101 MSB,
gustavatmel 1:9c5af431a1f1 102
gustavatmel 1:9c5af431a1f1 103 /**
gustavatmel 1:9c5af431a1f1 104 * Least significant byte first (at the smallest address).
gustavatmel 1:9c5af431a1f1 105 */
gustavatmel 1:9c5af431a1f1 106 LSB
gustavatmel 1:9c5af431a1f1 107 } ByteOrder_t;
gustavatmel 1:9c5af431a1f1 108
gustavatmel 1:9c5af431a1f1 109 /**
gustavatmel 1:9c5af431a1f1 110 * Type for a 16-bit UUID.
gustavatmel 1:9c5af431a1f1 111 */
gustavatmel 1:9c5af431a1f1 112 typedef uint16_t ShortUUIDBytes_t;
gustavatmel 1:9c5af431a1f1 113
gustavatmel 1:9c5af431a1f1 114 /**
gustavatmel 1:9c5af431a1f1 115 * Length in bytes of a long UUID.
gustavatmel 1:9c5af431a1f1 116 */
gustavatmel 1:9c5af431a1f1 117 static const unsigned LENGTH_OF_LONG_UUID = 16;
gustavatmel 1:9c5af431a1f1 118
gustavatmel 1:9c5af431a1f1 119 /**
gustavatmel 1:9c5af431a1f1 120 * Type for a 128-bit UUID.
gustavatmel 1:9c5af431a1f1 121 */
gustavatmel 1:9c5af431a1f1 122 typedef uint8_t LongUUIDBytes_t[LENGTH_OF_LONG_UUID];
gustavatmel 1:9c5af431a1f1 123
gustavatmel 1:9c5af431a1f1 124 /**
gustavatmel 1:9c5af431a1f1 125 * Maximum length for the string representation of a UUID excluding the null
gustavatmel 1:9c5af431a1f1 126 * terminator.
gustavatmel 1:9c5af431a1f1 127 *
gustavatmel 1:9c5af431a1f1 128 * The string is composed of two characters per byte plus four '-'
gustavatmel 1:9c5af431a1f1 129 * characters.
gustavatmel 1:9c5af431a1f1 130 */
gustavatmel 1:9c5af431a1f1 131 static const unsigned MAX_UUID_STRING_LENGTH = LENGTH_OF_LONG_UUID * 2 + 4;
gustavatmel 1:9c5af431a1f1 132
gustavatmel 1:9c5af431a1f1 133 public:
gustavatmel 1:9c5af431a1f1 134
gustavatmel 1:9c5af431a1f1 135 /**
gustavatmel 1:9c5af431a1f1 136 * Construct a 128-bit UUID from a string.
gustavatmel 1:9c5af431a1f1 137 *
gustavatmel 1:9c5af431a1f1 138 * @param[in] stringUUID Human readable representation of the UUID following
gustavatmel 1:9c5af431a1f1 139 * the format XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX.
gustavatmel 1:9c5af431a1f1 140 *
gustavatmel 1:9c5af431a1f1 141 * @note Upper and lower case are supported.
gustavatmel 1:9c5af431a1f1 142 * @note Hyphens are optional. The string must include at most four hyphens.
gustavatmel 1:9c5af431a1f1 143 *
gustavatmel 1:9c5af431a1f1 144 * @note Internally, the UUID is stored in the little endian order as a
gustavatmel 1:9c5af431a1f1 145 * 16-byte array.
gustavatmel 1:9c5af431a1f1 146 */
gustavatmel 1:9c5af431a1f1 147 UUID(const char* stringUUID) :
gustavatmel 1:9c5af431a1f1 148 type(UUID_TYPE_LONG),
gustavatmel 1:9c5af431a1f1 149 baseUUID(),
gustavatmel 1:9c5af431a1f1 150 shortUUID(0)
gustavatmel 1:9c5af431a1f1 151 {
gustavatmel 1:9c5af431a1f1 152 bool nibble = false;
gustavatmel 1:9c5af431a1f1 153 uint8_t byte = 0;
gustavatmel 1:9c5af431a1f1 154 size_t baseIndex = 0;
gustavatmel 1:9c5af431a1f1 155 uint8_t tempUUID[LENGTH_OF_LONG_UUID];
gustavatmel 1:9c5af431a1f1 156
gustavatmel 1:9c5af431a1f1 157 /*
gustavatmel 1:9c5af431a1f1 158 * Iterate through string; abort if NULL is encountered prematurely.
gustavatmel 1:9c5af431a1f1 159 * Ignore up to four hyphens.
gustavatmel 1:9c5af431a1f1 160 */
gustavatmel 1:9c5af431a1f1 161 for (size_t index = 0; (index < MAX_UUID_STRING_LENGTH) && (baseIndex < LENGTH_OF_LONG_UUID); index++) {
gustavatmel 1:9c5af431a1f1 162 if (stringUUID[index] == '\0') {
gustavatmel 1:9c5af431a1f1 163 /* Error abort */
gustavatmel 1:9c5af431a1f1 164 break;
gustavatmel 1:9c5af431a1f1 165 } else if (stringUUID[index] == '-') {
gustavatmel 1:9c5af431a1f1 166 /* Ignore hyphen */
gustavatmel 1:9c5af431a1f1 167 continue;
gustavatmel 1:9c5af431a1f1 168 } else if (nibble) {
gustavatmel 1:9c5af431a1f1 169 /* Got second nibble */
gustavatmel 1:9c5af431a1f1 170 byte |= char2int(stringUUID[index]);
gustavatmel 1:9c5af431a1f1 171 nibble = false;
gustavatmel 1:9c5af431a1f1 172
gustavatmel 1:9c5af431a1f1 173 /* Store copy */
gustavatmel 1:9c5af431a1f1 174 tempUUID[baseIndex++] = byte;
gustavatmel 1:9c5af431a1f1 175 } else {
gustavatmel 1:9c5af431a1f1 176 /* Got first nibble */
gustavatmel 1:9c5af431a1f1 177 byte = char2int(stringUUID[index]) << 4;
gustavatmel 1:9c5af431a1f1 178 nibble = true;
gustavatmel 1:9c5af431a1f1 179 }
gustavatmel 1:9c5af431a1f1 180 }
gustavatmel 1:9c5af431a1f1 181
gustavatmel 1:9c5af431a1f1 182 /* Populate internal variables if string was successfully parsed */
gustavatmel 1:9c5af431a1f1 183 if (baseIndex == LENGTH_OF_LONG_UUID) {
gustavatmel 1:9c5af431a1f1 184 setupLong(tempUUID, UUID::MSB);
gustavatmel 1:9c5af431a1f1 185 } else {
gustavatmel 1:9c5af431a1f1 186 const uint8_t sig[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
gustavatmel 1:9c5af431a1f1 187 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB };
gustavatmel 1:9c5af431a1f1 188 setupLong(sig, UUID::MSB);
gustavatmel 1:9c5af431a1f1 189 }
gustavatmel 1:9c5af431a1f1 190 }
gustavatmel 1:9c5af431a1f1 191
gustavatmel 1:9c5af431a1f1 192 /**
gustavatmel 1:9c5af431a1f1 193 * Construct a new UUID from a 128-bit representation.
gustavatmel 1:9c5af431a1f1 194 *
gustavatmel 1:9c5af431a1f1 195 * @param[in] longUUID The 128-bit (16-byte) of the UUID value.
gustavatmel 1:9c5af431a1f1 196 * @param[in] order Bytes order of @p longUUID.
gustavatmel 1:9c5af431a1f1 197 */
gustavatmel 1:9c5af431a1f1 198 UUID(const LongUUIDBytes_t longUUID, ByteOrder_t order = UUID::MSB) : type(UUID_TYPE_LONG), baseUUID(), shortUUID(0) {
gustavatmel 1:9c5af431a1f1 199 setupLong(longUUID, order);
gustavatmel 1:9c5af431a1f1 200 }
gustavatmel 1:9c5af431a1f1 201
gustavatmel 1:9c5af431a1f1 202 /**
gustavatmel 1:9c5af431a1f1 203 * Creates a new 16-bit UUID.
gustavatmel 1:9c5af431a1f1 204 *
gustavatmel 1:9c5af431a1f1 205 * The Bluetooth standard body defines 16-bit wide UUIDs. They are the
gustavatmel 1:9c5af431a1f1 206 * shortened version of the UUID 0000xxxx-0000-1000-8000-00805F9B34FB, where
gustavatmel 1:9c5af431a1f1 207 * xxxx is the value of the 16-bit UUID.
gustavatmel 1:9c5af431a1f1 208 *
gustavatmel 1:9c5af431a1f1 209 * @attention 16-bit UUIDs are not used in user defined data type or
gustavatmel 1:9c5af431a1f1 210 * user defined element ID.
gustavatmel 1:9c5af431a1f1 211 *
gustavatmel 1:9c5af431a1f1 212 * @param[in] _shortUUID 16-bit part of the standard UUID.
gustavatmel 1:9c5af431a1f1 213 * The short UUID value.
gustavatmel 1:9c5af431a1f1 214 *
gustavatmel 1:9c5af431a1f1 215 * @note User defined UUIDs are commonly named vendor-specific UUIDs across
gustavatmel 1:9c5af431a1f1 216 * the Bluetooth literature.
gustavatmel 1:9c5af431a1f1 217 */
gustavatmel 1:9c5af431a1f1 218 UUID(ShortUUIDBytes_t _shortUUID) :
gustavatmel 1:9c5af431a1f1 219 type(UUID_TYPE_SHORT),
gustavatmel 1:9c5af431a1f1 220 baseUUID(),
gustavatmel 1:9c5af431a1f1 221 shortUUID(_shortUUID) {
gustavatmel 1:9c5af431a1f1 222 }
gustavatmel 1:9c5af431a1f1 223
gustavatmel 1:9c5af431a1f1 224 /**
gustavatmel 1:9c5af431a1f1 225 * UUID copy constructor.
gustavatmel 1:9c5af431a1f1 226 *
gustavatmel 1:9c5af431a1f1 227 * @param[in] source The UUID to copy.
gustavatmel 1:9c5af431a1f1 228 */
gustavatmel 1:9c5af431a1f1 229 UUID(const UUID &source)
gustavatmel 1:9c5af431a1f1 230 {
gustavatmel 1:9c5af431a1f1 231 type = source.type;
gustavatmel 1:9c5af431a1f1 232 shortUUID = source.shortUUID;
gustavatmel 1:9c5af431a1f1 233 memcpy(baseUUID, source.baseUUID, LENGTH_OF_LONG_UUID);
gustavatmel 1:9c5af431a1f1 234 }
gustavatmel 1:9c5af431a1f1 235
gustavatmel 1:9c5af431a1f1 236 /**
gustavatmel 1:9c5af431a1f1 237 * Default constructor.
gustavatmel 1:9c5af431a1f1 238 *
gustavatmel 1:9c5af431a1f1 239 * Construct an invalid UUID.
gustavatmel 1:9c5af431a1f1 240 *
gustavatmel 1:9c5af431a1f1 241 * @post shortOrLong() returns the value UUID_TYPE_SHORT.
gustavatmel 1:9c5af431a1f1 242 * @post getShortUUID() returns the value BLE_UUID_UNKNOWN.
gustavatmel 1:9c5af431a1f1 243 */
gustavatmel 1:9c5af431a1f1 244 UUID(void) :
gustavatmel 1:9c5af431a1f1 245 type(UUID_TYPE_SHORT),
gustavatmel 1:9c5af431a1f1 246 shortUUID(BLE_UUID_UNKNOWN) {
gustavatmel 1:9c5af431a1f1 247 }
gustavatmel 1:9c5af431a1f1 248
gustavatmel 1:9c5af431a1f1 249 /**
gustavatmel 1:9c5af431a1f1 250 * Replace existing value with a 128-bit UUID.
gustavatmel 1:9c5af431a1f1 251 *
gustavatmel 1:9c5af431a1f1 252 * @param[in] longUUID New 16-byte wide UUID value.
gustavatmel 1:9c5af431a1f1 253 * @param[in] order Byte ordering of @p longUUID.
gustavatmel 1:9c5af431a1f1 254 */
gustavatmel 1:9c5af431a1f1 255 void setupLong(const LongUUIDBytes_t longUUID, ByteOrder_t order = UUID::MSB)
gustavatmel 1:9c5af431a1f1 256 {
gustavatmel 1:9c5af431a1f1 257 type = UUID_TYPE_LONG;
gustavatmel 1:9c5af431a1f1 258 if (order == UUID::MSB) {
gustavatmel 1:9c5af431a1f1 259 /*
gustavatmel 1:9c5af431a1f1 260 * Switch endian. Input is big-endian, internal representation
gustavatmel 1:9c5af431a1f1 261 * is little endian.
gustavatmel 1:9c5af431a1f1 262 */
gustavatmel 1:9c5af431a1f1 263 std::reverse_copy(longUUID, longUUID + LENGTH_OF_LONG_UUID, baseUUID);
gustavatmel 1:9c5af431a1f1 264 } else {
gustavatmel 1:9c5af431a1f1 265 std::copy(longUUID, longUUID + LENGTH_OF_LONG_UUID, baseUUID);
gustavatmel 1:9c5af431a1f1 266 }
gustavatmel 1:9c5af431a1f1 267 shortUUID = (uint16_t)((baseUUID[13] << 8) | (baseUUID[12]));
gustavatmel 1:9c5af431a1f1 268 }
gustavatmel 1:9c5af431a1f1 269
gustavatmel 1:9c5af431a1f1 270 public:
gustavatmel 1:9c5af431a1f1 271 /**
gustavatmel 1:9c5af431a1f1 272 * Return the internal type of the UUID.
gustavatmel 1:9c5af431a1f1 273 *
gustavatmel 1:9c5af431a1f1 274 * @return UUID_TYPE_SHORT if the UUID is 16-bit wide.
gustavatmel 1:9c5af431a1f1 275 * @return UUID_TYPE_LONG if the UUID is 128-bit wide.
gustavatmel 1:9c5af431a1f1 276 */
gustavatmel 1:9c5af431a1f1 277 UUID_Type_t shortOrLong(void) const
gustavatmel 1:9c5af431a1f1 278 {
gustavatmel 1:9c5af431a1f1 279 return type;
gustavatmel 1:9c5af431a1f1 280 }
gustavatmel 1:9c5af431a1f1 281
gustavatmel 1:9c5af431a1f1 282 /**
gustavatmel 1:9c5af431a1f1 283 * Get a pointer to the UUID value based on the current UUID type.
gustavatmel 1:9c5af431a1f1 284 *
gustavatmel 1:9c5af431a1f1 285 * @return A pointer to an uint16_t object if the UUID is 16 bits long.
gustavatmel 1:9c5af431a1f1 286 * @return A pointer to an array of 16 bytes if the UUID is 128 bits long.
gustavatmel 1:9c5af431a1f1 287 */
gustavatmel 1:9c5af431a1f1 288 const uint8_t *getBaseUUID(void) const
gustavatmel 1:9c5af431a1f1 289 {
gustavatmel 1:9c5af431a1f1 290 if (type == UUID_TYPE_SHORT) {
gustavatmel 1:9c5af431a1f1 291 return (const uint8_t*)&shortUUID;
gustavatmel 1:9c5af431a1f1 292 } else {
gustavatmel 1:9c5af431a1f1 293 return baseUUID;
gustavatmel 1:9c5af431a1f1 294 }
gustavatmel 1:9c5af431a1f1 295 }
gustavatmel 1:9c5af431a1f1 296
gustavatmel 1:9c5af431a1f1 297 /**
gustavatmel 1:9c5af431a1f1 298 * Get the uint16_t value of the UUID.
gustavatmel 1:9c5af431a1f1 299 *
gustavatmel 1:9c5af431a1f1 300 * @attention This function is not used on long UUIDs.
gustavatmel 1:9c5af431a1f1 301 *
gustavatmel 1:9c5af431a1f1 302 * @return The value of the shortened UUID.
gustavatmel 1:9c5af431a1f1 303 */
gustavatmel 1:9c5af431a1f1 304 ShortUUIDBytes_t getShortUUID(void) const
gustavatmel 1:9c5af431a1f1 305 {
gustavatmel 1:9c5af431a1f1 306 return shortUUID;
gustavatmel 1:9c5af431a1f1 307 }
gustavatmel 1:9c5af431a1f1 308
gustavatmel 1:9c5af431a1f1 309 /**
gustavatmel 1:9c5af431a1f1 310 * Get the length (in bytes) of the internal UUID representation.
gustavatmel 1:9c5af431a1f1 311 *
gustavatmel 1:9c5af431a1f1 312 * @return sizeof(ShortUUIDBytes_t) if the UUID type is UUID_TYPE_SHORT.
gustavatmel 1:9c5af431a1f1 313 * @return LENGTH_OF_LONG_UUID if the UUID type is UUID_TYPE_LONG.
gustavatmel 1:9c5af431a1f1 314 */
gustavatmel 1:9c5af431a1f1 315 uint8_t getLen(void) const
gustavatmel 1:9c5af431a1f1 316 {
gustavatmel 1:9c5af431a1f1 317 return ((type == UUID_TYPE_SHORT) ?
gustavatmel 1:9c5af431a1f1 318 sizeof(ShortUUIDBytes_t) :
gustavatmel 1:9c5af431a1f1 319 LENGTH_OF_LONG_UUID);
gustavatmel 1:9c5af431a1f1 320 }
gustavatmel 1:9c5af431a1f1 321
gustavatmel 1:9c5af431a1f1 322 /**
gustavatmel 1:9c5af431a1f1 323 * Equal to operator between UUIDs.
gustavatmel 1:9c5af431a1f1 324 *
gustavatmel 1:9c5af431a1f1 325 * @param[in] other The UUID to compare to this.
gustavatmel 1:9c5af431a1f1 326 *
gustavatmel 1:9c5af431a1f1 327 * @return true if both UUIDs are equal and false otherwise.
gustavatmel 1:9c5af431a1f1 328 */
gustavatmel 1:9c5af431a1f1 329 bool operator== (const UUID &other) const
gustavatmel 1:9c5af431a1f1 330 {
gustavatmel 1:9c5af431a1f1 331 if ((this->type == UUID_TYPE_SHORT) && (other.type == UUID_TYPE_SHORT) &&
gustavatmel 1:9c5af431a1f1 332 (this->shortUUID == other.shortUUID)) {
gustavatmel 1:9c5af431a1f1 333 return true;
gustavatmel 1:9c5af431a1f1 334 }
gustavatmel 1:9c5af431a1f1 335
gustavatmel 1:9c5af431a1f1 336 if ((this->type == UUID_TYPE_LONG) && (other.type == UUID_TYPE_LONG) &&
gustavatmel 1:9c5af431a1f1 337 (memcmp(this->baseUUID, other.baseUUID, LENGTH_OF_LONG_UUID) == 0)) {
gustavatmel 1:9c5af431a1f1 338 return true;
gustavatmel 1:9c5af431a1f1 339 }
gustavatmel 1:9c5af431a1f1 340
gustavatmel 1:9c5af431a1f1 341 return false;
gustavatmel 1:9c5af431a1f1 342 }
gustavatmel 1:9c5af431a1f1 343
gustavatmel 1:9c5af431a1f1 344 /**
gustavatmel 1:9c5af431a1f1 345 * Not equal to operator.
gustavatmel 1:9c5af431a1f1 346 *
gustavatmel 1:9c5af431a1f1 347 * @param[in] other The UUID compared to this.
gustavatmel 1:9c5af431a1f1 348 *
gustavatmel 1:9c5af431a1f1 349 * @return true if both UUIDs are not equal and false otherwise.
gustavatmel 1:9c5af431a1f1 350 */
gustavatmel 1:9c5af431a1f1 351 bool operator!= (const UUID &other) const
gustavatmel 1:9c5af431a1f1 352 {
gustavatmel 1:9c5af431a1f1 353 return !(*this == other);
gustavatmel 1:9c5af431a1f1 354 }
gustavatmel 1:9c5af431a1f1 355
gustavatmel 1:9c5af431a1f1 356 private:
gustavatmel 1:9c5af431a1f1 357 /**
gustavatmel 1:9c5af431a1f1 358 * Representation type of the UUID.
gustavatmel 1:9c5af431a1f1 359 */
gustavatmel 1:9c5af431a1f1 360 UUID_Type_t type;
gustavatmel 1:9c5af431a1f1 361
gustavatmel 1:9c5af431a1f1 362 /**
gustavatmel 1:9c5af431a1f1 363 * Container of UUID value if the UUID type is equal to UUID_TYPE_LONG.
gustavatmel 1:9c5af431a1f1 364 */
gustavatmel 1:9c5af431a1f1 365 LongUUIDBytes_t baseUUID;
gustavatmel 1:9c5af431a1f1 366
gustavatmel 1:9c5af431a1f1 367 /**
gustavatmel 1:9c5af431a1f1 368 * Container of UUID value if the UUID type is equal to UUID_TYPE_SHORT.
gustavatmel 1:9c5af431a1f1 369 */
gustavatmel 1:9c5af431a1f1 370 ShortUUIDBytes_t shortUUID;
gustavatmel 1:9c5af431a1f1 371 };
gustavatmel 1:9c5af431a1f1 372
gustavatmel 1:9c5af431a1f1 373 /**
gustavatmel 1:9c5af431a1f1 374 * @}
gustavatmel 1:9c5af431a1f1 375 * @}
gustavatmel 1:9c5af431a1f1 376 */
gustavatmel 1:9c5af431a1f1 377
gustavatmel 1:9c5af431a1f1 378 #endif // ifndef MBED_UUID_H__