From 94bd4c7b56f9f22cdec118df8e681ed30a2f47b3 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 5 Oct 2021 01:23:56 +0200 Subject: [PATCH 1/6] using correct version number now --- src/fsfw/tmtcpacket/pus/tm/TmPacketBase.h | 2 -- src/fsfw/tmtcpacket/pus/tm/TmPacketPusA.cpp | 7 +------ src/fsfw/tmtcpacket/pus/tm/TmPacketPusA.h | 3 +++ src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.cpp | 2 +- src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.h | 3 +++ src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusA.cpp | 3 +-- src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusC.cpp | 3 +-- 7 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketBase.h b/src/fsfw/tmtcpacket/pus/tm/TmPacketBase.h index 0379b977..31bfe3c8 100644 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketBase.h +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketBase.h @@ -31,8 +31,6 @@ public: //! Maximum size of a TM Packet in this mission. //! TODO: Make this dependant on a config variable. static const uint32_t MISSION_TM_PACKET_MAX_SIZE = 2048; - //! First four bits of first byte of secondary header - static const uint8_t VERSION_NUMBER_BYTE = 0b00010000; /** * This is the default constructor. diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketPusA.cpp b/src/fsfw/tmtcpacket/pus/tm/TmPacketPusA.cpp index c6540af5..a70fc45e 100644 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketPusA.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketPusA.cpp @@ -62,12 +62,7 @@ void TmPacketPusA::initializeTmPacket(uint16_t apid, uint8_t service, //First, set to zero. memset(&tmData->data_field, 0, sizeof(tmData->data_field)); - // NOTE: In PUS-C, the PUS Version is 2 and specified for the first 4 bits. - // The other 4 bits of the first byte are the spacecraft time reference - // status. To change to PUS-C, set 0b00100000. - // Set CCSDS_secondary header flag to 0, version number to 001 and ack - // to 0000 - tmData->data_field.version_type_ack = 0b00010000; + tmData->data_field.version_type_ack = TM_PUS_VERSION_NUMBER << 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 3856c779..839a6302 100644 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketPusA.h +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketPusA.h @@ -52,6 +52,9 @@ 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 2c6e1d97..e309843d 100644 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.cpp @@ -67,7 +67,7 @@ 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 = VERSION_NUMBER_BYTE | timeRefField; + tmData->dataField.versionTimeReferenceField = (TM_PUS_VERSION_NUMBER << 4) | timeRefField; tmData->dataField.serviceType = service; tmData->dataField.serviceSubtype = subservice; tmData->dataField.subcounterMsb = packetSubcounter << 8 & 0xff; diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.h b/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.h index 3a9be132..e5dee662 100644 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.h +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.h @@ -54,6 +54,9 @@ public: sizeof(PUSTmDataFieldHeaderPusC) + 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 2 according + //! to ECSS-E-ST-70-41C p.439 + static constexpr uint8_t TM_PUS_VERSION_NUMBER = 2; /** * This is the default constructor. diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusA.cpp b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusA.cpp index 538dc95e..6f249667 100644 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusA.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusA.cpp @@ -29,8 +29,7 @@ TmPacketStoredPusA::TmPacketStoredPusA(uint16_t apid, uint8_t service, initializeTmPacket(apid, service, subservice, packetSubcounter); memcpy(getSourceData(), headerData, headerSize); memcpy(getSourceData() + headerSize, data, size); - setPacketDataLength( - size + headerSize + sizeof(PUSTmDataFieldHeaderPusA) + CRC_SIZE - 1); + setPacketDataLength(size + headerSize + sizeof(PUSTmDataFieldHeaderPusA) + CRC_SIZE - 1); } TmPacketStoredPusA::TmPacketStoredPusA(uint16_t apid, uint8_t service, diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusC.cpp b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusC.cpp index 7f75407d..570d9d4e 100644 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusC.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusC.cpp @@ -30,8 +30,7 @@ TmPacketStoredPusC::TmPacketStoredPusC(uint16_t apid, uint8_t service, initializeTmPacket(apid, service, subservice, packetSubcounter, destinationId, timeRefField); memcpy(getSourceData(), headerData, headerSize); memcpy(getSourceData() + headerSize, data, size); - setPacketDataLength( - size + headerSize + sizeof(PUSTmDataFieldHeaderPusC) + CRC_SIZE - 1); + setPacketDataLength(size + headerSize + sizeof(PUSTmDataFieldHeaderPusC) + CRC_SIZE - 1); } TmPacketStoredPusC::TmPacketStoredPusC(uint16_t apid, uint8_t service, -- 2.43.0 From a8a1148c65d0f4b7249374bbc31244762ca6765b Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 5 Oct 2021 12:39:57 +0200 Subject: [PATCH 2/6] fixes for PUS A stored --- .../tmtcpacket/pus/tm/TmPacketStoredPusA.cpp | 49 +++++++++++++++---- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusA.cpp b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusA.cpp index 6f249667..3b183f09 100644 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusA.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusA.cpp @@ -29,7 +29,8 @@ TmPacketStoredPusA::TmPacketStoredPusA(uint16_t apid, uint8_t service, initializeTmPacket(apid, service, subservice, packetSubcounter); memcpy(getSourceData(), headerData, headerSize); memcpy(getSourceData() + headerSize, data, size); - setPacketDataLength(size + headerSize + sizeof(PUSTmDataFieldHeaderPusA) + CRC_SIZE - 1); + setPacketDataLength( + size + headerSize + sizeof(PUSTmDataFieldHeaderPusA) + CRC_SIZE - 1); } TmPacketStoredPusA::TmPacketStoredPusA(uint16_t apid, uint8_t service, @@ -41,32 +42,60 @@ TmPacketStoredPusA::TmPacketStoredPusA(uint16_t apid, uint8_t service, return; } size_t sourceDataSize = 0; - if (content != NULL) { + if (content != nullptr) { sourceDataSize += content->getSerializedSize(); } - if (header != NULL) { + if (header != nullptr) { sourceDataSize += header->getSerializedSize(); } - uint8_t *p_data = NULL; + uint8_t *pData = nullptr; + size_t sizeToReserve = getPacketMinimumSize() + sourceDataSize; ReturnValue_t returnValue = store->getFreeElement(&storeAddress, - (getPacketMinimumSize() + sourceDataSize), &p_data); + sizeToReserve, &pData); if (returnValue != store->RETURN_OK) { TmPacketStoredBase::checkAndReportLostTm(); +#if FSFW_VERBOSE_LEVEL >= 1 + switch(returnValue) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + case(StorageManagerIF::DATA_STORAGE_FULL): { + sif::warning << "TmPacketStoredPusA::TmPacketStoredPusC: Store full for packet with " + "size " << sizeToReserve << std::endl; + break; + } + case(StorageManagerIF::DATA_TOO_LARGE): { + sif::warning << "TmPacketStoredPusA::TmPacketStoredPusC: Data with size " << + sizeToReserve << " too large" << std::endl; + break; + } +#else + case(StorageManagerIF::DATA_STORAGE_FULL): { + sif::printWarning("TmPacketStoredPusA::TmPacketStoredPusC: Store full for packet with " + "size %d\n", sizeToReserve); + break; + } + case(StorageManagerIF::DATA_TOO_LARGE): { + sif::printWarning("TmPacketStoredPusA::TmPacketStoredPusC: Data with size " + "%d too large\n", sizeToReserve); + break; + } +#endif +#endif + } + return; } - setData(p_data); + setData(pData); initializeTmPacket(apid, service, subservice, packetSubcounter); uint8_t *putDataHere = getSourceData(); size_t size = 0; - if (header != NULL) { + if (header != nullptr) { header->serialize(&putDataHere, &size, sourceDataSize, SerializeIF::Endianness::BIG); } - if (content != NULL) { + if (content != nullptr) { content->serialize(&putDataHere, &size, sourceDataSize, SerializeIF::Endianness::BIG); } - setPacketDataLength( - sourceDataSize + sizeof(PUSTmDataFieldHeaderPusA) + CRC_SIZE - 1); + setPacketDataLength(sourceDataSize + sizeof(PUSTmDataFieldHeaderPusA) + CRC_SIZE - 1); } uint8_t* TmPacketStoredPusA::getAllTmData() { -- 2.43.0 From 91f43d00a25ce69639c89f976bcab0e10998b570 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 5 Oct 2021 12:47:30 +0200 Subject: [PATCH 3/6] moved store failure to separate function --- .../tmtcpacket/pus/tm/TmPacketStoredBase.cpp | 32 ++++++++++++++++- .../tmtcpacket/pus/tm/TmPacketStoredBase.h | 3 ++ .../tmtcpacket/pus/tm/TmPacketStoredPusA.cpp | 34 +++---------------- .../tmtcpacket/pus/tm/TmPacketStoredPusC.cpp | 34 +++---------------- 4 files changed, 42 insertions(+), 61 deletions(-) diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredBase.cpp b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredBase.cpp index 466e4cd2..20a8ed89 100644 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredBase.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredBase.cpp @@ -91,4 +91,34 @@ void TmPacketStoredBase::checkAndReportLostTm() { } } - +void TmPacketStoredBase::handleStoreFailure(const char *const packetType, ReturnValue_t result, + size_t sizeToReserve) { + checkAndReportLostTm(); +#if FSFW_VERBOSE_LEVEL >= 1 + switch(result) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + case(StorageManagerIF::DATA_STORAGE_FULL): { + sif::warning << "TmPacketStoredPus" << packetType << ": " << + "Store full for packet with size" << sizeToReserve << std::endl; + break; + } + case(StorageManagerIF::DATA_TOO_LARGE): { + sif::warning << "TmPacketStoredPus" << packetType << ": Data with size " << + sizeToReserve << " too large" << std::endl; + break; + } +#else + case(StorageManagerIF::DATA_STORAGE_FULL): { + sif::printWarning("TmPacketStoredPus%s: Store full for packet with " + "size %d\n", packetType, sizeToReserve); + break; + } + case(StorageManagerIF::DATA_TOO_LARGE): { + sif::printWarning("TmPacketStoredPus%s: Data with size " + "%d too large\n", packetType, sizeToReserve); + break; + } +#endif +#endif + } +} diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredBase.h b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredBase.h index 8e8b9c70..91ca2f93 100644 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredBase.h +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredBase.h @@ -82,6 +82,9 @@ protected: bool checkAndSetStore(); void checkAndReportLostTm(); + + void handleStoreFailure(const char* const packetType, ReturnValue_t result, + size_t sizeToReserve); }; diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusA.cpp b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusA.cpp index 3b183f09..a8a10da6 100644 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusA.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusA.cpp @@ -18,11 +18,12 @@ TmPacketStoredPusA::TmPacketStoredPusA(uint16_t apid, uint8_t service, return; } uint8_t *pData = nullptr; + size_t sizeToReserve = getPacketMinimumSize() + size + headerSize; ReturnValue_t returnValue = store->getFreeElement(&storeAddress, - (getPacketMinimumSize() + size + headerSize), &pData); + sizeToReserve, &pData); if (returnValue != store->RETURN_OK) { - TmPacketStoredBase::checkAndReportLostTm(); + handleStoreFailure("A", returnValue, sizeToReserve); return; } setData(pData); @@ -53,34 +54,7 @@ TmPacketStoredPusA::TmPacketStoredPusA(uint16_t apid, uint8_t service, ReturnValue_t returnValue = store->getFreeElement(&storeAddress, sizeToReserve, &pData); if (returnValue != store->RETURN_OK) { - TmPacketStoredBase::checkAndReportLostTm(); -#if FSFW_VERBOSE_LEVEL >= 1 - switch(returnValue) { -#if FSFW_CPP_OSTREAM_ENABLED == 1 - case(StorageManagerIF::DATA_STORAGE_FULL): { - sif::warning << "TmPacketStoredPusA::TmPacketStoredPusC: Store full for packet with " - "size " << sizeToReserve << std::endl; - break; - } - case(StorageManagerIF::DATA_TOO_LARGE): { - sif::warning << "TmPacketStoredPusA::TmPacketStoredPusC: Data with size " << - sizeToReserve << " too large" << std::endl; - break; - } -#else - case(StorageManagerIF::DATA_STORAGE_FULL): { - sif::printWarning("TmPacketStoredPusA::TmPacketStoredPusC: Store full for packet with " - "size %d\n", sizeToReserve); - break; - } - case(StorageManagerIF::DATA_TOO_LARGE): { - sif::printWarning("TmPacketStoredPusA::TmPacketStoredPusC: Data with size " - "%d too large\n", sizeToReserve); - break; - } -#endif -#endif - } + handleStoreFailure("A", returnValue, sizeToReserve); return; } setData(pData); diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusC.cpp b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusC.cpp index 570d9d4e..ee574299 100644 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusC.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusC.cpp @@ -19,11 +19,12 @@ TmPacketStoredPusC::TmPacketStoredPusC(uint16_t apid, uint8_t service, return; } uint8_t *pData = nullptr; + size_t sizeToReserve = getPacketMinimumSize() + size + headerSize; ReturnValue_t returnValue = store->getFreeElement(&storeAddress, - (getPacketMinimumSize() + size + headerSize), &pData); + sizeToReserve, &pData); if (returnValue != store->RETURN_OK) { - TmPacketStoredBase::checkAndReportLostTm(); + handleStoreFailure("C", returnValue, sizeToReserve); return; } setData(pData); @@ -52,34 +53,7 @@ TmPacketStoredPusC::TmPacketStoredPusC(uint16_t apid, uint8_t service, size_t sizeToReserve = getPacketMinimumSize() + sourceDataSize; ReturnValue_t returnValue = store->getFreeElement(&storeAddress, sizeToReserve, &pData); if (returnValue != store->RETURN_OK) { -#if FSFW_VERBOSE_LEVEL >= 1 - switch(returnValue) { -#if FSFW_CPP_OSTREAM_ENABLED == 1 - case(StorageManagerIF::DATA_STORAGE_FULL): { - sif::warning << "TmPacketStoredPusC::TmPacketStoredPusC: Store full for packet with " - "size " << sizeToReserve << std::endl; - break; - } - case(StorageManagerIF::DATA_TOO_LARGE): { - sif::warning << "TmPacketStoredPusC::TmPacketStoredPusC: Data with size " << - sizeToReserve << " too large" << std::endl; - break; - } -#else - case(StorageManagerIF::DATA_STORAGE_FULL): { - sif::printWarning("TmPacketStoredPusC::TmPacketStoredPusC: Store full for packet with " - "size %d\n", sizeToReserve); - break; - } - case(StorageManagerIF::DATA_TOO_LARGE): { - sif::printWarning("TmPacketStoredPusC::TmPacketStoredPusC: Data with size " - "%d too large\n", sizeToReserve); - break; - } -#endif - } -#endif - TmPacketStoredBase::checkAndReportLostTm(); + handleStoreFailure("C", returnValue, sizeToReserve); return; } setData(pData); -- 2.43.0 From 2124f36e36318bc4567c341bb7459cf61b4ab52f Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 5 Oct 2021 12:47:30 +0200 Subject: [PATCH 4/6] moved store failure to separate function --- .../tmtcpacket/pus/tm/TmPacketStoredPusA.cpp | 114 +++++++++--------- .../tmtcpacket/pus/tm/TmPacketStoredPusA.h | 74 ++++++------ 2 files changed, 94 insertions(+), 94 deletions(-) diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusA.cpp b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusA.cpp index a8a10da6..067b4f8f 100644 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusA.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusA.cpp @@ -5,71 +5,71 @@ #include -TmPacketStoredPusA::TmPacketStoredPusA(store_address_t setAddress) : - TmPacketStoredBase(setAddress), TmPacketPusA(nullptr){ +TmPacketStoredPusA::TmPacketStoredPusA(store_address_t setAddress): + TmPacketStoredBase(setAddress), TmPacketPusA(nullptr){ } TmPacketStoredPusA::TmPacketStoredPusA(uint16_t apid, uint8_t service, - uint8_t subservice, uint8_t packetSubcounter, const uint8_t *data, - uint32_t size, const uint8_t *headerData, uint32_t headerSize) : + uint8_t subservice, uint8_t packetSubcounter, const uint8_t *data, + uint32_t size, const uint8_t *headerData, uint32_t headerSize): TmPacketPusA(nullptr) { - storeAddress.raw = StorageManagerIF::INVALID_ADDRESS; - if (not TmPacketStoredBase::checkAndSetStore()) { - return; - } - uint8_t *pData = nullptr; - size_t sizeToReserve = getPacketMinimumSize() + size + headerSize; - ReturnValue_t returnValue = store->getFreeElement(&storeAddress, - sizeToReserve, &pData); + storeAddress.raw = StorageManagerIF::INVALID_ADDRESS; + if (not TmPacketStoredBase::checkAndSetStore()) { + return; + } + uint8_t *pData = nullptr; + size_t sizeToReserve = getPacketMinimumSize() + size + headerSize; + ReturnValue_t returnValue = store->getFreeElement(&storeAddress, + sizeToReserve, &pData); - if (returnValue != store->RETURN_OK) { - handleStoreFailure("A", returnValue, sizeToReserve); - return; - } - setData(pData); - initializeTmPacket(apid, service, subservice, packetSubcounter); - memcpy(getSourceData(), headerData, headerSize); - memcpy(getSourceData() + headerSize, data, size); - setPacketDataLength( - size + headerSize + sizeof(PUSTmDataFieldHeaderPusA) + CRC_SIZE - 1); + if (returnValue != store->RETURN_OK) { + handleStoreFailure("A", returnValue, sizeToReserve); + return; + } + setData(pData); + initializeTmPacket(apid, service, subservice, packetSubcounter); + memcpy(getSourceData(), headerData, headerSize); + memcpy(getSourceData() + headerSize, data, size); + setPacketDataLength( + size + headerSize + sizeof(PUSTmDataFieldHeaderPusA) + CRC_SIZE - 1); } TmPacketStoredPusA::TmPacketStoredPusA(uint16_t apid, uint8_t service, - uint8_t subservice, uint8_t packetSubcounter, SerializeIF *content, - SerializeIF *header) : - TmPacketPusA(nullptr) { - storeAddress.raw = StorageManagerIF::INVALID_ADDRESS; - if (not TmPacketStoredBase::checkAndSetStore()) { - return; - } - size_t sourceDataSize = 0; - if (content != nullptr) { - sourceDataSize += content->getSerializedSize(); - } - if (header != nullptr) { - sourceDataSize += header->getSerializedSize(); - } - uint8_t *pData = nullptr; - size_t sizeToReserve = getPacketMinimumSize() + sourceDataSize; - ReturnValue_t returnValue = store->getFreeElement(&storeAddress, - sizeToReserve, &pData); - if (returnValue != store->RETURN_OK) { - handleStoreFailure("A", returnValue, sizeToReserve); - return; - } - setData(pData); - initializeTmPacket(apid, service, subservice, packetSubcounter); - uint8_t *putDataHere = getSourceData(); - size_t size = 0; - if (header != nullptr) { - header->serialize(&putDataHere, &size, sourceDataSize, - SerializeIF::Endianness::BIG); - } - if (content != nullptr) { - content->serialize(&putDataHere, &size, sourceDataSize, - SerializeIF::Endianness::BIG); - } - setPacketDataLength(sourceDataSize + sizeof(PUSTmDataFieldHeaderPusA) + CRC_SIZE - 1); + uint8_t subservice, uint8_t packetSubcounter, SerializeIF *content, + SerializeIF *header) : + TmPacketPusA(nullptr) { + storeAddress.raw = StorageManagerIF::INVALID_ADDRESS; + if (not TmPacketStoredBase::checkAndSetStore()) { + return; + } + size_t sourceDataSize = 0; + if (content != nullptr) { + sourceDataSize += content->getSerializedSize(); + } + if (header != nullptr) { + sourceDataSize += header->getSerializedSize(); + } + uint8_t *pData = nullptr; + size_t sizeToReserve = getPacketMinimumSize() + sourceDataSize; + ReturnValue_t returnValue = store->getFreeElement(&storeAddress, + sizeToReserve, &pData); + if (returnValue != store->RETURN_OK) { + handleStoreFailure("A", returnValue, sizeToReserve); + return; + } + setData(pData); + initializeTmPacket(apid, service, subservice, packetSubcounter); + uint8_t *putDataHere = getSourceData(); + size_t size = 0; + if (header != nullptr) { + header->serialize(&putDataHere, &size, sourceDataSize, + SerializeIF::Endianness::BIG); + } + if (content != nullptr) { + content->serialize(&putDataHere, &size, sourceDataSize, + SerializeIF::Endianness::BIG); + } + setPacketDataLength(sourceDataSize + sizeof(PUSTmDataFieldHeaderPusA) + CRC_SIZE - 1); } uint8_t* TmPacketStoredPusA::getAllTmData() { diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusA.h b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusA.h index 0cfcf0b8..6a338cd5 100644 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusA.h +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketStoredPusA.h @@ -15,46 +15,46 @@ * packets in a store with the help of a storeAddress. * @ingroup tmtcpackets */ -class TmPacketStoredPusA : +class TmPacketStoredPusA: public TmPacketStoredBase, public TmPacketPusA { public: - /** - * This is a default constructor which does not set the data pointer. - * However, it does try to set the packet store. - */ - TmPacketStoredPusA( store_address_t setAddress ); - /** - * With this constructor, new space is allocated in the packet store and - * a new PUS Telemetry Packet is created there. - * Packet Application Data passed in data is copied into the packet. - * The Application data is passed in two parts, first a header, then a - * data field. This allows building a Telemetry Packet from two separate - * data sources. - * @param apid Sets the packet's APID field. - * @param service Sets the packet's Service ID field. - * This specifies the source service. - * @param subservice Sets the packet's Service Subtype field. - * This specifies the source sub-service. - * @param packet_counter Sets the Packet counter field of this packet - * @param data The payload data to be copied to the - * Application Data Field - * @param size The amount of data to be copied. - * @param headerData The header Data of the Application field, - * will be copied in front of data - * @param headerSize The size of the headerDataF - */ - TmPacketStoredPusA( uint16_t apid, uint8_t service, uint8_t subservice, - uint8_t packet_counter = 0, const uint8_t* data = nullptr, - uint32_t size = 0, const uint8_t* headerData = nullptr, - uint32_t headerSize = 0); - /** - * Another ctor to directly pass structured content and header data to the - * packet to avoid additional buffers. - */ - TmPacketStoredPusA( uint16_t apid, uint8_t service, uint8_t subservice, - uint8_t packet_counter, SerializeIF* content, - SerializeIF* header = nullptr); + /** + * This is a default constructor which does not set the data pointer. + * However, it does try to set the packet store. + */ + TmPacketStoredPusA( store_address_t setAddress ); + /** + * With this constructor, new space is allocated in the packet store and + * a new PUS Telemetry Packet is created there. + * Packet Application Data passed in data is copied into the packet. + * The Application data is passed in two parts, first a header, then a + * data field. This allows building a Telemetry Packet from two separate + * data sources. + * @param apid Sets the packet's APID field. + * @param service Sets the packet's Service ID field. + * This specifies the source service. + * @param subservice Sets the packet's Service Subtype field. + * This specifies the source sub-service. + * @param packet_counter Sets the Packet counter field of this packet + * @param data The payload data to be copied to the + * Application Data Field + * @param size The amount of data to be copied. + * @param headerData The header Data of the Application field, + * will be copied in front of data + * @param headerSize The size of the headerDataF + */ + TmPacketStoredPusA( uint16_t apid, uint8_t service, uint8_t subservice, + uint8_t packet_counter = 0, const uint8_t* data = nullptr, + uint32_t size = 0, const uint8_t* headerData = nullptr, + uint32_t headerSize = 0); + /** + * Another ctor to directly pass structured content and header data to the + * packet to avoid additional buffers. + */ + TmPacketStoredPusA( uint16_t apid, uint8_t service, uint8_t subservice, + uint8_t packet_counter, SerializeIF* content, + SerializeIF* header = nullptr); uint8_t* getAllTmData() override; void setDataPointer(const uint8_t* newPointer) override; -- 2.43.0 From 3502ddca7ff29d443bb6991d18c683496d26c313 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 5 Oct 2021 13:13:36 +0200 Subject: [PATCH 5/6] 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; -- 2.43.0 From db801a0ecc7323f3bc552be0de383c6bb1b29fb7 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 5 Oct 2021 13:17:12 +0200 Subject: [PATCH 6/6] removed unneeded static constexpr --- src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.h b/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.h index e5dee662..3a9be132 100644 --- a/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.h +++ b/src/fsfw/tmtcpacket/pus/tm/TmPacketPusC.h @@ -54,9 +54,6 @@ public: sizeof(PUSTmDataFieldHeaderPusC) + 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 2 according - //! to ECSS-E-ST-70-41C p.439 - static constexpr uint8_t TM_PUS_VERSION_NUMBER = 2; /** * This is the default constructor. -- 2.43.0