Skip to content

Commit

Permalink
Fix nasa#711, Added extended functions and minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
skliper committed Jun 10, 2020
1 parent 84569de commit a08b68c
Show file tree
Hide file tree
Showing 5 changed files with 300 additions and 12 deletions.
4 changes: 2 additions & 2 deletions fsw/cfe-core/src/inc/ccsds_hdr.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ typedef struct {
*/
typedef struct {

uint8 APIDQSubsystem[2]; /**< \brief subsystem qualifier */
uint8 Subsystem[2]; /**< \brief subsystem qualifier */
/* bits shift ------------ description ---------------- */
/* 0x01FF 0 : Subsystem Id mission defined */
/* 0x0200 9 : Playback flag 0 = original, 1 = playback */
/* 0x0400 10 : Endian: Big = 0, Little (Intel) = 1 */
/* 0xF800 11 : EDS Version for packet definition used */

uint8 APIDQSystemId[2]; /**< \brief system qualifier */
uint8 SystemId[2]; /**< \brief system qualifier */
/* 0xFFFF 0 : System Id mission defined */

} CCSDS_ExtendedHeader_t;
Expand Down
111 changes: 105 additions & 6 deletions fsw/cfe-core/src/msg/inc_public/cfe_msg_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,13 +294,13 @@ int32 CFE_MSG_SetSequenceCount(CFE_MSG_Message_t *MsgPtr, CFE_MSG_SequenceCount_
* This routine gets the message EDS version.
*
* \param[in] MsgPtr A pointer to the buffer that contains the message.
* \param[out] EDSVer EDS Version
* \param[out] Version EDS Version
*
* \return Execution status, see \ref CFEReturnCodes
* \retval #CFE_SUCCESS \copybrief CFE_SUCCESS
* \retval #CFE_MSG_BAD_ARGUMENT \copybrief CFE_MSG_BAD_ARGUMENT
*/
int32 CFE_MSG_GetEDSVer(const CFE_MSG_Message_t *MsgPtr, CFE_MSG_EDSVersion_t *EDSVer);
int32 CFE_MSG_GetEDSVersion(const CFE_MSG_Message_t *MsgPtr, CFE_MSG_EDSVersion_t *Version);

/*****************************************************************************/
/**
Expand All @@ -310,13 +310,13 @@ int32 CFE_MSG_GetEDSVer(const CFE_MSG_Message_t *MsgPtr, CFE_MSG_EDSVersion_t *E
* This routine sets the message EDS version.
*
* \param[in, out] MsgPtr A pointer to the buffer that contains the message.
* \param[in] EDSVer EDS Version
* \param[in] Version EDS Version
*
* \return Execution status, see \ref CFEReturnCodes
* \retval #CFE_SUCCESS \copybrief CFE_SUCCESS
* \retval #CFE_MSG_BAD_ARGUMENT \copybrief CFE_MSG_BAD_ARGUMENT
*/
int32 CFE_MSG_SetEDSVer(CFE_MSG_Message_t *MsgPtr, CFE_MSG_EDSVersion_t EDSVer);
int32 CFE_MSG_SetEDSVersion(CFE_MSG_Message_t *MsgPtr, CFE_MSG_EDSVersion_t Version);

/*****************************************************************************/
/**
Expand All @@ -339,7 +339,8 @@ int32 CFE_MSG_GetEndian(const CFE_MSG_Message_t *MsgPtr, CFE_MSG_Endian_t *Endia
* \brief Sets the message endian
*
* \par Description
* This routine sets the message endian.
* This routine sets the message endian. Invalid endian selection
* will set big endian.
*
* \param[in, out] MsgPtr A pointer to the buffer that contains the message.
* \param[in] Endian Endian
Expand All @@ -350,7 +351,105 @@ int32 CFE_MSG_GetEndian(const CFE_MSG_Message_t *MsgPtr, CFE_MSG_Endian_t *Endia
*/
int32 CFE_MSG_SetEndian(CFE_MSG_Message_t *MsgPtr, CFE_MSG_Endian_t Endian);

// TODO playback, subsystem, system
/*****************************************************************************/
/**
* \brief Gets the message playback flag
*
* \par Description
* This routine gets the message playback flag.
*
* \param[in] MsgPtr A pointer to the buffer that contains the message.
* \param[out] PlayFlag Playback Flag
*
* \return Execution status, see \ref CFEReturnCodes
* \retval #CFE_SUCCESS \copybrief CFE_SUCCESS
* \retval #CFE_MSG_BAD_ARGUMENT \copybrief CFE_MSG_BAD_ARGUMENT
*/
int32 CFE_MSG_GetPlaybackFlag(const CFE_MSG_Message_t *MsgPtr, CFE_MSG_PlaybackFlag_t *PlayFlag);

/*****************************************************************************/
/**
* \brief Sets the message playback flag
*
* \par Description
* This routine sets the message playback flag.
*
* \param[in, out] MsgPtr A pointer to the buffer that contains the message.
* \param[in] PlayFlag Playback Flag
*
* \return Execution status, see \ref CFEReturnCodes
* \retval #CFE_SUCCESS \copybrief CFE_SUCCESS
* \retval #CFE_MSG_BAD_ARGUMENT \copybrief CFE_MSG_BAD_ARGUMENT
*/
int32 CFE_MSG_SetPlaybackFlag(CFE_MSG_Message_t *MsgPtr, CFE_MSG_PlaybackFlag_t PlayFlag);

/*****************************************************************************/
/**
* \brief Gets the message subsystem
*
* \par Description
* This routine gets the message subsystem
*
* \param[in] MsgPtr A pointer to the buffer that contains the message.
* \param[out] Subsystem Subsystem
*
* \return Execution status, see \ref CFEReturnCodes
* \retval #CFE_SUCCESS \copybrief CFE_SUCCESS
* \retval #CFE_MSG_BAD_ARGUMENT \copybrief CFE_MSG_BAD_ARGUMENT
*/
int32 CFE_MSG_GetSubsystem(const CFE_MSG_Message_t *MsgPtr, CFE_MSG_Subsystem_t *Subsystem);

/*****************************************************************************/
/**
* \brief Sets the message subsystem
*
* \par Description
* This routine sets the message subsystem. Some bits may
* be set at initialization using the MsgId, but API available to set
* bits that may not be included in MsgId.
*
* \param[in, out] MsgPtr A pointer to the buffer that contains the message.
* \param[in] Subsystem Subsystem
*
* \return Execution status, see \ref CFEReturnCodes
* \retval #CFE_SUCCESS \copybrief CFE_SUCCESS
* \retval #CFE_MSG_BAD_ARGUMENT \copybrief CFE_MSG_BAD_ARGUMENT
*/
int32 CFE_MSG_SetSubsystem(CFE_MSG_Message_t *MsgPtr, CFE_MSG_Subsystem_t Subsystem);

/*****************************************************************************/
/**
* \brief Gets the message system
*
* \par Description
* This routine gets the message system id
*
* \param[in] MsgPtr A pointer to the buffer that contains the message.
* \param[out] System System
*
* \return Execution status, see \ref CFEReturnCodes
* \retval #CFE_SUCCESS \copybrief CFE_SUCCESS
* \retval #CFE_MSG_BAD_ARGUMENT \copybrief CFE_MSG_BAD_ARGUMENT
*/
int32 CFE_MSG_GetSystem(const CFE_MSG_Message_t *MsgPtr, CFE_MSG_System_t *System);

/*****************************************************************************/
/**
* \brief Sets the message system
*
* \par Description
* This routine sets the message system id. Some bits may
* be set at initialization using the MsgId, but API available to set
* bits that may not be included in MsgId.
*
* \param[in, out] MsgPtr A pointer to the buffer that contains the message.
* \param[in] System System
*
* \return Execution status, see \ref CFEReturnCodes
* \retval #CFE_SUCCESS \copybrief CFE_SUCCESS
* \retval #CFE_MSG_BAD_ARGUMENT \copybrief CFE_MSG_BAD_ARGUMENT
*/
int32 CFE_MSG_SetSystem(CFE_MSG_Message_t *MsgPtr, CFE_MSG_System_t System);

/*****************************************************************************/
/**
Expand Down
2 changes: 1 addition & 1 deletion fsw/cfe-core/src/msg/inc_public/cfe_msg_typedefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,6 @@ typedef enum
CFE_MSG_PlayFlag_Invalid, /**< \brief Invalid playback setting */
CFE_MSG_PlayFlag_Original, /**< \brief Original */
CFE_MSG_PlayFlag_Playback /**< \brief Playback */
} CFE_MSG_PlayFlag_t;
} CFE_MSG_PlaybackFlag_t;

#endif /* _cfe_msg_typedefs_ */
186 changes: 186 additions & 0 deletions fsw/cfe-core/src/msg/src/cfe_msg_ccsdsext.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,189 @@ void CFE_MSG_SetDefaultCCSDSExt(CFE_MSG_Message_t *MsgPtr)
CFE_MSG_SetSubsystem(MsgPtr, (CFE_MSG_Subsystem_t)CFE_PLATFORM_DEFAULT_SUBSYS);
CFE_MSB_SetSystem(MsgPtr, (CFE_MSG_System_t)CFE_MISSION_SPACECRAFT_ID);
}

/******************************************************************************
* Get message EDS version - See API and header file for details
*/
int32 CFE_MSG_GetEDSVersion(const CFE_MSG_Message_t *MsgPtr, CFE_MSG_EDSVersion_t *Version)
{

if (MsgPtr == NULL || Version == NULL)
{
return CFE_MSG_BAD_ARGUMENT;
}

CFE_MSG_GetHeaderField(MsgPtr->CCSDS.Ext.Subsystem, Version, CFE_MSG_EDSVER_MASK);
*Version >>= CFE_MSG_EDSVER_SHIFT;

return CFE_SUCCESS;
}

/******************************************************************************
* Set message EDS version - See API and header file for details
*/
int32 CFE_MSG_SetEDSVersion(CFE_MSG_Message_t *MsgPtr, CFE_MSG_EDSVersion_t Version)
{
Version <<= CFE_MSG_EDSVER_SHIFT;
if (MsgPtr == NULL || ((Version & CFE_MSG_EDSVER_MASK) != 0))
{
return CFE_MSG_BAD_ARGUMENT;
}

CFE_MSG_SetHeaderField(MsgPtr->CCSDS.Ext.Subsystem, Version, CFE_MSG_EDSVER_MASK);

return CFE_SUCCESS;
}

/******************************************************************************
* Get message endian - See API and header file for details
*/
int32 CFE_MSG_GetEndian(const CFE_MSG_Message_t *MsgPtr, CFE_MSG_Endian_t *Endian)
{

if (MsgPtr == NULL || Endian == NULL)
{
return CFE_MSG_BAD_ARGUMENT;
}

if ((MsgPtr->CCSDS.Ext.Subsystem[0] & (CFE_MSG_ENDIAN_MASK >> 8)) != 0)
{
*Endian = CFE_MSG_Endian_Little;
}
else
{
*Endian = CFE_MSG_Endian_Big;
}

return CFE_SUCCESS;
}

/******************************************************************************
* Set message endian - See API and header file for details
*/
int32 CFE_MSG_SetEndian(CFE_MSG_Message_t *MsgPtr, CFE_MSG_Endian_t Endian)
{
if (MsgPtr == NULL || Endian == CFE_MSG_Endian_Invalid)
{
return CFE_MSG_BAD_ARGUMENT;
}

if (Endian == CFE_MSG_Endian_Little)
{
MsgPtr->CCSDS.Ext.Subsystem[0] |= CFE_MSG_ENDIAN_MASK >> 8;
}
else
{
MsgPtr->CCSDS.Ext.Subsystem[0] &= ~(CFE_MSG_ENDIAN_MASK >> 8);
}

return CFE_SUCCESS;
}

/******************************************************************************
* Get message playback flag - See API and header file for details
*/
int32 CFE_MSG_GetPlaybackFlag(const CFE_MSG_Message_t *MsgPtr, CFE_MSG_PlaybackFlag_t *PlayFlag)
{

if (MsgPtr == NULL || PlayFlag == NULL)
{
return CFE_MSG_BAD_ARGUMENT;
}

if ((MsgPtr->CCSDS.Ext.Subsystem[0] & (CFE_MSG_PLAYBACK_MASK >> 8)) != 0)
{
*PlayFlag = CFE_MSG_PlayFlag_Playback;
}
else
{
*PlayFlag = CFE_MSG_PlayFlag_Original;
}

return CFE_SUCCESS;
}

/******************************************************************************
* Set message playback flag - See API and header file for details
*/
int32 CFE_MSG_SetPlaybackFlag(CFE_MSG_Message_t *MsgPtr, CFE_MSG_PlaybackFlag_t PlayFlag)
{
if (MsgPtr == NULL || PlayFlag == CFE_MSG_PlayFlag_Invalid)
{
return CFE_MSG_BAD_ARGUMENT;
}

if (PlayFlag == CFE_MSG_PlayFlag_Playback)
{
MsgPtr->CCSDS.Ext.Subsystem[0] |= CFE_MSG_PLAYBACK_MASK >> 8;
}
else
{
MsgPtr->CCSDS.Ext.Subsystem[0] &= ~(CFE_MSG_PLAYBACK_MASK >> 8);
}

return CFE_SUCCESS;
}

/******************************************************************************
* Get message subsystem - See API and header file for details
*/
int32 CFE_MSG_GetSubsystem(const CFE_MSG_Message_t *MsgPtr, CFE_MSG_Subsystem_t *Subsystem)
{

if (MsgPtr == NULL || Subsystem == NULL)
{
return CFE_MSG_BAD_ARGUMENT;
}

CFE_MSG_GetHeaderField(MsgPtr->CCSDS.Ext.Subsystem, Subsystem, CFE_MSG_SUBSYSTEM_MASK);

return CFE_SUCCESS;
}

/******************************************************************************
* Set message subsystem - See API and header file for details
*/
int32 CFE_MSG_SetSubsystem(CFE_MSG_Message_t *MsgPtr, CFE_MSG_Subsystem_t Subsystem)
{
if (MsgPtr == NULL || ((Subsystem & CFE_MSG_SUBSYSTEM_MASK) != 0))
{
return CFE_MSG_BAD_ARGUMENT;
}

CFE_MSG_SetHeaderField(MsgPtr->CCSDS.Ext.Subsystem, Subsystem, CFE_MSG_SUBSYSTEM_MASK);

return CFE_SUCCESS;
}

/******************************************************************************
* Get message system - See API and header file for details
*/
int32 CFE_MSG_GetSystem(const CFE_MSG_Message_t *MsgPtr, CFE_MSG_System_t *System)
{

if (MsgPtr == NULL || System == NULL)
{
return CFE_MSG_BAD_ARGUMENT;
}

*System = (MSGPtr->CCSDS.Ext.SystemId[0] << 8) + MsgPtr->CCSDS.Ext.SystemId[1];

return CFE_SUCCESS;
}

/******************************************************************************
* Set message system - See API and header file for details
*/
int32 CFE_MSG_SetSystem(CFE_MSG_Message_t *MsgPtr, CFE_MSG_System_t System)
{
if (MsgPtr == NULL)
{
return CFE_MSG_BAD_ARGUMENT;
}

MSGPtr->CCSDS.Ext.SystemId[0] = (System >> 8) & 0xFF;
MSGPtr->CCSDS.Ext.SystemId[1] = System & 0xFF;

return CFE_SUCCESS;
}
9 changes: 6 additions & 3 deletions fsw/cfe-core/src/msg/src/cfe_msg_ccsdspri.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ int32 CFE_MSG_GetType(const CFE_MSG_Message_t *MsgPtr, CFE_MSG_Type_t *Type)
return CFE_MSG_BAD_ARGUMENT;
}

if (MsgPtr->CCSDS.Pri.StreamId[0] & (CFE_MSG_TYPE_MASK >> 8))
if ((MsgPtr->CCSDS.Pri.StreamId[0] & (CFE_MSG_TYPE_MASK >> 8)) != 0)
{
*Type = CFE_MSG_Type_Cmd;
}
Expand All @@ -120,7 +120,7 @@ int32 CFE_MSG_GetType(const CFE_MSG_Message_t *MsgPtr, CFE_MSG_Type_t *Type)
*/
int32 CFE_MSG_SetType(CFE_MSG_Message_t *MsgPtr, CFE_MSG_Type_t Type)
{
if (MsgPtr == NULL)
if (MsgPtr == NULL || Type == CFE_MSG_Type_Invalid)
{
return CFE_MSG_BAD_ARGUMENT;
}
Expand Down Expand Up @@ -272,7 +272,10 @@ int32 CFE_MSG_SetSegmentationFlag(CFE_MSG_Message_t *MsgPtr, CFE_MSG_Segmentatio
status = CFE_MSG_BAD_ARGUMENT;
}

CFE_MSG_SetHeaderField(MsgPtr->CCSDS.Pri.Sequence, rawval, CFE_MSG_SEGFLG_MASK);
if (status == CFE_SUCCESS)
{
CFE_MSG_SetHeaderField(MsgPtr->CCSDS.Pri.Sequence, rawval, CFE_MSG_SEGFLG_MASK);
}

return status;
}
Expand Down

0 comments on commit a08b68c

Please sign in to comment.