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

(WIP) Trivial header redefine #721

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions cmake/mission_build.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ function(prepare)
endif (SIMULATION)

# Generate the cfe_mission_cfg.h wrapper file
generate_config_includefile("inc/cfe_mission_custom.h" mission_custom.h ${MISSIONCONFIG})
generate_config_includefile("inc/cfe_mission_cfg.h" mission_cfg.h ${MISSIONCONFIG})
generate_config_includefile("inc/cfe_perfids.h" perfids.h ${MISSIONCONFIG} )

Expand Down
2 changes: 1 addition & 1 deletion cmake/sample_defs/sample_mission_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
** MESSAGE_FORMAT_IS_CCSDS_VER_2 is optional
*/
/* #define MESSAGE_FORMAT_IS_CCSDS_VER_2 */
#undef MESSAGE_FORMAT_IS_CCSDS_VER_2
#define MESSAGE_FORMAT_IS_CUSTOM
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would we need a compile time switch for custom/not custom header format? Every mission needs one (and only one) defined message format. It should just be "the selected message format".

I assume "not custom" means the traditional CCSDS v1 with CFE-defined secondary headers, using the 6-byte TLM header? Does that mean every user who wants v2/extended header needs to enable this "custom" switch?

I'd rather see something where the user just specifies one specific header format, by name. If that happens to be one that CFE provides out of the box, then great. Otherwise the user will have to provide an implementation to go with their selection.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You want to break everyone's config if they don't define version 1? We certainly can take that approach if it's preferred. I went with minimizing impacts (it works just like default (v1), define for V2 as before, but adds an additional IS_CUSTOM).

Could also have unique typedefs for each option, and just define as a common name here. Is that what you are asking for?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it doesn't break existing config because it can be done on the CMake side. If CMake needs to do some sort of source selection based on the header format then CMake needs to know what the user wants, so it can select the files appropriately.

So it would work just like anything else - CMake has a default, which is used if the user does nothing, and if the user sets something then it uses that.

Besides that, even if it was only in the C header file, it's just a matter of putting the default value into the sample file. (but again, setting in the value via CMake is totally backward compatible provided we give a default)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it could certainly be done multiple ways and I was hoping for a CMake related update (per the design suggestions I provided) but I haven't seen progress on that front in line with our allotted schedule. Given that, I made these trivial changes that also work to redefine the header. This is certainly not meant as the perfect solution, it's just a trivial solution that works so I can still make schedule if a better solution is not complete in time.




Expand Down
18 changes: 18 additions & 0 deletions cmake/sample_defs/sample_mission_custom.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* Mission custom command and telemetry packet headers */
#include "ccsds.h"

typedef struct
{
CCSDS_SpacePacket_t SpacePacket; /**< \brief Standard Header on all packets */
CCSDS_CmdSecHdr_t Sec;
uint32 customfield;
} CCSDS_CommandPacket_t;

/*----- Generic combined telemetry header. -----*/

typedef struct
{
CCSDS_SpacePacket_t SpacePacket; /**< \brief Standard Header on all packets */
CCSDS_TlmSecHdr_t Sec;
} CCSDS_TelemetryPacket_t;

4 changes: 4 additions & 0 deletions fsw/cfe-core/src/inc/ccsds.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ typedef struct



#ifdef MESSAGE_FORMAT_IS_CUSTOM
#include "cfe_mission_custom.h" /* Should resolve/refactor to avoid including mid-file */
#else
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the "cfe_mission_custom.h" file needs to exist regardless, couldn't it just be generated to always have the "right" content in it (i.e. the user-selected format) and not have to introduce yet another preprocessor switch?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it doesn't? Did you try it? Works exactly like before (remove the file, don't define a format and it's V1, define V2 and it works also... I confirmed it. Only needs to exist if you want to redefine.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point is that you've called generate_config_includefile() function to create cfe_mission_custom.h .... but in the event that there is no config here the file will just be empty.

So why would we want to generate an empty file and then selectively ignore it? It would be simpler, cleaner to just generate the file with the right content. No #ifdef's or parallel settings required - just include the generated header file, and it has the right content.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also note that the whole generate_config_includefile stuff was originally for backward compatibility with the classic build where things were configured via header file. While that is still largely the case for CFE because it generally works, there are better methods of doing this in CMake (i.e. how we updated OSAL/osconfig.h recently). It isn't really a method I'd suggest for new development.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree 100% with adopting the source selection and CMake techniques implemented in OSAL. I have suggested that approach multiple times, but it hasn't seemed to have resonated with the group. For the previous comment - because it works with no impacts on previous configurations. There's certainly a trade to be made (it can certainly be implemented either way), I'll leave it up to @jwilmot @acudmore since the long term open source solution would help from architecture guidance.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well since we already have both (CMake config file + C headers) in use my recommendation is to favor the CMake method for new development, because it covers both areas (build + code).

That is, we can control the build and also easily generate a synchronized C header from the CMake variables to influence the actual code. Using a strictly C header approach is more limiting, as it is not really possible to go the other way, so the information isn't available to CMake for build/source selection.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And I continue to agree 100% on improving this to utilize CMake instead of defines in c headers. It was the solution I was hoping for and was trying to encourage.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do still prefer the core framework implements the basic two formats in the code such that it's covered by cppcheck (I'm not a fan of moving the supported header definitions into sample_defs and generating, but that's a trade we can discuss), but I definitely prefer using CMake to do the configuration work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My point is I don't want users to think they can redefine what version 1 and 2 means (could be implied by moving the definition to sample_defs). I'd rather control those in the core code.

/*----- Generic combined command header. -----*/

typedef struct
Expand All @@ -199,6 +202,7 @@ typedef struct
CCSDS_SpacePacket_t SpacePacket; /**< \brief Standard Header on all packets */
CCSDS_TlmSecHdr_t Sec;
} CCSDS_TelemetryPacket_t;
#endif

/*
* COMPATIBILITY TYPEDEFS:
Expand Down