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 20, 2022
1 parent ecd5579 commit a891407
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 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
8 changes: 7 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,8 @@ auto coreflashmanager = CoreFlashManagerIS25LP016D(coreqspi);
auto coreflash = CoreFlashIS25LP016D(coreqspi, coreflashmanager);
auto firmwarekit = FirmwareKit(coreflash);

auto rc = RobotController {sleep_timeout, battery, firmwarekit, motor_left, motor_right, ledkit, videokit, behaviorkit};
auto rc = RobotController {sleep_timeout, battery, serialnumberkit, firmwarekit, motor_left,
motor_right, ledkit, videokit, 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
CoreMotor
LedKit
Expand Down
12 changes: 10 additions & 2 deletions libs/RobotKit/include/RobotController.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "BehaviorKit.h"
#include "CoreMotor.h"
#include "LedKit.h"
#include "SerialNumberKit.h"
#include "StateMachine.h"
#include "VideoKit.h"
#include "interface/RobotController.h"
Expand All @@ -31,10 +32,12 @@ 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, CoreMotor &motor_left, CoreMotor &motor_right,
LedKit &ledkit, VideoKit &videokit, BehaviorKit &behaviorkit)
SerialNumberKit &serialnumberkit, interface::FirmwareUpdate &firmware_update,
CoreMotor &motor_left, CoreMotor &motor_right, LedKit &ledkit, VideoKit &videokit,
BehaviorKit &behaviorkit)
: _sleep_timeout(sleep_timeout),
_battery(battery),
_serialnumberkit(serialnumberkit),
_firmware_update(firmware_update),
_motor_left(motor_left),
_motor_right(motor_right),
Expand Down Expand Up @@ -135,6 +138,9 @@ class RobotController : public interface::RobotController
_ble.setServices(services);
_ble.init();

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

_motor_left.stop();
_motor_right.stop();

Expand Down Expand Up @@ -192,6 +198,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
9 changes: 8 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 @@ -100,7 +107,7 @@ 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, motor_left, motor_right, ledkit, videokit, bhvkit};
sleep_timeout, battery, serialnumberkit, firmware_update, motor_left, motor_right, ledkit, videokit, bhvkit};

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

Expand Down

0 comments on commit a891407

Please sign in to comment.