Skip to content

Commit

Permalink
🔀 Merge branch 'yann/feature/robot-controller/start-ble' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
ladislas committed Mar 10, 2022
2 parents e5b8e96 + f6b5006 commit 2685f5f
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/os/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ auto main() -> int
auto hello = HelloWorld();
hello.start();

rc.initializeComponents();
rc.registerEvents();

while (true) {
Expand Down
2 changes: 1 addition & 1 deletion libs/RobotKit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ target_sources(RobotKit
)

target_link_libraries(RobotKit
PRIVATE
BLEKit
)

if (${CMAKE_PROJECT_NAME} STREQUAL "LekaOSUnitTests")
Expand Down
7 changes: 6 additions & 1 deletion libs/RobotKit/include/RobotController.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#pragma once

#include "BLEKit.h"

#include "StateMachine.h"
#include "interface/RobotController.h"
#include "interface/drivers/Battery.h"
Expand All @@ -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 {}); };
Expand All @@ -51,6 +54,8 @@ class RobotController : public interface::RobotController
interface::Timeout &_sleep_timeout;

interface::Battery &_battery;

BLEKit _ble;
};

} // namespace leka
4 changes: 4 additions & 0 deletions libs/RobotKit/source/RobotController.cpp
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
// Leka - LekaOS
// Copyright 2022 APF France handicap
// SPDX-License-Identifier: Apache-2.0

#include "RobotController.h"
17 changes: 16 additions & 1 deletion libs/RobotKit/tests/RobotController_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "RobotController.h"

#include "ble_mocks.h"

#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "mocks/leka/Battery.h"
Expand All @@ -27,14 +29,16 @@ class RobotControllerTest : public testing::Test
protected:
void SetUp() override
{
ble::init_mocks();

EXPECT_CALL(sleep_timeout, onTimeout).WillOnce(GetCallback<interface::Timeout::callback_t>(&on_sleep_timeout));
EXPECT_CALL(battery, onChargeDidStart).WillOnce(GetCallback<mbed::Callback<void()>>(&on_charge_did_start));
EXPECT_CALL(battery, onChargeDidStop).WillOnce(GetCallback<mbed::Callback<void()>>(&on_charge_did_stop));
EXPECT_CALL(sleep_timeout, start).Times(1); // Hide Uninteresting mock function call

rc.registerEvents();
}
// void TearDown() override {}
void TearDown() override { ble::delete_mocks(); }

mock::Timeout sleep_timeout {};
mock::Battery battery {};
Expand All @@ -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);
Expand Down

0 comments on commit 2685f5f

Please sign in to comment.