Skip to content

Commit

Permalink
Fix #123, use CFE_MSG_PTR conversion macro
Browse files Browse the repository at this point in the history
Rather than taking the address of a sub-member, use the macro provided
from the CFE_MSG module to convert from a local container to a
CFE_MSG_Messge_t pointer.
  • Loading branch information
jphickey committed Oct 24, 2023
1 parent 1f40c79 commit bd37cab
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 23 deletions.
3 changes: 2 additions & 1 deletion fsw/src/sc_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ CFE_Status_t SC_AppInit(void)
SC_AppData.NextCmdTime[SC_Process_RTP] = SC_MAX_TIME;

/* Initialize the SC housekeeping packet */
CFE_MSG_Init(&SC_OperData.HkPacket.TelemetryHeader.Msg, CFE_SB_ValueToMsgId(SC_HK_TLM_MID), sizeof(SC_HkTlm_t));
CFE_MSG_Init(CFE_MSG_PTR(SC_OperData.HkPacket.TelemetryHeader), CFE_SB_ValueToMsgId(SC_HK_TLM_MID),
sizeof(SC_HkTlm_t));

/* Select auto-exec RTS to start during first HK request */
if (CFE_ES_GetResetType(NULL) == CFE_PSP_RST_TYPE_POWERON)
Expand Down
16 changes: 8 additions & 8 deletions fsw/src/sc_cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void SC_ProcessAtpCmd(void)
if (!SC_AppData.EnableHeaderUpdate)
{
/* If header update is NOT enabled, confirm this table entry has a valid checksum already */
CFE_MSG_ValidateChecksum(&EntryPtr->Msg, &ChecksumValid);
CFE_MSG_ValidateChecksum(CFE_MSG_PTR(EntryPtr->Msg), &ChecksumValid);
}
if (ChecksumValid)
{
Expand All @@ -128,8 +128,8 @@ void SC_ProcessAtpCmd(void)
** SC immediately executes the switch command.
*/

CFE_MSG_GetMsgId(&EntryPtr->Msg, &MessageID);
CFE_MSG_GetFcnCode(&EntryPtr->Msg, &CommandCode);
CFE_MSG_GetMsgId(CFE_MSG_PTR(EntryPtr->Msg), &MessageID);
CFE_MSG_GetFcnCode(CFE_MSG_PTR(EntryPtr->Msg), &CommandCode);

if (CommandCode == SC_SWITCH_ATS_CC && CFE_SB_MsgIdToValue(MessageID) == SC_CMD_MID)
{
Expand Down Expand Up @@ -157,7 +157,7 @@ void SC_ProcessAtpCmd(void)
}
else
{
Result = CFE_SB_TransmitMsg(&EntryPtr->Msg, SC_AppData.EnableHeaderUpdate);
Result = CFE_SB_TransmitMsg(CFE_MSG_PTR(EntryPtr->Msg), SC_AppData.EnableHeaderUpdate);

if (Result == CFE_SUCCESS)
{
Expand Down Expand Up @@ -339,15 +339,15 @@ void SC_ProcessRtpCommand(void)
if (!SC_AppData.EnableHeaderUpdate)
{
/* If header update is NOT enabled, confirm this table entry has a valid checksum already */
CFE_MSG_ValidateChecksum(&EntryPtr->Msg, &ChecksumValid);
CFE_MSG_ValidateChecksum(CFE_MSG_PTR(EntryPtr->Msg), &ChecksumValid);
}
if (ChecksumValid)
{
/*
** Try Sending the command on the Software Bus
*/

Result = CFE_SB_TransmitMsg(&EntryPtr->Msg, SC_AppData.EnableHeaderUpdate);
Result = CFE_SB_TransmitMsg(CFE_MSG_PTR(EntryPtr->Msg), SC_AppData.EnableHeaderUpdate);

if (Result == CFE_SUCCESS)
{
Expand Down Expand Up @@ -474,8 +474,8 @@ void SC_SendHkPacket(void)
} /* end for */

/* send the status packet */
CFE_SB_TimeStampMsg(&SC_OperData.HkPacket.TelemetryHeader.Msg);
CFE_SB_TransmitMsg(&SC_OperData.HkPacket.TelemetryHeader.Msg, true);
CFE_SB_TimeStampMsg(CFE_MSG_PTR(SC_OperData.HkPacket.TelemetryHeader));
CFE_SB_TransmitMsg(CFE_MSG_PTR(SC_OperData.HkPacket.TelemetryHeader), true);
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Expand Down
12 changes: 6 additions & 6 deletions fsw/src/sc_loads.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ void SC_LoadAts(uint16 AtsIndex)
SC_OperData.AtsCmdStatusTblAddr[AtsIndex][SC_ATS_CMD_NUM_TO_INDEX(AtsCmdNum)] == SC_Status_EMPTY)
{
/* get message size */
CFE_MSG_GetSize(&EntryPtr->Msg, &MessageSize);
CFE_MSG_GetSize(CFE_MSG_PTR(EntryPtr->Msg), &MessageSize);

/* if the length of the command is valid */
if (MessageSize >= SC_PACKET_MIN_SIZE && MessageSize <= SC_PACKET_MAX_SIZE)
Expand Down Expand Up @@ -404,12 +404,12 @@ bool SC_ParseRts(uint32 Buffer32[])
*/
EntryPtr = (SC_RtsEntry_t *)&Buffer32[i];

CFE_MSG_GetSize(&EntryPtr->Msg, &CmdSize);
CFE_MSG_GetSize(CFE_MSG_PTR(EntryPtr->Msg), &CmdSize);

/* Add header size, round up to boundary, convert to index delta */
IndexDelta = (CmdSize + SC_RTS_HEADER_SIZE + SC_ROUND_UP_BYTES) / sizeof(Buffer32[0]);

CFE_MSG_GetMsgId(&EntryPtr->Msg, &MessageID);
CFE_MSG_GetMsgId(CFE_MSG_PTR(EntryPtr->Msg), &MessageID);

if (!CFE_SB_IsValidMsgId(MessageID))
{
Expand Down Expand Up @@ -557,7 +557,7 @@ void SC_UpdateAppend(void)
}
else
{
CFE_MSG_GetSize(&EntryPtr->Msg, &CommandBytes);
CFE_MSG_GetSize(CFE_MSG_PTR(EntryPtr->Msg), &CommandBytes);
CommandWords = (CommandBytes + SC_ROUND_UP_BYTES) / SC_BYTES_IN_WORD;

if ((CommandBytes < SC_PACKET_MIN_SIZE) || (CommandBytes > SC_PACKET_MAX_SIZE))
Expand Down Expand Up @@ -644,7 +644,7 @@ void SC_ProcessAppend(uint16 AtsIndex)
SC_OperData.AtsCmdStatusTblAddr[AtsIndex][CmdIndex] = SC_Status_LOADED;

/* update entry index to point to the next entry */
CFE_MSG_GetSize(&EntryPtr->Msg, &CommandBytes);
CFE_MSG_GetSize(CFE_MSG_PTR(EntryPtr->Msg), &CommandBytes);
CommandWords = (CommandBytes + SC_ROUND_UP_BYTES) / SC_BYTES_IN_WORD;
EntryIndex += (SC_ATS_HDR_NOPKT_WORDS + CommandWords);
}
Expand Down Expand Up @@ -797,7 +797,7 @@ int32 SC_VerifyAtsEntry(uint32 *Buffer32, int32 EntryIndex, int32 BufferWords)
else
{
/* Start with the byte length of the command packet */
CFE_MSG_GetSize(&EntryPtr->Msg, &CommandBytes);
CFE_MSG_GetSize(CFE_MSG_PTR(EntryPtr->Msg), &CommandBytes);

/* Convert packet byte length to word length (round up odd bytes) */
CommandWords = (CommandBytes + SC_ROUND_UP_BYTES) / SC_BYTES_IN_WORD;
Expand Down
6 changes: 3 additions & 3 deletions fsw/src/sc_rtsrq.c
Original file line number Diff line number Diff line change
Expand Up @@ -551,9 +551,9 @@ void SC_AutoStartRts(uint16 RtsNumber)
/*
** Format the command packet to start the first RTS
*/
CFE_MSG_Init(&CmdPkt.CommandHeader.Msg, CFE_SB_ValueToMsgId(SC_CMD_MID), sizeof(CmdPkt));
CFE_MSG_Init(CFE_MSG_PTR(CmdPkt.CommandHeader), CFE_SB_ValueToMsgId(SC_CMD_MID), sizeof(CmdPkt));

CFE_MSG_SetFcnCode(&CmdPkt.CommandHeader.Msg, SC_START_RTS_CC);
CFE_MSG_SetFcnCode(CFE_MSG_PTR(CmdPkt.CommandHeader), SC_START_RTS_CC);

/*
** Get the RTS ID to start.
Expand All @@ -563,7 +563,7 @@ void SC_AutoStartRts(uint16 RtsNumber)
/*
** Now send the command back to SC
*/
CFE_SB_TransmitMsg(&CmdPkt.CommandHeader.Msg, true);
CFE_SB_TransmitMsg(CFE_MSG_PTR(CmdPkt.CommandHeader), true);
}
else
{
Expand Down
4 changes: 2 additions & 2 deletions fsw/src/sc_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ void SC_GetNextRtsCommand(void)
CmdOffset = SC_OperData.RtsInfoTblAddr[RtsIndex].NextCommandPtr;
EntryPtr = (SC_RtsEntry_t *)&SC_OperData.RtsTblAddr[RtsIndex][CmdOffset];

CFE_MSG_GetSize(&EntryPtr->Msg, &CmdLength);
CFE_MSG_GetSize(CFE_MSG_PTR(EntryPtr->Msg), &CmdLength);
CmdLength += SC_RTS_HEADER_SIZE;

/*
Expand Down Expand Up @@ -196,7 +196,7 @@ void SC_GetNextRtsCommand(void)
/*
** get the length of the new command
*/
CFE_MSG_GetSize(&EntryPtr->Msg, &CmdLength);
CFE_MSG_GetSize(CFE_MSG_PTR(EntryPtr->Msg), &CmdLength);
CmdLength += SC_RTS_HEADER_SIZE;

/*
Expand Down
6 changes: 3 additions & 3 deletions unit-test/sc_dispatch_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void SC_VerifyCmdLength_Test_Nominal(void)
UT_SC_Dispatch_SetMsgSize(MsgSize);

/* Execute the function being tested */
UtAssert_BOOL_TRUE(SC_VerifyCmdLength(&CmdPacket.CommandHeader.Msg, sizeof(CmdPacket)));
UtAssert_BOOL_TRUE(SC_VerifyCmdLength(CFE_MSG_PTR(CmdPacket.CommandHeader), sizeof(CmdPacket)));

/* Verify results */
UtAssert_UINT32_EQ(SC_OperData.HkPacket.Payload.CmdErrCtr, 0);
Expand All @@ -122,7 +122,7 @@ void SC_VerifyCmdLength_Test_LenError(void)
UT_SC_Dispatch_SetMsgSize(MsgSize);

/* Execute the function being tested */
UtAssert_BOOL_FALSE(SC_VerifyCmdLength(&CmdPacket.CommandHeader.Msg, 999));
UtAssert_BOOL_FALSE(SC_VerifyCmdLength(CFE_MSG_PTR(CmdPacket.CommandHeader), 999));

/* Verify results */
UtAssert_UINT32_EQ(SC_OperData.HkPacket.Payload.CmdCtr, 0);
Expand All @@ -144,7 +144,7 @@ void SC_VerifyCmdLength_Test_LenErrorNotMID(void)
UT_SC_Dispatch_SetMsgSize(MsgSize);

/* Execute the function being tested */
UtAssert_BOOL_FALSE(SC_VerifyCmdLength(&CmdPacket.CommandHeader.Msg, 999));
UtAssert_BOOL_FALSE(SC_VerifyCmdLength(CFE_MSG_PTR(CmdPacket.CommandHeader), 999));

/* Verify results */
UtAssert_UINT32_EQ(SC_OperData.HkPacket.Payload.CmdCtr, 0);
Expand Down

0 comments on commit bd37cab

Please sign in to comment.