Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yann/feature/ble/deep sleep in advertising data #1463

Merged
merged 2 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions libs/BLEKit/include/AdvertisingData.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct AdvertisingData {
uint8_t version_major {};
uint8_t version_minor {};
uint16_t version_revision {};
uint8_t is_deep_sleeping {};
Comment on lines 16 to +19
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
uint8_t version_major {};
uint8_t version_minor {};
uint16_t version_revision {};
uint8_t is_deep_sleeping {};
uint8_t is_deep_sleeping {};
uint8_t version_major {};
uint8_t version_minor {};
uint16_t version_revision {};


auto data()
{
Expand All @@ -28,15 +29,18 @@ struct AdvertisingData {
// private:
void updateValues()
{
_internal_values = {battery,
is_charging,
version_major,
version_minor,
static_cast<uint8_t>(version_revision >> 8),
static_cast<uint8_t>(version_revision)};
_internal_values = {
battery,
is_charging,
version_major,
version_minor,
static_cast<uint8_t>(version_revision >> 8),
static_cast<uint8_t>(version_revision),
is_deep_sleeping,
Comment on lines +32 to +39
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
_internal_values = {
battery,
is_charging,
version_major,
version_minor,
static_cast<uint8_t>(version_revision >> 8),
static_cast<uint8_t>(version_revision),
is_deep_sleeping,
_internal_values = {
battery,
is_charging,
is_deep_sleeping,
version_major,
version_minor,
static_cast<uint8_t>(version_revision >> 8),
static_cast<uint8_t>(version_revision),

};
}

std::array<uint8_t, 6> _internal_values = {};
std::array<uint8_t, 7> _internal_values = {};
};

} // namespace leka
2 changes: 2 additions & 0 deletions libs/BLEKit/tests/AdvertisingData_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -34,6 +35,7 @@ TEST(AdvertisingDataTest, data)
0x2D,
0x2E,
0x2F,
0x30,
});

auto actual_data_array = std::span {advertising_data.data(), advertising_data.size()};
Expand Down
13 changes: 9 additions & 4 deletions libs/BLEKit/tests/CoreGap_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint8_t>(default_advertising_data.version_revision >> 8),
static_cast<uint8_t>(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<uint8_t>(default_advertising_data.version_revision >> 8),
static_cast<uint8_t>(default_advertising_data.version_revision),
default_advertising_data.is_deep_sleeping,
}});

EXPECT_CALL(mbed_mock_gap,
setAdvertisingPayload(LEGACY_ADVERTISING_HANDLE, compareAdvertisingPayload(data_builder)))
Expand Down
4 changes: 4 additions & 0 deletions libs/RobotKit/include/RobotController.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }
Expand Down