From 9ee692ac710730183fe30378943cef822cecd799 Mon Sep 17 00:00:00 2001 From: Andrei Tumbar Date: Tue, 12 Nov 2024 10:55:59 -0800 Subject: [PATCH 1/5] Add component state machine getter --- .../ComponentStateMachines.scala | 26 +++++++++++- .../ActiveStateMachinesComponentAc.ref.cpp | 40 +++++++++++++++++++ .../ActiveStateMachinesComponentAc.ref.hpp | 24 +++++++++++ 3 files changed, 89 insertions(+), 1 deletion(-) diff --git a/compiler/lib/src/main/scala/codegen/CppWriter/ComponentCppWriter/ComponentStateMachines.scala b/compiler/lib/src/main/scala/codegen/CppWriter/ComponentCppWriter/ComponentStateMachines.scala index d49304f32..28c5778ee 100644 --- a/compiler/lib/src/main/scala/codegen/CppWriter/ComponentCppWriter/ComponentStateMachines.scala +++ b/compiler/lib/src/main/scala/codegen/CppWriter/ComponentCppWriter/ComponentStateMachines.scala @@ -26,7 +26,8 @@ case class ComponentStateMachines( def getFunctionMembers: List[CppDoc.Class.Member] = { List.concat( getOverflowHooks, - getSignalSendMember + getSignalSendMember, + getStateGetterFunction ) } @@ -199,6 +200,29 @@ case class ComponentStateMachines( ) } + private def getStateGetterFunction: List[CppDoc.Class.Member] = { + lazy val members = stateMachineInstances.map { smi => + + val smiName = smi.getName + val smName = s.writeSymbol(smi.symbol) + functionClassMember( + Some(s"Get the state of state machine instance $smiName"), + s"${smiName}_getState", + Nil, + CppDoc.Type(s"$smName::State", Some(s"$name::$smName::State")), + lines(s"return this->m_stateMachine_$smiName.state;"), + CppDoc.Function.NonSV, + CppDoc.Function.Const + ) + } + + addAccessTagAndComment( + "PROTECTED", + "State getter functions", + guardedList (hasStateMachineInstances) (members) + ) + } + private def writeStateMachineUpdate: List[Line] = Line.blank :: line("// Call the state machine update function") :: diff --git a/compiler/tools/fpp-to-cpp/test/component/base/ActiveStateMachinesComponentAc.ref.cpp b/compiler/tools/fpp-to-cpp/test/component/base/ActiveStateMachinesComponentAc.ref.cpp index 7340dd5eb..bc18d40e9 100644 --- a/compiler/tools/fpp-to-cpp/test/component/base/ActiveStateMachinesComponentAc.ref.cpp +++ b/compiler/tools/fpp-to-cpp/test/component/base/ActiveStateMachinesComponentAc.ref.cpp @@ -442,6 +442,46 @@ namespace M { ); } + // ---------------------------------------------------------------------- + // State getter functions + // ---------------------------------------------------------------------- + + ActiveStateMachines::M::ActiveStateMachines_S1::State ActiveStateMachinesComponentBase :: + sm1_getState() const + { + return this->m_stateMachine_sm1.state; + } + + ActiveStateMachines::M::ActiveStateMachines_S1::State ActiveStateMachinesComponentBase :: + sm2_getState() const + { + return this->m_stateMachine_sm2.state; + } + + ActiveStateMachines::M::ActiveStateMachines_S2::State ActiveStateMachinesComponentBase :: + sm3_getState() const + { + return this->m_stateMachine_sm3.state; + } + + ActiveStateMachines::M::ActiveStateMachines_S2::State ActiveStateMachinesComponentBase :: + sm4_getState() const + { + return this->m_stateMachine_sm4.state; + } + + ActiveStateMachines::M::ActiveStateMachines_S2::State ActiveStateMachinesComponentBase :: + sm5_getState() const + { + return this->m_stateMachine_sm5.state; + } + + ActiveStateMachines::M::ActiveStateMachines_S2::State ActiveStateMachinesComponentBase :: + sm6_getState() const + { + return this->m_stateMachine_sm6.state; + } + // ---------------------------------------------------------------------- // Message dispatch functions // ---------------------------------------------------------------------- diff --git a/compiler/tools/fpp-to-cpp/test/component/base/ActiveStateMachinesComponentAc.ref.hpp b/compiler/tools/fpp-to-cpp/test/component/base/ActiveStateMachinesComponentAc.ref.hpp index 52fecf7b6..89d41d94d 100644 --- a/compiler/tools/fpp-to-cpp/test/component/base/ActiveStateMachinesComponentAc.ref.hpp +++ b/compiler/tools/fpp-to-cpp/test/component/base/ActiveStateMachinesComponentAc.ref.hpp @@ -131,6 +131,30 @@ namespace M { const Fw::SmSignalBuffer& data //!< The state machine data ); + PROTECTED: + + // ---------------------------------------------------------------------- + // State getter functions + // ---------------------------------------------------------------------- + + //! Get the state of state machine instance sm1 + M::ActiveStateMachines_S1::State sm1_getState() const; + + //! Get the state of state machine instance sm2 + M::ActiveStateMachines_S1::State sm2_getState() const; + + //! Get the state of state machine instance sm3 + M::ActiveStateMachines_S2::State sm3_getState() const; + + //! Get the state of state machine instance sm4 + M::ActiveStateMachines_S2::State sm4_getState() const; + + //! Get the state of state machine instance sm5 + M::ActiveStateMachines_S2::State sm5_getState() const; + + //! Get the state of state machine instance sm6 + M::ActiveStateMachines_S2::State sm6_getState() const; + PRIVATE: // ---------------------------------------------------------------------- From dba95ff88180e1fd6d5335f648cf26712b555983 Mon Sep 17 00:00:00 2001 From: Andrei Tumbar Date: Tue, 12 Nov 2024 18:31:31 -0800 Subject: [PATCH 2/5] Fix and cpp-check --- .../ComponentCppWriter/ComponentStateMachines.scala | 3 ++- .../base/ActiveStateMachinesComponentAc.ref.cpp | 12 ++++++------ .../base/ActiveStateMachinesComponentAc.ref.hpp | 12 ++++++------ 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/compiler/lib/src/main/scala/codegen/CppWriter/ComponentCppWriter/ComponentStateMachines.scala b/compiler/lib/src/main/scala/codegen/CppWriter/ComponentCppWriter/ComponentStateMachines.scala index 28c5778ee..5df925124 100644 --- a/compiler/lib/src/main/scala/codegen/CppWriter/ComponentCppWriter/ComponentStateMachines.scala +++ b/compiler/lib/src/main/scala/codegen/CppWriter/ComponentCppWriter/ComponentStateMachines.scala @@ -205,11 +205,12 @@ case class ComponentStateMachines( val smiName = smi.getName val smName = s.writeSymbol(smi.symbol) + val smEnumName = s"$smName::${s.getName(smi.symbol)}_States"; functionClassMember( Some(s"Get the state of state machine instance $smiName"), s"${smiName}_getState", Nil, - CppDoc.Type(s"$smName::State", Some(s"$name::$smName::State")), + CppDoc.Type(smEnumName, Some(smEnumName)), lines(s"return this->m_stateMachine_$smiName.state;"), CppDoc.Function.NonSV, CppDoc.Function.Const diff --git a/compiler/tools/fpp-to-cpp/test/component/base/ActiveStateMachinesComponentAc.ref.cpp b/compiler/tools/fpp-to-cpp/test/component/base/ActiveStateMachinesComponentAc.ref.cpp index bc18d40e9..05fa61b7b 100644 --- a/compiler/tools/fpp-to-cpp/test/component/base/ActiveStateMachinesComponentAc.ref.cpp +++ b/compiler/tools/fpp-to-cpp/test/component/base/ActiveStateMachinesComponentAc.ref.cpp @@ -446,37 +446,37 @@ namespace M { // State getter functions // ---------------------------------------------------------------------- - ActiveStateMachines::M::ActiveStateMachines_S1::State ActiveStateMachinesComponentBase :: + M::ActiveStateMachines_S1::ActiveStateMachines_S1_States ActiveStateMachinesComponentBase :: sm1_getState() const { return this->m_stateMachine_sm1.state; } - ActiveStateMachines::M::ActiveStateMachines_S1::State ActiveStateMachinesComponentBase :: + M::ActiveStateMachines_S1::ActiveStateMachines_S1_States ActiveStateMachinesComponentBase :: sm2_getState() const { return this->m_stateMachine_sm2.state; } - ActiveStateMachines::M::ActiveStateMachines_S2::State ActiveStateMachinesComponentBase :: + M::ActiveStateMachines_S2::ActiveStateMachines_S2_States ActiveStateMachinesComponentBase :: sm3_getState() const { return this->m_stateMachine_sm3.state; } - ActiveStateMachines::M::ActiveStateMachines_S2::State ActiveStateMachinesComponentBase :: + M::ActiveStateMachines_S2::ActiveStateMachines_S2_States ActiveStateMachinesComponentBase :: sm4_getState() const { return this->m_stateMachine_sm4.state; } - ActiveStateMachines::M::ActiveStateMachines_S2::State ActiveStateMachinesComponentBase :: + M::ActiveStateMachines_S2::ActiveStateMachines_S2_States ActiveStateMachinesComponentBase :: sm5_getState() const { return this->m_stateMachine_sm5.state; } - ActiveStateMachines::M::ActiveStateMachines_S2::State ActiveStateMachinesComponentBase :: + M::ActiveStateMachines_S2::ActiveStateMachines_S2_States ActiveStateMachinesComponentBase :: sm6_getState() const { return this->m_stateMachine_sm6.state; diff --git a/compiler/tools/fpp-to-cpp/test/component/base/ActiveStateMachinesComponentAc.ref.hpp b/compiler/tools/fpp-to-cpp/test/component/base/ActiveStateMachinesComponentAc.ref.hpp index 89d41d94d..13c98b5ed 100644 --- a/compiler/tools/fpp-to-cpp/test/component/base/ActiveStateMachinesComponentAc.ref.hpp +++ b/compiler/tools/fpp-to-cpp/test/component/base/ActiveStateMachinesComponentAc.ref.hpp @@ -138,22 +138,22 @@ namespace M { // ---------------------------------------------------------------------- //! Get the state of state machine instance sm1 - M::ActiveStateMachines_S1::State sm1_getState() const; + M::ActiveStateMachines_S1::ActiveStateMachines_S1_States sm1_getState() const; //! Get the state of state machine instance sm2 - M::ActiveStateMachines_S1::State sm2_getState() const; + M::ActiveStateMachines_S1::ActiveStateMachines_S1_States sm2_getState() const; //! Get the state of state machine instance sm3 - M::ActiveStateMachines_S2::State sm3_getState() const; + M::ActiveStateMachines_S2::ActiveStateMachines_S2_States sm3_getState() const; //! Get the state of state machine instance sm4 - M::ActiveStateMachines_S2::State sm4_getState() const; + M::ActiveStateMachines_S2::ActiveStateMachines_S2_States sm4_getState() const; //! Get the state of state machine instance sm5 - M::ActiveStateMachines_S2::State sm5_getState() const; + M::ActiveStateMachines_S2::ActiveStateMachines_S2_States sm5_getState() const; //! Get the state of state machine instance sm6 - M::ActiveStateMachines_S2::State sm6_getState() const; + M::ActiveStateMachines_S2::ActiveStateMachines_S2_States sm6_getState() const; PRIVATE: From 4f135683e95231f59f5ea56706a303ea9bb578dc Mon Sep 17 00:00:00 2001 From: Rob Bocchino Date: Wed, 13 Nov 2024 07:47:33 -0800 Subject: [PATCH 3/5] Fix path to fpp-to-cpp --- compiler/tools/fpp-to-cpp/test/fprime/generate_cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/tools/fpp-to-cpp/test/fprime/generate_cpp b/compiler/tools/fpp-to-cpp/test/fprime/generate_cpp index d33ebbdcf..ebd8417dd 100755 --- a/compiler/tools/fpp-to-cpp/test/fprime/generate_cpp +++ b/compiler/tools/fpp-to-cpp/test/fprime/generate_cpp @@ -9,7 +9,7 @@ cd `dirname $0` echo "generating framework C++" fpp_files=`find . -name '*.fpp'` -fpp-to-cpp -p $PWD $fpp_files +../../../../bin/fpp-to-cpp -p $PWD $fpp_files # Move config files into place for base in FppConstantsAc ProcTypeEnumAc From c7a2446b281a66020d42f6f2a154f3627e877f84 Mon Sep 17 00:00:00 2001 From: Rob Bocchino Date: Wed, 13 Nov 2024 08:04:11 -0800 Subject: [PATCH 4/5] Remove guarded list It's not needed, since the guard is true if and only if the computed list is nonempty. --- .../ComponentCppWriter/ComponentStateMachines.scala | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/compiler/lib/src/main/scala/codegen/CppWriter/ComponentCppWriter/ComponentStateMachines.scala b/compiler/lib/src/main/scala/codegen/CppWriter/ComponentCppWriter/ComponentStateMachines.scala index 5df925124..8bf5b45a4 100644 --- a/compiler/lib/src/main/scala/codegen/CppWriter/ComponentCppWriter/ComponentStateMachines.scala +++ b/compiler/lib/src/main/scala/codegen/CppWriter/ComponentCppWriter/ComponentStateMachines.scala @@ -201,7 +201,7 @@ case class ComponentStateMachines( } private def getStateGetterFunction: List[CppDoc.Class.Member] = { - lazy val members = stateMachineInstances.map { smi => + val members = stateMachineInstances.map { smi => val smiName = smi.getName val smName = s.writeSymbol(smi.symbol) @@ -217,11 +217,7 @@ case class ComponentStateMachines( ) } - addAccessTagAndComment( - "PROTECTED", - "State getter functions", - guardedList (hasStateMachineInstances) (members) - ) + addAccessTagAndComment("PROTECTED", "State getter functions", members) } private def writeStateMachineUpdate: List[Line] = From d8e689a17913ab8080417f3582f8fdeb8108fdb0 Mon Sep 17 00:00:00 2001 From: Rob Bocchino Date: Wed, 13 Nov 2024 09:01:24 -0800 Subject: [PATCH 5/5] Minor cleanup to related code --- .../ComponentStateMachines.scala | 14 +++++++------- .../base/ActiveStateMachinesComponentAc.ref.cpp | 2 +- .../base/ActiveStateMachinesComponentAc.ref.hpp | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/compiler/lib/src/main/scala/codegen/CppWriter/ComponentCppWriter/ComponentStateMachines.scala b/compiler/lib/src/main/scala/codegen/CppWriter/ComponentCppWriter/ComponentStateMachines.scala index 8bf5b45a4..c6ff91835 100644 --- a/compiler/lib/src/main/scala/codegen/CppWriter/ComponentCppWriter/ComponentStateMachines.scala +++ b/compiler/lib/src/main/scala/codegen/CppWriter/ComponentCppWriter/ComponentStateMachines.scala @@ -26,8 +26,8 @@ case class ComponentStateMachines( def getFunctionMembers: List[CppDoc.Class.Member] = { List.concat( getOverflowHooks, - getSignalSendMember, - getStateGetterFunction + getSignalSendFunctions, + getStateGetterFunctions ) } @@ -132,8 +132,8 @@ case class ComponentStateMachines( CppDoc.Lines.Hpp ) - private def getSignalSendMember: List[CppDoc.Class.Member] = { - lazy val members = stateMachineInstances.map { smi => + private def getSignalSendFunctions: List[CppDoc.Class.Member] = { + val members = stateMachineInstances.map { smi => val serializeCode = lines( @@ -195,12 +195,12 @@ case class ComponentStateMachines( addAccessTagAndComment( "PROTECTED", - "State machine function to push signals to the input queue", - guardedList (hasStateMachineInstances) (members) + "Functions for sending sending state machine signals to the input queue", + members ) } - private def getStateGetterFunction: List[CppDoc.Class.Member] = { + private def getStateGetterFunctions: List[CppDoc.Class.Member] = { val members = stateMachineInstances.map { smi => val smiName = smi.getName diff --git a/compiler/tools/fpp-to-cpp/test/component/base/ActiveStateMachinesComponentAc.ref.cpp b/compiler/tools/fpp-to-cpp/test/component/base/ActiveStateMachinesComponentAc.ref.cpp index 05fa61b7b..bbf6533dd 100644 --- a/compiler/tools/fpp-to-cpp/test/component/base/ActiveStateMachinesComponentAc.ref.cpp +++ b/compiler/tools/fpp-to-cpp/test/component/base/ActiveStateMachinesComponentAc.ref.cpp @@ -117,7 +117,7 @@ namespace M { } // ---------------------------------------------------------------------- - // State machine function to push signals to the input queue + // Functions for sending sending state machine signals to the input queue // ---------------------------------------------------------------------- void ActiveStateMachinesComponentBase :: diff --git a/compiler/tools/fpp-to-cpp/test/component/base/ActiveStateMachinesComponentAc.ref.hpp b/compiler/tools/fpp-to-cpp/test/component/base/ActiveStateMachinesComponentAc.ref.hpp index 13c98b5ed..a57d4aa6a 100644 --- a/compiler/tools/fpp-to-cpp/test/component/base/ActiveStateMachinesComponentAc.ref.hpp +++ b/compiler/tools/fpp-to-cpp/test/component/base/ActiveStateMachinesComponentAc.ref.hpp @@ -92,7 +92,7 @@ namespace M { PROTECTED: // ---------------------------------------------------------------------- - // State machine function to push signals to the input queue + // Functions for sending sending state machine signals to the input queue // ---------------------------------------------------------------------- //! State machine base-class function for sendSignals