Skip to content

Commit

Permalink
✨ (rc): Set SerialNumber in BLE
Browse files Browse the repository at this point in the history
  • Loading branch information
YannLocatelli committed Mar 18, 2022
1 parent c6d28fb commit 5911c1f
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
2 changes: 2 additions & 0 deletions app/os/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ target_sources(LekaOS
target_link_libraries(LekaOS
bootutil
RobotKit
CoreMCU
CoreTimeout
CoreBattery
CoreQSPI
CoreFlashMemory
FileSystemKit
SerialNumberKit
FirmwareKit
BehaviorKit
CorePwm
Expand Down
7 changes: 6 additions & 1 deletion app/os/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "CoreBattery.h"
#include "CoreFlashIS25LP016D.h"
#include "CoreFlashManagerIS25LP016D.h"
#include "CoreMCU.h"
#include "CorePwm.h"
#include "CoreQSPI.h"
#include "CoreSPI.h"
Expand All @@ -21,6 +22,7 @@
#include "QSPIFBlockDevice.h"
#include "RobotController.h"
#include "SDBlockDevice.h"
#include "SerialNumberKit.h"
#include "SlicingBlockDevice.h"
#include "VideoKit.h"
#include "bootutil/bootutil.h"
Expand Down Expand Up @@ -52,6 +54,9 @@ void start()

auto sleep_timeout = CoreTimeout {};

auto mcu = CoreMCU {};
auto serialnumberkit = SerialNumberKit {mcu};

auto sd_blockdevice = SDBlockDevice {SD_SPI_MOSI, SD_SPI_MISO, SD_SPI_SCK};
auto fatfs = FATFileSystem {"fs"};

Expand Down Expand Up @@ -86,7 +91,7 @@ auto coreflashmanager = CoreFlashManagerIS25LP016D(coreqspi);
auto coreflash = CoreFlashIS25LP016D(coreqspi, coreflashmanager);
auto firmwarekit = FirmwareKit(coreflash);

auto rc = RobotController {sleep_timeout, battery, firmwarekit, behaviorkit};
auto rc = RobotController {sleep_timeout, battery, serialnumberkit, firmwarekit, behaviorkit};

void initializeSD()
{
Expand Down
1 change: 1 addition & 0 deletions libs/RobotKit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ target_sources(RobotKit

target_link_libraries(RobotKit
BatteryKit
SerialNumberKit
BLEKit
BehaviorKit
)
Expand Down
10 changes: 9 additions & 1 deletion libs/RobotKit/include/RobotController.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

#include "BatteryKit.h"
#include "BehaviorKit.h"
#include "SerialNumberKit.h"
#include "StateMachine.h"
#include "interface/RobotController.h"
#include "interface/drivers/Battery.h"
Expand All @@ -28,9 +29,11 @@ class RobotController : public interface::RobotController
sm_t state_machine {static_cast<interface::RobotController &>(*this)};

explicit RobotController(interface::Timeout &sleep_timeout, interface::Battery &battery,
interface::FirmwareUpdate &firmware_update, BehaviorKit &behaviorkit)
SerialNumberKit &serialnumberkit, interface::FirmwareUpdate &firmware_update,
BehaviorKit &behaviorkit)
: _sleep_timeout(sleep_timeout),
_battery(battery),
_serialnumberkit(serialnumberkit),
_firmware_update(firmware_update),
_behaviorkit(behaviorkit) {};

Expand Down Expand Up @@ -103,6 +106,9 @@ class RobotController : public interface::RobotController

_ble.setServices(services);
_ble.init();

auto _serial_number = _serialnumberkit.getSerialNumber();
_service_device_information.setSerialNumber(_serial_number);
}

void registerOnUpdateLoadedCallback(std::function<void()> const &on_update_loaded_callback)
Expand Down Expand Up @@ -142,6 +148,8 @@ class RobotController : public interface::RobotController
BatteryKit _battery_kit {_battery};
uint8_t _minimal_battery_level_to_update {25};

SerialNumberKit &_serialnumberkit;

interface::FirmwareUpdate &_firmware_update;
std::function<void()> _on_update_loaded_callback {};

Expand Down
10 changes: 9 additions & 1 deletion libs/RobotKit/tests/RobotController_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
#include "CoreMotor.h"
#include "CorePwm.h"
#include "CoreSPI.h"
#include "SerialNumberKit.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "mocks/leka/Battery.h"
#include "mocks/leka/FirmwareUpdate.h"
#include "mocks/leka/LEDAnimation.h"
#include "mocks/leka/MCU.h"
#include "mocks/leka/PwmOut.h"
#include "mocks/leka/Timeout.h"
#include "mocks/mbed/DigitalOut.h"
Expand Down Expand Up @@ -55,6 +57,7 @@ class RobotControllerTest : public testing::Test
EXPECT_CALL(mbed_mock_gatt, addService).Times(AnyNumber());
EXPECT_CALL(mbed_mock_gap, setEventHandler).Times(AnyNumber());
EXPECT_CALL(mbed_mock_gatt, setEventHandler).Times(AnyNumber());
EXPECT_CALL(mock_mcu, getID).Times(AnyNumber());

rc.initializeComponents();

Expand All @@ -72,6 +75,10 @@ class RobotControllerTest : public testing::Test

mock::Timeout sleep_timeout {};
mock::Battery battery {};

mock::MCU mock_mcu {};
SerialNumberKit serialnumberkit {mock_mcu};

mock::FirmwareUpdate firmware_update {};

CoreSPI spi {NC, NC, NC, NC};
Expand Down Expand Up @@ -99,7 +106,8 @@ class RobotControllerTest : public testing::Test

BehaviorKit bhvkit {videokit, ledkit, motor_left, motor_right};

RobotController<bsml::sm<robot::StateMachine, bsml::testing>> rc {sleep_timeout, battery, firmware_update, bhvkit};
RobotController<bsml::sm<robot::StateMachine, bsml::testing>> rc {sleep_timeout, battery, serialnumberkit,
firmware_update, bhvkit};

interface::Timeout::callback_t on_sleep_timeout = {};

Expand Down

0 comments on commit 5911c1f

Please sign in to comment.