Skip to content

Conversation

@tanakamasayuki
Copy link
Contributor

uuid16 is Missing first 4 characters.
uuid is Missing last 2 characters.

UUID string format: AABBCCDD-EEFF-GGHH-IIJJ-KKLLMMNNOOPP 123456789012345678901234567890123456 < 36 characters + null 

Test code

#include"BLEDevice.h"voidsetup(){Serial.begin(115200); delay(1000); BLEUUIDuuid("00001812-0000-1000-8000-00805F9B34FB"); Serial.printf("uuid : %s\n", uuid.toString().c_str()); BLEUUIDuuid16("1812"); Serial.printf("uuid16 : %s\n", uuid16.toString().c_str()); BLEUUIDuuid16_2(uuid16.toString().c_str()); Serial.printf("uuid16_2 : %s\n", uuid16_2.toString().c_str()); BLEUUIDuuid32("00001812"); Serial.printf("uuid32 : %s\n", uuid32.toString().c_str())} voidloop(){}

1.0.3 Run

uuid : 00001812-0000-1000-8000-00805f9b34 uuid16 : 1812-0000-1000-8000-00805f9b34fb uuid16_2 : <NULL> uuid32 : 00001812-0000-1000-8000-00805f9b34fb 

uuid -> Missing last 2 characters
uuid16 -> Missing first 4 characters
uuid32 -> Good

This patch

uuid : 00001812-0000-1000-8000-00805f9b34fb uuid16 : 00001812-0000-1000-8000-00805f9b34fb uuid16_2 : 00001812-0000-1000-8000-00805f9b34fb uuid32 : 00001812-0000-1000-8000-00805f9b34fb 

uuid16 is Missing first 4 characters. uuid is Missing last 2 characters.
@me-no-dev
Copy link
Member

what is the purpose of those 4 leading zeroes? I have never seen them printed or discussed before.

@tanakamasayuki
Copy link
ContributorAuthor

The UUID format is specified.

https://en.wikipedia.org/wiki/Universally_unique_identifier

123e4567-e89b-12d3-a456-426655440000 xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx 

in the form 8-4-4-4-12 for a total of 36 characters (32 alphanumeric characters and 4 hyphens).

https://www.bluetooth.com/specifications/assigned-numbers/service-discovery/

BASE_UUID | 00000000-0000-1000-8000-00805F9B34FB 

/libraries/BLE/src/BLEUUID.cpp

/** * @brief 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. * * @param [in] value The string to build a UUID from. */BLEUUID::BLEUUID(std::stringvalue){m_valueSet= true; if (value.length() ==4){m_uuid.len=ESP_UUID_LEN_16; m_uuid.uuid.uuid16=0; for(inti=0;i<value.length();){uint8_tMSB=value.c_str()[i]; uint8_tLSB=value.c_str()[i+1]; if(MSB>'9') MSB-=7; if(LSB>'9') LSB-=7; m_uuid.uuid.uuid16+= (((MSB&0x0F) <<4) | (LSB&0x0F))<<(2-i)*4; i+=2} } elseif (value.length() ==8){m_uuid.len=ESP_UUID_LEN_32; m_uuid.uuid.uuid32=0; for(inti=0;i<value.length();){uint8_tMSB=value.c_str()[i]; uint8_tLSB=value.c_str()[i+1]; if(MSB>'9') MSB-=7; if(LSB>'9') LSB-=7; m_uuid.uuid.uuid32+= (((MSB&0x0F) <<4) | (LSB&0x0F))<<(6-i)*4; i+=2} } elseif (value.length() ==16){// how we can have 16 byte length string reprezenting 128 bit uuid??? needs to be investigated (lack of time)m_uuid.len=ESP_UUID_LEN_128; memrcpy(m_uuid.uuid.uuid128, (uint8_t*)value.data(), 16)} elseif (value.length() ==36){// If the length of the string is 36 bytes then we will assume it is a long hex string in// UUID format.m_uuid.len=ESP_UUID_LEN_128; intn=0; for(inti=0;i<value.length();){if(value.c_str()[i] =='-') i++; uint8_tMSB=value.c_str()[i]; uint8_tLSB=value.c_str()[i+1]; if(MSB>'9') MSB-=7; if(LSB>'9') LSB-=7; m_uuid.uuid.uuid128[15-n++] = ((MSB&0x0F) <<4) | (LSB&0x0F); i+=2} } else{log_e("ERROR: UUID value not 2, 4, 16 or 36 bytes"); m_valueSet= false} } //BLEUUID(std::string)
*Thishasalengthof36characters. Weneedtoparsethisinto16bytes.
elseif (value.length() ==36){

If it is 32 characters, an input error occurs.

@me-no-devme-no-dev merged commit 71e3d51 into espressif:masterOct 1, 2019
Sign up for freeto 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

@tanakamasayuki@me-no-dev