From 3502ddca7ff29d443bb6991d18c683496d26c313 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 5 Oct 2021 13:13:36 +0200 Subject: [PATCH] using pus version enum now --- src/fsfw/tmtcpacket/pus/definitions.h | 16 ++++++++++++++++ src/fsfw/tmtcpacket/pus/tc/TcPacketPus.cpp | 11 +++++------ src/fsfw/tmtcpacket/pus/tc/TcPacketPus.h | 4 +++- src/fsfw/tmtcpacket/pus/tc/TcPacketStoredPus.cpp | 7 ++++++- src/fsfw/tmtcpacket/pus/tm/TmPacketPusA.cpp | 7 ++++--- src/fsfw/tmtcpacket/pus/tm/TmPacketPusA.h | 3 --- src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.cpp | 8 +++++--- 7 files changed, 39 insertions(+), 17 deletions(-) create mode 100644 src/fsfw/tmtcpacket/pus/definitions.h diff --git a/src/fsfw/tmtcpacket/pus/definitions.h b/src/fsfw/tmtcpacket/pus/definitions.h new file mode 100644 index 00000000..d92ab312 --- /dev/null +++ b/src/fsfw/tmtcpacket/pus/definitions.h @@ -0,0 +1,16 @@ +#ifndef FSFW_SRC_FSFW_TMTCPACKET_PUS_TM_DEFINITIONS_H_ +#define FSFW_SRC_FSFW_TMTCPACKET_PUS_TM_DEFINITIONS_H_ + +#include + +namespace pus { + +//! Version numbers according to ECSS-E-ST-70-41C p.439 +enum PusVersion: uint8_t { + PUS_A_VERSION = 1, + PUS_C_VERSION = 2 +}; + +} + +#endif /* FSFW_SRC_FSFW_TMTCPACKET_PUS_TM_DEFINITIONS_H_ */ diff --git a/src/fsfw/tmtcpacket/pus/tc/TcPacketPus.cpp b/src/fsfw/tmtcpacket/pus/tc/TcPacketPus.cpp index 28533754..2b97b0d2 100644 --- a/src/fsfw/tmtcpacket/pus/tc/TcPacketPus.cpp +++ b/src/fsfw/tmtcpacket/pus/tc/TcPacketPus.cpp @@ -1,4 +1,4 @@ -#include "fsfw/tmtcpacket/pus/tc/TcPacketPus.h" +#include "TcPacketPus.h" #include "fsfw/globalfunctions/CRC.h" #include @@ -8,14 +8,13 @@ TcPacketPus::TcPacketPus(const uint8_t *setData): TcPacketBase(setData) { } void TcPacketPus::initializeTcPacket(uint16_t apid, uint16_t sequenceCount, - uint8_t ack, uint8_t service, uint8_t subservice, uint16_t sourceId) { + uint8_t ack, uint8_t service, uint8_t subservice, pus::PusVersion pusVersion, + uint16_t sourceId) { initSpacePacketHeader(true, true, apid, sequenceCount); std::memset(&tcData->dataField, 0, sizeof(tcData->dataField)); setPacketDataLength(sizeof(PUSTcDataFieldHeader) + CRC_SIZE - 1); - // Data Field Header: - // Set CCSDS_secondary_header_flag to 0 and version number to 001 - tcData->dataField.versionTypeAck = 0b00010000; - tcData->dataField.versionTypeAck |= (ack & 0x0F); + // Data Field Header. For PUS A, the first bit (CCSDS Secondary Header Flag) is zero + tcData->dataField.versionTypeAck = pusVersion << 4 | (ack & 0x0F); tcData->dataField.serviceType = service; tcData->dataField.serviceSubtype = subservice; #if FSFW_USE_PUS_C_TELECOMMANDS == 1 diff --git a/src/fsfw/tmtcpacket/pus/tc/TcPacketPus.h b/src/fsfw/tmtcpacket/pus/tc/TcPacketPus.h index 082541ba..1bacc3a7 100644 --- a/src/fsfw/tmtcpacket/pus/tc/TcPacketPus.h +++ b/src/fsfw/tmtcpacket/pus/tc/TcPacketPus.h @@ -2,6 +2,7 @@ #define FSFW_TMTCPACKET_PUS_TCPACKETPUSA_H_ #include "fsfw/FSFW.h" +#include "../definitions.h" #include "fsfw/tmtcpacket/ccsds_header.h" #include "TcPacketBase.h" @@ -75,7 +76,8 @@ protected: * @param subservice PUS Subservice */ void initializeTcPacket(uint16_t apid, uint16_t sequenceCount, uint8_t ack, - uint8_t service, uint8_t subservice, uint16_t sourceId = 0); + uint8_t service, uint8_t subservice, pus::PusVersion pusVersion, + uint16_t sourceId = 0); /** * A pointer to a structure which defines the data structure of diff --git a/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredPus.cpp b/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredPus.cpp index 5ea9f5b1..7f8f4ac8 100644 --- a/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredPus.cpp +++ b/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredPus.cpp @@ -23,7 +23,12 @@ TcPacketStoredPus::TcPacketStoredPus(uint16_t apid, uint8_t service, return; } this->setData(pData); - initializeTcPacket(apid, sequenceCount, ack, service, subservice); +#if FSFW_USE_PUS_C_TELECOMMANDS == 1 + pus::PusVersion pusVersion = pus::PusVersion::PUS_C_VERSION; +#else + pus::PusVersion pusVersion = pus::PusVersion::PUS_A_VERSION; +#endif + initializeTcPacket(apid, sequenceCount, ack, service, subservice, pusVersion); std::memcpy(&tcData->appData, data, size); this->setPacketDataLength( size + sizeof(PUSTcDataFieldHeader) + CRC_SIZE - 1); diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketPusA.cpp b/src/fsfw/tmtcpacket/pus/tm/TmPacketPusA.cpp index a70fc45e..ccf5a8ac 100644 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketPusA.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketPusA.cpp @@ -1,5 +1,6 @@ -#include "fsfw/tmtcpacket/pus/tm/TmPacketPusA.h" -#include "fsfw/tmtcpacket/pus/tm/TmPacketBase.h" +#include "../definitions.h" +#include "TmPacketPusA.h" +#include "TmPacketBase.h" #include "fsfw/globalfunctions/CRC.h" #include "fsfw/globalfunctions/arrayprinter.h" @@ -62,7 +63,7 @@ void TmPacketPusA::initializeTmPacket(uint16_t apid, uint8_t service, //First, set to zero. memset(&tmData->data_field, 0, sizeof(tmData->data_field)); - tmData->data_field.version_type_ack = TM_PUS_VERSION_NUMBER << 4; + tmData->data_field.version_type_ack = pus::PusVersion::PUS_A_VERSION << 4; tmData->data_field.service_type = service; tmData->data_field.service_subtype = subservice; tmData->data_field.subcounter = packetSubcounter; diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketPusA.h b/src/fsfw/tmtcpacket/pus/tm/TmPacketPusA.h index 839a6302..3856c779 100644 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketPusA.h +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketPusA.h @@ -52,9 +52,6 @@ public: sizeof(PUSTmDataFieldHeaderPusA) + 2); //! Maximum size of a TM Packet in this mission. static const uint32_t MISSION_TM_PACKET_MAX_SIZE = fsfwconfig::FSFW_MAX_TM_PACKET_SIZE; - //! First four bits of first byte of secondary header. Set to 1 according - //! to ECSS-E-ST-70-41C p.439 - static constexpr uint8_t TM_PUS_VERSION_NUMBER = 1; /** * This is the default constructor. diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.cpp b/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.cpp index e309843d..003d565e 100644 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.cpp @@ -1,5 +1,6 @@ -#include "fsfw/tmtcpacket/pus/tm/TmPacketPusC.h" -#include "fsfw/tmtcpacket/pus/tm/TmPacketBase.h" +#include "../definitions.h" +#include "TmPacketPusC.h" +#include "TmPacketBase.h" #include "fsfw/globalfunctions/CRC.h" #include "fsfw/globalfunctions/arrayprinter.h" @@ -67,7 +68,8 @@ ReturnValue_t TmPacketPusC::initializeTmPacket(uint16_t apid, uint8_t service, /* Only account for last 4 bytes for time reference field */ timeRefField &= 0b1111; - tmData->dataField.versionTimeReferenceField = (TM_PUS_VERSION_NUMBER << 4) | timeRefField; + tmData->dataField.versionTimeReferenceField = + (pus::PusVersion::PUS_C_VERSION << 4) | timeRefField; tmData->dataField.serviceType = service; tmData->dataField.serviceSubtype = subservice; tmData->dataField.subcounterMsb = packetSubcounter << 8 & 0xff;