From 9a5a166d0f7b3fd3b64feb708ef12debfd3a1c7c Mon Sep 17 00:00:00 2001 From: Yann Locatelli Date: Mon, 19 Aug 2024 17:22:46 +0200 Subject: [PATCH 1/2] =?UTF-8?q?=E2=9C=A8=20(BLEKit):=20Add=20is=5Fdeep=5Fs?= =?UTF-8?q?leeping=20in=20advertising=20data?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/BLEKit/include/AdvertisingData.h | 18 +++++++++++------- libs/BLEKit/tests/AdvertisingData_test.cpp | 2 ++ libs/BLEKit/tests/CoreGap_test.cpp | 13 +++++++++---- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/libs/BLEKit/include/AdvertisingData.h b/libs/BLEKit/include/AdvertisingData.h index 89add21612..330ad5c0e7 100644 --- a/libs/BLEKit/include/AdvertisingData.h +++ b/libs/BLEKit/include/AdvertisingData.h @@ -16,6 +16,7 @@ struct AdvertisingData { uint8_t version_major {}; uint8_t version_minor {}; uint16_t version_revision {}; + uint8_t is_deep_sleeping {}; auto data() { @@ -28,15 +29,18 @@ struct AdvertisingData { // private: void updateValues() { - _internal_values = {battery, - is_charging, - version_major, - version_minor, - static_cast(version_revision >> 8), - static_cast(version_revision)}; + _internal_values = { + battery, + is_charging, + version_major, + version_minor, + static_cast(version_revision >> 8), + static_cast(version_revision), + is_deep_sleeping, + }; } - std::array _internal_values = {}; + std::array _internal_values = {}; }; } // namespace leka diff --git a/libs/BLEKit/tests/AdvertisingData_test.cpp b/libs/BLEKit/tests/AdvertisingData_test.cpp index 31a260bc6e..641ad34c57 100644 --- a/libs/BLEKit/tests/AdvertisingData_test.cpp +++ b/libs/BLEKit/tests/AdvertisingData_test.cpp @@ -25,6 +25,7 @@ TEST(AdvertisingDataTest, data) .version_major = 0x2C, .version_minor = 0x2D, .version_revision = 0x2E2F, + .is_deep_sleeping = 0x30, }; auto expected_data_array = std::to_array({ @@ -34,6 +35,7 @@ TEST(AdvertisingDataTest, data) 0x2D, 0x2E, 0x2F, + 0x30, }); auto actual_data_array = std::span {advertising_data.data(), advertising_data.size()}; diff --git a/libs/BLEKit/tests/CoreGap_test.cpp b/libs/BLEKit/tests/CoreGap_test.cpp index ec6aca7e1f..33ba464159 100644 --- a/libs/BLEKit/tests/CoreGap_test.cpp +++ b/libs/BLEKit/tests/CoreGap_test.cpp @@ -104,10 +104,15 @@ TEST_F(CoreGapTest, defaultAdvertisingPayload) data_builder.setName(default_advertising_data.name); data_builder.setServiceData(service::commands::uuid, - {{default_advertising_data.battery, default_advertising_data.is_charging, - default_advertising_data.version_major, default_advertising_data.version_minor, - static_cast(default_advertising_data.version_revision >> 8), - static_cast(default_advertising_data.version_revision)}}); + {{ + default_advertising_data.battery, + default_advertising_data.is_charging, + default_advertising_data.version_major, + default_advertising_data.version_minor, + static_cast(default_advertising_data.version_revision >> 8), + static_cast(default_advertising_data.version_revision), + default_advertising_data.is_deep_sleeping, + }}); EXPECT_CALL(mbed_mock_gap, setAdvertisingPayload(LEGACY_ADVERTISING_HANDLE, compareAdvertisingPayload(data_builder))) From fffd3ca60f11bae8d14d08c0a5424a687d92bcaf Mon Sep 17 00:00:00 2001 From: Yann Locatelli Date: Mon, 19 Aug 2024 17:26:37 +0200 Subject: [PATCH 2/2] =?UTF-8?q?=E2=9C=A8=20(RobotController):=20Set=20is?= =?UTF-8?q?=5Fdeep=5Fsleeping=20on=20DeepSleep=20enter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libs/RobotKit/include/RobotController.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libs/RobotKit/include/RobotController.h b/libs/RobotKit/include/RobotController.h index 129bf28b0f..d083a226ed 100644 --- a/libs/RobotKit/include/RobotController.h +++ b/libs/RobotKit/include/RobotController.h @@ -315,6 +315,10 @@ class RobotController : public interface::RobotController component->enableDeepSleep(); } _ble.disconnect(); + + auto advertising_data = _ble.getAdvertisingData(); + advertising_data.is_deep_sleeping = true; + _ble.setAdvertisingData(advertising_data); } void wakeUp() final { system_reset(); }