mirror of
https://github.com/esphome/esphome.git
synced 2024-12-10 14:45:56 +01:00
parent
e6c730ab10
commit
8439232b11
@ -34,7 +34,7 @@ ESPBTUUID ESPBTUUID::from_raw(const uint8_t *data) {
|
|||||||
ESPBTUUID ESPBTUUID::from_raw_reversed(const uint8_t *data) {
|
ESPBTUUID ESPBTUUID::from_raw_reversed(const uint8_t *data) {
|
||||||
ESPBTUUID ret;
|
ESPBTUUID ret;
|
||||||
ret.uuid_.len = ESP_UUID_LEN_128;
|
ret.uuid_.len = ESP_UUID_LEN_128;
|
||||||
for (int i = 0; i < ESP_UUID_LEN_128; i++)
|
for (uint8_t i = 0; i < ESP_UUID_LEN_128; i++)
|
||||||
ret.uuid_.uuid.uuid128[ESP_UUID_LEN_128 - 1 - i] = data[i];
|
ret.uuid_.uuid.uuid128[ESP_UUID_LEN_128 - 1 - i] = data[i];
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -43,30 +43,30 @@ ESPBTUUID ESPBTUUID::from_raw(const std::string &data) {
|
|||||||
if (data.length() == 4) {
|
if (data.length() == 4) {
|
||||||
ret.uuid_.len = ESP_UUID_LEN_16;
|
ret.uuid_.len = ESP_UUID_LEN_16;
|
||||||
ret.uuid_.uuid.uuid16 = 0;
|
ret.uuid_.uuid.uuid16 = 0;
|
||||||
for (int i = 0; i < data.length();) {
|
for (uint i = 0; i < data.length(); i += 2) {
|
||||||
uint8_t msb = data.c_str()[i];
|
uint8_t msb = data.c_str()[i];
|
||||||
uint8_t lsb = data.c_str()[i + 1];
|
uint8_t lsb = data.c_str()[i + 1];
|
||||||
|
uint8_t lsb_shift = i <= 2 ? (2 - i) * 4 : 0;
|
||||||
|
|
||||||
if (msb > '9')
|
if (msb > '9')
|
||||||
msb -= 7;
|
msb -= 7;
|
||||||
if (lsb > '9')
|
if (lsb > '9')
|
||||||
lsb -= 7;
|
lsb -= 7;
|
||||||
ret.uuid_.uuid.uuid16 += (((msb & 0x0F) << 4) | (lsb & 0x0F)) << (2 - i) * 4;
|
ret.uuid_.uuid.uuid16 += (((msb & 0x0F) << 4) | (lsb & 0x0F)) << lsb_shift;
|
||||||
i += 2;
|
|
||||||
}
|
}
|
||||||
} else if (data.length() == 8) {
|
} else if (data.length() == 8) {
|
||||||
ret.uuid_.len = ESP_UUID_LEN_32;
|
ret.uuid_.len = ESP_UUID_LEN_32;
|
||||||
ret.uuid_.uuid.uuid32 = 0;
|
ret.uuid_.uuid.uuid32 = 0;
|
||||||
for (int i = 0; i < data.length();) {
|
for (uint i = 0; i < data.length(); i += 2) {
|
||||||
uint8_t msb = data.c_str()[i];
|
uint8_t msb = data.c_str()[i];
|
||||||
uint8_t lsb = data.c_str()[i + 1];
|
uint8_t lsb = data.c_str()[i + 1];
|
||||||
|
uint8_t lsb_shift = i <= 6 ? (6 - i) * 4 : 0;
|
||||||
|
|
||||||
if (msb > '9')
|
if (msb > '9')
|
||||||
msb -= 7;
|
msb -= 7;
|
||||||
if (lsb > '9')
|
if (lsb > '9')
|
||||||
lsb -= 7;
|
lsb -= 7;
|
||||||
ret.uuid_.uuid.uuid32 += (((msb & 0x0F) << 4) | (lsb & 0x0F)) << (6 - i) * 4;
|
ret.uuid_.uuid.uuid32 += (((msb & 0x0F) << 4) | (lsb & 0x0F)) << lsb_shift;
|
||||||
i += 2;
|
|
||||||
}
|
}
|
||||||
} else if (data.length() == 16) { // how we can have 16 byte length string reprezenting 128 bit uuid??? needs to be
|
} else if (data.length() == 16) { // how we can have 16 byte length string reprezenting 128 bit uuid??? needs to be
|
||||||
// investigated (lack of time)
|
// investigated (lack of time)
|
||||||
@ -77,7 +77,7 @@ ESPBTUUID ESPBTUUID::from_raw(const std::string &data) {
|
|||||||
// UUID format.
|
// UUID format.
|
||||||
ret.uuid_.len = ESP_UUID_LEN_128;
|
ret.uuid_.len = ESP_UUID_LEN_128;
|
||||||
int n = 0;
|
int n = 0;
|
||||||
for (int i = 0; i < data.length();) {
|
for (uint i = 0; i < data.length(); i += 2) {
|
||||||
if (data.c_str()[i] == '-')
|
if (data.c_str()[i] == '-')
|
||||||
i++;
|
i++;
|
||||||
uint8_t msb = data.c_str()[i];
|
uint8_t msb = data.c_str()[i];
|
||||||
@ -88,7 +88,6 @@ ESPBTUUID ESPBTUUID::from_raw(const std::string &data) {
|
|||||||
if (lsb > '9')
|
if (lsb > '9')
|
||||||
lsb -= 7;
|
lsb -= 7;
|
||||||
ret.uuid_.uuid.uuid128[15 - n++] = ((msb & 0x0F) << 4) | (lsb & 0x0F);
|
ret.uuid_.uuid.uuid128[15 - n++] = ((msb & 0x0F) << 4) | (lsb & 0x0F);
|
||||||
i += 2;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGE(TAG, "ERROR: UUID value not 2, 4, 16 or 36 bytes - %s", data.c_str());
|
ESP_LOGE(TAG, "ERROR: UUID value not 2, 4, 16 or 36 bytes - %s", data.c_str());
|
||||||
@ -155,7 +154,7 @@ bool ESPBTUUID::operator==(const ESPBTUUID &uuid) const {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ESP_UUID_LEN_128:
|
case ESP_UUID_LEN_128:
|
||||||
for (int i = 0; i < ESP_UUID_LEN_128; i++) {
|
for (uint8_t i = 0; i < ESP_UUID_LEN_128; i++) {
|
||||||
if (uuid.uuid_.uuid.uuid128[i] != this->uuid_.uuid.uuid128[i]) {
|
if (uuid.uuid_.uuid.uuid128[i] != this->uuid_.uuid.uuid128[i]) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -432,7 +432,7 @@ void ESPBTDevice::parse_scan_rst(const esp_ble_gap_cb_param_t::ble_scan_result_e
|
|||||||
|
|
||||||
#ifdef ESPHOME_LOG_HAS_VERY_VERBOSE
|
#ifdef ESPHOME_LOG_HAS_VERY_VERBOSE
|
||||||
ESP_LOGVV(TAG, "Parse Result:");
|
ESP_LOGVV(TAG, "Parse Result:");
|
||||||
const char *address_type = "";
|
const char *address_type;
|
||||||
switch (this->address_type_) {
|
switch (this->address_type_) {
|
||||||
case BLE_ADDR_TYPE_PUBLIC:
|
case BLE_ADDR_TYPE_PUBLIC:
|
||||||
address_type = "PUBLIC";
|
address_type = "PUBLIC";
|
||||||
@ -446,6 +446,9 @@ void ESPBTDevice::parse_scan_rst(const esp_ble_gap_cb_param_t::ble_scan_result_e
|
|||||||
case BLE_ADDR_TYPE_RPA_RANDOM:
|
case BLE_ADDR_TYPE_RPA_RANDOM:
|
||||||
address_type = "RPA_RANDOM";
|
address_type = "RPA_RANDOM";
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
address_type = "UNKNOWN";
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
ESP_LOGVV(TAG, " Address: %02X:%02X:%02X:%02X:%02X:%02X (%s)", this->address_[0], this->address_[1],
|
ESP_LOGVV(TAG, " Address: %02X:%02X:%02X:%02X:%02X:%02X (%s)", this->address_[0], this->address_[1],
|
||||||
this->address_[2], this->address_[3], this->address_[4], this->address_[5], address_type);
|
this->address_[2], this->address_[3], this->address_[4], this->address_[5], address_type);
|
||||||
|
Loading…
Reference in New Issue
Block a user