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 6, 2020
1 parent b956292 commit b9a5193
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions fsw/src/sample_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ int32 SAMPLE_AppInit( void )
** Initialize housekeeping packet (clear user data area).
*/
CFE_SB_InitMsg(&SAMPLE_AppData.HkBuf.MsgHdr,
SAMPLE_APP_HK_TLM_MID,
CFE_SB_ValueToMsgId(SAMPLE_APP_HK_TLM_MID),
sizeof(SAMPLE_AppData.HkBuf),
true);

Expand All @@ -194,7 +194,7 @@ int32 SAMPLE_AppInit( void )
/*
** Subscribe to Housekeeping request commands
*/
status = CFE_SB_Subscribe(SAMPLE_APP_SEND_HK_MID,
status = CFE_SB_Subscribe(CFE_SB_ValueToMsgId(SAMPLE_APP_SEND_HK_MID),
SAMPLE_AppData.CommandPipe);
if (status != CFE_SUCCESS)
{
Expand All @@ -206,7 +206,7 @@ int32 SAMPLE_AppInit( void )
/*
** Subscribe to ground command packets
*/
status = CFE_SB_Subscribe(SAMPLE_APP_CMD_MID,
status = CFE_SB_Subscribe(CFE_SB_ValueToMsgId(SAMPLE_APP_CMD_MID),
SAMPLE_AppData.CommandPipe);
if (status != CFE_SUCCESS )
{
Expand Down Expand Up @@ -264,7 +264,7 @@ void SAMPLE_ProcessCommandPacket( CFE_SB_MsgPtr_t Msg )

MsgId = CFE_SB_GetMsgId(Msg);

switch (MsgId)
switch (CFE_SB_MsgIdToValue(MsgId))
{
case SAMPLE_APP_CMD_MID:
SAMPLE_ProcessGroundCommand(Msg);
Expand All @@ -278,7 +278,7 @@ void SAMPLE_ProcessCommandPacket( CFE_SB_MsgPtr_t Msg )
CFE_EVS_SendEvent(SAMPLE_INVALID_MSGID_ERR_EID,
CFE_EVS_EventType_ERROR,
"SAMPLE: invalid command packet,MID = 0x%x",
MsgId);
(unsigned int)CFE_SB_MsgIdToValue(MsgId));
break;
}

Expand Down Expand Up @@ -488,7 +488,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
6 changes: 3 additions & 3 deletions unit-test/coveragetest/coveragetest_sample_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,18 +264,18 @@ void Test_SAMPLE_ProcessCommandPacket(void)
* The CFE_SB_GetMsgId() stub uses a data buffer to hold the
* message ID values to return.
*/
TestMsgId = SAMPLE_APP_CMD_MID;
TestMsgId = CFE_SB_ValueToMsgId(SAMPLE_APP_CMD_MID);
UT_SetDataBuffer(UT_KEY(CFE_SB_GetMsgId), &TestMsgId,
sizeof(TestMsgId), false);
SAMPLE_ProcessCommandPacket(&TestMsg.Base);

TestMsgId = SAMPLE_APP_SEND_HK_MID;
TestMsgId = CFE_SB_ValueToMsgId(SAMPLE_APP_SEND_HK_MID);
UT_SetDataBuffer(UT_KEY(CFE_SB_GetMsgId), &TestMsgId,
sizeof(TestMsgId), false);
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 b9a5193

Please sign in to comment.