store helper
This commit is contained in:
parent
f629d60aaf
commit
d474c4a7ee
@ -64,7 +64,7 @@ class SerializeIF {
|
|||||||
/**
|
/**
|
||||||
* Forwards to regular @serialize call with network endianness
|
* 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);
|
return serialize(buffer, size, maxSize, SerializeIF::Endianness::NETWORK);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@ -105,13 +105,13 @@ class SerializeIF {
|
|||||||
/**
|
/**
|
||||||
* Forwards to regular @deSerialize call with network endianness
|
* 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);
|
return deSerialize(buffer, size, SerializeIF::Endianness::NETWORK);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* If endianness is not explicitly specified, use machine endianness
|
* 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);
|
return deSerialize(buffer, size, SerializeIF::Endianness::MACHINE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,6 +12,10 @@ struct PacketSeqCtrl : public SerializeIF {
|
|||||||
PacketSeqCtrl(ccsds::SequenceFlags seqFlags, uint16_t seqCount)
|
PacketSeqCtrl(ccsds::SequenceFlags seqFlags, uint16_t seqCount)
|
||||||
: seqFlags(seqFlags), seqCount(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
|
* NOTE: If the sequence control has an invalid value, the invalid bits will be cut off
|
||||||
* @return
|
* @return
|
||||||
|
@ -81,3 +81,5 @@ void SpacePacketCreator::setPacketType(ccsds::PacketType type) {
|
|||||||
params.packetId.packetType = type;
|
params.packetId.packetType = type;
|
||||||
}
|
}
|
||||||
bool SpacePacketCreator::operator==(const SpacePacketCreator &other) const { return false; }
|
bool SpacePacketCreator::operator==(const SpacePacketCreator &other) const { return false; }
|
||||||
|
|
||||||
|
SpacePacketCreator::operator bool() const { return isValid(); }
|
||||||
|
@ -26,6 +26,7 @@ class SpacePacketCreator : public SpacePacketIF, public SerializeIF {
|
|||||||
explicit SpacePacketCreator(SpacePacketParams params);
|
explicit SpacePacketCreator(SpacePacketParams params);
|
||||||
|
|
||||||
bool operator==(const SpacePacketCreator &other) const;
|
bool operator==(const SpacePacketCreator &other) const;
|
||||||
|
explicit operator bool() const;
|
||||||
|
|
||||||
SpacePacketCreator(ccsds::PacketType packetType, bool secHeaderFlag, uint16_t apid,
|
SpacePacketCreator(ccsds::PacketType packetType, bool secHeaderFlag, uint16_t apid,
|
||||||
ccsds::SequenceFlags seqFlags, uint16_t seqCount, uint16_t dataLen,
|
ccsds::SequenceFlags seqFlags, uint16_t seqCount, uint16_t dataLen,
|
||||||
|
@ -14,13 +14,10 @@ TmStoreHelper::TmStoreHelper(uint16_t defaultApid, StorageManagerIF* tmStore) :
|
|||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t TmStoreHelper::preparePacket(uint8_t service, uint8_t subservice, uint16_t counter) {
|
ReturnValue_t TmStoreHelper::preparePacket(uint8_t service, uint8_t subservice, uint16_t counter) {
|
||||||
// TODO: Implement
|
|
||||||
// creator.setApid(apid);
|
|
||||||
PusTmParams& params = creator.getParams();
|
PusTmParams& params = creator.getParams();
|
||||||
params.secHeader.service = service;
|
params.secHeader.service = service;
|
||||||
params.secHeader.subservice = subservice;
|
params.secHeader.subservice = subservice;
|
||||||
params.secHeader.messageTypeCounter = counter;
|
params.secHeader.messageTypeCounter = counter;
|
||||||
// TODO: Implement serialize and then serialize into the store
|
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
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); }
|
ReturnValue_t TmStoreHelper::deletePacket() { return tmStore->deleteData(currentAddr); }
|
||||||
|
|
||||||
void TmStoreHelper::setSourceDataRaw(const uint8_t* data, size_t len) {
|
void TmStoreHelper::setSourceDataRaw(const uint8_t* data, size_t len) {
|
||||||
PusTmParams& params = creator.getParams();
|
creator.setRawUserData(data, len);
|
||||||
params.dataWrapper.type = ecss::DataTypes::RAW;
|
|
||||||
params.dataWrapper.dataUnion.raw.data = data;
|
|
||||||
params.dataWrapper.dataUnion.raw.len = len;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TmStoreHelper::setSourceDataSerializable(SerializeIF* serializable) {
|
void TmStoreHelper::setSourceDataSerializable(SerializeIF* serializable) {
|
||||||
PusTmParams& params = creator.getParams();
|
creator.setSerializableUserData(serializable);
|
||||||
params.dataWrapper.type = ecss::DataTypes::SERIALIZABLE;
|
|
||||||
params.dataWrapper.dataUnion.serializable = serializable;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t TmStoreHelper::addPacketToStore() {
|
ReturnValue_t TmStoreHelper::addPacketToStore() {
|
||||||
creator.updateSpLengthField();
|
creator.updateSpLengthField();
|
||||||
uint8_t* dataPtr;
|
uint8_t* dataPtr;
|
||||||
tmStore->getFreeElement(¤tAddr, creator.getSerializedSize(), &dataPtr);
|
ReturnValue_t result =
|
||||||
|
tmStore->getFreeElement(¤tAddr, creator.getSerializedSize(), &dataPtr);
|
||||||
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
size_t serLen = 0;
|
size_t serLen = 0;
|
||||||
return creator.serialize(&dataPtr, &serLen, creator.getSerializedSize(),
|
return creator.serialize(&dataPtr, &serLen, creator.getSerializedSize(),
|
||||||
SerializeIF::Endianness::NETWORK);
|
SerializeIF::Endianness::NETWORK);
|
||||||
@ -55,4 +51,5 @@ ReturnValue_t TmStoreHelper::addPacketToStore() {
|
|||||||
void TmStoreHelper::setTimeStamper(TimeStamperIF* timeStamper_) {
|
void TmStoreHelper::setTimeStamper(TimeStamperIF* timeStamper_) {
|
||||||
creator.setTimeStamper(timeStamper_);
|
creator.setTimeStamper(timeStamper_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TmStoreHelper::setApid(uint16_t apid) { creator.setApid(apid); }
|
void TmStoreHelper::setApid(uint16_t apid) { creator.setApid(apid); }
|
||||||
|
@ -27,5 +27,6 @@ add_subdirectory(cfdp)
|
|||||||
add_subdirectory(hal)
|
add_subdirectory(hal)
|
||||||
add_subdirectory(internalerror)
|
add_subdirectory(internalerror)
|
||||||
add_subdirectory(devicehandler)
|
add_subdirectory(devicehandler)
|
||||||
|
add_subdirectory(tmtcservices)
|
||||||
|
|
||||||
target_include_directories(${FSFW_TEST_TGT} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
target_include_directories(${FSFW_TEST_TGT} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
#ifndef FSFW_TESTS_SIMPLESERIALIZABLE_H
|
#ifndef FSFW_TESTS_SIMPLESERIALIZABLE_H
|
||||||
#define FSFW_TESTS_SIMPLESERIALIZABLE_H
|
#define FSFW_TESTS_SIMPLESERIALIZABLE_H
|
||||||
|
|
||||||
#include "fsfw/serialize.h"
|
|
||||||
#include "fsfw/osal/Endiness.h"
|
#include "fsfw/osal/Endiness.h"
|
||||||
|
#include "fsfw/serialize.h"
|
||||||
|
|
||||||
class SimpleSerializable : public SerializeIF {
|
class SimpleSerializable : public SerializeIF {
|
||||||
public:
|
public:
|
||||||
|
@ -13,7 +13,8 @@ TEST_CASE("Serialize IF Serialize", "[serialize-if-ser]") {
|
|||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
|
|
||||||
SECTION("Little Endian Normal") {
|
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[0] == 1);
|
||||||
CHECK(buf[1] == 3);
|
CHECK(buf[1] == 3);
|
||||||
CHECK(buf[2] == 2);
|
CHECK(buf[2] == 2);
|
||||||
@ -23,7 +24,9 @@ TEST_CASE("Serialize IF Serialize", "[serialize-if-ser]") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SECTION("Little Endian Simple") {
|
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[0] == 1);
|
||||||
CHECK(buf[1] == 3);
|
CHECK(buf[1] == 3);
|
||||||
CHECK(buf[2] == 2);
|
CHECK(buf[2] == 2);
|
||||||
@ -35,7 +38,8 @@ TEST_CASE("Serialize IF Serialize", "[serialize-if-ser]") {
|
|||||||
HasReturnvaluesIF::RETURN_OK);
|
HasReturnvaluesIF::RETURN_OK);
|
||||||
}
|
}
|
||||||
SECTION("Network 0") {
|
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") {
|
SECTION("Network 1") {
|
||||||
REQUIRE(simpleSer.serializeNe(&ptr, &len, buf.size()) == HasReturnvaluesIF::RETURN_OK);
|
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("Big Endian Simple") {
|
||||||
SECTION("Explicit") {
|
SECTION("Explicit") {
|
||||||
REQUIRE(simpleSer.SerializeIF::serialize(buf.data(), buf.size(), SerializeIF::Endianness::BIG) ==
|
REQUIRE(
|
||||||
HasReturnvaluesIF::RETURN_OK);
|
simpleSer.SerializeIF::serialize(buf.data(), buf.size(), SerializeIF::Endianness::BIG) ==
|
||||||
|
HasReturnvaluesIF::RETURN_OK);
|
||||||
}
|
}
|
||||||
SECTION("Network 0") {
|
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") {
|
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[0] == 1);
|
||||||
CHECK(buf[1] == 2);
|
CHECK(buf[1] == 2);
|
||||||
@ -102,7 +110,8 @@ TEST_CASE("SerializeIF Deserialize", "[serialize-if-de]") {
|
|||||||
size_t len = buf.size();
|
size_t len = buf.size();
|
||||||
|
|
||||||
SECTION("Little Endian Normal") {
|
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.getU8() == 5);
|
||||||
CHECK(simpleSer.getU16() == 0x0100);
|
CHECK(simpleSer.getU16() == 0x0100);
|
||||||
CHECK(ptr == buf.data() + 3);
|
CHECK(ptr == buf.data() + 3);
|
||||||
@ -110,17 +119,20 @@ TEST_CASE("SerializeIF Deserialize", "[serialize-if-de]") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SECTION("Little Endian Simple") {
|
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.getU8() == 5);
|
||||||
CHECK(simpleSer.getU16() == 0x0100);
|
CHECK(simpleSer.getU16() == 0x0100);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("Big Endian Normal") {
|
SECTION("Big Endian Normal") {
|
||||||
SECTION("Explicit") {
|
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") {
|
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") {
|
SECTION("Network 1") {
|
||||||
REQUIRE(simpleSer.SerializeIF::deSerializeNe(&ptr, &len) == HasReturnvaluesIF::RETURN_OK);
|
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("Big Endian Simple") {
|
||||||
SECTION("Explicit") {
|
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);
|
HasReturnvaluesIF::RETURN_OK);
|
||||||
}
|
}
|
||||||
SECTION("Network 0") {
|
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") {
|
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.getU8() == 5);
|
||||||
CHECK(simpleSer.getU16() == 1);
|
CHECK(simpleSer.getU16() == 1);
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
#include <array>
|
#include <array>
|
||||||
#include <catch2/catch_test_macros.hpp>
|
#include <catch2/catch_test_macros.hpp>
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
#include "fsfw/tmtcpacket/ccsds/PacketId.h"
|
#include "fsfw/tmtcpacket/ccsds/PacketId.h"
|
||||||
|
#include "fsfw/tmtcpacket/ccsds/PacketSeqCtrl.h"
|
||||||
#include "fsfw/tmtcpacket/ccsds/header.h"
|
#include "fsfw/tmtcpacket/ccsds/header.h"
|
||||||
|
|
||||||
TEST_CASE("CCSDS Low Level", "[ccsds-ll]") {
|
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.raw() == 0x1ff);
|
||||||
REQUIRE(packetId.SerializeIF::serializeNe(buf.data(), buf.size()) ==
|
REQUIRE(packetId.SerializeIF::serializeNe(buf.data(), buf.size()) ==
|
||||||
HasReturnvaluesIF::RETURN_OK);
|
HasReturnvaluesIF::RETURN_OK);
|
||||||
REQUIRE(buf[0] == 0x1);
|
CHECK(buf[0] == 0x1);
|
||||||
REQUIRE(buf[1] == 0xff);
|
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") {
|
SECTION("From Raw") {
|
||||||
auto newId = PacketId(ccsds::PacketType::TC, true, 0x2ff);
|
auto newId = PacketId(ccsds::PacketType::TC, true, 0x2ff);
|
||||||
uint16_t rawId = newId.raw();
|
uint16_t rawId = newId.raw();
|
||||||
REQUIRE(rawId == 0x1aff);
|
CHECK(rawId == 0x1aff);
|
||||||
REQUIRE(PacketId::fromRaw(rawId) == newId);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -5,8 +5,9 @@
|
|||||||
#include "fsfw/tmtcpacket/ccsds/SpacePacketCreator.h"
|
#include "fsfw/tmtcpacket/ccsds/SpacePacketCreator.h"
|
||||||
|
|
||||||
TEST_CASE("CCSDS Creator", "[ccsds-creator]") {
|
TEST_CASE("CCSDS Creator", "[ccsds-creator]") {
|
||||||
auto params = SpacePacketParams(PacketId(ccsds::PacketType::TC, true, 0x02),
|
auto packetId = PacketId(ccsds::PacketType::TC, true, 0x02);
|
||||||
PacketSeqCtrl(ccsds::SequenceFlags::FIRST_SEGMENT, 0x34), 0x16);
|
auto psc = PacketSeqCtrl(ccsds::SequenceFlags::FIRST_SEGMENT, 0x34);
|
||||||
|
auto params = SpacePacketParams(packetId, psc, 0x16);
|
||||||
SpacePacketCreator base = SpacePacketCreator(params);
|
SpacePacketCreator base = SpacePacketCreator(params);
|
||||||
std::array<uint8_t, 6> buf{};
|
std::array<uint8_t, 6> buf{};
|
||||||
uint8_t* bufPtr = buf.data();
|
uint8_t* bufPtr = buf.data();
|
||||||
@ -21,15 +22,18 @@ TEST_CASE("CCSDS Creator", "[ccsds-creator]") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SECTION("Basic Test") {
|
SECTION("Basic Test") {
|
||||||
REQUIRE(base.isValid());
|
CHECK(base.isValid());
|
||||||
REQUIRE(base.getApid() == 0x02);
|
CHECK(base);
|
||||||
REQUIRE(base.getSequenceFlags() == ccsds::SequenceFlags::FIRST_SEGMENT);
|
CHECK(base.getApid() == 0x02);
|
||||||
REQUIRE(base.getVersion() == 0b000);
|
CHECK(base.getSequenceFlags() == ccsds::SequenceFlags::FIRST_SEGMENT);
|
||||||
REQUIRE(base.getSequenceCount() == 0x34);
|
CHECK(base.getVersion() == 0b000);
|
||||||
REQUIRE(base.getPacketDataLen() == 0x16);
|
CHECK(base.getSequenceCount() == 0x34);
|
||||||
REQUIRE(base.getPacketType() == ccsds::PacketType::TC);
|
CHECK(base.getPacketDataLen() == 0x16);
|
||||||
REQUIRE(base.getPacketIdRaw() == 0x1802);
|
CHECK(base.getPacketType() == ccsds::PacketType::TC);
|
||||||
REQUIRE(base.getSerializedSize() == 6);
|
CHECK(base.getPacketIdRaw() == 0x1802);
|
||||||
|
CHECK(base.getSerializedSize() == 6);
|
||||||
|
CHECK(base.getPacketSeqCtrl() == psc);
|
||||||
|
CHECK(base.getPacketId() == packetId);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("Deserialization Fails") {
|
SECTION("Deserialization Fails") {
|
||||||
@ -42,18 +46,18 @@ TEST_CASE("CCSDS Creator", "[ccsds-creator]") {
|
|||||||
SECTION("Raw Output") {
|
SECTION("Raw Output") {
|
||||||
REQUIRE(base.serializeNe(&bufPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
|
REQUIRE(base.serializeNe(&bufPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
|
||||||
// TC, and secondary header flag is set -> 0b0001100 -> 0x18
|
// TC, and secondary header flag is set -> 0b0001100 -> 0x18
|
||||||
REQUIRE(buf[0] == 0x18);
|
CHECK(buf[0] == 0x18);
|
||||||
// APID 0x02
|
// 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
|
// 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
|
// from the Sequence flag argument, which is the second bit for
|
||||||
// SequenceFlags.FIRST_SEGMENT
|
// SequenceFlags.FIRST_SEGMENT
|
||||||
REQUIRE(buf[2] == 0x40);
|
CHECK(buf[2] == 0x40);
|
||||||
// Sequence Count specified above
|
// 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)
|
// This byte and the next byte should be 22 big endian (packet length)
|
||||||
REQUIRE(buf[4] == 0x00);
|
CHECK(buf[4] == 0x00);
|
||||||
REQUIRE(buf[5] == 0x16);
|
CHECK(buf[5] == 0x16);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("All Ones Output") {
|
SECTION("All Ones Output") {
|
||||||
@ -63,19 +67,20 @@ TEST_CASE("CCSDS Creator", "[ccsds-creator]") {
|
|||||||
base.setDataLen(static_cast<int>(std::pow(2, 16)) - 1);
|
base.setDataLen(static_cast<int>(std::pow(2, 16)) - 1);
|
||||||
REQUIRE(base.isValid());
|
REQUIRE(base.isValid());
|
||||||
REQUIRE(base.serializeNe(&bufPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
|
REQUIRE(base.serializeNe(&bufPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
|
||||||
REQUIRE(buf[0] == 0x1F);
|
CHECK(buf[0] == 0x1F);
|
||||||
REQUIRE(buf[1] == 0xFF);
|
CHECK(buf[1] == 0xFF);
|
||||||
REQUIRE(buf[2] == 0xFF);
|
CHECK(buf[2] == 0xFF);
|
||||||
REQUIRE(buf[3] == 0xFF);
|
CHECK(buf[3] == 0xFF);
|
||||||
REQUIRE(buf[4] == 0xFF);
|
CHECK(buf[4] == 0xFF);
|
||||||
REQUIRE(buf[5] == 0xFF);
|
CHECK(buf[5] == 0xFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("Invalid APID") {
|
SECTION("Invalid APID") {
|
||||||
SpacePacketCreator invalid = SpacePacketCreator(
|
SpacePacketCreator creator = SpacePacketCreator(
|
||||||
ccsds::PacketType::TC, true, 0xFFFF, ccsds::SequenceFlags::FIRST_SEGMENT, 0x34, 0x16);
|
ccsds::PacketType::TC, true, 0xFFFF, ccsds::SequenceFlags::FIRST_SEGMENT, 0x34, 0x16);
|
||||||
REQUIRE(not invalid.isValid());
|
REQUIRE(not creator.isValid());
|
||||||
REQUIRE(invalid.serializeNe(&bufPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_FAILED);
|
REQUIRE(not creator);
|
||||||
|
REQUIRE(creator.serializeNe(&bufPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_FAILED);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("Invalid Seq Count") {
|
SECTION("Invalid Seq Count") {
|
||||||
|
2
unittests/tmtcservices/CMakeLists.txt
Normal file
2
unittests/tmtcservices/CMakeLists.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
target_sources(${FSFW_TEST_TGT} PRIVATE
|
||||||
|
)
|
3
unittests/tmtcservices/testStoreHelper.cpp
Normal file
3
unittests/tmtcservices/testStoreHelper.cpp
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
#include <catch2/catch_test_macros.hpp>
|
||||||
|
|
||||||
|
TEST_CASE("TM Store Helper", "[tm-store-helper]") {}
|
Loading…
Reference in New Issue
Block a user