Skip to content

Commit

Permalink
Merge pull request #108 from nasa/integration-candidate
Browse files Browse the repository at this point in the history
Integration Candidate: 2020-11-10
  • Loading branch information
astrogeco authored Nov 16, 2020
2 parents 23fe3c6 + f7f2d19 commit 0d11d9e
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 84 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ 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+dev22

- Replaces deprecated SB API's with MSG
- No impact, removes undesirable pattern use of `OS_PACK`
- See <https://github.com/nasa/sample_app/pull/108>

### Development Build: 1.2.0-rc1+dev18

- No behavior changes. All identifiers now use the prefix `SAMPLE_APP_`. Changes the name of the main function from SAMPLE_AppMain to SAMPLE_APP_Main which affects the CFE startup script.
Expand Down
64 changes: 34 additions & 30 deletions fsw/src/sample_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
SAMPLE_APP_Data_t SAMPLE_APP_Data;

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
/* SAMPLE_APP_Main() -- Application entry point and main process loop */
/* SAMPLE_APP_Main() -- Application entry point and main process loop */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
void SAMPLE_APP_Main(void)
Expand Down Expand Up @@ -113,7 +113,7 @@ void SAMPLE_APP_Main(void)

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* SAMPLE_APP_Init() -- initialization */
/* SAMPLE_APP_Init() -- initialization */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
int32 SAMPLE_APP_Init(void)
Expand Down Expand Up @@ -168,7 +168,7 @@ int32 SAMPLE_APP_Init(void)
/*
** Initialize housekeeping packet (clear user data area).
*/
CFE_SB_InitMsg(&SAMPLE_APP_Data.HkBuf.MsgHdr, SAMPLE_APP_HK_TLM_MID, sizeof(SAMPLE_APP_Data.HkBuf), true);
CFE_MSG_Init(&SAMPLE_APP_Data.HkTlm.TlmHeader.BaseMsg, SAMPLE_APP_HK_TLM_MID, sizeof(SAMPLE_APP_Data.HkTlm));

/*
** Create Software Bus message pipe.
Expand Down Expand Up @@ -225,27 +225,27 @@ int32 SAMPLE_APP_Init(void)
} /* End of SAMPLE_APP_Init() */

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
/* Name: SAMPLE_APP_ProcessCommandPacket */
/* Name: SAMPLE_APP_ProcessCommandPacket */
/* */
/* Purpose: */
/* This routine will process any packet that is received on the SAMPLE */
/* command pipe. */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void SAMPLE_APP_ProcessCommandPacket(CFE_SB_MsgPtr_t Msg)
void SAMPLE_APP_ProcessCommandPacket(CFE_MSG_Message_t *MsgPtr)
{
CFE_SB_MsgId_t MsgId;
CFE_SB_MsgId_t MsgId = CFE_SB_INVALID_MSG_ID;

MsgId = CFE_SB_GetMsgId(Msg);
CFE_MSG_GetMsgId(MsgPtr, &MsgId);

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

case SAMPLE_APP_SEND_HK_MID:
SAMPLE_APP_ReportHousekeeping((CFE_SB_CmdHdr_t *)Msg);
SAMPLE_APP_ReportHousekeeping((CFE_SB_CmdHdr_t *)MsgPtr);
break;

default:
Expand All @@ -260,40 +260,40 @@ void SAMPLE_APP_ProcessCommandPacket(CFE_SB_MsgPtr_t Msg)

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
/* */
/* SAMPLE_APP_ProcessGroundCommand() -- SAMPLE ground commands */
/* SAMPLE_APP_ProcessGroundCommand() -- SAMPLE ground commands */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
void SAMPLE_APP_ProcessGroundCommand(CFE_SB_MsgPtr_t Msg)
void SAMPLE_APP_ProcessGroundCommand(CFE_MSG_Message_t *MsgPtr)
{
uint16 CommandCode;
CFE_MSG_FcnCode_t CommandCode = 0;

CommandCode = CFE_SB_GetCmdCode(Msg);
CFE_MSG_GetFcnCode(MsgPtr, &CommandCode);

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

break;

case SAMPLE_APP_RESET_COUNTERS_CC:
if (SAMPLE_APP_VerifyCmdLength(Msg, sizeof(SAMPLE_APP_ResetCounters_t)))
if (SAMPLE_APP_VerifyCmdLength(MsgPtr, sizeof(SAMPLE_APP_ResetCounters_t)))
{
SAMPLE_APP_ResetCounters((SAMPLE_APP_ResetCounters_t *)Msg);
SAMPLE_APP_ResetCounters((SAMPLE_APP_ResetCounters_t *)MsgPtr);
}

break;

case SAMPLE_APP_PROCESS_CC:
if (SAMPLE_APP_VerifyCmdLength(Msg, sizeof(SAMPLE_APP_Process_t)))
if (SAMPLE_APP_VerifyCmdLength(MsgPtr, sizeof(SAMPLE_APP_Process_t)))
{
SAMPLE_APP_Process((SAMPLE_APP_Process_t *)Msg);
SAMPLE_APP_Process((SAMPLE_APP_Process_t *)MsgPtr);
}

break;
Expand Down Expand Up @@ -325,14 +325,14 @@ int32 SAMPLE_APP_ReportHousekeeping(const CFE_SB_CmdHdr_t *Msg)
/*
** Get command execution counters...
*/
SAMPLE_APP_Data.HkBuf.HkTlm.Payload.CommandErrorCounter = SAMPLE_APP_Data.ErrCounter;
SAMPLE_APP_Data.HkBuf.HkTlm.Payload.CommandCounter = SAMPLE_APP_Data.CmdCounter;
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(&SAMPLE_APP_Data.HkBuf.MsgHdr);
CFE_SB_SendMsg(&SAMPLE_APP_Data.HkBuf.MsgHdr);
CFE_SB_TimeStampMsg(&SAMPLE_APP_Data.HkTlm.TlmHeader.BaseMsg);
CFE_SB_SendMsg(&SAMPLE_APP_Data.HkTlm.TlmHeader.BaseMsg);

/*
** Manage any pending table loads, validations, etc.
Expand Down Expand Up @@ -429,23 +429,27 @@ int32 SAMPLE_APP_Process(const SAMPLE_APP_Process_t *Msg)
/* SAMPLE_APP_VerifyCmdLength() -- Verify command packet length */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
bool SAMPLE_APP_VerifyCmdLength(CFE_SB_MsgPtr_t Msg, uint16 ExpectedLength)
bool SAMPLE_APP_VerifyCmdLength(CFE_MSG_Message_t *MsgPtr, CFE_MSG_Size_t ExpectedLength)
{
bool result = true;
bool result = true;
CFE_MSG_Size_t ActualLength = 0;
CFE_SB_MsgId_t MsgId = CFE_SB_INVALID_MSG_ID;
CFE_MSG_FcnCode_t FcnCode = 0;

uint16 ActualLength = CFE_SB_GetTotalMsgLength(Msg);
CFE_MSG_GetSize(MsgPtr, &ActualLength);

/*
** Verify the command packet length.
*/
if (ExpectedLength != ActualLength)
{
CFE_SB_MsgId_t MessageID = CFE_SB_GetMsgId(Msg);
uint16 CommandCode = CFE_SB_GetCmdCode(Msg);
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 = %d, Len = %d, Expected = %d",
(unsigned int)CFE_SB_MsgIdToValue(MessageID), CommandCode, ActualLength, ExpectedLength);
"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;

Expand Down
22 changes: 6 additions & 16 deletions fsw/src/sample_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,6 @@
** 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_APP_HkTlm_t HkTlm;
} SAMPLE_APP_HkBuffer_t;

/*
** Global Data
*/
Expand All @@ -81,7 +71,7 @@ typedef struct
/*
** Housekeeping telemetry packet...
*/
SAMPLE_APP_HkBuffer_t HkBuf;
SAMPLE_APP_HkTlm_t HkTlm;

/*
** Run Status variable used in the main processing loop
Expand All @@ -91,8 +81,8 @@ typedef struct
/*
** Operational data (not reported in housekeeping)...
*/
CFE_SB_PipeId_t CommandPipe;
CFE_SB_MsgPtr_t MsgPtr;
CFE_SB_PipeId_t CommandPipe;
CFE_MSG_Message_t *MsgPtr;

/*
** Initialization data (not reported in housekeeping)...
Expand All @@ -114,8 +104,8 @@ typedef struct
*/
void SAMPLE_APP_Main(void);
int32 SAMPLE_APP_Init(void);
void SAMPLE_APP_ProcessCommandPacket(CFE_SB_MsgPtr_t Msg);
void SAMPLE_APP_ProcessGroundCommand(CFE_SB_MsgPtr_t Msg);
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);
Expand All @@ -124,6 +114,6 @@ void SAMPLE_APP_GetCrc(const char *TableName);

int32 SAMPLE_APP_TblValidationFunc(void *TblData);

bool SAMPLE_APP_VerifyCmdLength(CFE_SB_MsgPtr_t Msg, uint16 ExpectedLength);
bool SAMPLE_APP_VerifyCmdLength(CFE_MSG_Message_t *MsgPtr, CFE_MSG_Size_t ExpectedLength);

#endif /* _sample_app_h_ */
4 changes: 2 additions & 2 deletions fsw/src/sample_app_msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ typedef struct

typedef struct
{
uint8 TlmHeader[CFE_SB_TLM_HDR_SIZE];
CFE_SB_TlmHdr_t TlmHeader;
SAMPLE_APP_HkTlm_Payload_t Payload;
} SAMPLE_APP_HkTlm_t;

} OS_PACK SAMPLE_APP_HkTlm_t;

#endif /* _sample_app_msg_h_ */

Expand Down
2 changes: 1 addition & 1 deletion fsw/src/sample_app_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

/* Development Build Macro Definitions */

#define SAMPLE_APP_BUILD_NUMBER 18 /*!< Development Build: Number of commits since baseline */
#define SAMPLE_APP_BUILD_NUMBER 22 /*!< 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 */

Expand Down
Loading

0 comments on commit 0d11d9e

Please sign in to comment.