Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #2519, Add runtime TopicId conversion routines to SB #2520

Merged
merged 1 commit into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 127 additions & 0 deletions modules/core_api/fsw/inc/cfe_sb.h
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,133 @@ static inline CFE_SB_MsgId_t CFE_SB_ValueToMsgId(CFE_SB_MsgId_Atom_t MsgIdValue)
CFE_SB_MsgId_t Result = CFE_SB_MSGID_C(MsgIdValue);
return Result;
}

/*****************************************************************************/
/**
* \brief Converts a topic ID and instance number combination into a MsgID value integer
*
* \par Description
* This function accepts a data pair of topic ID + instance number and returns the
* corresponding MsgID Value (integer) for commands.
*
* \par Assumptions and Notes:
* A topic ID identifies a certain data stream from an application, for example
* the CFE Software bus ground commands (CFE_MISSION_SB_CMD_TOPICID). In
* contrast to MsgID, the topic ID is consistent across all CPUs in a system, whereas
* each CPU instance will have a unique MsgID.
*
* CPU instance numbers are 1-based. The instance number of 0 is reserved
* for "global" MsgID values that are the same on all CPUs. The PSP function
* may be used to obtain the current CPU number for the host processor.
*
* \sa CFE_SB_TlmTopicIdToMsgId(), CFE_PSP_GetProcessorId()
*
* \return Integer representation of the #CFE_SB_MsgId_t
*/
CFE_SB_MsgId_Atom_t CFE_SB_CmdTopicIdToMsgId(uint16 TopicId, uint16 InstanceNum);

/*****************************************************************************/
/**
* \brief Converts a topic ID and instance number combination into a MsgID value integer
*
* \par Description
* This function accepts a data pair of topic ID + instance number and returns the
* corresponding MsgID Value (integer) for telemetry.
*
* \par Assumptions and Notes:
* A topic ID identifies a certain data stream from an application, for example
* the CFE Software bus housekeeping telemetry (CFE_MISSION_SB_HK_TLM_TOPICID). In
* contrast to MsgID, the topic ID is consistent across all CPUs in a system, whereas
* each CPU instance will have a unique MsgID.
*
* CPU instance numbers are 1-based. The instance number of 0 is reserved
* for "global" MsgID values that are the same on all CPUs. The PSP function
* may be used to obtain the current CPU number for the host processor.
*
* \sa CFE_SB_CmdTopicIdToMsgId(), CFE_PSP_GetProcessorId()
*
* \return Integer representation of the #CFE_SB_MsgId_t
*/
CFE_SB_MsgId_Atom_t CFE_SB_TlmTopicIdToMsgId(uint16 TopicId, uint16 InstanceNum);

/*****************************************************************************/
/**
* \brief Converts a topic ID to a MsgID value integer for Global commands
*
* \par Description
* This is a wrapper around CFE_SB_CmdTopicIdToMsgId() for topic IDs which
* are the same on all CPUs within a system (i.e. not specific to a certain
* processor)
*
* \par Assumptions and Notes:
* Global MsgIDs may be used when only a single instance of a service exists
* within the system. The CFE framework does not use this feature for commands,
* but is defined for future use.
*
* \sa CFE_SB_CmdTopicIdToMsgId(), CFE_SB_LocalCmdTopicIdToMsgId()
*
* \return Integer representation of the #CFE_SB_MsgId_t
*/
CFE_SB_MsgId_Atom_t CFE_SB_GlobalCmdTopicIdToMsgId(uint16 TopicId);

/*****************************************************************************/
/**
* \brief Converts a topic ID to a MsgID value integer for Global telemetry
*
* \par Description
* This is a wrapper around CFE_SB_TlmTopicIdToMsgId() for topic IDs which
* are the same on all CPUs within a system (i.e. not specific to a certain
* processor)
*
* \par Assumptions and Notes:
* Global MsgIDs may be used when only a single instance of a service exists
* within the system. An example for such telemetry is the time synchronization
* service published by CFE_TIME.
*
* \sa CFE_SB_TlmTopicIdToMsgId(), CFE_SB_LocalTlmTopicIdToMsgId()
*
* \return Integer representation of the #CFE_SB_MsgId_t
*/
CFE_SB_MsgId_Atom_t CFE_SB_GlobalTlmTopicIdToMsgId(uint16 TopicId);

/*****************************************************************************/
/**
* \brief Converts a topic ID to a MsgID value integer for local commands
*
* \par Description
* This is a wrapper around CFE_SB_CmdTopicIdToMsgId() for topic IDs which
* are unique on all CPUs within a system (i.e. specific to a certain
* processor)
*
* \par Assumptions and Notes:
* This assumes the caller is referring to a service running on the same
* processor instance as itself.
*
* \sa CFE_SB_CmdTopicIdToMsgId(), CFE_SB_LocalTlmTopicIdToMsgId()
*
* \return Integer representation of the #CFE_SB_MsgId_t
*/
CFE_SB_MsgId_Atom_t CFE_SB_LocalCmdTopicIdToMsgId(uint16 TopicId);

/*****************************************************************************/
/**
* \brief Converts a topic ID to a MsgID value integer for local telemetry
*
* \par Description
* This is a wrapper around CFE_SB_TlmTopicIdToMsgId() for topic IDs which
* are unique on all CPUs within a system (i.e. specific to a certain
* processor)
*
* \par Assumptions and Notes:
* This assumes the caller is referring to a service running on the same
* processor instance as itself.
*
* \sa CFE_SB_TlmTopicIdToMsgId(), CFE_SB_LocalCmdTopicIdToMsgId()
*
* \return Integer representation of the #CFE_SB_MsgId_t
*/
CFE_SB_MsgId_Atom_t CFE_SB_LocalTlmTopicIdToMsgId(uint16 TopicId);

/** @} */

#endif /* CFE_SB_H */
5 changes: 3 additions & 2 deletions modules/core_api/ut-stubs/src/cfe_config_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,11 @@
* Generated stub function for CFE_Config_GetVersionString()
* ----------------------------------------------------
*/
void CFE_Config_GetVersionString(char *Buf, size_t Size, const char *Component, const char *SrcVersion, const char *CodeName, const char *LastOffcRel)
void CFE_Config_GetVersionString(char *Buf, size_t Size, const char *Component, const char *SrcVersion,

Check notice

Code scanning / CodeQL-coding-standard

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.
const char *CodeName, const char *LastOffcRel)
{
UT_GenStub_AddParam(CFE_Config_GetVersionString, char *, Buf);
UT_GenStub_AddParam(CFE_Config_GetVersionString, size_t , Size);
UT_GenStub_AddParam(CFE_Config_GetVersionString, size_t, Size);
UT_GenStub_AddParam(CFE_Config_GetVersionString, const char *, Component);
UT_GenStub_AddParam(CFE_Config_GetVersionString, const char *, SrcVersion);
UT_GenStub_AddParam(CFE_Config_GetVersionString, const char *, CodeName);
Expand Down
139 changes: 139 additions & 0 deletions modules/core_api/ut-stubs/src/cfe_sb_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,149 @@

return MetaPtr;
}

/*------------------------------------------------------------
*
* Helper function to fabricate a MsgID value for testing purposes
*
* Note this is not intended to match a real MsgID value used in flight
* software builds, it is just for UT. The fabricated value just needs
* to pass the "CFE_SB_IsValidMsgId()" test.
*
*------------------------------------------------------------*/
static void UT_CFE_SB_FabricateMsgIdValue(UT_EntryKey_t FuncKey, bool IsCmd, uint16 TopicId, uint16 InstanceNum)

Check notice

Code scanning / CodeQL-coding-standard

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.
{
CFE_SB_MsgId_Atom_t MsgIdValue;

/* This makes the bits line up with the "traditional" use of the first 16
* bits of a CCSDS space packet as a MsgId */
MsgIdValue = 1;
if (IsCmd)
{
MsgIdValue |= 2;
}
MsgIdValue <<= 4;
MsgIdValue |= InstanceNum & 0xF;
MsgIdValue <<= 7;
MsgIdValue |= TopicId & 0x7F;

UT_Stub_SetReturnValue(FuncKey, MsgIdValue);
}

/*
** Functions
*/

/*------------------------------------------------------------
*
* Default handler for CFE_SB_LocalCmdTopicIdToMsgId coverage stub function
*
*------------------------------------------------------------*/
void UT_DefaultHandler_CFE_SB_LocalCmdTopicIdToMsgId(void *UserObj, UT_EntryKey_t FuncKey,
const UT_StubContext_t *Context)
{
uint16 TopicId;

if (!UT_Stub_GetInt32StatusCode(Context, NULL))

Check warning

Code scanning / CodeQL-coding-standard

Side effect in a Boolean expression Warning

This Boolean expression is not side-effect free.
{
TopicId = UT_Hook_GetArgValueByName(Context, "TopicId", uint16);

UT_CFE_SB_FabricateMsgIdValue(FuncKey, true, TopicId, 1);
}
}

/*------------------------------------------------------------
*
* Default handler for CFE_SB_LocalTlmTopicIdToMsgId coverage stub function
*
*------------------------------------------------------------*/
void UT_DefaultHandler_CFE_SB_LocalTlmTopicIdToMsgId(void *UserObj, UT_EntryKey_t FuncKey,
const UT_StubContext_t *Context)
{
uint16 TopicId;

if (!UT_Stub_GetInt32StatusCode(Context, NULL))

Check warning

Code scanning / CodeQL-coding-standard

Side effect in a Boolean expression Warning

This Boolean expression is not side-effect free.
{
TopicId = UT_Hook_GetArgValueByName(Context, "TopicId", uint16);

UT_CFE_SB_FabricateMsgIdValue(FuncKey, false, TopicId, 1);
}
}

/*------------------------------------------------------------
*
* Default handler for CFE_SB_GlobalCmdTopicIdToMsgId coverage stub function
*
*------------------------------------------------------------*/
void UT_DefaultHandler_CFE_SB_GlobalCmdTopicIdToMsgId(void *UserObj, UT_EntryKey_t FuncKey,
const UT_StubContext_t *Context)
{
uint16 TopicId;

if (!UT_Stub_GetInt32StatusCode(Context, NULL))

Check warning

Code scanning / CodeQL-coding-standard

Side effect in a Boolean expression Warning

This Boolean expression is not side-effect free.
{
TopicId = UT_Hook_GetArgValueByName(Context, "TopicId", uint16);

UT_CFE_SB_FabricateMsgIdValue(FuncKey, true, TopicId, 0);
}
}

/*------------------------------------------------------------
*
* Default handler for CFE_SB_GlobalTlmTopicIdToMsgId coverage stub function
*
*------------------------------------------------------------*/
void UT_DefaultHandler_CFE_SB_GlobalTlmTopicIdToMsgId(void *UserObj, UT_EntryKey_t FuncKey,
const UT_StubContext_t *Context)
{
uint16 TopicId;

if (!UT_Stub_GetInt32StatusCode(Context, NULL))

Check warning

Code scanning / CodeQL-coding-standard

Side effect in a Boolean expression Warning

This Boolean expression is not side-effect free.
{
TopicId = UT_Hook_GetArgValueByName(Context, "TopicId", uint16);

UT_CFE_SB_FabricateMsgIdValue(FuncKey, false, TopicId, 0);
}
}

/*------------------------------------------------------------
*
* Default handler for CFE_SB_CmdTopicIdToMsgId coverage stub function
*
*------------------------------------------------------------*/
void UT_DefaultHandler_CFE_SB_CmdTopicIdToMsgId(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context)

Check notice

Code scanning / CodeQL-coding-standard

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.
{
uint16 TopicId;
uint16 InstanceNum;

if (!UT_Stub_GetInt32StatusCode(Context, NULL))

Check warning

Code scanning / CodeQL-coding-standard

Side effect in a Boolean expression Warning

This Boolean expression is not side-effect free.
{
TopicId = UT_Hook_GetArgValueByName(Context, "TopicId", uint16);
InstanceNum = UT_Hook_GetArgValueByName(Context, "InstanceNum", uint16);

UT_CFE_SB_FabricateMsgIdValue(FuncKey, true, TopicId, InstanceNum);
}
}

/*------------------------------------------------------------
*
* Default handler for CFE_SB_TlmTopicIdToMsgId coverage stub function
*
*------------------------------------------------------------*/
void UT_DefaultHandler_CFE_SB_TlmTopicIdToMsgId(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context)

Check notice

Code scanning / CodeQL-coding-standard

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.
{
uint16 TopicId;
uint16 InstanceNum;

if (!UT_Stub_GetInt32StatusCode(Context, NULL))

Check warning

Code scanning / CodeQL-coding-standard

Side effect in a Boolean expression Warning

This Boolean expression is not side-effect free.
{
TopicId = UT_Hook_GetArgValueByName(Context, "TopicId", uint16);
InstanceNum = UT_Hook_GetArgValueByName(Context, "InstanceNum", uint16);

UT_CFE_SB_FabricateMsgIdValue(FuncKey, false, TopicId, InstanceNum);
}
}

/*------------------------------------------------------------
*
* Default handler for CFE_SB_CreatePipe coverage stub function
Expand Down
Loading
Loading