Skip to content

Commit

Permalink
Fix #1527, Implement common command-handler return pattern across cFE
Browse files Browse the repository at this point in the history
  • Loading branch information
thnkslprpt committed Jul 9, 2024
1 parent 00fe82a commit 3b8404a
Show file tree
Hide file tree
Showing 14 changed files with 439 additions and 492 deletions.
16 changes: 8 additions & 8 deletions modules/core_api/fsw/inc/cfe_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,14 @@ char *CFE_ES_StatusToString(CFE_Status_t status, CFE_StatusString_t *status_stri
*/
#define CFE_STATUS_NO_COUNTER_INCREMENT ((CFE_Status_t)0x48000001)

/**
* @brief Command Execution Failure
*
* This error code will be returned when a command function fails
* to successfully execute its command
*/
#define CFE_STATUS_COMMAND_FAILURE ((CFE_Status_t)0xc8000001)

/**
* @brief Wrong Message Length
*
Expand Down Expand Up @@ -1251,14 +1259,6 @@ char *CFE_ES_StatusToString(CFE_Status_t status, CFE_StatusString_t *status_stri
*/
#define CFE_TBL_ERR_BAD_PROCESSOR_ID ((CFE_Status_t)0xcc000029)

/**
* @brief Message Error
*
* Error code indicating that the TBL command was not processed
* successfully and that the error counter should be incremented.
*/
#define CFE_TBL_MESSAGE_ERROR ((CFE_Status_t)0xcc00002a)

/**
** Error code indicating that the TBL file is shorter than
** indicated in the file header.
Expand Down
65 changes: 40 additions & 25 deletions modules/es/fsw/src/cfe_es_dispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ void CFE_ES_TaskPipe(const CFE_SB_Buffer_t *SBBufPtr)
{
CFE_SB_MsgId_t MessageID = CFE_SB_INVALID_MSG_ID;
CFE_MSG_FcnCode_t CommandCode = 0;
CFE_Status_t Status = CFE_STATUS_NO_COUNTER_INCREMENT;

CFE_MSG_GetMsgId(&SBBufPtr->Msg, &MessageID);
switch (CFE_SB_MsgIdToValue(MessageID))
Expand All @@ -101,178 +102,192 @@ void CFE_ES_TaskPipe(const CFE_SB_Buffer_t *SBBufPtr)
case CFE_ES_NOOP_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_NoopCmd_t)))
{
CFE_ES_NoopCmd((const CFE_ES_NoopCmd_t *)SBBufPtr);
Status = CFE_ES_NoopCmd((const CFE_ES_NoopCmd_t *)SBBufPtr);
}
break;

case CFE_ES_RESET_COUNTERS_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_ResetCountersCmd_t)))
{
CFE_ES_ResetCountersCmd((const CFE_ES_ResetCountersCmd_t *)SBBufPtr);
Status = CFE_ES_ResetCountersCmd((const CFE_ES_ResetCountersCmd_t *)SBBufPtr);
}
break;

case CFE_ES_RESTART_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_RestartCmd_t)))
{
CFE_ES_RestartCmd((const CFE_ES_RestartCmd_t *)SBBufPtr);
Status = CFE_ES_RestartCmd((const CFE_ES_RestartCmd_t *)SBBufPtr);
}
break;

case CFE_ES_START_APP_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_StartAppCmd_t)))
{
CFE_ES_StartAppCmd((const CFE_ES_StartAppCmd_t *)SBBufPtr);
Status = CFE_ES_StartAppCmd((const CFE_ES_StartAppCmd_t *)SBBufPtr);
}
break;

case CFE_ES_STOP_APP_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_StopAppCmd_t)))
{
CFE_ES_StopAppCmd((const CFE_ES_StopAppCmd_t *)SBBufPtr);
Status = CFE_ES_StopAppCmd((const CFE_ES_StopAppCmd_t *)SBBufPtr);
}
break;

case CFE_ES_RESTART_APP_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_RestartAppCmd_t)))
{
CFE_ES_RestartAppCmd((const CFE_ES_RestartAppCmd_t *)SBBufPtr);
Status = CFE_ES_RestartAppCmd((const CFE_ES_RestartAppCmd_t *)SBBufPtr);
}
break;

case CFE_ES_RELOAD_APP_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_ReloadAppCmd_t)))
{
CFE_ES_ReloadAppCmd((const CFE_ES_ReloadAppCmd_t *)SBBufPtr);
Status = CFE_ES_ReloadAppCmd((const CFE_ES_ReloadAppCmd_t *)SBBufPtr);
}
break;

case CFE_ES_QUERY_ONE_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_QueryOneCmd_t)))
{
CFE_ES_QueryOneCmd((const CFE_ES_QueryOneCmd_t *)SBBufPtr);
Status = CFE_ES_QueryOneCmd((const CFE_ES_QueryOneCmd_t *)SBBufPtr);
}
break;

case CFE_ES_QUERY_ALL_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_QueryAllCmd_t)))
{
CFE_ES_QueryAllCmd((const CFE_ES_QueryAllCmd_t *)SBBufPtr);
Status = CFE_ES_QueryAllCmd((const CFE_ES_QueryAllCmd_t *)SBBufPtr);
}
break;

case CFE_ES_QUERY_ALL_TASKS_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_QueryAllTasksCmd_t)))
{
CFE_ES_QueryAllTasksCmd((const CFE_ES_QueryAllTasksCmd_t *)SBBufPtr);
Status = CFE_ES_QueryAllTasksCmd((const CFE_ES_QueryAllTasksCmd_t *)SBBufPtr);
}
break;

case CFE_ES_CLEAR_SYS_LOG_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_ClearSysLogCmd_t)))
{
CFE_ES_ClearSysLogCmd((const CFE_ES_ClearSysLogCmd_t *)SBBufPtr);
Status = CFE_ES_ClearSysLogCmd((const CFE_ES_ClearSysLogCmd_t *)SBBufPtr);
}
break;

case CFE_ES_WRITE_SYS_LOG_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_WriteSysLogCmd_t)))
{
CFE_ES_WriteSysLogCmd((const CFE_ES_WriteSysLogCmd_t *)SBBufPtr);
Status = CFE_ES_WriteSysLogCmd((const CFE_ES_WriteSysLogCmd_t *)SBBufPtr);
}
break;

case CFE_ES_OVER_WRITE_SYS_LOG_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_OverWriteSysLogCmd_t)))
{
CFE_ES_OverWriteSysLogCmd((const CFE_ES_OverWriteSysLogCmd_t *)SBBufPtr);
Status = CFE_ES_OverWriteSysLogCmd((const CFE_ES_OverWriteSysLogCmd_t *)SBBufPtr);
}
break;

case CFE_ES_CLEAR_ER_LOG_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_ClearERLogCmd_t)))
{
CFE_ES_ClearERLogCmd((const CFE_ES_ClearERLogCmd_t *)SBBufPtr);
Status = CFE_ES_ClearERLogCmd((const CFE_ES_ClearERLogCmd_t *)SBBufPtr);
}
break;

case CFE_ES_WRITE_ER_LOG_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_WriteERLogCmd_t)))
{
CFE_ES_WriteERLogCmd((const CFE_ES_WriteERLogCmd_t *)SBBufPtr);
Status = CFE_ES_WriteERLogCmd((const CFE_ES_WriteERLogCmd_t *)SBBufPtr);
}
break;

case CFE_ES_START_PERF_DATA_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_StartPerfDataCmd_t)))
{
CFE_ES_StartPerfDataCmd((const CFE_ES_StartPerfDataCmd_t *)SBBufPtr);
Status = CFE_ES_StartPerfDataCmd((const CFE_ES_StartPerfDataCmd_t *)SBBufPtr);
}
break;

case CFE_ES_STOP_PERF_DATA_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_StopPerfDataCmd_t)))
{
CFE_ES_StopPerfDataCmd((const CFE_ES_StopPerfDataCmd_t *)SBBufPtr);
Status = CFE_ES_StopPerfDataCmd((const CFE_ES_StopPerfDataCmd_t *)SBBufPtr);
}
break;

case CFE_ES_SET_PERF_FILTER_MASK_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_SetPerfFilterMaskCmd_t)))
{
CFE_ES_SetPerfFilterMaskCmd((const CFE_ES_SetPerfFilterMaskCmd_t *)SBBufPtr);
Status = CFE_ES_SetPerfFilterMaskCmd((const CFE_ES_SetPerfFilterMaskCmd_t *)SBBufPtr);
}
break;

case CFE_ES_SET_PERF_TRIGGER_MASK_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_SetPerfTriggerMaskCmd_t)))
{
CFE_ES_SetPerfTriggerMaskCmd((const CFE_ES_SetPerfTriggerMaskCmd_t *)SBBufPtr);
Status = CFE_ES_SetPerfTriggerMaskCmd((const CFE_ES_SetPerfTriggerMaskCmd_t *)SBBufPtr);
}
break;

case CFE_ES_RESET_PR_COUNT_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_ResetPRCountCmd_t)))
{
CFE_ES_ResetPRCountCmd((const CFE_ES_ResetPRCountCmd_t *)SBBufPtr);
Status = CFE_ES_ResetPRCountCmd((const CFE_ES_ResetPRCountCmd_t *)SBBufPtr);
}
break;

case CFE_ES_SET_MAX_PR_COUNT_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_SetMaxPRCountCmd_t)))
{
CFE_ES_SetMaxPRCountCmd((const CFE_ES_SetMaxPRCountCmd_t *)SBBufPtr);
Status = CFE_ES_SetMaxPRCountCmd((const CFE_ES_SetMaxPRCountCmd_t *)SBBufPtr);
}
break;

case CFE_ES_DELETE_CDS_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_DeleteCDSCmd_t)))
{
CFE_ES_DeleteCDSCmd((const CFE_ES_DeleteCDSCmd_t *)SBBufPtr);
Status = CFE_ES_DeleteCDSCmd((const CFE_ES_DeleteCDSCmd_t *)SBBufPtr);
}
break;

case CFE_ES_SEND_MEM_POOL_STATS_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_SendMemPoolStatsCmd_t)))
{
CFE_ES_SendMemPoolStatsCmd((const CFE_ES_SendMemPoolStatsCmd_t *)SBBufPtr);
Status = CFE_ES_SendMemPoolStatsCmd((const CFE_ES_SendMemPoolStatsCmd_t *)SBBufPtr);
}
break;

case CFE_ES_DUMP_CDS_REGISTRY_CC:
if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_DumpCDSRegistryCmd_t)))
{
CFE_ES_DumpCDSRegistryCmd((const CFE_ES_DumpCDSRegistryCmd_t *)SBBufPtr);
Status = CFE_ES_DumpCDSRegistryCmd((const CFE_ES_DumpCDSRegistryCmd_t *)SBBufPtr);
}
break;

default:
CFE_EVS_SendEvent(CFE_ES_CC1_ERR_EID, CFE_EVS_EventType_ERROR,
"Invalid ground command code: ID = 0x%X, CC = %d",
(unsigned int)CFE_SB_MsgIdToValue(MessageID), (int)CommandCode);
CFE_ES_Global.TaskData.CommandErrorCounter++;
Status = CFE_STATUS_BAD_COMMAND_CODE;
break;
}

/*
* Any command functions returning a Status of CFE_STATUS_NO_COUNTER_INCREMENT
* will not increment either counter
*/
if (Status == CFE_SUCCESS)
{
CFE_ES_Global.TaskData.CommandCounter++;
}
else if ((Status == CFE_STATUS_COMMAND_FAILURE) || (Status == CFE_STATUS_BAD_COMMAND_CODE))
{
CFE_ES_Global.TaskData.CommandErrorCounter++;
}

break;

default:
Expand Down
29 changes: 12 additions & 17 deletions modules/es/fsw/src/cfe_es_perf.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ int32 CFE_ES_StartPerfDataCmd(const CFE_ES_StartPerfDataCmd_t *data)
const CFE_ES_StartPerfCmd_Payload_t *CmdPtr = &data->Payload;
CFE_ES_PerfDumpGlobal_t * PerfDumpState = &CFE_ES_Global.BackgroundPerfDumpState;
CFE_ES_PerfData_t * Perf;
CFE_Status_t ReturnCode = CFE_STATUS_COMMAND_FAILURE;

/*
** Set the pointer to the data area
Expand All @@ -157,7 +158,7 @@ int32 CFE_ES_StartPerfDataCmd(const CFE_ES_StartPerfDataCmd_t *data)
/* Make sure Trigger Mode is valid */
if (CmdPtr->TriggerMode <= CFE_ES_PerfTrigger_END)
{
CFE_ES_Global.TaskData.CommandCounter++;
ReturnCode = CFE_SUCCESS;

/* Taking lock here as this might be changing states from one active mode to another.
* In that case, need to make sure that the log is not written to while resetting the counters. */
Expand All @@ -177,20 +178,18 @@ int32 CFE_ES_StartPerfDataCmd(const CFE_ES_StartPerfDataCmd_t *data)
}
else
{
CFE_ES_Global.TaskData.CommandErrorCounter++;
CFE_EVS_SendEvent(CFE_ES_PERF_STARTCMD_TRIG_ERR_EID, CFE_EVS_EventType_ERROR,
"Cannot start collecting performance data, trigger mode (%d) out of range (%d to %d)",
(int)CmdPtr->TriggerMode, (int)CFE_ES_PerfTrigger_START, (int)CFE_ES_PerfTrigger_END);
}
}
else
{
CFE_ES_Global.TaskData.CommandErrorCounter++;
CFE_EVS_SendEvent(CFE_ES_PERF_STARTCMD_ERR_EID, CFE_EVS_EventType_ERROR,
"Cannot start collecting performance data,perf data write in progress");
}

return CFE_SUCCESS;
return ReturnCode;
}

/*----------------------------------------------------------------
Expand All @@ -205,6 +204,7 @@ int32 CFE_ES_StopPerfDataCmd(const CFE_ES_StopPerfDataCmd_t *data)
CFE_ES_PerfDumpGlobal_t * PerfDumpState = &CFE_ES_Global.BackgroundPerfDumpState;
CFE_ES_PerfData_t * Perf;
int32 Status;
CFE_Status_t ReturnCode = CFE_STATUS_COMMAND_FAILURE;

/*
** Set the pointer to the data area
Expand All @@ -231,29 +231,26 @@ int32 CFE_ES_StopPerfDataCmd(const CFE_ES_StopPerfDataCmd_t *data)
PerfDumpState->PendingState = CFE_ES_PerfDumpState_INIT;
CFE_ES_BackgroundWakeup();

CFE_ES_Global.TaskData.CommandCounter++;

ReturnCode = CFE_SUCCESS;
CFE_EVS_SendEvent(CFE_ES_PERF_STOPCMD_EID, CFE_EVS_EventType_DEBUG,
"Perf Stop Cmd Rcvd, will write %d entries.%dmS dly every %d entries",
(int)Perf->MetaData.DataCount, (int)CFE_PLATFORM_ES_PERF_CHILD_MS_DELAY,
(int)CFE_PLATFORM_ES_PERF_ENTRIES_BTWN_DLYS);
}
else
{
CFE_ES_Global.TaskData.CommandErrorCounter++;
CFE_EVS_SendEvent(CFE_ES_PERF_LOG_ERR_EID, CFE_EVS_EventType_ERROR, "Error parsing filename, RC = %d",
(int)Status);
}

} /* if data to write == 0 */
else
{
CFE_ES_Global.TaskData.CommandErrorCounter++;
CFE_EVS_SendEvent(CFE_ES_PERF_STOPCMD_ERR2_EID, CFE_EVS_EventType_ERROR,
"Stop performance data cmd ignored,perf data write in progress");
}

return CFE_SUCCESS;
return ReturnCode;
}

/*----------------------------------------------------------------
Expand Down Expand Up @@ -489,6 +486,7 @@ int32 CFE_ES_SetPerfFilterMaskCmd(const CFE_ES_SetPerfFilterMaskCmd_t *data)
{
const CFE_ES_SetPerfFilterMaskCmd_Payload_t *cmd = &data->Payload;
CFE_ES_PerfData_t * Perf;
CFE_Status_t ReturnCode = CFE_STATUS_COMMAND_FAILURE;

/*
** Set the pointer to the data area
Expand All @@ -503,18 +501,16 @@ int32 CFE_ES_SetPerfFilterMaskCmd(const CFE_ES_SetPerfFilterMaskCmd_t *data)
"Set Performance Filter Mask Cmd rcvd, num %u, val 0x%08X", (unsigned int)cmd->FilterMaskNum,
(unsigned int)cmd->FilterMask);

CFE_ES_Global.TaskData.CommandCounter++;
ReturnCode = CFE_SUCCESS;
}
else
{
CFE_EVS_SendEvent(CFE_ES_PERF_FILTMSKERR_EID, CFE_EVS_EventType_ERROR,
"Performance Filter Mask Cmd Error,Index(%u)out of range(%u)",
(unsigned int)cmd->FilterMaskNum, (unsigned int)CFE_ES_PERF_32BIT_WORDS_IN_MASK);

CFE_ES_Global.TaskData.CommandErrorCounter++;
}

return CFE_SUCCESS;
return ReturnCode;
}

/*----------------------------------------------------------------
Expand All @@ -527,6 +523,7 @@ int32 CFE_ES_SetPerfTriggerMaskCmd(const CFE_ES_SetPerfTriggerMaskCmd_t *data)
{
const CFE_ES_SetPerfTrigMaskCmd_Payload_t *cmd = &data->Payload;
CFE_ES_PerfData_t * Perf;
CFE_Status_t ReturnCode = CFE_STATUS_COMMAND_FAILURE;

/*
** Set the pointer to the data area
Expand All @@ -541,18 +538,16 @@ int32 CFE_ES_SetPerfTriggerMaskCmd(const CFE_ES_SetPerfTriggerMaskCmd_t *data)
"Set Performance Trigger Mask Cmd rcvd,num %u, val 0x%08X", (unsigned int)cmd->TriggerMaskNum,
(unsigned int)cmd->TriggerMask);

CFE_ES_Global.TaskData.CommandCounter++;
ReturnCode = CFE_SUCCESS;
}
else
{
CFE_EVS_SendEvent(CFE_ES_PERF_TRIGMSKERR_EID, CFE_EVS_EventType_ERROR,
"Performance Trigger Mask Cmd Error,Index(%u)out of range(%u)",
(unsigned int)cmd->TriggerMaskNum, (unsigned int)CFE_ES_PERF_32BIT_WORDS_IN_MASK);

CFE_ES_Global.TaskData.CommandErrorCounter++;
}

return CFE_SUCCESS;
return ReturnCode;
}

/*----------------------------------------------------------------
Expand Down
Loading

0 comments on commit 3b8404a

Please sign in to comment.