Skip to content

Commit

Permalink
Add new NimBLEUUID constructor, solves #17.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeroen88 authored and h2zero committed Apr 29, 2020
1 parent 846d690 commit f648724
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/NimBLEUUID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,26 @@ NimBLEUUID::NimBLEUUID(ble_uuid128_t* uuid) {
} // NimBLEUUID


/**
* @brief Create a UUID from the 128bit value using hex parts instead of string,
* instead of BLEUUID("ebe0ccb0-7a0a-4b0c-8a1a-6ff2997da3a6"), it becomes
* BLEUUID(0xebe0ccb0, 0x7a0a, 0x4b0c, 0x8a1a6ff2997da3a6)
*
* @param [in] first The first 32bit of the UUID.
* @param [in] second The next 16bit of the UUID.
* @param [in] third The next 16bit of the UUID.
* @param [in] fourth The last 64bit of the UUID, combining the last 2 parts of the string equivalent
*/
NimBLEUUID::NimBLEUUID(uint32_t first, uint16_t second, uint16_t third, uint64_t fourth) {
m_uuid.u.type = BLE_UUID_TYPE_128;
memcpy(m_uuid.u128.value + 12, &first, 4);
memcpy(m_uuid.u128.value + 10, &second, 2);
memcpy(m_uuid.u128.value + 8, &third, 2);
memcpy(m_uuid.u128.value, &fourth, 8);
m_valueSet = true;
}


NimBLEUUID::NimBLEUUID() {
m_valueSet = false;
} // NimBLEUUID
Expand Down
1 change: 1 addition & 0 deletions src/NimBLEUUID.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class NimBLEUUID {
NimBLEUUID(uint32_t uuid);
NimBLEUUID(ble_uuid128_t* uuid);
NimBLEUUID(uint8_t* pData, size_t size, bool msbFirst);
NimBLEUUID(uint32_t first, uint16_t second, uint16_t third, uint64_t fourth);
NimBLEUUID();
uint8_t bitSize(); // Get the number of bits in this uuid.
bool equals(NimBLEUUID uuid);
Expand Down

0 comments on commit f648724

Please sign in to comment.