Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #55, Refactor HK_AppInit() and HK_TableInit() to remove multiple returns #56

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
214 changes: 125 additions & 89 deletions fsw/src/hk_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,76 +140,94 @@ CFE_Status_t HK_AppInit(void)

/* Register for event services... */
Status = CFE_EVS_Register(NULL, 0, CFE_EVS_EventFilter_BINARY);

if (Status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("HK: error registering for event services: 0x%08X\n", (unsigned int)Status);
return Status;
}

/* Create HK Command Pipe */
Status = CFE_SB_CreatePipe(&HK_AppData.CmdPipe, HK_PIPE_DEPTH, HK_PIPE_NAME);
if (Status != CFE_SUCCESS)
if (Status == CFE_SUCCESS)
{
CFE_EVS_SendEvent(HK_CR_PIPE_ERR_EID, CFE_EVS_EventType_ERROR, "Error Creating SB Pipe,RC=0x%08X",
(unsigned int)Status);
return Status;
/* Create HK Command Pipe */
Status = CFE_SB_CreatePipe(&HK_AppData.CmdPipe, HK_PIPE_DEPTH, HK_PIPE_NAME);

if (Status != CFE_SUCCESS)
{
CFE_EVS_SendEvent(HK_CR_PIPE_ERR_EID, CFE_EVS_EventType_ERROR, "Error Creating SB Pipe,RC=0x%08X",
(unsigned int)Status);
}
}

/* Subscribe to 'Send Combined HK Pkt' Command */
Status = CFE_SB_Subscribe(CFE_SB_ValueToMsgId(HK_SEND_COMBINED_PKT_MID), HK_AppData.CmdPipe);
if (Status != CFE_SUCCESS)
if (Status == CFE_SUCCESS)
{
CFE_EVS_SendEvent(HK_SUB_CMB_ERR_EID, CFE_EVS_EventType_ERROR,
"Error Subscribing to HK Snd Cmb Pkt, MID=0x%08X, RC=0x%08X", HK_SEND_COMBINED_PKT_MID,
(unsigned int)Status);
return Status;
/* Subscribe to 'Send Combined HK Pkt' Command */
Status = CFE_SB_Subscribe(CFE_SB_ValueToMsgId(HK_SEND_COMBINED_PKT_MID), HK_AppData.CmdPipe);

if (Status != CFE_SUCCESS)
{
CFE_EVS_SendEvent(HK_SUB_CMB_ERR_EID, CFE_EVS_EventType_ERROR,
"Error Subscribing to HK Snd Cmb Pkt, MID=0x%08X, RC=0x%08X", HK_SEND_COMBINED_PKT_MID,
(unsigned int)Status);
}
}

/* Subscribe to Housekeeping Request */
Status = CFE_SB_Subscribe(CFE_SB_ValueToMsgId(HK_SEND_HK_MID), HK_AppData.CmdPipe);
if (Status != CFE_SUCCESS)
if (Status == CFE_SUCCESS)
{
CFE_EVS_SendEvent(HK_SUB_REQ_ERR_EID, CFE_EVS_EventType_ERROR,
"Error Subscribing to HK Request, MID=0x%08X, RC=0x%08X", HK_SEND_HK_MID,
(unsigned int)Status);
return Status;
/* Subscribe to Housekeeping Request */
Status = CFE_SB_Subscribe(CFE_SB_ValueToMsgId(HK_SEND_HK_MID), HK_AppData.CmdPipe);

if (Status != CFE_SUCCESS)
{
CFE_EVS_SendEvent(HK_SUB_REQ_ERR_EID, CFE_EVS_EventType_ERROR,
"Error Subscribing to HK Request, MID=0x%08X, RC=0x%08X", HK_SEND_HK_MID,
(unsigned int)Status);
}
}

/* Subscribe to HK ground commands */
Status = CFE_SB_Subscribe(CFE_SB_ValueToMsgId(HK_CMD_MID), HK_AppData.CmdPipe);
if (Status != CFE_SUCCESS)
if (Status == CFE_SUCCESS)
{
CFE_EVS_SendEvent(HK_SUB_CMD_ERR_EID, CFE_EVS_EventType_ERROR,
"Error Subscribing to HK Gnd Cmds, MID=0x%08X, RC=0x%08X", HK_CMD_MID, (unsigned int)Status);
return Status;
/* Subscribe to HK ground commands */
Status = CFE_SB_Subscribe(CFE_SB_ValueToMsgId(HK_CMD_MID), HK_AppData.CmdPipe);

if (Status != CFE_SUCCESS)
{
CFE_EVS_SendEvent(HK_SUB_CMD_ERR_EID, CFE_EVS_EventType_ERROR,
"Error Subscribing to HK Gnd Cmds, MID=0x%08X, RC=0x%08X", HK_CMD_MID,
(unsigned int)Status);
}
}

/* Create a memory pool for combined output messages */
Status = CFE_ES_PoolCreate(&HK_AppData.MemPoolHandle, HK_AppData.MemPoolBuffer, sizeof(HK_AppData.MemPoolBuffer));
if (Status != CFE_SUCCESS)
if (Status == CFE_SUCCESS)
{
CFE_EVS_SendEvent(HK_CR_POOL_ERR_EID, CFE_EVS_EventType_ERROR, "Error Creating Memory Pool,RC=0x%08X",
(unsigned int)Status);
return Status;
}
/* Create a memory pool for combined output messages */
Status =
CFE_ES_PoolCreate(&HK_AppData.MemPoolHandle, HK_AppData.MemPoolBuffer, sizeof(HK_AppData.MemPoolBuffer));

HK_ResetHkData();
if (Status != CFE_SUCCESS)
{
CFE_EVS_SendEvent(HK_CR_POOL_ERR_EID, CFE_EVS_EventType_ERROR, "Error Creating Memory Pool,RC=0x%08X",
(unsigned int)Status);
}
}

/* Register The HK Tables */
Status = HK_TableInit();
if (Status != CFE_SUCCESS)
if (Status == CFE_SUCCESS)
{
/* Specific failure is detailed in function HK_TableInit */
return Status;
}
HK_ResetHkData();

/* Application initialization event */
Status = CFE_EVS_SendEvent(HK_INIT_EID, CFE_EVS_EventType_INFORMATION, "HK Initialized. Version %d.%d.%d.%d",
HK_MAJOR_VERSION, HK_MINOR_VERSION, HK_REVISION, HK_MISSION_REV);
/* Register The HK Tables */
Status = HK_TableInit(); /* Any error events are sent from within HK_TableInit() */
}

if (Status != CFE_SUCCESS)
if (Status == CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("HK App:Error Sending Initialization Event,RC=0x%08X\n", (unsigned int)Status);
/* Application initialization event */
Status = CFE_EVS_SendEvent(HK_INIT_EID, CFE_EVS_EventType_INFORMATION, "HK Initialized. Version %d.%d.%d.%d",
HK_MAJOR_VERSION, HK_MINOR_VERSION, HK_REVISION, HK_MISSION_REV);

if (Status != CFE_SUCCESS)
{
CFE_ES_WriteToSysLog("HK App:Error Sending Initialization Event,RC=0x%08X\n", (unsigned int)Status);
}
}

return Status;
Expand All @@ -233,73 +251,91 @@ CFE_Status_t HK_TableInit(void)
{
CFE_EVS_SendEvent(HK_CPTBL_REG_ERR_EID, CFE_EVS_EventType_ERROR, "Error Registering Copy Table,RC=0x%08X",
(unsigned int)Status);
return Status;
}

/* Register The HK Runtime Table */
Status = CFE_TBL_Register(&HK_AppData.RuntimeTableHandle, HK_RUNTIME_TABLE_NAME,
(sizeof(hk_runtime_tbl_entry_t) * HK_COPY_TABLE_ENTRIES),
CFE_TBL_OPT_SNGL_BUFFER | CFE_TBL_OPT_DUMP_ONLY, NULL);
if (Status != CFE_SUCCESS)
if (Status == CFE_SUCCESS)
{
CFE_EVS_SendEvent(HK_RTTBL_REG_ERR_EID, CFE_EVS_EventType_ERROR, "Error Registering Runtime Table,RC=0x%08X",
(unsigned int)Status);
return Status;
/* Register The HK Runtime Table */
Status = CFE_TBL_Register(&HK_AppData.RuntimeTableHandle, HK_RUNTIME_TABLE_NAME,
(sizeof(hk_runtime_tbl_entry_t) * HK_COPY_TABLE_ENTRIES),
CFE_TBL_OPT_SNGL_BUFFER | CFE_TBL_OPT_DUMP_ONLY, NULL);

if (Status != CFE_SUCCESS)
{
CFE_EVS_SendEvent(HK_RTTBL_REG_ERR_EID, CFE_EVS_EventType_ERROR,
"Error Registering Runtime Table,RC=0x%08X", (unsigned int)Status);
}
}

Status = CFE_TBL_Load(HK_AppData.CopyTableHandle, CFE_TBL_SRC_FILE, HK_COPY_TABLE_FILENAME);
if (Status != CFE_SUCCESS)
if (Status == CFE_SUCCESS)
{
CFE_EVS_SendEvent(HK_CPTBL_LD_ERR_EID, CFE_EVS_EventType_ERROR, "Error Loading Copy Table,RC=0x%08X",
(unsigned int)Status);
return Status;
Status = CFE_TBL_Load(HK_AppData.CopyTableHandle, CFE_TBL_SRC_FILE, HK_COPY_TABLE_FILENAME);

if (Status != CFE_SUCCESS)
{
CFE_EVS_SendEvent(HK_CPTBL_LD_ERR_EID, CFE_EVS_EventType_ERROR, "Error Loading Copy Table,RC=0x%08X",
(unsigned int)Status);
}
}

Status = CFE_TBL_Manage(HK_AppData.CopyTableHandle);
if (Status != CFE_SUCCESS)
if (Status == CFE_SUCCESS)
{
CFE_EVS_SendEvent(HK_CPTBL_MNG_ERR_EID, CFE_EVS_EventType_ERROR,
"Error from TBL Manage call for Copy Table,RC=0x%08X", (unsigned int)Status);
return Status;
Status = CFE_TBL_Manage(HK_AppData.CopyTableHandle);

if (Status != CFE_SUCCESS)
{
CFE_EVS_SendEvent(HK_CPTBL_MNG_ERR_EID, CFE_EVS_EventType_ERROR,
"Error from TBL Manage call for Copy Table,RC=0x%08X", (unsigned int)Status);
}
}

Status = CFE_TBL_Manage(HK_AppData.RuntimeTableHandle);
if (Status != CFE_SUCCESS)
if (Status == CFE_SUCCESS)
{
CFE_EVS_SendEvent(HK_RTTBL_MNG_ERR_EID, CFE_EVS_EventType_ERROR,
"Error from TBL Manage call for Runtime Table,RC=0x%08X", (unsigned int)Status);
return Status;
Status = CFE_TBL_Manage(HK_AppData.RuntimeTableHandle);

if (Status != CFE_SUCCESS)
{
CFE_EVS_SendEvent(HK_RTTBL_MNG_ERR_EID, CFE_EVS_EventType_ERROR,
"Error from TBL Manage call for Runtime Table,RC=0x%08X", (unsigned int)Status);
}
}

Status = CFE_TBL_GetAddress((void *)(&HK_AppData.CopyTablePtr), HK_AppData.CopyTableHandle);
/* Status should be CFE_TBL_INFO_UPDATED because we loaded it above */
if (Status != CFE_TBL_INFO_UPDATED)
if (Status == CFE_SUCCESS)
{
CFE_EVS_SendEvent(HK_CPTBL_GADR_ERR_EID, CFE_EVS_EventType_ERROR, "Error Getting Adr for Cpy Tbl,RC=0x%08X",
(unsigned int)Status);
return Status;
Status = CFE_TBL_GetAddress((void *)(&HK_AppData.CopyTablePtr), HK_AppData.CopyTableHandle);

/* Status should be CFE_TBL_INFO_UPDATED because we loaded it above */
if (Status != CFE_TBL_INFO_UPDATED)
{
CFE_EVS_SendEvent(HK_CPTBL_GADR_ERR_EID, CFE_EVS_EventType_ERROR, "Error Getting Adr for Cpy Tbl,RC=0x%08X",
(unsigned int)Status);
}
}

Status = CFE_TBL_GetAddress((void *)(&HK_AppData.RuntimeTablePtr), HK_AppData.RuntimeTableHandle);
if (Status != CFE_SUCCESS)
if (Status == CFE_TBL_INFO_UPDATED)
{
CFE_EVS_SendEvent(HK_RTTBL_GADR_ERR_EID, CFE_EVS_EventType_ERROR,
"Error Getting Adr for Runtime Table,RC=0x%08X", (unsigned int)Status);
return Status;
}
Status = CFE_TBL_GetAddress((void *)(&HK_AppData.RuntimeTablePtr), HK_AppData.RuntimeTableHandle);

Status = HK_ProcessNewCopyTable(HK_AppData.CopyTablePtr, HK_AppData.RuntimeTablePtr);
if (Status != CFE_SUCCESS)
{
CFE_EVS_SendEvent(HK_RTTBL_GADR_ERR_EID, CFE_EVS_EventType_ERROR,
"Error Getting Adr for Runtime Table,RC=0x%08X", (unsigned int)Status);
}
}

if (Status != CFE_SUCCESS)
if (Status == CFE_SUCCESS)
{
/* If status was not success, then the copy table function received a NULL pointer argument */
CFE_EVS_SendEvent(HK_NEWCPYTBL_INIT_FAILED_EID, CFE_EVS_EventType_ERROR,
"Process New Copy Table Failed, status = 0x%08X", (unsigned int)Status);
Status = HK_ProcessNewCopyTable(HK_AppData.CopyTablePtr, HK_AppData.RuntimeTablePtr);

return Status;
if (Status != CFE_SUCCESS)
{
/* If status was not success, then the copy table function received a NULL pointer argument */
CFE_EVS_SendEvent(HK_NEWCPYTBL_INIT_FAILED_EID, CFE_EVS_EventType_ERROR,
"Process New Copy Table Failed, status = 0x%08X", (unsigned int)Status);
}
}

return CFE_SUCCESS;
return Status;
} /* HK_TableInit */

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Expand Down