fsfw/unittests/tmtcpacket/testPusTcReader.cpp

85 lines
3.3 KiB
C++
Raw Permalink Normal View History

2022-07-21 19:10:15 +02:00
#include <array>
#include <catch2/catch_test_macros.hpp>
#include "fsfw/tmtcpacket/pus/tc/PusTcCreator.h"
#include "fsfw/tmtcpacket/pus/tc/PusTcReader.h"
TEST_CASE("PUS TC Reader", "[pus-tc-reader]") {
auto packetId = PacketId(ccsds::PacketType::TC, true, 0x02);
auto spParams =
SpacePacketParams(packetId, PacketSeqCtrl(ccsds::SequenceFlags::UNSEGMENTED, 0x34), 0x00);
auto pusParams = PusTcParams(17, 1);
PusTcCreator creator(spParams, pusParams);
std::array<uint8_t, 32> buf{};
uint8_t* dataPtr = buf.data();
size_t serLen = 0;
PusTcReader reader;
SECTION("State") {
2022-08-16 01:08:26 +02:00
REQUIRE(creator.serializeBe(&dataPtr, &serLen, buf.size()) == returnvalue::OK);
2022-07-21 19:10:15 +02:00
REQUIRE(reader.isNull());
2022-07-22 18:22:35 +02:00
REQUIRE(not reader);
2022-07-22 17:09:44 +02:00
PusTcReader* readerPtr = nullptr;
bool callDelete = false;
2022-07-21 19:10:15 +02:00
SECTION("Setter") {
2022-07-22 17:09:44 +02:00
readerPtr = &reader;
2022-08-16 01:08:26 +02:00
REQUIRE(readerPtr->setReadOnlyData(buf.data(), serLen) == returnvalue::OK);
REQUIRE(readerPtr->parseDataWithCrcCheck() == returnvalue::OK);
2022-07-21 19:10:15 +02:00
}
SECTION("Directly Constructed") {
2022-07-22 17:09:44 +02:00
callDelete = true;
readerPtr = new PusTcReader(buf.data(), serLen);
REQUIRE(not readerPtr->isNull());
2022-08-16 01:08:26 +02:00
REQUIRE(readerPtr->parseDataWithCrcCheck() == returnvalue::OK);
2022-07-22 17:09:44 +02:00
}
REQUIRE(not readerPtr->isNull());
2022-07-22 18:22:35 +02:00
REQUIRE(*readerPtr);
2022-07-22 17:09:44 +02:00
REQUIRE(readerPtr->getPacketType() == ccsds::PacketType::TC);
REQUIRE(readerPtr->getApid() == 0x02);
REQUIRE(readerPtr->getService() == 17);
REQUIRE(readerPtr->getSubService() == 1);
REQUIRE(readerPtr->getFullPacketLen() == 13);
REQUIRE(readerPtr->getPacketDataLen() == 6);
REQUIRE(readerPtr->getPusVersion() == 2);
REQUIRE(readerPtr->getSequenceCount() == 0x34);
REQUIRE(readerPtr->getUserData() == nullptr);
REQUIRE(readerPtr->getUserDataLen() == 0);
REQUIRE(readerPtr->getFullData() == buf.data());
REQUIRE(readerPtr->getSourceId() == 0x00);
REQUIRE(readerPtr->getAcknowledgeFlags() == 0b1111);
// This value was verified to be correct
REQUIRE(readerPtr->getErrorControl() == 0xee63);
if (callDelete) {
delete readerPtr;
2022-07-21 19:10:15 +02:00
}
}
SECTION("Invalid CRC") {
2022-08-16 01:08:26 +02:00
REQUIRE(creator.serializeBe(&dataPtr, &serLen, buf.size()) == returnvalue::OK);
REQUIRE(reader.setReadOnlyData(buf.data(), serLen) == returnvalue::OK);
2022-07-21 19:10:15 +02:00
buf[11] = 0x00;
REQUIRE(reader.parseDataWithCrcCheck() == PusIF::INVALID_CRC_16);
}
SECTION("Invalid CRC but no check") {
2022-08-16 01:08:26 +02:00
REQUIRE(creator.serializeBe(&dataPtr, &serLen, buf.size()) == returnvalue::OK);
REQUIRE(reader.setReadOnlyData(buf.data(), serLen) == returnvalue::OK);
2022-07-21 19:10:15 +02:00
buf[11] = 0x00;
2022-08-16 01:08:26 +02:00
REQUIRE(reader.parseDataWithoutCrcCheck() == returnvalue::OK);
2022-07-21 19:10:15 +02:00
}
SECTION("With application data") {
auto& params = creator.getPusParams();
std::array<uint8_t, 3> data{1, 2, 3};
2022-07-22 17:09:44 +02:00
creator.setRawUserData(data.data(), data.size());
2022-08-16 01:08:26 +02:00
REQUIRE(creator.serializeBe(&dataPtr, &serLen, buf.size()) == returnvalue::OK);
REQUIRE(reader.setReadOnlyData(buf.data(), serLen) == returnvalue::OK);
REQUIRE(reader.parseDataWithCrcCheck() == returnvalue::OK);
2022-07-21 19:10:15 +02:00
const uint8_t* userDataPtr = reader.getUserData();
REQUIRE(userDataPtr != nullptr);
REQUIRE(reader.getUserDataLen() == 3);
REQUIRE(userDataPtr[0] == 1);
REQUIRE(userDataPtr[1] == 2);
REQUIRE(userDataPtr[2] == 3);
}
}