From 823c6c716cf9e99791fe2c520aff39ff2c51bd45 Mon Sep 17 00:00:00 2001 From: Yann Locatelli Date: Fri, 18 Mar 2022 16:22:39 +0100 Subject: [PATCH] :sparkles: (rc): Set SerialNumber in BLE --- app/os/CMakeLists.txt | 2 ++ app/os/main.cpp | 8 +++++++- libs/RobotKit/CMakeLists.txt | 1 + libs/RobotKit/include/RobotController.h | 12 ++++++++++-- libs/RobotKit/tests/RobotController_test.cpp | 9 ++++++++- 5 files changed, 28 insertions(+), 4 deletions(-) diff --git a/app/os/CMakeLists.txt b/app/os/CMakeLists.txt index 32cef29e92..6510aa74bb 100644 --- a/app/os/CMakeLists.txt +++ b/app/os/CMakeLists.txt @@ -17,11 +17,13 @@ target_sources(LekaOS target_link_libraries(LekaOS bootutil RobotKit + CoreMCU CoreTimeout CoreBattery CoreQSPI CoreFlashMemory FileSystemKit + SerialNumberKit FirmwareKit BehaviorKit CorePwm diff --git a/app/os/main.cpp b/app/os/main.cpp index faccc4a222..c89d35d500 100644 --- a/app/os/main.cpp +++ b/app/os/main.cpp @@ -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" @@ -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" @@ -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"}; @@ -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() { diff --git a/libs/RobotKit/CMakeLists.txt b/libs/RobotKit/CMakeLists.txt index e4dfdf5e89..182b88df2d 100644 --- a/libs/RobotKit/CMakeLists.txt +++ b/libs/RobotKit/CMakeLists.txt @@ -19,6 +19,7 @@ target_sources(RobotKit target_link_libraries(RobotKit BatteryKit + SerialNumberKit BLEKit CoreMotor LedKit diff --git a/libs/RobotKit/include/RobotController.h b/libs/RobotKit/include/RobotController.h index c37874e65a..06f6b8dc32 100644 --- a/libs/RobotKit/include/RobotController.h +++ b/libs/RobotKit/include/RobotController.h @@ -16,6 +16,7 @@ #include "BehaviorKit.h" #include "CoreMotor.h" #include "LedKit.h" +#include "SerialNumberKit.h" #include "StateMachine.h" #include "VideoKit.h" #include "interface/RobotController.h" @@ -32,10 +33,12 @@ class RobotController : public interface::RobotController sm_t state_machine {static_cast(*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), @@ -139,6 +142,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(); @@ -196,6 +202,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 _on_update_loaded_callback {}; diff --git a/libs/RobotKit/tests/RobotController_test.cpp b/libs/RobotKit/tests/RobotController_test.cpp index d3b225e64e..283d28338e 100644 --- a/libs/RobotKit/tests/RobotController_test.cpp +++ b/libs/RobotKit/tests/RobotController_test.cpp @@ -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" @@ -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(); @@ -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}; @@ -100,7 +107,7 @@ class RobotControllerTest : public testing::Test BehaviorKit bhvkit {videokit, ledkit, motor_left, motor_right}; RobotController> 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 = {};