From d0fc360697e0fae7ccb4b827b8bc3d0398c342bc Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 20 May 2022 08:34:14 +0200 Subject: [PATCH 1/9] apply afmt --- src/fsfw/objectmanager/frameworkObjects.h | 1 + src/fsfw/pus/Service11TelecommandScheduling.h | 48 +++++++------------ .../pus/Service11TelecommandScheduling.tpp | 48 +++++++++++-------- 3 files changed, 44 insertions(+), 53 deletions(-) diff --git a/src/fsfw/objectmanager/frameworkObjects.h b/src/fsfw/objectmanager/frameworkObjects.h index cc233c0f..cddc6ba2 100644 --- a/src/fsfw/objectmanager/frameworkObjects.h +++ b/src/fsfw/objectmanager/frameworkObjects.h @@ -14,6 +14,7 @@ enum framework_objects : object_id_t { PUS_SERVICE_5_EVENT_REPORTING = 0x53000005, PUS_SERVICE_8_FUNCTION_MGMT = 0x53000008, PUS_SERVICE_9_TIME_MGMT = 0x53000009, + PUS_SERVICE_11_TC_SCHEDULER = 0x53000011, PUS_SERVICE_17_TEST = 0x53000017, PUS_SERVICE_20_PARAMETERS = 0x53000020, PUS_SERVICE_200_MODE_MGMT = 0x53000200, diff --git a/src/fsfw/pus/Service11TelecommandScheduling.h b/src/fsfw/pus/Service11TelecommandScheduling.h index 5e446b07..9a8be603 100644 --- a/src/fsfw/pus/Service11TelecommandScheduling.h +++ b/src/fsfw/pus/Service11TelecommandScheduling.h @@ -45,19 +45,17 @@ class Service11TelecommandScheduling final : public PusServiceBase { HasReturnvaluesIF::makeReturnCode(CLASS_ID, 3); // The types of PUS-11 subservices - enum Subservice : uint8_t { - ENABLE_SCHEDULING = 1, - DISABLE_SCHEDULING = 2, - RESET_SCHEDULING = 3, - INSERT_ACTIVITY = 4, - DELETE_ACTIVITY = 5, - FILTER_DELETE_ACTIVITY = 6, - TIMESHIFT_ACTIVITY = 7, - FILTER_TIMESHIFT_ACTIVITY = 8, - DETAIL_REPORT = 9, - TIMEBASE_SCHEDULE_DETAIL_REPORT = 10, - TIMESHIFT_ALL_SCHEDULE_ACTIVITIES = 15 - }; + enum [[maybe_unused]] Subservice : uint8_t{ENABLE_SCHEDULING = 1, + DISABLE_SCHEDULING = 2, + RESET_SCHEDULING = 3, + INSERT_ACTIVITY = 4, + DELETE_ACTIVITY = 5, + FILTER_DELETE_ACTIVITY = 6, + TIMESHIFT_ACTIVITY = 7, + FILTER_TIMESHIFT_ACTIVITY = 8, + DETAIL_REPORT = 9, + TIMEBASE_SCHEDULE_DETAIL_REPORT = 10, + TIMESHIFT_ALL_SCHEDULE_ACTIVITIES = 15}; // The types of time windows for TC[11,6] and TC[11,8], as defined in ECSS-E-ST-70-41C, // requirement 8.11.3c (p. 507) @@ -73,7 +71,7 @@ class Service11TelecommandScheduling final : public PusServiceBase { uint16_t releaseTimeMarginSeconds = DEFAULT_RELEASE_TIME_MARGIN, bool debugMode = false); - ~Service11TelecommandScheduling(); + ~Service11TelecommandScheduling() override; /** PusServiceBase overrides */ ReturnValue_t handleRequest(uint8_t subservice) override; @@ -82,8 +80,8 @@ class Service11TelecommandScheduling final : public PusServiceBase { private: struct TelecommandStruct { - uint64_t requestId; - uint32_t seconds; + uint64_t requestId{}; + uint32_t seconds{}; store_address_t storeAddr; // uint16 }; @@ -92,9 +90,6 @@ class Service11TelecommandScheduling final : public PusServiceBase { // minimum release time offset to insert into schedule const uint16_t RELEASE_TIME_MARGIN_SECONDS = 5; - // the maximum amount of stored TCs is defined here - static constexpr uint16_t MAX_STORED_TELECOMMANDS = 500; - bool debugMode = false; StorageManagerIF* tcStore = nullptr; AcceptsTelecommandsIF* tcRecipient = nullptr; @@ -139,17 +134,6 @@ class Service11TelecommandScheduling final : public PusServiceBase { */ ReturnValue_t doFilterTimeshiftActivity(const uint8_t* data, size_t size); - /** - * @brief Deserializes a generic type from a payload buffer by using the FSFW - * SerializeAdapter Interface. - * @param output Output to be deserialized - * @param buf Payload buffer (application data) - * @param bufsize Remaining size of payload buffer (application data size) - * @return RETURN_OK if successful - */ - template - ReturnValue_t deserializeViaFsfwInterface(T& output, const uint8_t* buf, size_t bufsize); - /** * @brief Extracts the Request ID from the Application Data of a TC by utilizing a ctor of the * class TcPacketPus. @@ -177,7 +161,7 @@ class Service11TelecommandScheduling final : public PusServiceBase { * @param ssc Source Sequence Count * @return Request ID */ - uint64_t buildRequestId(uint32_t sourceId, uint16_t apid, uint16_t ssc) const; + [[nodiscard]] uint64_t buildRequestId(uint32_t sourceId, uint16_t apid, uint16_t ssc) const; /** * @brief Gets the filter range for filter TCs from a data packet @@ -194,7 +178,7 @@ class Service11TelecommandScheduling final : public PusServiceBase { /** * @brief Prints content of multimap. Use for simple debugging only. */ - void debugPrintMultimapContent(void) const; + void debugPrintMultimapContent() const; }; #include "Service11TelecommandScheduling.tpp" diff --git a/src/fsfw/pus/Service11TelecommandScheduling.tpp b/src/fsfw/pus/Service11TelecommandScheduling.tpp index c72e6631..41c36200 100644 --- a/src/fsfw/pus/Service11TelecommandScheduling.tpp +++ b/src/fsfw/pus/Service11TelecommandScheduling.tpp @@ -1,11 +1,12 @@ #pragma once -#include -#include -#include - #include +#include "fsfw/objectmanager/ObjectManager.h" +#include "fsfw/serialize/SerializeAdapter.h" +#include "fsfw/serviceinterface.h" +#include "fsfw/tmtcservices/AcceptsTelecommandsIF.h" + static constexpr auto DEF_END = SerializeIF::Endianness::BIG; template @@ -18,7 +19,7 @@ inline Service11TelecommandScheduling::Service11TelecommandScheduli tcRecipient(tcRecipient) {} template -inline Service11TelecommandScheduling::~Service11TelecommandScheduling() {} +inline Service11TelecommandScheduling::~Service11TelecommandScheduling() = default; template inline ReturnValue_t Service11TelecommandScheduling::handleRequest( @@ -404,7 +405,6 @@ inline ReturnValue_t Service11TelecommandScheduling::doFilterTimesh // and then insert it again as new entry telecommandMap.insert(std::make_pair(tempKey, tempTc)); shiftedItemsCount++; - continue; } if (debugMode) { @@ -463,9 +463,9 @@ template inline uint64_t Service11TelecommandScheduling::buildRequestId(uint32_t sourceId, uint16_t apid, uint16_t ssc) const { - uint64_t sourceId64 = static_cast(sourceId); - uint64_t apid64 = static_cast(apid); - uint64_t ssc64 = static_cast(ssc); + auto sourceId64 = static_cast(sourceId); + auto apid64 = static_cast(apid); + auto ssc64 = static_cast(ssc); return (sourceId64 << 32) | (apid64 << 16) | ssc64; } @@ -483,7 +483,7 @@ inline ReturnValue_t Service11TelecommandScheduling::getMapFilterFr if (typeRaw > 3) { return INVALID_TYPE_TIME_WINDOW; } - TypeOfTimeWindow type = static_cast(typeRaw); + auto type = static_cast(typeRaw); // we now have the type of delete activity - so now we set the range to delete, // according to the type of time window. @@ -558,7 +558,10 @@ inline ReturnValue_t Service11TelecommandScheduling::getMapFilterFr // additional security check, this should never be true if (itBegin->first > itEnd->first) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 +#else sif::printError("11::GetMapFilterFromData: itBegin > itEnd\n"); +#endif return RETURN_FAILED; } @@ -580,19 +583,22 @@ inline ReturnValue_t Service11TelecommandScheduling::handleInvalidD } template -inline void Service11TelecommandScheduling::debugPrintMultimapContent(void) const { +inline void Service11TelecommandScheduling::debugPrintMultimapContent() const { + for (const auto &dit : telecommandMap) { #if FSFW_DISABLE_PRINTOUT == 0 #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::debug << "Service11TelecommandScheduling::debugPrintMultimapContent: Multimap Content" - << std::endl; - sif::debug << "[" << dit->first << "]: Request ID: " << dit->second.requestId << " | " - << "Store Address: " << dit->second.storeAddr << std::endl; + sif::debug << "Service11TelecommandScheduling::debugPrintMultimapContent: Multimap Content" + << std::endl; + sif::debug << "[" << dit.first << "]: Request ID: " << dit.second.requestId << " | " + << "Store Address: " << dit.second.storeAddr.raw << std::endl; #else - sif::printDebug("Service11TelecommandScheduling::debugPrintMultimapContent: Multimap Content\n"); - for (auto dit = telecommandMap.begin(); dit != telecommandMap.end(); ++dit) { - sif::printDebug("[%d]: Request ID: %d | Store Address: %d\n", dit->first, - dit->second.requestId, dit->second.storeAddr); + sif::printDebug( + "Service11TelecommandScheduling::debugPrintMultimapContent: Multimap Content\n"); + for (auto dit = telecommandMap.begin(); dit != telecommandMap.end(); ++dit) { + sif::printDebug("[%d]: Request ID: %d | Store Address: %d\n", dit->first, + dit->second.requestId, dit->second.storeAddr); + } +#endif +#endif } -#endif -#endif } From dac700b80a98d9bfb5a9153c47589ce72c9381fc Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 20 May 2022 08:59:06 +0200 Subject: [PATCH 2/9] static STORE renamed --- .../tmtcpacket/pus/tc/TcPacketStoredBase.cpp | 22 ++++++++++--------- .../tmtcpacket/pus/tc/TcPacketStoredBase.h | 6 ++--- src/fsfw/tmtcpacket/pus/tc/TcPacketStoredIF.h | 2 +- .../tmtcpacket/pus/tc/TcPacketStoredPus.cpp | 12 +++++----- 4 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredBase.cpp b/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredBase.cpp index 8cc38c5f..22918526 100644 --- a/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredBase.cpp +++ b/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredBase.cpp @@ -6,20 +6,20 @@ #include "fsfw/objectmanager/frameworkObjects.h" #include "fsfw/serviceinterface/ServiceInterface.h" -StorageManagerIF* TcPacketStoredBase::store = nullptr; +StorageManagerIF* TcPacketStoredBase::STORE = nullptr; TcPacketStoredBase::TcPacketStoredBase() { this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS; - this->checkAndSetStore(); + TcPacketStoredBase::checkAndSetStore(); } -TcPacketStoredBase::~TcPacketStoredBase() {} +TcPacketStoredBase::~TcPacketStoredBase() = default; ReturnValue_t TcPacketStoredBase::getData(const uint8_t** dataPtr, size_t* dataSize) { - auto result = this->store->getData(storeAddress, dataPtr, dataSize); + auto result = TcPacketStoredBase::STORE->getData(storeAddress, dataPtr, dataSize); if (result != HasReturnvaluesIF::RETURN_OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::warning << "TcPacketStoredBase: Could not get data!" << std::endl; + sif::warning << "TcPacketStoredBase: Could not get data" << std::endl; #else sif::printWarning("TcPacketStoredBase: Could not get data!\n"); #endif @@ -28,11 +28,13 @@ ReturnValue_t TcPacketStoredBase::getData(const uint8_t** dataPtr, size_t* dataS } bool TcPacketStoredBase::checkAndSetStore() { - if (this->store == nullptr) { - this->store = ObjectManager::instance()->get(objects::TC_STORE); - if (this->store == nullptr) { + if (TcPacketStoredBase::STORE == nullptr) { + TcPacketStoredBase::STORE = ObjectManager::instance()->get(objects::TC_STORE); + if (TcPacketStoredBase::STORE == nullptr) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "TcPacketStoredBase::TcPacketStoredBase: TC Store not found!" << std::endl; + sif::error << "TcPacketStoredBase::TcPacketStoredBase: TC Store not found" << std::endl; +#else + sif::printError("TcPacketStoredBase::TcPacketStoredBase: TC Store not found\n"); #endif return false; } @@ -47,7 +49,7 @@ void TcPacketStoredBase::setStoreAddress(store_address_t setAddress, size_t tempSize; ReturnValue_t status = StorageManagerIF::RETURN_FAILED; if (this->checkAndSetStore()) { - status = this->store->getData(this->storeAddress, &tempData, &tempSize); + status = TcPacketStoredBase::STORE->getData(this->storeAddress, &tempData, &tempSize); } if (status == StorageManagerIF::RETURN_OK) { diff --git a/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredBase.h b/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredBase.h index 86f0d94e..ece0e482 100644 --- a/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredBase.h +++ b/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredBase.h @@ -65,7 +65,7 @@ class TcPacketStoredBase : public TcPacketStoredIF { * call tries to set it and throws an error message in case of failures. * The default store is objects::TC_STORE. */ - static StorageManagerIF* store; + static StorageManagerIF* STORE; /** * The address where the packet data of the object instance is stored. */ @@ -77,7 +77,7 @@ class TcPacketStoredBase : public TcPacketStoredIF { * @return @li @c true if the store is linked or could be created. * @li @c false otherwise. */ - bool checkAndSetStore(); + static bool checkAndSetStore(); }; -#endif /* TMTCPACKET_PUS_TcPacketStoredBase_H_ */ +#endif /* TMTCPACKET_PUS_TCPACKETSTORED_H_ */ diff --git a/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredIF.h b/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredIF.h index ac4019cd..4baeb3c5 100644 --- a/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredIF.h +++ b/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredIF.h @@ -9,7 +9,7 @@ class TcPacketStoredIF { public: - virtual ~TcPacketStoredIF(){}; + virtual ~TcPacketStoredIF()= default;; /** * With this call, the stored packet can be set to another packet in a store. This is useful diff --git a/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredPus.cpp b/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredPus.cpp index 153ad863..643c2ecc 100644 --- a/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredPus.cpp +++ b/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredPus.cpp @@ -14,8 +14,8 @@ TcPacketStoredPus::TcPacketStoredPus(uint16_t apid, uint8_t service, uint8_t sub } uint8_t* pData = nullptr; ReturnValue_t returnValue = - this->store->getFreeElement(&this->storeAddress, (TC_PACKET_MIN_SIZE + size), &pData); - if (returnValue != this->store->RETURN_OK) { + this->STORE->getFreeElement(&this->storeAddress, (TC_PACKET_MIN_SIZE + size), &pData); + if (returnValue != this->STORE->RETURN_OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::warning << "TcPacketStoredBase: Could not get free element from store!" << std::endl; #endif @@ -44,19 +44,19 @@ TcPacketStoredPus::TcPacketStoredPus(const uint8_t* data, size_t size) : TcPacke return; } if (this->checkAndSetStore()) { - ReturnValue_t status = store->addData(&storeAddress, data, size); + ReturnValue_t status = STORE->addData(&storeAddress, data, size); if (status != HasReturnvaluesIF::RETURN_OK) { this->setData(nullptr, size); } const uint8_t* storePtr = nullptr; // Repoint base data pointer to the data in the store. - store->getData(storeAddress, &storePtr, &size); + STORE->getData(storeAddress, &storePtr, &size); this->setData(const_cast(storePtr), size); } } ReturnValue_t TcPacketStoredPus::deletePacket() { - ReturnValue_t result = this->store->deleteData(this->storeAddress); + ReturnValue_t result = this->STORE->deleteData(this->storeAddress); this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS; // To circumvent size checks this->setData(nullptr, -1); @@ -68,7 +68,7 @@ TcPacketPusBase* TcPacketStoredPus::getPacketBase() { return this; } bool TcPacketStoredPus::isSizeCorrect() { const uint8_t* temp_data = nullptr; size_t temp_size; - ReturnValue_t status = this->store->getData(this->storeAddress, &temp_data, &temp_size); + ReturnValue_t status = this->STORE->getData(this->storeAddress, &temp_data, &temp_size); if (status == StorageManagerIF::RETURN_OK) { if (this->getFullSize() == temp_size) { return true; From 8e2597f609f54d7b4fe58183a3ff955cc5930cc7 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 20 May 2022 11:09:03 +0200 Subject: [PATCH 3/9] clang-format --- src/fsfw/pus/Service5EventReporting.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fsfw/pus/Service5EventReporting.cpp b/src/fsfw/pus/Service5EventReporting.cpp index 4517bc26..987217dc 100644 --- a/src/fsfw/pus/Service5EventReporting.cpp +++ b/src/fsfw/pus/Service5EventReporting.cpp @@ -86,8 +86,8 @@ ReturnValue_t Service5EventReporting::handleRequest(uint8_t subservice) { // In addition to the default PUSServiceBase initialization, this service needs // to be registered to the event manager to listen for events. ReturnValue_t Service5EventReporting::initialize() { - EventManagerIF* manager = ObjectManager::instance()->get(objects::EVENT_MANAGER); - if (manager == NULL) { + auto* manager = ObjectManager::instance()->get(objects::EVENT_MANAGER); + if (manager == nullptr) { return RETURN_FAILED; } // register Service 5 as listener for events From 0b53b4873fc4f7773a9ec59a985369794ceef3a6 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 20 May 2022 11:20:31 +0200 Subject: [PATCH 4/9] bugfix for srv11 --- src/fsfw/pus/Service11TelecommandScheduling.tpp | 4 +--- src/fsfw/tcdistribution/PUSDistributor.cpp | 10 ++++------ 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/fsfw/pus/Service11TelecommandScheduling.tpp b/src/fsfw/pus/Service11TelecommandScheduling.tpp index 41c36200..5ee08194 100644 --- a/src/fsfw/pus/Service11TelecommandScheduling.tpp +++ b/src/fsfw/pus/Service11TelecommandScheduling.tpp @@ -117,8 +117,6 @@ template inline ReturnValue_t Service11TelecommandScheduling::doInsertActivity( const uint8_t *data, size_t size) { uint32_t timestamp = 0; - const uint8_t *initData = data; - size_t initSz = size; ReturnValue_t result = SerializeAdapter::deSerialize(×tamp, &data, &size, DEF_END); if (result != RETURN_OK) { return result; @@ -143,7 +141,7 @@ inline ReturnValue_t Service11TelecommandScheduling::doInsertActivi // store currentPacket and receive the store address store_address_t addr{}; - if (tcStore->addData(&addr, initData, initSz) != RETURN_OK || + if (tcStore->addData(&addr, data, size) != RETURN_OK || addr.raw == storeId::INVALID_STORE_ADDRESS) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::error << "Service11TelecommandScheduling::doInsertActivity: Adding data to TC Store failed" diff --git a/src/fsfw/tcdistribution/PUSDistributor.cpp b/src/fsfw/tcdistribution/PUSDistributor.cpp index aadecd69..5c02145d 100644 --- a/src/fsfw/tcdistribution/PUSDistributor.cpp +++ b/src/fsfw/tcdistribution/PUSDistributor.cpp @@ -15,7 +15,7 @@ PUSDistributor::PUSDistributor(uint16_t setApid, object_id_t setObjectId, tcStatus(RETURN_FAILED), packetSource(setPacketSource) {} -PUSDistributor::~PUSDistributor() {} +PUSDistributor::~PUSDistributor() = default; PUSDistributor::TcMqMapIter PUSDistributor::selectDestination() { #if FSFW_CPP_OSTREAM_ENABLED == 1 && PUS_DISTRIBUTOR_DEBUGGING == 1 @@ -23,7 +23,7 @@ PUSDistributor::TcMqMapIter PUSDistributor::selectDestination() { sif::debug << "PUSDistributor::handlePacket received: " << storeId.poolIndex << ", " << storeId.packetIndex << std::endl; #endif - TcMqMapIter queueMapIt = this->queueMap.end(); + auto queueMapIt = this->queueMap.end(); if (this->currentPacket == nullptr) { return queueMapIt; } @@ -49,9 +49,7 @@ PUSDistributor::TcMqMapIter PUSDistributor::selectDestination() { << " error" << std::endl; #else sif::printWarning( - "PUSDistributor::handlePacket: Packet format invalid, " - "%s error\n", - keyword); + "PUSDistributor::handlePacket: Packet format invalid, %s error\n", keyword); #endif #endif } @@ -133,7 +131,7 @@ ReturnValue_t PUSDistributor::initialize() { return ObjectManagerIF::CHILD_INIT_FAILED; } - CCSDSDistributorIF* ccsdsDistributor = + auto* ccsdsDistributor = ObjectManager::instance()->get(packetSource); if (ccsdsDistributor == nullptr) { #if FSFW_CPP_OSTREAM_ENABLED == 1 From 34658ef7dba9d6ae67b7b433088fe4b3c901c1f5 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 24 May 2022 10:40:25 +0200 Subject: [PATCH 5/9] afmt --- src/fsfw/pus/Service11TelecommandScheduling.h | 24 ++++++++++--------- src/fsfw/tcdistribution/PUSDistributor.cpp | 7 +++--- src/fsfw/tmtcpacket/pus/tc/TcPacketStoredIF.h | 3 ++- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/fsfw/pus/Service11TelecommandScheduling.h b/src/fsfw/pus/Service11TelecommandScheduling.h index 9a8be603..f11c8bd1 100644 --- a/src/fsfw/pus/Service11TelecommandScheduling.h +++ b/src/fsfw/pus/Service11TelecommandScheduling.h @@ -45,17 +45,19 @@ class Service11TelecommandScheduling final : public PusServiceBase { HasReturnvaluesIF::makeReturnCode(CLASS_ID, 3); // The types of PUS-11 subservices - enum [[maybe_unused]] Subservice : uint8_t{ENABLE_SCHEDULING = 1, - DISABLE_SCHEDULING = 2, - RESET_SCHEDULING = 3, - INSERT_ACTIVITY = 4, - DELETE_ACTIVITY = 5, - FILTER_DELETE_ACTIVITY = 6, - TIMESHIFT_ACTIVITY = 7, - FILTER_TIMESHIFT_ACTIVITY = 8, - DETAIL_REPORT = 9, - TIMEBASE_SCHEDULE_DETAIL_REPORT = 10, - TIMESHIFT_ALL_SCHEDULE_ACTIVITIES = 15}; + enum Subservice : uint8_t { + ENABLE_SCHEDULING = 1, + DISABLE_SCHEDULING = 2, + RESET_SCHEDULING = 3, + INSERT_ACTIVITY = 4, + DELETE_ACTIVITY = 5, + FILTER_DELETE_ACTIVITY = 6, + TIMESHIFT_ACTIVITY = 7, + FILTER_TIMESHIFT_ACTIVITY = 8, + DETAIL_REPORT = 9, + TIMEBASE_SCHEDULE_DETAIL_REPORT = 10, + TIMESHIFT_ALL_SCHEDULE_ACTIVITIES = 15 + }; // The types of time windows for TC[11,6] and TC[11,8], as defined in ECSS-E-ST-70-41C, // requirement 8.11.3c (p. 507) diff --git a/src/fsfw/tcdistribution/PUSDistributor.cpp b/src/fsfw/tcdistribution/PUSDistributor.cpp index 5c02145d..dad002a1 100644 --- a/src/fsfw/tcdistribution/PUSDistributor.cpp +++ b/src/fsfw/tcdistribution/PUSDistributor.cpp @@ -48,8 +48,8 @@ PUSDistributor::TcMqMapIter PUSDistributor::selectDestination() { sif::warning << "PUSDistributor::handlePacket: Packet format invalid, " << keyword << " error" << std::endl; #else - sif::printWarning( - "PUSDistributor::handlePacket: Packet format invalid, %s error\n", keyword); + sif::printWarning("PUSDistributor::handlePacket: Packet format invalid, %s error\n", + keyword); #endif #endif } @@ -131,8 +131,7 @@ ReturnValue_t PUSDistributor::initialize() { return ObjectManagerIF::CHILD_INIT_FAILED; } - auto* ccsdsDistributor = - ObjectManager::instance()->get(packetSource); + auto* ccsdsDistributor = ObjectManager::instance()->get(packetSource); if (ccsdsDistributor == nullptr) { #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::error << "PUSDistributor::initialize: Packet source invalid" << std::endl; diff --git a/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredIF.h b/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredIF.h index 4baeb3c5..7ac8c331 100644 --- a/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredIF.h +++ b/src/fsfw/tmtcpacket/pus/tc/TcPacketStoredIF.h @@ -9,7 +9,8 @@ class TcPacketStoredIF { public: - virtual ~TcPacketStoredIF()= default;; + virtual ~TcPacketStoredIF() = default; + ; /** * With this call, the stored packet can be set to another packet in a store. This is useful From e60a665de4d53bee65f782c099e7a739e366d594 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 24 May 2022 11:52:29 +0200 Subject: [PATCH 6/9] added 3 new subservices --- src/fsfw/events/fwSubsystemIdRanges.h | 1 + src/fsfw/pus/Service11TelecommandScheduling.h | 15 ++++ .../pus/Service11TelecommandScheduling.tpp | 80 ++++++++++++++----- src/fsfw/tmtcservices/AcceptsTelecommandsIF.h | 4 +- 4 files changed, 79 insertions(+), 21 deletions(-) diff --git a/src/fsfw/events/fwSubsystemIdRanges.h b/src/fsfw/events/fwSubsystemIdRanges.h index 21123600..fa4351e9 100644 --- a/src/fsfw/events/fwSubsystemIdRanges.h +++ b/src/fsfw/events/fwSubsystemIdRanges.h @@ -27,6 +27,7 @@ enum : uint8_t { PUS_SERVICE_6 = 86, PUS_SERVICE_8 = 88, PUS_SERVICE_9 = 89, + PUS_SERVICE_11 = 91, PUS_SERVICE_17 = 97, PUS_SERVICE_23 = 103, MGM_LIS3MDL = 106, diff --git a/src/fsfw/pus/Service11TelecommandScheduling.h b/src/fsfw/pus/Service11TelecommandScheduling.h index f11c8bd1..0fed8bca 100644 --- a/src/fsfw/pus/Service11TelecommandScheduling.h +++ b/src/fsfw/pus/Service11TelecommandScheduling.h @@ -44,6 +44,12 @@ class Service11TelecommandScheduling final : public PusServiceBase { static constexpr ReturnValue_t INVALID_RELATIVE_TIME = HasReturnvaluesIF::makeReturnCode(CLASS_ID, 3); + static constexpr uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::PUS_SERVICE_11; + + //! [EXPORT] : [COMMENT] Deletion of a TC from the map failed. + //! P1: First 32 bit of request ID, P2. Last 32 bit of Request ID + static constexpr Event TC_DELETION_FAILED = event::makeEvent(SUBSYSTEM_ID, 0, severity::MEDIUM); + // The types of PUS-11 subservices enum Subservice : uint8_t { ENABLE_SCHEDULING = 1, @@ -75,6 +81,9 @@ class Service11TelecommandScheduling final : public PusServiceBase { ~Service11TelecommandScheduling() override; + void enableExpiredTcDeletion(); + void disableExpiredTcDeletion(); + /** PusServiceBase overrides */ ReturnValue_t handleRequest(uint8_t subservice) override; ReturnValue_t performService() override; @@ -92,6 +101,11 @@ class Service11TelecommandScheduling final : public PusServiceBase { // minimum release time offset to insert into schedule const uint16_t RELEASE_TIME_MARGIN_SECONDS = 5; + /** + * By default, the scheduling will be disabled. This is a standard requirement + */ + bool schedulingEnabled = false; + bool deleteExpiredTcWhenDisabled = true; bool debugMode = false; StorageManagerIF* tcStore = nullptr; AcceptsTelecommandsIF* tcRecipient = nullptr; @@ -106,6 +120,7 @@ class Service11TelecommandScheduling final : public PusServiceBase { TelecommandMap telecommandMap; + ReturnValue_t handleResetCommand(); /** * @brief Logic to be performed on an incoming TC[11,4]. * @return RETURN_OK if successful diff --git a/src/fsfw/pus/Service11TelecommandScheduling.tpp b/src/fsfw/pus/Service11TelecommandScheduling.tpp index 5ee08194..9304dbf1 100644 --- a/src/fsfw/pus/Service11TelecommandScheduling.tpp +++ b/src/fsfw/pus/Service11TelecommandScheduling.tpp @@ -38,6 +38,17 @@ inline ReturnValue_t Service11TelecommandScheduling::handleRequest( return handleInvalidData("handleRequest"); } switch (subservice) { + case Subservice::ENABLE_SCHEDULING: { + schedulingEnabled = true; + break; + } + case Subservice::DISABLE_SCHEDULING: { + schedulingEnabled = false; + break; + } + case Subservice::RESET_SCHEDULING: { + return handleResetCommand(); + } case Subservice::INSERT_ACTIVITY: return doInsertActivity(data, size); case Subservice::DELETE_ACTIVITY: @@ -49,41 +60,42 @@ inline ReturnValue_t Service11TelecommandScheduling::handleRequest( case Subservice::FILTER_TIMESHIFT_ACTIVITY: return doFilterTimeshiftActivity(data, size); default: - break; + return AcceptsTelecommandsIF::INVALID_SUBSERVICE; } - - return HasReturnvaluesIF::RETURN_FAILED; + return RETURN_OK; } template inline ReturnValue_t Service11TelecommandScheduling::performService() { - // DEBUG - // DebugPrintMultimapContent(); - + if (not schedulingEnabled) { + return RETURN_OK; + } // get current time as UNIX timestamp timeval tNow = {}; Clock::getClock_timeval(&tNow); + // TODO: Optionally limit the max number of released TCs per cycle? // NOTE: The iterator is increased in the loop here. Increasing the iterator as for-loop arg // does not work in this case as we are deleting the current element here. for (auto it = telecommandMap.begin(); it != telecommandMap.end();) { if (it->first <= tNow.tv_sec) { - // release tc - TmTcMessage releaseMsg(it->second.storeAddr); - auto sendRet = this->requestQueue->sendMessage(recipientMsgQueueId, &releaseMsg, false); + if (schedulingEnabled) { + // release tc + TmTcMessage releaseMsg(it->second.storeAddr); + auto sendRet = this->requestQueue->sendMessage(recipientMsgQueueId, &releaseMsg, false); - if (sendRet != HasReturnvaluesIF::RETURN_OK) { - return sendRet; - } - - telecommandMap.erase(it++); - - if (debugMode) { + if (sendRet != HasReturnvaluesIF::RETURN_OK) { + return sendRet; + } + if (debugMode) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::info << "Released TC & erased it from TC map" << std::endl; + sif::info << "Released TC & erased it from TC map" << std::endl; #else - sif::printInfo("Released TC & erased it from TC map\n"); + sif::printInfo("Released TC & erased it from TC map\n"); #endif + } + } else if (deleteExpiredTcWhenDisabled) { + telecommandMap.erase(it++); } continue; } @@ -113,6 +125,26 @@ inline ReturnValue_t Service11TelecommandScheduling::initialize() { return res; } +template +inline ReturnValue_t Service11TelecommandScheduling::handleResetCommand() { + for (auto it = telecommandMap.begin(); it != telecommandMap.end(); it++) { + ReturnValue_t result = tcStore->deleteData(it->second.storeAddr); + if (result != RETURN_OK) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + // This should not happen + sif::warning << "Service11TelecommandScheduling::handleRequestDeleting: Deletion failed" + << std::endl; +#else + sif::printWarning("Service11TelecommandScheduling::handleRequestDeleting: Deletion failed\n"); +#endif + triggerEvent(TC_DELETION_FAILED, (it->second.requestId >> 32) & 0xffffffff, + it->second.requestId & 0xffffffff); + } + } + telecommandMap.clear(); + return RETURN_OK; +} + template inline ReturnValue_t Service11TelecommandScheduling::doInsertActivity( const uint8_t *data, size_t size) { @@ -582,7 +614,7 @@ inline ReturnValue_t Service11TelecommandScheduling::handleInvalidD template inline void Service11TelecommandScheduling::debugPrintMultimapContent() const { - for (const auto &dit : telecommandMap) { + for ([[maybe_unused]] const auto &dit : telecommandMap) { #if FSFW_DISABLE_PRINTOUT == 0 #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::debug << "Service11TelecommandScheduling::debugPrintMultimapContent: Multimap Content" @@ -600,3 +632,13 @@ inline void Service11TelecommandScheduling::debugPrintMultimapConte #endif } } + +template +inline void Service11TelecommandScheduling::enableExpiredTcDeletion() { + deleteExpiredTcWhenDisabled = true; +} + +template +inline void Service11TelecommandScheduling::disableExpiredTcDeletion() { + deleteExpiredTcWhenDisabled = false; +} diff --git a/src/fsfw/tmtcservices/AcceptsTelecommandsIF.h b/src/fsfw/tmtcservices/AcceptsTelecommandsIF.h index 4186f4df..e18a4f3a 100644 --- a/src/fsfw/tmtcservices/AcceptsTelecommandsIF.h +++ b/src/fsfw/tmtcservices/AcceptsTelecommandsIF.h @@ -1,7 +1,7 @@ #ifndef FRAMEWORK_TMTCSERVICES_ACCEPTSTELECOMMANDSIF_H_ #define FRAMEWORK_TMTCSERVICES_ACCEPTSTELECOMMANDSIF_H_ -#include "../ipc/MessageQueueSenderIF.h" +#include "fsfw/ipc/MessageQueueSenderIF.h" /** * @brief This interface is implemented by classes that are sinks for @@ -20,7 +20,7 @@ class AcceptsTelecommandsIF { /** * @brief The virtual destructor as it is mandatory for C++ interfaces. */ - virtual ~AcceptsTelecommandsIF() {} + virtual ~AcceptsTelecommandsIF() = default; /** * @brief Getter for the service id. * @details Any receiving service (at least any PUS service) shall have a From f7cde800880f17bcfbed77aa4cd66fcb2a9b1ee3 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 24 May 2022 14:32:35 +0200 Subject: [PATCH 7/9] added missing delete --- src/fsfw/pus/Service11TelecommandScheduling.tpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/fsfw/pus/Service11TelecommandScheduling.tpp b/src/fsfw/pus/Service11TelecommandScheduling.tpp index 9304dbf1..cb43e8e8 100644 --- a/src/fsfw/pus/Service11TelecommandScheduling.tpp +++ b/src/fsfw/pus/Service11TelecommandScheduling.tpp @@ -94,6 +94,7 @@ inline ReturnValue_t Service11TelecommandScheduling::performService sif::printInfo("Released TC & erased it from TC map\n"); #endif } + telecommandMap.erase(it++); } else if (deleteExpiredTcWhenDisabled) { telecommandMap.erase(it++); } From e59f1f26bf672fe3256499ca2859aa32a0b72e5a Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 24 May 2022 14:33:18 +0200 Subject: [PATCH 8/9] return end iterator instead of crashing --- src/fsfw/tcdistribution/CCSDSDistributor.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/fsfw/tcdistribution/CCSDSDistributor.cpp b/src/fsfw/tcdistribution/CCSDSDistributor.cpp index 3f4bbee3..628dd8d0 100644 --- a/src/fsfw/tcdistribution/CCSDSDistributor.cpp +++ b/src/fsfw/tcdistribution/CCSDSDistributor.cpp @@ -9,7 +9,7 @@ CCSDSDistributor::CCSDSDistributor(uint16_t setDefaultApid, object_id_t setObjectId) : TcDistributor(setObjectId), defaultApid(setDefaultApid) {} -CCSDSDistributor::~CCSDSDistributor() {} +CCSDSDistributor::~CCSDSDistributor() = default; TcDistributor::TcMqMapIter CCSDSDistributor::selectDestination() { #if CCSDS_DISTRIBUTOR_DEBUGGING == 1 @@ -38,6 +38,7 @@ TcDistributor::TcMqMapIter CCSDSDistributor::selectDestination() { " store failed!\n"); #endif #endif + return queueMap.end(); } SpacePacketBase currentPacket(packet); @@ -45,7 +46,7 @@ TcDistributor::TcMqMapIter CCSDSDistributor::selectDestination() { sif::info << "CCSDSDistributor::selectDestination has packet with APID " << std::hex << currentPacket.getAPID() << std::dec << std::endl; #endif - TcMqMapIter position = this->queueMap.find(currentPacket.getAPID()); + auto position = this->queueMap.find(currentPacket.getAPID()); if (position != this->queueMap.end()) { return position; } else { From c697d0f8ab83163c5d58e288ca74c771e6a9bb45 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 30 May 2022 10:34:03 +0200 Subject: [PATCH 9/9] bump etl to 20.28.0 --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 40c0b879..6328f176 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -71,7 +71,7 @@ set(FSFW_ETL_LIB_MAJOR_VERSION 20 CACHE STRING "ETL library major version requirement") set(FSFW_ETL_LIB_VERSION - ${FSFW_ETL_LIB_MAJOR_VERSION}.27.3 + ${FSFW_ETL_LIB_MAJOR_VERSION}.28.0 CACHE STRING "ETL library exact version requirement") set(FSFW_ETL_LINK_TARGET etl::etl) @@ -185,7 +185,7 @@ endif() message(STATUS "${MSG_PREFIX} Finding and/or providing ETL library") # Check whether the user has already installed ETL first -find_package(${FSFW_ETL_LIB_NAME} ${FSFW_ETL_LIB_MAJOR_VERSION} QUIET) +find_package(${FSFW_ETL_LIB_NAME} ${FSFW_ETL_LIB_MAJOR_VERSION} CONFIG QUIET) # Not installed, so use FetchContent to download and provide etl if(NOT ${FSFW_ETL_LIB_NAME}_FOUND) message(