Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of BLE_API by
Revision 332:1dc2f80b4710, committed 2015-04-15
- Comitter:
- rgrover1
- Date:
- Wed Apr 15 09:05:10 2015 +0100
- Parent:
- 331:10f190629734
- Child:
- 333:098598ba075d
- Commit message:
- Synchronized with git rev 18e4b666
Author: Rohit Grover
merge UUID.cpp into UUID.h
Changed in this revision
| common/UUID.cpp | Show diff for this revision Revisions of this file |
| public/UUID.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/common/UUID.cpp Wed Apr 15 09:05:10 2015 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,88 +0,0 @@
-/* mbed Microcontroller Library
- * Copyright (c) 2006-2013 ARM Limited
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <string.h>
-
-#include "UUID.h"
-
-UUID::UUID(ShortUUIDBytes_t shortUUID) : type(UUID_TYPE_SHORT), baseUUID(), shortUUID(shortUUID) {
- /* empty */
-}
-
-/**************************************************************************/
-/*!
- @brief Creates a new 128-bit UUID
-
- @note The UUID is a unique 128-bit (16 byte) ID used to identify
- different service or characteristics on the BLE device.
-
- @note When creating a UUID, the constructor will check if all bytes
- except bytes 2/3 are equal to 0. If only bytes 2/3 have a
- value, the UUID will be treated as a short/BLE UUID, and the
- .type field will be set to UUID::UUID_TYPE_SHORT. If any
- of the bytes outside byte 2/3 have a non-zero value, the UUID
- will be considered a 128-bit ID, and .type will be assigned
- as UUID::UUID_TYPE_LONG.
-
- @param[in] uuid_base
- The 128-bit (16-byte) UUID value. For 128-bit values,
- assign all 16 bytes. For 16-bit values, assign the
- 16-bits to byte 2 and 3, and leave the rest of the bytes
- as 0.
-
- @section EXAMPLE
-
- @code
-
- // Create a short UUID (0x180F)
- uint8_t shortID[16] = { 0, 0, 0x0F, 0x18, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
- UUID ble_uuid = UUID(shortID);
- // ble_uuid.type = UUID_TYPE_SHORT
- // ble_uuid.value = 0x180F
-
- // Creeate a long UUID
- uint8_t longID[16] = { 0x00, 0x11, 0x22, 0x33,
- 0x44, 0x55, 0x66, 0x77,
- 0x88, 0x99, 0xAA, 0xBB,
- 0xCC, 0xDD, 0xEE, 0xFF };
- UUID custom_uuid = UUID(longID);
- // custom_uuid.type = UUID_TYPE_LONG
- // custom_uuid.value = 0x3322
- // custom_uuid.base = 00 11 22 33 44 55 66 77 88 99 AA BB CC DD EE FF
-
- @endcode
-*/
-/**************************************************************************/
-UUID::UUID(const LongUUIDBytes_t longUUID) : type(UUID_TYPE_LONG), baseUUID(), shortUUID(0)
-{
- memcpy(baseUUID, longUUID, LENGTH_OF_LONG_UUID);
- shortUUID = (uint16_t)((longUUID[2] << 8) | (longUUID[3]));
-}
-
-bool UUID::operator==(const UUID &other) const
-{
- if ((this->type == UUID_TYPE_SHORT) && (other.type == UUID_TYPE_SHORT) &&
- (this->shortUUID == other.shortUUID)) {
- return true;
- }
-
- if ((this->type == UUID_TYPE_LONG) && (other.type == UUID_TYPE_LONG) &&
- (memcmp(this->baseUUID, other.baseUUID, LENGTH_OF_LONG_UUID) == 0)) {
- return true;
- }
-
- return false;
-}
\ No newline at end of file
--- a/public/UUID.h Wed Apr 15 09:05:10 2015 +0100
+++ b/public/UUID.h Wed Apr 15 09:05:10 2015 +0100
@@ -31,8 +31,49 @@
};
public:
- UUID(const LongUUIDBytes_t);
- UUID(ShortUUIDBytes_t);
+ /**
+ * Creates a new 128-bit UUID
+ *
+ * @note The UUID is a unique 128-bit (16 byte) ID used to identify
+ * different service or characteristics on the BLE device.
+ *
+ * @param longUUID
+ * The 128-bit (16-byte) UUID value.
+ */
+ UUID(const LongUUIDBytes_t longUUID) : type(UUID_TYPE_LONG), baseUUID(), shortUUID(0) {
+ memcpy(baseUUID, longUUID, LENGTH_OF_LONG_UUID);
+ shortUUID = (uint16_t)((longUUID[2] << 8) | (longUUID[3]));
+ }
+
+ /**
+ * Creates a new 16-bit UUID
+ *
+ * @note The UUID is a unique 16-bit (2 byte) ID used to identify
+ * different service or characteristics on the BLE device.
+ *
+ * For efficiency, and because 16 bytes would take a large chunk of the
+ * 27-byte data payload length of the Link Layer, the BLE specification adds
+ * two additional UUID formats: 16-bit and 32-bit UUIDs. These shortened
+ * formats can be used only with UUIDs that are defined in the Bluetooth
+ * specification (i.e., that are listed by the Bluetooth SIG as standard
+ * Bluetooth UUIDs).
+ *
+ * To reconstruct the full 128-bit UUID from the shortened version, insert
+ * the 16-bit short value (indicated by xxxx, including leading zeros) into
+ * the Bluetooth Base UUID:
+ *
+ * 0000xxxx-0000-1000-8000-00805F9B34FB
+ *
+ * @note Shortening is not available for UUIDs that are not derived from the
+ * Bluetooth Base UUID. Such non-standard UUIDs are commonly called
+ * vendor-specific UUIDs. In these cases, you’ll need to use the full
+ * 128-bit UUID value at all times.
+ *
+ * @note we don't yet support 32-bit shortened UUIDs.
+ */
+ UUID(ShortUUIDBytes_t shortUUID) : type(UUID_TYPE_SHORT), baseUUID(), shortUUID(shortUUID) {
+ /* empty */
+ }
public:
UUID_Type_t shortOrLong(void) const {return type; }
@@ -43,12 +84,25 @@
return baseUUID;
}
}
+
ShortUUIDBytes_t getShortUUID(void) const {return shortUUID;}
uint8_t getLen(void) const {
return ((type == UUID_TYPE_SHORT) ? sizeof(ShortUUIDBytes_t) : LENGTH_OF_LONG_UUID);
}
- bool operator== (const UUID&) const;
+ bool operator== (const UUID &other) const {
+ if ((this->type == UUID_TYPE_SHORT) && (other.type == UUID_TYPE_SHORT) &&
+ (this->shortUUID == other.shortUUID)) {
+ return true;
+ }
+
+ if ((this->type == UUID_TYPE_LONG) && (other.type == UUID_TYPE_LONG) &&
+ (memcmp(this->baseUUID, other.baseUUID, LENGTH_OF_LONG_UUID) == 0)) {
+ return true;
+ }
+
+ return false;
+ }
private:
UUID_Type_t type; // UUID_TYPE_SHORT or UUID_TYPE_LONG
