13 static const char *
const TAG =
"esp32_ble";
18 ret.
uuid_.len = ESP_UUID_LEN_16;
19 ret.
uuid_.uuid.uuid16 = uuid;
24 ret.
uuid_.len = ESP_UUID_LEN_32;
25 ret.
uuid_.uuid.uuid32 = uuid;
30 ret.
uuid_.len = ESP_UUID_LEN_128;
31 memcpy(ret.
uuid_.uuid.uuid128, data, ESP_UUID_LEN_128);
36 ret.
uuid_.len = ESP_UUID_LEN_128;
37 for (uint8_t i = 0; i < ESP_UUID_LEN_128; i++)
38 ret.
uuid_.uuid.uuid128[ESP_UUID_LEN_128 - 1 - i] = data[i];
43 if (data.length() == 4) {
44 ret.
uuid_.len = ESP_UUID_LEN_16;
45 ret.
uuid_.uuid.uuid16 = 0;
46 for (uint i = 0; i < data.length(); i += 2) {
47 uint8_t msb = data.c_str()[i];
48 uint8_t lsb = data.c_str()[i + 1];
49 uint8_t lsb_shift = i <= 2 ? (2 - i) * 4 : 0;
55 ret.
uuid_.uuid.uuid16 += (((msb & 0x0F) << 4) | (lsb & 0x0F)) << lsb_shift;
57 }
else if (data.length() == 8) {
58 ret.
uuid_.len = ESP_UUID_LEN_32;
59 ret.
uuid_.uuid.uuid32 = 0;
60 for (uint i = 0; i < data.length(); i += 2) {
61 uint8_t msb = data.c_str()[i];
62 uint8_t lsb = data.c_str()[i + 1];
63 uint8_t lsb_shift = i <= 6 ? (6 - i) * 4 : 0;
69 ret.
uuid_.uuid.uuid32 += (((msb & 0x0F) << 4) | (lsb & 0x0F)) << lsb_shift;
71 }
else if (data.length() == 16) {
73 ret.
uuid_.len = ESP_UUID_LEN_128;
74 memcpy(ret.
uuid_.uuid.uuid128, (uint8_t *) data.data(), 16);
75 }
else if (data.length() == 36) {
78 ret.
uuid_.len = ESP_UUID_LEN_128;
80 for (uint i = 0; i < data.length(); i += 2) {
81 if (data.c_str()[i] ==
'-')
83 uint8_t msb = data.c_str()[i];
84 uint8_t lsb = data.c_str()[i + 1];
90 ret.
uuid_.uuid.uuid128[15 - n++] = ((msb & 0x0F) << 4) | (lsb & 0x0F);
93 ESP_LOGE(TAG,
"ERROR: UUID value not 2, 4, 16 or 36 bytes - %s", data.c_str());
99 ret.
uuid_.len = uuid.len;
100 if (uuid.len == ESP_UUID_LEN_16) {
101 ret.
uuid_.uuid.uuid16 = uuid.uuid.uuid16;
102 }
else if (uuid.len == ESP_UUID_LEN_32) {
103 ret.
uuid_.uuid.uuid32 = uuid.uuid.uuid32;
104 }
else if (uuid.len == ESP_UUID_LEN_128) {
105 memcpy(ret.
uuid_.uuid.uuid128, uuid.uuid.uuid128, ESP_UUID_LEN_128);
110 if (this->
uuid_.len == ESP_UUID_LEN_128) {
113 uint8_t data[] = {0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
115 if (this->
uuid_.len == ESP_UUID_LEN_32) {
116 uuid32 = this->
uuid_.uuid.uuid32;
118 uuid32 = this->
uuid_.uuid.uuid16;
120 for (uint8_t i = 0; i < this->
uuid_.len; i++) {
121 data[12 + i] = ((uuid32 >> i * 8) & 0xFF);
126 if (this->
uuid_.len == ESP_UUID_LEN_16) {
127 return (this->
uuid_.uuid.uuid16 >> 8) == data2 && (this->
uuid_.uuid.uuid16 & 0xFF) == data1;
128 }
else if (this->
uuid_.len == ESP_UUID_LEN_32) {
129 for (uint8_t i = 0; i < 3; i++) {
130 bool a = ((this->
uuid_.uuid.uuid32 >> i * 8) & 0xFF) == data1;
131 bool b = ((this->
uuid_.uuid.uuid32 >> (i + 1) * 8) & 0xFF) == data2;
136 for (uint8_t i = 0; i < 15; i++) {
137 if (this->
uuid_.uuid.uuid128[i] == data1 && this->uuid_.uuid.uuid128[i + 1] == data2)
145 switch (this->
uuid_.len) {
146 case ESP_UUID_LEN_16:
147 if (uuid.
uuid_.uuid.uuid16 == this->uuid_.uuid.uuid16) {
151 case ESP_UUID_LEN_32:
152 if (uuid.
uuid_.uuid.uuid32 == this->uuid_.uuid.uuid32) {
156 case ESP_UUID_LEN_128:
157 for (uint8_t i = 0; i < ESP_UUID_LEN_128; i++) {
158 if (uuid.
uuid_.uuid.uuid128[i] != this->uuid_.uuid.uuid128[i]) {
172 switch (this->
uuid_.len) {
173 case ESP_UUID_LEN_16:
174 return str_snprintf(
"0x%02X%02X", 6, this->
uuid_.uuid.uuid16 >> 8, this->uuid_.uuid.uuid16 & 0xff);
175 case ESP_UUID_LEN_32:
176 return str_snprintf(
"0x%02" PRIX32
"%02" PRIX32
"%02" PRIX32
"%02" PRIX32, 10, (this->
uuid_.uuid.uuid32 >> 24),
177 (this->uuid_.uuid.uuid32 >> 16 & 0xff), (this->uuid_.uuid.uuid32 >> 8 & 0xff),
178 this->uuid_.uuid.uuid32 & 0xff);
180 case ESP_UUID_LEN_128:
182 for (int8_t i = 15; i >= 0; i--) {
184 if (i == 6 || i == 8 || i == 10 || i == 12)
bool operator==(const ESPBTUUID &uuid) const
static ESPBTUUID from_uuid(esp_bt_uuid_t uuid)
static ESPBTUUID from_uint32(uint32_t uuid)
static ESPBTUUID from_uint16(uint16_t uuid)
std::string to_string() const
bool contains(uint8_t data1, uint8_t data2) const
Implementation of SPI Controller mode.
static ESPBTUUID from_raw(const uint8_t *data)
ESPBTUUID as_128bit() const
std::string str_snprintf(const char *fmt, size_t len,...)
static ESPBTUUID from_raw_reversed(const uint8_t *data)
esp_bt_uuid_t get_uuid() const