From 434145c17b5f9ab749bfdcb4157b4d54ef4f3f65 Mon Sep 17 00:00:00 2001 From: Yann Locatelli Date: Sun, 20 Mar 2022 12:47:02 +0100 Subject: [PATCH] :sparkles: (sm): Add transition Sleeping to Idle states Add event command_received --- libs/RobotKit/include/StateMachine.h | 3 +++ libs/RobotKit/tests/RobotController_test.cpp | 9 +++++++++ libs/RobotKit/tests/StateMachine_test.cpp | 13 +++++++++++++ 3 files changed, 25 insertions(+) diff --git a/libs/RobotKit/include/StateMachine.h b/libs/RobotKit/include/StateMachine.h index ca8cf776c7..0518d8576f 100644 --- a/libs/RobotKit/include/StateMachine.h +++ b/libs/RobotKit/include/StateMachine.h @@ -15,6 +15,8 @@ namespace sm::event { }; struct sleep_timeout_did_end { }; + struct command_received { + }; struct charge_did_start { }; struct charge_did_stop { @@ -118,6 +120,7 @@ struct StateMachine { , sm::state::sleeping + boost::sml::on_entry<_> / sm::action::start_sleeping_behavior {} , sm::state::sleeping + boost::sml::on_exit<_> / sm::action::stop_sleeping_behavior {} + , sm::state::sleeping + event = sm::state::idle , sm::state::sleeping + event [sm::guard::is_charging {}] = sm::state::charging , sm::state::charging + boost::sml::on_entry<_> / sm::action::start_charging_behavior {} diff --git a/libs/RobotKit/tests/RobotController_test.cpp b/libs/RobotKit/tests/RobotController_test.cpp index 097c7fa8ae..786aa83c08 100644 --- a/libs/RobotKit/tests/RobotController_test.cpp +++ b/libs/RobotKit/tests/RobotController_test.cpp @@ -241,6 +241,15 @@ TEST_F(RobotControllerTest, stateIdleEventTimeout) EXPECT_TRUE(rc.state_machine.is(lksm::state::sleeping)); } +TEST_F(RobotControllerTest, stateSleepingEventCommandReceived) +{ + rc.state_machine.set_current_states(lksm::state::sleeping); + + // TODO: Trigger command_received in StateMachine from BLE + + // EXPECT_TRUE(rc.state_machine.is(lksm::state::idle)); +} + TEST_F(RobotControllerTest, stateSleepingEventChargeDidStartGuardIsChargingTrue) { rc.state_machine.set_current_states(lksm::state::sleeping); diff --git a/libs/RobotKit/tests/StateMachine_test.cpp b/libs/RobotKit/tests/StateMachine_test.cpp index d5ad9913c1..4f2f1be872 100644 --- a/libs/RobotKit/tests/StateMachine_test.cpp +++ b/libs/RobotKit/tests/StateMachine_test.cpp @@ -91,6 +91,19 @@ TEST_F(StateMachineTest, stateIdleEventTimeout) EXPECT_TRUE(sm.is(lksm::state::sleeping)); } +TEST_F(StateMachineTest, stateSleepEventCommandReceived) +{ + sm.set_current_states(lksm::state::sleeping); + + EXPECT_CALL(mock_rc, stopSleepingBehavior).Times(1); + EXPECT_CALL(mock_rc, startSleepTimeout).Times(1); + EXPECT_CALL(mock_rc, startWaitingBehavior).Times(1); + + sm.process_event(lksm::event::command_received {}); + + EXPECT_TRUE(sm.is(lksm::state::idle)); +} + TEST_F(StateMachineTest, stateSleepEventChargeDidStart) { sm.set_current_states(lksm::state::sleeping);