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
UUID.h
00001 /* mbed Microcontroller Library 00002 * Copyright (c) 2006-2013 ARM Limited 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef __UUID_H__ 00018 #define __UUID_H__ 00019 00020 #include <string.h> 00021 00022 #include "blecommon.h" 00023 00024 const unsigned LENGTH_OF_LONG_UUID = 16; 00025 typedef uint16_t ShortUUIDBytes_t; 00026 typedef uint8_t LongUUIDBytes_t[LENGTH_OF_LONG_UUID]; 00027 00028 class UUID { 00029 public: 00030 enum UUID_Type_t { 00031 UUID_TYPE_SHORT = 0, // Short BLE UUID 00032 UUID_TYPE_LONG = 1 // Full 128-bit UUID 00033 }; 00034 00035 public: 00036 /** 00037 * Creates a new 128-bit UUID 00038 * 00039 * @note The UUID is a unique 128-bit (16 byte) ID used to identify 00040 * different service or characteristics on the BLE device. 00041 * 00042 * @param longUUID 00043 * The 128-bit (16-byte) UUID value. 00044 */ 00045 UUID(const LongUUIDBytes_t longUUID) : type(UUID_TYPE_LONG), baseUUID(), shortUUID(0) { 00046 memcpy(baseUUID, longUUID, LENGTH_OF_LONG_UUID); 00047 shortUUID = (uint16_t)((longUUID[2] << 8) | (longUUID[3])); 00048 } 00049 00050 /** 00051 * Creates a new 16-bit UUID 00052 * 00053 * @note The UUID is a unique 16-bit (2 byte) ID used to identify 00054 * different service or characteristics on the BLE device. 00055 * 00056 * For efficiency, and because 16 bytes would take a large chunk of the 00057 * 27-byte data payload length of the Link Layer, the BLE specification adds 00058 * two additional UUID formats: 16-bit and 32-bit UUIDs. These shortened 00059 * formats can be used only with UUIDs that are defined in the Bluetooth 00060 * specification (i.e., that are listed by the Bluetooth SIG as standard 00061 * Bluetooth UUIDs). 00062 * 00063 * To reconstruct the full 128-bit UUID from the shortened version, insert 00064 * the 16-bit short value (indicated by xxxx, including leading zeros) into 00065 * the Bluetooth Base UUID: 00066 * 00067 * 0000xxxx-0000-1000-8000-00805F9B34FB 00068 * 00069 * @note Shortening is not available for UUIDs that are not derived from the 00070 * Bluetooth Base UUID. Such non-standard UUIDs are commonly called 00071 * vendor-specific UUIDs. In these cases, you’ll need to use the full 00072 * 128-bit UUID value at all times. 00073 * 00074 * @note we don't yet support 32-bit shortened UUIDs. 00075 */ 00076 UUID(ShortUUIDBytes_t shortUUID) : type(UUID_TYPE_SHORT), baseUUID(), shortUUID(shortUUID) { 00077 /* empty */ 00078 } 00079 00080 public: 00081 UUID_Type_t shortOrLong(void) const {return type; } 00082 const uint8_t *getBaseUUID(void) const { 00083 if (type == UUID_TYPE_SHORT) { 00084 return (const uint8_t*)&shortUUID; 00085 } else { 00086 return baseUUID; 00087 } 00088 } 00089 00090 ShortUUIDBytes_t getShortUUID(void) const {return shortUUID;} 00091 uint8_t getLen(void) const { 00092 return ((type == UUID_TYPE_SHORT) ? sizeof(ShortUUIDBytes_t) : LENGTH_OF_LONG_UUID); 00093 } 00094 00095 bool operator== (const UUID &other) const { 00096 if ((this->type == UUID_TYPE_SHORT) && (other.type == UUID_TYPE_SHORT) && 00097 (this->shortUUID == other.shortUUID)) { 00098 return true; 00099 } 00100 00101 if ((this->type == UUID_TYPE_LONG) && (other.type == UUID_TYPE_LONG) && 00102 (memcmp(this->baseUUID, other.baseUUID, LENGTH_OF_LONG_UUID) == 0)) { 00103 return true; 00104 } 00105 00106 return false; 00107 } 00108 00109 private: 00110 UUID_Type_t type; // UUID_TYPE_SHORT or UUID_TYPE_LONG 00111 LongUUIDBytes_t baseUUID; /* the base of the long UUID (if 00112 * used). Note: bytes 12 and 13 (counting from LSB) 00113 * are zeroed out to allow comparison with other long 00114 * UUIDs which differ only in the 16-bit relative 00115 * part.*/ 00116 ShortUUIDBytes_t shortUUID; // 16 bit uuid (byte 2-3 using with base) 00117 }; 00118 00119 #endif // ifndef __UUID_H__
Generated on Tue Jul 12 2022 18:47:13 by
