From 7e2fdc06cd53d31a946d0f6c4bf854a15a52bad8 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 18 Jul 2022 14:05:43 +0200 Subject: [PATCH] hmm this is problematic --- src/fsfw/tmtcpacket/SpacePacketCreator.cpp | 4 +-- src/fsfw/tmtcpacket/SpacePacketCreator.h | 3 ++- .../fsfw_tests/unit/tmtcpacket/testCcsds.cpp | 25 ++++++++++++++++--- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/fsfw/tmtcpacket/SpacePacketCreator.cpp b/src/fsfw/tmtcpacket/SpacePacketCreator.cpp index b02bae80..06df33c0 100644 --- a/src/fsfw/tmtcpacket/SpacePacketCreator.cpp +++ b/src/fsfw/tmtcpacket/SpacePacketCreator.cpp @@ -23,8 +23,7 @@ SpacePacketCreator::SpacePacketCreator(ccsds::PacketType packetType, bool secHea return; } version = version_; - packetId = - (version_ << 13) | (static_cast(packetType) << 12) | (secHeaderFlag << 11) | apid; + packetId = (static_cast(packetType) << 12) | (static_cast(secHeaderFlag) << 11) | apid; packetSeqCtrl = static_cast(seqFlags) << 14 | seqCount; dataLen = dataLen_; } @@ -53,3 +52,4 @@ ReturnValue_t SpacePacketCreator::deSerialize(const uint8_t **buffer, size_t *si SerializeIF::Endianness streamEndianness) { return HasReturnvaluesIF::RETURN_FAILED; } +bool SpacePacketCreator::isValid() const { return valid; } diff --git a/src/fsfw/tmtcpacket/SpacePacketCreator.h b/src/fsfw/tmtcpacket/SpacePacketCreator.h index 79ea47dc..f99cb9dd 100644 --- a/src/fsfw/tmtcpacket/SpacePacketCreator.h +++ b/src/fsfw/tmtcpacket/SpacePacketCreator.h @@ -11,7 +11,7 @@ class SpacePacketCreator : public SerializeIF, public SpacePacketIF { uint8_t version = 0); SpacePacketCreator(uint16_t packetId, uint16_t packetSeqCtrl, uint16_t dataLen, uint8_t version = 0); - bool valid; + [[nodiscard]] bool isValid() const; [[nodiscard]] uint16_t getPacketId() const override; [[nodiscard]] uint16_t getPacketSeqCtrl() const override; [[nodiscard]] uint16_t getPacketDataLen() const override; @@ -22,6 +22,7 @@ class SpacePacketCreator : public SerializeIF, public SpacePacketIF { Endianness streamEndianness) override; private: + bool valid; uint16_t packetId; uint16_t packetSeqCtrl; uint16_t dataLen; diff --git a/tests/src/fsfw_tests/unit/tmtcpacket/testCcsds.cpp b/tests/src/fsfw_tests/unit/tmtcpacket/testCcsds.cpp index 0925cdc7..93cea57a 100644 --- a/tests/src/fsfw_tests/unit/tmtcpacket/testCcsds.cpp +++ b/tests/src/fsfw_tests/unit/tmtcpacket/testCcsds.cpp @@ -1,9 +1,14 @@ +#include #include #include "fsfw/tmtcpacket/SpacePacketCreator.h" #include "fsfw/tmtcpacket/SpacePacketReader.h" TEST_CASE("CCSDS Test", "[ccsds]") { + SpacePacketCreator base = SpacePacketCreator( + ccsds::PacketType::TC, true, 0x02, + ccsds::SequenceFlags::FIRST_SEGMENT, 0x34, 0x16); + SECTION("Constexpr Helpers") { REQUIRE(ccsds::getTcSpacePacketIdFromApid(0x22) == 0x1822); REQUIRE(ccsds::getTmSpacePacketIdFromApid(0x22) == 0x0822); @@ -12,15 +17,27 @@ TEST_CASE("CCSDS Test", "[ccsds]") { REQUIRE(ccsds::getTmSpacePacketIdFromApid(0x7ff) == 0xfff); } - SECTION("Header Creator Tests") { - SpacePacketCreator base = SpacePacketCreator( - ccsds::PacketType::TC, true, 0x02, - ccsds::SequenceFlags::FIRST_SEGMENT, 0x34, 0x16); + SECTION("Basic Test") { + REQUIRE(base.isValid()); REQUIRE(base.getApid() == 0x02); REQUIRE(base.getSequenceFlags() == ccsds::SequenceFlags::FIRST_SEGMENT); REQUIRE(base.getVersion() == 0b000); REQUIRE(base.getSequenceCount() == 0x34); REQUIRE(base.getPacketDataLen() == 0x16); REQUIRE(base.getPacketType() == ccsds::PacketType::TC); + REQUIRE(base.getPacketId() == 0x1802); + } + + SECTION("Raw Output") { + std::array buf {}; + uint8_t* bufPtr = buf.data(); + size_t serLen = 0; + base.serialize(&bufPtr, &serLen, buf.size(), SerializeIF::Endianness::MACHINE); + REQUIRE(buf[0] == 0x18); + REQUIRE(buf[1] == 0x02); + REQUIRE(buf[2] == 0x40); + REQUIRE(buf[3] == 0x34); + REQUIRE(buf[4] == 0x00); + REQUIRE(buf[5] == 0x16); } }