Skip to content

Commit

Permalink
Fix #263, Expose CFE_SB_IsValidMsgId() API
Browse files Browse the repository at this point in the history
This also more properly defines the the CFE_SB_INVALID_MSG_ID macro for
external use going forward.
  • Loading branch information
jphickey committed Apr 15, 2020
1 parent 60a5f65 commit 537f9b8
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 15 deletions.
41 changes: 39 additions & 2 deletions fsw/cfe-core/src/inc/cfe_sb.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,30 @@
#define CFE_SB_SUBSCRIPTION 0 /**< \brief Subtype specifier used in #CFE_SB_SingleSubscriptionTlm_t by SBN App */
#define CFE_SB_UNSUBSCRIPTION 1 /**< \brief Subtype specified used in #CFE_SB_SingleSubscriptionTlm_t by SBN App */

#define CFE_SB_INVALID_MSG_ID 0xFFFF /**< \brief Initializer for #CFE_SB_MsgId_t values that will not match any real MsgId */
/* ------------------------------------------------------ */
/* Macro Constants for use with the CFE_SB_MsgId_t type */
/* ------------------------------------------------------ */

/**
* \brief Reserved value for CFE_SB_MsgId_t that will not match any valid MsgId
*
* This rvalue macro can be used for static/compile-time data initialization to ensure that
* the initialized value does not alias to a valid MsgId object.
*/
#define CFE_SB_MSGID_RESERVED ((CFE_SB_MsgId_t)(-1))

/**
* \brief A literal of the CFE_SB_MsgId_t type representing an invalid ID
*
* This value should be used for runtime initialization of CFE_SB_MsgId_t values.
*
* \note This may be a compound literal in a future revision. Per C99, compound
* literals are lvalues, not rvalues, so this value should not be used in
* static/compile-time data initialization. For static data initialization
* purposes (rvalue), #CFE_SB_MSGID_RESERVED should be used instead.
* However, in the current implementation, they are equivalent.
*/
#define CFE_SB_INVALID_MSG_ID CFE_SB_MSGID_RESERVED

/*
** Macro Definitions
Expand Down Expand Up @@ -1278,7 +1301,21 @@ bool CFE_SB_ValidateChecksum(CFE_SB_MsgPtr_t MsgPtr);

/*****************************************************************************/
/**
* \brief Identifies whether a two #CFE_SB_MsgId_t values are equal
* \brief Identifies whether a given CFE_SB_MsgId_t is valid
*
* \par Description
* Implements a basic sanity check on the value provided
*
* \return Boolean message ID validity indicator
* \retval true Message ID is within the valid range
* \retval false Message ID is not within the valid range
*/
bool CFE_SB_IsValidMsgId(CFE_SB_MsgId_t MsgId);


/*****************************************************************************/
/**
* \brief Identifies whether two #CFE_SB_MsgId_t values are equal
*
* \par Description
* In cases where the #CFE_SB_MsgId_t type is not a simple integer
Expand Down
12 changes: 12 additions & 0 deletions fsw/cfe-core/src/sb/cfe_sb_msg_id_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,15 @@ void CFE_SB_SetMsgId(CFE_SB_MsgPtr_t MsgPtr,

#endif
}/* end CFE_SB_SetMsgId */

/*
* Function: CFE_SB_IsValidMsgId - See API and header file for details
*/
bool CFE_SB_IsValidMsgId(CFE_SB_MsgId_t MsgId)
{
return (!CFE_SB_MsgId_Equal(MsgId, CFE_SB_INVALID_MSG_ID) &&
CFE_SB_MsgIdToValue(MsgId) <= CFE_SB_HIGHEST_VALID_MSGID);
} /* end CFE_SB_IsValidMsgId */



13 changes: 0 additions & 13 deletions fsw/cfe-core/src/sb/cfe_sb_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -472,19 +472,6 @@ extern cfe_sb_t CFE_SB;
* or use case is legitimate.
* --------------------------------------------------------- */

/**
* @brief Identifies whether a given CFE_SB_MsgId_t is valid
*
* Implements a basic sanity check on the value provided
*
* @returns true if sanity checks passed, false otherwise.
*/
static inline bool CFE_SB_IsValidMsgId(CFE_SB_MsgId_t MsgId)
{
/* cppcheck-suppress redundantCondition */
return (MsgId != CFE_SB_INVALID_MSG_ID && MsgId <= CFE_PLATFORM_SB_HIGHEST_VALID_MSGID);
}

/**
* @brief Identifies whether a given CFE_SB_MsgKey_t is valid
*
Expand Down

0 comments on commit 537f9b8

Please sign in to comment.