diff --git a/FppTest/state_machine/CMakeLists.txt b/FppTest/state_machine/CMakeLists.txt index fbe3a2c692..d4fa621627 100644 --- a/FppTest/state_machine/CMakeLists.txt +++ b/FppTest/state_machine/CMakeLists.txt @@ -2,6 +2,7 @@ set(SOURCE_FILES "${CMAKE_CURRENT_LIST_DIR}/SmTest.cpp" "${CMAKE_CURRENT_LIST_DIR}/SmTest.fpp" "${CMAKE_CURRENT_LIST_DIR}/DeviceSm.cpp" + "${CMAKE_CURRENT_LIST_DIR}/HackSm.cpp" ) set(MOD_DEPS Fw/SMSignal) @@ -13,6 +14,7 @@ set(UT_SOURCE_FILES "${CMAKE_CURRENT_LIST_DIR}/test/ut/Tester.cpp" "${CMAKE_CURRENT_LIST_DIR}/test/ut/TesterHelpers.cpp" "${CMAKE_CURRENT_LIST_DIR}/DeviceSm.cpp" + "${CMAKE_CURRENT_LIST_DIR}/HackSm.cpp" ) set(UT_MOD_DEPS STest) register_fprime_ut() diff --git a/FppTest/state_machine/DeviceSm.cpp b/FppTest/state_machine/DeviceSm.cpp index aff8d5b76b..c4d0ae0801 100644 --- a/FppTest/state_machine/DeviceSm.cpp +++ b/FppTest/state_machine/DeviceSm.cpp @@ -12,14 +12,19 @@ #include "DeviceSm.hpp" -void FppTest::DeviceSm::init() +void FppTest::DeviceSm::init(const FwEnumStoreType stateMachineId) { + parent->DeviceSm_turnOff(stateMachineId); this->state = OFF; } -void FppTest::DeviceSm::update(const DeviceSmEvents signal, const Fw::SMSignalBuffer &data) +void FppTest::DeviceSm::update( + const FwEnumStoreType stateMachineId, + const DeviceSm_Interface::DeviceSmEvents signal, + const Fw::SMSignalBuffer &data +) { switch (this->state) { @@ -30,8 +35,12 @@ void FppTest::DeviceSm::update(const DeviceSmEvents signal, const Fw::SMSignalBu switch (signal) { - case RTI_SIG: - this->state = ON; + case DeviceSm_Interface::DeviceSmEvents::RTI_SIG: + if ( parent->DeviceSm_g1(stateMachineId) ) { + parent->DeviceSm_a1(stateMachineId, signal, data); + parent->DeviceSm_turnOn(stateMachineId); + this->state = ON; + } break; @@ -47,8 +56,12 @@ void FppTest::DeviceSm::update(const DeviceSmEvents signal, const Fw::SMSignalBu switch (signal) { - case RTI_SIG: - this->state = OFF; + case DeviceSm_Interface::DeviceSmEvents::RTI_SIG: + if (parent->DeviceSm_g2(stateMachineId, signal, data) ) { + parent->DeviceSm_a2(stateMachineId); + parent->DeviceSm_turnOff(stateMachineId); + this->state = OFF; + } break; diff --git a/FppTest/state_machine/DeviceSm.hpp b/FppTest/state_machine/DeviceSm.hpp index 9bbaf344a5..884dbca062 100644 --- a/FppTest/state_machine/DeviceSm.hpp +++ b/FppTest/state_machine/DeviceSm.hpp @@ -10,6 +10,7 @@ #define DEVICESM_H_ #include +#include namespace Fw { class SMSignals; @@ -19,6 +20,34 @@ namespace FppTest { class DeviceSm_Interface { public: + enum DeviceSmEvents { + RTI_SIG, + }; + + + virtual bool DeviceSm_g1(const FwEnumStoreType stateMachineId) = 0; + + + virtual bool DeviceSm_g2( + const FwEnumStoreType stateMachineId, + const DeviceSm_Interface::DeviceSmEvents signal, + const Fw::SMSignalBuffer &data) = 0; + + + virtual void DeviceSm_turnOff(const FwEnumStoreType stateMachineId) = 0; + + + virtual void DeviceSm_a1( + const FwEnumStoreType stateMachineId, + const DeviceSm_Interface::DeviceSmEvents signal, + const Fw::SMSignalBuffer &data) = 0; + + + virtual void DeviceSm_turnOn(const FwEnumStoreType stateMachineId) = 0; + + + virtual void DeviceSm_a2(const FwEnumStoreType stateMachineId) = 0; + }; @@ -35,18 +64,17 @@ class DeviceSm { OFF, ON, }; - - enum DeviceSmEvents { - RTI_SIG, - }; enum DeviceSmStates state; void * extension; - void init(); - void update(const DeviceSmEvents signal, const Fw::SMSignalBuffer &data); - + void init(const FwEnumStoreType stateMachineId); + void update( + const FwEnumStoreType stateMachineId, + const DeviceSm_Interface::DeviceSmEvents signal, + const Fw::SMSignalBuffer &data + ); }; } diff --git a/FppTest/state_machine/DeviceSm.plantuml b/FppTest/state_machine/DeviceSm.plantuml index 820b43c34b..48a3e38645 100644 --- a/FppTest/state_machine/DeviceSm.plantuml +++ b/FppTest/state_machine/DeviceSm.plantuml @@ -4,12 +4,13 @@ [*] --> OFF state OFF { + OFF::Entry: turnOff() } state ON { - + ON::Entry: turnOn() } -OFF --> ON : RTI -ON --> OFF : RTI +OFF --> ON : RTI [g1()]/a1(e) +ON --> OFF : RTI [g2(e)]/a2() @enduml diff --git a/FppTest/state_machine/DeviceSm.trans b/FppTest/state_machine/DeviceSm.trans deleted file mode 100644 index 3a5135542f..0000000000 --- a/FppTest/state_machine/DeviceSm.trans +++ /dev/null @@ -1,2 +0,0 @@ -InitialState = OFF, Event = RTI, guard = None, action = None, TargetState = ON -InitialState = ON, Event = RTI, guard = None, action = None, TargetState = OFF diff --git a/FppTest/state_machine/HackSm.cpp b/FppTest/state_machine/HackSm.cpp new file mode 100644 index 0000000000..e4f88ccd0e --- /dev/null +++ b/FppTest/state_machine/HackSm.cpp @@ -0,0 +1,100 @@ + +// ====================================================================== +// \title HackSm.cpp +// \author Auto-generated +// \brief cpp file for state machine HackSm +// +// ====================================================================== + +#include "stdio.h" +#include "assert.h" +#include "Fw/Types/SMSignalsSerializableAc.hpp" +#include "HackSm.hpp" + + +void FppTest::HackSm::init(const FwEnumStoreType stateMachineId) +{ + parent->HackSm_turnOff(stateMachineId); + this->state = OFF; + +} + + +void FppTest::HackSm::update( + const FwEnumStoreType stateMachineId, + const HackSm_Interface::HackSmEvents signal, + const Fw::SMSignalBuffer &data +) +{ + switch (this->state) { + + /** + * state OFF + */ + case OFF: + + switch (signal) { + + case HackSm_Interface::HackSmEvents::RTI_SIG: + parent->HackSm_turnOn(stateMachineId); + this->state = ON; + + break; + + case HackSm_Interface::HackSmEvents::CHECK_SIG: + parent->HackSm_doDiag(stateMachineId); + this->state = DIAG; + + break; + + default: + break; + } + break; + + /** + * state ON + */ + case ON: + + switch (signal) { + + case HackSm_Interface::HackSmEvents::RTI_SIG: + parent->HackSm_turnOff(stateMachineId); + this->state = OFF; + + break; + + case HackSm_Interface::HackSmEvents::CHECK_SIG: + parent->HackSm_doDiag(stateMachineId); + this->state = DIAG; + + break; + + default: + break; + } + break; + + /** + * state DIAG + */ + case DIAG: + + switch (signal) { + + case HackSm_Interface::HackSmEvents::RTI_SIG: + parent->HackSm_turnOff(stateMachineId); + this->state = OFF; + + break; + + default: + break; + } + break; + + default: + assert(0); + } +} diff --git a/FppTest/state_machine/HackSm.hpp b/FppTest/state_machine/HackSm.hpp new file mode 100644 index 0000000000..438cf3f4ba --- /dev/null +++ b/FppTest/state_machine/HackSm.hpp @@ -0,0 +1,69 @@ + +// ====================================================================== +// \title HackSm.h +// \author Auto-generated +// \brief header file for state machine HackSm +// +// ====================================================================== + +#ifndef HACKSM_H_ +#define HACKSM_H_ + +#include +#include + +namespace Fw { + class SMSignals; +} + +namespace FppTest { + +class HackSm_Interface { + public: + enum HackSmEvents { + RTI_SIG, + CHECK_SIG, + }; + + + virtual void HackSm_turnOff(const FwEnumStoreType stateMachineId) = 0; + + + virtual void HackSm_turnOn(const FwEnumStoreType stateMachineId) = 0; + + + virtual void HackSm_doDiag(const FwEnumStoreType stateMachineId) = 0; + + +}; + +class HackSm { + + private: + HackSm_Interface *parent; + + public: + + HackSm(HackSm_Interface* parent) : parent(parent) {} + + enum HackSmStates { + OFF, + ON, + DIAG, + }; + + enum HackSmStates state; + + void * extension; + + void init(const FwEnumStoreType stateMachineId); + void update( + const FwEnumStoreType stateMachineId, + const HackSm_Interface::HackSmEvents signal, + const Fw::SMSignalBuffer &data + ); +}; + +} + +#endif diff --git a/FppTest/state_machine/HackSm.plantuml b/FppTest/state_machine/HackSm.plantuml new file mode 100644 index 0000000000..3c02ab7a76 --- /dev/null +++ b/FppTest/state_machine/HackSm.plantuml @@ -0,0 +1,23 @@ + +@startuml + +[*] --> OFF + +state OFF { + OFF::Entry: turnOff() +} + +state ON { + ON::Entry: turnOn() +} + +state DIAG { + DIAG::Entry: doDiag() +} + +OFF --> ON : RTI +ON --> OFF : RTI +ON --> DIAG : CHECK +OFF --> DIAG : CHECK +DIAG --> OFF : RTI +@enduml diff --git a/FppTest/state_machine/SmTest.cpp b/FppTest/state_machine/SmTest.cpp index 472ca628b4..7e615c537b 100644 --- a/FppTest/state_machine/SmTest.cpp +++ b/FppTest/state_machine/SmTest.cpp @@ -31,12 +31,68 @@ SmTest ::~SmTest() {} void SmTest::schedIn_handler(const NATIVE_INT_TYPE portNum, U32 context) { Fw::SMSignalBuffer data; - device1StateMachineInvoke(DeviceSm::RTI_SIG, data); - device2StateMachineInvoke(DeviceSm::RTI_SIG, data); - device3StateMachineInvoke(DeviceSm::RTI_SIG, data); + device1_stateMachineInvoke(DeviceSm_Interface::DeviceSmEvents::RTI_SIG, data); + device2_stateMachineInvoke(DeviceSm_Interface::DeviceSmEvents::RTI_SIG, data); + device3_stateMachineInvoke(HackSm_Interface::HackSmEvents::RTI_SIG, data); + device4_stateMachineInvoke(HackSm_Interface::HackSmEvents::RTI_SIG, data); + device5_stateMachineInvoke(HackSm_Interface::HackSmEvents::RTI_SIG, data); } +//! Overflow hook for state machine device4 +void SmTest::device4_stateMachineOverflowHook( + const HackSm_Interface::HackSmEvents signal, //!< The state machine signal + const Fw::SMSignalBuffer& data //!< The state machine data +) { + +} + +void SmTest::DeviceSm_turnOn(const FwEnumStoreType stateMachineId) { + printf("DeviceSm turnOn for state machine %d\n", stateMachineId); +} + +void SmTest::DeviceSm_turnOff(const FwEnumStoreType stateMachineId) { + printf("DeviceSm turnOff for state machine %d\n", stateMachineId); +} + +void SmTest::DeviceSm_a1( + const FwEnumStoreType stateMachineId, + const DeviceSmEvents signal, + const Fw::SMSignalBuffer& data + ) { + printf("Action 1, stateMachineId = %d, signal = %d\n", stateMachineId, signal); +} + + + bool SmTest::DeviceSm_g1(const FwEnumStoreType stateMachineId) { + return true; + } + + bool SmTest::DeviceSm_g2( + const FwEnumStoreType stateMachineId, + const DeviceSmEvents signal, + const Fw::SMSignalBuffer& data + ) { + return true; + } + +void SmTest::DeviceSm_a2(const FwEnumStoreType stateMachineId) { + printf("Action 2\n"); +} + +void SmTest::HackSm_turnOn(const FwEnumStoreType stateMachineId) { + printf("HackSm turn on\n"); +} + +void SmTest::HackSm_turnOff(const FwEnumStoreType stateMachineId) { + printf("HackSm turn off\n"); +} + +void SmTest::HackSm_doDiag(const FwEnumStoreType stateMachineId) { + printf("HackSm do diag\n"); +} + + // ---------------------------------------------------------------------- // Data product handler implementations // ---------------------------------------------------------------------- diff --git a/FppTest/state_machine/SmTest.fpp b/FppTest/state_machine/SmTest.fpp index 2d4b2ea4b5..c62cb7c62f 100644 --- a/FppTest/state_machine/SmTest.fpp +++ b/FppTest/state_machine/SmTest.fpp @@ -2,6 +2,7 @@ module FppTest { state machine DeviceSm + state machine HackSm @ A component for testing data product code gen active component SmTest { @@ -20,7 +21,9 @@ module FppTest { state machine instance device1: DeviceSm priority 1 block state machine instance device2: DeviceSm priority 2 assert - state machine instance device3: DeviceSm priority 3 drop + state machine instance device3: HackSm priority 3 drop + state machine instance device4: HackSm priority 4 hook + state machine instance device5: HackSm } diff --git a/FppTest/state_machine/SmTest.hpp b/FppTest/state_machine/SmTest.hpp index 1310bb6e34..25c5ab4a07 100644 --- a/FppTest/state_machine/SmTest.hpp +++ b/FppTest/state_machine/SmTest.hpp @@ -67,6 +67,39 @@ class SmTest : U32 context //!< The call order ) final; + //! Overflow hook for state machine device4 + void device4_stateMachineOverflowHook( + const HackSm_Interface::HackSmEvents signal, //!< The state machine signal + const Fw::SMSignalBuffer& data //!< The state machine data + ); + + // State machine functions + void DeviceSm_turnOn(const FwEnumStoreType stateMachineId); + + void DeviceSm_turnOff(const FwEnumStoreType stateMachineId); + + void DeviceSm_a1( + const FwEnumStoreType stateMachineId, + const DeviceSmEvents signal, + const Fw::SMSignalBuffer& data + ); + + void DeviceSm_a2(const FwEnumStoreType stateMachineId); + + bool DeviceSm_g1(const FwEnumStoreType stateMachineId); + + bool DeviceSm_g2( + const FwEnumStoreType stateMachineId, + const DeviceSmEvents signal, + const Fw::SMSignalBuffer& data + ); + + void HackSm_turnOn(const FwEnumStoreType stateMachineId); + + void HackSm_turnOff(const FwEnumStoreType stateMachineId); + + void HackSm_doDiag(const FwEnumStoreType stateMachineId); + private: // ---------------------------------------------------------------------- // Data product handler implementations diff --git a/FppTest/state_machine/autosm.sh b/FppTest/state_machine/autosm.sh deleted file mode 100755 index ee19c9a1d3..0000000000 --- a/FppTest/state_machine/autosm.sh +++ /dev/null @@ -1 +0,0 @@ - /home/watney/STARS/autocoder/Stars.py -namespace FppTest -backend fprime -noImpl -model DeviceSm.plantuml diff --git a/FppTest/state_machine/test/ut/Tester.cpp b/FppTest/state_machine/test/ut/Tester.cpp index 113334dcd7..f8a7e93d73 100644 --- a/FppTest/state_machine/test/ut/Tester.cpp +++ b/FppTest/state_machine/test/ut/Tester.cpp @@ -34,19 +34,31 @@ void Tester::schedIn_OK() { ASSERT_EQ(DeviceSm::OFF, this->component.m_stateMachine_device1.state); ASSERT_EQ(DeviceSm::OFF, this->component.m_stateMachine_device2.state); ASSERT_EQ(DeviceSm::OFF, this->component.m_stateMachine_device3.state); + ASSERT_EQ(DeviceSm::OFF, this->component.m_stateMachine_device4.state); + ASSERT_EQ(DeviceSm::OFF, this->component.m_stateMachine_device5.state); invoke_to_schedIn(0,0); dispatchAll(); ASSERT_EQ(DeviceSm::ON, this->component.m_stateMachine_device1.state); ASSERT_EQ(DeviceSm::ON, this->component.m_stateMachine_device2.state); ASSERT_EQ(DeviceSm::ON, this->component.m_stateMachine_device3.state); + ASSERT_EQ(DeviceSm::ON, this->component.m_stateMachine_device4.state); + ASSERT_EQ(DeviceSm::ON, this->component.m_stateMachine_device5.state); invoke_to_schedIn(0,0); dispatchAll(); ASSERT_EQ(DeviceSm::OFF, this->component.m_stateMachine_device1.state); ASSERT_EQ(DeviceSm::OFF, this->component.m_stateMachine_device2.state); ASSERT_EQ(DeviceSm::OFF, this->component.m_stateMachine_device3.state); - ASSERT_EQ(0, this->component.m_stateMachine_device1.state); - ASSERT_EQ(0, this->component.m_stateMachine_device2.state); - ASSERT_EQ(0, this->component.m_stateMachine_device3.state); + ASSERT_EQ(DeviceSm::OFF, this->component.m_stateMachine_device4.state); + ASSERT_EQ(DeviceSm::OFF, this->component.m_stateMachine_device5.state); + + Fw::SMSignalBuffer data; + this->component.device3_stateMachineInvoke(HackSm_Interface::HackSmEvents::CHECK_SIG, data); + dispatchAll(); + ASSERT_EQ(HackSm::DIAG, this->component.m_stateMachine_device3.state); + invoke_to_schedIn(0,0); + dispatchAll(); + ASSERT_EQ(HackSm::OFF, this->component.m_stateMachine_device3.state); + }