Skip to content

Commit

Permalink
🔀️ Merge branch 'yann/feature/ble/reorganize-adv-data' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
ladislas committed Aug 27, 2024
2 parents e1a764d + fed30ad commit cdd6946
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 46 deletions.
15 changes: 4 additions & 11 deletions libs/BLEKit/include/AdvertisingData.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ namespace leka {

struct AdvertisingData {
const char *name = "Leka"; // TODO: Get default name from configuration files
uint8_t battery {};
uint8_t is_charging {};
uint8_t version_major {};
uint8_t version_minor {};
uint16_t version_revision {};
uint8_t battery {};
uint8_t is_charging {};
uint8_t is_deep_sleeping {};

auto data()
Expand All @@ -30,17 +29,11 @@ struct AdvertisingData {
void updateValues()
{
_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,
version_major, version_minor, battery, is_charging, is_deep_sleeping,
};
}

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

} // namespace leka
23 changes: 10 additions & 13 deletions libs/BLEKit/tests/AdvertisingData_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,19 @@ TEST(AdvertisingDataTest, initialisation)
TEST(AdvertisingDataTest, data)
{
auto advertising_data = AdvertisingData {
.battery = 0x2A,
.is_charging = 0x2B,
.version_major = 0x2C,
.version_minor = 0x2D,
.version_revision = 0x2E2F,
.is_deep_sleeping = 0x30,
.version_major = 0x3A,
.version_minor = 0x3B,
.battery = 0x3C,
.is_charging = 0x3D,
.is_deep_sleeping = 0x3E,
};

auto expected_data_array = std::to_array({
0x2A,
0x2B,
0x2C,
0x2D,
0x2E,
0x2F,
0x30,
0x3A,
0x3B,
0x3C,
0x3D,
0x3E,
});

auto actual_data_array = std::span {advertising_data.data(), advertising_data.size()};
Expand Down
17 changes: 7 additions & 10 deletions libs/BLEKit/tests/CoreGap_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,13 @@ TEST_F(CoreGapTest, defaultAdvertisingPayload)
auto default_advertising_data = AdvertisingData {};

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.is_deep_sleeping,
}});
data_builder.setServiceData(service::commands::uuid, {{
default_advertising_data.version_major,
default_advertising_data.version_minor,
default_advertising_data.battery,
default_advertising_data.is_charging,
default_advertising_data.is_deep_sleeping,
}});

EXPECT_CALL(mbed_mock_gap,
setAdvertisingPayload(LEGACY_ADVERTISING_HANDLE, compareAdvertisingPayload(data_builder)))
Expand Down
9 changes: 4 additions & 5 deletions libs/RobotKit/include/RobotController.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,10 @@ class RobotController : public interface::RobotController

_service_config.setRobotName(_robot_name);

auto advertising_data = _ble.getAdvertisingData();
advertising_data.name = reinterpret_cast<const char *>(_robot_name.data());
advertising_data.version_major = _os_version.major;
advertising_data.version_minor = _os_version.minor;
advertising_data.version_revision = _os_version.revision;
auto advertising_data = _ble.getAdvertisingData();
advertising_data.name = reinterpret_cast<const char *>(_robot_name.data());
advertising_data.version_major = _os_version.major;
advertising_data.version_minor = _os_version.minor;

_ble.setAdvertisingData(advertising_data);

Expand Down
13 changes: 6 additions & 7 deletions spikes/lk_ble/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,12 @@ auto main() -> int
auto version = service_update.getVersion();
log_info("Requested version: %d.%d.%d", version.major, version.minor, version.revision);

auto advertising_data = blekit.getAdvertisingData();
advertising_data.name = "NewLeka";
advertising_data.battery = level;
advertising_data.is_charging = charging_status;
advertising_data.version_major = uint8_t {0x01};
advertising_data.version_minor = uint8_t {0x02};
advertising_data.version_revision = uint16_t {0x0304};
auto advertising_data = blekit.getAdvertisingData();
advertising_data.name = "NewLeka";
advertising_data.battery = level;
advertising_data.is_charging = charging_status;
advertising_data.version_major = uint8_t {0x01};
advertising_data.version_minor = uint8_t {0x02};

blekit.setAdvertisingData(advertising_data);
}
Expand Down

0 comments on commit cdd6946

Please sign in to comment.