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 (
int 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 (
int i = 0; i < data.length();) {
47 uint8_t msb = data.c_str()[i];
48 uint8_t lsb = data.c_str()[i + 1];
54 ret.
uuid_.uuid.uuid16 += (((msb & 0x0F) << 4) | (lsb & 0x0F)) << (2 - i) * 4;
57 }
else if (data.length() == 8) {
58 ret.
uuid_.len = ESP_UUID_LEN_32;
59 ret.
uuid_.uuid.uuid32 = 0;
60 for (
int i = 0; i < data.length();) {
61 uint8_t msb = data.c_str()[i];
62 uint8_t lsb = data.c_str()[i + 1];
68 ret.
uuid_.uuid.uuid32 += (((msb & 0x0F) << 4) | (lsb & 0x0F)) << (6 - i) * 4;
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 (
int i = 0; i < data.length();) {
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);
94 ESP_LOGE(TAG,
"ERROR: UUID value not 2, 4, 16 or 36 bytes - %s", data.c_str());
100 ret.
uuid_.len = uuid.len;
101 if (uuid.len == ESP_UUID_LEN_16) {
102 ret.
uuid_.uuid.uuid16 = uuid.uuid.uuid16;
103 }
else if (uuid.len == ESP_UUID_LEN_32) {
104 ret.
uuid_.uuid.uuid32 = uuid.uuid.uuid32;
105 }
else if (uuid.len == ESP_UUID_LEN_128) {
106 memcpy(ret.
uuid_.uuid.uuid128, uuid.uuid.uuid128, ESP_UUID_LEN_128);
111 if (this->
uuid_.len == ESP_UUID_LEN_128) {
114 uint8_t data[] = {0xFB, 0x34, 0x9B, 0x5F, 0x80, 0x00, 0x00, 0x80, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
116 if (this->
uuid_.len == ESP_UUID_LEN_32) {
117 uuid32 = this->
uuid_.uuid.uuid32;
119 uuid32 = this->
uuid_.uuid.uuid16;
121 for (uint8_t i = 0; i < this->
uuid_.len; i++) {
122 data[12 + i] = ((uuid32 >> i * 8) & 0xFF);
127 if (this->
uuid_.len == ESP_UUID_LEN_16) {
128 return (this->
uuid_.uuid.uuid16 >> 8) == data2 && (this->
uuid_.uuid.uuid16 & 0xFF) == data1;
129 }
else if (this->
uuid_.len == ESP_UUID_LEN_32) {
130 for (uint8_t i = 0; i < 3; i++) {
131 bool a = ((this->
uuid_.uuid.uuid32 >> i * 8) & 0xFF) == data1;
132 bool b = ((this->
uuid_.uuid.uuid32 >> (i + 1) * 8) & 0xFF) == data2;
137 for (uint8_t i = 0; i < 15; i++) {
138 if (this->
uuid_.uuid.uuid128[i] == data1 && this->uuid_.uuid.uuid128[i + 1] == data2)
146 switch (this->
uuid_.len) {
147 case ESP_UUID_LEN_16:
148 if (uuid.
uuid_.uuid.uuid16 == this->uuid_.uuid.uuid16) {
152 case ESP_UUID_LEN_32:
153 if (uuid.
uuid_.uuid.uuid32 == this->uuid_.uuid.uuid32) {
157 case ESP_UUID_LEN_128:
158 for (
int i = 0; i < ESP_UUID_LEN_128; i++) {
159 if (uuid.
uuid_.uuid.uuid128[i] != this->uuid_.uuid.uuid128[i]) {
173 switch (this->
uuid_.len) {
174 case ESP_UUID_LEN_16:
175 return str_snprintf(
"0x%02X%02X", 6, this->
uuid_.uuid.uuid16 >> 8, this->uuid_.uuid.uuid16 & 0xff);
176 case ESP_UUID_LEN_32:
177 return str_snprintf(
"0x%02" PRIX32
"%02" PRIX32
"%02" PRIX32
"%02" PRIX32, 10, (this->
uuid_.uuid.uuid32 >> 24),
178 (this->uuid_.uuid.uuid32 >> 16 & 0xff), (this->uuid_.uuid.uuid32 >> 8 & 0xff),
179 this->uuid_.uuid.uuid32 & 0xff);
181 case ESP_UUID_LEN_128:
183 for (int8_t i = 15; i >= 0; i--) {
185 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