Preliminary main mbed library for nexpaq development

Committer:
nexpaq
Date:
Fri Nov 04 20:27:58 2016 +0000
Revision:
0:6c56fb4bc5f0
Moving to library for sharing updates

Who changed what in which revision?

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