diff --git a/.github/actions/spelling/allow.txt b/.github/actions/spelling/allow.txt index 111542f0db..75f73d63e8 100644 --- a/.github/actions/spelling/allow.txt +++ b/.github/actions/spelling/allow.txt @@ -6,3 +6,5 @@ usec usecs workaround workarounds +DEVICESM +HACKSM diff --git a/Drv/GpioDriverPorts/GpioDriverPorts.fpp b/Drv/GpioDriverPorts/GpioDriverPorts.fpp index 9bb6a2297a..70c673052e 100644 --- a/Drv/GpioDriverPorts/GpioDriverPorts.fpp +++ b/Drv/GpioDriverPorts/GpioDriverPorts.fpp @@ -1,7 +1,7 @@ module Drv { port GpioWrite( - state: Fw.Logic + $state: Fw.Logic ) } @@ -9,7 +9,7 @@ module Drv { module Drv { port GpioRead( - ref state: Fw.Logic + ref $state: Fw.Logic ) } diff --git a/FppTest/CMakeLists.txt b/FppTest/CMakeLists.txt index 43cae3f2ba..1ae2e7930e 100644 --- a/FppTest/CMakeLists.txt +++ b/FppTest/CMakeLists.txt @@ -14,12 +14,14 @@ include("${CMAKE_CURRENT_LIST_DIR}/../cmake/FPrime-Code.cmake") add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/array/") add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/component/") add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/dp/") +add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/state_machine/") add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/enum/") add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/struct/") set(SOURCE_FILES "source.cpp") set(MOD_DEPS ${PROJECT_NAME}/array ${PROJECT_NAME}/dp + ${PROJECT_NAME}/state_machine ${PROJECT_NAME}/enum ${PROJECT_NAME}/struct ${PROJECT_NAME}/component/empty diff --git a/FppTest/state_machine/CMakeLists.txt b/FppTest/state_machine/CMakeLists.txt new file mode 100644 index 0000000000..6d1e6c1e0f --- /dev/null +++ b/FppTest/state_machine/CMakeLists.txt @@ -0,0 +1,21 @@ +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/Sm) + +register_fprime_module() + +set(UT_SOURCE_FILES + "${CMAKE_CURRENT_LIST_DIR}/SmTest.fpp" + "${CMAKE_CURRENT_LIST_DIR}/test/ut/SmTestTestMain.cpp" + "${CMAKE_CURRENT_LIST_DIR}/test/ut/SmTestTester.cpp" + "${CMAKE_CURRENT_LIST_DIR}/DeviceSm.cpp" + "${CMAKE_CURRENT_LIST_DIR}/HackSm.cpp" +) + +set(UT_MOD_DEPS STest) +set(UT_AUTO_HELPERS ON) +register_fprime_ut() diff --git a/FppTest/state_machine/DeviceSm.cpp b/FppTest/state_machine/DeviceSm.cpp new file mode 100644 index 0000000000..5fce5cf81c --- /dev/null +++ b/FppTest/state_machine/DeviceSm.cpp @@ -0,0 +1,74 @@ + +// ====================================================================== +// \title DeviceSm.cpp +// \author Auto-generated +// \brief cpp file for state machine DeviceSm +// +// ====================================================================== + +#include +#include "DeviceSm.hpp" + + +void FppTest::DeviceSm::init(const FwEnumStoreType stateMachineId) +{ + parent->DeviceSm_turnOff(stateMachineId); + this->state = OFF; + +} + + +void FppTest::DeviceSm::update( + const FwEnumStoreType stateMachineId, + const DeviceSm_Interface::DeviceSm_Signals signal, + const Fw::SmSignalBuffer &data +) +{ + switch (this->state) { + + /** + * state OFF + */ + case OFF: + + switch (signal) { + + case DeviceSm_Interface::DeviceSm_Signals::RTI_SIG: + if ( parent->DeviceSm_g1(stateMachineId) ) { + parent->DeviceSm_a1(stateMachineId, signal, data); + parent->DeviceSm_turnOn(stateMachineId); + this->state = ON; + } + + break; + + default: + break; + } + break; + + /** + * state ON + */ + case ON: + + switch (signal) { + + case DeviceSm_Interface::DeviceSm_Signals::RTI_SIG: + if (parent->DeviceSm_g2(stateMachineId, signal, data) ) { + parent->DeviceSm_a2(stateMachineId); + parent->DeviceSm_turnOff(stateMachineId); + this->state = OFF; + } + + break; + + default: + break; + } + break; + + default: + FW_ASSERT(0); + } +} diff --git a/FppTest/state_machine/DeviceSm.fppi b/FppTest/state_machine/DeviceSm.fppi new file mode 100644 index 0000000000..a506e51c3a --- /dev/null +++ b/FppTest/state_machine/DeviceSm.fppi @@ -0,0 +1,7 @@ + + + enum DeviceSmStates { + OFF = 0 + ON = 1 + } + diff --git a/FppTest/state_machine/DeviceSm.hpp b/FppTest/state_machine/DeviceSm.hpp new file mode 100644 index 0000000000..c9592b07fd --- /dev/null +++ b/FppTest/state_machine/DeviceSm.hpp @@ -0,0 +1,76 @@ + +// ====================================================================== +// \title DeviceSm.h +// \author Auto-generated +// \brief header file for state machine DeviceSm +// +// ====================================================================== + +#ifndef DEVICESM_H_ +#define DEVICESM_H_ + +#include +#include + +namespace FppTest { + +class DeviceSm_Interface { + public: + enum DeviceSm_Signals { + RTI_SIG, + }; + + + virtual bool DeviceSm_g1(const FwEnumStoreType stateMachineId) = 0; + + + virtual bool DeviceSm_g2( + const FwEnumStoreType stateMachineId, + const DeviceSm_Interface::DeviceSm_Signals signal, + const Fw::SmSignalBuffer &data) = 0; + + + virtual void DeviceSm_turnOff(const FwEnumStoreType stateMachineId) = 0; + + + virtual void DeviceSm_a1( + const FwEnumStoreType stateMachineId, + const DeviceSm_Interface::DeviceSm_Signals signal, + const Fw::SmSignalBuffer &data) = 0; + + + virtual void DeviceSm_turnOn(const FwEnumStoreType stateMachineId) = 0; + + + virtual void DeviceSm_a2(const FwEnumStoreType stateMachineId) = 0; + + +}; + +class DeviceSm { + + private: + DeviceSm_Interface *parent; + + public: + + DeviceSm(DeviceSm_Interface* parent) : parent(parent) {} + + enum DeviceSm_States { + OFF, + ON, + }; + + enum DeviceSm_States state; + + void init(const FwEnumStoreType stateMachineId); + void update( + const FwEnumStoreType stateMachineId, + const DeviceSm_Interface::DeviceSm_Signals signal, + const Fw::SmSignalBuffer &data + ); +}; + +} + +#endif diff --git a/FppTest/state_machine/DeviceSm.plantuml b/FppTest/state_machine/DeviceSm.plantuml new file mode 100644 index 0000000000..48a3e38645 --- /dev/null +++ b/FppTest/state_machine/DeviceSm.plantuml @@ -0,0 +1,16 @@ + +@startuml + +[*] --> OFF + +state OFF { + OFF::Entry: turnOff() +} + +state ON { + ON::Entry: turnOn() +} + +OFF --> ON : RTI [g1()]/a1(e) +ON --> OFF : RTI [g2(e)]/a2() +@enduml diff --git a/FppTest/state_machine/HackSm.cpp b/FppTest/state_machine/HackSm.cpp new file mode 100644 index 0000000000..6cf444f0ca --- /dev/null +++ b/FppTest/state_machine/HackSm.cpp @@ -0,0 +1,98 @@ + +// ====================================================================== +// \title HackSm.cpp +// \author Auto-generated +// \brief cpp file for state machine HackSm +// +// ====================================================================== + +#include +#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::HackSm_Signals signal, + const Fw::SmSignalBuffer &data +) +{ + switch (this->state) { + + /** + * state OFF + */ + case OFF: + + switch (signal) { + + case HackSm_Interface::HackSm_Signals::RTI_SIG: + parent->HackSm_turnOn(stateMachineId); + this->state = ON; + + break; + + case HackSm_Interface::HackSm_Signals::CHECK_SIG: + parent->HackSm_doDiag(stateMachineId); + this->state = DIAG; + + break; + + default: + break; + } + break; + + /** + * state ON + */ + case ON: + + switch (signal) { + + case HackSm_Interface::HackSm_Signals::RTI_SIG: + parent->HackSm_turnOff(stateMachineId); + this->state = OFF; + + break; + + case HackSm_Interface::HackSm_Signals::CHECK_SIG: + parent->HackSm_doDiag(stateMachineId); + this->state = DIAG; + + break; + + default: + break; + } + break; + + /** + * state DIAG + */ + case DIAG: + + switch (signal) { + + case HackSm_Interface::HackSm_Signals::RTI_SIG: + parent->HackSm_turnOff(stateMachineId); + this->state = OFF; + + break; + + default: + break; + } + break; + + default: + FW_ASSERT(0); + } +} diff --git a/FppTest/state_machine/HackSm.hpp b/FppTest/state_machine/HackSm.hpp new file mode 100644 index 0000000000..7cfa698ad2 --- /dev/null +++ b/FppTest/state_machine/HackSm.hpp @@ -0,0 +1,63 @@ + +// ====================================================================== +// \title HackSm.h +// \author Auto-generated +// \brief header file for state machine HackSm +// +// ====================================================================== + +#ifndef HACKSM_H_ +#define HACKSM_H_ + +#include +#include + +namespace FppTest { + +class HackSm_Interface { + public: + enum HackSm_Signals { + 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 HackSm_States { + OFF, + ON, + DIAG, + }; + + enum HackSm_States state; + + void init(const FwEnumStoreType stateMachineId); + void update( + const FwEnumStoreType stateMachineId, + const HackSm_Interface::HackSm_Signals 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/Makefile b/FppTest/state_machine/Makefile new file mode 100644 index 0000000000..8784d9e203 --- /dev/null +++ b/FppTest/state_machine/Makefile @@ -0,0 +1,3 @@ +HOME_DIR := $(HOME) +autocode: + $(HOME_DIR)/STARS/autocoder/Stars.py -noImpl -backend fprime -namespace FppTest -model DeviceSm.plantuml diff --git a/FppTest/state_machine/SMEvents.hpp b/FppTest/state_machine/SMEvents.hpp new file mode 100644 index 0000000000..161053a135 --- /dev/null +++ b/FppTest/state_machine/SMEvents.hpp @@ -0,0 +1 @@ +#include "Fw/Types/SMEventsSerializableAc.hpp" diff --git a/FppTest/state_machine/SmTest.cpp b/FppTest/state_machine/SmTest.cpp new file mode 100644 index 0000000000..41bc45e1c1 --- /dev/null +++ b/FppTest/state_machine/SmTest.cpp @@ -0,0 +1,105 @@ +// ====================================================================== +// \title SmTest.cpp +// \author watney +// \brief hpp file for SmTest component implementation class +// ====================================================================== + +#include + +#include "FppTest/state_machine/SmTest.hpp" +#include "Fw/Types/Assert.hpp" + +namespace FppTest { + +// ---------------------------------------------------------------------- +// Construction, initialization, and destruction +// ---------------------------------------------------------------------- + +SmTest::SmTest(const char* const compName): + SmTestComponentBase(compName) {} + +void SmTest ::init(const NATIVE_INT_TYPE queueDepth, const NATIVE_INT_TYPE instance) { + SmTestComponentBase::init(queueDepth, instance); +} + +SmTest ::~SmTest() {} + +// ---------------------------------------------------------------------- +// Handler implementations for user-defined typed input ports +// ---------------------------------------------------------------------- + +void SmTest::schedIn_handler(const NATIVE_INT_TYPE portNum, U32 context) { + Fw::SmSignalBuffer data; + + device1_stateMachineInvoke(DeviceSm_Interface::DeviceSm_Signals::RTI_SIG, data); + device2_stateMachineInvoke(DeviceSm_Interface::DeviceSm_Signals::RTI_SIG, data); + device3_stateMachineInvoke(HackSm_Interface::HackSm_Signals::RTI_SIG, data); + device4_stateMachineInvoke(HackSm_Interface::HackSm_Signals::RTI_SIG, data); + device5_stateMachineInvoke(HackSm_Interface::HackSm_Signals::RTI_SIG, data); + +} + +//! Overflow hook for state machine device4 +void SmTest::device4_stateMachineOverflowHook( + const HackSm_Interface::HackSm_Signals 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 DeviceSm_Signals 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 DeviceSm_Signals 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 +// ---------------------------------------------------------------------- + + +// ---------------------------------------------------------------------- +// Private helper functions +// ---------------------------------------------------------------------- + +} // end namespace FppTest diff --git a/FppTest/state_machine/SmTest.fpp b/FppTest/state_machine/SmTest.fpp new file mode 100644 index 0000000000..c62cb7c62f --- /dev/null +++ b/FppTest/state_machine/SmTest.fpp @@ -0,0 +1,30 @@ + +module FppTest { + + state machine DeviceSm + state machine HackSm + + @ A component for testing data product code gen + active component SmTest { + + # ---------------------------------------------------------------------- + # Types + # ---------------------------------------------------------------------- + + + # ---------------------------------------------------------------------- + # General ports + # ---------------------------------------------------------------------- + + @ A schedIn port to run the data product generation + async input port schedIn: Svc.Sched + + state machine instance device1: DeviceSm priority 1 block + state machine instance device2: DeviceSm priority 2 assert + 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 new file mode 100644 index 0000000000..de68a75615 --- /dev/null +++ b/FppTest/state_machine/SmTest.hpp @@ -0,0 +1,126 @@ +// ====================================================================== +// \title SmTest.hpp +// \author watney +// \brief hpp file for SmTest component implementation class +// ====================================================================== + +#ifndef FppTest_SmTest_HPP +#define FppTest_SmTest_HPP + +#include + +#include "FppTest/state_machine/SmTestComponentAc.hpp" +#include "Fw/Types/String.hpp" + +namespace FppTest { + +class SmTest : + public SmTestComponentBase +{ + + // Friend class for testing + friend class Tester; + + public: + // ---------------------------------------------------------------------- + // Constants + // ---------------------------------------------------------------------- + + + + public: + // ---------------------------------------------------------------------- + // Types + // ---------------------------------------------------------------------- + + + public: + // ---------------------------------------------------------------------- + // Construction, initialization, and destruction + // ---------------------------------------------------------------------- + + //! Construct object SmTest + SmTest(const char* const compName); //!< The component name + + //! Initialize object SmTest + void init(const NATIVE_INT_TYPE queueDepth, //!< The queue depth + const NATIVE_INT_TYPE instance = 0 //!< The instance number + ); + + //! Destroy object SmTest + ~SmTest(); + + public: + // ---------------------------------------------------------------------- + // Public interface methods + // ---------------------------------------------------------------------- + + + + private: + // ---------------------------------------------------------------------- + // Handler implementations for user-defined typed input ports + // ---------------------------------------------------------------------- + + //! Handler implementation for schedIn + void schedIn_handler(const NATIVE_INT_TYPE portNum, //!< The port number + U32 context //!< The call order + ) final; + + //! Overflow hook for state machine device4 + void device4_stateMachineOverflowHook( + const HackSm_Interface::HackSm_Signals 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 DeviceSm_Signals signal, + const Fw::SmSignalBuffer& data + ); + + void DeviceSm_a2(const FwEnumStoreType stateMachineId); + + bool DeviceSm_g1(const FwEnumStoreType stateMachineId); + + bool DeviceSm_g2( + const FwEnumStoreType stateMachineId, + const DeviceSm_Signals 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 + // ---------------------------------------------------------------------- + + + private: + // ---------------------------------------------------------------------- + // Private helper functions + // ---------------------------------------------------------------------- + + + + private: + // ---------------------------------------------------------------------- + // Private member variables + // ---------------------------------------------------------------------- + + +}; + +} // end namespace FppTest + +#endif diff --git a/FppTest/state_machine/test/ut/SmTestTestMain.cpp b/FppTest/state_machine/test/ut/SmTestTestMain.cpp new file mode 100644 index 0000000000..769b464f3d --- /dev/null +++ b/FppTest/state_machine/test/ut/SmTestTestMain.cpp @@ -0,0 +1,22 @@ +// ---------------------------------------------------------------------- +// SmTestTestMain.cpp +// ---------------------------------------------------------------------- + +#include "FppTest/state_machine/test/ut/SmTestTester.hpp" +#include "Fw/Test/UnitTest.hpp" +#include "STest/Random/Random.hpp" + +using namespace FppTest; + +TEST(schedIn, OK) { + COMMENT("schedIn OK"); + SmTestTester tester; + tester.schedIn_OK(); +} + + +int main(int argc, char** argv) { + ::testing::InitGoogleTest(&argc, argv); + STest::Random::seed(); + return RUN_ALL_TESTS(); +} diff --git a/FppTest/state_machine/test/ut/SmTestTester.cpp b/FppTest/state_machine/test/ut/SmTestTester.cpp new file mode 100644 index 0000000000..ebca73c4a0 --- /dev/null +++ b/FppTest/state_machine/test/ut/SmTestTester.cpp @@ -0,0 +1,80 @@ +// ====================================================================== +// \title SmTestTester.cpp +// \author watney +// \brief cpp file for SmTest test harness implementation class +// ====================================================================== + +#include + +#include "FppTest/state_machine/test/ut/SmTestTester.hpp" +#include "Fw/Types/ExternalString.hpp" +#include "STest/Pick/Pick.hpp" + +namespace FppTest { + +// ---------------------------------------------------------------------- +// Construction and destruction +// ---------------------------------------------------------------------- + +SmTestTester::SmTestTester() + : SmTestGTestBase("SmTestTester", SmTestTester::MAX_HISTORY_SIZE), + component("SmTest") { + this->initComponents(); + this->connectPorts(); + this->component.setIdBase(ID_BASE); +} + +SmTestTester::~SmTestTester() {} + +// ---------------------------------------------------------------------- +// Tests +// ---------------------------------------------------------------------- + +void SmTestTester::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(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::HackSm_Signals::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); + +} + + +// ---------------------------------------------------------------------- +// Helper methods +// ---------------------------------------------------------------------- +void SmTestTester :: + dispatchAll() + { + while (this->component.m_queue.getNumMsgs() > 0) + this->component.doDispatch(); + } + +// ---------------------------------------------------------------------- +// Handlers for typed from ports +// ---------------------------------------------------------------------- + + +} // end namespace FppTest diff --git a/FppTest/state_machine/test/ut/SmTestTester.hpp b/FppTest/state_machine/test/ut/SmTestTester.hpp new file mode 100644 index 0000000000..66021b5622 --- /dev/null +++ b/FppTest/state_machine/test/ut/SmTestTester.hpp @@ -0,0 +1,82 @@ +// ====================================================================== +// \title SmTest/test/ut/Tester.hpp +// \author watney +// \brief hpp file for SmTest test harness implementation class +// ====================================================================== + +#ifndef FppTest_SmTest_Tester_HPP +#define FppTest_SmTest_Tester_HPP + +#include "SmTestGTestBase.hpp" +#include "FppTest/state_machine/SmTest.hpp" +#include "STest/Pick/Pick.hpp" + +namespace FppTest { + +class SmTestTester : public SmTestGTestBase { + // ---------------------------------------------------------------------- + // Construction and destruction + // ---------------------------------------------------------------------- + + public: + // Maximum size of histories storing events, telemetry, and port outputs + static constexpr FwSizeType MAX_HISTORY_SIZE = 10; + // Instance ID supplied to the component instance under test + static constexpr FwSizeType TEST_INSTANCE_ID = 0; + // Queue depth supplied to component instance under test + static constexpr FwSizeType TEST_INSTANCE_QUEUE_DEPTH = 10; + // The component id base + static constexpr FwDpIdType ID_BASE = 100; + // The max string length for string data + static constexpr FwSizeType MAX_STRING_LENGTH = 100; + + //! Construct object Tester + //! + SmTestTester(); + + //! Destroy object Tester + //! + ~SmTestTester(); + + public: + // ---------------------------------------------------------------------- + // Tests + // ---------------------------------------------------------------------- + + //! schedIn OK + void schedIn_OK(); + + + private: + // ---------------------------------------------------------------------- + // Handlers for data product ports + // ---------------------------------------------------------------------- + + private: + // ---------------------------------------------------------------------- + // Helper methods + // ---------------------------------------------------------------------- + + //! Connect ports + //! + void connectPorts(); + + //! Initialize components + //! + void initComponents(); + + void dispatchAll(); + + private: + // ---------------------------------------------------------------------- + // Variables + // ---------------------------------------------------------------------- + + + //! The component under test + SmTest component; +}; + +} // end namespace FppTest + +#endif diff --git a/Fw/CMakeLists.txt b/Fw/CMakeLists.txt index 86291b9083..8905c8647e 100644 --- a/Fw/CMakeLists.txt +++ b/Fw/CMakeLists.txt @@ -14,6 +14,7 @@ add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Tlm/") # Framework subdirectories add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Cfg/") add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Comp/") +add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Sm/") add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/FilePacket/") add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Obj/") add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/Port/") diff --git a/Fw/Sm/CMakeLists.txt b/Fw/Sm/CMakeLists.txt new file mode 100644 index 0000000000..2df8067315 --- /dev/null +++ b/Fw/Sm/CMakeLists.txt @@ -0,0 +1,11 @@ +#### +# F prime CMakeLists.txt: +# +# SOURCE_FILES: combined list of source and autocoding files +# MOD_DEPS: (optional) module dependencies +# +#### +set(SOURCE_FILES + "${CMAKE_CURRENT_LIST_DIR}/SmSignalBuffer.cpp" +) +register_fprime_module() diff --git a/Fw/Sm/README b/Fw/Sm/README new file mode 100644 index 0000000000..c00d7c7621 --- /dev/null +++ b/Fw/Sm/README @@ -0,0 +1 @@ +SmSignalBuffer.hpp(.cpp) - A buffer holding serialized state machine signal data diff --git a/Fw/Sm/SmSignalBuffer.cpp b/Fw/Sm/SmSignalBuffer.cpp new file mode 100644 index 0000000000..66c047b520 --- /dev/null +++ b/Fw/Sm/SmSignalBuffer.cpp @@ -0,0 +1,55 @@ +#include +#include + +namespace Fw { + + SmSignalBuffer::SmSignalBuffer(const U8 *args, Serializable::SizeType size) : m_bufferData{} { + FW_ASSERT(args != nullptr); + FW_ASSERT(size <= sizeof(this->m_bufferData)); + SerializeStatus stat = SerializeBufferBase::setBuff(args,static_cast(size)); + FW_ASSERT(FW_SERIALIZE_OK == stat,static_cast(stat)); + } + + SmSignalBuffer::SmSignalBuffer() : m_bufferData{} { + } + + SmSignalBuffer::~SmSignalBuffer() { + } + + SmSignalBuffer::SmSignalBuffer(const SmSignalBuffer& other) : Fw::SerializeBufferBase(), + m_bufferData{} + { + FW_ASSERT(other.getBuffAddr() != nullptr); + FW_ASSERT(other.getBuffLength() <= sizeof(this->m_bufferData)); + + SerializeStatus stat = SerializeBufferBase::setBuff(other.m_bufferData,other.getBuffLength()); + FW_ASSERT(FW_SERIALIZE_OK == stat,static_cast(stat)); + } + + SmSignalBuffer& SmSignalBuffer::operator=(const SmSignalBuffer& other) { + if(this == &other) { + return *this; + } + + FW_ASSERT(other.getBuffAddr() != nullptr); + FW_ASSERT(other.getBuffLength() <= sizeof(this->m_bufferData)); + + SerializeStatus stat = SerializeBufferBase::setBuff(other.m_bufferData,other.getBuffLength()); + FW_ASSERT(FW_SERIALIZE_OK == stat,static_cast(stat)); + return *this; + } + + Serializable::SizeType SmSignalBuffer::getBuffCapacity() const { + return sizeof(this->m_bufferData); + } + + const U8* SmSignalBuffer::getBuffAddr() const { + return this->m_bufferData; + } + + U8* SmSignalBuffer::getBuffAddr() { + return this->m_bufferData; + } + +} + diff --git a/Fw/Sm/SmSignalBuffer.hpp b/Fw/Sm/SmSignalBuffer.hpp new file mode 100644 index 0000000000..90e7b2d32a --- /dev/null +++ b/Fw/Sm/SmSignalBuffer.hpp @@ -0,0 +1,42 @@ +/* + * SmSignalBuffer.hpp + * + */ + +/* + * Description: + * This object contains the SmSignalBuffer type, used for attaching data to state machine signals + */ +#ifndef FW_SM_SIGNAL_BUFFER_HPP +#define FW_SM_SIGNAL_BUFFER_HPP + +#include +#include + +namespace Fw { + + class SmSignalBuffer : public SerializeBufferBase { + public: + + enum { + SERIALIZED_TYPE_ID = 1010, + SERIALIZED_SIZE = FW_COM_BUFFER_MAX_SIZE + sizeof(FwSizeStoreType) // size of buffer + storage of size word + }; + + SmSignalBuffer(const U8 *args, Serializable::SizeType size); + SmSignalBuffer(); + SmSignalBuffer(const SmSignalBuffer& other); + virtual ~SmSignalBuffer(); + SmSignalBuffer& operator=(const SmSignalBuffer& other); + + Serializable::SizeType getBuffCapacity() const; // !< returns capacity, not current size, of buffer + U8* getBuffAddr(); + const U8* getBuffAddr() const; + + private: + U8 m_bufferData[FW_SM_SIGNAL_BUFFER_MAX_SIZE]; // packet data buffer + }; + +} + +#endif diff --git a/Svc/BufferLogger/Commands.fppi b/Svc/BufferLogger/Commands.fppi index 576929eeed..e8b2636adf 100644 --- a/Svc/BufferLogger/Commands.fppi +++ b/Svc/BufferLogger/Commands.fppi @@ -15,7 +15,7 @@ enum LogState { @ Sets the volatile logging state async command BL_SetLogging( - state: LogState + $state: LogState ) \ opcode 0x02 diff --git a/Svc/DpCatalog/DpCatalog.fpp b/Svc/DpCatalog/DpCatalog.fpp index b5d548505e..06dc6d6702 100644 --- a/Svc/DpCatalog/DpCatalog.fpp +++ b/Svc/DpCatalog/DpCatalog.fpp @@ -21,7 +21,7 @@ module Svc { tSub: U32 $priority: U32 $size: U64 - state: Fw.DpState + $state: Fw.DpState } diff --git a/Svc/SeqDispatcher/SeqDispatcherEvents.fppi b/Svc/SeqDispatcher/SeqDispatcherEvents.fppi index 9b92eca254..ec76d60c96 100644 --- a/Svc/SeqDispatcher/SeqDispatcherEvents.fppi +++ b/Svc/SeqDispatcher/SeqDispatcherEvents.fppi @@ -31,7 +31,7 @@ event UnexpectedSequenceStarted( event LogSequencerStatus( idx: U16 - state: CmdSequencerState + $state: CmdSequencerState filename: string size 240 ) \ severity activity low \ diff --git a/config/FpConfig.h b/config/FpConfig.h index 5e4bde9d65..1646f92a53 100644 --- a/config/FpConfig.h +++ b/config/FpConfig.h @@ -276,6 +276,11 @@ typedef FwIndexType FwQueueSizeType; #define FW_COM_BUFFER_MAX_SIZE 512 #endif +// Specifies the size of the buffer attached to state machine signals. +#ifndef FW_SM_SIGNAL_BUFFER_MAX_SIZE +#define FW_SM_SIGNAL_BUFFER_MAX_SIZE 128 // Not to exceed size of NATIVE_UINT_TYPE +#endif + // Specifies the size of the buffer that contains the serialized command arguments. #ifndef FW_CMD_ARG_BUFFER_MAX_SIZE diff --git a/requirements.txt b/requirements.txt index e051503b91..dfc036df53 100644 --- a/requirements.txt +++ b/requirements.txt @@ -18,18 +18,18 @@ fprime-fpl-convert-xml==1.0.3 fprime-fpl-extract-xml==1.0.3 fprime-fpl-layout==1.0.3 fprime-fpl-write-pic==1.0.3 -fprime-fpp-check==2.2.0a2 -fprime-fpp-depend==2.2.0a2 -fprime-fpp-filenames==2.2.0a2 -fprime-fpp-format==2.2.0a2 -fprime-fpp-from-xml==2.2.0a2 -fprime-fpp-locate-defs==2.2.0a2 -fprime-fpp-locate-uses==2.2.0a2 -fprime-fpp-syntax==2.2.0a2 -fprime-fpp-to-cpp==2.2.0a2 -fprime-fpp-to-dict==2.2.0a2 -fprime-fpp-to-json==2.2.0a2 -fprime-fpp-to-xml==2.2.0a2 +fprime-fpp-check==2.2.0a3 +fprime-fpp-depend==2.2.0a3 +fprime-fpp-filenames==2.2.0a3 +fprime-fpp-format==2.2.0a3 +fprime-fpp-from-xml==2.2.0a3 +fprime-fpp-locate-defs==2.2.0a3 +fprime-fpp-locate-uses==2.2.0a3 +fprime-fpp-syntax==2.2.0a3 +fprime-fpp-to-cpp==2.2.0a3 +fprime-fpp-to-dict==2.2.0a3 +fprime-fpp-to-json==2.2.0a3 +fprime-fpp-to-xml==2.2.0a3 fprime-gds==3.4.4a3 fprime-tools==v3.4.5a1 fprime-visual==1.0.2