ELEC-C7222
Libraries for ELEC C7222 Course Work
Loading...
Searching...
No Matches
c7222::Uuid Class Reference

UUID storage for 16-bit and 128-bit UUIDs. More...

#include <uuid.hpp>

Collaboration diagram for c7222::Uuid:
Collaboration graph

Public Types

enum class  Type : uint8_t { Invalid = 0 , k16Bit = 1 , k128Bit = 2 }
 UUID representation type. More...
 
enum class  AttributeType : uint16_t {
  kPrimaryServiceDeclaration = 0x2800 , kSecondaryServiceDeclaration = 0x2801 , kIncludedServiceDeclaration = 0x2802 , kCharacteristicDeclaration = 0x2803 ,
  kServerCharacteristicConfiguration = 0x2903 , kClientCharacteristicConfiguration = 0x2902 , kCharacteristicUserDescription = 0x2901 , kCharacteristicExtendedProperties = 0x2900 ,
  kCharacteristicPresentationFormat = 0x2904 , kCharacteristicAggregateFormat = 0x2905
}
 Standard GATT Attribute Type UUIDs (16-bit). More...
 

Public Member Functions

 Uuid ()=default
 Constructs an invalid/empty UUID.
 
 Uuid (const Uuid &)=default
 Copy-constructs a UUID.
 
 Uuid (Uuid &&) noexcept=default
 Move-constructs a UUID.
 
Uuidoperator= (const Uuid &)=default
 Copy assignment operator.
 
Uuidoperator= (Uuid &&) noexcept=default
 Move assignment operator.
 
 Uuid (uint16_t uuid16)
 Constructs a 16-bit UUID from a numeric value.
 
 Uuid (const uint8_t *uuid, size_t size)
 Constructs a UUID from a raw byte buffer.
 
 Uuid (const std::array< uint8_t, 16 > &uuid)
 Constructs a 128-bit UUID from an array.
 
 Uuid (const std::array< uint8_t, 2 > &uuid)
 Constructs a 16-bit UUID from an array.
 
Type type () const
 Returns the UUID type.
 
bool Is16Bit () const
 Returns true if this UUID is 16-bit.
 
bool Is128Bit () const
 Returns true if this UUID is 128-bit.
 
bool IsValid () const
 Returns true if the UUID has been initialized to 16- or 128-bit.
 
uint16_t Get16Bit () const
 Returns the 16-bit UUID value.
 
const std::array< uint8_t, 16 > & Get128Bit () const
 Returns the 128-bit UUID bytes.
 
const uint8_t * data () const
 Returns the raw UUID storage pointer.
 
bool operator== (const Uuid &other) const
 Equality comparison based on UUID type and value.
 
bool operator!= (const Uuid &other) const
 Inequality comparison based on UUID type and value.
 

Static Public Member Functions

static Uuid Convert16To128 (const Uuid &uuid16)
 Converts a 16-bit UUID to a 128-bit Bluetooth base UUID.
 
static Uuid PrimaryServiceDeclaration ()
 Create a Primary Service Declaration UUID (0x2800).
 
static Uuid SecondaryServiceDeclaration ()
 Create a Secondary Service Declaration UUID (0x2801).
 
static Uuid IncludedServiceDeclaration ()
 Create an Included Service Declaration UUID (0x2802).
 
static Uuid CharacteristicDeclaration ()
 Create a Characteristic Declaration UUID (0x2803).
 
static Uuid ClientCharacteristicConfiguration ()
 Create a Client Characteristic Configuration UUID (0x2902).
 
static Uuid ServerCharacteristicConfiguration ()
 Create a Server Characteristic Configuration UUID (0x2903).
 
static Uuid CharacteristicUserDescription ()
 Create a Characteristic User Description UUID (0x2901).
 
static Uuid CharacteristicExtendedProperties ()
 Create a Characteristic Extended Properties UUID (0x2900).
 
static Uuid CharacteristicPresentationFormat ()
 Create a Characteristic Presentation Format UUID (0x2904).
 
static Uuid CharacteristicAggregateFormat ()
 Create a Characteristic Aggregate Format UUID (0x2905).
 
static bool IsPrimaryServiceDeclaration (const Uuid &uuid)
 Check if UUID is Primary Service Declaration (0x2800).
 
static bool IsSecondaryServiceDeclaration (const Uuid &uuid)
 Check if UUID is Secondary Service Declaration (0x2801).
 
static bool IsIncludedServiceDeclaration (const Uuid &uuid)
 Check if UUID is Included Service Declaration (0x2802).
 
static bool IsCharacteristicDeclaration (const Uuid &uuid)
 Check if UUID is Characteristic Declaration (0x2803).
 
static bool IsServiceDeclaration (const Uuid &uuid)
 Check if UUID is any Service Declaration (Primary or Secondary).
 
static bool IsClientCharacteristicConfiguration (const Uuid &uuid)
 Check if UUID is Client Characteristic Configuration (0x2902).
 
static bool IsServerCharacteristicConfiguration (const Uuid &uuid)
 Check if UUID is Server Characteristic Configuration (0x2903).
 
static bool IsCharacteristicUserDescription (const Uuid &uuid)
 Check if UUID is Characteristic User Description (0x2901).
 
static bool IsCharacteristicExtendedProperties (const Uuid &uuid)
 Check if UUID is Characteristic Extended Properties (0x2900).
 
static bool IsDescriptor (const Uuid &uuid)
 Check if UUID matches a known descriptor type.
 

Friends

std::ostream & operator<< (std::ostream &os, const Uuid &uuid)
 Prints the UUID to a stream.
 

Detailed Description

UUID storage for 16-bit and 128-bit UUIDs.

The first two bytes of uuid_ are used for 16-bit UUIDs and the full 16-byte array is used for 128-bit UUIDs. On RP2040, 16-bit UUIDs are stored in little-endian order to match the BTstack ATT DB layout. For 128-bit UUIDs, the byte order matches the standard UUID string format shown by the stream operator.

The class also defines common 16-bit GATT attribute type UUIDs and helper predicates to recognize declaration/descriptor UUIDs.

Note
The UUID class provides type-safe and endian-aware access to 16-bit and 128-bit UUID values, ensuring compatibility with Bluetooth Low Energy (BLE) specifications and BTstack's attribute database layout.
You can find BTstack defined UUIDs in "bluetooth_gatt.h" file in ".pico-sdk/sdk/2.2.0/lib/btstack/src/bluetooth_gatt.h"

Example (16-bit construction and access):

c7222::Uuid uuid16(0x180D);
uint16_t short_id = uuid16.Get16Bit();
UUID storage for 16-bit and 128-bit UUIDs.
Definition uuid.hpp:53

Example (128-bit construction and access):

std::array<uint8_t, 16> bytes = {0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC,
0xDE, 0xF0, 0x11, 0x22, 0x33, 0x44,
0x55, 0x66, 0x77, 0x88};
c7222::Uuid uuid128(bytes);
const auto& raw = uuid128.Get128Bit();

Member Enumeration Documentation

◆ AttributeType

enum class c7222::Uuid::AttributeType : uint16_t
strong

Standard GATT Attribute Type UUIDs (16-bit).

These values identify service/characteristic declarations and common descriptors as defined by Bluetooth Assigned Numbers.

Enumerator
kPrimaryServiceDeclaration 

Primary Service Declaration attribute (0x2800).

kSecondaryServiceDeclaration 

Secondary Service Declaration attribute (0x2801).

kIncludedServiceDeclaration 

Included Service Declaration attribute (0x2802).

kCharacteristicDeclaration 

Characteristic Declaration attribute (0x2803).

kServerCharacteristicConfiguration 

Server Characteristic Configuration Descriptor (0x2903).

kClientCharacteristicConfiguration 

Client Characteristic Configuration Descriptor (0x2902).

kCharacteristicUserDescription 

Characteristic User Description Descriptor (0x2901).

kCharacteristicExtendedProperties 

Characteristic Extended Properties Descriptor (0x2900).

kCharacteristicPresentationFormat 

Characteristic Presentation Format Descriptor (0x2904).

kCharacteristicAggregateFormat 

Characteristic Aggregate Format Descriptor (0x2905).

◆ Type

enum class c7222::Uuid::Type : uint8_t
strong

UUID representation type.

Enumerator
Invalid 

Uninitialized or invalid UUID.

k16Bit 

16-bit UUID stored in the first two bytes.

k128Bit 

128-bit UUID stored in the full array.

Constructor & Destructor Documentation

◆ Uuid() [1/7]

c7222::Uuid::Uuid ( )
default

Constructs an invalid/empty UUID.

◆ Uuid() [2/7]

c7222::Uuid::Uuid ( const Uuid )
default

Copy-constructs a UUID.

◆ Uuid() [3/7]

c7222::Uuid::Uuid ( Uuid &&  )
defaultnoexcept

Move-constructs a UUID.

◆ Uuid() [4/7]

c7222::Uuid::Uuid ( uint16_t  uuid16)
inlineexplicit

Constructs a 16-bit UUID from a numeric value.

Parameters
uuid1616-bit UUID value (stored in little-endian order).

◆ Uuid() [5/7]

c7222::Uuid::Uuid ( const uint8_t *  uuid,
size_t  size 
)

Constructs a UUID from a raw byte buffer.

Parameters
uuidPointer to 2 or 16 bytes of UUID data.
sizeSize of the buffer in bytes (must be 2 or 16).

For 16-bit UUIDs, the buffer is interpreted as little-endian. For 128-bit UUIDs, the buffer is interpreted in standard byte order.

◆ Uuid() [6/7]

c7222::Uuid::Uuid ( const std::array< uint8_t, 16 > &  uuid)
inlineexplicit

Constructs a 128-bit UUID from an array.

Parameters
uuid128-bit UUID bytes in standard order.

◆ Uuid() [7/7]

c7222::Uuid::Uuid ( const std::array< uint8_t, 2 > &  uuid)
inlineexplicit

Constructs a 16-bit UUID from an array.

Parameters
uuid16-bit UUID bytes in little-endian order.

Member Function Documentation

◆ CharacteristicAggregateFormat()

static Uuid c7222::Uuid::CharacteristicAggregateFormat ( )
static

Create a Characteristic Aggregate Format UUID (0x2905).

◆ CharacteristicDeclaration()

static Uuid c7222::Uuid::CharacteristicDeclaration ( )
static

Create a Characteristic Declaration UUID (0x2803).

◆ CharacteristicExtendedProperties()

static Uuid c7222::Uuid::CharacteristicExtendedProperties ( )
static

Create a Characteristic Extended Properties UUID (0x2900).

◆ CharacteristicPresentationFormat()

static Uuid c7222::Uuid::CharacteristicPresentationFormat ( )
static

Create a Characteristic Presentation Format UUID (0x2904).

◆ CharacteristicUserDescription()

static Uuid c7222::Uuid::CharacteristicUserDescription ( )
static

Create a Characteristic User Description UUID (0x2901).

◆ ClientCharacteristicConfiguration()

static Uuid c7222::Uuid::ClientCharacteristicConfiguration ( )
static

Create a Client Characteristic Configuration UUID (0x2902).

◆ Convert16To128()

static Uuid c7222::Uuid::Convert16To128 ( const Uuid uuid16)
static

Converts a 16-bit UUID to a 128-bit Bluetooth base UUID.

Parameters
uuid1616-bit UUID to expand.
Returns
128-bit UUID using the Bluetooth base UUID format.

◆ data()

const uint8_t * c7222::Uuid::data ( ) const
inline

Returns the raw UUID storage pointer.

Returns
Pointer to the internal UUID byte array.

The byte order matches the storage rules documented above.

◆ Get128Bit()

const std::array< uint8_t, 16 > & c7222::Uuid::Get128Bit ( ) const
inline

Returns the 128-bit UUID bytes.

Returns
128-bit UUID byte array.

◆ Get16Bit()

uint16_t c7222::Uuid::Get16Bit ( ) const
inline

Returns the 16-bit UUID value.

Returns
16-bit UUID value.

◆ IncludedServiceDeclaration()

static Uuid c7222::Uuid::IncludedServiceDeclaration ( )
static

Create an Included Service Declaration UUID (0x2802).

◆ Is128Bit()

bool c7222::Uuid::Is128Bit ( ) const

Returns true if this UUID is 128-bit.

Here is the caller graph for this function:

◆ Is16Bit()

bool c7222::Uuid::Is16Bit ( ) const
inline

Returns true if this UUID is 16-bit.

◆ IsCharacteristicDeclaration()

static bool c7222::Uuid::IsCharacteristicDeclaration ( const Uuid uuid)
static

Check if UUID is Characteristic Declaration (0x2803).

◆ IsCharacteristicExtendedProperties()

static bool c7222::Uuid::IsCharacteristicExtendedProperties ( const Uuid uuid)
static

Check if UUID is Characteristic Extended Properties (0x2900).

◆ IsCharacteristicUserDescription()

static bool c7222::Uuid::IsCharacteristicUserDescription ( const Uuid uuid)
static

Check if UUID is Characteristic User Description (0x2901).

◆ IsClientCharacteristicConfiguration()

static bool c7222::Uuid::IsClientCharacteristicConfiguration ( const Uuid uuid)
static

Check if UUID is Client Characteristic Configuration (0x2902).

◆ IsDescriptor()

static bool c7222::Uuid::IsDescriptor ( const Uuid uuid)
static

Check if UUID matches a known descriptor type.

◆ IsIncludedServiceDeclaration()

static bool c7222::Uuid::IsIncludedServiceDeclaration ( const Uuid uuid)
static

Check if UUID is Included Service Declaration (0x2802).

◆ IsPrimaryServiceDeclaration()

static bool c7222::Uuid::IsPrimaryServiceDeclaration ( const Uuid uuid)
static

Check if UUID is Primary Service Declaration (0x2800).

◆ IsSecondaryServiceDeclaration()

static bool c7222::Uuid::IsSecondaryServiceDeclaration ( const Uuid uuid)
static

Check if UUID is Secondary Service Declaration (0x2801).

◆ IsServerCharacteristicConfiguration()

static bool c7222::Uuid::IsServerCharacteristicConfiguration ( const Uuid uuid)
static

Check if UUID is Server Characteristic Configuration (0x2903).

◆ IsServiceDeclaration()

static bool c7222::Uuid::IsServiceDeclaration ( const Uuid uuid)
static

Check if UUID is any Service Declaration (Primary or Secondary).

◆ IsValid()

bool c7222::Uuid::IsValid ( ) const
inline

Returns true if the UUID has been initialized to 16- or 128-bit.

Here is the caller graph for this function:

◆ operator!=()

bool c7222::Uuid::operator!= ( const Uuid other) const
inline

Inequality comparison based on UUID type and value.

Parameters
otherUUID to compare against.
Returns
true when type or value differ.

◆ operator=() [1/2]

Uuid & c7222::Uuid::operator= ( const Uuid )
default

Copy assignment operator.

◆ operator=() [2/2]

Uuid & c7222::Uuid::operator= ( Uuid &&  )
defaultnoexcept

Move assignment operator.

◆ operator==()

bool c7222::Uuid::operator== ( const Uuid other) const

Equality comparison based on UUID type and value.

Parameters
otherUUID to compare against.
Returns
true when type and value match.

◆ PrimaryServiceDeclaration()

static Uuid c7222::Uuid::PrimaryServiceDeclaration ( )
static

Create a Primary Service Declaration UUID (0x2800).

◆ SecondaryServiceDeclaration()

static Uuid c7222::Uuid::SecondaryServiceDeclaration ( )
static

Create a Secondary Service Declaration UUID (0x2801).

◆ ServerCharacteristicConfiguration()

static Uuid c7222::Uuid::ServerCharacteristicConfiguration ( )
static

Create a Server Characteristic Configuration UUID (0x2903).

◆ type()

Type c7222::Uuid::type ( ) const
inline

Returns the UUID type.

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream &  os,
const Uuid uuid 
)
friend

Prints the UUID to a stream.

For 16-bit UUIDs the output is 0xNNNN. For 128-bit UUIDs the output is the standard 8-4-4-4-12 hex format.

This is the definition corresponding to the friend declaration above.


The documentation for this class was generated from the following file: