Skip to content

Commit

Permalink
Fix #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 427cae8 commit 385ce0d
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 78 deletions.
56 changes: 30 additions & 26 deletions fsw/src/sample_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ int32 SAMPLE_AppInit(void)
/*
** Initialize housekeeping packet (clear user data area).
*/
CFE_SB_InitMsg(&SAMPLE_AppData.HkBuf.MsgHdr, SAMPLE_APP_HK_TLM_MID, sizeof(SAMPLE_AppData.HkBuf), true);
CFE_MSG_Init(&SAMPLE_AppData.HkTlm.TlmHeader.BaseMsg, SAMPLE_APP_HK_TLM_MID, sizeof(SAMPLE_AppData.HkTlm));

/*
** Create Software Bus message pipe.
Expand Down Expand Up @@ -230,20 +230,20 @@ int32 SAMPLE_AppInit(void)
/* command pipe. */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
void SAMPLE_ProcessCommandPacket(CFE_SB_MsgPtr_t Msg)
void SAMPLE_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_ProcessGroundCommand(Msg);
SAMPLE_ProcessGroundCommand(MsgPtr);
break;

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

default:
Expand All @@ -261,37 +261,37 @@ void SAMPLE_ProcessCommandPacket(CFE_SB_MsgPtr_t Msg)
/* SAMPLE_ProcessGroundCommand() -- SAMPLE ground commands */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
void SAMPLE_ProcessGroundCommand(CFE_SB_MsgPtr_t Msg)
void SAMPLE_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_VerifyCmdLength(Msg, sizeof(SAMPLE_Noop_t)))
if (SAMPLE_VerifyCmdLength(MsgPtr, sizeof(SAMPLE_Noop_t)))
{
SAMPLE_Noop((SAMPLE_Noop_t *)Msg);
SAMPLE_Noop((SAMPLE_Noop_t *)MsgPtr);
}

break;

case SAMPLE_APP_RESET_COUNTERS_CC:
if (SAMPLE_VerifyCmdLength(Msg, sizeof(SAMPLE_ResetCounters_t)))
if (SAMPLE_VerifyCmdLength(MsgPtr, sizeof(SAMPLE_ResetCounters_t)))
{
SAMPLE_ResetCounters((SAMPLE_ResetCounters_t *)Msg);
SAMPLE_ResetCounters((SAMPLE_ResetCounters_t *)MsgPtr);
}

break;

case SAMPLE_APP_PROCESS_CC:
if (SAMPLE_VerifyCmdLength(Msg, sizeof(SAMPLE_Process_t)))
if (SAMPLE_VerifyCmdLength(MsgPtr, sizeof(SAMPLE_Process_t)))
{
SAMPLE_Process((SAMPLE_Process_t *)Msg);
SAMPLE_Process((SAMPLE_Process_t *)MsgPtr);
}

break;
Expand Down Expand Up @@ -323,14 +323,14 @@ int32 SAMPLE_ReportHousekeeping(const CFE_SB_CmdHdr_t *Msg)
/*
** Get command execution counters...
*/
SAMPLE_AppData.HkBuf.HkTlm.Payload.CommandErrorCounter = SAMPLE_AppData.ErrCounter;
SAMPLE_AppData.HkBuf.HkTlm.Payload.CommandCounter = SAMPLE_AppData.CmdCounter;
SAMPLE_AppData.HkTlm.Payload.CommandErrorCounter = SAMPLE_AppData.ErrCounter;
SAMPLE_AppData.HkTlm.Payload.CommandCounter = SAMPLE_AppData.CmdCounter;

/*
** Send housekeeping telemetry packet...
*/
CFE_SB_TimeStampMsg(&SAMPLE_AppData.HkBuf.MsgHdr);
CFE_SB_SendMsg(&SAMPLE_AppData.HkBuf.MsgHdr);
CFE_SB_TimeStampMsg(&SAMPLE_AppData.HkTlm.TlmHeader.BaseMsg);
CFE_SB_SendMsg(&SAMPLE_AppData.HkTlm.TlmHeader.BaseMsg);

/*
** Manage any pending table loads, validations, etc.
Expand Down Expand Up @@ -427,23 +427,27 @@ int32 SAMPLE_Process(const SAMPLE_Process_t *Msg)
/* SAMPLE_VerifyCmdLength() -- Verify command packet length */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
bool SAMPLE_VerifyCmdLength(CFE_SB_MsgPtr_t Msg, uint16 ExpectedLength)
bool SAMPLE_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_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_HkTlm_t HkTlm;
} SAMPLE_HkBuffer_t;

/*
** Global Data
*/
Expand All @@ -81,7 +71,7 @@ typedef struct
/*
** Housekeeping telemetry packet...
*/
SAMPLE_HkBuffer_t HkBuf;
SAMPLE_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_AppMain(void);
int32 SAMPLE_AppInit(void);
void SAMPLE_ProcessCommandPacket(CFE_SB_MsgPtr_t Msg);
void SAMPLE_ProcessGroundCommand(CFE_SB_MsgPtr_t Msg);
void SAMPLE_ProcessCommandPacket(CFE_MSG_Message_t *MsgPtr);
void SAMPLE_ProcessGroundCommand(CFE_MSG_Message_t *MsgPtr);
int32 SAMPLE_ReportHousekeeping(const CFE_SB_CmdHdr_t *Msg);
int32 SAMPLE_ResetCounters(const SAMPLE_ResetCounters_t *Msg);
int32 SAMPLE_Process(const SAMPLE_Process_t *Msg);
Expand All @@ -124,6 +114,6 @@ void SAMPLE_GetCrc(const char *TableName);

int32 SAMPLE_TblValidationFunc(void *TblData);

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

#endif /* _sample_app_h_ */
2 changes: 1 addition & 1 deletion fsw/src/sample_app_msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ typedef struct

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

} OS_PACK SAMPLE_HkTlm_t;
Expand Down
Loading

0 comments on commit 385ce0d

Please sign in to comment.