Skip to content

Commit

Permalink
Merge pull request #532 from nasa/tumbar-sm-getter
Browse files Browse the repository at this point in the history
Add component state machine getter
  • Loading branch information
bocchino authored Nov 13, 2024
2 parents d70098f + d8e689a commit 2753fd4
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ case class ComponentStateMachines(
def getFunctionMembers: List[CppDoc.Class.Member] = {
List.concat(
getOverflowHooks,
getSignalSendMember
getSignalSendFunctions,
getStateGetterFunctions
)
}

Expand Down Expand Up @@ -131,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(
Expand Down Expand Up @@ -194,11 +195,31 @@ 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 getStateGetterFunctions: List[CppDoc.Class.Member] = {
val members = stateMachineInstances.map { smi =>

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(smEnumName, Some(smEnumName)),
lines(s"return this->m_stateMachine_$smiName.state;"),
CppDoc.Function.NonSV,
CppDoc.Function.Const
)
}

addAccessTagAndComment("PROTECTED", "State getter functions", members)
}

private def writeStateMachineUpdate: List[Line] =
Line.blank ::
line("// Call the state machine update function") ::
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ::
Expand Down Expand Up @@ -442,6 +442,46 @@ namespace M {
);
}

// ----------------------------------------------------------------------
// State getter functions
// ----------------------------------------------------------------------

M::ActiveStateMachines_S1::ActiveStateMachines_S1_States ActiveStateMachinesComponentBase ::
sm1_getState() const
{
return this->m_stateMachine_sm1.state;
}

M::ActiveStateMachines_S1::ActiveStateMachines_S1_States ActiveStateMachinesComponentBase ::
sm2_getState() const
{
return this->m_stateMachine_sm2.state;
}

M::ActiveStateMachines_S2::ActiveStateMachines_S2_States ActiveStateMachinesComponentBase ::
sm3_getState() const
{
return this->m_stateMachine_sm3.state;
}

M::ActiveStateMachines_S2::ActiveStateMachines_S2_States ActiveStateMachinesComponentBase ::
sm4_getState() const
{
return this->m_stateMachine_sm4.state;
}

M::ActiveStateMachines_S2::ActiveStateMachines_S2_States ActiveStateMachinesComponentBase ::
sm5_getState() const
{
return this->m_stateMachine_sm5.state;
}

M::ActiveStateMachines_S2::ActiveStateMachines_S2_States ActiveStateMachinesComponentBase ::
sm6_getState() const
{
return this->m_stateMachine_sm6.state;
}

// ----------------------------------------------------------------------
// Message dispatch functions
// ----------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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::ActiveStateMachines_S1_States sm1_getState() const;

//! Get the state of state machine instance sm2
M::ActiveStateMachines_S1::ActiveStateMachines_S1_States sm2_getState() const;

//! Get the state of state machine instance sm3
M::ActiveStateMachines_S2::ActiveStateMachines_S2_States sm3_getState() const;

//! Get the state of state machine instance sm4
M::ActiveStateMachines_S2::ActiveStateMachines_S2_States sm4_getState() const;

//! Get the state of state machine instance sm5
M::ActiveStateMachines_S2::ActiveStateMachines_S2_States sm5_getState() const;

//! Get the state of state machine instance sm6
M::ActiveStateMachines_S2::ActiveStateMachines_S2_States sm6_getState() const;

PRIVATE:

// ----------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion compiler/tools/fpp-to-cpp/test/fprime/generate_cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2753fd4

Please sign in to comment.