Skip to content

Commit

Permalink
Fix nasa#103, Use MSG APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
skliper committed Nov 4, 2020
1 parent 23fe3c6 commit 204b27f
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 83 deletions.
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_ */
3 changes: 1 addition & 2 deletions fsw/src/sample_app_msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,8 @@ typedef struct

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

} OS_PACK SAMPLE_APP_HkTlm_t;

#endif /* _sample_app_msg_h_ */
Expand Down
Loading

0 comments on commit 204b27f

Please sign in to comment.