From b9a519378c1f427e901e4042a74d1c9a18c332fd Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Wed, 8 Jan 2020 15:14:37 -0500 Subject: [PATCH] Fix #53, Opaque CFE_SB_MsgId_t values 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. --- fsw/src/sample_app.c | 12 ++++++------ unit-test/coveragetest/coveragetest_sample_app.c | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/fsw/src/sample_app.c b/fsw/src/sample_app.c index 82e51e1..cd79837 100644 --- a/fsw/src/sample_app.c +++ b/fsw/src/sample_app.c @@ -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); @@ -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) { @@ -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 ) { @@ -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); @@ -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; } @@ -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); diff --git a/unit-test/coveragetest/coveragetest_sample_app.c b/unit-test/coveragetest/coveragetest_sample_app.c index b7a53a6..25d0a87 100644 --- a/unit-test/coveragetest/coveragetest_sample_app.c +++ b/unit-test/coveragetest/coveragetest_sample_app.c @@ -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);