From 4a4b6e5c18fb6af03563fe0b3b9483eb272c2dd5 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Tue, 11 Feb 2020 12:13:20 -0500 Subject: [PATCH 1/2] Fix #40: Apply consistent naming conventions Update SAMPLE to better correlate with the naming conventions used elsewhere and documented in the CFE naming conventions - Put all global runtime data into a single "SAMPLE_AppData" object - Name all global-scope identifiers consistently with a "SAMPLE_" prefix - Do not use SAMPLE prefix for members already inside global - Command handlers named to match the command they process - Command handlers return an int32 status value - Telemetry payload defined in a separate structure - Member names in telemetry struct following convention in the CFE naming convention document. --- fsw/src/sample_app.c | 130 +++++++++++++++++++-------------------- fsw/src/sample_app.h | 22 +++---- fsw/src/sample_app_msg.h | 14 +++-- fsw/src/sample_table.c | 2 +- fsw/src/sample_table.h | 2 +- 5 files changed, 88 insertions(+), 82 deletions(-) diff --git a/fsw/src/sample_app.c b/fsw/src/sample_app.c index 42cdfe9..b8dd1ae 100644 --- a/fsw/src/sample_app.c +++ b/fsw/src/sample_app.c @@ -41,7 +41,7 @@ /* ** global data */ -Sample_AppData_t Sample_AppData; +SAMPLE_AppData_t SAMPLE_AppData; /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ /* SAMPLE_AppMain() -- Application entry point and main process loop */ @@ -69,13 +69,13 @@ void SAMPLE_AppMain( void ) status = SAMPLE_AppInit(); if (status != CFE_SUCCESS) { - Sample_AppData.RunStatus = CFE_ES_RunStatus_APP_ERROR; + SAMPLE_AppData.RunStatus = CFE_ES_RunStatus_APP_ERROR; } /* ** SAMPLE Runloop */ - while (CFE_ES_RunLoop(&Sample_AppData.RunStatus) == true) + while (CFE_ES_RunLoop(&SAMPLE_AppData.RunStatus) == true) { /* ** Performance Log Exit Stamp @@ -83,8 +83,8 @@ void SAMPLE_AppMain( void ) CFE_ES_PerfLogExit(SAMPLE_APP_PERF_ID); /* Pend on receipt of command packet */ - status = CFE_SB_RcvMsg(&Sample_AppData.SAMPLEMsgPtr, - Sample_AppData.SAMPLE_CommandPipe, + status = CFE_SB_RcvMsg(&SAMPLE_AppData.MsgPtr, + SAMPLE_AppData.CommandPipe, CFE_SB_PEND_FOREVER); /* @@ -94,7 +94,7 @@ void SAMPLE_AppMain( void ) if (status == CFE_SUCCESS) { - SAMPLE_ProcessCommandPacket(Sample_AppData.SAMPLEMsgPtr); + SAMPLE_ProcessCommandPacket(SAMPLE_AppData.MsgPtr); } else { @@ -102,7 +102,7 @@ void SAMPLE_AppMain( void ) CFE_EVS_EventType_ERROR, "SAMPLE APP: SB Pipe Read Error, App Will Exit"); - Sample_AppData.RunStatus = CFE_ES_RunStatus_APP_ERROR; + SAMPLE_AppData.RunStatus = CFE_ES_RunStatus_APP_ERROR; } } @@ -112,7 +112,7 @@ void SAMPLE_AppMain( void ) */ CFE_ES_PerfLogExit(SAMPLE_APP_PERF_ID); - CFE_ES_ExitApp(Sample_AppData.RunStatus); + CFE_ES_ExitApp(SAMPLE_AppData.RunStatus); } /* End of SAMPLE_AppMain() */ @@ -125,43 +125,43 @@ int32 SAMPLE_AppInit( void ) { int32 status; - Sample_AppData.RunStatus = CFE_ES_RunStatus_APP_RUN; + SAMPLE_AppData.RunStatus = CFE_ES_RunStatus_APP_RUN; /* ** Initialize app command execution counters */ - Sample_AppData.CmdCounter = 0; - Sample_AppData.ErrCounter = 0; + SAMPLE_AppData.CmdCounter = 0; + SAMPLE_AppData.ErrCounter = 0; /* ** Initialize app configuration data */ - Sample_AppData.PipeDepth = SAMPLE_PIPE_DEPTH; + SAMPLE_AppData.PipeDepth = SAMPLE_PIPE_DEPTH; - strcpy(Sample_AppData.PipeName, "SAMPLE_CMD_PIPE"); + strcpy(SAMPLE_AppData.PipeName, "SAMPLE_CMD_PIPE"); /* ** Initialize event filter table... */ - Sample_AppData.SAMPLE_EventFilters[0].EventID = SAMPLE_STARTUP_INF_EID; - Sample_AppData.SAMPLE_EventFilters[0].Mask = 0x0000; - Sample_AppData.SAMPLE_EventFilters[1].EventID = SAMPLE_COMMAND_ERR_EID; - Sample_AppData.SAMPLE_EventFilters[1].Mask = 0x0000; - Sample_AppData.SAMPLE_EventFilters[2].EventID = SAMPLE_COMMANDNOP_INF_EID; - Sample_AppData.SAMPLE_EventFilters[2].Mask = 0x0000; - Sample_AppData.SAMPLE_EventFilters[3].EventID = SAMPLE_COMMANDRST_INF_EID; - Sample_AppData.SAMPLE_EventFilters[3].Mask = 0x0000; - Sample_AppData.SAMPLE_EventFilters[4].EventID = SAMPLE_INVALID_MSGID_ERR_EID; - Sample_AppData.SAMPLE_EventFilters[4].Mask = 0x0000; - Sample_AppData.SAMPLE_EventFilters[5].EventID = SAMPLE_LEN_ERR_EID; - Sample_AppData.SAMPLE_EventFilters[5].Mask = 0x0000; - Sample_AppData.SAMPLE_EventFilters[6].EventID = SAMPLE_PIPE_ERR_EID; - Sample_AppData.SAMPLE_EventFilters[6].Mask = 0x0000; + SAMPLE_AppData.EventFilters[0].EventID = SAMPLE_STARTUP_INF_EID; + SAMPLE_AppData.EventFilters[0].Mask = 0x0000; + SAMPLE_AppData.EventFilters[1].EventID = SAMPLE_COMMAND_ERR_EID; + SAMPLE_AppData.EventFilters[1].Mask = 0x0000; + SAMPLE_AppData.EventFilters[2].EventID = SAMPLE_COMMANDNOP_INF_EID; + SAMPLE_AppData.EventFilters[2].Mask = 0x0000; + SAMPLE_AppData.EventFilters[3].EventID = SAMPLE_COMMANDRST_INF_EID; + SAMPLE_AppData.EventFilters[3].Mask = 0x0000; + SAMPLE_AppData.EventFilters[4].EventID = SAMPLE_INVALID_MSGID_ERR_EID; + SAMPLE_AppData.EventFilters[4].Mask = 0x0000; + SAMPLE_AppData.EventFilters[5].EventID = SAMPLE_LEN_ERR_EID; + SAMPLE_AppData.EventFilters[5].Mask = 0x0000; + SAMPLE_AppData.EventFilters[6].EventID = SAMPLE_PIPE_ERR_EID; + SAMPLE_AppData.EventFilters[6].Mask = 0x0000; /* ** Register the events */ - status = CFE_EVS_Register(Sample_AppData.SAMPLE_EventFilters, + status = CFE_EVS_Register(SAMPLE_AppData.EventFilters, SAMPLE_EVENT_COUNTS, CFE_EVS_EventFilter_BINARY); if (status != CFE_SUCCESS) @@ -174,17 +174,17 @@ int32 SAMPLE_AppInit( void ) /* ** Initialize housekeeping packet (clear user data area). */ - CFE_SB_InitMsg(&Sample_AppData.SAMPLE_HkTelemetryPkt, + CFE_SB_InitMsg(&SAMPLE_AppData.HkBuf, SAMPLE_APP_HK_TLM_MID, - sizeof(sample_hk_tlm_t), + sizeof(SAMPLE_AppData.HkBuf), true); /* ** Create Software Bus message pipe. */ - status = CFE_SB_CreatePipe(&Sample_AppData.SAMPLE_CommandPipe, - Sample_AppData.PipeDepth, - Sample_AppData.PipeName); + status = CFE_SB_CreatePipe(&SAMPLE_AppData.CommandPipe, + SAMPLE_AppData.PipeDepth, + SAMPLE_AppData.PipeName); if (status != CFE_SUCCESS) { CFE_ES_WriteToSysLog("Sample App: Error creating pipe, RC = 0x%08lX\n", @@ -196,7 +196,7 @@ int32 SAMPLE_AppInit( void ) ** Subscribe to Housekeeping request commands */ status = CFE_SB_Subscribe(SAMPLE_APP_SEND_HK_MID, - Sample_AppData.SAMPLE_CommandPipe); + SAMPLE_AppData.CommandPipe); if (status != CFE_SUCCESS) { CFE_ES_WriteToSysLog("Sample App: Error Subscribing to HK request, RC = 0x%08lX\n", @@ -208,7 +208,7 @@ int32 SAMPLE_AppInit( void ) ** Subscribe to ground command packets */ status = CFE_SB_Subscribe(SAMPLE_APP_CMD_MID, - Sample_AppData.SAMPLE_CommandPipe); + SAMPLE_AppData.CommandPipe); if (status != CFE_SUCCESS ) { CFE_ES_WriteToSysLog("Sample App: Error Subscribing to Command, RC = 0x%08lX\n", @@ -220,9 +220,9 @@ int32 SAMPLE_AppInit( void ) /* ** Register Table(s) */ - status = CFE_TBL_Register(&Sample_AppData.TblHandles[0], + status = CFE_TBL_Register(&SAMPLE_AppData.TblHandles[0], "SampleTable", - sizeof(SampleTable_t), + sizeof(SAMPLE_Table_t), CFE_TBL_OPT_DEFAULT, SAMPLE_TblValidationFunc); if ( status != CFE_SUCCESS ) @@ -234,7 +234,7 @@ int32 SAMPLE_AppInit( void ) } else { - status = CFE_TBL_Load(Sample_AppData.TblHandles[0], + status = CFE_TBL_Load(SAMPLE_AppData.TblHandles[0], CFE_TBL_SRC_FILE, SAMPLE_TABLE_FILE); } @@ -306,7 +306,7 @@ void SAMPLE_ProcessGroundCommand( CFE_SB_MsgPtr_t Msg ) case SAMPLE_APP_NOOP_CC: if (SAMPLE_VerifyCmdLength(Msg, sizeof(SAMPLE_Noop_t))) { - SAMPLE_NoopCmd((SAMPLE_Noop_t *)Msg); + SAMPLE_Noop((SAMPLE_Noop_t *)Msg); } break; @@ -322,7 +322,7 @@ void SAMPLE_ProcessGroundCommand( CFE_SB_MsgPtr_t Msg ) case SAMPLE_APP_PROCESS_CC: if (SAMPLE_VerifyCmdLength(Msg, sizeof(SAMPLE_Process_t))) { - SAMPLE_ProcessCC((SAMPLE_Process_t *)Msg); + SAMPLE_Process((SAMPLE_Process_t *)Msg); } break; @@ -349,43 +349,43 @@ void SAMPLE_ProcessGroundCommand( CFE_SB_MsgPtr_t Msg ) /* telemetry, packetize it and send it to the housekeeping task via */ /* the software bus */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -void SAMPLE_ReportHousekeeping( const CCSDS_CommandPacket_t *Msg ) +int32 SAMPLE_ReportHousekeeping( const CCSDS_CommandPacket_t *Msg ) { int i; /* ** Get command execution counters... */ - Sample_AppData.SAMPLE_HkTelemetryPkt.sample_command_error_count = Sample_AppData.ErrCounter; - Sample_AppData.SAMPLE_HkTelemetryPkt.sample_command_count = Sample_AppData.CmdCounter; + SAMPLE_AppData.HkBuf.Payload.CommandErrorCounter = SAMPLE_AppData.ErrCounter; + SAMPLE_AppData.HkBuf.Payload.CommandCounter = SAMPLE_AppData.CmdCounter; /* ** Send housekeeping telemetry packet... */ - CFE_SB_TimeStampMsg((CFE_SB_Msg_t *) &Sample_AppData.SAMPLE_HkTelemetryPkt); - CFE_SB_SendMsg((CFE_SB_Msg_t *) &Sample_AppData.SAMPLE_HkTelemetryPkt); + CFE_SB_TimeStampMsg(&SAMPLE_AppData.HkBuf); + CFE_SB_SendMsg(&SAMPLE_AppData.HkBuf); /* ** Manage any pending table loads, validations, etc. */ - for (i=0; i Date: Tue, 11 Feb 2020 12:23:01 -0500 Subject: [PATCH 2/2] Fix #38: Add union for proper TLM buffer alignment Put the HkTlm buffer into a union to ensure it is aligned appropriately for conversion to a CFE_SB_Msg_t type. --- fsw/src/sample_app.c | 10 +++++----- fsw/src/sample_app.h | 13 ++++++++++++- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/fsw/src/sample_app.c b/fsw/src/sample_app.c index b8dd1ae..ce6bab1 100644 --- a/fsw/src/sample_app.c +++ b/fsw/src/sample_app.c @@ -174,7 +174,7 @@ int32 SAMPLE_AppInit( void ) /* ** Initialize housekeeping packet (clear user data area). */ - CFE_SB_InitMsg(&SAMPLE_AppData.HkBuf, + CFE_SB_InitMsg(&SAMPLE_AppData.HkBuf.MsgHdr, SAMPLE_APP_HK_TLM_MID, sizeof(SAMPLE_AppData.HkBuf), true); @@ -356,14 +356,14 @@ int32 SAMPLE_ReportHousekeeping( const CCSDS_CommandPacket_t *Msg ) /* ** Get command execution counters... */ - SAMPLE_AppData.HkBuf.Payload.CommandErrorCounter = SAMPLE_AppData.ErrCounter; - SAMPLE_AppData.HkBuf.Payload.CommandCounter = SAMPLE_AppData.CmdCounter; + SAMPLE_AppData.HkBuf.HkTlm.Payload.CommandErrorCounter = SAMPLE_AppData.ErrCounter; + SAMPLE_AppData.HkBuf.HkTlm.Payload.CommandCounter = SAMPLE_AppData.CmdCounter; /* ** Send housekeeping telemetry packet... */ - CFE_SB_TimeStampMsg(&SAMPLE_AppData.HkBuf); - CFE_SB_SendMsg(&SAMPLE_AppData.HkBuf); + CFE_SB_TimeStampMsg(&SAMPLE_AppData.HkBuf.MsgHdr); + CFE_SB_SendMsg(&SAMPLE_AppData.HkBuf.MsgHdr); /* ** Manage any pending table loads, validations, etc. diff --git a/fsw/src/sample_app.h b/fsw/src/sample_app.h index 18a0f56..a7c2c47 100644 --- a/fsw/src/sample_app.h +++ b/fsw/src/sample_app.h @@ -56,6 +56,17 @@ /************************************************************************ ** Type Definitions *************************************************************************/ + +/* + * Buffer to hold telemetry data prior to sending + * Defined as a union to ensure proper alignment for a CFE_SB_Msg_t type + */ +typedef union +{ + CFE_SB_Msg_t MsgHdr; + SAMPLE_HkTlm_t HkTlm; +} SAMPLE_HkBuffer_t; + /* ** Global Data */ @@ -70,7 +81,7 @@ typedef struct /* ** Housekeeping telemetry packet... */ - SAMPLE_HkTlm_t HkBuf; + SAMPLE_HkBuffer_t HkBuf; /* ** Run Status variable used in the main processing loop