1
0
mirror of https://github.com/esphome/esphome.git synced 2025-11-18 15:55:46 +00:00

Make parse_characteristics and parse_descriptors lazy to reduce memory pressure (#4063)

This commit is contained in:
J. Nick Koston
2022-11-27 14:28:02 -10:00
committed by GitHub
parent c5f59fad62
commit 53e0af18fb
6 changed files with 30 additions and 2 deletions

View File

@@ -135,6 +135,7 @@ bool BLEClientBase::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_
for (auto &svc : this->services_)
delete svc; // NOLINT(cppcoreguidelines-owning-memory)
this->services_.clear();
esp_ble_gattc_cache_clean(this->remote_bda_);
this->set_state(espbt::ClientState::IDLE);
break;
}
@@ -154,7 +155,6 @@ bool BLEClientBase::gattc_event_handler(esp_gattc_cb_event_t event, esp_gatt_if_
svc->uuid.to_string().c_str());
ESP_LOGI(TAG, "[%d] [%s] start_handle: 0x%x end_handle: 0x%x", this->connection_index_,
this->address_str_.c_str(), svc->start_handle, svc->end_handle);
svc->parse_characteristics();
}
this->set_state(espbt::ClientState::CONNECTED);
this->state_ = espbt::ClientState::ESTABLISHED;
@@ -287,6 +287,8 @@ BLECharacteristic *BLEClientBase::get_characteristic(uint16_t service, uint16_t
BLECharacteristic *BLEClientBase::get_characteristic(uint16_t handle) {
for (auto *svc : this->services_) {
if (!svc->parsed)
svc->parse_characteristics();
for (auto *chr : svc->characteristics) {
if (chr->handle == handle)
return chr;
@@ -298,6 +300,8 @@ BLECharacteristic *BLEClientBase::get_characteristic(uint16_t handle) {
BLEDescriptor *BLEClientBase::get_config_descriptor(uint16_t handle) {
auto *chr = this->get_characteristic(handle);
if (chr != nullptr) {
if (!chr->parsed)
chr->parse_descriptors();
for (auto &desc : chr->descriptors) {
if (desc->uuid.get_uuid().uuid.uuid16 == 0x2902)
return desc;
@@ -323,7 +327,11 @@ BLEDescriptor *BLEClientBase::get_descriptor(uint16_t service, uint16_t chr, uin
BLEDescriptor *BLEClientBase::get_descriptor(uint16_t handle) {
for (auto *svc : this->services_) {
if (!svc->parsed)
svc->parse_characteristics();
for (auto *chr : svc->characteristics) {
if (!chr->parsed)
chr->parse_descriptors();
for (auto *desc : chr->descriptors) {
if (desc->handle == handle)
return desc;