From 65caabfd5c899067a65d872ac37e51e7c7ab4cf2 Mon Sep 17 00:00:00 2001 From: Vivek Raj Date: Thu, 5 Feb 2026 10:58:56 -0500 Subject: [PATCH 1/2] sample_app: improve error handling and event reporting in ProcessCmd --- fsw/src/sample_app_cmds.c | 62 ++++++++++++++++++++++++++------------- 1 file changed, 42 insertions(+), 20 deletions(-) diff --git a/fsw/src/sample_app_cmds.c b/fsw/src/sample_app_cmds.c index b9d8da3..bf6c1fc 100644 --- a/fsw/src/sample_app_cmds.c +++ b/fsw/src/sample_app_cmds.c @@ -112,39 +112,61 @@ CFE_Status_t SAMPLE_APP_ResetCountersCmd(const SAMPLE_APP_ResetCountersCmd_t *Ms CFE_Status_t SAMPLE_APP_ProcessCmd(const SAMPLE_APP_ProcessCmd_t *Msg) { CFE_Status_t Status; - void * TblAddr; + void * TblAddr = NULL; SAMPLE_APP_ExampleTable_t *TblPtr; const char * TableName = "SAMPLE_APP.ExampleTable"; - /* Sample Use of Example Table */ + /* Count command execution */ SAMPLE_APP_Data.CmdCounter++; + + /* Get table address */ Status = CFE_TBL_GetAddress(&TblAddr, SAMPLE_APP_Data.TblHandles[0]); if (Status < CFE_SUCCESS) { - CFE_ES_WriteToSysLog("Sample App: Fail to get table address: 0x%08lx", (unsigned long)Status); + SAMPLE_APP_Data.ErrCounter++; + + CFE_EVS_SendEvent(SAMPLE_APP_CMD_ERR_EID, + CFE_EVS_EventType_ERROR, + "SAMPLE_APP_ProcessCmd: Failed to get table address, RC=0x%08lx", + (unsigned long)Status); + + CFE_ES_WriteToSysLog("Sample App: Fail to get table address: 0x%08lx", + (unsigned long)Status); + + return Status; } - else + + /* Use the table */ + TblPtr = (SAMPLE_APP_ExampleTable_t *)TblAddr; + CFE_ES_WriteToSysLog("Sample App: Example Table Value 1: %d Value 2: %d", + TblPtr->Int1, TblPtr->Int2); + + SAMPLE_APP_GetCrc(TableName); + + /* Release table address */ + Status = CFE_TBL_ReleaseAddress(SAMPLE_APP_Data.TblHandles[0]); + if (Status != CFE_SUCCESS) { - TblPtr = TblAddr; - CFE_ES_WriteToSysLog("Sample App: Example Table Value 1: %d Value 2: %d", TblPtr->Int1, TblPtr->Int2); - - SAMPLE_APP_GetCrc(TableName); - - Status = CFE_TBL_ReleaseAddress(SAMPLE_APP_Data.TblHandles[0]); - if (Status != CFE_SUCCESS) - { - CFE_ES_WriteToSysLog("Sample App: Fail to release table address: 0x%08lx", (unsigned long)Status); - } - else - { - /* Invoke a function provided by SAMPLE_APP_LIB */ - SAMPLE_LIB_Function(); - } + SAMPLE_APP_Data.ErrCounter++; + + CFE_EVS_SendEvent(SAMPLE_APP_CMD_ERR_EID, + CFE_EVS_EventType_ERROR, + "SAMPLE_APP_ProcessCmd: Failed to get table address, RC=0x%08lx", + (unsigned long)Status); + + CFE_ES_WriteToSysLog("Sample App: Fail to release table address: 0x%08lx", + (unsigned long)Status); + + return Status; } - return Status; + /* Invoke a function provided by SAMPLE_APP_LIB */ + SAMPLE_LIB_Function(); + + return CFE_SUCCESS; } + /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ /* */ /* A simple example command that displays a passed-in value */ From 005cdea3813d67e57d52dbc05c16e29793fb1074 Mon Sep 17 00:00:00 2001 From: Vivek Raj Date: Mon, 9 Feb 2026 19:53:05 -0500 Subject: [PATCH 2/2] sample_app: initialize TblPtr and fix release error message --- fsw/src/sample_app_cmds.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fsw/src/sample_app_cmds.c b/fsw/src/sample_app_cmds.c index bf6c1fc..bf513e6 100644 --- a/fsw/src/sample_app_cmds.c +++ b/fsw/src/sample_app_cmds.c @@ -113,7 +113,7 @@ CFE_Status_t SAMPLE_APP_ProcessCmd(const SAMPLE_APP_ProcessCmd_t *Msg) { CFE_Status_t Status; void * TblAddr = NULL; - SAMPLE_APP_ExampleTable_t *TblPtr; + SAMPLE_APP_ExampleTable_t *TblPtr = NULL; const char * TableName = "SAMPLE_APP.ExampleTable"; /* Count command execution */ @@ -151,7 +151,7 @@ CFE_Status_t SAMPLE_APP_ProcessCmd(const SAMPLE_APP_ProcessCmd_t *Msg) CFE_EVS_SendEvent(SAMPLE_APP_CMD_ERR_EID, CFE_EVS_EventType_ERROR, - "SAMPLE_APP_ProcessCmd: Failed to get table address, RC=0x%08lx", + "SAMPLE_APP_ProcessCmd: Failed to release table address, RC=0x%08lx", (unsigned long)Status); CFE_ES_WriteToSysLog("Sample App: Fail to release table address: 0x%08lx",