2022-07-22 18:46:58 +02:00
|
|
|
#include <array>
|
|
|
|
#include <catch2/catch_test_macros.hpp>
|
2022-07-23 11:43:48 +02:00
|
|
|
#include <cmath>
|
2022-07-22 18:46:58 +02:00
|
|
|
|
|
|
|
#include "fsfw/tmtcpacket/ccsds/PacketId.h"
|
2022-07-23 11:43:48 +02:00
|
|
|
#include "fsfw/tmtcpacket/ccsds/PacketSeqCtrl.h"
|
2022-07-22 18:46:58 +02:00
|
|
|
#include "fsfw/tmtcpacket/ccsds/header.h"
|
|
|
|
|
|
|
|
TEST_CASE("CCSDS Low Level", "[ccsds-ll]") {
|
|
|
|
SECTION("Lowlevel Header Packet ID test") {
|
|
|
|
ccsds::PrimaryHeader header{};
|
|
|
|
uint16_t packetIdRaw = 0x3ff;
|
|
|
|
ccsds::setPacketId(header, packetIdRaw);
|
|
|
|
REQUIRE(header.packetIdHAndVersion == 3);
|
|
|
|
REQUIRE(header.packetIdL == 0xff);
|
|
|
|
REQUIRE(ccsds::getPacketId(header) == 0x3ff);
|
|
|
|
header.packetIdHAndVersion |= 0b00100000;
|
|
|
|
REQUIRE(ccsds::getPacketId(header) == 0x3ff);
|
|
|
|
REQUIRE(ccsds::getVersion(header) == 0b001);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("Lowlevel Header APID Test") {
|
|
|
|
ccsds::PrimaryHeader header{};
|
|
|
|
uint16_t packetIdRaw = 0x3ff;
|
|
|
|
ccsds::setPacketId(header, packetIdRaw);
|
|
|
|
ccsds::setApid(header, 0x1ff);
|
2022-07-27 21:06:23 +02:00
|
|
|
REQUIRE(ccsds::getPacketId(header) == 0x3ff);
|
2022-07-22 18:46:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("Lowlevel Packet Length Test") {
|
|
|
|
ccsds::PrimaryHeader header{};
|
|
|
|
header.packetLenH = 0x02;
|
|
|
|
header.packetLenL = 0x03;
|
|
|
|
REQUIRE(ccsds::getPacketLen(header) == 0x0203);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE("CCSDS Packet ID", "[ccsds-packet-id]") {
|
|
|
|
PacketId packetId;
|
|
|
|
std::array<uint8_t, 3> buf{};
|
|
|
|
SECTION("Basic") {
|
|
|
|
packetId.apid = 0x1ff;
|
|
|
|
packetId.secHeaderFlag = false;
|
|
|
|
packetId.packetType = ccsds::PacketType::TM;
|
2022-07-27 21:29:05 +02:00
|
|
|
size_t serLen = 0;
|
2022-07-22 18:46:58 +02:00
|
|
|
REQUIRE(packetId.raw() == 0x1ff);
|
2022-07-27 21:29:05 +02:00
|
|
|
REQUIRE(packetId.SerializeIF::serializeBe(buf.data(), serLen, buf.size()) ==
|
2022-07-22 18:46:58 +02:00
|
|
|
HasReturnvaluesIF::RETURN_OK);
|
2022-07-23 11:43:48 +02:00
|
|
|
CHECK(buf[0] == 0x1);
|
|
|
|
CHECK(buf[1] == 0xff);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("Invalid Ser") {
|
2022-07-27 21:29:05 +02:00
|
|
|
size_t serLen = 0;
|
|
|
|
REQUIRE(packetId.SerializeIF::serializeBe(buf.data(), serLen, 0) ==
|
|
|
|
SerializeIF::BUFFER_TOO_SHORT);
|
|
|
|
REQUIRE(packetId.SerializeIF::serializeBe(buf.data(), serLen, 1) ==
|
|
|
|
SerializeIF::BUFFER_TOO_SHORT);
|
2022-07-23 11:43:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("Invalid Deser") {
|
2022-07-27 21:29:05 +02:00
|
|
|
size_t deserLen = 0;
|
|
|
|
REQUIRE(packetId.SerializeIF::deSerialize(buf.data(), deserLen, 1) ==
|
|
|
|
SerializeIF::STREAM_TOO_SHORT);
|
|
|
|
REQUIRE(packetId.SerializeIF::deSerialize(buf.data(), deserLen, 0) ==
|
|
|
|
SerializeIF::STREAM_TOO_SHORT);
|
2022-07-22 18:46:58 +02:00
|
|
|
}
|
2022-07-23 10:24:56 +02:00
|
|
|
|
|
|
|
SECTION("From Raw") {
|
|
|
|
auto newId = PacketId(ccsds::PacketType::TC, true, 0x2ff);
|
|
|
|
uint16_t rawId = newId.raw();
|
2022-07-23 11:43:48 +02:00
|
|
|
CHECK(rawId == 0x1aff);
|
|
|
|
CHECK(PacketId::fromRaw(rawId) == newId);
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("Deserialize") {
|
|
|
|
buf[0] = 0x1a;
|
|
|
|
buf[1] = 0xff;
|
2022-07-27 21:29:05 +02:00
|
|
|
size_t deserLen = 0xff;
|
|
|
|
REQUIRE(packetId.SerializeIF::deSerialize(buf.data(), deserLen, buf.size()) ==
|
2022-07-23 11:43:48 +02:00
|
|
|
HasReturnvaluesIF::RETURN_OK);
|
|
|
|
CHECK(packetId.apid == 0x2ff);
|
2022-07-27 21:29:05 +02:00
|
|
|
CHECK(deserLen == 2);
|
2022-07-23 11:43:48 +02:00
|
|
|
CHECK(packetId.packetType == ccsds::PacketType::TC);
|
|
|
|
CHECK(packetId.secHeaderFlag == true);
|
2022-07-23 10:24:56 +02:00
|
|
|
}
|
2022-07-22 18:46:58 +02:00
|
|
|
}
|
|
|
|
|
2022-07-23 11:43:48 +02:00
|
|
|
TEST_CASE("CCSDS Packet Seq Ctrl", "[ccsds-packet-seq-ctrl]") {
|
|
|
|
PacketSeqCtrl psc;
|
|
|
|
std::array<uint8_t, 3> buf{};
|
|
|
|
SECTION("Basic") {
|
2022-07-27 21:29:05 +02:00
|
|
|
size_t serLen = 0xff;
|
2022-07-23 11:43:48 +02:00
|
|
|
psc.seqFlags = ccsds::SequenceFlags::FIRST_SEGMENT;
|
|
|
|
psc.seqCount = static_cast<uint16_t>(std::round(std::pow(2, 14) - 1));
|
|
|
|
REQUIRE(psc.raw() == 0x7fff);
|
2022-07-27 21:29:05 +02:00
|
|
|
REQUIRE(psc.SerializeIF::serializeBe(buf.data(), serLen, buf.size()) ==
|
|
|
|
HasReturnvaluesIF::RETURN_OK);
|
2022-07-23 11:43:48 +02:00
|
|
|
CHECK(buf[0] == 0x7f);
|
|
|
|
CHECK(buf[1] == 0xff);
|
2022-07-27 21:29:05 +02:00
|
|
|
CHECK(serLen == 2);
|
2022-07-23 11:43:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2022-07-27 21:29:05 +02:00
|
|
|
size_t deserLen = 0xff;
|
|
|
|
REQUIRE(psc.SerializeIF::deSerialize(buf.data(), deserLen, buf.size()) ==
|
|
|
|
HasReturnvaluesIF::RETURN_OK);
|
2022-07-23 11:43:48 +02:00
|
|
|
CHECK(psc.seqFlags == ccsds::SequenceFlags::LAST_SEGMENT);
|
2022-07-27 21:29:05 +02:00
|
|
|
CHECK(deserLen == 2);
|
2022-07-23 11:43:48 +02:00
|
|
|
CHECK(psc.seqCount == static_cast<uint16_t>(std::round(std::pow(2, 14) - 2)));
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("Invalid Ser") {
|
2022-07-27 21:29:05 +02:00
|
|
|
size_t deserLen = 0;
|
|
|
|
REQUIRE(psc.SerializeIF::serializeBe(buf.data(), deserLen, 0) == SerializeIF::BUFFER_TOO_SHORT);
|
|
|
|
REQUIRE(psc.SerializeIF::serializeBe(buf.data(), deserLen, 1) == SerializeIF::BUFFER_TOO_SHORT);
|
2022-07-23 11:43:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("Invalid Deser") {
|
2022-07-27 21:29:05 +02:00
|
|
|
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);
|
2022-07-23 11:43:48 +02:00
|
|
|
}
|
|
|
|
}
|