Skip to content

Commit

Permalink
Fix #53, Opaque CFE_SB_MsgId_t values
Browse files Browse the repository at this point in the history
Do not assume CFE_SB_MsgId_t is implicitly integral in nature.
When an integer value is required for printing or backward
compatibility, use the explicit conversion routine to
get this.
  • Loading branch information
jphickey committed Apr 8, 2020
1 parent b956292 commit 73c9083
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 21 deletions.
13 changes: 10 additions & 3 deletions fsw/platform_inc/sample_app_msgids.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,16 @@
#ifndef _sample_app_msgids_h_
#define _sample_app_msgids_h_

#define SAMPLE_APP_CMD_MID 0x1882
#define SAMPLE_APP_SEND_HK_MID 0x1883
#define SAMPLE_APP_HK_TLM_MID 0x0883
#define SAMPLE_APP_CMD_MID_VALUE 0x1882
#define SAMPLE_APP_SEND_HK_MID_VALUE 0x1883
#define SAMPLE_APP_HK_TLM_MID_VALUE 0x0883


#define SAMPLE_APP_CMD_MID CFE_SB_MSGID_LITERAL(SAMPLE_APP_CMD_MID_VALUE )
#define SAMPLE_APP_SEND_HK_MID CFE_SB_MSGID_LITERAL(SAMPLE_APP_SEND_HK_MID_VALUE)
#define SAMPLE_APP_HK_TLM_MID CFE_SB_MSGID_LITERAL(SAMPLE_APP_HK_TLM_MID_VALUE )



#endif /* _sample_app_msgids_h_ */

Expand Down
31 changes: 14 additions & 17 deletions fsw/src/sample_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,23 +263,20 @@ void SAMPLE_ProcessCommandPacket( CFE_SB_MsgPtr_t Msg )
CFE_SB_MsgId_t MsgId;

MsgId = CFE_SB_GetMsgId(Msg);

switch (MsgId)
if (CFE_SB_MsgId_Equal(MsgId, SAMPLE_APP_CMD_MID))
{
case SAMPLE_APP_CMD_MID:
SAMPLE_ProcessGroundCommand(Msg);
break;

case SAMPLE_APP_SEND_HK_MID:
SAMPLE_ReportHousekeeping((CCSDS_CommandPacket_t *)Msg);
break;

default:
CFE_EVS_SendEvent(SAMPLE_INVALID_MSGID_ERR_EID,
CFE_EVS_EventType_ERROR,
"SAMPLE: invalid command packet,MID = 0x%x",
MsgId);
break;
SAMPLE_ProcessGroundCommand(Msg);
}
else if (CFE_SB_MsgId_Equal(MsgId, SAMPLE_APP_SEND_HK_MID))
{
SAMPLE_ReportHousekeeping((CCSDS_CommandPacket_t *)Msg);
}
else
{
CFE_EVS_SendEvent(SAMPLE_INVALID_MSGID_ERR_EID,
CFE_EVS_EventType_ERROR,
"SAMPLE: invalid command packet,MID = 0x%x",
(unsigned int)CFE_SB_MsgIdToValue(MsgId));
}

return;
Expand Down Expand Up @@ -488,7 +485,7 @@ bool SAMPLE_VerifyCmdLength( CFE_SB_MsgPtr_t Msg, uint16 ExpectedLength )
CFE_EVS_SendEvent(SAMPLE_LEN_ERR_EID,
CFE_EVS_EventType_ERROR,
"Invalid Msg length: ID = 0x%X, CC = %d, Len = %d, Expected = %d",
MessageID,
(unsigned int)CFE_SB_MsgIdToValue(MessageID),
CommandCode,
ActualLength,
ExpectedLength);
Expand Down
2 changes: 1 addition & 1 deletion unit-test/coveragetest/coveragetest_sample_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ void Test_SAMPLE_ProcessCommandPacket(void)
SAMPLE_ProcessCommandPacket(&TestMsg.Base);

/* invalid message id */
TestMsgId = 0;
TestMsgId = CFE_SB_INVALID_MSG_ID;
UT_SetDataBuffer(UT_KEY(CFE_SB_GetMsgId), &TestMsgId,
sizeof(TestMsgId), false);
SAMPLE_ProcessCommandPacket(&TestMsg.Base);
Expand Down

0 comments on commit 73c9083

Please sign in to comment.