fsfw/src/fsfw/globalfunctions/Type.h

102 lines
2.5 KiB
C
Raw Normal View History

2020-12-14 11:10:22 +01:00
#ifndef FSFW_GLOBALFUNCTIONS_TYPE_H_
#define FSFW_GLOBALFUNCTIONS_TYPE_H_
2022-02-02 10:29:30 +01:00
#include <type_traits>
2022-08-16 12:48:22 +02:00
#include "fsfw/returnvalues/returnvalue.h"
2021-07-13 20:22:54 +02:00
#include "fsfw/serialize/SerializeIF.h"
2020-12-14 11:10:22 +01:00
/**
* @brief Type definition for CCSDS or ECSS.
*/
2022-02-02 10:29:30 +01:00
class Type : public SerializeIF {
public:
enum ActualType_t {
UINT8_T,
INT8_T,
UINT16_T,
INT16_T,
UINT32_T,
INT32_T,
FLOAT,
DOUBLE,
UNKNOWN_TYPE
};
2022-02-02 10:29:30 +01:00
Type();
2022-02-02 10:29:30 +01:00
Type(ActualType_t actualType);
2022-02-02 10:29:30 +01:00
Type(const Type &type);
2022-02-02 10:29:30 +01:00
Type &operator=(Type rhs);
2022-02-02 10:29:30 +01:00
Type &operator=(ActualType_t actualType);
2022-02-02 10:29:30 +01:00
operator ActualType_t() const;
2022-02-02 10:29:30 +01:00
bool operator==(const Type &rhs);
bool operator!=(const Type &rhs);
2022-02-02 10:29:30 +01:00
uint8_t getSize() const;
2022-02-02 10:29:30 +01:00
ReturnValue_t getPtcPfc(uint8_t *ptc, uint8_t *pfc) const;
2022-02-02 10:29:30 +01:00
static ActualType_t getActualType(uint8_t ptc, uint8_t pfc);
2022-02-02 10:29:30 +01:00
virtual ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize,
Endianness streamEndianness) const override;
2022-02-02 10:29:30 +01:00
virtual size_t getSerializedSize() const override;
2022-02-02 10:29:30 +01:00
virtual ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size,
Endianness streamEndianness) override;
2022-02-02 10:29:30 +01:00
private:
ActualType_t actualType;
};
2022-02-02 10:29:30 +01:00
template <typename T>
struct PodTypeConversion {
2022-02-02 10:29:30 +01:00
static_assert(not std::is_same<T, bool>::value,
"Do not use boolean for the PoolEntry type, use uint8_t "
"instead! The ECSS standard defines a boolean as a one bit "
"field. Therefore it is preferred to store a boolean as an "
"uint8_t");
static const Type::ActualType_t type = Type::UNKNOWN_TYPE;
};
2022-02-02 10:29:30 +01:00
template <>
struct PodTypeConversion<uint8_t> {
2022-02-02 10:29:30 +01:00
static const Type::ActualType_t type = Type::UINT8_T;
};
2022-02-02 10:29:30 +01:00
template <>
struct PodTypeConversion<uint16_t> {
2022-02-02 10:29:30 +01:00
static const Type::ActualType_t type = Type::UINT16_T;
};
2022-02-02 10:29:30 +01:00
template <>
struct PodTypeConversion<uint32_t> {
2022-02-02 10:29:30 +01:00
static const Type::ActualType_t type = Type::UINT32_T;
};
2022-02-02 10:29:30 +01:00
template <>
struct PodTypeConversion<int8_t> {
2022-02-02 10:29:30 +01:00
static const Type::ActualType_t type = Type::INT8_T;
};
2022-02-02 10:29:30 +01:00
template <>
struct PodTypeConversion<int16_t> {
2022-02-02 10:29:30 +01:00
static const Type::ActualType_t type = Type::INT16_T;
};
2022-02-02 10:29:30 +01:00
template <>
struct PodTypeConversion<int32_t> {
2022-02-02 10:29:30 +01:00
static const Type::ActualType_t type = Type::INT32_T;
};
2022-02-02 10:29:30 +01:00
template <>
struct PodTypeConversion<float> {
2022-02-02 10:29:30 +01:00
static const Type::ActualType_t type = Type::FLOAT;
};
2022-02-02 10:29:30 +01:00
template <>
struct PodTypeConversion<double> {
2022-02-02 10:29:30 +01:00
static const Type::ActualType_t type = Type::DOUBLE;
};
2020-12-14 11:10:22 +01:00
#endif /* FSFW_GLOBALFUNCTIONS_TYPE_H_ */