diff --git a/fsw/cfe-core/unit-test/evs_UT.c b/fsw/cfe-core/unit-test/evs_UT.c index 7d2259f15..9cbea7bd1 100644 --- a/fsw/cfe-core/unit-test/evs_UT.c +++ b/fsw/cfe-core/unit-test/evs_UT.c @@ -2703,6 +2703,8 @@ void Test_Misc(void) /* Test housekeeping report with log enabled */ UT_InitData(); + CFE_SB_InitMsg((CFE_SB_Msg_t *) &CFE_EVS_GlobalData.EVS_TlmPkt, HK_SnapshotData.MsgId, + sizeof(CFE_EVS_GlobalData.EVS_TlmPkt), false); CFE_EVS_GlobalData.EVS_TlmPkt.Payload.LogEnabled = true; HK_SnapshotData.Count = 0; UT_SetHookFunction(UT_KEY(CFE_SB_SendMsg), UT_SoftwareBusSnapshotHook, &HK_SnapshotData); @@ -2729,6 +2731,8 @@ void Test_Misc(void) /* Test housekeeping report with log disabled */ UT_InitData(); + CFE_SB_InitMsg((CFE_SB_Msg_t *) &CFE_EVS_GlobalData.EVS_TlmPkt, HK_SnapshotData.MsgId, + sizeof(CFE_EVS_GlobalData.EVS_TlmPkt), false); CFE_EVS_GlobalData.EVS_TlmPkt.Payload.LogEnabled = false; HK_SnapshotData.Count = 0; UT_SetHookFunction(UT_KEY(CFE_SB_SendMsg), UT_SoftwareBusSnapshotHook, &HK_SnapshotData); diff --git a/fsw/cfe-core/unit-test/tbl_UT.c b/fsw/cfe-core/unit-test/tbl_UT.c index 4164d8bd4..f1d3e4c2f 100644 --- a/fsw/cfe-core/unit-test/tbl_UT.c +++ b/fsw/cfe-core/unit-test/tbl_UT.c @@ -367,19 +367,17 @@ void Test_CFE_TBL_TaskInit(void) */ void Test_CFE_TBL_InitData(void) { - CFE_SB_MsgId_t MsgIdBuf[2]; - #ifdef UT_VERBOSE UT_Text("Begin Test Init Data\n"); #endif /* This function has only one possible path with no return code */ UT_InitData(); - UT_SetDataBuffer(UT_KEY(CFE_SB_SetMsgId), MsgIdBuf, sizeof(MsgIdBuf), false); CFE_TBL_InitData(); UT_Report(__FILE__, __LINE__, - CFE_SB_MsgId_Equal(MsgIdBuf[1], CFE_SB_ValueToMsgId(CFE_TBL_REG_TLM_MID)) && - UT_GetStubCount(UT_KEY(CFE_SB_SetMsgId)) == 2, + CFE_SB_MsgId_Equal(CFE_SB_GetMsgId((CFE_SB_Msg_t*)&CFE_TBL_TaskData.HkPacket), CFE_SB_ValueToMsgId(CFE_TBL_HK_TLM_MID)) && + CFE_SB_MsgId_Equal(CFE_SB_GetMsgId((CFE_SB_Msg_t*)&CFE_TBL_TaskData.TblRegPacket), CFE_SB_ValueToMsgId(CFE_TBL_REG_TLM_MID)) && + UT_GetStubCount(UT_KEY(CFE_SB_InitMsg)) == 2, "CFE_TBL_SearchCmdHndlrTbl", "Initialize data"); } diff --git a/fsw/cfe-core/unit-test/time_UT.c b/fsw/cfe-core/unit-test/time_UT.c index 4b8097cc6..f8d01854c 100644 --- a/fsw/cfe-core/unit-test/time_UT.c +++ b/fsw/cfe-core/unit-test/time_UT.c @@ -284,7 +284,7 @@ void Test_Init(void) ExpRtn++; CFE_TIME_EarlyInit(); UT_Report(__FILE__, __LINE__, - UT_GetStubCount(UT_KEY(CFE_SB_SetMsgId)) == ExpRtn, + UT_GetStubCount(UT_KEY(CFE_SB_InitMsg)) == ExpRtn, "CFE_TIME_EarlyInit", "Successful"); @@ -1904,6 +1904,8 @@ void Test_PipeCmds(void) /* Test sending the housekeeping telemetry request command */ UT_InitData(); + CFE_SB_InitMsg((CFE_SB_Msg_t *) &CFE_TIME_TaskData.HkPacket, LocalSnapshotData.MsgId, + sizeof(CFE_TIME_TaskData.HkPacket), false); UT_SetHookFunction(UT_KEY(CFE_SB_SendMsg), UT_SoftwareBusSnapshotHook, &LocalSnapshotData); UT_CallTaskPipe(CFE_TIME_TaskPipe, &CmdBuf.message, sizeof(CmdBuf.cmd), UT_TPID_CFE_TIME_SEND_HK); diff --git a/fsw/cfe-core/unit-test/ut_support.c b/fsw/cfe-core/unit-test/ut_support.c index f8fa5d153..56f73725f 100644 --- a/fsw/cfe-core/unit-test/ut_support.c +++ b/fsw/cfe-core/unit-test/ut_support.c @@ -232,8 +232,7 @@ void UT_CallTaskPipe(void (*TaskPipeFunc)(CFE_SB_MsgPtr_t), CFE_SB_MsgPtr_t Msg, * macros (not stubs) to read this info direct from * the buffer. */ - CCSDS_WR_LEN(Msg->Hdr, MsgSize); - CCSDS_WR_SHDR(Msg->Hdr, 1); + CFE_SB_SetTotalMsgLength(Msg, MsgSize); CFE_SB_SetMsgId(Msg, DispatchId.MsgId); CFE_SB_SetCmdCode(Msg, DispatchId.CommandCode); diff --git a/fsw/cfe-core/ut-stubs/ut_sb_stubs.c b/fsw/cfe-core/ut-stubs/ut_sb_stubs.c index 940543303..fe04a804e 100644 --- a/fsw/cfe-core/ut-stubs/ut_sb_stubs.c +++ b/fsw/cfe-core/ut-stubs/ut_sb_stubs.c @@ -36,6 +36,16 @@ #include "cfe.h" #include "utstubs.h" +typedef struct +{ + CFE_SB_MsgId_t MsgId; + uint16 Length; + uint16 CommandCode; + CFE_TIME_SysTime_t TimeStamp; + +} CFE_SB_StubMsg_MetaData_t; + + /* ** Global variables ** @@ -45,6 +55,27 @@ */ CFE_SB_Qos_t CFE_SB_Default_Qos; +static CFE_SB_StubMsg_MetaData_t* CFE_SB_StubMsg_GetMetaData(const CFE_SB_Msg_t *MsgPtr) +{ + CFE_SB_StubMsg_MetaData_t* MetaPtr; + CFE_SB_StubMsg_MetaData_t DefaultMeta; + uint32 MetaSize; + UT_EntryKey_t MsgKey = (UT_EntryKey_t)MsgPtr; + + UT_GetDataBuffer(MsgKey, (void**)&MetaPtr, &MetaSize, NULL); + if (MetaPtr == NULL || MetaSize != sizeof(DefaultMeta)) + { + memset(&DefaultMeta, 0, sizeof(DefaultMeta)); + DefaultMeta.MsgId = CFE_SB_INVALID_MSG_ID; + UT_ResetState(MsgKey); + UT_SetDataBuffer(MsgKey, &DefaultMeta, sizeof(DefaultMeta), true); + + /* Because "allocate copy" is true above, this gets a pointer to the copy */ + UT_GetDataBuffer(MsgKey, (void**)&MetaPtr, &MetaSize, NULL); + } + + return MetaPtr; +} /* ** Functions */ @@ -235,25 +266,26 @@ int32 CFE_SB_GetPipeIdByName(CFE_SB_PipeId_t *PipeIdPtr, const char *PipeName) ** None ** ** \returns -** Returns either the function code from command secondary header or -** CFE_SUCCESS. +** Returns either the function code from command secondary header or 0. ** ******************************************************************************/ uint16 CFE_SB_GetCmdCode(CFE_SB_MsgPtr_t MsgPtr) { int32 status; - CFE_SB_CmdHdr_t *CmdHdrPtr; + uint16 cmdcode = 0; status = UT_DEFAULT_IMPL(CFE_SB_GetCmdCode); - if (status == 0 && CCSDS_RD_TYPE(MsgPtr->Hdr) != CCSDS_TLM) + if (status != 0) + { + cmdcode = status; + } + else { - /* Cast the input pointer to a Cmd Msg pointer */ - CmdHdrPtr = (CFE_SB_CmdHdr_t *)MsgPtr; - status = CCSDS_RD_FC(CmdHdrPtr->Sec); + cmdcode = CFE_SB_StubMsg_GetMetaData(MsgPtr)->CommandCode; } - return status; + return cmdcode; } /*****************************************************************************/ @@ -273,39 +305,13 @@ uint16 CFE_SB_GetCmdCode(CFE_SB_MsgPtr_t MsgPtr) ******************************************************************************/ CFE_SB_MsgId_t CFE_SB_GetMsgId(const CFE_SB_Msg_t *MsgPtr) { - CFE_SB_MsgId_t Result = CFE_SB_INVALID_MSG_ID; - CFE_SB_MsgId_Atom_t MsgIdVal = 0; + CFE_SB_MsgId_t Result; UT_DEFAULT_IMPL(CFE_SB_GetMsgId); if (UT_Stub_CopyToLocal(UT_KEY(CFE_SB_GetMsgId), &Result, sizeof(Result)) < sizeof(Result)) { - -#ifndef MESSAGE_FORMAT_IS_CCSDS_VER_2 - MsgIdVal = CCSDS_RD_SID(MsgPtr->Hdr); -#else - - uint32 SubSystemId; - - MsgIdVal = CCSDS_RD_APID(MsgPtr->Hdr); /* Primary header APID */ - - if ( CCSDS_RD_TYPE(MsgPtr->Hdr) == CCSDS_CMD) - MsgIdVal = MsgIdVal | CFE_SB_CMD_MESSAGE_TYPE; - - /* Add in the SubSystem ID as needed */ - SubSystemId = CCSDS_RD_SUBSYSTEM_ID(MsgPtr->SpacePacket.ApidQ); - MsgIdVal = (MsgIdVal | (SubSystemId << 8)); - -/* Example code to add in the System ID as needed. */ -/* The default is to init this field to the Spacecraft ID but ignore for routing. */ -/* To fully implement this field would require significant SB optimization to avoid */ -/* prohibitively large routing and index tables. */ -/* uint16 SystemId; */ -/* SystemId = CCSDS_RD_SYSTEM_ID(HdrPtr->ApidQ); */ -/* MsgIdVal = (MsgIdVal | (SystemId << 16)) */ -#endif - Result = CFE_SB_ValueToMsgId(MsgIdVal); - + Result = CFE_SB_StubMsg_GetMetaData(MsgPtr)->MsgId; } return Result; @@ -337,11 +343,10 @@ void CFE_SB_InitMsg(void *MsgPtr, if (status >= 0) { - if (UT_Stub_CopyToLocal(UT_KEY(CFE_SB_InitMsg), (uint8*)MsgPtr, Length) < Length) - { - CFE_SB_SetMsgId(MsgPtr, MsgId); - CFE_SB_SetTotalMsgLength(MsgPtr, Length); - } + CFE_SB_StubMsg_GetMetaData(MsgPtr)->MsgId = MsgId; + CFE_SB_StubMsg_GetMetaData(MsgPtr)->Length = Length; + + UT_Stub_CopyToLocal(UT_KEY(CFE_SB_InitMsg), (uint8*)MsgPtr, Length); } } @@ -450,23 +455,12 @@ int32 CFE_SB_SendMsg(CFE_SB_Msg_t *MsgPtr) int32 CFE_SB_SetCmdCode(CFE_SB_MsgPtr_t MsgPtr, uint16 CmdCode) { int32 status; - CFE_SB_CmdHdr_t *CmdHdrPtr; status = UT_DEFAULT_IMPL(CFE_SB_SetCmdCode); - if (status >= 0) + if (status == 0) { - /* If msg type is telemetry, ignore the request */ - if (CCSDS_RD_TYPE(MsgPtr->Hdr) == CCSDS_TLM) - { - status = CFE_SB_WRONG_MSG_TYPE; - } - else - { - /* Cast the input pointer to a Cmd Msg pointer */ - CmdHdrPtr = (CFE_SB_CmdHdr_t *) MsgPtr; - CCSDS_WR_FC(CmdHdrPtr->Sec,CmdCode); - } + CFE_SB_StubMsg_GetMetaData(MsgPtr)->CommandCode = CmdCode; } return status; @@ -489,33 +483,15 @@ int32 CFE_SB_SetCmdCode(CFE_SB_MsgPtr_t MsgPtr, uint16 CmdCode) ******************************************************************************/ void CFE_SB_SetMsgId(CFE_SB_MsgPtr_t MsgPtr, CFE_SB_MsgId_t MsgId) { - UT_DEFAULT_IMPL(CFE_SB_SetMsgId); - UT_Stub_CopyFromLocal(UT_KEY(CFE_SB_SetMsgId), (uint8*)&MsgId, sizeof(MsgId)); - CFE_SB_MsgId_Atom_t MsgIdVal = CFE_SB_MsgIdToValue(MsgId); -#ifndef MESSAGE_FORMAT_IS_CCSDS_VER_2 - CCSDS_WR_SID(MsgPtr->Hdr, MsgIdVal); -#else - CCSDS_WR_VERS(MsgPtr->SpacePacket.Hdr, 1); - - /* Set the stream ID APID in the primary header. */ - CCSDS_WR_APID(MsgPtr->SpacePacket.Hdr, CFE_SB_RD_APID_FROM_MSGID(MsgIdVal) ); - - CCSDS_WR_TYPE(MsgPtr->SpacePacket.Hdr, CFE_SB_RD_TYPE_FROM_MSGID(MsgIdVal) ); - - - CCSDS_CLR_SEC_APIDQ(MsgPtr->SpacePacket.ApidQ); - - CCSDS_WR_EDS_VER(MsgPtr->SpacePacket.ApidQ, 1); - - CCSDS_WR_ENDIAN(MsgPtr->SpacePacket.ApidQ, CFE_PLATFORM_ENDIAN); - - CCSDS_WR_PLAYBACK(MsgPtr->SpacePacket.ApidQ, false); - - CCSDS_WR_SUBSYSTEM_ID(MsgPtr->SpacePacket.ApidQ, CFE_SB_RD_SUBSYS_ID_FROM_MSGID(MsgIdVal)); - - CCSDS_WR_SYSTEM_ID(MsgPtr->SpacePacket.ApidQ, CFE_SPACECRAFT_ID); - -#endif + int32 status; + + status = UT_DEFAULT_IMPL(CFE_SB_SetMsgId); + + if (status == 0) + { + UT_Stub_CopyFromLocal(UT_KEY(CFE_SB_SetMsgId), &MsgId, sizeof(MsgId)); + CFE_SB_StubMsg_GetMetaData(MsgPtr)->MsgId = MsgId; + } } @@ -540,6 +516,11 @@ int32 CFE_SB_SetMsgTime(CFE_SB_MsgPtr_t MsgPtr, CFE_TIME_SysTime_t time) status = UT_DEFAULT_IMPL(CFE_SB_SetMsgTime); + if (status == 0) + { + CFE_SB_StubMsg_GetMetaData(MsgPtr)->TimeStamp = time; + } + return status; } @@ -688,7 +669,7 @@ uint16 CFE_SB_GetTotalMsgLength(const CFE_SB_Msg_t *MsgPtr) } else { - result = CCSDS_RD_LEN(MsgPtr->Hdr); + result = CFE_SB_StubMsg_GetMetaData(MsgPtr)->Length; } return result; } @@ -824,8 +805,7 @@ CFE_TIME_SysTime_t CFE_SB_GetMsgTime(CFE_SB_MsgPtr_t MsgPtr) if (UT_Stub_CopyToLocal(UT_KEY(CFE_SB_GetMsgTime), &TimeFromMsg, sizeof(CFE_TIME_SysTime_t)) != sizeof(CFE_TIME_SysTime_t)) { - TimeFromMsg.Seconds = 123; - TimeFromMsg.Subseconds = 456; + TimeFromMsg = CFE_SB_StubMsg_GetMetaData(MsgPtr)->TimeStamp; } return TimeFromMsg; @@ -869,9 +849,15 @@ void *CFE_SB_GetUserData(CFE_SB_MsgPtr_t MsgPtr) void CFE_SB_SetTotalMsgLength (CFE_SB_MsgPtr_t MsgPtr,uint16 TotalLength) { - UT_DEFAULT_IMPL(CFE_SB_SetTotalMsgLength); - CCSDS_WR_LEN(MsgPtr->Hdr,TotalLength); - UT_Stub_CopyFromLocal(UT_KEY(CFE_SB_SetTotalMsgLength), &TotalLength, sizeof(TotalLength)); + int32 status; + + status = UT_DEFAULT_IMPL(CFE_SB_SetTotalMsgLength); + + if (status == 0) + { + UT_Stub_CopyFromLocal(UT_KEY(CFE_SB_SetTotalMsgLength), &TotalLength, sizeof(TotalLength)); + CFE_SB_StubMsg_GetMetaData(MsgPtr)->Length = TotalLength; + } } uint32 CFE_SB_GetPktType(CFE_SB_MsgId_t MsgId)