From 98e963e1e340e7d612b98d4f74e370ac2bd710db Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Mon, 27 Jun 2022 23:27:57 -0300 Subject: [PATCH 1/5] Fixes BLE server Descriptor update --- libraries/BLE/src/BLE2902.cpp | 2 ++ libraries/BLE/src/BLEDescriptor.cpp | 12 ++++++++---- libraries/BLE/src/BLEDescriptor.h | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/libraries/BLE/src/BLE2902.cpp b/libraries/BLE/src/BLE2902.cpp index 0b695c268d6..880e73e2f79 100644 --- a/libraries/BLE/src/BLE2902.cpp +++ b/libraries/BLE/src/BLE2902.cpp @@ -46,6 +46,7 @@ void BLE2902::setIndications(bool flag) { uint8_t *pValue = getValue(); if (flag) pValue[0] |= 1 << 1; else pValue[0] &= ~(1 << 1); + setValue(pValue, 2); } // setIndications @@ -57,6 +58,7 @@ void BLE2902::setNotifications(bool flag) { uint8_t *pValue = getValue(); if (flag) pValue[0] |= 1 << 0; else pValue[0] &= ~(1 << 0); + setValue(pValue, 2); } // setNotifications #endif diff --git a/libraries/BLE/src/BLEDescriptor.cpp b/libraries/BLE/src/BLEDescriptor.cpp index ef96dbe73b4..85cce32f9ea 100644 --- a/libraries/BLE/src/BLEDescriptor.cpp +++ b/libraries/BLE/src/BLEDescriptor.cpp @@ -32,7 +32,7 @@ BLEDescriptor::BLEDescriptor(const char* uuid, uint16_t len) : BLEDescriptor(BLE BLEDescriptor::BLEDescriptor(BLEUUID uuid, uint16_t max_len) { m_bleUUID = uuid; m_value.attr_len = 0; // Initial length is 0. - m_value.attr_max_len = max_len; // Maximum length of the data. + m_value.attr_max_len = max_len; // Maximum length of the data. m_handle = NULL_HANDLE; // Handle is initially unknown. m_pCharacteristic = nullptr; // No initial characteristic. m_pCallback = nullptr; // No initial callback. @@ -185,9 +185,9 @@ void BLEDescriptor::handleGATTServerEvent( case ESP_GATTS_READ_EVT: { if (param->read.handle == m_handle) { // If this event is for this descriptor ... process it - if (m_pCallback != nullptr) { // If we have a user supplied callback, invoke it now. - m_pCallback->onRead(this); // Invoke the onRead callback method in the callback handler. - } + if (m_pCallback != nullptr) { // If we have a user supplied callback, invoke it now. + m_pCallback->onRead(this); // Invoke the onRead callback method in the callback handler. + } } // End of this is our handle break; @@ -235,6 +235,10 @@ void BLEDescriptor::setValue(uint8_t* data, size_t length) { } m_value.attr_len = length; memcpy(m_value.attr_value, data, length); + if (m_handle != NULL_HANDLE) { + esp_ble_gatts_set_attr_value(m_handle, length, (const uint8_t *)data); + log_d("Set the value in the GATTS database using handle 0x%x", m_handle); + } } // setValue diff --git a/libraries/BLE/src/BLEDescriptor.h b/libraries/BLE/src/BLEDescriptor.h index e3ccc57bdb9..7f6e0aa42a8 100644 --- a/libraries/BLE/src/BLEDescriptor.h +++ b/libraries/BLE/src/BLEDescriptor.h @@ -51,7 +51,7 @@ class BLEDescriptor { uint16_t m_handle; BLEDescriptorCallbacks* m_pCallback; BLECharacteristic* m_pCharacteristic; - esp_gatt_perm_t m_permissions = ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE; + esp_gatt_perm_t m_permissions = ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE; FreeRTOS::Semaphore m_semaphoreCreateEvt = FreeRTOS::Semaphore("CreateEvt"); esp_attr_value_t m_value; From db296e70b1919a60ad9312c63f937b41a8b3ceef Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Mon, 27 Jun 2022 23:36:18 -0300 Subject: [PATCH 2/5] indentation --- libraries/BLE/src/BLEDescriptor.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/BLE/src/BLEDescriptor.cpp b/libraries/BLE/src/BLEDescriptor.cpp index 85cce32f9ea..f9bd0626d4e 100644 --- a/libraries/BLE/src/BLEDescriptor.cpp +++ b/libraries/BLE/src/BLEDescriptor.cpp @@ -185,9 +185,9 @@ void BLEDescriptor::handleGATTServerEvent( case ESP_GATTS_READ_EVT: { if (param->read.handle == m_handle) { // If this event is for this descriptor ... process it - if (m_pCallback != nullptr) { // If we have a user supplied callback, invoke it now. - m_pCallback->onRead(this); // Invoke the onRead callback method in the callback handler. - } + if (m_pCallback != nullptr) { // If we have a user supplied callback, invoke it now. + m_pCallback->onRead(this); // Invoke the onRead callback method in the callback handler. + } } // End of this is our handle break; From d8cbe1f3d4728f1ae8fab553898730845a1e52e6 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Mon, 27 Jun 2022 23:37:10 -0300 Subject: [PATCH 3/5] indentation --- libraries/BLE/src/BLEDescriptor.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/BLE/src/BLEDescriptor.h b/libraries/BLE/src/BLEDescriptor.h index 7f6e0aa42a8..53516eb6b93 100644 --- a/libraries/BLE/src/BLEDescriptor.h +++ b/libraries/BLE/src/BLEDescriptor.h @@ -51,7 +51,7 @@ class BLEDescriptor { uint16_t m_handle; BLEDescriptorCallbacks* m_pCallback; BLECharacteristic* m_pCharacteristic; - esp_gatt_perm_t m_permissions = ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE; + esp_gatt_perm_t m_permissions = ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE; FreeRTOS::Semaphore m_semaphoreCreateEvt = FreeRTOS::Semaphore("CreateEvt"); esp_attr_value_t m_value; From 956ca6d47a50f1e797195958d641ef370add561b Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Mon, 27 Jun 2022 23:38:25 -0300 Subject: [PATCH 4/5] indentation --- libraries/BLE/src/BLEDescriptor.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/BLE/src/BLEDescriptor.h b/libraries/BLE/src/BLEDescriptor.h index 53516eb6b93..aafb43754b0 100644 --- a/libraries/BLE/src/BLEDescriptor.h +++ b/libraries/BLE/src/BLEDescriptor.h @@ -48,9 +48,9 @@ class BLEDescriptor { friend class BLEDescriptorMap; friend class BLECharacteristic; BLEUUID m_bleUUID; - uint16_t m_handle; - BLEDescriptorCallbacks* m_pCallback; - BLECharacteristic* m_pCharacteristic; + uint16_t m_handle; + BLEDescriptorCallbacks* m_pCallback; + BLECharacteristic* m_pCharacteristic; esp_gatt_perm_t m_permissions = ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE; FreeRTOS::Semaphore m_semaphoreCreateEvt = FreeRTOS::Semaphore("CreateEvt"); esp_attr_value_t m_value; From b44668d211d0f78d8b6b11f268aed359a4b5d933 Mon Sep 17 00:00:00 2001 From: Rodrigo Garcia Date: Mon, 27 Jun 2022 23:41:20 -0300 Subject: [PATCH 5/5] indentation --- libraries/BLE/src/BLEDescriptor.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/BLE/src/BLEDescriptor.h b/libraries/BLE/src/BLEDescriptor.h index aafb43754b0..cc501e85a2f 100644 --- a/libraries/BLE/src/BLEDescriptor.h +++ b/libraries/BLE/src/BLEDescriptor.h @@ -48,10 +48,10 @@ class BLEDescriptor { friend class BLEDescriptorMap; friend class BLECharacteristic; BLEUUID m_bleUUID; - uint16_t m_handle; - BLEDescriptorCallbacks* m_pCallback; - BLECharacteristic* m_pCharacteristic; - esp_gatt_perm_t m_permissions = ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE; + uint16_t m_handle; + BLEDescriptorCallbacks* m_pCallback; + BLECharacteristic* m_pCharacteristic; + esp_gatt_perm_t m_permissions = ESP_GATT_PERM_READ | ESP_GATT_PERM_WRITE; FreeRTOS::Semaphore m_semaphoreCreateEvt = FreeRTOS::Semaphore("CreateEvt"); esp_attr_value_t m_value;