diff --git a/src/fsfw/datapoollocal/ProvidesDataPoolSubscriptionIF.h b/src/fsfw/datapoollocal/ProvidesDataPoolSubscriptionIF.h index e1aca321..3001ea10 100644 --- a/src/fsfw/datapoollocal/ProvidesDataPoolSubscriptionIF.h +++ b/src/fsfw/datapoollocal/ProvidesDataPoolSubscriptionIF.h @@ -70,6 +70,15 @@ class ProvidesDataPoolSubscriptionIF { virtual ReturnValue_t subscribeForDiagPeriodicPacket( subdp::DiagnosticsHkPeriodicParams params) = 0; + [[deprecated( + "Please use the new API which takes all arguments as one wrapper " + "struct")]] virtual ReturnValue_t + subscribeForPeriodicPacket(sid_t sid, bool enableReporting, float collectionInterval, + bool isDiagnostics) { + return subscribeForPeriodicPacket(sid, enableReporting, collectionInterval, isDiagnostics, + objects::NO_OBJECT); + } + [[deprecated( "Please use the new API which takes all arguments as one wrapper " "struct")]] virtual ReturnValue_t @@ -97,6 +106,12 @@ class ProvidesDataPoolSubscriptionIF { virtual ReturnValue_t subscribeForRegularUpdatePacket(subdp::RegularHkUpdateParams params) = 0; virtual ReturnValue_t subscribeForDiagUpdatePacket(subdp::DiagnosticsHkUpdateParams params) = 0; + [[deprecated( + "Please use the new API which takes all arguments as one wrapper " + "struct")]] virtual ReturnValue_t + subscribeForUpdatePacket(sid_t sid, bool reportingEnabled, bool isDiagnostics) { + return subscribeForUpdatePacket(sid, reportingEnabled, isDiagnostics, objects::NO_OBJECT); + } [[deprecated( "Please use the new API which takes all arguments as one wrapper " "struct")]] virtual ReturnValue_t diff --git a/src/fsfw/pus/Service11TelecommandScheduling.h b/src/fsfw/pus/Service11TelecommandScheduling.h index 0fed8bca..2d855be1 100644 --- a/src/fsfw/pus/Service11TelecommandScheduling.h +++ b/src/fsfw/pus/Service11TelecommandScheduling.h @@ -74,8 +74,7 @@ class Service11TelecommandScheduling final : public PusServiceBase { TO_TIMETAG = 3 }; - Service11TelecommandScheduling(object_id_t objectId, uint16_t apid, uint8_t serviceId, - AcceptsTelecommandsIF* tcRecipient, + Service11TelecommandScheduling(PsbParams params, AcceptsTelecommandsIF* tcRecipient, uint16_t releaseTimeMarginSeconds = DEFAULT_RELEASE_TIME_MARGIN, bool debugMode = false); @@ -159,7 +158,7 @@ class Service11TelecommandScheduling final : public PusServiceBase { * @param data The Application data of the TC (get via getApplicationData()). * @return requestId */ - uint64_t getRequestIdFromDataTC(const uint8_t* data) const; + [[nodiscard]] uint64_t getRequestIdFromTc() const; /** * @brief Extracts the Request ID from the Application Data directly, assuming it is packed diff --git a/src/fsfw/pus/Service11TelecommandScheduling.tpp b/src/fsfw/pus/Service11TelecommandScheduling.tpp index 968a59ff..15440a21 100644 --- a/src/fsfw/pus/Service11TelecommandScheduling.tpp +++ b/src/fsfw/pus/Service11TelecommandScheduling.tpp @@ -11,9 +11,9 @@ static constexpr auto DEF_END = SerializeIF::Endianness::BIG; template inline Service11TelecommandScheduling::Service11TelecommandScheduling( - object_id_t objectId, uint16_t apid, uint8_t serviceId, AcceptsTelecommandsIF *tcRecipient, - uint16_t releaseTimeMarginSeconds, bool debugMode) - : PusServiceBase(objectId, apid, serviceId), + PsbParams params, AcceptsTelecommandsIF *tcRecipient, uint16_t releaseTimeMarginSeconds, + bool debugMode) + : PusServiceBase(params), RELEASE_TIME_MARGIN_SECONDS(releaseTimeMarginSeconds), debugMode(debugMode), tcRecipient(tcRecipient) {} @@ -32,8 +32,8 @@ inline ReturnValue_t Service11TelecommandScheduling::handleRequest( #endif } // Get de-serialized Timestamp - const uint8_t *data = currentPacket.getApplicationData(); - size_t size = currentPacket.getApplicationDataSize(); + const uint8_t *data = currentPacket.getUserData(); + size_t size = currentPacket.getUserDataLen(); if (data == nullptr) { return handleInvalidData("handleRequest"); } @@ -82,7 +82,7 @@ inline ReturnValue_t Service11TelecommandScheduling::performService if (schedulingEnabled) { // release tc TmTcMessage releaseMsg(it->second.storeAddr); - auto sendRet = this->requestQueue->sendMessage(recipientMsgQueueId, &releaseMsg, false); + auto sendRet = psbParams.reqQueue->sendMessage(recipientMsgQueueId, &releaseMsg, false); if (sendRet != HasReturnvaluesIF::RETURN_OK) { return sendRet; @@ -175,7 +175,7 @@ inline ReturnValue_t Service11TelecommandScheduling::doInsertActivi // store currentPacket and receive the store address store_address_t addr{}; if (tcStore->addData(&addr, data, size) != RETURN_OK || - addr.raw == storeId::INVALID_STORE_ADDRESS) { + addr.raw == store_address_t::INVALID_RAW) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::error << "Service11TelecommandScheduling::doInsertActivity: Adding data to TC Store failed" << std::endl; @@ -190,8 +190,7 @@ inline ReturnValue_t Service11TelecommandScheduling::doInsertActivi TelecommandStruct tc; tc.seconds = timestamp; tc.storeAddr = addr; - tc.requestId = - getRequestIdFromDataTC(data); // TODO: Missing sanity check of the returned request id + tc.requestId = getRequestIdFromTc(); // TODO: Missing sanity check of the returned request id auto it = telecommandMap.insert(std::pair(timestamp, tc)); if (it == telecommandMap.end()) { @@ -455,13 +454,10 @@ inline ReturnValue_t Service11TelecommandScheduling::doFilterTimesh } template -inline uint64_t Service11TelecommandScheduling::getRequestIdFromDataTC( - const uint8_t *data) const { - TcPacketPus mask(data); - - uint32_t sourceId = mask.getSourceId(); - uint16_t apid = mask.getAPID(); - uint16_t sequenceCount = mask.getPacketSequenceCount(); +inline uint64_t Service11TelecommandScheduling::getRequestIdFromTc() const { + uint32_t sourceId = currentPacket.getSourceId(); + uint16_t apid = currentPacket.getApid(); + uint16_t sequenceCount = currentPacket.getSequenceCount(); return buildRequestId(sourceId, apid, sequenceCount); } diff --git a/src/fsfw/returnvalues/HasReturnvaluesIF.h b/src/fsfw/returnvalues/HasReturnvaluesIF.h index 4d59c26b..caef5954 100644 --- a/src/fsfw/returnvalues/HasReturnvaluesIF.h +++ b/src/fsfw/returnvalues/HasReturnvaluesIF.h @@ -33,8 +33,7 @@ class HasReturnvaluesIF { * @param number * @return */ - [[deprecated("Use retval::makeCode instead")]] static constexpr ReturnValue_t makeReturnCode( - uint8_t classId, uint8_t number) { + static constexpr ReturnValue_t makeReturnCode(uint8_t classId, uint8_t number) { return retval::makeCode(classId, number); } }; diff --git a/src/fsfw/tcdistribution/PusDistributor.cpp b/src/fsfw/tcdistribution/PusDistributor.cpp index 981fca1c..9b436dec 100644 --- a/src/fsfw/tcdistribution/PusDistributor.cpp +++ b/src/fsfw/tcdistribution/PusDistributor.cpp @@ -8,8 +8,8 @@ #define PUS_DISTRIBUTOR_DEBUGGING 0 -PusDistributor::PusDistributor(StorageManagerIF* store_, uint16_t setApid, object_id_t setObjectId, - object_id_t setPacketSource) +PusDistributor::PusDistributor(uint16_t setApid, object_id_t setObjectId, + object_id_t setPacketSource, StorageManagerIF* store_) : TcDistributor(setObjectId), store(store_), checker(setApid, ccsds::PacketType::TC), @@ -151,5 +151,11 @@ ReturnValue_t PusDistributor::initialize() { #endif return RETURN_FAILED; } + if (store == nullptr) { + store = ObjectManager::instance()->get(objects::TC_STORE); + if (store == nullptr) { + return ObjectManagerIF::CHILD_INIT_FAILED; + } + } return ccsdsDistributor->registerApplication(this); } diff --git a/src/fsfw/tcdistribution/PusDistributor.h b/src/fsfw/tcdistribution/PusDistributor.h index 3849c793..b16f1478 100644 --- a/src/fsfw/tcdistribution/PusDistributor.h +++ b/src/fsfw/tcdistribution/PusDistributor.h @@ -27,8 +27,8 @@ class PusDistributor : public TcDistributor, public PUSDistributorIF, public Acc * @param setPacketSource Object ID of the source of TC packets. * Must implement CCSDSDistributorIF. */ - PusDistributor(StorageManagerIF* store, uint16_t setApid, object_id_t setObjectId, - object_id_t setPacketSource); + PusDistributor(uint16_t setApid, object_id_t setObjectId, object_id_t setPacketSource, + StorageManagerIF* store = nullptr); /** * The destructor is empty. */ diff --git a/src/fsfw/tmtcpacket/ccsds/header.cpp b/src/fsfw/tmtcpacket/ccsds/header.cpp index b87ab5b3..6491d207 100644 --- a/src/fsfw/tmtcpacket/ccsds/header.cpp +++ b/src/fsfw/tmtcpacket/ccsds/header.cpp @@ -17,7 +17,7 @@ uint16_t ccsds::getPacketLen(const PrimaryHeader &header) { } void ccsds::setPacketId(PrimaryHeader &header, uint16_t packetId) { - header.packetIdHAndVersion = (packetId >> 8) & 0x1F; + header.packetIdHAndVersion |= (packetId >> 8) & 0x1F; header.packetIdL = packetId & 0xff; } @@ -27,3 +27,8 @@ void ccsds::setApid(PrimaryHeader &header, uint16_t apid) { packetIdRaw |= apid & 0x7FF; setPacketId(header, packetIdRaw); } + +void ccsds::setSequenceCount(PrimaryHeader &header, uint16_t seqCount) { + header.packetSeqCtrlH |= (seqCount >> 8) & 0x3F; + header.packetSeqCtrlL = seqCount & 0xFF; +} diff --git a/src/fsfw/tmtcpacket/ccsds/header.h b/src/fsfw/tmtcpacket/ccsds/header.h index d416f697..89e00601 100644 --- a/src/fsfw/tmtcpacket/ccsds/header.h +++ b/src/fsfw/tmtcpacket/ccsds/header.h @@ -24,6 +24,7 @@ uint16_t getPacketLen(const PrimaryHeader& header); void setPacketId(PrimaryHeader& header, uint16_t packetId); void setApid(PrimaryHeader& header, uint16_t apid); +void setSequenceCount(PrimaryHeader& header, uint16_t seqCount); } // namespace ccsds diff --git a/src/fsfw/tmtcpacket/pus/tm.h b/src/fsfw/tmtcpacket/pus/tm.h index 619f9e01..fc3f0b94 100644 --- a/src/fsfw/tmtcpacket/pus/tm.h +++ b/src/fsfw/tmtcpacket/pus/tm.h @@ -3,5 +3,6 @@ #include "tm/PusTmCreator.h" #include "tm/PusTmReader.h" +#include "tm/PusTmZcWriter.h" #endif /* FSFW_TMTCPACKET_PUS_TM_H_ */ diff --git a/src/fsfw/tmtcpacket/pus/tm/CMakeLists.txt b/src/fsfw/tmtcpacket/pus/tm/CMakeLists.txt index 57c45927..1395d927 100644 --- a/src/fsfw/tmtcpacket/pus/tm/CMakeLists.txt +++ b/src/fsfw/tmtcpacket/pus/tm/CMakeLists.txt @@ -1,2 +1,2 @@ target_sources(${LIB_FSFW_NAME} PRIVATE PusTmCreator.cpp PusTmReader.cpp - PusTmMinimal.cpp) + PusTmMinimal.cpp PusTmZcWriter.cpp) diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp index ddcad33e..6e6eb686 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.cpp @@ -83,8 +83,11 @@ ReturnValue_t PusTmCreator::serialize(uint8_t** buffer, size_t* size, size_t max return result; } } - uint16_t crc16 = CRC::crc16ccitt(start, getFullPacketLen() - sizeof(ecss::PusChecksumT)); - return SerializeAdapter::serialize(&crc16, buffer, size, maxSize, streamEndianness); + if (calculateCrcOnSerialization) { + uint16_t crc16 = CRC::crc16ccitt(start, getFullPacketLen() - sizeof(ecss::PusChecksumT)); + return SerializeAdapter::serialize(&crc16, buffer, size, maxSize, streamEndianness); + } + return HasReturnvaluesIF::RETURN_OK; } size_t PusTmCreator::getSerializedSize() const { return getFullPacketLen(); } @@ -108,10 +111,6 @@ void PusTmCreator::updateSpLengthField() { void PusTmCreator::setApid(uint16_t apid) { spCreator.setApid(apid); } -ReturnValue_t PusTmCreator::serialize(uint8_t** buffer, size_t* size, size_t maxSize) const { - return serialize(buffer, size, maxSize, SerializeIF::Endianness::NETWORK); -} - void PusTmCreator::setup() { updateSpLengthField(); spCreator.setPacketType(ccsds::PacketType::TM); diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h index 41f72c38..78414c37 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmCreator.h @@ -63,7 +63,6 @@ class PusTmCreator : public SerializeIF, public PusTmIF, public CustomUserDataIF uint8_t getScTimeRefStatus() override; uint16_t getMessageTypeCounter() override; uint16_t getDestId() override; - ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize) const; ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, Endianness streamEndianness) const override; [[nodiscard]] size_t getSerializedSize() const override; @@ -76,6 +75,7 @@ class PusTmCreator : public SerializeIF, public PusTmIF, public CustomUserDataIF private: void setup(); PusTmParams pusParams{}; + bool calculateCrcOnSerialization = true; SpacePacketCreator spCreator; }; #endif // FSFW_TMTCPACKET_TMPACKETCREATOR_H diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmReader.h b/src/fsfw/tmtcpacket/pus/tm/PusTmReader.h index e5a61aec..780b3e5f 100644 --- a/src/fsfw/tmtcpacket/pus/tm/PusTmReader.h +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmReader.h @@ -38,13 +38,15 @@ class PusTmReader : public PusTmIF, uint16_t getMessageTypeCounter() override; uint16_t getDestId() override; - private: - ReturnValue_t setData(uint8_t* dataPtr, size_t size, void* args) override; - ReturnValue_t parseData(bool crcCheck); + protected: + ecss::PusPointers pointers{}; SpacePacketReader spReader{}; size_t sourceDataLen = 0; TimeReaderIF* timeReader{}; - ecss::PusPointers pointers{}; + ReturnValue_t setData(uint8_t* dataPtr, size_t size, void* args) override; + ReturnValue_t parseData(bool crcCheck); + + private: }; #endif // FSFW_TMTCPACKET_PUSTMREADER_H diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.cpp b/src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.cpp new file mode 100644 index 00000000..4c6c56d3 --- /dev/null +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.cpp @@ -0,0 +1,18 @@ +#include "PusTmZcWriter.h" + +#include "fsfw/globalfunctions/CRC.h" + +PusTmZeroCopyWriter::PusTmZeroCopyWriter(uint8_t* data, size_t size) : PusTmReader(data, size) {} + +void PusTmZeroCopyWriter::setSequenceCount(uint16_t seqCount) { + auto* spHeader = + reinterpret_cast(const_cast((pointers.spHeaderStart))); + ccsds::setSequenceCount(*spHeader, seqCount); +} +void PusTmZeroCopyWriter::updateErrorControl() { + auto* crcStart = reinterpret_cast(const_cast((pointers.spHeaderStart))); + uint16_t crc16 = + CRC::crc16ccitt(PusTmReader::getFullData(), getFullPacketLen() - sizeof(ecss::PusChecksumT)); + crcStart[0] = (crc16 >> 8) & 0xff; + crcStart[1] = crc16 & 0xff; +} diff --git a/src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.h b/src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.h new file mode 100644 index 00000000..c3f5db35 --- /dev/null +++ b/src/fsfw/tmtcpacket/pus/tm/PusTmZcWriter.h @@ -0,0 +1,14 @@ +#ifndef FSFW_EXAMPLE_HOSTED_PUSTMZCWRITER_H +#define FSFW_EXAMPLE_HOSTED_PUSTMZCWRITER_H + +#include "PusTmReader.h" +class PusTmZeroCopyWriter : public PusTmReader { + public: + PusTmZeroCopyWriter(uint8_t* data, size_t size); + + void setSequenceCount(uint16_t seqCount); + void updateErrorControl(); + + private: +}; +#endif // FSFW_EXAMPLE_HOSTED_PUSTMZCWRITER_H diff --git a/src/fsfw/tmtcservices/PusServiceBase.cpp b/src/fsfw/tmtcservices/PusServiceBase.cpp index 97f018e5..094a4156 100644 --- a/src/fsfw/tmtcservices/PusServiceBase.cpp +++ b/src/fsfw/tmtcservices/PusServiceBase.cpp @@ -27,7 +27,7 @@ ReturnValue_t PusServiceBase::performOperation(uint8_t opCode) { if (result != RETURN_OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::error << "PusService " << psbParams.serviceId << ": performService returned with " - << static_cast(result) << std::endl; + << static_cast(result) << std::endl; #endif return RETURN_FAILED; } diff --git a/src/fsfw_tests/integration/devices/TestDeviceHandler.cpp b/src/fsfw_tests/integration/devices/TestDeviceHandler.cpp index 36f1ea8c..551e252f 100644 --- a/src/fsfw_tests/integration/devices/TestDeviceHandler.cpp +++ b/src/fsfw_tests/integration/devices/TestDeviceHandler.cpp @@ -645,7 +645,7 @@ ReturnValue_t TestDevice::initializeLocalDataPool(localpool::DataPool& localData sid_t sid(this->getObjectId(), td::TEST_SET_ID); /* Subscribe for periodic HK packets but do not enable reporting for now. Non-diangostic with a period of one second */ - poolManager.subscribeForPeriodicPacket(sid, false, 1.0, false); + poolManager.subscribeForRegularPeriodicPacket(subdp::RegularHkPeriodicParams(sid, false, 1.0)); return HasReturnvaluesIF::RETURN_OK; }