Skip to content

Commit

Permalink
Revise state machine code gen
Browse files Browse the repository at this point in the history
  • Loading branch information
bocchino committed Sep 4, 2024
1 parent 37ea7d9 commit e20c6fd
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,6 @@ case class ComponentStateMachines(
)
}

def getInternalInterfaceHandler: List[Line] =
Line.blank ::
line("// Call the state machine update function") ::
wrapInSwitch(
"stateMachineId",
stateMachineInstances.flatMap((smi) => {
val smName = s.writeSymbol(smi.symbol)
val enumName = s.getName(smi.symbol)

Line.blank ::
lines(
s"""|case STATE_MACHINE_${smi.getName.toUpperCase}: {
| ${smName}_Interface::${enumName}_Signals signal =
| static_cast<${smName}_Interface::${enumName}_Signals>(enumStoreSmSignal);
| this->m_stateMachine_${smi.getName}.update(stateMachineId, signal, data);
| break;
|}"""
)
})
)

/** Gets the state machine interfaces */
def getSmInterfaces: String =
smSymbols.map(symbol => s", public ${s.writeSymbol(symbol)}_Interface").
Expand Down Expand Up @@ -80,43 +59,45 @@ case class ComponentStateMachines(

/** Writes the dispatch case, if any, for state machine instances */
def writeDispatch: List[Line] = {
lazy val caseBody = List.concat(
lines(
s"""|// Deserialize the state machine ID
|FwEnumStoreType enumStoreSmId = 0;
|Fw::SerializeStatus deserStatus = msg.deserialize(enumStoreSmId);
|FW_ASSERT(
| deserStatus == Fw::FW_SERIALIZE_OK,
| static_cast<FwAssertArgType>(deserStatus)
|);
|SmId stateMachineId = static_cast<SmId>(enumStoreSmId);
|
|// Deserialize the state machine signal
|FwEnumStoreType enumStoreSmSignal = 0;
|deserStatus = msg.deserialize(enumStoreSmSignal);
|FW_ASSERT(
| deserStatus == Fw::FW_SERIALIZE_OK,
| static_cast<FwAssertArgType>(deserStatus)
|);
|
|// Deserialize the state machine data
|Fw::SmSignalBuffer data;
|deserStatus = msg.deserialize(data);
|FW_ASSERT(
| Fw::FW_SERIALIZE_OK == deserStatus,
| static_cast<FwAssertArgType>(deserStatus)
|);
|
|// Make sure there was no data left over.
|// That means the buffer size was incorrect.
|FW_ASSERT(
| msg.getBuffLeft() == 0,
| static_cast<FwAssertArgType>(msg.getBuffLeft())
|);"""
),
getInternalInterfaceHandler,
lines("\nbreak;")
)
lazy val caseBody =
Line.blank ::
List.concat(
lines(
s"""|// Deserialize the state machine ID
|FwEnumStoreType enumStoreSmId = 0;
|Fw::SerializeStatus deserStatus = msg.deserialize(enumStoreSmId);
|FW_ASSERT(
| deserStatus == Fw::FW_SERIALIZE_OK,
| static_cast<FwAssertArgType>(deserStatus)
|);
|SmId stateMachineId = static_cast<SmId>(enumStoreSmId);
|
|// Deserialize the state machine signal
|FwEnumStoreType enumStoreSmSignal = 0;
|deserStatus = msg.deserialize(enumStoreSmSignal);
|FW_ASSERT(
| deserStatus == Fw::FW_SERIALIZE_OK,
| static_cast<FwAssertArgType>(deserStatus)
|);
|
|// Deserialize the state machine data
|Fw::SmSignalBuffer data;
|deserStatus = msg.deserialize(data);
|FW_ASSERT(
| Fw::FW_SERIALIZE_OK == deserStatus,
| static_cast<FwAssertArgType>(deserStatus)
|);
|
|// Make sure there was no data left over.
|// That means the buffer size was incorrect.
|FW_ASSERT(
| msg.getBuffLeft() == 0,
| static_cast<FwAssertArgType>(msg.getBuffLeft())
|);"""
),
writeStateMachineUpdate,
lines("\nbreak;")
)
lazy val caseStmt =
Line.blank ::
line(s"// Handle state machine signals") ::
Expand Down Expand Up @@ -215,6 +196,33 @@ case class ComponentStateMachines(
)
}

private def writeStateMachineUpdate: List[Line] =
Line.blank ::
line("// Call the state machine update function") ::
wrapInSwitch(
"stateMachineId",
List.concat(
stateMachineInstances.flatMap((smi) => {
val smName = s.writeSymbol(smi.symbol)
val enumName = s.getName(smi.symbol)
Line.blank ::
lines(
s"""|case STATE_MACHINE_${smi.getName.toUpperCase}: {
| ${smName}_Interface::${enumName}_Signals signal =
| static_cast<${smName}_Interface::${enumName}_Signals>(enumStoreSmSignal);
| this->m_stateMachine_${smi.getName}.update(stateMachineId, signal, data);
| break;
|}"""
)
}),
Line.blank :: lines(
s"""|default:
| FW_ASSERT(0, static_cast<FwAssertArgType>(stateMachineId));
| break;"""
)
)
)

}

object ComponentStateMachines {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@ namespace M {

// Handle state machine signals
case STATEMACHINE_SENDSIGNALS: {

// Deserialize the state machine ID
FwEnumStoreType enumStoreSmId = 0;
Fw::SerializeStatus deserStatus = msg.deserialize(enumStoreSmId);
Expand Down Expand Up @@ -565,6 +566,10 @@ namespace M {
this->m_stateMachine_sm6.update(stateMachineId, signal, data);
break;
}

default:
FW_ASSERT(0, static_cast<FwAssertArgType>(stateMachineId));
break;
}

break;
Expand Down

0 comments on commit e20c6fd

Please sign in to comment.