store helper

This commit is contained in:
Robin Müller 2022-07-23 11:43:48 +02:00
parent f629d60aaf
commit d474c4a7ee
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
12 changed files with 150 additions and 60 deletions

View File

@ -64,7 +64,7 @@ class SerializeIF {
/**
* Forwards to regular @serialize call with network endianness
*/
virtual ReturnValue_t serializeNe(uint8_t** buffer, size_t* size, size_t maxSize) {
virtual ReturnValue_t serializeNe(uint8_t **buffer, size_t *size, size_t maxSize) {
return serialize(buffer, size, maxSize, SerializeIF::Endianness::NETWORK);
}
/**
@ -105,13 +105,13 @@ class SerializeIF {
/**
* Forwards to regular @deSerialize call with network endianness
*/
virtual ReturnValue_t deSerializeNe(const uint8_t** buffer, size_t* size) {
virtual ReturnValue_t deSerializeNe(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) {
virtual ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size) {
return deSerialize(buffer, size, SerializeIF::Endianness::MACHINE);
}

View File

@ -12,6 +12,10 @@ struct PacketSeqCtrl : public SerializeIF {
PacketSeqCtrl(ccsds::SequenceFlags seqFlags, uint16_t seqCount)
: seqFlags(seqFlags), seqCount(seqCount) {}
bool operator==(const PacketSeqCtrl &other) const {
return seqCount == other.seqCount and seqFlags == other.seqFlags;
}
/**
* NOTE: If the sequence control has an invalid value, the invalid bits will be cut off
* @return

View File

@ -81,3 +81,5 @@ void SpacePacketCreator::setPacketType(ccsds::PacketType type) {
params.packetId.packetType = type;
}
bool SpacePacketCreator::operator==(const SpacePacketCreator &other) const { return false; }
SpacePacketCreator::operator bool() const { return isValid(); }

View File

@ -26,6 +26,7 @@ class SpacePacketCreator : public SpacePacketIF, public SerializeIF {
explicit SpacePacketCreator(SpacePacketParams params);
bool operator==(const SpacePacketCreator &other) const;
explicit operator bool() const;
SpacePacketCreator(ccsds::PacketType packetType, bool secHeaderFlag, uint16_t apid,
ccsds::SequenceFlags seqFlags, uint16_t seqCount, uint16_t dataLen,

View File

@ -14,13 +14,10 @@ TmStoreHelper::TmStoreHelper(uint16_t defaultApid, StorageManagerIF* tmStore) :
}
ReturnValue_t TmStoreHelper::preparePacket(uint8_t service, uint8_t subservice, uint16_t counter) {
// TODO: Implement
// creator.setApid(apid);
PusTmParams& params = creator.getParams();
params.secHeader.service = service;
params.secHeader.subservice = subservice;
params.secHeader.messageTypeCounter = counter;
// TODO: Implement serialize and then serialize into the store
return HasReturnvaluesIF::RETURN_OK;
}
@ -31,22 +28,21 @@ const store_address_t& TmStoreHelper::getCurrentAddr() const { return currentAdd
ReturnValue_t TmStoreHelper::deletePacket() { return tmStore->deleteData(currentAddr); }
void TmStoreHelper::setSourceDataRaw(const uint8_t* data, size_t len) {
PusTmParams& params = creator.getParams();
params.dataWrapper.type = ecss::DataTypes::RAW;
params.dataWrapper.dataUnion.raw.data = data;
params.dataWrapper.dataUnion.raw.len = len;
creator.setRawUserData(data, len);
}
void TmStoreHelper::setSourceDataSerializable(SerializeIF* serializable) {
PusTmParams& params = creator.getParams();
params.dataWrapper.type = ecss::DataTypes::SERIALIZABLE;
params.dataWrapper.dataUnion.serializable = serializable;
creator.setSerializableUserData(serializable);
}
ReturnValue_t TmStoreHelper::addPacketToStore() {
creator.updateSpLengthField();
uint8_t* dataPtr;
ReturnValue_t result =
tmStore->getFreeElement(&currentAddr, creator.getSerializedSize(), &dataPtr);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
size_t serLen = 0;
return creator.serialize(&dataPtr, &serLen, creator.getSerializedSize(),
SerializeIF::Endianness::NETWORK);
@ -55,4 +51,5 @@ ReturnValue_t TmStoreHelper::addPacketToStore() {
void TmStoreHelper::setTimeStamper(TimeStamperIF* timeStamper_) {
creator.setTimeStamper(timeStamper_);
}
void TmStoreHelper::setApid(uint16_t apid) { creator.setApid(apid); }

View File

@ -27,5 +27,6 @@ add_subdirectory(cfdp)
add_subdirectory(hal)
add_subdirectory(internalerror)
add_subdirectory(devicehandler)
add_subdirectory(tmtcservices)
target_include_directories(${FSFW_TEST_TGT} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})

View File

@ -1,8 +1,8 @@
#ifndef FSFW_TESTS_SIMPLESERIALIZABLE_H
#define FSFW_TESTS_SIMPLESERIALIZABLE_H
#include "fsfw/serialize.h"
#include "fsfw/osal/Endiness.h"
#include "fsfw/serialize.h"
class SimpleSerializable : public SerializeIF {
public:

View File

@ -13,7 +13,8 @@ TEST_CASE("Serialize IF Serialize", "[serialize-if-ser]") {
size_t len = 0;
SECTION("Little Endian Normal") {
REQUIRE(simpleSer.serialize(&ptr, &len, buf.size(), SerializeIF::Endianness::LITTLE) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(simpleSer.serialize(&ptr, &len, buf.size(), SerializeIF::Endianness::LITTLE) ==
HasReturnvaluesIF::RETURN_OK);
CHECK(buf[0] == 1);
CHECK(buf[1] == 3);
CHECK(buf[2] == 2);
@ -23,7 +24,9 @@ TEST_CASE("Serialize IF Serialize", "[serialize-if-ser]") {
}
SECTION("Little Endian Simple") {
REQUIRE(simpleSer.SerializeIF::serialize(buf.data(), buf.size(), SerializeIF::Endianness::LITTLE) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(
simpleSer.SerializeIF::serialize(buf.data(), buf.size(), SerializeIF::Endianness::LITTLE) ==
HasReturnvaluesIF::RETURN_OK);
CHECK(buf[0] == 1);
CHECK(buf[1] == 3);
CHECK(buf[2] == 2);
@ -35,7 +38,8 @@ TEST_CASE("Serialize IF Serialize", "[serialize-if-ser]") {
HasReturnvaluesIF::RETURN_OK);
}
SECTION("Network 0") {
REQUIRE(simpleSer.serialize(&ptr, &len, buf.size(), SerializeIF::Endianness::NETWORK) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(simpleSer.serialize(&ptr, &len, buf.size(), SerializeIF::Endianness::NETWORK) ==
HasReturnvaluesIF::RETURN_OK);
}
SECTION("Network 1") {
REQUIRE(simpleSer.serializeNe(&ptr, &len, buf.size()) == HasReturnvaluesIF::RETURN_OK);
@ -51,14 +55,18 @@ TEST_CASE("Serialize IF Serialize", "[serialize-if-ser]") {
SECTION("Big Endian Simple") {
SECTION("Explicit") {
REQUIRE(simpleSer.SerializeIF::serialize(buf.data(), buf.size(), SerializeIF::Endianness::BIG) ==
REQUIRE(
simpleSer.SerializeIF::serialize(buf.data(), buf.size(), SerializeIF::Endianness::BIG) ==
HasReturnvaluesIF::RETURN_OK);
}
SECTION("Network 0") {
REQUIRE(simpleSer.SerializeIF::serialize(buf.data(), buf.size(), SerializeIF::Endianness::NETWORK) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(simpleSer.SerializeIF::serialize(buf.data(), buf.size(),
SerializeIF::Endianness::NETWORK) ==
HasReturnvaluesIF::RETURN_OK);
}
SECTION("Network 1") {
REQUIRE(simpleSer.SerializeIF::serializeNe(buf.data(), buf.size()) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(simpleSer.SerializeIF::serializeNe(buf.data(), buf.size()) ==
HasReturnvaluesIF::RETURN_OK);
}
CHECK(buf[0] == 1);
CHECK(buf[1] == 2);
@ -102,7 +110,8 @@ TEST_CASE("SerializeIF Deserialize", "[serialize-if-de]") {
size_t len = buf.size();
SECTION("Little Endian Normal") {
REQUIRE(simpleSer.deSerialize(&ptr, &len, SerializeIF::Endianness::LITTLE) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(simpleSer.deSerialize(&ptr, &len, SerializeIF::Endianness::LITTLE) ==
HasReturnvaluesIF::RETURN_OK);
CHECK(simpleSer.getU8() == 5);
CHECK(simpleSer.getU16() == 0x0100);
CHECK(ptr == buf.data() + 3);
@ -110,17 +119,20 @@ TEST_CASE("SerializeIF Deserialize", "[serialize-if-de]") {
}
SECTION("Little Endian Simple") {
REQUIRE(simpleSer.SerializeIF::deSerialize(ptr, len, SerializeIF::Endianness::LITTLE) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(simpleSer.SerializeIF::deSerialize(ptr, len, SerializeIF::Endianness::LITTLE) ==
HasReturnvaluesIF::RETURN_OK);
CHECK(simpleSer.getU8() == 5);
CHECK(simpleSer.getU16() == 0x0100);
}
SECTION("Big Endian Normal") {
SECTION("Explicit") {
REQUIRE(simpleSer.deSerialize(&ptr, &len, SerializeIF::Endianness::BIG) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(simpleSer.deSerialize(&ptr, &len, SerializeIF::Endianness::BIG) ==
HasReturnvaluesIF::RETURN_OK);
}
SECTION("Network 0") {
REQUIRE(simpleSer.deSerialize(&ptr, &len, SerializeIF::Endianness::NETWORK) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(simpleSer.deSerialize(&ptr, &len, SerializeIF::Endianness::NETWORK) ==
HasReturnvaluesIF::RETURN_OK);
}
SECTION("Network 1") {
REQUIRE(simpleSer.SerializeIF::deSerializeNe(&ptr, &len) == HasReturnvaluesIF::RETURN_OK);
@ -133,14 +145,18 @@ TEST_CASE("SerializeIF Deserialize", "[serialize-if-de]") {
SECTION("Big Endian Simple") {
SECTION("Explicit") {
REQUIRE(simpleSer.SerializeIF::deSerialize(buf.data(), buf.size(), SerializeIF::Endianness::BIG) ==
REQUIRE(simpleSer.SerializeIF::deSerialize(buf.data(), buf.size(),
SerializeIF::Endianness::BIG) ==
HasReturnvaluesIF::RETURN_OK);
}
SECTION("Network 0") {
REQUIRE(simpleSer.SerializeIF::deSerialize(buf.data(), buf.size(), SerializeIF::Endianness::NETWORK) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(simpleSer.SerializeIF::deSerialize(buf.data(), buf.size(),
SerializeIF::Endianness::NETWORK) ==
HasReturnvaluesIF::RETURN_OK);
}
SECTION("Network 1") {
REQUIRE(simpleSer.SerializeIF::deSerializeNe(buf.data(), buf.size()) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(simpleSer.SerializeIF::deSerializeNe(buf.data(), buf.size()) ==
HasReturnvaluesIF::RETURN_OK);
}
CHECK(simpleSer.getU8() == 5);
CHECK(simpleSer.getU16() == 1);

View File

@ -1,7 +1,9 @@
#include <array>
#include <catch2/catch_test_macros.hpp>
#include <cmath>
#include "fsfw/tmtcpacket/ccsds/PacketId.h"
#include "fsfw/tmtcpacket/ccsds/PacketSeqCtrl.h"
#include "fsfw/tmtcpacket/ccsds/header.h"
TEST_CASE("CCSDS Low Level", "[ccsds-ll]") {
@ -43,16 +45,73 @@ TEST_CASE("CCSDS Packet ID", "[ccsds-packet-id]") {
REQUIRE(packetId.raw() == 0x1ff);
REQUIRE(packetId.SerializeIF::serializeNe(buf.data(), buf.size()) ==
HasReturnvaluesIF::RETURN_OK);
REQUIRE(buf[0] == 0x1);
REQUIRE(buf[1] == 0xff);
CHECK(buf[0] == 0x1);
CHECK(buf[1] == 0xff);
}
SECTION("Invalid Ser") {
REQUIRE(packetId.SerializeIF::serializeNe(buf.data(), 0) == SerializeIF::BUFFER_TOO_SHORT);
REQUIRE(packetId.SerializeIF::serializeNe(buf.data(), 1) == SerializeIF::BUFFER_TOO_SHORT);
}
SECTION("Invalid Deser") {
REQUIRE(packetId.SerializeIF::deSerialize(buf.data(), 1) == SerializeIF::STREAM_TOO_SHORT);
REQUIRE(packetId.SerializeIF::deSerialize(buf.data(), 0) == SerializeIF::STREAM_TOO_SHORT);
}
SECTION("From Raw") {
auto newId = PacketId(ccsds::PacketType::TC, true, 0x2ff);
uint16_t rawId = newId.raw();
REQUIRE(rawId == 0x1aff);
REQUIRE(PacketId::fromRaw(rawId) == newId);
CHECK(rawId == 0x1aff);
CHECK(PacketId::fromRaw(rawId) == newId);
}
SECTION("Deserialize") {
buf[0] = 0x1a;
buf[1] = 0xff;
REQUIRE(packetId.SerializeIF::deSerialize(buf.data(), buf.size()) ==
HasReturnvaluesIF::RETURN_OK);
CHECK(packetId.apid == 0x2ff);
CHECK(packetId.packetType == ccsds::PacketType::TC);
CHECK(packetId.secHeaderFlag == true);
}
}
TEST_CASE("CCSDS Packet Seq Ctrl", "[ccsds-packet-seq-ctrl]") {}
TEST_CASE("CCSDS Packet Seq Ctrl", "[ccsds-packet-seq-ctrl]") {
PacketSeqCtrl psc;
std::array<uint8_t, 3> buf{};
SECTION("Basic") {
psc.seqFlags = ccsds::SequenceFlags::FIRST_SEGMENT;
psc.seqCount = static_cast<uint16_t>(std::round(std::pow(2, 14) - 1));
REQUIRE(psc.raw() == 0x7fff);
REQUIRE(psc.SerializeIF::serializeNe(buf.data(), buf.size()) == HasReturnvaluesIF::RETURN_OK);
CHECK(buf[0] == 0x7f);
CHECK(buf[1] == 0xff);
}
SECTION("From Raw") {
auto newId = PacketSeqCtrl(ccsds::SequenceFlags::LAST_SEGMENT,
static_cast<uint16_t>(std::round(std::pow(2, 14) - 2)));
uint16_t rawId = newId.raw();
REQUIRE(rawId == 0xbffe);
CHECK(PacketSeqCtrl::fromRaw(rawId) == newId);
}
SECTION("Deserialize") {
buf[0] = 0xbf;
buf[1] = 0xfe;
REQUIRE(psc.SerializeIF::deSerialize(buf.data(), buf.size()) == HasReturnvaluesIF::RETURN_OK);
CHECK(psc.seqFlags == ccsds::SequenceFlags::LAST_SEGMENT);
CHECK(psc.seqCount == static_cast<uint16_t>(std::round(std::pow(2, 14) - 2)));
}
SECTION("Invalid Ser") {
REQUIRE(psc.SerializeIF::serializeNe(buf.data(), 0) == SerializeIF::BUFFER_TOO_SHORT);
REQUIRE(psc.SerializeIF::serializeNe(buf.data(), 1) == SerializeIF::BUFFER_TOO_SHORT);
}
SECTION("Invalid Deser") {
REQUIRE(psc.SerializeIF::deSerialize(buf.data(), 1) == SerializeIF::STREAM_TOO_SHORT);
REQUIRE(psc.SerializeIF::deSerialize(buf.data(), 0) == SerializeIF::STREAM_TOO_SHORT);
}
}

View File

@ -5,8 +5,9 @@
#include "fsfw/tmtcpacket/ccsds/SpacePacketCreator.h"
TEST_CASE("CCSDS Creator", "[ccsds-creator]") {
auto params = SpacePacketParams(PacketId(ccsds::PacketType::TC, true, 0x02),
PacketSeqCtrl(ccsds::SequenceFlags::FIRST_SEGMENT, 0x34), 0x16);
auto packetId = PacketId(ccsds::PacketType::TC, true, 0x02);
auto psc = PacketSeqCtrl(ccsds::SequenceFlags::FIRST_SEGMENT, 0x34);
auto params = SpacePacketParams(packetId, psc, 0x16);
SpacePacketCreator base = SpacePacketCreator(params);
std::array<uint8_t, 6> buf{};
uint8_t* bufPtr = buf.data();
@ -21,15 +22,18 @@ TEST_CASE("CCSDS Creator", "[ccsds-creator]") {
}
SECTION("Basic Test") {
REQUIRE(base.isValid());
REQUIRE(base.getApid() == 0x02);
REQUIRE(base.getSequenceFlags() == ccsds::SequenceFlags::FIRST_SEGMENT);
REQUIRE(base.getVersion() == 0b000);
REQUIRE(base.getSequenceCount() == 0x34);
REQUIRE(base.getPacketDataLen() == 0x16);
REQUIRE(base.getPacketType() == ccsds::PacketType::TC);
REQUIRE(base.getPacketIdRaw() == 0x1802);
REQUIRE(base.getSerializedSize() == 6);
CHECK(base.isValid());
CHECK(base);
CHECK(base.getApid() == 0x02);
CHECK(base.getSequenceFlags() == ccsds::SequenceFlags::FIRST_SEGMENT);
CHECK(base.getVersion() == 0b000);
CHECK(base.getSequenceCount() == 0x34);
CHECK(base.getPacketDataLen() == 0x16);
CHECK(base.getPacketType() == ccsds::PacketType::TC);
CHECK(base.getPacketIdRaw() == 0x1802);
CHECK(base.getSerializedSize() == 6);
CHECK(base.getPacketSeqCtrl() == psc);
CHECK(base.getPacketId() == packetId);
}
SECTION("Deserialization Fails") {
@ -42,18 +46,18 @@ TEST_CASE("CCSDS Creator", "[ccsds-creator]") {
SECTION("Raw Output") {
REQUIRE(base.serializeNe(&bufPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
// TC, and secondary header flag is set -> 0b0001100 -> 0x18
REQUIRE(buf[0] == 0x18);
CHECK(buf[0] == 0x18);
// APID 0x02
REQUIRE(buf[1] == 0x02);
CHECK(buf[1] == 0x02);
// Sequence count is one byte value, so the only set bit here is the bit
// from the Sequence flag argument, which is the second bit for
// SequenceFlags.FIRST_SEGMENT
REQUIRE(buf[2] == 0x40);
CHECK(buf[2] == 0x40);
// Sequence Count specified above
REQUIRE(buf[3] == 0x34);
CHECK(buf[3] == 0x34);
// This byte and the next byte should be 22 big endian (packet length)
REQUIRE(buf[4] == 0x00);
REQUIRE(buf[5] == 0x16);
CHECK(buf[4] == 0x00);
CHECK(buf[5] == 0x16);
}
SECTION("All Ones Output") {
@ -63,19 +67,20 @@ TEST_CASE("CCSDS Creator", "[ccsds-creator]") {
base.setDataLen(static_cast<int>(std::pow(2, 16)) - 1);
REQUIRE(base.isValid());
REQUIRE(base.serializeNe(&bufPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(buf[0] == 0x1F);
REQUIRE(buf[1] == 0xFF);
REQUIRE(buf[2] == 0xFF);
REQUIRE(buf[3] == 0xFF);
REQUIRE(buf[4] == 0xFF);
REQUIRE(buf[5] == 0xFF);
CHECK(buf[0] == 0x1F);
CHECK(buf[1] == 0xFF);
CHECK(buf[2] == 0xFF);
CHECK(buf[3] == 0xFF);
CHECK(buf[4] == 0xFF);
CHECK(buf[5] == 0xFF);
}
SECTION("Invalid APID") {
SpacePacketCreator invalid = SpacePacketCreator(
SpacePacketCreator creator = SpacePacketCreator(
ccsds::PacketType::TC, true, 0xFFFF, ccsds::SequenceFlags::FIRST_SEGMENT, 0x34, 0x16);
REQUIRE(not invalid.isValid());
REQUIRE(invalid.serializeNe(&bufPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_FAILED);
REQUIRE(not creator.isValid());
REQUIRE(not creator);
REQUIRE(creator.serializeNe(&bufPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_FAILED);
}
SECTION("Invalid Seq Count") {

View File

@ -0,0 +1,2 @@
target_sources(${FSFW_TEST_TGT} PRIVATE
)

View File

@ -0,0 +1,3 @@
#include <catch2/catch_test_macros.hpp>
TEST_CASE("TM Store Helper", "[tm-store-helper]") {}