Merge remote-tracking branch 'upstream/mueller/refactor-tmtc-stack' into mueller/tmtc-stack-refactoring

This commit is contained in:
Robin Müller 2022-08-15 19:18:46 +02:00
commit c57e95c698
21 changed files with 179 additions and 136 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

@ -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

@ -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

@ -79,6 +79,9 @@ struct PacketId : public SerializeIF {
ccsds::PacketType packetType = ccsds::PacketType::TM;
bool secHeaderFlag = false;
uint16_t apid = 0;
using SerializeIF::deSerialize;
using SerializeIF::serialize;
};
#endif // FSFW_TMTCPACKET_PACKETID_H

View File

@ -55,6 +55,9 @@ struct PacketSeqCtrl : public SerializeIF {
ccsds::SequenceFlags seqFlags = ccsds::SequenceFlags::CONTINUATION;
uint16_t seqCount = 0;
using SerializeIF::deSerialize;
using SerializeIF::serialize;
};
#endif // FSFW_TMTCPACKET_PACKETSEQCTRL_H

View File

@ -103,13 +103,6 @@ ReturnValue_t PusTcCreator::setSerializableUserData(SerializeIF &serializable) {
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t PusTcCreator::serialize(uint8_t **buffer, size_t *size, size_t maxSize) const {
return serialize(buffer, size, maxSize, SerializeIF::Endianness::NETWORK);
}
ReturnValue_t PusTcCreator::serialize(uint8_t *buffer, size_t &serLen, size_t maxSize) const {
return SerializeIF::serialize(buffer, serLen, maxSize, SerializeIF::Endianness::NETWORK);
}
void PusTcCreator::setup() {
spCreator.setPacketType(ccsds::PacketType::TC);
spCreator.setSecHeaderFlag();

View File

@ -40,8 +40,6 @@ class PusTcCreator : public PusTcIF, public SerializeIF, public CustomUserDataIF
PusTcParams &getPusParams();
SpacePacketParams &getSpParams();
ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize) const override;
ReturnValue_t serialize(uint8_t *buffer, size_t &serLen, size_t maxSize) const override;
[[nodiscard]] size_t getSerializedSize() const override;
[[nodiscard]] uint16_t getPacketIdRaw() const override;
@ -55,7 +53,11 @@ class PusTcCreator : public PusTcIF, public SerializeIF, public CustomUserDataIF
ReturnValue_t setRawUserData(const uint8_t *data, size_t len) override;
ReturnValue_t setSerializableUserData(SerializeIF &serializable) override;
// Load all big endian helpers into the class namespace
using SerializeIF::serializeBe;
private:
// Forbidden to use, enforce big endian serialization
ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize,
Endianness streamEndianness) const override;
// Forbidden to use

View File

@ -150,11 +150,3 @@ void PusTmCreator::setSubservice(uint8_t subservice) {
pusParams.secHeader.subservice = subservice;
}
bool PusTmCreator::crcCalculationEnabled() const { return calculateCrcOnSerialization; }
ReturnValue_t PusTmCreator::serialize(uint8_t** buffer, size_t* size, size_t maxSize) const {
return serialize(buffer, size, maxSize, SerializeIF::Endianness::NETWORK);
}
ReturnValue_t PusTmCreator::serialize(uint8_t* buffer, size_t& serLen, size_t maxSize) const {
return SerializeIF::serialize(buffer, serLen, maxSize, SerializeIF::Endianness::NETWORK);
}

View File

@ -82,9 +82,6 @@ class PusTmCreator : public SerializeIF, public PusTmIF, public CustomUserDataIF
uint8_t getScTimeRefStatus() override;
uint16_t getMessageTypeCounter() override;
uint16_t getDestId() override;
// Override these to use default big endianness
ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize) const override;
ReturnValue_t serialize(uint8_t* buffer, size_t& serLen, size_t maxSize) const override;
ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize,
Endianness streamEndianness) const override;
[[nodiscard]] size_t getSerializedSize() const override;
@ -92,6 +89,9 @@ class PusTmCreator : public SerializeIF, public PusTmIF, public CustomUserDataIF
ReturnValue_t setRawUserData(const uint8_t* data, size_t len) override;
ReturnValue_t setSerializableUserData(SerializeIF& serializable) override;
// Load all big endian (network endian) helpers into scope
using SerializeIF::serializeBe;
private:
// Forbidden to use
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,

View File

@ -0,0 +1,47 @@
#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

@ -305,7 +305,7 @@ void MgmRM3100Handler::fillCommandAndReplyMap() {
insertInCommandAndReplyMap(RM3100::READ_DATA, 3, &primaryDataset);
}
void MgmRM3100Handler::modeChanged(void) { internalState = InternalState::NONE; }
void MgmRM3100Handler::modeChanged() { internalState = InternalState::NONE; }
ReturnValue_t MgmRM3100Handler::initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
LocalDataPoolManager &poolManager) {

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

@ -60,9 +60,9 @@ TEST_CASE("CCSDS Packet ID", "[ccsds-packet-id]") {
SECTION("Invalid Deser") {
size_t deserLen = 0;
REQUIRE(packetId.SerializeIF::deSerialize(buf.data(), deserLen, 1) ==
REQUIRE(packetId.deSerialize(buf.data(), deserLen, 1, SerializeIF::Endianness::NETWORK) ==
SerializeIF::STREAM_TOO_SHORT);
REQUIRE(packetId.SerializeIF::deSerialize(buf.data(), deserLen, 0) ==
REQUIRE(packetId.deSerialize(buf.data(), deserLen, 0, SerializeIF::Endianness::NETWORK) ==
SerializeIF::STREAM_TOO_SHORT);
}
@ -77,8 +77,8 @@ TEST_CASE("CCSDS Packet ID", "[ccsds-packet-id]") {
buf[0] = 0x1a;
buf[1] = 0xff;
size_t deserLen = 0xff;
REQUIRE(packetId.SerializeIF::deSerialize(buf.data(), deserLen, buf.size()) ==
HasReturnvaluesIF::RETURN_OK);
REQUIRE(packetId.deSerialize(buf.data(), deserLen, buf.size(),
SerializeIF::Endianness::NETWORK) == HasReturnvaluesIF::RETURN_OK);
CHECK(packetId.apid == 0x2ff);
CHECK(deserLen == 2);
CHECK(packetId.packetType == ccsds::PacketType::TC);
@ -113,7 +113,7 @@ TEST_CASE("CCSDS Packet Seq Ctrl", "[ccsds-packet-seq-ctrl]") {
buf[0] = 0xbf;
buf[1] = 0xfe;
size_t deserLen = 0xff;
REQUIRE(psc.SerializeIF::deSerialize(buf.data(), deserLen, buf.size()) ==
REQUIRE(psc.deSerialize(buf.data(), deserLen, buf.size(), SerializeIF::Endianness::NETWORK) ==
HasReturnvaluesIF::RETURN_OK);
CHECK(psc.seqFlags == ccsds::SequenceFlags::LAST_SEGMENT);
CHECK(deserLen == 2);
@ -128,7 +128,9 @@ TEST_CASE("CCSDS Packet Seq Ctrl", "[ccsds-packet-seq-ctrl]") {
SECTION("Invalid Deser") {
size_t deserLen = 0;
REQUIRE(psc.SerializeIF::deSerialize(buf.data(), deserLen, 1) == SerializeIF::STREAM_TOO_SHORT);
REQUIRE(psc.SerializeIF::deSerialize(buf.data(), deserLen, 0) == SerializeIF::STREAM_TOO_SHORT);
REQUIRE(psc.deSerialize(buf.data(), deserLen, 1, SerializeIF::Endianness::NETWORK) ==
SerializeIF::STREAM_TOO_SHORT);
REQUIRE(psc.deSerialize(buf.data(), deserLen, 0, SerializeIF::Endianness::NETWORK) ==
SerializeIF::STREAM_TOO_SHORT);
}
}

View File

@ -34,7 +34,7 @@ TEST_CASE("PUS TC Creator", "[pus-tc-creator]") {
}
SECTION("Serialized") {
REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(creator.serializeBe(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(serLen == 13);
REQUIRE(buf[0] == 0x18);
REQUIRE(buf[1] == 0x02);
@ -64,7 +64,7 @@ TEST_CASE("PUS TC Creator", "[pus-tc-creator]") {
auto& params = creator.getPusParams();
params.sourceId = 0x5ff;
REQUIRE(creator.getSourceId() == 0x5ff);
REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(creator.serializeBe(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(((buf[9] << 8) | buf[10]) == 0x5ff);
}
@ -76,7 +76,7 @@ TEST_CASE("PUS TC Creator", "[pus-tc-creator]") {
REQUIRE(creator.getSerializedSize() == 13);
creator.updateSpLengthField();
REQUIRE(creator.getSerializedSize() == 16);
REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(creator.serializeBe(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(serLen == 16);
REQUIRE(buf[11] == 1);
REQUIRE(buf[12] == 2);
@ -88,7 +88,7 @@ TEST_CASE("PUS TC Creator", "[pus-tc-creator]") {
auto simpleSer = SimpleSerializable();
creator.setSerializableUserData(simpleSer);
REQUIRE(creator.getSerializedSize() == 16);
REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(creator.serializeBe(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(serLen == 16);
REQUIRE(buf[11] == 1);
REQUIRE(buf[12] == 2);
@ -100,7 +100,7 @@ TEST_CASE("PUS TC Creator", "[pus-tc-creator]") {
auto simpleSer = SimpleSerializable();
creator.setSerializableUserData(simpleSer);
REQUIRE(creator.getSerializedSize() == 16);
REQUIRE(creator.serialize(dataPtr, serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(creator.serializeBe(dataPtr, serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(serLen == 16);
REQUIRE(buf[11] == 1);
REQUIRE(buf[12] == 2);
@ -120,13 +120,13 @@ TEST_CASE("PUS TC Creator", "[pus-tc-creator]") {
for (size_t maxSize = 0; maxSize < reqSize; maxSize++) {
dataPtr = buf.data();
serLen = 0;
REQUIRE(creator.serialize(&dataPtr, &serLen, maxSize) == SerializeIF::BUFFER_TOO_SHORT);
REQUIRE(creator.serializeBe(&dataPtr, &serLen, maxSize) == SerializeIF::BUFFER_TOO_SHORT);
}
}
SECTION("Invalid PUS Version") {
auto& params = creator.getPusParams();
params.pusVersion = 0;
REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == PusIF::INVALID_PUS_VERSION);
REQUIRE(creator.serializeBe(&dataPtr, &serLen, buf.size()) == PusIF::INVALID_PUS_VERSION);
}
}

View File

@ -16,7 +16,7 @@ TEST_CASE("PUS TC Reader", "[pus-tc-reader]") {
PusTcReader reader;
SECTION("State") {
REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(creator.serializeBe(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(reader.isNull());
REQUIRE(not reader);
PusTcReader* readerPtr = nullptr;
@ -55,14 +55,14 @@ TEST_CASE("PUS TC Reader", "[pus-tc-reader]") {
}
SECTION("Invalid CRC") {
REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(creator.serializeBe(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(reader.setReadOnlyData(buf.data(), serLen) == HasReturnvaluesIF::RETURN_OK);
buf[11] = 0x00;
REQUIRE(reader.parseDataWithCrcCheck() == PusIF::INVALID_CRC_16);
}
SECTION("Invalid CRC but no check") {
REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(creator.serializeBe(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(reader.setReadOnlyData(buf.data(), serLen) == HasReturnvaluesIF::RETURN_OK);
buf[11] = 0x00;
REQUIRE(reader.parseDataWithoutCrcCheck() == HasReturnvaluesIF::RETURN_OK);
@ -72,7 +72,7 @@ TEST_CASE("PUS TC Reader", "[pus-tc-reader]") {
auto& params = creator.getPusParams();
std::array<uint8_t, 3> data{1, 2, 3};
creator.setRawUserData(data.data(), data.size());
REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(creator.serializeBe(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(reader.setReadOnlyData(buf.data(), serLen) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(reader.parseDataWithCrcCheck() == HasReturnvaluesIF::RETURN_OK);
const uint8_t* userDataPtr = reader.getUserData();

View File

@ -90,7 +90,7 @@ TEST_CASE("PUS TM Creator", "[pus-tm-creator]") {
REQUIRE(creator.getApid() == 0x3ff);
REQUIRE(creator.getDestId() == 0xfff);
REQUIRE(creator.getMessageTypeCounter() == 0x313);
REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(creator.serializeBe(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
// Message Sequence Count
REQUIRE(((buf[9] << 8) | buf[10]) == 0x313);
// Destination ID
@ -108,8 +108,7 @@ TEST_CASE("PUS TM Creator", "[pus-tm-creator]") {
std::array<uint8_t, 3> data{1, 2, 3};
creator.setRawUserData(data.data(), data.size());
REQUIRE(creator.getFullPacketLen() == 25);
REQUIRE(creator.SerializeIF::serialize(&dataPtr, &serLen, buf.size()) ==
HasReturnvaluesIF::RETURN_OK);
REQUIRE(creator.serializeBe(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(buf[20] == 1);
REQUIRE(buf[21] == 2);
REQUIRE(buf[22] == 3);
@ -119,7 +118,8 @@ TEST_CASE("PUS TM Creator", "[pus-tm-creator]") {
auto simpleSer = SimpleSerializable();
creator.setSerializableUserData(simpleSer);
REQUIRE(creator.getFullPacketLen() == 25);
REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size(), SerializeIF::Endianness::NETWORK) ==
HasReturnvaluesIF::RETURN_OK);
REQUIRE(buf[20] == 1);
REQUIRE(buf[21] == 2);
REQUIRE(buf[22] == 3);
@ -143,7 +143,7 @@ TEST_CASE("PUS TM Creator", "[pus-tm-creator]") {
for (size_t maxSize = 0; maxSize < reqSize; maxSize++) {
dataPtr = buf.data();
serLen = 0;
REQUIRE(creator.SerializeIF::serialize(&dataPtr, &serLen, maxSize) ==
REQUIRE(creator.serialize(&dataPtr, &serLen, maxSize, SerializeIF::Endianness::NETWORK) ==
SerializeIF::BUFFER_TOO_SHORT);
}
}
@ -151,7 +151,7 @@ TEST_CASE("PUS TM Creator", "[pus-tm-creator]") {
SECTION("No CRC Generation") {
creator.disableCrcCalculation();
REQUIRE(not creator.crcCalculationEnabled());
REQUIRE(creator.serialize(dataPtr, serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(creator.serializeBe(dataPtr, serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(serLen == 22);
REQUIRE(buf[20] == 0x00);
REQUIRE(buf[21] == 0x00);

View File

@ -62,7 +62,7 @@ TEST_CASE("PUS TM Reader", "[pus-tm-reader]") {
}
SECTION("Invalid CRC") {
REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(creator.serializeBe(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
buf[20] = 0;
REQUIRE(reader.setReadOnlyData(buf.data(), serLen) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(reader.parseDataWithCrcCheck() == PusIF::INVALID_CRC_16);
@ -74,7 +74,7 @@ TEST_CASE("PUS TM Reader", "[pus-tm-reader]") {
}
SECTION("Invalid CRC ignored") {
REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(creator.serializeBe(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
buf[20] = 0;
REQUIRE(reader.setReadOnlyData(buf.data(), serLen) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(reader.parseDataWithoutCrcCheck() == HasReturnvaluesIF::RETURN_OK);
@ -83,7 +83,7 @@ TEST_CASE("PUS TM Reader", "[pus-tm-reader]") {
SECTION("Read with source data") {
std::array<uint8_t, 3> data{1, 2, 3};
creator.setRawUserData(data.data(), data.size());
REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(creator.serializeBe(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(reader.setReadOnlyData(buf.data(), serLen) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(reader.parseDataWithCrcCheck() == HasReturnvaluesIF::RETURN_OK);
REQUIRE(reader.getUserDataLen() == 3);
@ -94,7 +94,7 @@ TEST_CASE("PUS TM Reader", "[pus-tm-reader]") {
}
SECTION("Invalid stream lengths") {
REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(creator.serializeBe(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
for (size_t i = 0; i < serLen - 1; i++) {
REQUIRE(reader.setReadOnlyData(buf.data(), i) == SerializeIF::STREAM_TOO_SHORT);
}
@ -102,7 +102,7 @@ TEST_CASE("PUS TM Reader", "[pus-tm-reader]") {
SECTION("Reading timestamp fails") {
timeStamperAndReader.nextDeserFails = true;
REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(creator.serializeBe(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(reader.setReadOnlyData(buf.data(), serLen) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(reader.parseDataWithCrcCheck() == HasReturnvaluesIF::RETURN_FAILED);
}

View File

@ -18,7 +18,7 @@ TEST_CASE("TM ZC Helper", "[tm-zc-helper]") {
size_t serLen = 0;
SECTION("No Crash For Uninitialized Object") {
REQUIRE(creator.serialize(dataPtr, serLen, buf.size()) == result::OK);
REQUIRE(creator.serializeBe(dataPtr, serLen, buf.size()) == result::OK);
PusTmZeroCopyWriter writer(timeStamper, dataPtr, serLen);
REQUIRE(writer.getSequenceCount() == 22);
writer.setSequenceCount(23);
@ -28,7 +28,7 @@ TEST_CASE("TM ZC Helper", "[tm-zc-helper]") {
}
SECTION("Basic") {
REQUIRE(creator.serialize(dataPtr, serLen, buf.size()) == result::OK);
REQUIRE(creator.serializeBe(dataPtr, serLen, buf.size()) == result::OK);
PusTmZeroCopyWriter writer(timeStamper, dataPtr, serLen);
REQUIRE(writer.parseDataWithoutCrcCheck() == result::OK);
REQUIRE(writer.getSequenceCount() == 22);

View File

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

View File

@ -0,0 +1,76 @@
#include <array>
#include <catch2/catch_test_macros.hpp>
#include "fsfw/util/UnsignedByteField.h"
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);
}
}