Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new NimBLEUUID constructor, solves #17 #21

Merged
merged 2 commits into from
Apr 29, 2020

Conversation

Jeroen88
Copy link

Adding to NimBLEUUID.h:

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

and to NimBLEUUID.cpp:

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;
}

This does not save any library memory, but is does save sketch memory. In stead of

BLEUUID("ebe0ccb0-7a0a-4b0c-8a1a-6ff2997da3a6")

you can do

BLEUUID(0xebe0ccb0, 0x7a0a, 0x4b0c, 0x8a1a6ff2997da3a6)

thus trading 37 bytes of the string literal for 16 bytes uint literals, saving 21 bytes per UUID literal!

@@ -156,6 +156,24 @@ NimBLEUUID::NimBLEUUID(ble_uuid128_t* uuid) {
} // NimBLEUUID


/**
* @brief Create a UUID from the 128bit value using hex parts instead of string, so BLEUUID("ebe0ccb0-7a0a-4b0c-8a1a-6ff2997da3a6") becomes BLEUUID(0xebe0ccb0, 0x7a0a, 0x4b0c, 0x8a1a6ff2997da3a6)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we change this to:

 * @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)

for better presentation?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

@h2zero
Copy link
Owner

h2zero commented Apr 29, 2020

Looks good, just a couple minor things.

Could you change the title to: Add new NimBLEUUID constructor, solves #17

@Jeroen88 Jeroen88 changed the title Add new constructor, solves #17 Add new NimBLEUUID constructor, solves #17 Apr 29, 2020
@h2zero h2zero merged commit 63d3930 into h2zero:master Apr 29, 2020
@h2zero
Copy link
Owner

h2zero commented Apr 29, 2020

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants