Skip to content

Commit

Permalink
Fix nasa#210, symbol name updates and UT breakup
Browse files Browse the repository at this point in the history
Update internal symbol naming to better follow conventions.  Notably,
this renames the "SampleAppTable" to be "ExampleTable", among other
things.

This also adds a separate dispatch source file, splits the unit test
into source file units as well.
  • Loading branch information
jphickey committed Nov 1, 2023
1 parent d043686 commit d18673e
Show file tree
Hide file tree
Showing 27 changed files with 1,411 additions and 696 deletions.
11 changes: 8 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
project(CFE_SAMPLE_APP C)

set(APP_SRC_FILES
fsw/src/sample_app.c
fsw/src/sample_app_cmds.c
fsw/src/sample_app_dispatch.c
fsw/src/sample_app_utils.c
)

# Create the app module
add_cfe_app(sample_app fsw/src/sample_app.c
fsw/src/sample_app_cmds.c
fsw/src/sample_app_utils.c)
add_cfe_app(sample_app ${APP_SRC_FILES})

target_include_directories(sample_app PUBLIC fsw/inc)
# Include the public API from sample_lib to demonstrate how
Expand Down
2 changes: 1 addition & 1 deletion config/default_sample_app_internal_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
/***********************************************************************/
#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_NUMBER_OF_TABLES 1 /* Number of Example Table(s) */

#define SAMPLE_APP_TABLE_OUT_OF_RANGE_ERR_CODE -1

Expand Down
2 changes: 1 addition & 1 deletion config/default_sample_app_tbldefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ typedef struct
{
uint16 Int1;
uint16 Int2;
} SAMPLE_APP_Table_t;
} SAMPLE_APP_ExampleTable_t;

#endif
124 changes: 6 additions & 118 deletions fsw/src/sample_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@
/*
** Include Files:
*/
#include <string.h>

#include "sample_app.h"
#include "sample_app_cmds.h"
#include "sample_app_utils.h"
#include "sample_app_eventids.h"
#include "sample_app_version.h"
#include "sample_app_dispatch.h"
#include "sample_app_tbl.h"
#include "sample_app_version.h"

/*
** global data
Expand Down Expand Up @@ -84,7 +83,7 @@ void SAMPLE_APP_Main(void)

if (status == CFE_SUCCESS)
{
SAMPLE_APP_ProcessCommandPacket(SBBufPtr);
SAMPLE_APP_TaskPipe(SBBufPtr);
}
else
{
Expand Down Expand Up @@ -178,13 +177,13 @@ int32 SAMPLE_APP_Init(void)
if (status == CFE_SUCCESS)
{
/*
** Register Table(s)
** Register Example Table(s)
*/
status = CFE_TBL_Register(&SAMPLE_APP_Data.TblHandles[0], "SampleAppTable", sizeof(SAMPLE_APP_Table_t),
status = CFE_TBL_Register(&SAMPLE_APP_Data.TblHandles[0], "ExampleTable", sizeof(SAMPLE_APP_ExampleTable_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);
CFE_ES_WriteToSysLog("Sample App: Error Registering Example Table, RC = 0x%08lX\n", (unsigned long)status);
}
else
{
Expand All @@ -197,114 +196,3 @@ int32 SAMPLE_APP_Init(void)

return status;
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
/* */
/* Purpose: */
/* This routine will process any packet that is received on the Sample */
/* App command pipe. */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void SAMPLE_APP_ProcessCommandPacket(CFE_SB_Buffer_t *SBBufPtr)
{
CFE_SB_MsgId_t MsgId = CFE_SB_INVALID_MSG_ID;

CFE_MSG_GetMsgId(&SBBufPtr->Msg, &MsgId);

switch (CFE_SB_MsgIdToValue(MsgId))
{
case SAMPLE_APP_CMD_MID:
SAMPLE_APP_ProcessGroundCommand(SBBufPtr);
break;

case SAMPLE_APP_SEND_HK_MID:
SAMPLE_APP_ReportHousekeeping((CFE_MSG_CommandHeader_t *)SBBufPtr);
break;

default:
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;
}
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
/* */
/* Process Ground Commands */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
void SAMPLE_APP_ProcessGroundCommand(CFE_SB_Buffer_t *SBBufPtr)
{
CFE_MSG_FcnCode_t CommandCode = 0;

CFE_MSG_GetFcnCode(&SBBufPtr->Msg, &CommandCode);

/*
** Process "known" Sample App ground commands
*/
switch (CommandCode)
{
case SAMPLE_APP_NOOP_CC:
if (SAMPLE_APP_VerifyCmdLength(&SBBufPtr->Msg, sizeof(SAMPLE_APP_NoopCmd_t)))
{
SAMPLE_APP_Noop((SAMPLE_APP_NoopCmd_t *)SBBufPtr);
}
break;

case SAMPLE_APP_RESET_COUNTERS_CC:
if (SAMPLE_APP_VerifyCmdLength(&SBBufPtr->Msg, sizeof(SAMPLE_APP_ResetCountersCmd_t)))
{
SAMPLE_APP_ResetCounters((SAMPLE_APP_ResetCountersCmd_t *)SBBufPtr);
}
break;

case SAMPLE_APP_PROCESS_CC:
if (SAMPLE_APP_VerifyCmdLength(&SBBufPtr->Msg, sizeof(SAMPLE_APP_ProcessCmd_t)))
{
SAMPLE_APP_Process((SAMPLE_APP_ProcessCmd_t *)SBBufPtr);
}
break;

/* default case already found during FC vs length test */
default:
CFE_EVS_SendEvent(SAMPLE_APP_CC_ERR_EID, CFE_EVS_EventType_ERROR, "Invalid ground command code: CC = %d",
CommandCode);
break;
}
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
/* */
/* Purpose: */
/* This function is triggered in response to a task telemetry request */
/* 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. */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int32 SAMPLE_APP_ReportHousekeeping(const CFE_MSG_CommandHeader_t *Msg)
{
int i;

/*
** Get command execution counters...
*/
SAMPLE_APP_Data.HkTlm.Payload.CommandErrorCounter = SAMPLE_APP_Data.ErrCounter;
SAMPLE_APP_Data.HkTlm.Payload.CommandCounter = SAMPLE_APP_Data.CmdCounter;

/*
** Send housekeeping telemetry packet...
*/
CFE_SB_TimeStampMsg(CFE_MSG_PTR(SAMPLE_APP_Data.HkTlm.TelemetryHeader));
CFE_SB_TransmitMsg(CFE_MSG_PTR(SAMPLE_APP_Data.HkTlm.TelemetryHeader), true);

/*
** Manage any pending table loads, validations, etc.
*/
for (i = 0; i < SAMPLE_APP_NUMBER_OF_TABLES; i++)
{
CFE_TBL_Manage(SAMPLE_APP_Data.TblHandles[i]);
}

return CFE_SUCCESS;
}
3 changes: 0 additions & 3 deletions fsw/src/sample_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,5 @@ extern SAMPLE_APP_Data_t SAMPLE_APP_Data;
*/
void SAMPLE_APP_Main(void);
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);

#endif /* SAMPLE_APP_H */
56 changes: 47 additions & 9 deletions fsw/src/sample_app_cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
*/
#include "sample_app.h"
#include "sample_app_cmds.h"
#include "sample_app_msgids.h"
#include "sample_app_eventids.h"
#include "sample_app_version.h"
#include "sample_app_tbl.h"
Expand All @@ -35,12 +36,47 @@
/* The sample_lib module provides the SAMPLE_Function() prototype */
#include "sample_lib.h"

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
/* */
/* Purpose: */
/* This function is triggered in response to a task telemetry request */
/* from the housekeeping task. This function will gather the Apps */
/* telemetry, packetize it and send it to the housekeeping task via */
/* the software bus */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
CFE_Status_t SAMPLE_APP_SendHkCmd(const SAMPLE_APP_SendHkCmd_t *Msg)
{
int i;

/*
** Get command execution counters...
*/
SAMPLE_APP_Data.HkTlm.Payload.CommandErrorCounter = SAMPLE_APP_Data.ErrCounter;
SAMPLE_APP_Data.HkTlm.Payload.CommandCounter = SAMPLE_APP_Data.CmdCounter;

/*
** Send housekeeping telemetry packet...
*/
CFE_SB_TimeStampMsg(CFE_MSG_PTR(SAMPLE_APP_Data.HkTlm.TelemetryHeader));
CFE_SB_TransmitMsg(CFE_MSG_PTR(SAMPLE_APP_Data.HkTlm.TelemetryHeader), true);

/*
** Manage any pending table loads, validations, etc.
*/
for (i = 0; i < SAMPLE_APP_NUMBER_OF_TABLES; i++)
{
CFE_TBL_Manage(SAMPLE_APP_Data.TblHandles[i]);
}

return CFE_SUCCESS;
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
/* */
/* SAMPLE NOOP commands */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
int32 SAMPLE_APP_Noop(const SAMPLE_APP_NoopCmd_t *Msg)
CFE_Status_t SAMPLE_APP_NoopCmd(const SAMPLE_APP_NoopCmd_t *Msg)
{
SAMPLE_APP_Data.CmdCounter++;

Expand All @@ -57,7 +93,7 @@ int32 SAMPLE_APP_Noop(const SAMPLE_APP_NoopCmd_t *Msg)
/* part of the task telemetry. */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int32 SAMPLE_APP_ResetCounters(const SAMPLE_APP_ResetCountersCmd_t *Msg)
CFE_Status_t SAMPLE_APP_ResetCountersCmd(const SAMPLE_APP_ResetCountersCmd_t *Msg)
{
SAMPLE_APP_Data.CmdCounter = 0;
SAMPLE_APP_Data.ErrCounter = 0;
Expand All @@ -73,23 +109,25 @@ int32 SAMPLE_APP_ResetCounters(const SAMPLE_APP_ResetCountersCmd_t *Msg)
/* This function Process Ground Station Command */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int32 SAMPLE_APP_Process(const SAMPLE_APP_ProcessCmd_t *Msg)
CFE_Status_t SAMPLE_APP_ProcessCmd(const SAMPLE_APP_ProcessCmd_t *Msg)
{
int32 status;
SAMPLE_APP_Table_t *TblPtr;
const char * TableName = "SAMPLE_APP.SampleAppTable";
int32 status;
void * TblAddr;
SAMPLE_APP_ExampleTable_t *TblPtr;
const char * TableName = "SAMPLE_APP.ExampleTable";

/* Sample Use of Table */
/* Sample Use of Example Table */

status = CFE_TBL_GetAddress((void *)&TblPtr, SAMPLE_APP_Data.TblHandles[0]);
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: Table Value 1: %d Value 2: %d", TblPtr->Int1, TblPtr->Int2);
TblPtr = TblAddr;
CFE_ES_WriteToSysLog("Sample App: Example Table Value 1: %d Value 2: %d", TblPtr->Int1, TblPtr->Int2);

SAMPLE_APP_GetCrc(TableName);

Expand Down
12 changes: 7 additions & 5 deletions fsw/src/sample_app_cmds.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@
/*
** Required header files.
*/
#include "sample_app.h"
#include "cfe_error.h"
#include "sample_app_msg.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);
CFE_Status_t SAMPLE_APP_SendHkCmd(const SAMPLE_APP_SendHkCmd_t *Msg);
CFE_Status_t SAMPLE_APP_ResetCountersCmd(const SAMPLE_APP_ResetCountersCmd_t *Msg);
CFE_Status_t SAMPLE_APP_ProcessCmd(const SAMPLE_APP_ProcessCmd_t *Msg);
CFE_Status_t SAMPLE_APP_NoopCmd(const SAMPLE_APP_NoopCmd_t *Msg);

#endif /* SAMPLE_APP_CMDS_H */
#endif /* SAMPLE_APP_CMDS_H */
Loading

0 comments on commit d18673e

Please sign in to comment.