From b086532e9e29ba7d0b6e0226e50c9de47e926103 Mon Sep 17 00:00:00 2001 From: Yann Locatelli Date: Thu, 15 Feb 2024 14:56:40 +0100 Subject: [PATCH] :sparkles: (StateMachine): Transition DeepSleeping state to Terminate state on BLE events --- libs/RobotKit/include/StateMachine.h | 3 +++ libs/RobotKit/tests/StateMachine_test.cpp | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/libs/RobotKit/include/StateMachine.h b/libs/RobotKit/include/StateMachine.h index e0be6f6ac..bed5bf071 100644 --- a/libs/RobotKit/include/StateMachine.h +++ b/libs/RobotKit/include/StateMachine.h @@ -244,6 +244,9 @@ struct StateMachine { , sm::state::deep_sleeping + event = X , sm::state::deep_sleeping + event = X + , sm::state::deep_sleeping + event = X + , sm::state::deep_sleeping + event = X + , sm::state::charging + boost::sml::on_entry<_> / (sm::action::start_deep_sleep_timeout {}, sm::action::start_charging_behavior {} ) , sm::state::charging + boost::sml::on_exit<_> / (sm::action::stop_deep_sleep_timeout {}, sm::action::stop_charging_behavior {} ) diff --git a/libs/RobotKit/tests/StateMachine_test.cpp b/libs/RobotKit/tests/StateMachine_test.cpp index c1a30f7b8..3de5137be 100644 --- a/libs/RobotKit/tests/StateMachine_test.cpp +++ b/libs/RobotKit/tests/StateMachine_test.cpp @@ -267,6 +267,28 @@ TEST_F(StateMachineTest, stateDeepSleepingEventChargeDidStop) EXPECT_TRUE(sm.is(X)); } +TEST_F(StateMachineTest, stateDeepSleepingEventBleConnection) +{ + sm.set_current_states(lksm::state::deep_sleeping); + + EXPECT_CALL(mock_rc, wakeUp); + + sm.process_event(lksm::event::ble_connection {}); + + EXPECT_TRUE(sm.is(X)); +} + +TEST_F(StateMachineTest, stateDeepSleepingEventBleDisconnection) +{ + sm.set_current_states(lksm::state::deep_sleeping); + + EXPECT_CALL(mock_rc, wakeUp); + + sm.process_event(lksm::event::ble_disconnection {}); + + EXPECT_TRUE(sm.is(X)); +} + TEST_F(StateMachineTest, stateIdleEventChargeDidStart) { sm.set_current_states(lksm::state::idle);