nasa / fprime

F´ - A flight software and embedded systems framework
https://fprime.jpl.nasa.gov
Apache License 2.0
10.02k stars 1.29k forks source link

Add serial ID to port definitions #2594

Open timcanham opened 5 months ago

timcanham commented 5 months ago
F´ Version 3.4.3
Affected Component n/a

Feature Description

Have the FPP code generator add a SERIALIZED_TYPE_ID field to ports and structs.

Rationale

This was an old feature idea to "harden" the port interfaces, especially when crossing through serialization interfaces like the Hub Pattern. If different ports that coincidentally have the same serialization size are connected to either side of the hub, the receiving port will deserialize the data and attempt to invoke the interface with incorrect data.

If a serialized ID that uniquely identifies the port type is added to the serialized data, the receiving port can check it to verify that it matches before invoking the component.

The original idea was to compute a 32-but hash based on the text contents of the XML (back before FPP). That should produce a value that would make it very unlikely that two different ports with the same serialization size would produce the same hash. A similar approach could be used for FPP port code generator files.

This same hash could be added to FPP generated structs so that users of those structs either onboard or in the ground system could confirm that the type matches.

This would add safety at the cost of some serialization data overhead. It could be a feature that is turned on or off in a project specific config file.