From 30d640e5b03cdc6ac1ed708a47e5729bfcfd2d00 Mon Sep 17 00:00:00 2001 From: Avi Date: Fri, 21 Oct 2022 20:44:31 +1000 Subject: [PATCH 1/9] Fix #188, Apply consistent Event ID names to common events --- fsw/src/sample_app.c | 14 +++++++------- fsw/src/sample_app_events.h | 16 ++++++++-------- unit-test/coveragetest/coveragetest_sample_app.c | 14 +++++++------- 3 files changed, 22 insertions(+), 22 deletions(-) diff --git a/fsw/src/sample_app.c b/fsw/src/sample_app.c index 2961237..dafb2e6 100644 --- a/fsw/src/sample_app.c +++ b/fsw/src/sample_app.c @@ -191,7 +191,7 @@ int32 SAMPLE_APP_Init(void) status = CFE_TBL_Load(SAMPLE_APP_Data.TblHandles[0], CFE_TBL_SRC_FILE, SAMPLE_APP_TABLE_FILE); } - CFE_EVS_SendEvent(SAMPLE_APP_STARTUP_INF_EID, CFE_EVS_EventType_INFORMATION, "SAMPLE App Initialized.%s", + CFE_EVS_SendEvent(SAMPLE_APP_INIT_INF_EID, CFE_EVS_EventType_INFORMATION, "SAMPLE App Initialized.%s", SAMPLE_APP_VERSION_STRING); return CFE_SUCCESS; @@ -221,7 +221,7 @@ void SAMPLE_APP_ProcessCommandPacket(CFE_SB_Buffer_t *SBBufPtr) break; default: - CFE_EVS_SendEvent(SAMPLE_APP_INVALID_MSGID_ERR_EID, CFE_EVS_EventType_ERROR, + CFE_EVS_SendEvent(SAMPLE_APP_MID_ERR_EID, CFE_EVS_EventType_ERROR, "SAMPLE: invalid command packet,MID = 0x%x", (unsigned int)CFE_SB_MsgIdToValue(MsgId)); break; } @@ -269,8 +269,8 @@ void SAMPLE_APP_ProcessGroundCommand(CFE_SB_Buffer_t *SBBufPtr) /* default case already found during FC vs length test */ default: - CFE_EVS_SendEvent(SAMPLE_APP_COMMAND_ERR_EID, CFE_EVS_EventType_ERROR, - "Invalid ground command code: CC = %d", CommandCode); + CFE_EVS_SendEvent(SAMPLE_APP_CC_ERR_EID, CFE_EVS_EventType_ERROR, "Invalid ground command code: CC = %d", + CommandCode); break; } } @@ -319,7 +319,7 @@ int32 SAMPLE_APP_Noop(const SAMPLE_APP_NoopCmd_t *Msg) { SAMPLE_APP_Data.CmdCounter++; - CFE_EVS_SendEvent(SAMPLE_APP_COMMANDNOP_INF_EID, CFE_EVS_EventType_INFORMATION, "SAMPLE: NOOP command %s", + CFE_EVS_SendEvent(SAMPLE_APP_NOOP_INF_EID, CFE_EVS_EventType_INFORMATION, "SAMPLE: NOOP command %s", SAMPLE_APP_VERSION); return CFE_SUCCESS; @@ -337,7 +337,7 @@ int32 SAMPLE_APP_ResetCounters(const SAMPLE_APP_ResetCountersCmd_t *Msg) SAMPLE_APP_Data.CmdCounter = 0; SAMPLE_APP_Data.ErrCounter = 0; - CFE_EVS_SendEvent(SAMPLE_APP_COMMANDRST_INF_EID, CFE_EVS_EventType_INFORMATION, "SAMPLE: RESET command"); + CFE_EVS_SendEvent(SAMPLE_APP_RESET_INF_EID, CFE_EVS_EventType_INFORMATION, "SAMPLE: RESET command"); return CFE_SUCCESS; } @@ -403,7 +403,7 @@ bool SAMPLE_APP_VerifyCmdLength(CFE_MSG_Message_t *MsgPtr, size_t ExpectedLength CFE_MSG_GetMsgId(MsgPtr, &MsgId); CFE_MSG_GetFcnCode(MsgPtr, &FcnCode); - CFE_EVS_SendEvent(SAMPLE_APP_LEN_ERR_EID, CFE_EVS_EventType_ERROR, + CFE_EVS_SendEvent(SAMPLE_APP_CMD_LEN_ERR_EID, CFE_EVS_EventType_ERROR, "Invalid Msg length: ID = 0x%X, CC = %u, Len = %u, Expected = %u", (unsigned int)CFE_SB_MsgIdToValue(MsgId), (unsigned int)FcnCode, (unsigned int)ActualLength, (unsigned int)ExpectedLength); diff --git a/fsw/src/sample_app_events.h b/fsw/src/sample_app_events.h index 46e7aaf..0d8a586 100644 --- a/fsw/src/sample_app_events.h +++ b/fsw/src/sample_app_events.h @@ -25,13 +25,13 @@ #ifndef SAMPLE_APP_EVENTS_H #define SAMPLE_APP_EVENTS_H -#define SAMPLE_APP_RESERVED_EID 0 -#define SAMPLE_APP_STARTUP_INF_EID 1 -#define SAMPLE_APP_COMMAND_ERR_EID 2 -#define SAMPLE_APP_COMMANDNOP_INF_EID 3 -#define SAMPLE_APP_COMMANDRST_INF_EID 4 -#define SAMPLE_APP_INVALID_MSGID_ERR_EID 5 -#define SAMPLE_APP_LEN_ERR_EID 6 -#define SAMPLE_APP_PIPE_ERR_EID 7 +#define SAMPLE_APP_RESERVED_EID 0 +#define SAMPLE_APP_INIT_INF_EID 1 +#define SAMPLE_APP_CC_ERR_EID 2 +#define SAMPLE_APP_NOOP_INF_EID 3 +#define SAMPLE_APP_RESET_INF_EID 4 +#define SAMPLE_APP_MID_ERR_EID 5 +#define SAMPLE_APP_CMD_LEN_ERR_EID 6 +#define SAMPLE_APP_PIPE_ERR_EID 7 #endif /* SAMPLE_APP_EVENTS_H */ diff --git a/unit-test/coveragetest/coveragetest_sample_app.c b/unit-test/coveragetest/coveragetest_sample_app.c index a1ca631..cb7f2c1 100644 --- a/unit-test/coveragetest/coveragetest_sample_app.c +++ b/unit-test/coveragetest/coveragetest_sample_app.c @@ -291,7 +291,7 @@ void Test_SAMPLE_APP_ProcessCommandPacket(void) UT_CheckEvent_t EventTest; memset(&TestMsg, 0, sizeof(TestMsg)); - UT_CHECKEVENT_SETUP(&EventTest, SAMPLE_APP_INVALID_MSGID_ERR_EID, "SAMPLE: invalid command packet,MID = 0x%x"); + UT_CHECKEVENT_SETUP(&EventTest, SAMPLE_APP_MID_ERR_EID, "SAMPLE: invalid command packet,MID = 0x%x"); /* * The CFE_MSG_GetMsgId() stub uses a data buffer to hold the @@ -355,7 +355,7 @@ void Test_SAMPLE_APP_ProcessGroundCommand(void) Size = sizeof(TestMsg.Noop); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &FcnCode, sizeof(FcnCode), false); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &Size, sizeof(Size), false); - UT_CHECKEVENT_SETUP(&EventTest, SAMPLE_APP_COMMANDNOP_INF_EID, NULL); + UT_CHECKEVENT_SETUP(&EventTest, SAMPLE_APP_NOOP_INF_EID, NULL); SAMPLE_APP_ProcessGroundCommand(&TestMsg.SBBuf); @@ -366,7 +366,7 @@ void Test_SAMPLE_APP_ProcessGroundCommand(void) Size = sizeof(TestMsg.Reset); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &FcnCode, sizeof(FcnCode), false); UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &Size, sizeof(Size), false); - UT_CHECKEVENT_SETUP(&EventTest, SAMPLE_APP_COMMANDRST_INF_EID, NULL); + UT_CHECKEVENT_SETUP(&EventTest, SAMPLE_APP_RESET_INF_EID, NULL); SAMPLE_APP_ProcessGroundCommand(&TestMsg.SBBuf); @@ -386,7 +386,7 @@ void Test_SAMPLE_APP_ProcessGroundCommand(void) /* test an invalid CC */ FcnCode = 1000; UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &FcnCode, sizeof(FcnCode), false); - UT_CHECKEVENT_SETUP(&EventTest, SAMPLE_APP_COMMAND_ERR_EID, "Invalid ground command code: CC = %d"); + UT_CHECKEVENT_SETUP(&EventTest, SAMPLE_APP_CC_ERR_EID, "Invalid ground command code: CC = %d"); SAMPLE_APP_ProcessGroundCommand(&TestMsg.SBBuf); /* @@ -443,7 +443,7 @@ void Test_SAMPLE_APP_NoopCmd(void) memset(&TestMsg, 0, sizeof(TestMsg)); /* test dispatch of NOOP */ - UT_CHECKEVENT_SETUP(&EventTest, SAMPLE_APP_COMMANDNOP_INF_EID, NULL); + UT_CHECKEVENT_SETUP(&EventTest, SAMPLE_APP_NOOP_INF_EID, NULL); UtAssert_INT32_EQ(SAMPLE_APP_Noop(&TestMsg), CFE_SUCCESS); @@ -464,7 +464,7 @@ void Test_SAMPLE_APP_ResetCounters(void) memset(&TestMsg, 0, sizeof(TestMsg)); - UT_CHECKEVENT_SETUP(&EventTest, SAMPLE_APP_COMMANDRST_INF_EID, "SAMPLE: RESET command"); + UT_CHECKEVENT_SETUP(&EventTest, SAMPLE_APP_RESET_INF_EID, "SAMPLE: RESET command"); UtAssert_INT32_EQ(SAMPLE_APP_ResetCounters(&TestMsg), CFE_SUCCESS); @@ -527,7 +527,7 @@ void Test_SAMPLE_APP_VerifyCmdLength(void) * test a match case */ UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &size, sizeof(size), false); - UT_CHECKEVENT_SETUP(&EventTest, SAMPLE_APP_LEN_ERR_EID, + UT_CHECKEVENT_SETUP(&EventTest, SAMPLE_APP_CMD_LEN_ERR_EID, "Invalid Msg length: ID = 0x%X, CC = %u, Len = %u, Expected = %u"); SAMPLE_APP_VerifyCmdLength(NULL, size); From 5b49af7b234b5b306fd86877540c52528846dc8d Mon Sep 17 00:00:00 2001 From: Avi Date: Thu, 2 Feb 2023 11:56:31 +1000 Subject: [PATCH 2/9] Fix #194, Remove component-specific cFE header #includes --- fsw/src/sample_app.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/fsw/src/sample_app.h b/fsw/src/sample_app.h index 5e9006d..0f13d85 100644 --- a/fsw/src/sample_app.h +++ b/fsw/src/sample_app.h @@ -29,10 +29,6 @@ ** Required header files. */ #include "cfe.h" -#include "cfe_error.h" -#include "cfe_evs.h" -#include "cfe_sb.h" -#include "cfe_es.h" #include "sample_app_perfids.h" #include "sample_app_msgids.h" From de9e945ef4210771411c07a876a3e7d36773ef58 Mon Sep 17 00:00:00 2001 From: Avi Date: Mon, 6 Mar 2023 13:43:53 +1000 Subject: [PATCH 3/9] Fix #197, Refactor SAMPLE_APP_Init/Process to remove multiple returns --- fsw/src/sample_app.c | 168 +++++++++--------- fsw/src/sample_app.h | 2 +- fsw/src/sample_app_events.h | 2 +- fsw/src/sample_app_msg.h | 6 +- .../coveragetest/coveragetest_sample_app.c | 4 +- 5 files changed, 93 insertions(+), 89 deletions(-) diff --git a/fsw/src/sample_app.c b/fsw/src/sample_app.c index 2961237..8a2f115 100644 --- a/fsw/src/sample_app.c +++ b/fsw/src/sample_app.c @@ -54,7 +54,7 @@ void SAMPLE_APP_Main(void) CFE_ES_PerfLogEntry(SAMPLE_APP_PERF_ID); /* - ** Perform application specific initialization + ** Perform application-specific initialization ** If the Initialization fails, set the RunStatus to ** CFE_ES_RunStatus_APP_ERROR and the App will not enter the RunLoop */ @@ -65,7 +65,7 @@ void SAMPLE_APP_Main(void) } /* - ** SAMPLE Runloop + ** Sample App Runloop */ while (CFE_ES_RunLoop(&SAMPLE_APP_Data.RunStatus) == true) { @@ -135,73 +135,77 @@ int32 SAMPLE_APP_Init(void) if (status != CFE_SUCCESS) { CFE_ES_WriteToSysLog("Sample App: Error Registering Events, RC = 0x%08lX\n", (unsigned long)status); - return status; } - - /* - ** Initialize housekeeping packet (clear user data area). - */ - CFE_MSG_Init(CFE_MSG_PTR(SAMPLE_APP_Data.HkTlm.TelemetryHeader), CFE_SB_ValueToMsgId(SAMPLE_APP_HK_TLM_MID), - sizeof(SAMPLE_APP_Data.HkTlm)); - - /* - ** Create Software Bus message pipe. - */ - status = CFE_SB_CreatePipe(&SAMPLE_APP_Data.CommandPipe, SAMPLE_APP_Data.PipeDepth, SAMPLE_APP_Data.PipeName); - if (status != CFE_SUCCESS) + else { - CFE_ES_WriteToSysLog("Sample App: Error creating pipe, RC = 0x%08lX\n", (unsigned long)status); - return status; + /* + ** Initialize housekeeping packet (clear user data area). + */ + CFE_MSG_Init(CFE_MSG_PTR(SAMPLE_APP_Data.HkTlm.TelemetryHeader), CFE_SB_ValueToMsgId(SAMPLE_APP_HK_TLM_MID), + sizeof(SAMPLE_APP_Data.HkTlm)); + + /* + ** Create Software Bus message pipe. + */ + status = CFE_SB_CreatePipe(&SAMPLE_APP_Data.CommandPipe, SAMPLE_APP_Data.PipeDepth, SAMPLE_APP_Data.PipeName); + if (status != CFE_SUCCESS) + { + CFE_ES_WriteToSysLog("Sample App: Error creating pipe, RC = 0x%08lX\n", (unsigned long)status); + } } - /* - ** Subscribe to Housekeeping request commands - */ - status = CFE_SB_Subscribe(CFE_SB_ValueToMsgId(SAMPLE_APP_SEND_HK_MID), SAMPLE_APP_Data.CommandPipe); - if (status != CFE_SUCCESS) + if (status == CFE_SUCCESS) { - CFE_ES_WriteToSysLog("Sample App: Error Subscribing to HK request, RC = 0x%08lX\n", (unsigned long)status); - return status; + /* + ** Subscribe to Housekeeping request commands + */ + status = CFE_SB_Subscribe(CFE_SB_ValueToMsgId(SAMPLE_APP_SEND_HK_MID), SAMPLE_APP_Data.CommandPipe); + if (status != CFE_SUCCESS) + { + CFE_ES_WriteToSysLog("Sample App: Error Subscribing to HK request, RC = 0x%08lX\n", (unsigned long)status); + } } - /* - ** Subscribe to ground command packets - */ - status = CFE_SB_Subscribe(CFE_SB_ValueToMsgId(SAMPLE_APP_CMD_MID), SAMPLE_APP_Data.CommandPipe); - if (status != CFE_SUCCESS) + if (status == CFE_SUCCESS) { - CFE_ES_WriteToSysLog("Sample App: Error Subscribing to Command, RC = 0x%08lX\n", (unsigned long)status); - - return status; + /* + ** Subscribe to ground command packets + */ + status = CFE_SB_Subscribe(CFE_SB_ValueToMsgId(SAMPLE_APP_CMD_MID), SAMPLE_APP_Data.CommandPipe); + if (status != CFE_SUCCESS) + { + CFE_ES_WriteToSysLog("Sample App: Error Subscribing to Command, RC = 0x%08lX\n", (unsigned long)status); + } } - /* - ** Register Table(s) - */ - status = CFE_TBL_Register(&SAMPLE_APP_Data.TblHandles[0], "SampleAppTable", sizeof(SAMPLE_APP_Table_t), - CFE_TBL_OPT_DEFAULT, SAMPLE_APP_TblValidationFunc); - if (status != CFE_SUCCESS) + if (status == CFE_SUCCESS) { - CFE_ES_WriteToSysLog("Sample App: Error Registering Table, RC = 0x%08lX\n", (unsigned long)status); + /* + ** Register Table(s) + */ + status = CFE_TBL_Register(&SAMPLE_APP_Data.TblHandles[0], "SampleAppTable", sizeof(SAMPLE_APP_Table_t), + CFE_TBL_OPT_DEFAULT, SAMPLE_APP_TblValidationFunc); + if (status != CFE_SUCCESS) + { + CFE_ES_WriteToSysLog("Sample App: Error Registering Table, RC = 0x%08lX\n", (unsigned long)status); + } + else + { + status = CFE_TBL_Load(SAMPLE_APP_Data.TblHandles[0], CFE_TBL_SRC_FILE, SAMPLE_APP_TABLE_FILE); + } - return status; - } - else - { - status = CFE_TBL_Load(SAMPLE_APP_Data.TblHandles[0], CFE_TBL_SRC_FILE, SAMPLE_APP_TABLE_FILE); + CFE_EVS_SendEvent(SAMPLE_APP_STARTUP_INF_EID, CFE_EVS_EventType_INFORMATION, "Sample App Initialized.%s", + SAMPLE_APP_VERSION_STRING); } - CFE_EVS_SendEvent(SAMPLE_APP_STARTUP_INF_EID, CFE_EVS_EventType_INFORMATION, "SAMPLE App Initialized.%s", - SAMPLE_APP_VERSION_STRING); - - return CFE_SUCCESS; + return status; } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ /* */ /* Purpose: */ -/* This routine will process any packet that is received on the SAMPLE */ -/* command pipe. */ +/* This routine will process any packet that is received on the Sample */ +/* App command pipe. */ /* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void SAMPLE_APP_ProcessCommandPacket(CFE_SB_Buffer_t *SBBufPtr) @@ -229,7 +233,7 @@ void SAMPLE_APP_ProcessCommandPacket(CFE_SB_Buffer_t *SBBufPtr) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ /* */ -/* SAMPLE ground commands */ +/* Process Ground Commands */ /* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ void SAMPLE_APP_ProcessGroundCommand(CFE_SB_Buffer_t *SBBufPtr) @@ -239,7 +243,7 @@ void SAMPLE_APP_ProcessGroundCommand(CFE_SB_Buffer_t *SBBufPtr) CFE_MSG_GetFcnCode(&SBBufPtr->Msg, &CommandCode); /* - ** Process "known" SAMPLE app ground commands + ** Process "known" Sample App ground commands */ switch (CommandCode) { @@ -248,7 +252,6 @@ void SAMPLE_APP_ProcessGroundCommand(CFE_SB_Buffer_t *SBBufPtr) { SAMPLE_APP_Noop((SAMPLE_APP_NoopCmd_t *)SBBufPtr); } - break; case SAMPLE_APP_RESET_COUNTERS_CC: @@ -256,7 +259,6 @@ void SAMPLE_APP_ProcessGroundCommand(CFE_SB_Buffer_t *SBBufPtr) { SAMPLE_APP_ResetCounters((SAMPLE_APP_ResetCountersCmd_t *)SBBufPtr); } - break; case SAMPLE_APP_PROCESS_CC: @@ -264,7 +266,6 @@ void SAMPLE_APP_ProcessGroundCommand(CFE_SB_Buffer_t *SBBufPtr) { SAMPLE_APP_Process((SAMPLE_APP_ProcessCmd_t *)SBBufPtr); } - break; /* default case already found during FC vs length test */ @@ -279,9 +280,10 @@ void SAMPLE_APP_ProcessGroundCommand(CFE_SB_Buffer_t *SBBufPtr) /* */ /* Purpose: */ /* This function is triggered in response to a task telemetry request */ -/* from the housekeeping task. This function will gather the Apps */ +/* from the housekeeping task. This function will gather the App's */ /* telemetry, packetize it and send it to the housekeeping task via */ -/* the software bus */ +/* the software bus. */ +/* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ int32 SAMPLE_APP_ReportHousekeeping(const CFE_MSG_CommandHeader_t *Msg) { @@ -312,7 +314,7 @@ int32 SAMPLE_APP_ReportHousekeeping(const CFE_MSG_CommandHeader_t *Msg) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ /* */ -/* SAMPLE NOOP commands */ +/* Sample App NOOP command */ /* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ int32 SAMPLE_APP_Noop(const SAMPLE_APP_NoopCmd_t *Msg) @@ -345,7 +347,7 @@ int32 SAMPLE_APP_ResetCounters(const SAMPLE_APP_ResetCountersCmd_t *Msg) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ /* */ /* Purpose: */ -/* This function Process Ground Station Command */ +/* This function processes Ground Station Commands */ /* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ int32 SAMPLE_APP_Process(const SAMPLE_APP_ProcessCmd_t *Msg) @@ -361,24 +363,26 @@ int32 SAMPLE_APP_Process(const SAMPLE_APP_ProcessCmd_t *Msg) if (status < CFE_SUCCESS) { CFE_ES_WriteToSysLog("Sample App: Fail to get table address: 0x%08lx", (unsigned long)status); - return status; } + else + { + CFE_ES_WriteToSysLog("Sample App: Table Value 1: %d Value 2: %d", TblPtr->Int1, TblPtr->Int2); - CFE_ES_WriteToSysLog("Sample App: Table Value 1: %d Value 2: %d", TblPtr->Int1, TblPtr->Int2); - - SAMPLE_APP_GetCrc(TableName); + 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); - return status; + 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_LIB */ + SAMPLE_LIB_Function(); + } } - /* Invoke a function provided by SAMPLE_APP_LIB */ - SAMPLE_LIB_Function(); - - return CFE_SUCCESS; + return status; } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ @@ -416,11 +420,11 @@ bool SAMPLE_APP_VerifyCmdLength(CFE_MSG_Message_t *MsgPtr, size_t ExpectedLength return result; } -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -/* */ -/* Verify contents of First Table buffer contents */ -/* */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ +/* */ +/* Verify contents of First Table buffer contents */ +/* */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ int32 SAMPLE_APP_TblValidationFunc(void *TblData) { int32 ReturnCode = CFE_SUCCESS; @@ -438,11 +442,11 @@ int32 SAMPLE_APP_TblValidationFunc(void *TblData) return ReturnCode; } -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -/* */ -/* Output CRC */ -/* */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ +/* */ +/* Output CRC */ +/* */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ void SAMPLE_APP_GetCrc(const char *TableName) { int32 status; diff --git a/fsw/src/sample_app.h b/fsw/src/sample_app.h index 5e9006d..d73d063 100644 --- a/fsw/src/sample_app.h +++ b/fsw/src/sample_app.h @@ -19,7 +19,7 @@ /** * @file * - * Main header file for the SAMPLE application + * Main header file for the Sample application */ #ifndef SAMPLE_APP_H diff --git a/fsw/src/sample_app_events.h b/fsw/src/sample_app_events.h index 46e7aaf..b92b9e8 100644 --- a/fsw/src/sample_app_events.h +++ b/fsw/src/sample_app_events.h @@ -19,7 +19,7 @@ /** * @file * - * Define SAMPLE App Events IDs + * Define Sample App Events IDs */ #ifndef SAMPLE_APP_EVENTS_H diff --git a/fsw/src/sample_app_msg.h b/fsw/src/sample_app_msg.h index 537d1d7..c08b8c1 100644 --- a/fsw/src/sample_app_msg.h +++ b/fsw/src/sample_app_msg.h @@ -19,14 +19,14 @@ /** * @file * - * Define SAMPLE App Messages and info + * Define Sample App messages and info */ #ifndef SAMPLE_APP_MSG_H #define SAMPLE_APP_MSG_H /* -** SAMPLE App command codes +** Sample App command codes */ #define SAMPLE_APP_NOOP_CC 0 #define SAMPLE_APP_RESET_COUNTERS_CC 1 @@ -55,7 +55,7 @@ typedef SAMPLE_APP_NoArgsCmd_t SAMPLE_APP_ProcessCmd_t; /*************************************************************************/ /* -** Type definition (SAMPLE App housekeeping) +** Type definition (Sample App housekeeping) */ typedef struct diff --git a/unit-test/coveragetest/coveragetest_sample_app.c b/unit-test/coveragetest/coveragetest_sample_app.c index a1ca631..dbb391d 100644 --- a/unit-test/coveragetest/coveragetest_sample_app.c +++ b/unit-test/coveragetest/coveragetest_sample_app.c @@ -20,11 +20,11 @@ ** File: coveragetest_sample_app.c ** ** Purpose: -** Coverage Unit Test cases for the SAMPLE Application +** Coverage Unit Test cases for the Sample Application ** ** Notes: ** This implements various test cases to exercise all code -** paths through all functions defined in the SAMPLE application. +** paths through all functions defined in the Sample application. ** ** It is primarily focused at providing examples of the various ** stub configurations, hook functions, and wrapper calls that From d08ee4374fd0fe622ad2d70336cfcacbd8fd9ab4 Mon Sep 17 00:00:00 2001 From: Avi Weiss Date: Thu, 23 Mar 2023 08:20:14 +1000 Subject: [PATCH 4/9] Fix #141, Zero out global data structure during initialization --- fsw/src/sample_app.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/fsw/src/sample_app.c b/fsw/src/sample_app.c index 2961237..6684f0b 100644 --- a/fsw/src/sample_app.c +++ b/fsw/src/sample_app.c @@ -112,13 +112,10 @@ int32 SAMPLE_APP_Init(void) { int32 status; - SAMPLE_APP_Data.RunStatus = CFE_ES_RunStatus_APP_RUN; + /* Zero out the global data structure */ + memset(&SAMPLE_APP_Data, 0, sizeof(SAMPLE_APP_Data)); - /* - ** Initialize app command execution counters - */ - SAMPLE_APP_Data.CmdCounter = 0; - SAMPLE_APP_Data.ErrCounter = 0; + SAMPLE_APP_Data.RunStatus = CFE_ES_RunStatus_APP_RUN; /* ** Initialize app configuration data From 3aebb801992b99e22825798ccf82d01d16c7eb3d Mon Sep 17 00:00:00 2001 From: Avi Date: Tue, 7 Mar 2023 16:38:34 +1000 Subject: [PATCH 5/9] Fix #199, Add test for missing branch in SAMPLE_APP_Process() --- .../coveragetest/coveragetest_sample_app.c | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/unit-test/coveragetest/coveragetest_sample_app.c b/unit-test/coveragetest/coveragetest_sample_app.c index a1ca631..e550a94 100644 --- a/unit-test/coveragetest/coveragetest_sample_app.c +++ b/unit-test/coveragetest/coveragetest_sample_app.c @@ -493,6 +493,13 @@ void Test_SAMPLE_APP_ProcessCC(void) UT_SetDataBuffer(UT_KEY(CFE_TBL_GetAddress), &TblPtr, sizeof(TblPtr), false); UtAssert_INT32_EQ(SAMPLE_APP_Process(&TestMsg), CFE_SUCCESS); + /* + * Successful operation results in two calls to CFE_ES_WriteToSysLog() - one + * in this function reporting the table values, and one through + * SAMPLE_APP_GetCrc(). + */ + UtAssert_STUB_COUNT(CFE_ES_WriteToSysLog, 2); + /* * Confirm that the CFE_TBL_GetAddress() call was done */ @@ -505,11 +512,26 @@ void Test_SAMPLE_APP_ProcessCC(void) UtAssert_STUB_COUNT(SAMPLE_LIB_Function, 1); /* - * Configure the CFE_TBL_GetAddress function to return an error - * Exercise the error return path + * Configure the CFE_TBL_GetAddress function to return an error. + * Exercise the error return path. + * Error at this point should add only one additional call to + * CFE_ES_WriteToSysLog() through the CFE_TBL_GetAddress() error path. */ UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_GetAddress), CFE_TBL_ERR_UNREGISTERED); UtAssert_INT32_EQ(SAMPLE_APP_Process(&TestMsg), CFE_TBL_ERR_UNREGISTERED); + UtAssert_STUB_COUNT(CFE_ES_WriteToSysLog, 3); + + /* + * Configure CFE_TBL_ReleaseAddress() to return an error, exercising the + * error return path. + * Confirm three additional calls to CFE_ES_WriteToSysLog() - one + * reporting the table values, one through SAMPLE_APP_GetCrc() and one + * through the CFE_TBL_ReleaseAddress() error path. + */ + UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_GetAddress), CFE_SUCCESS); + UT_SetDefaultReturnValue(UT_KEY(CFE_TBL_ReleaseAddress), CFE_TBL_ERR_NO_ACCESS); + UtAssert_INT32_EQ(SAMPLE_APP_Process(&TestMsg), CFE_TBL_ERR_NO_ACCESS); + UtAssert_STUB_COUNT(CFE_ES_WriteToSysLog, 6); } void Test_SAMPLE_APP_VerifyCmdLength(void) From 599bfca018c5f010ec2e40435c19637cc1a37a76 Mon Sep 17 00:00:00 2001 From: Avi Date: Wed, 22 Feb 2023 10:30:53 +1000 Subject: [PATCH 6/9] Fix #45, Move cmds and utils into separate files --- CMakeLists.txt | 4 +- fsw/src/sample_app.c | 161 +----------------- fsw/src/sample_app.h | 13 +- fsw/src/sample_app_cmds.c | 107 ++++++++++++ fsw/src/sample_app_cmds.h | 36 ++++ fsw/src/sample_app_utils.c | 110 ++++++++++++ fsw/src/sample_app_utils.h | 36 ++++ unit-test/CMakeLists.txt | 3 +- .../coveragetest/coveragetest_sample_app.c | 1 - .../sample_app_coveragetest_common.h | 4 +- unit-test/inc/ut_sample_app.h | 1 - 11 files changed, 307 insertions(+), 169 deletions(-) create mode 100644 fsw/src/sample_app_cmds.c create mode 100644 fsw/src/sample_app_cmds.h create mode 100644 fsw/src/sample_app_utils.c create mode 100644 fsw/src/sample_app_utils.h diff --git a/CMakeLists.txt b/CMakeLists.txt index f83279b..d499b8a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,9 @@ project(CFE_SAMPLE_APP C) # Create the app module -add_cfe_app(sample_app fsw/src/sample_app.c) +add_cfe_app(sample_app fsw/src/sample_app.c + fsw/src/sample_app_cmds.c + fsw/src/sample_app_utils.c) # Include the public API from sample_lib to demonstrate how # to call library-provided functions diff --git a/fsw/src/sample_app.c b/fsw/src/sample_app.c index 2961237..012d863 100644 --- a/fsw/src/sample_app.c +++ b/fsw/src/sample_app.c @@ -24,15 +24,15 @@ /* ** Include Files: */ +#include + +#include "sample_app.h" +#include "sample_app_cmds.h" +#include "sample_app_utils.h" #include "sample_app_events.h" #include "sample_app_version.h" -#include "sample_app.h" #include "sample_app_table.h" -/* The sample_lib module provides the SAMPLE_LIB_Function() prototype */ -#include -#include "sample_lib.h" - /* ** global data */ @@ -309,154 +309,3 @@ int32 SAMPLE_APP_ReportHousekeeping(const CFE_MSG_CommandHeader_t *Msg) return CFE_SUCCESS; } - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ -/* */ -/* SAMPLE NOOP commands */ -/* */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ -int32 SAMPLE_APP_Noop(const SAMPLE_APP_NoopCmd_t *Msg) -{ - SAMPLE_APP_Data.CmdCounter++; - - CFE_EVS_SendEvent(SAMPLE_APP_COMMANDNOP_INF_EID, CFE_EVS_EventType_INFORMATION, "SAMPLE: NOOP command %s", - SAMPLE_APP_VERSION); - - return CFE_SUCCESS; -} - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ -/* */ -/* Purpose: */ -/* This function resets all the global counter variables that are */ -/* part of the task telemetry. */ -/* */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -int32 SAMPLE_APP_ResetCounters(const SAMPLE_APP_ResetCountersCmd_t *Msg) -{ - SAMPLE_APP_Data.CmdCounter = 0; - SAMPLE_APP_Data.ErrCounter = 0; - - CFE_EVS_SendEvent(SAMPLE_APP_COMMANDRST_INF_EID, CFE_EVS_EventType_INFORMATION, "SAMPLE: RESET command"); - - return CFE_SUCCESS; -} - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ -/* */ -/* Purpose: */ -/* This function Process Ground Station Command */ -/* */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -int32 SAMPLE_APP_Process(const SAMPLE_APP_ProcessCmd_t *Msg) -{ - int32 status; - SAMPLE_APP_Table_t *TblPtr; - const char * TableName = "SAMPLE_APP.SampleAppTable"; - - /* Sample Use of Table */ - - status = CFE_TBL_GetAddress((void *)&TblPtr, 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: 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); - return status; - } - - /* Invoke a function provided by SAMPLE_APP_LIB */ - SAMPLE_LIB_Function(); - - return CFE_SUCCESS; -} - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ -/* */ -/* Verify command packet length */ -/* */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ -bool SAMPLE_APP_VerifyCmdLength(CFE_MSG_Message_t *MsgPtr, size_t ExpectedLength) -{ - bool result = true; - size_t ActualLength = 0; - CFE_SB_MsgId_t MsgId = CFE_SB_INVALID_MSG_ID; - CFE_MSG_FcnCode_t FcnCode = 0; - - CFE_MSG_GetSize(MsgPtr, &ActualLength); - - /* - ** Verify the command packet length. - */ - if (ExpectedLength != ActualLength) - { - CFE_MSG_GetMsgId(MsgPtr, &MsgId); - CFE_MSG_GetFcnCode(MsgPtr, &FcnCode); - - CFE_EVS_SendEvent(SAMPLE_APP_LEN_ERR_EID, CFE_EVS_EventType_ERROR, - "Invalid Msg length: ID = 0x%X, CC = %u, Len = %u, Expected = %u", - (unsigned int)CFE_SB_MsgIdToValue(MsgId), (unsigned int)FcnCode, (unsigned int)ActualLength, - (unsigned int)ExpectedLength); - - result = false; - - SAMPLE_APP_Data.ErrCounter++; - } - - return result; -} - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -/* */ -/* Verify contents of First Table buffer contents */ -/* */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -int32 SAMPLE_APP_TblValidationFunc(void *TblData) -{ - int32 ReturnCode = CFE_SUCCESS; - SAMPLE_APP_Table_t *TblDataPtr = (SAMPLE_APP_Table_t *)TblData; - - /* - ** Sample Table Validation - */ - if (TblDataPtr->Int1 > SAMPLE_APP_TBL_ELEMENT_1_MAX) - { - /* First element is out of range, return an appropriate error code */ - ReturnCode = SAMPLE_APP_TABLE_OUT_OF_RANGE_ERR_CODE; - } - - return ReturnCode; -} - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -/* */ -/* Output CRC */ -/* */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -void SAMPLE_APP_GetCrc(const char *TableName) -{ - int32 status; - uint32 Crc; - CFE_TBL_Info_t TblInfoPtr; - - status = CFE_TBL_GetInfo(&TblInfoPtr, TableName); - if (status != CFE_SUCCESS) - { - CFE_ES_WriteToSysLog("Sample App: Error Getting Table Info"); - } - else - { - Crc = TblInfoPtr.Crc; - CFE_ES_WriteToSysLog("Sample App: CRC: 0x%08lX\n\n", (unsigned long)Crc); - } -} diff --git a/fsw/src/sample_app.h b/fsw/src/sample_app.h index 5e9006d..0f9d448 100644 --- a/fsw/src/sample_app.h +++ b/fsw/src/sample_app.h @@ -88,6 +88,11 @@ typedef struct CFE_TBL_Handle_t TblHandles[SAMPLE_APP_NUMBER_OF_TABLES]; } SAMPLE_APP_Data_t; +/* +** Global data structure +*/ +extern SAMPLE_APP_Data_t SAMPLE_APP_Data; + /****************************************************************************/ /* ** Local function prototypes. @@ -100,13 +105,5 @@ int32 SAMPLE_APP_Init(void); void SAMPLE_APP_ProcessCommandPacket(CFE_SB_Buffer_t *SBBufPtr); void SAMPLE_APP_ProcessGroundCommand(CFE_SB_Buffer_t *SBBufPtr); int32 SAMPLE_APP_ReportHousekeeping(const CFE_MSG_CommandHeader_t *Msg); -int32 SAMPLE_APP_ResetCounters(const SAMPLE_APP_ResetCountersCmd_t *Msg); -int32 SAMPLE_APP_Process(const SAMPLE_APP_ProcessCmd_t *Msg); -int32 SAMPLE_APP_Noop(const SAMPLE_APP_NoopCmd_t *Msg); -void SAMPLE_APP_GetCrc(const char *TableName); - -int32 SAMPLE_APP_TblValidationFunc(void *TblData); - -bool SAMPLE_APP_VerifyCmdLength(CFE_MSG_Message_t *MsgPtr, size_t ExpectedLength); #endif /* SAMPLE_APP_H */ diff --git a/fsw/src/sample_app_cmds.c b/fsw/src/sample_app_cmds.c new file mode 100644 index 0000000..b8cf2ff --- /dev/null +++ b/fsw/src/sample_app_cmds.c @@ -0,0 +1,107 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/** + * \file + * This file contains the source code for the Sample App Ground Command-handling functions + */ + +/* +** Include Files: +*/ +#include "sample_app.h" +#include "sample_app_cmds.h" +#include "sample_app_events.h" +#include "sample_app_version.h" +#include "sample_app_table.h" +#include "sample_app_utils.h" +#include "sample_app_msg.h" + +/* The sample_lib module provides the SAMPLE_Function() prototype */ +#include "sample_lib.h" + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ +/* */ +/* SAMPLE NOOP commands */ +/* */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ +int32 SAMPLE_APP_Noop(const SAMPLE_APP_NoopCmd_t *Msg) +{ + SAMPLE_APP_Data.CmdCounter++; + + CFE_EVS_SendEvent(SAMPLE_APP_COMMANDNOP_INF_EID, CFE_EVS_EventType_INFORMATION, "SAMPLE: NOOP command %s", + SAMPLE_APP_VERSION); + + return CFE_SUCCESS; +} + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ +/* */ +/* Purpose: */ +/* This function resets all the global counter variables that are */ +/* part of the task telemetry. */ +/* */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +int32 SAMPLE_APP_ResetCounters(const SAMPLE_APP_ResetCountersCmd_t *Msg) +{ + SAMPLE_APP_Data.CmdCounter = 0; + SAMPLE_APP_Data.ErrCounter = 0; + + CFE_EVS_SendEvent(SAMPLE_APP_COMMANDRST_INF_EID, CFE_EVS_EventType_INFORMATION, "SAMPLE: RESET command"); + + return CFE_SUCCESS; +} + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ +/* */ +/* Purpose: */ +/* This function Process Ground Station Command */ +/* */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +int32 SAMPLE_APP_Process(const SAMPLE_APP_ProcessCmd_t *Msg) +{ + int32 status; + SAMPLE_APP_Table_t *TblPtr; + const char * TableName = "SAMPLE_APP.SampleAppTable"; + + /* Sample Use of Table */ + + status = CFE_TBL_GetAddress((void *)&TblPtr, 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: 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); + return status; + } + + /* Invoke a function provided by SAMPLE_APP_LIB */ + SAMPLE_LIB_Function(); + + return CFE_SUCCESS; +} \ No newline at end of file diff --git a/fsw/src/sample_app_cmds.h b/fsw/src/sample_app_cmds.h new file mode 100644 index 0000000..7b899e9 --- /dev/null +++ b/fsw/src/sample_app_cmds.h @@ -0,0 +1,36 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/** + * @file + * This file contains the prototypes for the Sample App Ground Command-handling functions + */ + +#ifndef SAMPLE_APP_CMDS_H +#define SAMPLE_APP_CMDS_H + +/* +** Required header files. +*/ +#include "sample_app.h" + +int32 SAMPLE_APP_ResetCounters(const SAMPLE_APP_ResetCountersCmd_t *Msg); +int32 SAMPLE_APP_Process(const SAMPLE_APP_ProcessCmd_t *Msg); +int32 SAMPLE_APP_Noop(const SAMPLE_APP_NoopCmd_t *Msg); + +#endif /* SAMPLE_APP_CMDS_H */ \ No newline at end of file diff --git a/fsw/src/sample_app_utils.c b/fsw/src/sample_app_utils.c new file mode 100644 index 0000000..9489e6b --- /dev/null +++ b/fsw/src/sample_app_utils.c @@ -0,0 +1,110 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/** + * \file + * This file contains the source code for the Sample App utility functions + */ + +/* +** Include Files: +*/ +#include "sample_app.h" +#include "sample_app_events.h" +#include "sample_app_table.h" +#include "sample_app_utils.h" + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ +/* */ +/* Verify command packet length */ +/* */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ +bool SAMPLE_APP_VerifyCmdLength(CFE_MSG_Message_t *MsgPtr, size_t ExpectedLength) +{ + bool result = true; + size_t ActualLength = 0; + CFE_SB_MsgId_t MsgId = CFE_SB_INVALID_MSG_ID; + CFE_MSG_FcnCode_t FcnCode = 0; + + CFE_MSG_GetSize(MsgPtr, &ActualLength); + + /* + ** Verify the command packet length. + */ + if (ExpectedLength != ActualLength) + { + CFE_MSG_GetMsgId(MsgPtr, &MsgId); + CFE_MSG_GetFcnCode(MsgPtr, &FcnCode); + + CFE_EVS_SendEvent(SAMPLE_APP_LEN_ERR_EID, CFE_EVS_EventType_ERROR, + "Invalid Msg length: ID = 0x%X, CC = %u, Len = %u, Expected = %u", + (unsigned int)CFE_SB_MsgIdToValue(MsgId), (unsigned int)FcnCode, (unsigned int)ActualLength, + (unsigned int)ExpectedLength); + + result = false; + + SAMPLE_APP_Data.ErrCounter++; + } + + return result; +} + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/* */ +/* Verify contents of First Table buffer contents */ +/* */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +int32 SAMPLE_APP_TblValidationFunc(void *TblData) +{ + int32 ReturnCode = CFE_SUCCESS; + SAMPLE_APP_Table_t *TblDataPtr = (SAMPLE_APP_Table_t *)TblData; + + /* + ** Sample Table Validation + */ + if (TblDataPtr->Int1 > SAMPLE_APP_TBL_ELEMENT_1_MAX) + { + /* First element is out of range, return an appropriate error code */ + ReturnCode = SAMPLE_APP_TABLE_OUT_OF_RANGE_ERR_CODE; + } + + return ReturnCode; +} + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/* */ +/* Output CRC */ +/* */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +void SAMPLE_APP_GetCrc(const char *TableName) +{ + int32 status; + uint32 Crc; + CFE_TBL_Info_t TblInfoPtr; + + status = CFE_TBL_GetInfo(&TblInfoPtr, TableName); + if (status != CFE_SUCCESS) + { + CFE_ES_WriteToSysLog("Sample App: Error Getting Table Info"); + } + else + { + Crc = TblInfoPtr.Crc; + CFE_ES_WriteToSysLog("Sample App: CRC: 0x%08lX\n\n", (unsigned long)Crc); + } +} diff --git a/fsw/src/sample_app_utils.h b/fsw/src/sample_app_utils.h new file mode 100644 index 0000000..369f050 --- /dev/null +++ b/fsw/src/sample_app_utils.h @@ -0,0 +1,36 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/** + * @file + * This file contains the prototypes for the Sample App utility functions + */ + +#ifndef SAMPLE_APP_UTILS_H +#define SAMPLE_APP_UTILS_H + +/* +** Required header files. +*/ +#include "sample_app.h" + +bool SAMPLE_APP_VerifyCmdLength(CFE_MSG_Message_t *MsgPtr, size_t ExpectedLength); +int32 SAMPLE_APP_TblValidationFunc(void *TblData); +void SAMPLE_APP_GetCrc(const char *TableName); + +#endif /* SAMPLE_APP_UTILS_H */ \ No newline at end of file diff --git a/unit-test/CMakeLists.txt b/unit-test/CMakeLists.txt index ed625c7..224c97d 100644 --- a/unit-test/CMakeLists.txt +++ b/unit-test/CMakeLists.txt @@ -23,7 +23,6 @@ include_directories(${PROJECT_SOURCE_DIR}/fsw/src) include_directories(${CMAKE_CURRENT_SOURCE_DIR}/inc) - # Add a coverage test executable called "sample_app-ALL" that # covers all of the functions in sample_app. # @@ -34,6 +33,8 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/inc) add_cfe_coverage_test(sample_app ALL "coveragetest/coveragetest_sample_app.c" "${CFE_SAMPLE_APP_SOURCE_DIR}/fsw/src/sample_app.c" + "${CFE_SAMPLE_APP_SOURCE_DIR}/fsw/src/sample_app_cmds.c" + "${CFE_SAMPLE_APP_SOURCE_DIR}/fsw/src/sample_app_utils.c" ) # The sample_app uses library functions provided by sample_lib so must be linked diff --git a/unit-test/coveragetest/coveragetest_sample_app.c b/unit-test/coveragetest/coveragetest_sample_app.c index a1ca631..e8bfd2f 100644 --- a/unit-test/coveragetest/coveragetest_sample_app.c +++ b/unit-test/coveragetest/coveragetest_sample_app.c @@ -35,7 +35,6 @@ /* * Includes */ - #include "sample_lib.h" /* For SAMPLE_LIB_Function */ #include "sample_app_coveragetest_common.h" #include "ut_sample_app.h" diff --git a/unit-test/coveragetest/sample_app_coveragetest_common.h b/unit-test/coveragetest/sample_app_coveragetest_common.h index 134e2ca..464a4a9 100644 --- a/unit-test/coveragetest/sample_app_coveragetest_common.h +++ b/unit-test/coveragetest/sample_app_coveragetest_common.h @@ -34,8 +34,10 @@ #include "utstubs.h" #include "cfe.h" -#include "sample_app_events.h" #include "sample_app.h" +#include "sample_app_cmds.h" +#include "sample_app_utils.h" +#include "sample_app_events.h" #include "sample_app_table.h" /* diff --git a/unit-test/inc/ut_sample_app.h b/unit-test/inc/ut_sample_app.h index ca8567e..88f222a 100644 --- a/unit-test/inc/ut_sample_app.h +++ b/unit-test/inc/ut_sample_app.h @@ -39,7 +39,6 @@ * Necessary to include these here to get the definition of the * "SAMPLE_APP_Data_t" typedef. */ -#include "sample_app_events.h" #include "sample_app.h" /* From 6d3d30e8c95f1ba47e6e848b4e613c7f61a59735 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Wed, 25 Oct 2023 16:12:30 -0400 Subject: [PATCH 7/9] Fix #207, organize source files according to current patterns Re-organize the source files to adhere to the recommended patterns. --- CMakeLists.txt | 8 +-- arch_build.cmake | 27 +++++++++ config/default_sample_app_fcncodes.h | 42 ++++++++++++++ config/default_sample_app_internal_cfg.h | 44 ++++++++++++++ config/default_sample_app_mission_cfg.h | 36 ++++++++++++ config/default_sample_app_msg.h | 38 +++++++++++++ config/default_sample_app_msgdefs.h | 44 ++++++++++++++ .../default_sample_app_msgids.h | 8 +-- .../default_sample_app_msgstruct.h | 57 ++++++++++--------- .../default_sample_app_perfids.h | 6 +- config/default_sample_app_platform_cfg.h | 41 +++++++++++++ .../default_sample_app_tbl.h | 23 ++++---- config/default_sample_app_tbldefs.h | 45 +++++++++++++++ config/default_sample_app_tblstruct.h | 45 +++++++++++++++ .../sample_app_eventids.h} | 2 +- fsw/src/sample_app.c | 6 +- fsw/src/sample_app.h | 14 +---- fsw/tables/sample_app_tbl.c | 2 +- mission_build.cmake | 49 ++++++++++++++++ .../sample_app_coveragetest_common.h | 4 +- unit-test/inc/ut_sample_app.h | 2 +- 21 files changed, 470 insertions(+), 73 deletions(-) create mode 100644 arch_build.cmake create mode 100644 config/default_sample_app_fcncodes.h create mode 100644 config/default_sample_app_internal_cfg.h create mode 100644 config/default_sample_app_mission_cfg.h create mode 100644 config/default_sample_app_msg.h create mode 100644 config/default_sample_app_msgdefs.h rename fsw/platform_inc/sample_app_msgids.h => config/default_sample_app_msgids.h (87%) rename fsw/src/sample_app_msg.h => config/default_sample_app_msgstruct.h (60%) rename fsw/mission_inc/sample_app_perfids.h => config/default_sample_app_perfids.h (93%) create mode 100644 config/default_sample_app_platform_cfg.h rename fsw/platform_inc/sample_app_table.h => config/default_sample_app_tbl.h (70%) create mode 100644 config/default_sample_app_tbldefs.h create mode 100644 config/default_sample_app_tblstruct.h rename fsw/{src/sample_app_events.h => inc/sample_app_eventids.h} (97%) create mode 100644 mission_build.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index f83279b..70e099f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,7 @@ project(CFE_SAMPLE_APP C) # Create the app module add_cfe_app(sample_app fsw/src/sample_app.c) +target_include_directories(sample_app PUBLIC fsw/inc) # Include the public API from sample_lib to demonstrate how # to call library-provided functions add_cfe_app_dependency(sample_app sample_lib) @@ -10,14 +11,9 @@ add_cfe_app_dependency(sample_app sample_lib) # Add table add_cfe_tables(sample_app fsw/tables/sample_app_tbl.c) -target_include_directories(sample_app PUBLIC - fsw/mission_inc - fsw/platform_inc -) - # If UT is enabled, then add the tests from the subdirectory # Note that this is an app, and therefore does not provide -# stub functions, as other entities would not typically make +# stub functions, as other entities would not typically make # direct function calls into this application. if (ENABLE_UNIT_TESTS) add_subdirectory(unit-test) diff --git a/arch_build.cmake b/arch_build.cmake new file mode 100644 index 0000000..d2d95e2 --- /dev/null +++ b/arch_build.cmake @@ -0,0 +1,27 @@ +########################################################### +# +# SAMPLE_APP platform build setup +# +# This file is evaluated as part of the "prepare" stage +# and can be used to set up prerequisites for the build, +# such as generating header files +# +########################################################### + +# The list of header files that control the SAMPLE_APP configuration +set(SAMPLE_APP_PLATFORM_CONFIG_FILE_LIST + sample_app_internal_cfg.h + sample_app_platform_cfg.h + sample_app_perfids.h + sample_app_msgids.h +) + +# Create wrappers around the all the config header files +# This makes them individually overridable by the missions, without modifying +# the distribution default copies +foreach(SAMPLE_APP_CFGFILE ${SAMPLE_APP_PLATFORM_CONFIG_FILE_LIST}) + generate_config_includefile( + FILE_NAME "${SAMPLE_APP_CFGFILE}" + FALLBACK_FILE "${CMAKE_CURRENT_LIST_DIR}/config/default_${SAMPLE_APP_CFGFILE}" + ) +endforeach() diff --git a/config/default_sample_app_fcncodes.h b/config/default_sample_app_fcncodes.h new file mode 100644 index 0000000..aec457f --- /dev/null +++ b/config/default_sample_app_fcncodes.h @@ -0,0 +1,42 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/** + * @file + * Specification for the SAMPLE_APP command function codes + * + * @note + * This file should be strictly limited to the command/function code (CC) + * macro definitions. Other definitions such as enums, typedefs, or other + * macros should be placed in the msgdefs.h or msg.h files. + */ +#ifndef SAMPLE_APP_FCNCODES_H +#define SAMPLE_APP_FCNCODES_H + +/************************************************************************ + * Macro Definitions + ************************************************************************/ + +/* +** Sample App command codes +*/ +#define SAMPLE_APP_NOOP_CC 0 +#define SAMPLE_APP_RESET_COUNTERS_CC 1 +#define SAMPLE_APP_PROCESS_CC 2 + +#endif diff --git a/config/default_sample_app_internal_cfg.h b/config/default_sample_app_internal_cfg.h new file mode 100644 index 0000000..32862ae --- /dev/null +++ b/config/default_sample_app_internal_cfg.h @@ -0,0 +1,44 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/** + * @file + * SAMPLE_APP Application Private Config Definitions + * + * This provides default values for configurable items that are internal + * to this module and do NOT affect the interface(s) of this module. Changes + * to items in this file only affect the local module and will be transparent + * to external entities that are using the public interface(s). + * + * @note This file may be overridden/superceded by mission-provided defintions + * either by overriding this header or by generating definitions from a command/data + * dictionary tool. + */ +#ifndef SAMPLE_APP_INTERNAL_CFG_H +#define SAMPLE_APP_INTERNAL_CFG_H + +/***********************************************************************/ +#define SAMPLE_APP_PIPE_DEPTH 32 /* Depth of the Command Pipe for Application */ + +#define SAMPLE_APP_NUMBER_OF_TABLES 1 /* Number of Table(s) */ + +#define SAMPLE_APP_TABLE_OUT_OF_RANGE_ERR_CODE -1 + +#define SAMPLE_APP_TBL_ELEMENT_1_MAX 10 + +#endif diff --git a/config/default_sample_app_mission_cfg.h b/config/default_sample_app_mission_cfg.h new file mode 100644 index 0000000..93d3307 --- /dev/null +++ b/config/default_sample_app_mission_cfg.h @@ -0,0 +1,36 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/** + * @file + * + * SAMPLE_APP Application Mission Configuration Header File + * + * This is a compatibility header for the "mission_cfg.h" file that has + * traditionally provided public config definitions for each CFS app. + * + * @note This file may be overridden/superceded by mission-provided defintions + * either by overriding this header or by generating definitions from a command/data + * dictionary tool. + */ +#ifndef SAMPLE_APP_MISSION_CFG_H +#define SAMPLE_APP_MISSION_CFG_H + +/* Placeholder - SAMPLE_APP currently has no mission-scope config options */ + +#endif diff --git a/config/default_sample_app_msg.h b/config/default_sample_app_msg.h new file mode 100644 index 0000000..1d94e43 --- /dev/null +++ b/config/default_sample_app_msg.h @@ -0,0 +1,38 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/** + * @file + * Specification for the SAMPLE_APP command and telemetry + * message data types. + * + * This is a compatibility header for the "sample_app_msg.h" file that has + * traditionally provided the message definitions for cFS apps. + * + * @note This file may be overridden/superceded by mission-provided defintions + * either by overriding this header or by generating definitions from a command/data + * dictionary tool. + */ +#ifndef SAMPLE_APP_MSG_H +#define SAMPLE_APP_MSG_H + +#include "sample_app_mission_cfg.h" +#include "sample_app_msgdefs.h" +#include "sample_app_msgstruct.h" + +#endif diff --git a/config/default_sample_app_msgdefs.h b/config/default_sample_app_msgdefs.h new file mode 100644 index 0000000..7ea7b82 --- /dev/null +++ b/config/default_sample_app_msgdefs.h @@ -0,0 +1,44 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/** + * @file + * Specification for the SAMPLE_APP command and telemetry + * message constant definitions. + * + * For SAMPLE_APP this is only the function/command code definitions + */ +#ifndef SAMPLE_APP_MSGDEFS_H +#define SAMPLE_APP_MSGDEFS_H + +#include "common_types.h" +#include "sample_app_fcncodes.h" + +/*************************************************************************/ +/* +** Type definition (Sample App housekeeping) +*/ + +typedef struct +{ + uint8 CommandErrorCounter; + uint8 CommandCounter; + uint8 spare[2]; +} SAMPLE_APP_HkTlm_Payload_t; + +#endif diff --git a/fsw/platform_inc/sample_app_msgids.h b/config/default_sample_app_msgids.h similarity index 87% rename from fsw/platform_inc/sample_app_msgids.h rename to config/default_sample_app_msgids.h index 154569e..6b11e55 100644 --- a/fsw/platform_inc/sample_app_msgids.h +++ b/config/default_sample_app_msgids.h @@ -18,12 +18,8 @@ /** * @file - * - * Define Sample App Message IDs - * - * \note The Sample App assumes default configuration which uses V1 of message id implementation + * SAMPLE_APP Application Message IDs */ - #ifndef SAMPLE_APP_MSGIDS_H #define SAMPLE_APP_MSGIDS_H @@ -33,4 +29,4 @@ /* V1 Telemetry Message IDs must be 0x08xx */ #define SAMPLE_APP_HK_TLM_MID 0x0883 -#endif /* SAMPLE_APP_MSGIDS_H */ +#endif diff --git a/fsw/src/sample_app_msg.h b/config/default_sample_app_msgstruct.h similarity index 60% rename from fsw/src/sample_app_msg.h rename to config/default_sample_app_msgstruct.h index 537d1d7..90d1a47 100644 --- a/fsw/src/sample_app_msg.h +++ b/config/default_sample_app_msgstruct.h @@ -18,30 +18,26 @@ /** * @file + * Specification for the SAMPLE_APP command and telemetry + * message data types. * - * Define SAMPLE App Messages and info + * @note + * Constants and enumerated types related to these message structures + * are defined in sample_app_msgdefs.h. */ +#ifndef SAMPLE_APP_MSGSTRUCT_H +#define SAMPLE_APP_MSGSTRUCT_H -#ifndef SAMPLE_APP_MSG_H -#define SAMPLE_APP_MSG_H +/************************************************************************ + * Includes + ************************************************************************/ -/* -** SAMPLE App command codes -*/ -#define SAMPLE_APP_NOOP_CC 0 -#define SAMPLE_APP_RESET_COUNTERS_CC 1 -#define SAMPLE_APP_PROCESS_CC 2 +#include "sample_app_mission_cfg.h" +#include "sample_app_msgdefs.h" +#include "cfe_msg_hdr.h" /*************************************************************************/ -/* -** Type definition (generic "no arguments" command) -*/ -typedef struct -{ - CFE_MSG_CommandHeader_t CmdHeader; /**< \brief Command header */ -} SAMPLE_APP_NoArgsCmd_t; - /* ** The following commands all share the "NoArgs" format ** @@ -49,21 +45,30 @@ typedef struct ** allows them to change independently in the future without changing the prototype ** of the handler function */ -typedef SAMPLE_APP_NoArgsCmd_t SAMPLE_APP_NoopCmd_t; -typedef SAMPLE_APP_NoArgsCmd_t SAMPLE_APP_ResetCountersCmd_t; -typedef SAMPLE_APP_NoArgsCmd_t SAMPLE_APP_ProcessCmd_t; +typedef struct +{ + CFE_MSG_CommandHeader_t CommandHeader; /**< \brief Command header */ +} SAMPLE_APP_NoopCmd_t; + +typedef struct +{ + CFE_MSG_CommandHeader_t CommandHeader; /**< \brief Command header */ +} SAMPLE_APP_ResetCountersCmd_t; + +typedef struct +{ + CFE_MSG_CommandHeader_t CommandHeader; /**< \brief Command header */ +} SAMPLE_APP_ProcessCmd_t; /*************************************************************************/ /* -** Type definition (SAMPLE App housekeeping) +** Type definition (Sample App housekeeping) */ typedef struct { - uint8 CommandErrorCounter; - uint8 CommandCounter; - uint8 spare[2]; -} SAMPLE_APP_HkTlm_Payload_t; + CFE_MSG_CommandHeader_t CommandHeader; /**< \brief Command header */ +} SAMPLE_APP_SendHkCmd_t; typedef struct { @@ -71,4 +76,4 @@ typedef struct SAMPLE_APP_HkTlm_Payload_t Payload; /**< \brief Telemetry payload */ } SAMPLE_APP_HkTlm_t; -#endif /* SAMPLE_APP_MSG_H */ +#endif /* SAMPLE_APP_MSGSTRUCT_H */ diff --git a/fsw/mission_inc/sample_app_perfids.h b/config/default_sample_app_perfids.h similarity index 93% rename from fsw/mission_inc/sample_app_perfids.h rename to config/default_sample_app_perfids.h index d87ea64..5c83334 100644 --- a/fsw/mission_inc/sample_app_perfids.h +++ b/config/default_sample_app_perfids.h @@ -18,13 +18,11 @@ /** * @file - * - * Define Sample App Performance IDs + * Define TO Lab Performance IDs */ - #ifndef SAMPLE_APP_PERFIDS_H #define SAMPLE_APP_PERFIDS_H #define SAMPLE_APP_PERF_ID 91 -#endif /* SAMPLE_APP_PERFIDS_H */ +#endif diff --git a/config/default_sample_app_platform_cfg.h b/config/default_sample_app_platform_cfg.h new file mode 100644 index 0000000..d62a136 --- /dev/null +++ b/config/default_sample_app_platform_cfg.h @@ -0,0 +1,41 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/** + * @file + * + * SAMPLE_APP Application Platform Configuration Header File + * + * This is a compatibility header for the "platform_cfg.h" file that has + * traditionally provided both public and private config definitions + * for each CFS app. + * + * These definitions are now provided in two separate files, one for + * the public/mission scope and one for internal scope. + * + * @note This file may be overridden/superceded by mission-provided defintions + * either by overriding this header or by generating definitions from a command/data + * dictionary tool. + */ +#ifndef SAMPLE_APP_PLATFORM_CFG_H +#define SAMPLE_APP_PLATFORM_CFG_H + +#include "sample_app_mission_cfg.h" +#include "sample_app_internal_cfg.h" + +#endif diff --git a/fsw/platform_inc/sample_app_table.h b/config/default_sample_app_tbl.h similarity index 70% rename from fsw/platform_inc/sample_app_table.h rename to config/default_sample_app_tbl.h index ca688f0..f62b974 100644 --- a/fsw/platform_inc/sample_app_table.h +++ b/config/default_sample_app_tbl.h @@ -18,20 +18,19 @@ /** * @file + * Specification for the SAMPLE_APP table structures * - * Define sample app table + * @note + * Constants and enumerated types related to these table structures + * are defined in sample_app_tbldefs.h. */ +#ifndef SAMPLE_APP_TBL_H +#define SAMPLE_APP_TBL_H -#ifndef SAMPLE_APP_TABLE_H -#define SAMPLE_APP_TABLE_H +#include "sample_app_tbldefs.h" +#include "sample_app_tblstruct.h" -/* -** Table structure -*/ -typedef struct -{ - uint16 Int1; - uint16 Int2; -} SAMPLE_APP_Table_t; +/* Define filenames of default data images for tables */ +#define SAMPLE_APP_TABLE_FILE "/cf/sample_app_tbl.tbl" -#endif /* SAMPLE_APP_TABLE_H */ +#endif diff --git a/config/default_sample_app_tbldefs.h b/config/default_sample_app_tbldefs.h new file mode 100644 index 0000000..7338708 --- /dev/null +++ b/config/default_sample_app_tbldefs.h @@ -0,0 +1,45 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/** + * @file + * Specification for the SAMPLE_APP table related + * constant definitions. + * + * @note + * These Macro definitions have been put in this file (instead of + * sample_app_tbl.h). DO NOT PUT ANY TYPEDEFS OR + * STRUCTURE DEFINITIONS IN THIS FILE! + * ADD THEM TO sample_app_tbl.h IF NEEDED! + */ +#ifndef SAMPLE_APP_TBLDEFS_H +#define SAMPLE_APP_TBLDEFS_H + +#include "common_types.h" +#include "sample_app_mission_cfg.h" + +/* +** Example Table structure +*/ +typedef struct +{ + uint16 Int1; + uint16 Int2; +} SAMPLE_APP_Table_t; + +#endif diff --git a/config/default_sample_app_tblstruct.h b/config/default_sample_app_tblstruct.h new file mode 100644 index 0000000..3cd7882 --- /dev/null +++ b/config/default_sample_app_tblstruct.h @@ -0,0 +1,45 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/** + * @file + * Specification for the SAMPLE_APP table structures + * + * Provides default definitions for SAMPLE_APP table structures + * + * @note This file may be overridden/superceded by mission-provided defintions + * either by overriding this header or by generating definitions from a command/data + * dictionary tool. + */ +#ifndef SAMPLE_APP_TBLSTRUCT_H +#define SAMPLE_APP_TBLSTRUCT_H + +/************************************************************************* + * Includes + *************************************************************************/ +#include "sample_app_tbldefs.h" + +/************************************************************************ + * Macro Definitions + ************************************************************************/ + +/************************************************************************* + * Type Definitions + *************************************************************************/ + +#endif diff --git a/fsw/src/sample_app_events.h b/fsw/inc/sample_app_eventids.h similarity index 97% rename from fsw/src/sample_app_events.h rename to fsw/inc/sample_app_eventids.h index 46e7aaf..b92b9e8 100644 --- a/fsw/src/sample_app_events.h +++ b/fsw/inc/sample_app_eventids.h @@ -19,7 +19,7 @@ /** * @file * - * Define SAMPLE App Events IDs + * Define Sample App Events IDs */ #ifndef SAMPLE_APP_EVENTS_H diff --git a/fsw/src/sample_app.c b/fsw/src/sample_app.c index 2961237..75fa897 100644 --- a/fsw/src/sample_app.c +++ b/fsw/src/sample_app.c @@ -24,10 +24,10 @@ /* ** Include Files: */ -#include "sample_app_events.h" +#include "sample_app_eventids.h" #include "sample_app_version.h" #include "sample_app.h" -#include "sample_app_table.h" +#include "sample_app_tbl.h" /* The sample_lib module provides the SAMPLE_LIB_Function() prototype */ #include @@ -239,7 +239,7 @@ void SAMPLE_APP_ProcessGroundCommand(CFE_SB_Buffer_t *SBBufPtr) CFE_MSG_GetFcnCode(&SBBufPtr->Msg, &CommandCode); /* - ** Process "known" SAMPLE app ground commands + ** Process "known" Sample App ground commands */ switch (CommandCode) { diff --git a/fsw/src/sample_app.h b/fsw/src/sample_app.h index 5e9006d..922ddd4 100644 --- a/fsw/src/sample_app.h +++ b/fsw/src/sample_app.h @@ -34,21 +34,13 @@ #include "cfe_sb.h" #include "cfe_es.h" +#include "sample_app_mission_cfg.h" +#include "sample_app_platform_cfg.h" + #include "sample_app_perfids.h" #include "sample_app_msgids.h" #include "sample_app_msg.h" -/***********************************************************************/ -#define SAMPLE_APP_PIPE_DEPTH 32 /* Depth of the Command Pipe for Application */ - -#define SAMPLE_APP_NUMBER_OF_TABLES 1 /* Number of Table(s) */ - -/* Define filenames of default data images for tables */ -#define SAMPLE_APP_TABLE_FILE "/cf/sample_app_tbl.tbl" - -#define SAMPLE_APP_TABLE_OUT_OF_RANGE_ERR_CODE -1 - -#define SAMPLE_APP_TBL_ELEMENT_1_MAX 10 /************************************************************************ ** Type Definitions *************************************************************************/ diff --git a/fsw/tables/sample_app_tbl.c b/fsw/tables/sample_app_tbl.c index 435409d..c380534 100644 --- a/fsw/tables/sample_app_tbl.c +++ b/fsw/tables/sample_app_tbl.c @@ -17,7 +17,7 @@ ************************************************************************/ #include "cfe_tbl_filedef.h" /* Required to obtain the CFE_TBL_FILEDEF macro definition */ -#include "sample_app_table.h" +#include "sample_app_tbl.h" /* ** The following is an example of the declaration statement that defines the desired diff --git a/mission_build.cmake b/mission_build.cmake new file mode 100644 index 0000000..9b7d460 --- /dev/null +++ b/mission_build.cmake @@ -0,0 +1,49 @@ +########################################################### +# +# SAMPLE_APP mission build setup +# +# This file is evaluated as part of the "prepare" stage +# and can be used to set up prerequisites for the build, +# such as generating header files +# +########################################################### + +# The list of header files that control the SAMPLE_APP configuration +set(SAMPLE_APP_MISSION_CONFIG_FILE_LIST + sample_app_fcncodes.h + sample_app_mission_cfg.h + sample_app_perfids.h + sample_app_msg.h + sample_app_msgdefs.h + sample_app_msgstruct.h + sample_app_tbl.h + sample_app_tbldefs.h + sample_app_tblstruct.h +) + +if (CFE_EDS_ENABLED_BUILD) + + # In an EDS-based build, these files come generated from the EDS tool + set(SAMPLE_APP_CFGFILE_SRC_sample_app_tbldefs "sample_app_eds_typedefs.h") + set(SAMPLE_APP_CFGFILE_SRC_sample_app_tblstruct "sample_app_eds_typedefs.h") + set(SAMPLE_APP_CFGFILE_SRC_sample_app_msgdefs "sample_app_eds_typedefs.h") + set(SAMPLE_APP_CFGFILE_SRC_sample_app_msgstruct "sample_app_eds_typedefs.h") + set(SAMPLE_APP_CFGFILE_SRC_sample_app_fcncodes "sample_app_eds_cc.h") + +endif(CFE_EDS_ENABLED_BUILD) + +# Create wrappers around the all the config header files +# This makes them individually overridable by the missions, without modifying +# the distribution default copies +foreach(SAMPLE_APP_CFGFILE ${SAMPLE_APP_MISSION_CONFIG_FILE_LIST}) + get_filename_component(CFGKEY "${SAMPLE_APP_CFGFILE}" NAME_WE) + if (DEFINED SAMPLE_APP_CFGFILE_SRC_${CFGKEY}) + set(DEFAULT_SOURCE GENERATED_FILE "${SAMPLE_APP_CFGFILE_SRC_${CFGKEY}}") + else() + set(DEFAULT_SOURCE FALLBACK_FILE "${CMAKE_CURRENT_LIST_DIR}/config/default_${SAMPLE_APP_CFGFILE}") + endif() + generate_config_includefile( + FILE_NAME "${SAMPLE_APP_CFGFILE}" + ${DEFAULT_SOURCE} + ) +endforeach() diff --git a/unit-test/coveragetest/sample_app_coveragetest_common.h b/unit-test/coveragetest/sample_app_coveragetest_common.h index 134e2ca..3f48bf6 100644 --- a/unit-test/coveragetest/sample_app_coveragetest_common.h +++ b/unit-test/coveragetest/sample_app_coveragetest_common.h @@ -34,9 +34,9 @@ #include "utstubs.h" #include "cfe.h" -#include "sample_app_events.h" +#include "sample_app_eventids.h" #include "sample_app.h" -#include "sample_app_table.h" +#include "sample_app_tbl.h" /* * Macro to add a test case to the list of tests to execute diff --git a/unit-test/inc/ut_sample_app.h b/unit-test/inc/ut_sample_app.h index ca8567e..858ef29 100644 --- a/unit-test/inc/ut_sample_app.h +++ b/unit-test/inc/ut_sample_app.h @@ -39,7 +39,7 @@ * Necessary to include these here to get the definition of the * "SAMPLE_APP_Data_t" typedef. */ -#include "sample_app_events.h" +#include "sample_app_eventids.h" #include "sample_app.h" /* From b7c1b4a559ae4d2c6cef07f3af2fd24a98ce6dcc Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Mon, 30 Oct 2023 10:36:45 -0400 Subject: [PATCH 8/9] HotFix #209, correct merge issues related to event names --- fsw/src/sample_app.c | 2 +- fsw/src/sample_app_cmds.c | 4 ++-- fsw/src/sample_app_utils.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/fsw/src/sample_app.c b/fsw/src/sample_app.c index 9b93285..d2abb76 100644 --- a/fsw/src/sample_app.c +++ b/fsw/src/sample_app.c @@ -191,7 +191,7 @@ int32 SAMPLE_APP_Init(void) status = CFE_TBL_Load(SAMPLE_APP_Data.TblHandles[0], CFE_TBL_SRC_FILE, SAMPLE_APP_TABLE_FILE); } - CFE_EVS_SendEvent(SAMPLE_APP_STARTUP_INF_EID, CFE_EVS_EventType_INFORMATION, "Sample App Initialized.%s", + CFE_EVS_SendEvent(SAMPLE_APP_INIT_INF_EID, CFE_EVS_EventType_INFORMATION, "Sample App Initialized.%s", SAMPLE_APP_VERSION_STRING); } diff --git a/fsw/src/sample_app_cmds.c b/fsw/src/sample_app_cmds.c index 5df7e96..fc635d5 100644 --- a/fsw/src/sample_app_cmds.c +++ b/fsw/src/sample_app_cmds.c @@ -44,7 +44,7 @@ int32 SAMPLE_APP_Noop(const SAMPLE_APP_NoopCmd_t *Msg) { SAMPLE_APP_Data.CmdCounter++; - CFE_EVS_SendEvent(SAMPLE_APP_COMMANDNOP_INF_EID, CFE_EVS_EventType_INFORMATION, "SAMPLE: NOOP command %s", + CFE_EVS_SendEvent(SAMPLE_APP_NOOP_INF_EID, CFE_EVS_EventType_INFORMATION, "SAMPLE: NOOP command %s", SAMPLE_APP_VERSION); return CFE_SUCCESS; @@ -62,7 +62,7 @@ int32 SAMPLE_APP_ResetCounters(const SAMPLE_APP_ResetCountersCmd_t *Msg) SAMPLE_APP_Data.CmdCounter = 0; SAMPLE_APP_Data.ErrCounter = 0; - CFE_EVS_SendEvent(SAMPLE_APP_COMMANDRST_INF_EID, CFE_EVS_EventType_INFORMATION, "SAMPLE: RESET command"); + CFE_EVS_SendEvent(SAMPLE_APP_RESET_INF_EID, CFE_EVS_EventType_INFORMATION, "SAMPLE: RESET command"); return CFE_SUCCESS; } diff --git a/fsw/src/sample_app_utils.c b/fsw/src/sample_app_utils.c index 9c97201..a316dcf 100644 --- a/fsw/src/sample_app_utils.c +++ b/fsw/src/sample_app_utils.c @@ -51,7 +51,7 @@ bool SAMPLE_APP_VerifyCmdLength(CFE_MSG_Message_t *MsgPtr, size_t ExpectedLength CFE_MSG_GetMsgId(MsgPtr, &MsgId); CFE_MSG_GetFcnCode(MsgPtr, &FcnCode); - CFE_EVS_SendEvent(SAMPLE_APP_LEN_ERR_EID, CFE_EVS_EventType_ERROR, + CFE_EVS_SendEvent(SAMPLE_APP_CMD_LEN_ERR_EID, CFE_EVS_EventType_ERROR, "Invalid Msg length: ID = 0x%X, CC = %u, Len = %u, Expected = %u", (unsigned int)CFE_SB_MsgIdToValue(MsgId), (unsigned int)FcnCode, (unsigned int)ActualLength, (unsigned int)ExpectedLength); From b309b83c766280c785a66c2b3e779fab7f95ff09 Mon Sep 17 00:00:00 2001 From: Dylan Date: Mon, 30 Oct 2023 12:48:06 -0400 Subject: [PATCH 9/9] v1.3.0-rc4+dev56 --- CHANGELOG.md | 10 ++++++++++ fsw/src/sample_app_version.h | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 116c3fc..d59533b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Changelog +## Development Build: v1.3.0-rc4+dev56 +- Apply consistent Event ID names to common events +- Remove component-specific cFE header #includes +- Refactor SAMPLE_APP_Init/Process to remove multiple returns +- Add test for missing branch in SAMPLE_APP_Process() +- Zero out global data structure during initialization +- Move cmds and utils into separate files +- organize source files according to current patterns +- See , , , , , , and + ## Development Build: v1.3.0-rc4+dev39 - update cmake recipe - See diff --git a/fsw/src/sample_app_version.h b/fsw/src/sample_app_version.h index a2ea178..b29b42d 100644 --- a/fsw/src/sample_app_version.h +++ b/fsw/src/sample_app_version.h @@ -27,7 +27,7 @@ /* Development Build Macro Definitions */ -#define SAMPLE_APP_BUILD_NUMBER 39 /*!< Development Build: Number of commits since baseline */ +#define SAMPLE_APP_BUILD_NUMBER 56 /*!< Development Build: Number of commits since baseline */ #define SAMPLE_APP_BUILD_BASELINE \ "v1.3.0-rc4" /*!< Development Build: git tag that is the base for the current development */