Skip to content

Commit

Permalink
Fix nasa#96, Moved command validation out of command functions
Browse files Browse the repository at this point in the history
  • Loading branch information
havencarlson committed Sep 1, 2023
1 parent 2733b00 commit 7c8589f
Show file tree
Hide file tree
Showing 6 changed files with 424 additions and 467 deletions.
18 changes: 0 additions & 18 deletions fsw/src/sc_atsrq.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ void SC_StartAtsCmd(const CFE_SB_Buffer_t *BufPtr)
uint16 AtsId; /* ATS ID */
uint16 AtsIndex; /* ATS array index */

if (SC_VerifyCmdLength(&BufPtr->Msg, sizeof(SC_StartAtsCmd_t)))
{
AtsId = ((SC_StartAtsCmd_t *)BufPtr)->AtsId;

/* validate ATS ID */
Expand Down Expand Up @@ -120,7 +118,6 @@ void SC_StartAtsCmd(const CFE_SB_Buffer_t *BufPtr)
SC_OperData.HkPacket.CmdErrCtr++;

} /* end if */
}
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Expand All @@ -133,8 +130,6 @@ void SC_StopAtsCmd(const CFE_SB_Buffer_t *BufPtr)
char TempAtsChar = ' ';
int32 Result = SC_ERROR;

if (SC_VerifyCmdLength(&BufPtr->Msg, sizeof(SC_NoArgsCmd_t)))
{
/*
** Set the temp ATS ID if it is valid
*/
Expand Down Expand Up @@ -169,7 +164,6 @@ void SC_StopAtsCmd(const CFE_SB_Buffer_t *BufPtr)
SC_OperData.AtsCtrlBlckAddr->SwitchPendFlag = false;

SC_OperData.HkPacket.CmdCtr++;
}
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Expand Down Expand Up @@ -301,8 +295,6 @@ void SC_GroundSwitchCmd(const CFE_SB_Buffer_t *BufPtr)
{
uint16 NewAtsIndex; /* the index of the ats to switch to*/

if (SC_VerifyCmdLength(&BufPtr->Msg, sizeof(SC_NoArgsCmd_t)))
{
/* make sure that an ATS is running on the ATP */
if (SC_OperData.AtsCtrlBlckAddr->AtpState == SC_EXECUTING)
{
Expand Down Expand Up @@ -345,7 +337,6 @@ void SC_GroundSwitchCmd(const CFE_SB_Buffer_t *BufPtr)
SC_OperData.AtsCtrlBlckAddr->SwitchPendFlag = false;

} /* end if */
}
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Expand Down Expand Up @@ -504,8 +495,6 @@ void SC_JumpAtsCmd(const CFE_SB_Buffer_t *BufPtr)
CFE_TIME_SysTime_t NewTime;
uint16 NumSkipped;

if (SC_VerifyCmdLength(&BufPtr->Msg, sizeof(SC_JumpAtsCmd_t)))
{
if (SC_OperData.AtsCtrlBlckAddr->AtpState == SC_EXECUTING)
{
JumpTime = ((SC_JumpAtsCmd_t *)BufPtr)->NewTime;
Expand Down Expand Up @@ -612,7 +601,6 @@ void SC_JumpAtsCmd(const CFE_SB_Buffer_t *BufPtr)
SC_OperData.HkPacket.CmdErrCtr++;

} /* end if */
}
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Expand All @@ -624,8 +612,6 @@ void SC_ContinueAtsOnFailureCmd(const CFE_SB_Buffer_t *BufPtr)
{
uint16 State;

if (SC_VerifyCmdLength(&BufPtr->Msg, sizeof(SC_SetContinueAtsOnFailureCmd_t)))
{
State = ((SC_SetContinueAtsOnFailureCmd_t *)BufPtr)->ContinueState;

if (State != SC_CONTINUE_TRUE && State != SC_CONTINUE_FALSE)
Expand All @@ -644,7 +630,6 @@ void SC_ContinueAtsOnFailureCmd(const CFE_SB_Buffer_t *BufPtr)
CFE_EVS_SendEvent(SC_CONT_CMD_DEB_EID, CFE_EVS_EventType_DEBUG,
"Continue-ATS-On-Failure command, State: %d", State);
}
}
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Expand All @@ -657,8 +642,6 @@ void SC_AppendAtsCmd(const CFE_SB_Buffer_t *BufPtr)
SC_AppendAtsCmd_t *AppendCmd = (SC_AppendAtsCmd_t *)BufPtr;
uint16 AtsIndex; /* index (not ID) of target ATS */

if (SC_VerifyCmdLength(&BufPtr->Msg, sizeof(SC_AppendAtsCmd_t)))
{
if ((AppendCmd->AtsId == 0) || (AppendCmd->AtsId > SC_NUMBER_OF_ATS))
{
/* invalid target ATS selection */
Expand Down Expand Up @@ -714,5 +697,4 @@ void SC_AppendAtsCmd(const CFE_SB_Buffer_t *BufPtr)
"Append ATS %c command: %d ATS entries appended", 'A' + AtsIndex,
SC_OperData.HkPacket.AppendEntryCount);
}
}
}
96 changes: 73 additions & 23 deletions fsw/src/sc_cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -475,8 +475,6 @@ void SC_SendHkPacket(void)

void SC_ResetCountersCmd(const CFE_SB_Buffer_t *BufPtr)
{
if (SC_VerifyCmdLength(&BufPtr->Msg, sizeof(SC_NoArgsCmd_t)))
{
CFE_EVS_SendEvent(SC_RESET_DEB_EID, CFE_EVS_EventType_DEBUG, "Reset counters command");

SC_OperData.HkPacket.CmdCtr = 0;
Expand All @@ -487,7 +485,6 @@ void SC_ResetCountersCmd(const CFE_SB_Buffer_t *BufPtr)
SC_OperData.HkPacket.RtsCmdErrCtr = 0;
SC_OperData.HkPacket.RtsActiveCtr = 0;
SC_OperData.HkPacket.RtsActiveErrCtr = 0;
}
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Expand All @@ -497,12 +494,9 @@ void SC_ResetCountersCmd(const CFE_SB_Buffer_t *BufPtr)
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void SC_NoOpCmd(const CFE_SB_Buffer_t *BufPtr)
{
if (SC_VerifyCmdLength(&BufPtr->Msg, sizeof(SC_NoArgsCmd_t)))
{
SC_OperData.HkPacket.CmdCtr++;
CFE_EVS_SendEvent(SC_NOOP_INF_EID, CFE_EVS_EventType_INFORMATION, "No-op command. Version %d.%d.%d.%d",
SC_MAJOR_VERSION, SC_MINOR_VERSION, SC_REVISION, SC_MISSION_REV);
}
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Expand Down Expand Up @@ -628,73 +622,129 @@ void SC_ProcessCommand(const CFE_SB_Buffer_t *BufPtr)
switch (CommandCode)
{
case SC_NOOP_CC:
SC_NoOpCmd(BufPtr);
if (SC_VerifyCmdLength(&BufPtr->Msg, sizeof(SC_NoArgsCmd_t)))
{
SC_NoOpCmd(BufPtr);
}
break;


case SC_RESET_COUNTERS_CC:
SC_ResetCountersCmd(BufPtr);
if (SC_VerifyCmdLength(&BufPtr->Msg, sizeof(SC_NoArgsCmd_t)))
{
SC_ResetCountersCmd(BufPtr);
}
break;

case SC_START_ATS_CC:
SC_StartAtsCmd(BufPtr);
if (SC_VerifyCmdLength(&BufPtr->Msg, sizeof(SC_StartAtsCmd_t)))
{
SC_StartAtsCmd(BufPtr);
}
break;

case SC_STOP_ATS_CC:
SC_StopAtsCmd(BufPtr);
if (SC_VerifyCmdLength(&BufPtr->Msg, sizeof(SC_NoArgsCmd_t)))
{
SC_StopAtsCmd(BufPtr);
}
break;

case SC_START_RTS_CC:
SC_StartRtsCmd(BufPtr);
if (SC_VerifyCmdLength(&BufPtr->Msg, sizeof(SC_RtsCmd_t)))
{
SC_StartRtsCmd(BufPtr);
}
else
{
SC_OperData.HkPacket.RtsActiveErrCtr++;
}
break;

case SC_STOP_RTS_CC:
SC_StopRtsCmd(BufPtr);
if (SC_VerifyCmdLength(&BufPtr->Msg, sizeof(SC_RtsCmd_t)))
{
SC_StopRtsCmd(BufPtr);
}
break;

case SC_DISABLE_RTS_CC:
SC_DisableRtsCmd(BufPtr);
if (SC_VerifyCmdLength(&BufPtr->Msg, sizeof(SC_RtsCmd_t)))
{
SC_DisableRtsCmd(BufPtr);
}
break;

case SC_ENABLE_RTS_CC:
SC_EnableRtsCmd(BufPtr);
if (SC_VerifyCmdLength(&BufPtr->Msg, sizeof(SC_RtsCmd_t)))
{
SC_EnableRtsCmd(BufPtr);
}
break;

case SC_SWITCH_ATS_CC:
SC_GroundSwitchCmd(BufPtr);
if (SC_VerifyCmdLength(&BufPtr->Msg, sizeof(SC_NoArgsCmd_t)))
{
SC_GroundSwitchCmd(BufPtr);
}
break;

case SC_JUMP_ATS_CC:
SC_JumpAtsCmd(BufPtr);
if (SC_VerifyCmdLength(&BufPtr->Msg, sizeof(SC_JumpAtsCmd_t)))
{
SC_JumpAtsCmd(BufPtr);
}
break;

case SC_CONTINUE_ATS_ON_FAILURE_CC:
SC_ContinueAtsOnFailureCmd(BufPtr);
if (SC_VerifyCmdLength(&BufPtr->Msg, sizeof(SC_SetContinueAtsOnFailureCmd_t)))
{
SC_ContinueAtsOnFailureCmd(BufPtr);
}
break;

case SC_APPEND_ATS_CC:
SC_AppendAtsCmd(BufPtr);
if (SC_VerifyCmdLength(&BufPtr->Msg, sizeof(SC_AppendAtsCmd_t)))
{
SC_AppendAtsCmd(BufPtr);
}
break;

case SC_MANAGE_TABLE_CC:
SC_TableManageCmd(BufPtr);
if (SC_VerifyCmdLength(&BufPtr->Msg, sizeof(SC_NoArgsCmd_t)))
{
SC_TableManageCmd(BufPtr);
}
break;

#if (SC_ENABLE_GROUP_COMMANDS == true)

case SC_START_RTS_GRP_CC:
SC_StartRtsGrpCmd(BufPtr);
if (SC_VerifyCmdLength(&BufPtr->Msg, sizeof(SC_RtsGrpCmd_t)))
{
SC_StartRtsGrpCmd(BufPtr);
}
break;

case SC_STOP_RTS_GRP_CC:
SC_StopRtsGrpCmd(BufPtr);
if (SC_VerifyCmdLength(&BufPtr->Msg, sizeof(SC_RtsGrpCmd_t)))
{
SC_StopRtsGrpCmd(BufPtr);
}
break;

case SC_DISABLE_RTS_GRP_CC:
SC_DisableRtsGrpCmd(BufPtr);
if (SC_VerifyCmdLength(&BufPtr->Msg, sizeof(SC_RtsGrpCmd_t)))
{
SC_DisableRtsGrpCmd(BufPtr);
}
break;

case SC_ENABLE_RTS_GRP_CC:
SC_EnableRtsGrpCmd(BufPtr);
if (SC_VerifyCmdLength(&BufPtr->Msg, sizeof(SC_RtsGrpCmd_t)))
{
SC_EnableRtsGrpCmd(BufPtr);
}
break;
#endif

Expand Down
Loading

0 comments on commit 7c8589f

Please sign in to comment.