From cce66fb9661b70f4cf5e236f7a2d523e39afc18f Mon Sep 17 00:00:00 2001 From: Yann Locatelli Date: Mon, 28 Feb 2022 11:09:48 +0100 Subject: [PATCH 1/2] :memo: (copyright): Add missing copyright --- libs/RobotKit/source/RobotController.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libs/RobotKit/source/RobotController.cpp b/libs/RobotKit/source/RobotController.cpp index 5d369a255e..9d9292bfdc 100644 --- a/libs/RobotKit/source/RobotController.cpp +++ b/libs/RobotKit/source/RobotController.cpp @@ -1 +1,5 @@ +// Leka - LekaOS +// Copyright 2022 APF France handicap +// SPDX-License-Identifier: Apache-2.0 + #include "RobotController.h" From f6b5006276835fe4f86a1ef25acd3a72f8e88476 Mon Sep 17 00:00:00 2001 From: Yann Locatelli Date: Mon, 28 Feb 2022 11:10:08 +0100 Subject: [PATCH 2/2] :sparkles: (rc): Add BLEKit --- app/os/main.cpp | 1 + libs/RobotKit/CMakeLists.txt | 2 +- libs/RobotKit/include/RobotController.h | 7 ++++++- libs/RobotKit/tests/RobotController_test.cpp | 17 ++++++++++++++++- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/app/os/main.cpp b/app/os/main.cpp index 9a4fa84cc9..8175f79a8e 100644 --- a/app/os/main.cpp +++ b/app/os/main.cpp @@ -35,6 +35,7 @@ auto main() -> int auto hello = HelloWorld(); hello.start(); + rc.initializeComponents(); rc.registerEvents(); while (true) { diff --git a/libs/RobotKit/CMakeLists.txt b/libs/RobotKit/CMakeLists.txt index 5cfc23ce45..ef87321276 100644 --- a/libs/RobotKit/CMakeLists.txt +++ b/libs/RobotKit/CMakeLists.txt @@ -18,7 +18,7 @@ target_sources(RobotKit ) target_link_libraries(RobotKit - PRIVATE + BLEKit ) if (${CMAKE_PROJECT_NAME} STREQUAL "LekaOSUnitTests") diff --git a/libs/RobotKit/include/RobotController.h b/libs/RobotKit/include/RobotController.h index 71d7851780..cf272ee832 100644 --- a/libs/RobotKit/include/RobotController.h +++ b/libs/RobotKit/include/RobotController.h @@ -4,6 +4,8 @@ #pragma once +#include "BLEKit.h" + #include "StateMachine.h" #include "interface/RobotController.h" #include "interface/drivers/Battery.h" @@ -27,11 +29,12 @@ class RobotController : public interface::RobotController void raise(auto event) { state_machine.process_event(event); }; + void initializeComponents() { _ble.init(); } + void registerEvents() { using namespace system::robot::sm; - // Initializations // Setup callbacks for each events auto on_sleep_timeout = [this]() { raise(event::sleep_timeout_did_end {}); }; @@ -51,6 +54,8 @@ class RobotController : public interface::RobotController interface::Timeout &_sleep_timeout; interface::Battery &_battery; + + BLEKit _ble; }; } // namespace leka diff --git a/libs/RobotKit/tests/RobotController_test.cpp b/libs/RobotKit/tests/RobotController_test.cpp index de742a0069..ddabf555c9 100644 --- a/libs/RobotKit/tests/RobotController_test.cpp +++ b/libs/RobotKit/tests/RobotController_test.cpp @@ -4,6 +4,8 @@ #include "RobotController.h" +#include "ble_mocks.h" + #include "gmock/gmock.h" #include "gtest/gtest.h" #include "mocks/leka/Battery.h" @@ -27,6 +29,8 @@ class RobotControllerTest : public testing::Test protected: void SetUp() override { + ble::init_mocks(); + EXPECT_CALL(sleep_timeout, onTimeout).WillOnce(GetCallback(&on_sleep_timeout)); EXPECT_CALL(battery, onChargeDidStart).WillOnce(GetCallback>(&on_charge_did_start)); EXPECT_CALL(battery, onChargeDidStop).WillOnce(GetCallback>(&on_charge_did_stop)); @@ -34,7 +38,7 @@ class RobotControllerTest : public testing::Test rc.registerEvents(); } - // void TearDown() override {} + void TearDown() override { ble::delete_mocks(); } mock::Timeout sleep_timeout {}; mock::Battery battery {}; @@ -52,6 +56,17 @@ TEST_F(RobotControllerTest, initialization) EXPECT_NE(&rc, nullptr); } +TEST_F(RobotControllerTest, initializeComponents) +{ + ble::GapMock &mbed_mock_gap = ble::gap_mock(); + ble::GattServerMock &mbed_mock_gatt = ble::gatt_server_mock(); + + EXPECT_CALL(mbed_mock_gap, setEventHandler).Times(1); + EXPECT_CALL(mbed_mock_gatt, setEventHandler).Times(1); + + rc.initializeComponents(); +} + TEST_F(RobotControllerTest, stateSetupEventSetupComplete) { rc.state_machine.set_current_states(lksm::state::setup);