Skip to content

Commit 2753fd4

Browse files
authored
Merge pull request #532 from nasa/tumbar-sm-getter
Add component state machine getter
2 parents d70098f + d8e689a commit 2753fd4

File tree

4 files changed

+93
-8
lines changed

4 files changed

+93
-8
lines changed

compiler/lib/src/main/scala/codegen/CppWriter/ComponentCppWriter/ComponentStateMachines.scala

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ case class ComponentStateMachines(
2626
def getFunctionMembers: List[CppDoc.Class.Member] = {
2727
List.concat(
2828
getOverflowHooks,
29-
getSignalSendMember
29+
getSignalSendFunctions,
30+
getStateGetterFunctions
3031
)
3132
}
3233

@@ -131,8 +132,8 @@ case class ComponentStateMachines(
131132
CppDoc.Lines.Hpp
132133
)
133134

134-
private def getSignalSendMember: List[CppDoc.Class.Member] = {
135-
lazy val members = stateMachineInstances.map { smi =>
135+
private def getSignalSendFunctions: List[CppDoc.Class.Member] = {
136+
val members = stateMachineInstances.map { smi =>
136137

137138
val serializeCode =
138139
lines(
@@ -194,11 +195,31 @@ case class ComponentStateMachines(
194195

195196
addAccessTagAndComment(
196197
"PROTECTED",
197-
"State machine function to push signals to the input queue",
198-
guardedList (hasStateMachineInstances) (members)
198+
"Functions for sending sending state machine signals to the input queue",
199+
members
199200
)
200201
}
201202

203+
private def getStateGetterFunctions: List[CppDoc.Class.Member] = {
204+
val members = stateMachineInstances.map { smi =>
205+
206+
val smiName = smi.getName
207+
val smName = s.writeSymbol(smi.symbol)
208+
val smEnumName = s"$smName::${s.getName(smi.symbol)}_States";
209+
functionClassMember(
210+
Some(s"Get the state of state machine instance $smiName"),
211+
s"${smiName}_getState",
212+
Nil,
213+
CppDoc.Type(smEnumName, Some(smEnumName)),
214+
lines(s"return this->m_stateMachine_$smiName.state;"),
215+
CppDoc.Function.NonSV,
216+
CppDoc.Function.Const
217+
)
218+
}
219+
220+
addAccessTagAndComment("PROTECTED", "State getter functions", members)
221+
}
222+
202223
private def writeStateMachineUpdate: List[Line] =
203224
Line.blank ::
204225
line("// Call the state machine update function") ::

compiler/tools/fpp-to-cpp/test/component/base/ActiveStateMachinesComponentAc.ref.cpp

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ namespace M {
117117
}
118118

119119
// ----------------------------------------------------------------------
120-
// State machine function to push signals to the input queue
120+
// Functions for sending sending state machine signals to the input queue
121121
// ----------------------------------------------------------------------
122122

123123
void ActiveStateMachinesComponentBase ::
@@ -442,6 +442,46 @@ namespace M {
442442
);
443443
}
444444

445+
// ----------------------------------------------------------------------
446+
// State getter functions
447+
// ----------------------------------------------------------------------
448+
449+
M::ActiveStateMachines_S1::ActiveStateMachines_S1_States ActiveStateMachinesComponentBase ::
450+
sm1_getState() const
451+
{
452+
return this->m_stateMachine_sm1.state;
453+
}
454+
455+
M::ActiveStateMachines_S1::ActiveStateMachines_S1_States ActiveStateMachinesComponentBase ::
456+
sm2_getState() const
457+
{
458+
return this->m_stateMachine_sm2.state;
459+
}
460+
461+
M::ActiveStateMachines_S2::ActiveStateMachines_S2_States ActiveStateMachinesComponentBase ::
462+
sm3_getState() const
463+
{
464+
return this->m_stateMachine_sm3.state;
465+
}
466+
467+
M::ActiveStateMachines_S2::ActiveStateMachines_S2_States ActiveStateMachinesComponentBase ::
468+
sm4_getState() const
469+
{
470+
return this->m_stateMachine_sm4.state;
471+
}
472+
473+
M::ActiveStateMachines_S2::ActiveStateMachines_S2_States ActiveStateMachinesComponentBase ::
474+
sm5_getState() const
475+
{
476+
return this->m_stateMachine_sm5.state;
477+
}
478+
479+
M::ActiveStateMachines_S2::ActiveStateMachines_S2_States ActiveStateMachinesComponentBase ::
480+
sm6_getState() const
481+
{
482+
return this->m_stateMachine_sm6.state;
483+
}
484+
445485
// ----------------------------------------------------------------------
446486
// Message dispatch functions
447487
// ----------------------------------------------------------------------

compiler/tools/fpp-to-cpp/test/component/base/ActiveStateMachinesComponentAc.ref.hpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ namespace M {
9292
PROTECTED:
9393

9494
// ----------------------------------------------------------------------
95-
// State machine function to push signals to the input queue
95+
// Functions for sending sending state machine signals to the input queue
9696
// ----------------------------------------------------------------------
9797

9898
//! State machine base-class function for sendSignals
@@ -131,6 +131,30 @@ namespace M {
131131
const Fw::SmSignalBuffer& data //!< The state machine data
132132
);
133133

134+
PROTECTED:
135+
136+
// ----------------------------------------------------------------------
137+
// State getter functions
138+
// ----------------------------------------------------------------------
139+
140+
//! Get the state of state machine instance sm1
141+
M::ActiveStateMachines_S1::ActiveStateMachines_S1_States sm1_getState() const;
142+
143+
//! Get the state of state machine instance sm2
144+
M::ActiveStateMachines_S1::ActiveStateMachines_S1_States sm2_getState() const;
145+
146+
//! Get the state of state machine instance sm3
147+
M::ActiveStateMachines_S2::ActiveStateMachines_S2_States sm3_getState() const;
148+
149+
//! Get the state of state machine instance sm4
150+
M::ActiveStateMachines_S2::ActiveStateMachines_S2_States sm4_getState() const;
151+
152+
//! Get the state of state machine instance sm5
153+
M::ActiveStateMachines_S2::ActiveStateMachines_S2_States sm5_getState() const;
154+
155+
//! Get the state of state machine instance sm6
156+
M::ActiveStateMachines_S2::ActiveStateMachines_S2_States sm6_getState() const;
157+
134158
PRIVATE:
135159

136160
// ----------------------------------------------------------------------

compiler/tools/fpp-to-cpp/test/fprime/generate_cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ cd `dirname $0`
99
echo "generating framework C++"
1010

1111
fpp_files=`find . -name '*.fpp'`
12-
fpp-to-cpp -p $PWD $fpp_files
12+
../../../../bin/fpp-to-cpp -p $PWD $fpp_files
1313

1414
# Move config files into place
1515
for base in FppConstantsAc ProcTypeEnumAc

0 commit comments

Comments
 (0)