From bbd27eca7630f98c65b5e3815403663ff1450901 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 10 Mar 2023 20:32:11 +0100 Subject: [PATCH] basic FDIR if dump takes too long --- .../controller/acs/MultiplicativeKalmanFilter.h | 2 +- mission/persistentTmStoreDefs.h | 12 +++++++----- mission/tmtc/PersistentTmStore.cpp | 13 +++++++++++-- mission/tmtc/PersistentTmStore.h | 4 +++- mission/tmtc/TmStoreTaskBase.cpp | 16 +++++++++++++++- mission/tmtc/TmStoreTaskBase.h | 4 ++++ 6 files changed, 41 insertions(+), 10 deletions(-) diff --git a/mission/controller/acs/MultiplicativeKalmanFilter.h b/mission/controller/acs/MultiplicativeKalmanFilter.h index 3e9bfa49..ceb98339 100644 --- a/mission/controller/acs/MultiplicativeKalmanFilter.h +++ b/mission/controller/acs/MultiplicativeKalmanFilter.h @@ -86,7 +86,7 @@ class MultiplicativeKalmanFilter { double initialCovarianceMatrix[6][6] = {{0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}}; - double propagatedQuaternion[4]; /*Filter Quaternion for next step*/ + double propagatedQuaternion[4]; /*Filter Quaternion for next step*/ uint8_t sensorsAvail = 0; /*Outputs*/ diff --git a/mission/persistentTmStoreDefs.h b/mission/persistentTmStoreDefs.h index 021f6f89..e84f12c1 100644 --- a/mission/persistentTmStoreDefs.h +++ b/mission/persistentTmStoreDefs.h @@ -25,17 +25,19 @@ static constexpr Event POSSIBLE_FILE_CORRUPTION = event::makeEvent(SUBSYSTEM_ID, //! P2: Allowed file size static constexpr Event FILE_TOO_LARGE = event::makeEvent(SUBSYSTEM_ID, 1, severity::LOW); static constexpr Event BUSY_DUMPING_EVENT = event::makeEvent(SUBSYSTEM_ID, 2, severity::INFO); +//! [EXPORT] : [COMMENT] Dump was cancelled. P1: Object ID of store. +static constexpr Event DUMP_WAS_CANCELLED = event::makeEvent(SUBSYSTEM_ID, 3, severity::LOW); //! [EXPORT] : [COMMENT] P1: Start time as UNIX seconds. P2: End time as UNIX seconds. -static constexpr Event DUMP_OK_STORE_DONE = event::makeEvent(SUBSYSTEM_ID, 3, severity::INFO); +static constexpr Event DUMP_OK_STORE_DONE = event::makeEvent(SUBSYSTEM_ID, 5, severity::INFO); //! [EXPORT] : [COMMENT] P1: Start time as UNIX seconds. P2: End time as UNIX seconds. -static constexpr Event DUMP_NOK_STORE_DONE = event::makeEvent(SUBSYSTEM_ID, 4, severity::INFO); +static constexpr Event DUMP_NOK_STORE_DONE = event::makeEvent(SUBSYSTEM_ID, 6, severity::INFO); //! [EXPORT] : [COMMENT] P1: Start time as UNIX seconds. P2: End time as UNIX seconds. -static constexpr Event DUMP_MISC_STORE_DONE = event::makeEvent(SUBSYSTEM_ID, 5, severity::INFO); +static constexpr Event DUMP_MISC_STORE_DONE = event::makeEvent(SUBSYSTEM_ID, 7, severity::INFO); //! [EXPORT] : [COMMENT] P1: Start time as UNIX seconds. P2: End time as UNIX seconds. -static constexpr Event DUMP_HK_STORE_DONE = event::makeEvent(SUBSYSTEM_ID, 6, severity::INFO); +static constexpr Event DUMP_HK_STORE_DONE = event::makeEvent(SUBSYSTEM_ID, 8, severity::INFO); //! [EXPORT] : [COMMENT] P1: Start time as UNIX seconds. P2: End time as UNIX seconds. -static constexpr Event DUMP_CFDP_STORE_DONE = event::makeEvent(SUBSYSTEM_ID, 7, severity::INFO); +static constexpr Event DUMP_CFDP_STORE_DONE = event::makeEvent(SUBSYSTEM_ID, 9, severity::INFO); }; // namespace persTmStore #endif /* MISSION_PERSISTENTTMSTOREDEFS_H_ */ diff --git a/mission/tmtc/PersistentTmStore.cpp b/mission/tmtc/PersistentTmStore.cpp index 79b7384b..2599a42f 100644 --- a/mission/tmtc/PersistentTmStore.cpp +++ b/mission/tmtc/PersistentTmStore.cpp @@ -26,6 +26,11 @@ PersistentTmStore::PersistentTmStore(PersistentTmStoreArgs args) calcDiffSeconds(args.intervalUnit, args.intervalCount); } +ReturnValue_t PersistentTmStore::cancelDump() { + state = State::IDLE; + return returnvalue::OK; +} + ReturnValue_t PersistentTmStore::assignAndOrCreateMostRecentFile() { if (not activeFile.has_value()) { return createMostRecentFile(std::nullopt); @@ -33,7 +38,8 @@ ReturnValue_t PersistentTmStore::assignAndOrCreateMostRecentFile() { return returnvalue::OK; } -ReturnValue_t PersistentTmStore::handleCommandQueue(StorageManagerIF& ipcStore) { +ReturnValue_t PersistentTmStore::handleCommandQueue(StorageManagerIF& ipcStore, + Command_t& execCmd) { CommandMessage cmdMessage; ReturnValue_t result = tcQueue->receiveMessage(&cmdMessage); if (result != returnvalue::OK) { @@ -49,6 +55,7 @@ ReturnValue_t PersistentTmStore::handleCommandQueue(StorageManagerIF& ipcStore) size_t size = accessor.second.size(); SerializeAdapter::deSerialize(&deleteUpToUnixSeconds, accessor.second.data(), &size, SerializeIF::Endianness::NETWORK); + execCmd = cmd; deleteUpTo(deleteUpToUnixSeconds); } else if (cmd == TmStoreMessage::DOWNLINK_STORE_CONTENT_TIME) { Clock::getClock_timeval(¤tTv); @@ -67,10 +74,12 @@ ReturnValue_t PersistentTmStore::handleCommandQueue(StorageManagerIF& ipcStore) result = startDumpFromUpTo(dumpFromUnixSeconds, dumpUntilUnixSeconds); if (result == BUSY_DUMPING) { triggerEvent(persTmStore::BUSY_DUMPING_EVENT); + } else { + execCmd = cmd; } } } - return returnvalue::OK; + return result; } ReturnValue_t PersistentTmStore::startDumpFrom(uint32_t fromUnixSeconds) { diff --git a/mission/tmtc/PersistentTmStore.h b/mission/tmtc/PersistentTmStore.h index 994b7d30..a0910026 100644 --- a/mission/tmtc/PersistentTmStore.h +++ b/mission/tmtc/PersistentTmStore.h @@ -1,6 +1,7 @@ #ifndef MISSION_TMTC_TMSTOREBACKEND_H_ #define MISSION_TMTC_TMSTOREBACKEND_H_ +#include #include #include #include @@ -49,7 +50,7 @@ class PersistentTmStore : public TmStoreFrontendSimpleIF, public SystemObject { ReturnValue_t initializeTmStore(); State getState() const; - ReturnValue_t handleCommandQueue(StorageManagerIF& ipcStore); + ReturnValue_t handleCommandQueue(StorageManagerIF& ipcStore, Command_t& execCmd); void deleteUpTo(uint32_t unixSeconds); ReturnValue_t startDumpFrom(uint32_t fromUnixSeconds); @@ -66,6 +67,7 @@ class PersistentTmStore : public TmStoreFrontendSimpleIF, public SystemObject { void getStartAndEndTimeCurrentOrLastDump(uint32_t& startTime, uint32_t& endTime) const; ReturnValue_t storePacket(PusTmReader& reader); + ReturnValue_t cancelDump(); protected: StorageManagerIF& tmStore; diff --git a/mission/tmtc/TmStoreTaskBase.cpp b/mission/tmtc/TmStoreTaskBase.cpp index fc79439b..ba0197fd 100644 --- a/mission/tmtc/TmStoreTaskBase.cpp +++ b/mission/tmtc/TmStoreTaskBase.cpp @@ -1,7 +1,11 @@ #include "TmStoreTaskBase.h" +#include #include #include +#include + +#include "mission/persistentTmStoreDefs.h" TmStoreTaskBase::TmStoreTaskBase(object_id_t objectId, StorageManagerIF& ipcStore, VirtualChannel& channel, SdCardMountedIF& sdcMan) @@ -22,6 +26,7 @@ bool TmStoreTaskBase::handleOneStore(PersistentTmStoreWithTmQueue& store, Event size_t dumpedLen; bool fileHasSwapped; if (not channel.isBusy()) { + tmSinkBusyCd.resetTimer(); // TODO: We could continously dump until a file swap during active downlink.. result = store.dumpNextPacket(channel, dumpedLen, fileHasSwapped); if (result == PersistentTmStore::DUMP_DONE) { @@ -34,10 +39,19 @@ bool TmStoreTaskBase::handleOneStore(PersistentTmStoreWithTmQueue& store, Event dumpsPerformed = true; } } + if (cancelDumpCd.hasTimedOut() or tmSinkBusyCd.hasTimedOut()) { + triggerEvent(persTmStore::DUMP_WAS_CANCELLED, store.getObjectId()); + store.cancelDump(); + } } else { + Command_t execCmd; // Handle TC requests, for example deletion or retrieval requests. - result = store.handleCommandQueue(ipcStore); + result = store.handleCommandQueue(ipcStore, execCmd); if (result == returnvalue::OK) { + if (execCmd == TmStoreMessage::DOWNLINK_STORE_CONTENT_TIME) { + cancelDumpCd.resetTimer(); + tmSinkBusyCd.resetTimer(); + } tcRequestReceived = true; } } diff --git a/mission/tmtc/TmStoreTaskBase.h b/mission/tmtc/TmStoreTaskBase.h index aa308590..c29db8bf 100644 --- a/mission/tmtc/TmStoreTaskBase.h +++ b/mission/tmtc/TmStoreTaskBase.h @@ -28,6 +28,10 @@ class TmStoreTaskBase : public SystemObject { StorageManagerIF& ipcStore; Countdown sdCardCheckCd = Countdown(800); + // 20 minutes are allowed as maximum dump time. + Countdown cancelDumpCd = Countdown(60 * 20 * 1000); + // If the TM sink is busy for 1 minute for whatever reason, cancel the dump. + Countdown tmSinkBusyCd = Countdown(60 * 1000); VirtualChannel& channel; bool storesInitialized = false; SdCardMountedIF& sdcMan;