From 05c4f4fadca0ba73f1e51bd4ac50d278df11aabd Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 18 Nov 2021 19:56:24 +0100 Subject: [PATCH] Bugfix for Packet ID getters - Also added related unittests --- src/fsfw/tmtcpacket/SpacePacket.h | 2 +- tests/src/fsfw_tests/unit/tmtcpacket/CMakeLists.txt | 2 +- tests/src/fsfw_tests/unit/tmtcpacket/testCcsds.cpp | 11 +++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 tests/src/fsfw_tests/unit/tmtcpacket/testCcsds.cpp diff --git a/src/fsfw/tmtcpacket/SpacePacket.h b/src/fsfw/tmtcpacket/SpacePacket.h index 166733192..a092712c6 100644 --- a/src/fsfw/tmtcpacket/SpacePacket.h +++ b/src/fsfw/tmtcpacket/SpacePacket.h @@ -73,7 +73,7 @@ namespace spacepacket { constexpr uint16_t getSpacePacketIdFromApid(bool isTc, uint16_t apid, bool secondaryHeaderFlag = true) { - return (((isTc << 5) & 0x10) | ((secondaryHeaderFlag << 4) & 0x08) | + return ((isTc << 4) | (secondaryHeaderFlag << 3) | ((apid >> 8) & 0x07)) << 8 | (apid & 0x00ff); } diff --git a/tests/src/fsfw_tests/unit/tmtcpacket/CMakeLists.txt b/tests/src/fsfw_tests/unit/tmtcpacket/CMakeLists.txt index 36838b24b..958bda405 100644 --- a/tests/src/fsfw_tests/unit/tmtcpacket/CMakeLists.txt +++ b/tests/src/fsfw_tests/unit/tmtcpacket/CMakeLists.txt @@ -1,3 +1,3 @@ target_sources(${FSFW_TEST_TGT} PRIVATE - PusTmTest.cpp + testCcsds.cpp ) diff --git a/tests/src/fsfw_tests/unit/tmtcpacket/testCcsds.cpp b/tests/src/fsfw_tests/unit/tmtcpacket/testCcsds.cpp new file mode 100644 index 000000000..8f5318052 --- /dev/null +++ b/tests/src/fsfw_tests/unit/tmtcpacket/testCcsds.cpp @@ -0,0 +1,11 @@ +#include + +#include "fsfw/tmtcpacket/SpacePacket.h" + +TEST_CASE( "CCSDS Test" , "[ccsds]") { + REQUIRE(spacepacket::getTcSpacePacketIdFromApid(0x22) == 0x1822); + REQUIRE(spacepacket::getTmSpacePacketIdFromApid(0x22) == 0x0822); + + REQUIRE(spacepacket::getTcSpacePacketIdFromApid(0x7ff) == 0x1fff); + REQUIRE(spacepacket::getTmSpacePacketIdFromApid(0x7ff) == 0xfff); +}