F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
FPrimeBasicTypes.hpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title Fw/FPrimeBasicTypes.hpp
3 // \author mstarch
4 // \brief hpp file for basic types used in F Prime
5 //
6 // \copyright
7 // Copyright 2025, by the California Institute of Technology.
8 // ALL RIGHTS RESERVED. United States Government Sponsorship
9 // acknowledged.
10 //
11 // FPrime defines a number of basic types, platform configurable types,
12 // and project configurable types. This file provides a single header
13 // users can import for using these types. It wraps the underlying C
14 // header in C-linkage to allow C++ users to include this header.
15 //
16 // ======================================================================
17 #ifndef FPRIME_BASIC_TYPES_HPP
18 #define FPRIME_BASIC_TYPES_HPP
19 #include <limits>
20 extern "C" {
21 #include <Fw/FPrimeBasicTypes.h>
22 }
23 #include <Fw/Types/BasicTypes.hpp>
24 // Needed for FwAssertTextSize
26 
27 // Define max length of assert string
28 // Note: This constant truncates file names in assertion failure event reports
29 #ifndef FW_ASSERT_TEXT_SIZE
30 #define FW_ASSERT_TEXT_SIZE \
31  FwAssertTextSize
32 #endif
33 
35 
36 // Check that Fw::String is big enough to hold any string that can be given a
37 // default value in FPP.
38 
39 static_assert(FW_FIXED_LENGTH_STRING_SIZE >= static_cast<FwSizeType>(FW_CMD_STRING_MAX_SIZE),
40  "A generic string should be able to hold a command string");
41 static_assert(FW_FIXED_LENGTH_STRING_SIZE >= static_cast<FwSizeType>(FW_LOG_STRING_MAX_SIZE),
42  "A generic string should be able to hold an event string");
43 static_assert(FW_FIXED_LENGTH_STRING_SIZE >= static_cast<FwSizeType>(FW_TLM_STRING_MAX_SIZE),
44  "A generic string should be able to hold a telemetry string");
45 static_assert(FW_FIXED_LENGTH_STRING_SIZE >= static_cast<FwSizeType>(FW_PARAM_STRING_MAX_SIZE),
46  "A generic string should be able to hold a parameter string");
47 
48 // Check that command/telemetry strings are not larger than an argument buffer
49 
50 static_assert(static_cast<FwSizeType>(FW_CMD_STRING_MAX_SIZE) + sizeof(FwSizeStoreType) <=
51  static_cast<FwSizeType>(FW_CMD_ARG_BUFFER_MAX_SIZE),
52  "FW_CMD_STRING_MAX_SIZE cannot be larger than FW_CMD_ARG_BUFFER_MAX_SIZE");
53 static_assert(static_cast<FwSizeType>(FW_LOG_STRING_MAX_SIZE) + sizeof(FwSizeStoreType) <=
54  static_cast<FwSizeType>(FW_LOG_BUFFER_MAX_SIZE),
55  "FW_LOG_STRING_MAX_SIZE cannot be larger than FW_LOG_BUFFER_MAX_SIZE");
56 static_assert(static_cast<FwSizeType>(FW_TLM_STRING_MAX_SIZE) + sizeof(FwSizeStoreType) <=
57  static_cast<FwSizeType>(FW_TLM_BUFFER_MAX_SIZE),
58  "FW_TLM_STRING_MAX_SIZE cannot be larger than FW_TLM_BUFFER_MAX_SIZE");
59 static_assert(static_cast<FwSizeType>(FW_PARAM_STRING_MAX_SIZE) + sizeof(FwSizeStoreType) <=
60  static_cast<FwSizeType>(FW_PARAM_BUFFER_MAX_SIZE),
61  "FW_PARAM_STRING_MAX_SIZE cannot be larger than FW_PARAM_BUFFER_MAX_SIZE");
62 
63 // Text logging needs the code generator for serializables to generate a stringified version of the
64 // value.
65 static_assert((FW_ENABLE_TEXT_LOGGING == 0) || (FW_SERIALIZABLE_TO_STRING != 0),
66  "FW_SERIALIZABLE_TO_STRING must be enabled to enable FW_ENABLE_TEXT_LOGGING");
67 
68 // Unit testing needs serializable strings
69 #ifdef BUILD_UT
70 static_assert(FW_SERIALIZABLE_TO_STRING != 0, "FW_SERIALIZABLE_TO_STRING must be enabled for unit testing");
71 #endif
72 
73 static_assert(std::numeric_limits<FwBuffSizeType>::max() == std::numeric_limits<FwSizeStoreType>::max() &&
75  "FwBuffSizeType must be equivalent to FwExternalSizeType");
76 
77 static_assert(std::numeric_limits<FwSizeType>::max() >= std::numeric_limits<FwSizeStoreType>::max() &&
79  "FwSizeType cannot entirely store values of type FwExternalSizeType");
80 
81 // Check platform defined types for required invariants
82 static_assert(sizeof(PlatformPointerCastType) == sizeof(void*),
83  "PlatformPointerCastType must be the same size as pointers");
84 static_assert(std::numeric_limits<PlatformSizeType>::max() >= std::numeric_limits<unsigned int>::max(),
85  "PlatformSizeType must be at least as large as unsigned int");
86 static_assert(std::numeric_limits<PlatformSignedSizeType>::max() >= std::numeric_limits<int>::max(),
87  "PlatformSignedSizeType must be at least as large as int");
89  "PlatformSignedSizeType must be at least as small as int");
90 static_assert(std::numeric_limits<PlatformIndexType>::is_signed, "PlatformIndexType must be signed");
91 static_assert(not std::numeric_limits<PlatformSizeType>::is_signed, "PlatformSizeType must be unsigned");
92 static_assert(std::numeric_limits<PlatformSignedSizeType>::is_signed, "PlatformSignedSizeType must be signed");
93 static_assert(std::numeric_limits<PlatformSizeType>::max() >= std::numeric_limits<U32>::max(),
94  "PlatformSizeType must be at least as large as U32");
95 static_assert(sizeof(PlatformSizeType) == sizeof(PlatformSignedSizeType),
96  "PlatformSizeType must be the same size as PlatformSignedSizeType");
97 
98 // Check framework configured types for required invariants
99 static_assert(std::numeric_limits<FwSizeType>::max() >= std::numeric_limits<unsigned int>::max(),
100  "FwSizeType must be at least as large as unsigned int");
101 static_assert(std::numeric_limits<FwSignedSizeType>::max() >= std::numeric_limits<int>::max(),
102  "FwSignedSizeType must be at least as large as int");
104  "FwSignedSizeType must be at least as large as int");
105 static_assert(std::numeric_limits<FwIndexType>::is_signed, "FwIndexType must be signed");
106 static_assert(not std::numeric_limits<FwSizeType>::is_signed, "FwSizeType must be unsigned");
107 static_assert(std::numeric_limits<FwSignedSizeType>::is_signed, "FwSignedSizeType must be signed");
108 static_assert(std::numeric_limits<FwSizeType>::max() >= std::numeric_limits<U32>::max(),
109  "FwSizeType must be at least as large as U32");
110 static_assert(sizeof(FwSizeType) == sizeof(FwSignedSizeType), "FwSizeType must be the same size as FwSignedSizeType");
111 
112 #endif // FW_TYPES_HPP
#define FW_ENABLE_TEXT_LOGGING
Indicates whether text logging is turned on.
Definition: FpConfig.h:150
PlatformSizeType FwSizeType
#define FW_SERIALIZABLE_TO_STRING
Indicates if autocoded serializables have toString() methods.
Definition: FpConfig.h:156
PlatformSignedSizeType FwSignedSizeType
U16 FwSizeStoreType
The type used to serialize a size value.
static U32 min(const U32 a, const U32 b)
Definition: Checksum.cpp:16
C++ header for working with basic fprime types.