Skip to content

Commit

Permalink
Fix nasa#1009, Alignment pattern - Msg module updates
Browse files Browse the repository at this point in the history
- CFE_MSG_Message_t no longer worst case alignment
- CFE_MSG_CommandHeader_t and CFE_MSG_TelemetryHeader_t now
  contain the base message type, CFE_MSG_Message_t
- Fixed size type issue in CFE_MSG_ComputeChecksum
- Replaced CFE_SB_TlmHdr_t and CFE_SB_CmdHdr_t with
  CFE_MSG_CommandHeader_t and CFE_MSG_TelemetryHeader_t
  • Loading branch information
skliper committed Dec 2, 2020
1 parent 38bd893 commit ebb12e8
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 69 deletions.
27 changes: 13 additions & 14 deletions modules/msg/mission_inc/default_cfe_msg_hdr_pri.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,23 @@ typedef struct
CCSDS_PrimaryHeader_t Pri; /**< \brief CCSDS Primary Header */
} CCSDS_SpacePacket_t;

/**
* \brief cFS generic base message
*/
typedef union
{
CCSDS_SpacePacket_t CCSDS; /**< \brief CCSDS Header (Pri or Pri + Ext) */
uint8 Byte[sizeof(CCSDS_SpacePacket_t)]; /**< \brief Byte level access */
} CFE_MSG_Message_t;

/**
* \brief cFS command header
*/
typedef struct
{

CCSDS_SpacePacket_t CCSDS; /**< \brief CCSDS header */
CFE_MSG_CommandSecondaryHeader_t Sec; /**< \brief Secondary header */
CFE_MSG_Message_t Msg; /**< \brief Base message */
CFE_MSG_CommandSecondaryHeader_t Sec; /**< \brief Secondary header */

} CFE_MSG_CommandHeader_t;

Expand All @@ -71,19 +80,9 @@ typedef struct
typedef struct
{

CCSDS_SpacePacket_t CCSDS; /**< \brief CCSDS header */
CFE_MSG_TelemetrySecondaryHeader_t Sec; /**< \brief Secondary header */
CFE_MSG_Message_t Msg; /**< \brief Base message */
CFE_MSG_TelemetrySecondaryHeader_t Sec; /**< \brief Secondary header */

} CFE_MSG_TelemetryHeader_t;

/**
* \brief cFS Generic packet header
*/
typedef union
{
CCSDS_SpacePacket_t CCSDS; /**< \brief CCSDS Header (Pri or Pri + Ext) */
uint32 Align; /**< \brief Force 32-bit alignment */
uint8 Byte[sizeof(CCSDS_SpacePacket_t)]; /**< \brief Byte level access */
} CFE_MSG_Message_t;

#endif /* _cfe_msg_hdr_ */
27 changes: 13 additions & 14 deletions modules/msg/mission_inc/default_cfe_msg_hdr_priext.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,23 @@ typedef struct
CCSDS_ExtendedHeader_t Ext; /**< \brief CCSDS Extended Header */
} CCSDS_SpacePacket_t;

/**
* \brief cFS generic base message
*/
typedef union
{
CCSDS_SpacePacket_t CCSDS; /**< \brief CCSDS Header (Pri or Pri + Ext) */
uint8 Byte[sizeof(CCSDS_SpacePacket_t)]; /**< \brief Byte level access */
} CFE_MSG_Message_t;

/**
* \brief cFS command header
*/
typedef struct
{

CCSDS_SpacePacket_t CCSDS; /**< \brief CCSDS header */
CFE_MSG_CommandSecondaryHeader_t Sec; /**< \brief Secondary header */
CFE_MSG_Message_t Msg; /**< \brief Base message */
CFE_MSG_CommandSecondaryHeader_t Sec; /**< \brief Secondary header */

} CFE_MSG_CommandHeader_t;

Expand All @@ -72,19 +81,9 @@ typedef struct
typedef struct
{

CCSDS_SpacePacket_t CCSDS; /**< \brief CCSDS header */
CFE_MSG_TelemetrySecondaryHeader_t Sec; /**< \brief Secondary header */
CFE_MSG_Message_t Msg; /**< \brief Base message */
CFE_MSG_TelemetrySecondaryHeader_t Sec; /**< \brief Secondary header */

} CFE_MSG_TelemetryHeader_t;

/**
* \brief cFS Generic packet header
*/
typedef union
{
CCSDS_SpacePacket_t CCSDS; /**< \brief CCSDS Header (Pri or Pri + Ext) */
uint32 Align; /**< \brief Force 32-bit alignment */
uint8 Byte[sizeof(CCSDS_SpacePacket_t)]; /**< \brief Byte level access */
} CFE_MSG_Message_t;

#endif /* _cfe_msg_hdr_ */
2 changes: 1 addition & 1 deletion modules/msg/src/cfe_msg_sechdr_checksum.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
CFE_MSG_Checksum_t CFE_MSG_ComputeCheckSum(const CFE_MSG_Message_t *MsgPtr)
{

uint32 PktLen = 0;
CFE_MSG_Size_t PktLen = 0;
const uint8 * BytePtr = MsgPtr->Byte;
CFE_MSG_Checksum_t chksum = 0xFF;

Expand Down
6 changes: 3 additions & 3 deletions modules/msg/unit-test-coverage/test_cfe_msg_checksum.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@

void Test_MSG_Checksum(void)
{
CFE_SB_CmdHdr_t cmd;
CFE_MSG_Message_t *msgptr = (CFE_MSG_Message_t *)&cmd;
bool actual;
CFE_MSG_CommandHeader_t cmd;
CFE_MSG_Message_t *msgptr = &cmd.Msg;
bool actual;

UtPrintf("Bad parameter tests, Null pointers");
memset(&cmd, 0, sizeof(cmd));
Expand Down
10 changes: 5 additions & 5 deletions modules/msg/unit-test-coverage/test_cfe_msg_fc.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@

void Test_MSG_FcnCode(void)
{
CFE_SB_CmdHdr_t cmd;
CFE_MSG_Message_t *msgptr = (CFE_MSG_Message_t *)&cmd;
CFE_MSG_FcnCode_t input[] = {0, TEST_FCNCODE_MAX / 2, TEST_FCNCODE_MAX};
CFE_MSG_FcnCode_t actual = TEST_FCNCODE_MAX;
int i;
CFE_MSG_CommandHeader_t cmd;
CFE_MSG_Message_t *msgptr = &cmd.Msg;
CFE_MSG_FcnCode_t input[] = {0, TEST_FCNCODE_MAX / 2, TEST_FCNCODE_MAX};
CFE_MSG_FcnCode_t actual = TEST_FCNCODE_MAX;
int i;

UtPrintf("Bad parameter tests, Null pointers, invalid (max valid + 1, max)");
memset(&cmd, 0, sizeof(cmd));
Expand Down
55 changes: 28 additions & 27 deletions modules/msg/unit-test-coverage/test_cfe_msg_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
void Test_MSG_Init(void)
{

CFE_MSG_Message_t msg;
CFE_MSG_CommandHeader_t cmd;
CFE_MSG_Size_t size;
CFE_SB_MsgId_Atom_t msgidval_exp;
CFE_SB_MsgId_t msgid_act;
Expand All @@ -54,28 +54,28 @@ void Test_MSG_Init(void)
bool is_v1;

UtPrintf("Bad parameter tests, Null pointer, invalid size, invalid msgid");
ASSERT_EQ(CFE_MSG_Init(NULL, CFE_SB_ValueToMsgId(0), sizeof(msg)), CFE_MSG_BAD_ARGUMENT);
ASSERT_EQ(CFE_MSG_Init(&msg, CFE_SB_ValueToMsgId(0), 0), CFE_MSG_BAD_ARGUMENT);
ASSERT_EQ(CFE_MSG_Init(&msg, CFE_SB_ValueToMsgId(CFE_PLATFORM_SB_HIGHEST_VALID_MSGID + 1), sizeof(msg)),
ASSERT_EQ(CFE_MSG_Init(NULL, CFE_SB_ValueToMsgId(0), sizeof(cmd)), CFE_MSG_BAD_ARGUMENT);
ASSERT_EQ(CFE_MSG_Init(&cmd.Msg, CFE_SB_ValueToMsgId(0), 0), CFE_MSG_BAD_ARGUMENT);
ASSERT_EQ(CFE_MSG_Init(&cmd.Msg, CFE_SB_ValueToMsgId(CFE_PLATFORM_SB_HIGHEST_VALID_MSGID + 1), sizeof(cmd)),
CFE_MSG_BAD_ARGUMENT);
ASSERT_EQ(CFE_MSG_Init(&msg, CFE_SB_ValueToMsgId(-1), sizeof(msg)), CFE_MSG_BAD_ARGUMENT);
ASSERT_EQ(CFE_MSG_Init(&cmd.Msg, CFE_SB_ValueToMsgId(-1), sizeof(cmd)), CFE_MSG_BAD_ARGUMENT);

UtPrintf("Set to all F's, msgid value = 0");
memset(&msg, 0xFF, sizeof(msg));
memset(&cmd, 0xFF, sizeof(cmd));
msgidval_exp = 0;

ASSERT_EQ(CFE_MSG_Init(&msg, CFE_SB_ValueToMsgId(msgidval_exp), sizeof(msg)), CFE_SUCCESS);
Test_MSG_PrintMsg(&msg, 0);
ASSERT_EQ(CFE_MSG_GetMsgId(&msg, &msgid_act), CFE_SUCCESS);
ASSERT_EQ(CFE_MSG_Init(&cmd.Msg, CFE_SB_ValueToMsgId(msgidval_exp), sizeof(cmd)), CFE_SUCCESS);
Test_MSG_PrintMsg(&cmd.Msg, 0);
ASSERT_EQ(CFE_MSG_GetMsgId(&cmd.Msg, &msgid_act), CFE_SUCCESS);
ASSERT_EQ(CFE_SB_MsgIdToValue(msgid_act), msgidval_exp);
ASSERT_EQ(CFE_MSG_GetSize(&msg, &size), CFE_SUCCESS);
ASSERT_EQ(size, sizeof(msg));
ASSERT_EQ(CFE_MSG_GetSegmentationFlag(&msg, &segflag), CFE_SUCCESS);
ASSERT_EQ(CFE_MSG_GetSize(&cmd.Msg, &size), CFE_SUCCESS);
ASSERT_EQ(size, sizeof(cmd));
ASSERT_EQ(CFE_MSG_GetSegmentationFlag(&cmd.Msg, &segflag), CFE_SUCCESS);
ASSERT_EQ(segflag, CFE_MSG_SegFlag_Unsegmented);

ASSERT_EQ(CFE_MSG_GetApId(&msg, &apid), CFE_SUCCESS);
ASSERT_EQ(CFE_MSG_GetHeaderVersion(&msg, &hdrver), CFE_SUCCESS);
ASSERT_EQ(CFE_MSG_GetHasSecondaryHeader(&msg, &hassec), CFE_SUCCESS);
ASSERT_EQ(CFE_MSG_GetApId(&cmd.Msg, &apid), CFE_SUCCESS);
ASSERT_EQ(CFE_MSG_GetHeaderVersion(&cmd.Msg, &hdrver), CFE_SUCCESS);
ASSERT_EQ(CFE_MSG_GetHasSecondaryHeader(&cmd.Msg, &hassec), CFE_SUCCESS);

/* A zero msgid will set hassec to false for v1 */
is_v1 = !hassec;
Expand All @@ -92,25 +92,25 @@ void Test_MSG_Init(void)
}

/* Confirm the rest of the fields not already explicitly checked */
ASSERT_EQ(Test_MSG_Pri_NotZero(&msg) & ~(MSG_APID_FLAG | MSG_HDRVER_FLAG | MSG_HASSEC_FLAG),
ASSERT_EQ(Test_MSG_Pri_NotZero(&cmd.Msg) & ~(MSG_APID_FLAG | MSG_HDRVER_FLAG | MSG_HASSEC_FLAG),
MSG_LENGTH_FLAG | MSG_SEGMENT_FLAG);

UtPrintf("Set to all 0, max msgid value");
memset(&msg, 0, sizeof(msg));
memset(&cmd, 0, sizeof(cmd));
msgidval_exp = CFE_PLATFORM_SB_HIGHEST_VALID_MSGID;

ASSERT_EQ(CFE_MSG_Init(&msg, CFE_SB_ValueToMsgId(msgidval_exp), sizeof(msg)), CFE_SUCCESS);
Test_MSG_PrintMsg(&msg, 0);
ASSERT_EQ(CFE_MSG_GetMsgId(&msg, &msgid_act), CFE_SUCCESS);
ASSERT_EQ(CFE_MSG_Init(&cmd.Msg, CFE_SB_ValueToMsgId(msgidval_exp), sizeof(cmd)), CFE_SUCCESS);
Test_MSG_PrintMsg(&cmd.Msg, 0);
ASSERT_EQ(CFE_MSG_GetMsgId(&cmd.Msg, &msgid_act), CFE_SUCCESS);
ASSERT_EQ(CFE_SB_MsgIdToValue(msgid_act), msgidval_exp);
ASSERT_EQ(CFE_MSG_GetSize(&msg, &size), CFE_SUCCESS);
ASSERT_EQ(size, sizeof(msg));
ASSERT_EQ(CFE_MSG_GetSegmentationFlag(&msg, &segflag), CFE_SUCCESS);
ASSERT_EQ(CFE_MSG_GetSize(&cmd.Msg, &size), CFE_SUCCESS);
ASSERT_EQ(size, sizeof(cmd));
ASSERT_EQ(CFE_MSG_GetSegmentationFlag(&cmd.Msg, &segflag), CFE_SUCCESS);
ASSERT_EQ(segflag, CFE_MSG_SegFlag_Unsegmented);

ASSERT_EQ(CFE_MSG_GetApId(&msg, &apid), CFE_SUCCESS);
ASSERT_EQ(CFE_MSG_GetHeaderVersion(&msg, &hdrver), CFE_SUCCESS);
ASSERT_EQ(CFE_MSG_GetHasSecondaryHeader(&msg, &hassec), CFE_SUCCESS);
ASSERT_EQ(CFE_MSG_GetApId(&cmd.Msg, &apid), CFE_SUCCESS);
ASSERT_EQ(CFE_MSG_GetHeaderVersion(&cmd.Msg, &hdrver), CFE_SUCCESS);
ASSERT_EQ(CFE_MSG_GetHasSecondaryHeader(&cmd.Msg, &hassec), CFE_SUCCESS);
ASSERT_EQ(hassec, true);
if (!is_v1)
{
Expand All @@ -123,5 +123,6 @@ void Test_MSG_Init(void)
ASSERT_EQ(hdrver, 0);
}

ASSERT_EQ(Test_MSG_Pri_NotZero(&msg) & ~MSG_HDRVER_FLAG, MSG_APID_FLAG | MSG_HASSEC_FLAG | MSG_TYPE_FLAG | MSG_LENGTH_FLAG | MSG_SEGMENT_FLAG);
ASSERT_EQ(Test_MSG_Pri_NotZero(&cmd.Msg) & ~MSG_HDRVER_FLAG, MSG_APID_FLAG | MSG_HASSEC_FLAG | MSG_TYPE_FLAG |
MSG_LENGTH_FLAG | MSG_SEGMENT_FLAG);
}
10 changes: 5 additions & 5 deletions modules/msg/unit-test-coverage/test_cfe_msg_time.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@

void Test_MSG_Time(void)
{
CFE_SB_TlmHdr_t tlm;
CFE_MSG_Message_t *msgptr = (CFE_MSG_Message_t *)&tlm;
CFE_TIME_SysTime_t input[] = {{0, 0}, {0x12345678, 0xABCDEF12}, {0xFFFFFFFF, 0xFFFFFFFF}};
CFE_TIME_SysTime_t actual = {0xFFFFFFFF, 0xFFFFFFFF};
int i;
CFE_MSG_TelemetryHeader_t tlm;
CFE_MSG_Message_t *msgptr = &tlm.Msg;
CFE_TIME_SysTime_t input[] = {{0, 0}, {0x12345678, 0xABCDEF12}, {0xFFFFFFFF, 0xFFFFFFFF}};
CFE_TIME_SysTime_t actual = {0xFFFFFFFF, 0xFFFFFFFF};
int i;

UtPrintf("Bad parameter tests, Null pointers, no secondary header");
memset(&tlm, 0, sizeof(tlm));
Expand Down

0 comments on commit ebb12e8

Please sign in to comment.