Back to Fprime

Data Structures and Types

docs/user-manual/overview/05-enum-arr-ser.md

4.2.26.0 KB
Original Source

Data Structures and Types

This guide will describe the types available in F´. F´ defines both useful short names for primitive types as well as a set of autocoded complex types. The types described here are available to both the flight software and the ground system unless otherwise noted. Included in this document:

Primitive Types

F´ provides convenient type names for C/C++ primitive types. These are established to simplify the writing of F´ code across multiple systems as well as give an exact definition for each variable used. These types are described in the following table and are available to both the ground system, events, channels, and commands, and the software itself.

F´ TypeC/C++ TypeDescription
BOOLboolC++ boolean
I8int8_tsigned 8-bit integer
I16int16_tsigned 16-bit integer
I32int32_tsigned 32-bit integer
I64int64_tsigned 64-bit integer
U8uint8_tunsigned 8-bit integer
U16uint16_tunsigned 16-bit integer
U32uint32_tunsigned 32-bit integer
U64uint64_tunsigned 64-bit integer
F32float32-bit floating point
F64double64-bit floating point

[!NOTE] For a full description of numerical types available to F´ see: Numerical Types.

[!NOTE] C/C++ types come from stdint.h and stdbool.h. The last three types above are not of set size but are architecture-dependent. Should a project's architecture not support all these types, see: Configuring F´: Architecture Supported Primitive Types

Polymorphic Type

F´ defines a type for use by the user that can represent any of the primitive types using the same storage space. This is similar to a C union defined with fields of each above type.

Setting Polymorphic Values

The PolyType object can have a value assigned to it via the constructor or the equals operator:

PolyType myInt(123)
PolyType myFloat;
myFloat = 123.03

Getting Polymorphic Values

The value stored in the PolyType object can be retrieved in two ways:

  1. Cast the object to the type of the value:
U32 val = (U32)pt;
  1. Use the get() method:
U32 val;
pt.get(val);

In both cases, if the type being retrieved does not match the stored type, the code will assert.

Checking Polymorphic Values

The PolyType instance has isXXX functions for checking what type is being stored, where XXX is the name of the type.

PolyType p(123);
if (p.isU32()) {
    ...
}

Complex Types

The F´ framework supports several types of auto-generated complex types that can be used in the system, including use in software, command, event, and channel types, and even with the F´ ground system. These types are:

  1. Enums: defined enumeration of values
  2. Arrays: fixed-length containers of other types
  3. Serializable: defined composition of other types akin to a C++ struct/class

These can all be designed and used in the modeling of F´ and the C++ implementation is autogenerated.

Enums

Enums are a fixed set of values that can be referred to by name, but are stored and transmitted as an integer type. The auto-generator produces a class to wrap the type providing convenience functions.

Arrays

Arrays are fixed-length containers of other types. They must be type-homogeneous but can store any other single type.

Serializables

Serializables are field-value compositions of other types. They can be type-heterogeneous and may contain any other type as a value. The autocoder will generate a class with accessor methods for the fields.

C++ Classes

When interacting only in the software and not within the F´ design layer, nor with the ground system the user may use arbitrary C++ class/struct types. If these types are to be passed through a port invocation as an argument, they should be defined as subclasses of the Fw::Serializable and define serializeTo and deserializeFrom methods to be called to perform the serialization.

Specifically, user-defined serializable classes must implement the following methods, which operate on the Fw::SerialBufferBase interface and support selectable endianness (default: big-endian):

cpp
Fw::SerializeStatus serializeTo(Fw::SerialBufferBase& buffer,
                                Fw::Endianness mode = Fw::Endianness::BIG) const;

Fw::SerializeStatus deserializeFrom(Fw::SerialBufferBase& buffer,
                                    Fw::Endianness mode = Fw::Endianness::BIG);

Notes:

  • Fw::SerialBufferBase is the abstract buffer interface accepted by Fw::Serializable APIs. Concrete buffers such as Fw::SerializeBufferBase and helper wrappers like Fw::ExternalSerializeBufferWithMemberCopy implement this interface.
  • Endianness defaults to Fw::Endianness::BIG (network byte order). Pass Fw::Endianness::LITTLE to serialize or deserialize fields in little-endian.

Alias Types

Alias types provide an alternate name for a type that is defined elsewhere. An alias type can refer to any type, including another alias type (excluding itself).

Alias types are designed and used in the modeling of F´ and the C++ implementation is autogenerated.

Conclusion

F´ supports many different types, including autocoded complex types.