added sp reader unittests
This commit is contained in:
parent
23f264096c
commit
08e0b0f1a0
@ -22,6 +22,12 @@ class SpacePacketIF {
|
||||
|
||||
virtual ~SpacePacketIF() = default;
|
||||
|
||||
/**
|
||||
* CCSDS header always has 6 bytes
|
||||
* @return
|
||||
*/
|
||||
static constexpr size_t getHeaderLen() { return ccsds::HEADER_LEN; }
|
||||
|
||||
/**
|
||||
* Returns the complete first two bytes of the packet, which together form
|
||||
* the CCSDS packet ID
|
||||
|
@ -8,6 +8,9 @@ SpacePacketReader::SpacePacketReader(const uint8_t* setAddress, size_t maxSize_)
|
||||
}
|
||||
|
||||
ReturnValue_t SpacePacketReader::checkSize() const {
|
||||
if (isNull()) {
|
||||
return HasReturnvaluesIF::RETURN_FAILED;
|
||||
}
|
||||
if (getFullPacketLen() > bufSize) {
|
||||
return SerializeIF::STREAM_TOO_SHORT;
|
||||
}
|
||||
@ -33,7 +36,9 @@ uint16_t SpacePacketReader::getPacketDataLen() const { return ccsds::getPacketLe
|
||||
ReturnValue_t SpacePacketReader::setInternalFields(const uint8_t* data, size_t maxSize_) {
|
||||
bufSize = maxSize_;
|
||||
spHeader = reinterpret_cast<const ccsds::PrimaryHeader*>(data);
|
||||
packetDataField = data + ccsds::HEADER_LEN;
|
||||
if (maxSize_ > 6) {
|
||||
packetDataField = data + ccsds::HEADER_LEN;
|
||||
}
|
||||
return checkSize();
|
||||
}
|
||||
|
||||
|
@ -62,11 +62,6 @@ class SpacePacketReader : public SpacePacketIF,
|
||||
*/
|
||||
[[nodiscard]] size_t getBufSize() const;
|
||||
|
||||
/**
|
||||
* CCSDS header always has 6 bytes
|
||||
* @return
|
||||
*/
|
||||
static constexpr size_t getHeaderLen() { return ccsds::HEADER_LEN; }
|
||||
[[nodiscard]] uint16_t getPacketIdRaw() const override;
|
||||
[[nodiscard]] uint16_t getPacketSeqCtrlRaw() const override;
|
||||
[[nodiscard]] uint16_t getPacketDataLen() const override;
|
||||
|
@ -1,7 +1,7 @@
|
||||
#include "header.h"
|
||||
|
||||
uint16_t ccsds::getPacketId(const PrimaryHeader &header) {
|
||||
return ((header.packetIdHAndVersion & 0x1F00) << 8) + header.packetIdL;
|
||||
return ((header.packetIdHAndVersion & 0x1F) << 8) + header.packetIdL;
|
||||
}
|
||||
|
||||
uint16_t ccsds::getPacketSeqCtrl(const PrimaryHeader &header) {
|
||||
|
@ -1,5 +1,54 @@
|
||||
#include <array>
|
||||
#include <catch2/catch_test_macros.hpp>
|
||||
|
||||
#include "fsfw/tmtcpacket/ccsds/SpacePacketCreator.h"
|
||||
#include "fsfw/tmtcpacket/ccsds/SpacePacketReader.h"
|
||||
|
||||
TEST_CASE("CCSDS Reader", "[ccsds-reader]") {}
|
||||
TEST_CASE("CCSDS Reader", "[ccsds-reader]") {
|
||||
auto params = SpacePacketParams(PacketId(ccsds::PacketType::TC, true, 0x02),
|
||||
PacketSeqCtrl(ccsds::SequenceFlags::FIRST_SEGMENT, 0x34), 0x16);
|
||||
SpacePacketCreator base = SpacePacketCreator(params);
|
||||
// This is enough to hold 0x16 (22) bytes + 6 (SP header length) + 1 as defined as the full packet
|
||||
// length derived from the length field
|
||||
std::array<uint8_t, 32> buf{};
|
||||
uint8_t* bufPtr = buf.data();
|
||||
size_t serLen = 0;
|
||||
SpacePacketReader reader;
|
||||
SECTION("Empty Reader") {
|
||||
REQUIRE(reader.isNull());
|
||||
REQUIRE(reader.checkSize() == HasReturnvaluesIF::RETURN_FAILED);
|
||||
}
|
||||
|
||||
SECTION("Basic Read") {
|
||||
REQUIRE(base.serialize(&bufPtr, &serLen, buf.size(), SerializeIF::Endianness::NETWORK) ==
|
||||
HasReturnvaluesIF::RETURN_OK);
|
||||
reader.setReadOnlyData(buf.data(), SpacePacketIF::getHeaderLen());
|
||||
REQUIRE(reader.getPacketDataLen() == 0x16);
|
||||
REQUIRE(reader.getFullData() == buf.data());
|
||||
REQUIRE(reader.getFullPacketLen() == 0x16 + SpacePacketReader::getHeaderLen() + 1);
|
||||
REQUIRE(reader.getPacketIdRaw() == 0x1802);
|
||||
REQUIRE(reader.getSequenceFlags() == ccsds::SequenceFlags::FIRST_SEGMENT);
|
||||
REQUIRE(reader.getSequenceCount() == 0x34);
|
||||
REQUIRE(reader.getPacketSeqCtrlRaw() == 0x4034);
|
||||
REQUIRE(reader.hasSecHeader());
|
||||
REQUIRE(reader.getApid() == 0x02);
|
||||
REQUIRE(not reader.isNull());
|
||||
// We only serialized the 6 bytes of the header, so the packer data should be invalid
|
||||
REQUIRE(reader.getPacketData() == nullptr);
|
||||
}
|
||||
|
||||
SECTION("Read with additional data") {
|
||||
REQUIRE(base.serialize(&bufPtr, &serLen, buf.size(), SerializeIF::Endianness::NETWORK) ==
|
||||
HasReturnvaluesIF::RETURN_OK);
|
||||
REQUIRE(reader.setReadOnlyData(buf.data(), buf.size()) == HasReturnvaluesIF::RETURN_OK);
|
||||
REQUIRE(reader.getPacketData() == buf.data() + SpacePacketIF::getHeaderLen());
|
||||
}
|
||||
|
||||
SECTION("Invalid Size") {
|
||||
for (size_t i = 0; i < 5; i++) {
|
||||
REQUIRE(reader.setReadOnlyData(buf.data(), i) == SerializeIF::STREAM_TOO_SHORT);
|
||||
REQUIRE(not reader.isNull());
|
||||
REQUIRE(reader.getPacketData() == nullptr);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user