Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sample_app Integration Candidate: 2020-12-08 #114

Merged
merged 3 commits into from
Dec 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ sample_app is an example for how to build and link an application in cFS. See al

## Version History


### Development Build: 1.2.0-rc1+dev29

- Aligns messages according to changes in cFE <https://github.com/nasa/cFE/issues/1009>. Uses the "raw" message cmd/tlm types in definition
- See <https://github.com/nasa/sample_app/pull/114>


### Development Build: 1.2.0-rc1+dev25

- Rename `UT_SetForceFail` to `UT_SetDefaultReturnValue` since some functions that retain more than 1 value are not necessarily failing
Expand Down
58 changes: 29 additions & 29 deletions fsw/src/sample_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ SAMPLE_APP_Data_t SAMPLE_APP_Data;
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
void SAMPLE_APP_Main(void)
{
int32 status;
int32 status;
CFE_SB_Buffer_t *SBBufPtr;

/*
** Register the app with Executive services
Expand Down Expand Up @@ -82,7 +83,7 @@ void SAMPLE_APP_Main(void)
CFE_ES_PerfLogExit(SAMPLE_APP_PERF_ID);

/* Pend on receipt of command packet */
status = CFE_SB_RcvMsg(&SAMPLE_APP_Data.MsgPtr, SAMPLE_APP_Data.CommandPipe, CFE_SB_PEND_FOREVER);
status = CFE_SB_ReceiveBuffer(&SBBufPtr, SAMPLE_APP_Data.CommandPipe, CFE_SB_PEND_FOREVER);

/*
** Performance Log Entry Stamp
Expand All @@ -91,7 +92,7 @@ void SAMPLE_APP_Main(void)

if (status == CFE_SUCCESS)
{
SAMPLE_APP_ProcessCommandPacket(SAMPLE_APP_Data.MsgPtr);
SAMPLE_APP_ProcessCommandPacket(SBBufPtr);
}
else
{
Expand Down Expand Up @@ -133,9 +134,8 @@ int32 SAMPLE_APP_Init(void)
*/
SAMPLE_APP_Data.PipeDepth = SAMPLE_APP_PIPE_DEPTH;

strncpy(SAMPLE_APP_Data.PipeName, "SAMPLE_APP_CMD_PIPE",
sizeof(SAMPLE_APP_Data.PipeName));
SAMPLE_APP_Data.PipeName[sizeof(SAMPLE_APP_Data.PipeName)-1] = 0;
strncpy(SAMPLE_APP_Data.PipeName, "SAMPLE_APP_CMD_PIPE", sizeof(SAMPLE_APP_Data.PipeName));
SAMPLE_APP_Data.PipeName[sizeof(SAMPLE_APP_Data.PipeName) - 1] = 0;

/*
** Initialize event filter table...
Expand Down Expand Up @@ -168,7 +168,7 @@ int32 SAMPLE_APP_Init(void)
/*
** Initialize housekeeping packet (clear user data area).
*/
CFE_MSG_Init(&SAMPLE_APP_Data.HkTlm.TlmHeader.BaseMsg, SAMPLE_APP_HK_TLM_MID, sizeof(SAMPLE_APP_Data.HkTlm));
CFE_MSG_Init(&SAMPLE_APP_Data.HkTlm.TlmHeader.Msg, SAMPLE_APP_HK_TLM_MID, sizeof(SAMPLE_APP_Data.HkTlm));

/*
** Create Software Bus message pipe.
Expand Down Expand Up @@ -232,20 +232,20 @@ int32 SAMPLE_APP_Init(void)
/* command pipe. */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void SAMPLE_APP_ProcessCommandPacket(CFE_MSG_Message_t *MsgPtr)
void SAMPLE_APP_ProcessCommandPacket(CFE_SB_Buffer_t *SBBufPtr)
{
CFE_SB_MsgId_t MsgId = CFE_SB_INVALID_MSG_ID;

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

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

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

default:
Expand All @@ -263,37 +263,37 @@ void SAMPLE_APP_ProcessCommandPacket(CFE_MSG_Message_t *MsgPtr)
/* SAMPLE_APP_ProcessGroundCommand() -- SAMPLE ground commands */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
void SAMPLE_APP_ProcessGroundCommand(CFE_MSG_Message_t *MsgPtr)
void SAMPLE_APP_ProcessGroundCommand(CFE_SB_Buffer_t *SBBufPtr)
{
CFE_MSG_FcnCode_t CommandCode = 0;

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

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

break;

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

break;

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

break;
Expand All @@ -318,7 +318,7 @@ void SAMPLE_APP_ProcessGroundCommand(CFE_MSG_Message_t *MsgPtr)
/* telemetry, packetize it and send it to the housekeeping task via */
/* the software bus */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int32 SAMPLE_APP_ReportHousekeeping(const CFE_SB_CmdHdr_t *Msg)
int32 SAMPLE_APP_ReportHousekeeping(const CFE_MSG_CommandHeader_t *Msg)
{
int i;

Expand All @@ -331,8 +331,8 @@ int32 SAMPLE_APP_ReportHousekeeping(const CFE_SB_CmdHdr_t *Msg)
/*
** Send housekeeping telemetry packet...
*/
CFE_SB_TimeStampMsg(&SAMPLE_APP_Data.HkTlm.TlmHeader.BaseMsg);
CFE_SB_SendMsg(&SAMPLE_APP_Data.HkTlm.TlmHeader.BaseMsg);
CFE_SB_TimeStampMsg(&SAMPLE_APP_Data.HkTlm.TlmHeader.Msg);
CFE_SB_TransmitMsg(&SAMPLE_APP_Data.HkTlm.TlmHeader.Msg, true);

/*
** Manage any pending table loads, validations, etc.
Expand All @@ -351,7 +351,7 @@ int32 SAMPLE_APP_ReportHousekeeping(const CFE_SB_CmdHdr_t *Msg)
/* SAMPLE_APP_Noop -- SAMPLE NOOP commands */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
int32 SAMPLE_APP_Noop(const SAMPLE_APP_Noop_t *Msg)
int32 SAMPLE_APP_Noop(const SAMPLE_APP_NoopCmd_t *Msg)
{

SAMPLE_APP_Data.CmdCounter++;
Expand All @@ -371,7 +371,7 @@ int32 SAMPLE_APP_Noop(const SAMPLE_APP_Noop_t *Msg)
/* part of the task telemetry. */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int32 SAMPLE_APP_ResetCounters(const SAMPLE_APP_ResetCounters_t *Msg)
int32 SAMPLE_APP_ResetCounters(const SAMPLE_APP_ResetCountersCmd_t *Msg)
{

SAMPLE_APP_Data.CmdCounter = 0;
Expand All @@ -390,7 +390,7 @@ int32 SAMPLE_APP_ResetCounters(const SAMPLE_APP_ResetCounters_t *Msg)
/* This function Process Ground Station Command */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
int32 SAMPLE_APP_Process(const SAMPLE_APP_Process_t *Msg)
int32 SAMPLE_APP_Process(const SAMPLE_APP_ProcessCmd_t *Msg)
{
int32 status;
SAMPLE_APP_Table_t *TblPtr;
Expand Down Expand Up @@ -429,10 +429,10 @@ int32 SAMPLE_APP_Process(const SAMPLE_APP_Process_t *Msg)
/* SAMPLE_APP_VerifyCmdLength() -- Verify command packet length */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
bool SAMPLE_APP_VerifyCmdLength(CFE_MSG_Message_t *MsgPtr, CFE_MSG_Size_t ExpectedLength)
bool SAMPLE_APP_VerifyCmdLength(CFE_MSG_Message_t *MsgPtr, size_t ExpectedLength)
{
bool result = true;
CFE_MSG_Size_t ActualLength = 0;
size_t ActualLength = 0;
CFE_SB_MsgId_t MsgId = CFE_SB_INVALID_MSG_ID;
CFE_MSG_FcnCode_t FcnCode = 0;

Expand All @@ -448,8 +448,8 @@ bool SAMPLE_APP_VerifyCmdLength(CFE_MSG_Message_t *MsgPtr, CFE_MSG_Size_t Expect

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);
(unsigned int)CFE_SB_MsgIdToValue(MsgId), (unsigned int)FcnCode, (unsigned int)ActualLength,
(unsigned int)ExpectedLength);

result = false;

Expand Down
17 changes: 8 additions & 9 deletions fsw/src/sample_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ typedef struct
/*
** Operational data (not reported in housekeeping)...
*/
CFE_SB_PipeId_t CommandPipe;
CFE_MSG_Message_t *MsgPtr;
CFE_SB_PipeId_t CommandPipe;

/*
** Initialization data (not reported in housekeeping)...
Expand All @@ -104,16 +103,16 @@ typedef struct
*/
void SAMPLE_APP_Main(void);
int32 SAMPLE_APP_Init(void);
void SAMPLE_APP_ProcessCommandPacket(CFE_MSG_Message_t *MsgPtr);
void SAMPLE_APP_ProcessGroundCommand(CFE_MSG_Message_t *MsgPtr);
int32 SAMPLE_APP_ReportHousekeeping(const CFE_SB_CmdHdr_t *Msg);
int32 SAMPLE_APP_ResetCounters(const SAMPLE_APP_ResetCounters_t *Msg);
int32 SAMPLE_APP_Process(const SAMPLE_APP_Process_t *Msg);
int32 SAMPLE_APP_Noop(const SAMPLE_APP_Noop_t *Msg);
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, CFE_MSG_Size_t ExpectedLength);
bool SAMPLE_APP_VerifyCmdLength(CFE_MSG_Message_t *MsgPtr, size_t ExpectedLength);

#endif /* _sample_app_h_ */
16 changes: 7 additions & 9 deletions fsw/src/sample_app_msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,19 @@
*/
typedef struct
{
uint8 CmdHeader[CFE_SB_CMD_HDR_SIZE];

CFE_MSG_CommandHeader_t CmdHeader; /**< \brief Command header */
} SAMPLE_APP_NoArgsCmd_t;

/*
** The following commands all share the "NoArgs" format
**
** They are each given their own type name matching the command name, which_open_mode
** They are each given their own type name matching the command name, which
** allows them to change independently in the future without changing the prototype
** of the handler function
*/
typedef SAMPLE_APP_NoArgsCmd_t SAMPLE_APP_Noop_t;
typedef SAMPLE_APP_NoArgsCmd_t SAMPLE_APP_ResetCounters_t;
typedef SAMPLE_APP_NoArgsCmd_t SAMPLE_APP_Process_t;
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;

/*************************************************************************/
/*
Expand All @@ -73,11 +72,10 @@ typedef struct

typedef struct
{
CFE_SB_TlmHdr_t TlmHeader;
SAMPLE_APP_HkTlm_Payload_t Payload;
CFE_MSG_TelemetryHeader_t TlmHeader; /**< \brief Telemetry header */
SAMPLE_APP_HkTlm_Payload_t Payload; /**< \brief Telemetry payload */
} SAMPLE_APP_HkTlm_t;


#endif /* _sample_app_msg_h_ */

/************************/
Expand Down
6 changes: 3 additions & 3 deletions fsw/src/sample_app_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@

/* Development Build Macro Definitions */

#define SAMPLE_APP_BUILD_NUMBER 25 /*!< Development Build: Number of commits since baseline */
#define SAMPLE_APP_BUILD_NUMBER 29 /*!< Development Build: Number of commits since baseline */
#define SAMPLE_APP_BUILD_BASELINE \
"v1.2.0-rc1" /*!< Development Build: git tag that is the base for the current development */

/* Version Macro Definitions */

#define SAMPLE_APP_MAJOR_VERSION 1 /*!< @brief ONLY APPLY for OFFICIAL releases. Major version number. */
#define SAMPLE_APP_MINOR_VERSION 1 /*!< @brief ONLY APPLY for OFFICIAL releases. Minor version number. */
#define SAMPLE_APP_REVISION 99 /*!< @brief ONLY APPLY for OFFICIAL releases. The value "99" indicates a development version. Revision version number. */
#define SAMPLE_APP_MISSION_REV 0 /*!< @brief ONLY USED by MISSION Implementations. Mission revision */
#define SAMPLE_APP_REVISION 99 /*!< @brief ONLY APPLY for OFFICIAL releases. Revision version number. */
#define SAMPLE_APP_MISSION_REV 0 /*!< @brief ONLY USED by MISSION Implementations. Mission revision */

#define SAMPLE_APP_STR_HELPER(x) #x /*!< @brief Helper function to concatenate strings from integer macros */
#define SAMPLE_APP_STR(x) \
Expand Down
Loading