Skip to content

Commit

Permalink
Fix #85, updates to struct/typedef names
Browse files Browse the repository at this point in the history
Implements a bit of paradigm shift in how names of symbols/types are
generated, relying on prefixes rather than suffixes.  Using suffixes
has an opportunity of name collisions that is not possible when using
prefixes.

A separate typedef file maps to the existing type names and thus keeps
it compatible with existing code, but only if that typedef file is used.
  • Loading branch information
jphickey committed Feb 29, 2024
1 parent cf06166 commit 147dc08
Show file tree
Hide file tree
Showing 35 changed files with 1,177 additions and 785 deletions.
30 changes: 15 additions & 15 deletions cfecfs/eds2cfetbl/eds2cfetbl.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@
#include "cfe_tbl_filedef.h"
#include "cfe_mission_eds_parameters.h"
#include "cfe_mission_eds_interface_parameters.h"
#include "cfe_tbl_eds_typedefs.h"
#include "cfe_fs_eds_typedefs.h"
#include "cfe_sb_eds_typedefs.h"
#include "cfe_tbl_eds_datatypes.h"
#include "cfe_fs_eds_datatypes.h"
#include "cfe_sb_eds_datatypes.h"
#include "edslib_lua_objects.h"
#include "cfe_missionlib_lua_softwarebus.h"
#include "cfe_missionlib_runtime.h"
Expand All @@ -88,10 +88,10 @@ EdsTableTool_Global_t EdsTableTool_Global;
* This calls the same impl that CFE FSW uses
*
*-----------------------------------------------------------------*/
CFE_SB_MsgIdValue_Atom_t CFE_SB_CmdTopicIdToMsgId(uint16_t TopicId, uint16_t InstanceNum)
EdsDataType_CFE_SB_MsgIdValue_t CFE_SB_CmdTopicIdToMsgId(uint16_t TopicId, uint16_t InstanceNum)
{
const CFE_SB_Listener_Component_t Params = {{ .InstanceNumber = InstanceNum, .TopicId = TopicId }};
CFE_SB_SoftwareBus_PubSub_Interface_t Output;
const EdsComponent_CFE_SB_Listener_t Params = {{ .InstanceNumber = InstanceNum, .TopicId = TopicId }};
EdsInterface_CFE_SB_SoftwareBus_PubSub_t Output;

CFE_MissionLib_MapListenerComponent(&Output, &Params);

Expand All @@ -104,10 +104,10 @@ CFE_SB_MsgIdValue_Atom_t CFE_SB_CmdTopicIdToMsgId(uint16_t TopicId, uint16_t Ins
* This calls the same impl that CFE FSW uses
*
*-----------------------------------------------------------------*/
CFE_SB_MsgIdValue_Atom_t CFE_SB_TlmTopicIdToMsgId(uint16_t TopicId, uint16_t InstanceNum)
EdsDataType_CFE_SB_MsgIdValue_t CFE_SB_TlmTopicIdToMsgId(uint16_t TopicId, uint16_t InstanceNum)
{
const CFE_SB_Publisher_Component_t Params = {{ .InstanceNumber = InstanceNum, .TopicId = TopicId }};
CFE_SB_SoftwareBus_PubSub_Interface_t Output;
const EdsComponent_CFE_SB_Publisher_t Params = {{ .InstanceNumber = InstanceNum, .TopicId = TopicId }};
EdsInterface_CFE_SB_SoftwareBus_PubSub_t Output;

CFE_MissionLib_MapPublisherComponent(&Output, &Params);

Expand Down Expand Up @@ -182,8 +182,8 @@ void LoadTemplateFile(lua_State *lua, const char *Filename)
int obj_idx;
size_t RuntimeAppNameLen;
CFE_TBL_FileDef_t *CFE_TBL_FileDefPtr;
BASE_TYPES_ApiName_String_t RuntimeAppName;
BASE_TYPES_ApiName_String_t TableName;
EdsDataType_BASE_TYPES_ApiName_t RuntimeAppName;
EdsDataType_BASE_TYPES_ApiName_t TableName;
const char *EdsAppName;
size_t EdsAppNameLen;
char EdsTypeName[64];
Expand Down Expand Up @@ -551,11 +551,11 @@ int Write_CFE_EnacapsulationFile(lua_State *lua)
{
union
{
CFE_FS_Header_t FileHeader;
CFE_TBL_File_Hdr_t TblHeader;
EdsDataType_CFE_FS_Header_t FileHeader;
EdsDataType_CFE_TBL_File_Hdr_t TblHeader;
} Buffer;
CFE_FS_Header_PackedBuffer_t PackedFileHeader;
CFE_TBL_File_Hdr_PackedBuffer_t PackedTblHeader;
EdsPackedBuffer_CFE_FS_Header_t PackedFileHeader;
EdsPackedBuffer_CFE_TBL_File_Hdr_t PackedTblHeader;
uint32_t TblHeaderBlockSize;
uint32_t FileHeaderBlockSize;
EdsLib_Id_t PackedEdsId;
Expand Down
14 changes: 7 additions & 7 deletions cfecfs/eds2cfetbl/scripts/eds_tbltool_filedef.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,34 @@
#include <stdint.h>
#include <stddef.h>

#include <cfe_sb_eds_typedefs.h>
#include <cfe_sb_eds_datatypes.h>

CFE_SB_MsgIdValue_Atom_t CFE_SB_CmdTopicIdToMsgId(uint16_t TopicId, uint16_t InstanceNum);
CFE_SB_MsgIdValue_Atom_t CFE_SB_TlmTopicIdToMsgId(uint16_t TopicId, uint16_t InstanceNum);
EdsDataType_CFE_SB_MsgIdValue_t CFE_SB_CmdTopicIdToMsgId(uint16_t TopicId, uint16_t InstanceNum);
EdsDataType_CFE_SB_MsgIdValue_t CFE_SB_TlmTopicIdToMsgId(uint16_t TopicId, uint16_t InstanceNum);

uint16_t EdsTableTool_GetProcessorId(void);
void EdsTableTool_DoExport(void *arg, const void *filedefptr, const void *obj, size_t sz);


static inline CFE_SB_MsgIdValue_Atom_t CFE_SB_GlobalCmdTopicIdToMsgId(uint16_t TopicId)
static inline EdsDataType_CFE_SB_MsgIdValue_t CFE_SB_GlobalCmdTopicIdToMsgId(uint16_t TopicId)
{
/* Instance number 0 is used for globals */
return CFE_SB_CmdTopicIdToMsgId(TopicId, 0);
}

static inline CFE_SB_MsgIdValue_Atom_t CFE_SB_GlobalTlmTopicIdToMsgId(uint16_t TopicId)
static inline EdsDataType_CFE_SB_MsgIdValue_t CFE_SB_GlobalTlmTopicIdToMsgId(uint16_t TopicId)
{
/* Instance number 0 is used for globals */
return CFE_SB_TlmTopicIdToMsgId(TopicId, 0);
}

static inline CFE_SB_MsgIdValue_Atom_t CFE_SB_LocalCmdTopicIdToMsgId(uint16_t TopicId)
static inline EdsDataType_CFE_SB_MsgIdValue_t CFE_SB_LocalCmdTopicIdToMsgId(uint16_t TopicId)
{
/* PSP-reported Instance number is used for locals */
return CFE_SB_CmdTopicIdToMsgId(TopicId, EdsTableTool_GetProcessorId());
}

static inline CFE_SB_MsgIdValue_Atom_t CFE_SB_LocalTlmTopicIdToMsgId(uint16_t TopicId)
static inline EdsDataType_CFE_SB_MsgIdValue_t CFE_SB_LocalTlmTopicIdToMsgId(uint16_t TopicId)
{
/* PSP-reported Instance number is used for locals */
return CFE_SB_TlmTopicIdToMsgId(TopicId, EdsTableTool_GetProcessorId());
Expand Down
60 changes: 50 additions & 10 deletions cfecfs/edsmsg/fsw/inc/cfe_msg_hdr_eds.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include "cfe_msg_api_typedefs.h"

/* In this build the structure definitions come from EDS */
#include "cfe_hdr_eds_typedefs.h"
#include "cfe_hdr_eds_datatypes.h"

/*
* Macro Definitions
Expand All @@ -54,7 +54,7 @@
* Implemented as a macro, so it should work with both Command and Telemetry headers.
*
* In the EDS version it goes through a "void*" type, so as to not trigger alias warnings, however
* all MSG-related structs must all begin with an actual instance of CFE_HDR_Message_t for
* all MSG-related structs must all begin with an actual instance of CFE_MSG_Message_t for
* this to be valid/safe. All EDS-generated message structures meet this requirement because
* they all (eventually) derive from this base type, but any hand-written struct could be incorrect,
* and unfortunately will not trigger an error when using void* cast.
Expand Down Expand Up @@ -83,6 +83,20 @@
* Type Definitions
*/

/*
* The header size should be aligned to the largest possible type on the system.
* This is so conventional struct definitions will not add extra padding between
* the header and the payload. Specifically, there is still padding, but it will
* be reflected in sizeof(CFE_MSG_CommandHeader) as opposed simply existing as
* a gap between the header and payload.
*/
union CFE_EDSMSG_Align
{
uintmax_t AlignInt; /**< alignment for largest native integer */
void * AlignPtr; /**< alignment for pointers */
double AlignDbl; /**< alignment for double-precision float */
};

/**********************************************************************
* Structure definitions for full header
*
Expand All @@ -95,17 +109,28 @@
*
* This provides the definition of CFE_MSG_Message_t
*/
union CFE_MSG_Message
struct CFE_MSG_Message
{
/**
* EDS-defined base message structure
*/
CFE_HDR_Message_t BaseMsg;
EdsDataType_CFE_HDR_Message_t BaseMsg;
};

/**
* \brief Aligned command header
*
* Df
*/
union CFE_EDSMSG_CommandHeader_Aligned
{
/**
* \brief Byte level access
* EDS-defined command header structure
*/
uint8 Byte[sizeof(CFE_HDR_Message_t)];
EdsDataType_CFE_HDR_CommandHeader_t HeaderData;

/* Member for alignment (unused in code) */
union CFE_EDSMSG_Align Align;
};

/**
Expand All @@ -114,11 +139,24 @@ union CFE_MSG_Message
* This provides the definition of CFE_MSG_CommandHeader_t
*/
struct CFE_MSG_CommandHeader
{
union CFE_EDSMSG_CommandHeader_Aligned Content;
};

/**
* \brief cFS telemetry header
*
* This provides the definition of CFE_MSG_TelemetryHeader_t
*/
union CFE_EDSMSG_TelemetryHeader_Aligned
{
/**
* EDS-defined command header structure
* EDS-defined telemetry header structure
*/
CFE_HDR_CommandHeader_t HeaderData;
EdsDataType_CFE_HDR_TelemetryHeader_t HeaderData;

/* Member for alignment (unused in code) */
union CFE_EDSMSG_Align Align;
};

/**
Expand All @@ -131,9 +169,10 @@ struct CFE_MSG_TelemetryHeader
/**
* EDS-defined telemetry header structure
*/
CFE_HDR_TelemetryHeader_t HeaderData;
union CFE_EDSMSG_TelemetryHeader_Aligned Content;
};

#ifdef jphfix
/**
* Helper function to cast an arbitrary base pointer to a CFE_MSG_Message_t* for use with SB APIs
*/
Expand All @@ -142,9 +181,10 @@ static inline CFE_MSG_Message_t *CFE_MSG_CastBaseMsg(void *BaseMsg)
/*
* In a pedantic sense, this is "promoting" the base message pointer to the
* union type. This should not be an actual violation though, as the union
* contains a CFE_HDR_Message_t member.
* contains a CFE_MSG_Message_t member.
*/
return ((CFE_MSG_Message_t *)BaseMsg);
}
#endif

#endif /* CFE_MSG_HDR_EDS_H */
Loading

0 comments on commit 147dc08

Please sign in to comment.