Rtos API example

Committer:
marcozecchini
Date:
Sat Feb 23 12:13:36 2019 +0000
Revision:
0:9fca2b23d0ba
final commit

Who changed what in which revision?

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