From 13cda86d23f8761a751b3a71a30b18ebcffbbe74 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 18 May 2022 13:13:24 +0200 Subject: [PATCH 1/5] remove commented code --- src/fsfw/osal/common/TcpTmTcServer.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/fsfw/osal/common/TcpTmTcServer.cpp b/src/fsfw/osal/common/TcpTmTcServer.cpp index b3017e01..a8890006 100644 --- a/src/fsfw/osal/common/TcpTmTcServer.cpp +++ b/src/fsfw/osal/common/TcpTmTcServer.cpp @@ -122,7 +122,6 @@ TcpTmTcServer::~TcpTmTcServer() { closeSocket(listenerTcpSocket); } } connSocket = accept(listenerTcpSocket, &clientSockAddr, &connectorSockAddrLen); - // connSocket = accept(listenerTcpSocket, nullptr, nullptr); if (connSocket == INVALID_SOCKET) { handleError(Protocol::TCP, ErrorSources::ACCEPT_CALL, 500); From 34658ef7dba9d6ae67b7b433088fe4b3c901c1f5 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 24 May 2022 10:40:25 +0200 Subject: [PATCH 2/5] 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 3/5] 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 4/5] 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 5/5] 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 {