esp-nimble-cpp 2.0.2
Loading...
Searching...
No Matches
NimBLEUUID Class Reference

A model of a BLE UUID. More...

#include <NimBLEUUID.h>

Public Member Functions

 NimBLEUUID ()=default
 Created a blank UUID.
 
 NimBLEUUID (const ble_uuid_any_t &uuid)
 Create a UUID from the native UUID.
 
 NimBLEUUID (const std::string &uuid)
 Create a UUID from a string.
 
 NimBLEUUID (uint16_t uuid)
 Create a UUID from the 16bit value.
 
 NimBLEUUID (uint32_t uuid)
 Create a UUID from the 32bit value.
 
 NimBLEUUID (const ble_uuid128_t *uuid)
 Create a UUID from the native UUID.
 
 NimBLEUUID (const uint8_t *pData, size_t size)
 Create a UUID from 2, 4, 16 bytes of memory.
 
 NimBLEUUID (uint32_t first, uint16_t second, uint16_t third, uint64_t fourth)
 Create a UUID from the 128bit value using hex parts instead of string, instead of NimBLEUUID("ebe0ccb0-7a0a-4b0c-8a1a-6ff2997da3a6"), it becomes NimBLEUUID(0xebe0ccb0, 0x7a0a, 0x4b0c, 0x8a1a6ff2997da3a6)
 
uint8_t bitSize () const
 Get the bit size of the UUID, 16, 32 or 128.
 
const uint8_t * getValue () const
 Get the uuid value.
 
const ble_uuid_t * getBase () const
 Get a pointer to the NimBLE UUID base structure.
 
bool equals (const NimBLEUUID &uuid) const
 Compare a UUID against this UUID.
 
std::string toString () const
 Get a string representation of the UUID.
 
const NimBLEUUIDto128 ()
 Convert a UUID to its 128 bit representation.
 
const NimBLEUUIDto16 ()
 Convert 128 bit UUID to its 16 bit representation.
 
const NimBLEUUIDreverseByteOrder ()
 Reverse the byte order of the UUID.
 
bool operator== (const NimBLEUUID &rhs) const
 Convenience operator to check if this UUID is equal to another.
 
bool operator!= (const NimBLEUUID &rhs) const
 Convenience operator to check if this UUID is not equal to another.
 
 operator std::string () const
 Convenience operator to convert this UUID to string representation.
 

Static Public Member Functions

static NimBLEUUID fromString (const std::string &uuid)
 

Detailed Description

A model of a BLE UUID.

Constructor & Destructor Documentation

◆ NimBLEUUID() [1/7]

NimBLEUUID::NimBLEUUID ( const ble_uuid_any_t &  uuid)

Create a UUID from the native UUID.

Parameters
[in]uuidThe native UUID.

◆ NimBLEUUID() [2/7]

NimBLEUUID::NimBLEUUID ( const std::string &  value)

Create a UUID from a string.

Create a UUID from a string. There will be two possible stories here. Either the string represents a binary data field or the string represents a hex encoding of a UUID. For the hex encoding, here is an example:

"beb5483e-36e1-4688-b7f5-ea07361b26a8"
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5
12345678-90ab-cdef-1234-567890abcdef

This has a length of 36 characters. We need to parse this into 16 bytes.

Parameters
[in]valueThe string to build a UUID from.

◆ NimBLEUUID() [3/7]

NimBLEUUID::NimBLEUUID ( uint16_t  uuid)

Create a UUID from the 16bit value.

Parameters
[in]uuidThe 16bit short form UUID.

◆ NimBLEUUID() [4/7]

NimBLEUUID::NimBLEUUID ( uint32_t  uuid)

Create a UUID from the 32bit value.

Parameters
[in]uuidThe 32bit short form UUID.

◆ NimBLEUUID() [5/7]

NimBLEUUID::NimBLEUUID ( const ble_uuid128_t *  uuid)

Create a UUID from the native UUID.

Parameters
[in]uuidThe native UUID.

◆ NimBLEUUID() [6/7]

NimBLEUUID::NimBLEUUID ( const uint8_t *  pData,
size_t  size 
)

Create a UUID from 2, 4, 16 bytes of memory.

Parameters
[in]pDataThe pointer to the start of the UUID.
[in]sizeThe size of the data.

◆ NimBLEUUID() [7/7]

NimBLEUUID::NimBLEUUID ( uint32_t  first,
uint16_t  second,
uint16_t  third,
uint64_t  fourth 
)

Create a UUID from the 128bit value using hex parts instead of string, instead of NimBLEUUID("ebe0ccb0-7a0a-4b0c-8a1a-6ff2997da3a6"), it becomes NimBLEUUID(0xebe0ccb0, 0x7a0a, 0x4b0c, 0x8a1a6ff2997da3a6)

Parameters
[in]firstThe first 32bit of the UUID.
[in]secondThe next 16bit of the UUID.
[in]thirdThe next 16bit of the UUID.
[in]fourthThe last 64bit of the UUID, combining the last 2 parts of the string equivalent

Member Function Documentation

◆ bitSize()

uint8_t NimBLEUUID::bitSize ( ) const

Get the bit size of the UUID, 16, 32 or 128.

Returns
The bit size of the UUID or 0 if not initialized.

◆ equals()

bool NimBLEUUID::equals ( const NimBLEUUID uuid) const

Compare a UUID against this UUID.

Parameters
[in]uuidThe UUID to compare against.
Returns
True if the UUIDs are equal and false otherwise.

◆ fromString()

NimBLEUUID NimBLEUUID::fromString ( const std::string &  uuid)
static

Create a NimBLEUUID from a string of the form: 0xNNNN 0xNNNNNNNN 0x<UUID> NNNN NNNNNNNN <UUID>

Parameters
[in]uuidThe string to create the UUID from.

◆ getBase()

const ble_uuid_t * NimBLEUUID::getBase ( ) const

Get a pointer to the NimBLE UUID base structure.

Returns
A Read-only pointer to the NimBLE UUID base structure.
Note
The type value should be checked, if no 16, 32 or 128 then the UUID is not initialized.

◆ getValue()

const uint8_t * NimBLEUUID::getValue ( ) const

Get the uuid value.

Returns
A pointer to the UUID value or nullptr if not initialized.
Note
This should be checked with bitSize() before accessing.

◆ operator std::string()

NimBLEUUID::operator std::string ( ) const

Convenience operator to convert this UUID to string representation.

This allows passing NimBLEUUID to functions that accept std::string and/or or it's methods as a parameter.

◆ reverseByteOrder()

const NimBLEUUID & NimBLEUUID::reverseByteOrder ( )

Reverse the byte order of the UUID.

Returns
The NimBLEUUID with the byte order reversed.

This is useful when comparing UUIDs or when the advertisement data is reversed.

◆ to128()

const NimBLEUUID & NimBLEUUID::to128 ( )

Convert a UUID to its 128 bit representation.

A UUID can be internally represented as 16bit, 32bit or the full 128bit. This method will convert 16 or 32bit representations to the full 128bit.

Returns
The NimBLEUUID converted to 128bit.

◆ to16()

const NimBLEUUID & NimBLEUUID::to16 ( )

Convert 128 bit UUID to its 16 bit representation.

A UUID can be internally represented as 16bit, 32bit or the full 128bit. This method will convert a 128bit uuid to 16bit if it contains the ble base uuid.

Returns
The NimBLEUUID converted to 16bit if successful, otherwise the original uuid.

◆ toString()

std::string NimBLEUUID::toString ( ) const

Get a string representation of the UUID.

The format of a string is: 01234567 8901 2345 6789 012345678901 0000180d-0000-1000-8000-00805f9b34fb 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5

Returns
A string representation of the UUID.
Deprecated:
Use std::string() operator instead.