From 0c204908a1e4cf59aa0793b2e79ed9dc5d2183b8 Mon Sep 17 00:00:00 2001 From: Anh D Van Date: Wed, 2 Apr 2025 16:16:08 +0000 Subject: [PATCH] Fix #237, update sample app to reflect 582 standard Fix #237, Update to remove global pipename and data structure. Update cmd to increment command counter. Update SAMPLE_APP_ProcessCmd to have only 1 return. --- config/default_sample_app_internal_cfg.h | 1 + fsw/src/sample_app.c | 10 +----- fsw/src/sample_app.h | 6 ---- fsw/src/sample_app_cmds.c | 44 +++++++++++++----------- 4 files changed, 25 insertions(+), 36 deletions(-) diff --git a/config/default_sample_app_internal_cfg.h b/config/default_sample_app_internal_cfg.h index 25d753f..145f040 100644 --- a/config/default_sample_app_internal_cfg.h +++ b/config/default_sample_app_internal_cfg.h @@ -34,6 +34,7 @@ /***********************************************************************/ #define SAMPLE_APP_PIPE_DEPTH 32 /* Depth of the Command Pipe for Application */ +#define SAMPLE_APP_PIPE_NAME "SAMPLE_APP_CMD_PIPE" #define SAMPLE_APP_NUMBER_OF_TABLES 1 /* Number of Example Table(s) */ diff --git a/fsw/src/sample_app.c b/fsw/src/sample_app.c index afa8396..fd32277 100644 --- a/fsw/src/sample_app.c +++ b/fsw/src/sample_app.c @@ -117,14 +117,6 @@ CFE_Status_t SAMPLE_APP_Init(void) SAMPLE_APP_Data.RunStatus = CFE_ES_RunStatus_APP_RUN; - /* - ** Initialize app configuration data - */ - SAMPLE_APP_Data.PipeDepth = SAMPLE_APP_PIPE_DEPTH; - - strncpy(SAMPLE_APP_Data.PipeName, "SAMPLE_APP_CMD_PIPE", sizeof(SAMPLE_APP_Data.PipeName)); - SAMPLE_APP_Data.PipeName[sizeof(SAMPLE_APP_Data.PipeName) - 1] = 0; - /* ** Register the events */ @@ -144,7 +136,7 @@ CFE_Status_t SAMPLE_APP_Init(void) /* ** Create Software Bus message pipe. */ - status = CFE_SB_CreatePipe(&SAMPLE_APP_Data.CommandPipe, SAMPLE_APP_Data.PipeDepth, SAMPLE_APP_Data.PipeName); + status = CFE_SB_CreatePipe(&SAMPLE_APP_Data.CommandPipe, SAMPLE_APP_PIPE_DEPTH, SAMPLE_APP_PIPE_NAME); if (status != CFE_SUCCESS) { CFE_EVS_SendEvent(SAMPLE_APP_CR_PIPE_ERR_EID, CFE_EVS_EventType_ERROR, diff --git a/fsw/src/sample_app.h b/fsw/src/sample_app.h index 1cd31ee..27d174c 100644 --- a/fsw/src/sample_app.h +++ b/fsw/src/sample_app.h @@ -68,12 +68,6 @@ typedef struct */ CFE_SB_PipeId_t CommandPipe; - /* - ** Initialization data (not reported in housekeeping)... - */ - char PipeName[CFE_MISSION_MAX_API_LEN]; - uint16 PipeDepth; - CFE_TBL_Handle_t TblHandles[SAMPLE_APP_NUMBER_OF_TABLES]; } SAMPLE_APP_Data_t; diff --git a/fsw/src/sample_app_cmds.c b/fsw/src/sample_app_cmds.c index b2eb155..3d22caf 100644 --- a/fsw/src/sample_app_cmds.c +++ b/fsw/src/sample_app_cmds.c @@ -111,37 +111,38 @@ 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; + CFE_Status_t Status; void * TblAddr; SAMPLE_APP_ExampleTable_t *TblPtr; const char * TableName = "SAMPLE_APP.ExampleTable"; /* Sample Use of Example Table */ - - status = CFE_TBL_GetAddress(&TblAddr, SAMPLE_APP_Data.TblHandles[0]); - - if (status < CFE_SUCCESS) + SAMPLE_APP_Data.CmdCounter++; + 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); - return status; + CFE_ES_WriteToSysLog("Sample App: Fail to get table address: 0x%08lx", (unsigned long)Status); } - - 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) + else { - CFE_ES_WriteToSysLog("Sample App: Fail to release table address: 0x%08lx", (unsigned long)status); - return status; + 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(); + } } - /* Invoke a function provided by SAMPLE_APP_LIB */ - SAMPLE_LIB_Function(); - - return CFE_SUCCESS; + return Status; } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ @@ -151,6 +152,7 @@ CFE_Status_t SAMPLE_APP_ProcessCmd(const SAMPLE_APP_ProcessCmd_t *Msg) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ CFE_Status_t SAMPLE_APP_DisplayParamCmd(const SAMPLE_APP_DisplayParamCmd_t *Msg) { + SAMPLE_APP_Data.CmdCounter++; CFE_EVS_SendEvent(SAMPLE_APP_VALUE_INF_EID, CFE_EVS_EventType_INFORMATION, "SAMPLE_APP: ValU32=%lu, ValI16=%d, ValStr=%s", (unsigned long)Msg->Payload.ValU32, (int)Msg->Payload.ValI16, Msg->Payload.ValStr);