Skip to content

Commit

Permalink
Add component state machine getter
Browse files Browse the repository at this point in the history
  • Loading branch information
Kronos3 committed Nov 12, 2024
1 parent d70098f commit 9ee692a
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 1 deletion.
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
getSignalSendMember,
getStateGetterFunction
)
}

Expand Down Expand Up @@ -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") ::
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
// ----------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
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::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:

// ----------------------------------------------------------------------
Expand Down

0 comments on commit 9ee692a

Please sign in to comment.