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 9e67d33 commit 37ea7d9
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 177 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ case class ComponentStateMachines(
}

def getInternalInterfaceHandler: List[Line] =
Line.blank ::
line("// Call the state machine update function") ::
wrapInSwitch(
"stateMachineId",
stateMachineInstances.flatMap((smi) => {
Expand All @@ -40,37 +42,13 @@ case class ComponentStateMachines(
Line.blank ::
lines(
s"""|case STATE_MACHINE_${smi.getName.toUpperCase}: {
| // Deserialize the state machine signal
| FwEnumStoreType desMsg = 0;
| Fw::SerializeStatus deserStatus = msg.deserialize(desMsg);
| FW_ASSERT(
| deserStatus == Fw::FW_SERIALIZE_OK,
| static_cast<FwAssertArgType>(deserStatus)
| );
| ${smName}_Interface::${enumName}_Signals signal =
| static_cast<${smName}_Interface::${enumName}_Signals>(desMsg);
|
| // 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())
| );
|
| static_cast<${smName}_Interface::${enumName}_Signals>(enumStoreSmSignal);
| this->m_stateMachine_${smi.getName}.update(stateMachineId, signal, data);
| break;
|}"""
)
}
)
})
)

/** Gets the state machine interfaces */
Expand Down Expand Up @@ -104,14 +82,37 @@ case class ComponentStateMachines(
def writeDispatch: List[Line] = {
lazy val caseBody = List.concat(
lines(
s"""|
|FwEnumStoreType desMsg = 0;
|Fw::SerializeStatus deserStatus = msg.deserialize(desMsg);
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>(desMsg);"""
|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;")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,192 +489,79 @@ namespace M {

// Handle state machine signals
case STATEMACHINE_SENDSIGNALS: {
// 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);

FwEnumStoreType desMsg = 0;
Fw::SerializeStatus deserStatus = msg.deserialize(desMsg);
// Deserialize the state machine signal
FwEnumStoreType enumStoreSmSignal = 0;
deserStatus = msg.deserialize(enumStoreSmSignal);
FW_ASSERT(
deserStatus == Fw::FW_SERIALIZE_OK,
static_cast<FwAssertArgType>(deserStatus)
);
SmId stateMachineId = static_cast<SmId>(desMsg);

// 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())
);

// Call the state machine update function
switch (stateMachineId) {

case STATE_MACHINE_SM1: {
// Deserialize the state machine signal
FwEnumStoreType desMsg = 0;
Fw::SerializeStatus deserStatus = msg.deserialize(desMsg);
FW_ASSERT(
deserStatus == Fw::FW_SERIALIZE_OK,
static_cast<FwAssertArgType>(deserStatus)
);
M::ActiveStateMachines_S1_Interface::ActiveStateMachines_S1_Signals signal =
static_cast<M::ActiveStateMachines_S1_Interface::ActiveStateMachines_S1_Signals>(desMsg);

// 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())
);

static_cast<M::ActiveStateMachines_S1_Interface::ActiveStateMachines_S1_Signals>(enumStoreSmSignal);
this->m_stateMachine_sm1.update(stateMachineId, signal, data);
break;
}

case STATE_MACHINE_SM2: {
// Deserialize the state machine signal
FwEnumStoreType desMsg = 0;
Fw::SerializeStatus deserStatus = msg.deserialize(desMsg);
FW_ASSERT(
deserStatus == Fw::FW_SERIALIZE_OK,
static_cast<FwAssertArgType>(deserStatus)
);
M::ActiveStateMachines_S1_Interface::ActiveStateMachines_S1_Signals signal =
static_cast<M::ActiveStateMachines_S1_Interface::ActiveStateMachines_S1_Signals>(desMsg);

// 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())
);

static_cast<M::ActiveStateMachines_S1_Interface::ActiveStateMachines_S1_Signals>(enumStoreSmSignal);
this->m_stateMachine_sm2.update(stateMachineId, signal, data);
break;
}

case STATE_MACHINE_SM3: {
// Deserialize the state machine signal
FwEnumStoreType desMsg = 0;
Fw::SerializeStatus deserStatus = msg.deserialize(desMsg);
FW_ASSERT(
deserStatus == Fw::FW_SERIALIZE_OK,
static_cast<FwAssertArgType>(deserStatus)
);
M::ActiveStateMachines_S2_Interface::ActiveStateMachines_S2_Signals signal =
static_cast<M::ActiveStateMachines_S2_Interface::ActiveStateMachines_S2_Signals>(desMsg);

// 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())
);

static_cast<M::ActiveStateMachines_S2_Interface::ActiveStateMachines_S2_Signals>(enumStoreSmSignal);
this->m_stateMachine_sm3.update(stateMachineId, signal, data);
break;
}

case STATE_MACHINE_SM4: {
// Deserialize the state machine signal
FwEnumStoreType desMsg = 0;
Fw::SerializeStatus deserStatus = msg.deserialize(desMsg);
FW_ASSERT(
deserStatus == Fw::FW_SERIALIZE_OK,
static_cast<FwAssertArgType>(deserStatus)
);
M::ActiveStateMachines_S2_Interface::ActiveStateMachines_S2_Signals signal =
static_cast<M::ActiveStateMachines_S2_Interface::ActiveStateMachines_S2_Signals>(desMsg);

// 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())
);

static_cast<M::ActiveStateMachines_S2_Interface::ActiveStateMachines_S2_Signals>(enumStoreSmSignal);
this->m_stateMachine_sm4.update(stateMachineId, signal, data);
break;
}

case STATE_MACHINE_SM5: {
// Deserialize the state machine signal
FwEnumStoreType desMsg = 0;
Fw::SerializeStatus deserStatus = msg.deserialize(desMsg);
FW_ASSERT(
deserStatus == Fw::FW_SERIALIZE_OK,
static_cast<FwAssertArgType>(deserStatus)
);
M::ActiveStateMachines_S2_Interface::ActiveStateMachines_S2_Signals signal =
static_cast<M::ActiveStateMachines_S2_Interface::ActiveStateMachines_S2_Signals>(desMsg);

// 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())
);

static_cast<M::ActiveStateMachines_S2_Interface::ActiveStateMachines_S2_Signals>(enumStoreSmSignal);
this->m_stateMachine_sm5.update(stateMachineId, signal, data);
break;
}

case STATE_MACHINE_SM6: {
// Deserialize the state machine signal
FwEnumStoreType desMsg = 0;
Fw::SerializeStatus deserStatus = msg.deserialize(desMsg);
FW_ASSERT(
deserStatus == Fw::FW_SERIALIZE_OK,
static_cast<FwAssertArgType>(deserStatus)
);
M::ActiveStateMachines_S2_Interface::ActiveStateMachines_S2_Signals signal =
static_cast<M::ActiveStateMachines_S2_Interface::ActiveStateMachines_S2_Signals>(desMsg);

// 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())
);

static_cast<M::ActiveStateMachines_S2_Interface::ActiveStateMachines_S2_Signals>(enumStoreSmSignal);
this->m_stateMachine_sm6.update(stateMachineId, signal, data);
break;
}
Expand Down

0 comments on commit 37ea7d9

Please sign in to comment.