diff --git a/config/default_sample_app_internal_cfg.h b/config/default_sample_app_internal_cfg.h index 145f040..0c59a9e 100644 --- a/config/default_sample_app_internal_cfg.h +++ b/config/default_sample_app_internal_cfg.h @@ -42,4 +42,14 @@ #define SAMPLE_APP_TBL_ELEMENT_1_MAX 10 +/** + * \brief Amount of time to wait in CFE_SB_RecieveBuffer + * + * Applications need to wait for messages to arrive on the Software Bus, + * but this wait should be time limited to ensure that the app also + * periodically checks the status of CFE_ES_RunLoop(), in case an + * administrative command comes in. + */ +#define SAMPLE_APP_SB_WAIT_PERIOD 1000 + #endif diff --git a/fsw/src/sample_app.c b/fsw/src/sample_app.c index fd32277..6159d45 100644 --- a/fsw/src/sample_app.c +++ b/fsw/src/sample_app.c @@ -73,8 +73,14 @@ void SAMPLE_APP_Main(void) */ CFE_ES_PerfLogExit(SAMPLE_APP_PERF_ID); - /* Pend on receipt of command packet */ - status = CFE_SB_ReceiveBuffer(&SBBufPtr, SAMPLE_APP_Data.CommandPipe, CFE_SB_PEND_FOREVER); + /* + * Pend on receipt of command packet + * + * Note that apps should not wait forever here, to ensure + * that the status of CFE_ES_RunLoop() is also checked periodically, + * even if no software bus messages arrive. + */ + status = CFE_SB_ReceiveBuffer(&SBBufPtr, SAMPLE_APP_Data.CommandPipe, SAMPLE_APP_SB_WAIT_PERIOD); /* ** Performance Log Entry Stamp @@ -85,8 +91,9 @@ void SAMPLE_APP_Main(void) { SAMPLE_APP_TaskPipe(SBBufPtr); } - else + else if (status != CFE_SB_TIME_OUT) { + /* Timeout is normal if no activity, but anything else constitutes a real error */ CFE_EVS_SendEvent(SAMPLE_APP_PIPE_ERR_EID, CFE_EVS_EventType_ERROR, "SAMPLE APP: SB Pipe Read Error, App Will Exit");