Skip to content

Commit

Permalink
🚧 Apply suggestion from sonardcloud
Browse files Browse the repository at this point in the history
  • Loading branch information
YannLocatelli committed Apr 11, 2022
1 parent 238af47 commit 0f7c662
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 30 deletions.
21 changes: 10 additions & 11 deletions libs/BLEKit/include/AdvertisingData.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@
namespace leka {

struct AdvertisingData {
const char *name = "Leka"; // TODO: Get default name from configuration files
uint8_t battery = 0;
uint8_t is_charging = 0;
uint8_t led_red = 0;
uint8_t led_green = 0;
uint8_t led_blue = 0;
const char *name = "Leka"; // TODO: Get default name from configuration files
uint8_t battery {};
uint8_t is_charging {};
uint8_t led_red {};
uint8_t led_green {};
uint8_t led_blue {};

static inline int _advertising_data_size = 5;
std::array<uint8_t, 16> data {};

auto getData() -> std::span<const uint8_t>
{
Expand All @@ -25,11 +28,7 @@ struct AdvertisingData {
return std::span<uint8_t> {data.data(), std::size(tmp)};
}

auto getDataSize() -> int { return _advertising_data_size; }

private:
static constexpr int _advertising_data_size = 5;
std::array<uint8_t, 16> data {};
[[nodiscard]] auto getDataSize() const -> int { return _advertising_data_size; }
};

} // namespace leka
4 changes: 2 additions & 2 deletions libs/BLEKit/include/BLEKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class BLEKit

void init();

void setAdvertisingData(AdvertisingData &advertising_data);
auto getAdvertisingData() -> AdvertisingData;
void setAdvertisingData(const AdvertisingData &advertising_data);
[[nodiscard]] auto getAdvertisingData() const -> AdvertisingData;

private:
// ? mbed::BLE specific function
Expand Down
4 changes: 2 additions & 2 deletions libs/BLEKit/source/BLEKit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ void BLEKit::processEvents(BLE::OnEventsToProcessCallbackContext *context)
_event_queue.callMbedCallback(mbed::callback(&context->ble, &BLE::processEvents));
}

void BLEKit::setAdvertisingData(AdvertisingData &advertising_data)
void BLEKit::setAdvertisingData(const AdvertisingData &advertising_data)
{
_advertising_data = advertising_data;

_core_gap.refreshAdvertising(_advertising_data);
}

auto BLEKit::getAdvertisingData() -> AdvertisingData
auto BLEKit::getAdvertisingData() const -> AdvertisingData
{
return _advertising_data;
}
9 changes: 2 additions & 7 deletions libs/BLEKit/tests/AdvertisingData_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,8 @@ TEST(AdvertisingDataTest, initialisation)

TEST(AdvertisingDataTest, getData)
{
auto advertising_data = AdvertisingData {};

advertising_data.battery = 0x2A;
advertising_data.is_charging = 0x2B;
advertising_data.led_red = 0x2C;
advertising_data.led_green = 0x2D;
advertising_data.led_blue = 0x2E;
auto advertising_data =
AdvertisingData {.battery = 0x2A, .is_charging = 0x2B, .led_red = 0x2C, .led_green = 0x2D, .led_blue = 0x2E};

auto expected_data_array =
std::to_array({advertising_data.battery, advertising_data.is_charging, advertising_data.led_red,
Expand Down
11 changes: 3 additions & 8 deletions libs/BLEKit/tests/CoreGap_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,9 @@ TEST_F(CoreGapTest, onInitializationComplete)
TEST_F(CoreGapTest, refreshAdvertising)
{
std::array<uint8_t, 64> buffer {};
auto data_builder = AdvertisingDataBuilder {{buffer.begin(), buffer.end()}};
auto new_advertising_data = AdvertisingData {};
new_advertising_data.name = "NewLeka";
new_advertising_data.battery = 0x42;
new_advertising_data.is_charging = 0x01;
new_advertising_data.led_red = 0x2A;
new_advertising_data.led_green = 0x2B;
new_advertising_data.led_blue = 0x2C;
auto data_builder = AdvertisingDataBuilder {{buffer.begin(), buffer.end()}};
auto new_advertising_data = AdvertisingData {
.name = "NewLeka", .battery = 0x42, .is_charging = 0x01, .led_red = 0x2A, .led_green = 0x2B, .led_blue = 0x2C};

data_builder.setName(new_advertising_data.name);
data_builder.setServiceData(
Expand Down

0 comments on commit 0f7c662

Please sign in to comment.