fsfw/unittests/tmtcpacket/testPusTcReader.cpp

85 lines
3.4 KiB
C++
Raw 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") {
REQUIRE(creator.serialize(&dataPtr, &serLen, buf.size()) == HasReturnvaluesIF::RETURN_OK);
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;
REQUIRE(readerPtr->setReadOnlyData(buf.data(), serLen) == HasReturnvaluesIF::RETURN_OK);
REQUIRE(readerPtr->parseDataWithCrcCheck() == HasReturnvaluesIF::RETURN_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());
REQUIRE(readerPtr->parseDataWithCrcCheck() == HasReturnvaluesIF::RETURN_OK);
}
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") {
REQUIRE(creator.serialize(&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(reader.setReadOnlyData(buf.data(), serLen) == HasReturnvaluesIF::RETURN_OK);
buf[11] = 0x00;
REQUIRE(reader.parseDataWithoutCrcCheck() == HasReturnvaluesIF::RETURN_OK);
}
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-07-21 19:10:15 +02:00
REQUIRE(creator.serialize(&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();
REQUIRE(userDataPtr != nullptr);
REQUIRE(reader.getUserDataLen() == 3);
REQUIRE(userDataPtr[0] == 1);
REQUIRE(userDataPtr[1] == 2);
REQUIRE(userDataPtr[2] == 3);
}
}