Merge remote-tracking branch 'origin/development' into mueller/refactor-tmtc-stack
fsfw/fsfw/pipeline/pr-development There was a failure building this commit Details

This commit is contained in:
Robin Müller 2022-08-15 19:05:50 +02:00
commit d7ec04bf4b
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
16 changed files with 175 additions and 128 deletions

View File

@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
# [unreleased]
## Added
- Add new `UnsignedByteField` class
# [v5.0.0] 25.07.2022
## Changes

View File

@ -118,6 +118,12 @@ option(FSFW_ADD_INTERNAL_TESTS "Add internal unit tests" ON)
option(FSFW_ADD_UNITTESTS "Add regular unittests. Requires Catch2" OFF)
option(FSFW_ADD_HAL "Add Hardware Abstraction Layer" ON)
if(UNIX)
option(FSFW_HAL_LINUX_ADD_PERIPHERAL_DRIVERS "Add Linux peripheral drivers"
OFF)
option(FSFW_HAL_LINUX_ADD_LIBGPIOD "Attempt to add Linux GPIOD drivers" OFF)
endif()
# Optional sources
option(FSFW_ADD_PUS "Compile with PUS sources" ON)
option(FSFW_ADD_MONITORING "Compile with monitoring components" ON)
@ -183,7 +189,10 @@ if(FSFW_BUILD_TESTS)
endif()
endif()
message(STATUS "${MSG_PREFIX} Finding and/or providing ETL library")
message(
STATUS
"${MSG_PREFIX} Finding and/or providing etl library with version ${FSFW_ETL_LIB_MAJOR_VERSION}"
)
# Check whether the user has already installed ETL first
find_package(${FSFW_ETL_LIB_NAME} ${FSFW_ETL_LIB_MAJOR_VERSION} QUIET)
@ -191,7 +200,7 @@ find_package(${FSFW_ETL_LIB_NAME} ${FSFW_ETL_LIB_MAJOR_VERSION} QUIET)
if(NOT ${FSFW_ETL_LIB_NAME}_FOUND)
message(
STATUS
"No ETL installation was found with find_package. Installing and providing "
"${MSG_PREFIX} No ETL installation was found with find_package. Installing and providing "
"etl with FindPackage")
include(FetchContent)

View File

@ -16,7 +16,7 @@
* This is the typedef for object identifiers.
* @ingroup system_objects
*/
typedef uint32_t object_id_t;
using object_id_t = uint32_t;
/**
* This interface allows a class to be included in the object manager

View File

@ -75,7 +75,6 @@ class EndianConverter {
}
#elif BYTE_ORDER_SYSTEM == BIG_ENDIAN
memcpy(out, in, size);
return;
#endif
}
@ -112,7 +111,6 @@ class EndianConverter {
for (size_t count = 0; count < size; count++) {
out[size - count - 1] = in[count];
}
return;
#elif BYTE_ORDER_SYSTEM == LITTLE_ENDIAN
memcpy(out, in, size);
#endif

View File

@ -68,13 +68,6 @@ class SerializeIF {
size_t maxSize) const {
return serialize(buffer, size, maxSize, SerializeIF::Endianness::NETWORK);
}
/**
* If endianness is not explicitly specified, use machine endianness
*/
[[nodiscard]] virtual ReturnValue_t serialize(uint8_t **buffer, size_t *size,
size_t maxSize) const {
return serialize(buffer, size, maxSize, SerializeIF::Endianness::MACHINE);
}
/**
* Gets the size of a object if it would be serialized in a buffer
@ -110,12 +103,6 @@ class SerializeIF {
virtual ReturnValue_t deSerializeBe(const uint8_t **buffer, size_t *size) {
return deSerialize(buffer, size, SerializeIF::Endianness::NETWORK);
}
/**
* If endianness is not explicitly specified, use machine endianness
*/
virtual ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size) {
return deSerialize(buffer, size, SerializeIF::Endianness::MACHINE);
}
/**
* Helper method which can be used if serialization should be performed without any additional
@ -139,13 +126,6 @@ class SerializeIF {
size_t maxSize) const {
return serialize(buffer, serLen, maxSize, SerializeIF::Endianness::NETWORK);
}
/**
* If endianness is not explicitly specified, use machine endianness
*/
[[nodiscard]] virtual ReturnValue_t serialize(uint8_t *buffer, size_t &serLen,
size_t maxSize) const {
return serialize(buffer, serLen, maxSize, SerializeIF::Endianness::MACHINE);
}
/**
* Helper methods which can be used if deserialization should be performed without any additional
@ -168,12 +148,6 @@ class SerializeIF {
virtual ReturnValue_t deSerializeBe(const uint8_t *buffer, size_t &deserSize, size_t maxSize) {
return deSerialize(buffer, deserSize, maxSize, SerializeIF::Endianness::NETWORK);
}
/**
* If endianness is not explicitly specified, use machine endianness
*/
virtual ReturnValue_t deSerialize(const uint8_t *buffer, size_t &deserSize, size_t maxSize) {
return deSerialize(buffer, deserSize, maxSize, SerializeIF::Endianness::MACHINE);
}
};
#endif /* FSFW_SERIALIZE_SERIALIZEIF_H_ */

View File

@ -0,0 +1,52 @@
#ifndef FSFW_UTIL_UNSIGNEDBYTEFIELD_H
#define FSFW_UTIL_UNSIGNEDBYTEFIELD_H
#include "fsfw/serialize.h"
template<typename T>
class UnsignedByteField: public SerializeIF {
public:
static_assert(std::is_unsigned<T>::value);
explicit UnsignedByteField(T value): value(value) {}
[[nodiscard]] ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize,
Endianness streamEndianness) const override {
return SerializeAdapter::serialize(&value, buffer, size, maxSize, streamEndianness);
}
ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size,
Endianness streamEndianness) override {
return SerializeAdapter::deSerialize(&value, buffer, size, streamEndianness);
}
[[nodiscard]] size_t getSerializedSize() const override {
return sizeof(T);
}
[[nodiscard]] T getValue() const {
return value;
}
void setValue(T value_) {
value = value_;
}
private:
T value;
};
class U32ByteField: public UnsignedByteField<uint32_t> {
public:
explicit U32ByteField(uint32_t value): UnsignedByteField<uint32_t>(value) {}
};
class U16ByteField: public UnsignedByteField<uint16_t> {
public:
explicit U16ByteField(uint16_t value): UnsignedByteField<uint16_t>(value) {}
};
class U8ByteField: public UnsignedByteField<uint8_t> {
public:
explicit U8ByteField(uint8_t value): UnsignedByteField<uint8_t>(value) {}
};
#endif // FSFW_UTIL_UNSIGNEDBYTEFIELD_H

View File

@ -286,26 +286,22 @@ ReturnValue_t MgmLIS3MDLHandler::interpretDeviceReply(DeviceCommandId_t id, cons
PoolReadGuard readHelper(&dataset);
if (readHelper.getReadResult() == HasReturnvaluesIF::RETURN_OK) {
if (std::abs(mgmX) > absLimitX or std::abs(mgmY) > absLimitY or
std::abs(mgmZ) > absLimitZ) {
dataset.fieldStrengths.setValid(false);
}
if (std::abs(mgmX) < absLimitX) {
dataset.fieldStrengthX = mgmX;
dataset.fieldStrengthX.setValid(true);
} else {
dataset.fieldStrengthX.setValid(false);
dataset.fieldStrengths[0] = mgmX;
}
if (std::abs(mgmY) < absLimitY) {
dataset.fieldStrengthY = mgmY;
dataset.fieldStrengthY.setValid(true);
} else {
dataset.fieldStrengthY.setValid(false);
dataset.fieldStrengths[1] = mgmY;
}
if (std::abs(mgmZ) < absLimitZ) {
dataset.fieldStrengthZ = mgmZ;
dataset.fieldStrengthZ.setValid(true);
} else {
dataset.fieldStrengthZ.setValid(false);
dataset.fieldStrengths[2] = mgmZ;
}
dataset.fieldStrengths.setValid(true);
}
break;
}
@ -468,10 +464,9 @@ void MgmLIS3MDLHandler::modeChanged(void) { internalState = InternalState::STATE
ReturnValue_t MgmLIS3MDLHandler::initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
LocalDataPoolManager &poolManager) {
localDataPoolMap.emplace(MGMLIS3MDL::FIELD_STRENGTH_X, new PoolEntry<float>({0.0}));
localDataPoolMap.emplace(MGMLIS3MDL::FIELD_STRENGTH_Y, new PoolEntry<float>({0.0}));
localDataPoolMap.emplace(MGMLIS3MDL::FIELD_STRENGTH_Z, new PoolEntry<float>({0.0}));
localDataPoolMap.emplace(MGMLIS3MDL::TEMPERATURE_CELCIUS, new PoolEntry<float>({0.0}));
localDataPoolMap.emplace(MGMLIS3MDL::FIELD_STRENGTHS, &mgmXYZ);
localDataPoolMap.emplace(MGMLIS3MDL::TEMPERATURE_CELCIUS, &temperature);
poolManager.subscribeForPeriodicPacket(dataset.getSid(), false, 10.0, false);
return HasReturnvaluesIF::RETURN_OK;
}

View File

@ -103,6 +103,8 @@ class MgmLIS3MDLHandler : public DeviceHandlerBase {
CommunicationStep communicationStep = CommunicationStep::DATA;
bool commandExecuted = false;
PoolEntry<float> mgmXYZ = PoolEntry<float>(3);
PoolEntry<float> temperature = PoolEntry<float>();
/*------------------------------------------------------------------------*/
/* Device specific commands and variables */
/*------------------------------------------------------------------------*/

View File

@ -309,9 +309,8 @@ void MgmRM3100Handler::modeChanged(void) { internalState = InternalState::NONE;
ReturnValue_t MgmRM3100Handler::initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
LocalDataPoolManager &poolManager) {
localDataPoolMap.emplace(RM3100::FIELD_STRENGTH_X, new PoolEntry<float>({0.0}));
localDataPoolMap.emplace(RM3100::FIELD_STRENGTH_Y, new PoolEntry<float>({0.0}));
localDataPoolMap.emplace(RM3100::FIELD_STRENGTH_Z, new PoolEntry<float>({0.0}));
localDataPoolMap.emplace(RM3100::FIELD_STRENGTHS, &mgmXYZ);
poolManager.subscribeForPeriodicPacket(primaryDataset.getSid(), false, 10.0, false);
return HasReturnvaluesIF::RETURN_OK;
}
@ -354,9 +353,9 @@ ReturnValue_t MgmRM3100Handler::handleDataReadout(const uint8_t *packet) {
// TODO: Sanity check on values?
PoolReadGuard readGuard(&primaryDataset);
if (readGuard.getReadResult() == HasReturnvaluesIF::RETURN_OK) {
primaryDataset.fieldStrengthX = fieldStrengthX;
primaryDataset.fieldStrengthY = fieldStrengthY;
primaryDataset.fieldStrengthZ = fieldStrengthZ;
primaryDataset.fieldStrengths[0] = fieldStrengthX;
primaryDataset.fieldStrengths[1] = fieldStrengthY;
primaryDataset.fieldStrengths[2] = fieldStrengthZ;
primaryDataset.setValidity(true, true);
}
return RETURN_OK;

View File

@ -85,6 +85,7 @@ class MgmRM3100Handler : public DeviceHandlerBase {
bool goToNormalModeAtStartup = false;
uint32_t transitionDelay;
PoolEntry<float> mgmXYZ = PoolEntry<float>(3);
ReturnValue_t handleCycleCountConfigCommand(DeviceCommandId_t deviceCommand,
const uint8_t *commandData, size_t commandDataLen);

View File

@ -139,12 +139,7 @@ static const uint8_t CTRL_REG5_DEFAULT = 0;
static const uint32_t MGM_DATA_SET_ID = READ_CONFIG_AND_DATA;
enum MgmPoolIds : lp_id_t {
FIELD_STRENGTH_X,
FIELD_STRENGTH_Y,
FIELD_STRENGTH_Z,
TEMPERATURE_CELCIUS
};
enum MgmPoolIds : lp_id_t { FIELD_STRENGTHS, TEMPERATURE_CELCIUS };
class MgmPrimaryDataset : public StaticLocalDataSet<4> {
public:
@ -152,9 +147,10 @@ class MgmPrimaryDataset : public StaticLocalDataSet<4> {
MgmPrimaryDataset(object_id_t mgmId) : StaticLocalDataSet(sid_t(mgmId, MGM_DATA_SET_ID)) {}
lp_var_t<float> fieldStrengthX = lp_var_t<float>(sid.objectId, FIELD_STRENGTH_X, this);
lp_var_t<float> fieldStrengthY = lp_var_t<float>(sid.objectId, FIELD_STRENGTH_Y, this);
lp_var_t<float> fieldStrengthZ = lp_var_t<float>(sid.objectId, FIELD_STRENGTH_Z, this);
/**
* Field strenghts in uT
*/
lp_vec_t<float, 3> fieldStrengths = lp_vec_t<float, 3>(sid.objectId, FIELD_STRENGTHS, this);
lp_var_t<float> temperature = lp_var_t<float>(sid.objectId, TEMPERATURE_CELCIUS, this);
};

View File

@ -101,11 +101,7 @@ class CycleCountCommand : public SerialLinkedListAdapter<SerializeIF> {
static constexpr uint32_t MGM_DATASET_ID = READ_DATA;
enum MgmPoolIds : lp_id_t {
FIELD_STRENGTH_X,
FIELD_STRENGTH_Y,
FIELD_STRENGTH_Z,
};
enum MgmPoolIds : lp_id_t { FIELD_STRENGTHS };
class Rm3100PrimaryDataset : public StaticLocalDataSet<3> {
public:
@ -113,10 +109,10 @@ class Rm3100PrimaryDataset : public StaticLocalDataSet<3> {
Rm3100PrimaryDataset(object_id_t mgmId) : StaticLocalDataSet(sid_t(mgmId, MGM_DATASET_ID)) {}
// Field strengths in micro Tesla.
lp_var_t<float> fieldStrengthX = lp_var_t<float>(sid.objectId, FIELD_STRENGTH_X, this);
lp_var_t<float> fieldStrengthY = lp_var_t<float>(sid.objectId, FIELD_STRENGTH_Y, this);
lp_var_t<float> fieldStrengthZ = lp_var_t<float>(sid.objectId, FIELD_STRENGTH_Z, this);
/**
* Field strenghts in uT
*/
lp_vec_t<float, 3> fieldStrengths = lp_vec_t<float, 3>(sid.objectId, FIELD_STRENGTHS, this);
};
} // namespace RM3100

View File

@ -15,6 +15,7 @@ add_subdirectory(mocks)
add_subdirectory(action)
add_subdirectory(power)
add_subdirectory(util)
add_subdirectory(container)
add_subdirectory(osal)
add_subdirectory(serialize)

View File

@ -76,37 +76,6 @@ TEST_CASE("Serialize IF Serialize", "[serialize-if-ser]") {
CHECK(buf[2] == 3);
CHECK(serLen == 3);
}
SECTION("Machine Endian Implicit") {
REQUIRE(simpleSer.SerializeIF::serialize(&ptr, &len, buf.size()) ==
HasReturnvaluesIF::RETURN_OK);
CHECK(buf[0] == 1);
#if BYTE_ORDER_SYSTEM == LITTLE_ENDIAN
CHECK(buf[1] == 3);
CHECK(buf[2] == 2);
#else
CHECK(buf[1] == 2);
CHECK(buf[2] == 3);
#endif
// Verify pointer arithmetic and size increment
CHECK(ptr == buf.data() + 3);
CHECK(len == 3);
}
SECTION("Machine Endian Simple Implicit") {
size_t serLen = 0xff;
REQUIRE(simpleSer.SerializeIF::serialize(buf.data(), serLen, buf.size()) ==
HasReturnvaluesIF::RETURN_OK);
CHECK(buf[0] == 1);
#if BYTE_ORDER_SYSTEM == LITTLE_ENDIAN
CHECK(buf[1] == 3);
CHECK(buf[2] == 2);
#else
CHECK(buf[1] == 2);
CHECK(buf[2] == 3);
#endif
CHECK(serLen == 3);
}
}
TEST_CASE("SerializeIF Deserialize", "[serialize-if-de]") {
@ -172,30 +141,4 @@ TEST_CASE("SerializeIF Deserialize", "[serialize-if-de]") {
CHECK(simpleSer.getU16() == 1);
CHECK(deserLen == 3);
}
SECTION("Machine Endian Implicit") {
REQUIRE(simpleSer.SerializeIF::deSerialize(&ptr, &len) == HasReturnvaluesIF::RETURN_OK);
CHECK(simpleSer.getU8() == 5);
#if BYTE_ORDER_SYSTEM == LITTLE_ENDIAN
CHECK(simpleSer.getU16() == 0x0100);
#else
CHECK(simpleSer.getU16() == 1);
#endif
// Verify pointer arithmetic and size increment
CHECK(ptr == buf.data() + 3);
CHECK(len == 0);
}
SECTION("Machine Endian Simple Implicit") {
size_t deserLen = 0xff;
REQUIRE(simpleSer.SerializeIF::deSerialize(buf.data(), deserLen, buf.size()) ==
HasReturnvaluesIF::RETURN_OK);
CHECK(simpleSer.getU8() == 5);
#if BYTE_ORDER_SYSTEM == LITTLE_ENDIAN
CHECK(simpleSer.getU16() == 0x0100);
#else
CHECK(simpleSer.getU16() == 1);
#endif
CHECK(deserLen == 3);
}
}

View File

@ -0,0 +1,3 @@
target_sources(${FSFW_TEST_TGT} PRIVATE
testUnsignedByteField.cpp
)

View File

@ -0,0 +1,74 @@
#include <catch2/catch_test_macros.hpp>
#include "fsfw/util/UnsignedByteField.h"
#include <array>
TEST_CASE("Unsigned Byte Field", "[unsigned-byte-field]") {
auto testByteField = UnsignedByteField<uint32_t>(10);
auto u32ByteField = U32ByteField(10);
auto u16ByteField = U16ByteField(5);
auto u8ByteField = U8ByteField(2);
std::array<uint8_t, 16> buf{};
size_t serLen = 0;
SECTION("State") {
CHECK(testByteField.getValue() == 10);
CHECK(testByteField.getSerializedSize() == 4);
CHECK(u32ByteField.getValue() == 10);
CHECK(u32ByteField.getSerializedSize() == 4);
CHECK(u16ByteField.getValue() == 5);
CHECK(u8ByteField.getValue() == 2);
CHECK(u8ByteField.getSerializedSize() == 1);
}
SECTION("Setter") {
u32ByteField.setValue(20);
REQUIRE(u32ByteField.getValue() == 20);
}
SECTION("Serialize U32") {
CHECK(testByteField.serializeBe(buf.data(), serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
CHECK(serLen == 4);
CHECK(buf[0] == 0);
CHECK(buf[3] == 10);
}
SECTION("Serialize U32 Concrete") {
CHECK(u32ByteField.serializeBe(buf.data(), serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
CHECK(serLen == 4);
CHECK(buf[0] == 0);
CHECK(buf[3] == 10);
}
SECTION("Serialize U16 Concrete") {
CHECK(u16ByteField.serializeBe(buf.data(), serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
CHECK(serLen == 2);
CHECK(buf[0] == 0);
CHECK(buf[1] == 5);
}
SECTION("Serialize U8 Concrete") {
CHECK(u8ByteField.serializeBe(buf.data(), serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
CHECK(serLen == 1);
CHECK(buf[0] == 2);
}
SECTION("Deserialize") {
buf[0] = 0x50;
buf[1] = 0x40;
buf[2] = 0x30;
buf[3] = 0x20;
size_t deserLen = 0;
CHECK(testByteField.deSerializeBe(buf.data(), deserLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
CHECK(testByteField.getValue() == 0x50403020);
}
SECTION("Deserialize U16") {
buf[0] = 0x50;
buf[1] = 0x40;
size_t deserLen = 0;
CHECK(u16ByteField.deSerializeBe(buf.data(), deserLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
CHECK(u16ByteField.getValue() == 0x5040);
}
}