Refactor TM handling #450

Merged
muellerr merged 47 commits from refactor_tm_handling into develop 2023-03-11 15:05:22 +01:00
6 changed files with 41 additions and 10 deletions
Showing only changes of commit bbd27eca76 - Show all commits

View File

@ -25,17 +25,19 @@ static constexpr Event POSSIBLE_FILE_CORRUPTION = event::makeEvent(SUBSYSTEM_ID,
//! P2: Allowed file size //! P2: Allowed file size
static constexpr Event FILE_TOO_LARGE = event::makeEvent(SUBSYSTEM_ID, 1, severity::LOW); 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); 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. //! [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. //! [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. //! [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. //! [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. //! [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 }; // namespace persTmStore
#endif /* MISSION_PERSISTENTTMSTOREDEFS_H_ */ #endif /* MISSION_PERSISTENTTMSTOREDEFS_H_ */

View File

@ -26,6 +26,11 @@ PersistentTmStore::PersistentTmStore(PersistentTmStoreArgs args)
calcDiffSeconds(args.intervalUnit, args.intervalCount); calcDiffSeconds(args.intervalUnit, args.intervalCount);
} }
ReturnValue_t PersistentTmStore::cancelDump() {
state = State::IDLE;
return returnvalue::OK;
}
ReturnValue_t PersistentTmStore::assignAndOrCreateMostRecentFile() { ReturnValue_t PersistentTmStore::assignAndOrCreateMostRecentFile() {
if (not activeFile.has_value()) { if (not activeFile.has_value()) {
return createMostRecentFile(std::nullopt); return createMostRecentFile(std::nullopt);
@ -33,7 +38,8 @@ ReturnValue_t PersistentTmStore::assignAndOrCreateMostRecentFile() {
return returnvalue::OK; return returnvalue::OK;
} }
ReturnValue_t PersistentTmStore::handleCommandQueue(StorageManagerIF& ipcStore) { ReturnValue_t PersistentTmStore::handleCommandQueue(StorageManagerIF& ipcStore,
Command_t& execCmd) {
CommandMessage cmdMessage; CommandMessage cmdMessage;
ReturnValue_t result = tcQueue->receiveMessage(&cmdMessage); ReturnValue_t result = tcQueue->receiveMessage(&cmdMessage);
if (result != returnvalue::OK) { if (result != returnvalue::OK) {
@ -49,6 +55,7 @@ ReturnValue_t PersistentTmStore::handleCommandQueue(StorageManagerIF& ipcStore)
size_t size = accessor.second.size(); size_t size = accessor.second.size();
SerializeAdapter::deSerialize(&deleteUpToUnixSeconds, accessor.second.data(), &size, SerializeAdapter::deSerialize(&deleteUpToUnixSeconds, accessor.second.data(), &size,
SerializeIF::Endianness::NETWORK); SerializeIF::Endianness::NETWORK);
execCmd = cmd;
deleteUpTo(deleteUpToUnixSeconds); deleteUpTo(deleteUpToUnixSeconds);
} else if (cmd == TmStoreMessage::DOWNLINK_STORE_CONTENT_TIME) { } else if (cmd == TmStoreMessage::DOWNLINK_STORE_CONTENT_TIME) {
Clock::getClock_timeval(&currentTv); Clock::getClock_timeval(&currentTv);
@ -67,10 +74,12 @@ ReturnValue_t PersistentTmStore::handleCommandQueue(StorageManagerIF& ipcStore)
result = startDumpFromUpTo(dumpFromUnixSeconds, dumpUntilUnixSeconds); result = startDumpFromUpTo(dumpFromUnixSeconds, dumpUntilUnixSeconds);
if (result == BUSY_DUMPING) { if (result == BUSY_DUMPING) {
triggerEvent(persTmStore::BUSY_DUMPING_EVENT); triggerEvent(persTmStore::BUSY_DUMPING_EVENT);
} else {
execCmd = cmd;
} }
} }
} }
return returnvalue::OK; return result;
} }
ReturnValue_t PersistentTmStore::startDumpFrom(uint32_t fromUnixSeconds) { ReturnValue_t PersistentTmStore::startDumpFrom(uint32_t fromUnixSeconds) {

View File

@ -1,6 +1,7 @@
#ifndef MISSION_TMTC_TMSTOREBACKEND_H_ #ifndef MISSION_TMTC_TMSTOREBACKEND_H_
#define MISSION_TMTC_TMSTOREBACKEND_H_ #define MISSION_TMTC_TMSTOREBACKEND_H_
#include <fsfw/ipc/CommandMessageIF.h>
#include <fsfw/objectmanager/SystemObject.h> #include <fsfw/objectmanager/SystemObject.h>
#include <fsfw/storagemanager/StorageManagerIF.h> #include <fsfw/storagemanager/StorageManagerIF.h>
#include <fsfw/timemanager/CdsShortTimeStamper.h> #include <fsfw/timemanager/CdsShortTimeStamper.h>
@ -49,7 +50,7 @@ class PersistentTmStore : public TmStoreFrontendSimpleIF, public SystemObject {
ReturnValue_t initializeTmStore(); ReturnValue_t initializeTmStore();
State getState() const; State getState() const;
ReturnValue_t handleCommandQueue(StorageManagerIF& ipcStore); ReturnValue_t handleCommandQueue(StorageManagerIF& ipcStore, Command_t& execCmd);
void deleteUpTo(uint32_t unixSeconds); void deleteUpTo(uint32_t unixSeconds);
ReturnValue_t startDumpFrom(uint32_t fromUnixSeconds); 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; void getStartAndEndTimeCurrentOrLastDump(uint32_t& startTime, uint32_t& endTime) const;
ReturnValue_t storePacket(PusTmReader& reader); ReturnValue_t storePacket(PusTmReader& reader);
ReturnValue_t cancelDump();
protected: protected:
StorageManagerIF& tmStore; StorageManagerIF& tmStore;

View File

@ -1,7 +1,11 @@
#include "TmStoreTaskBase.h" #include "TmStoreTaskBase.h"
#include <fsfw/ipc/CommandMessageIF.h>
#include <fsfw/tasks/TaskFactory.h> #include <fsfw/tasks/TaskFactory.h>
#include <fsfw/timemanager/Stopwatch.h> #include <fsfw/timemanager/Stopwatch.h>
#include <fsfw/tmstorage/TmStoreMessage.h>
#include "mission/persistentTmStoreDefs.h"
TmStoreTaskBase::TmStoreTaskBase(object_id_t objectId, StorageManagerIF& ipcStore, TmStoreTaskBase::TmStoreTaskBase(object_id_t objectId, StorageManagerIF& ipcStore,
VirtualChannel& channel, SdCardMountedIF& sdcMan) VirtualChannel& channel, SdCardMountedIF& sdcMan)
@ -22,6 +26,7 @@ bool TmStoreTaskBase::handleOneStore(PersistentTmStoreWithTmQueue& store, Event
size_t dumpedLen; size_t dumpedLen;
bool fileHasSwapped; bool fileHasSwapped;
if (not channel.isBusy()) { if (not channel.isBusy()) {
tmSinkBusyCd.resetTimer();
// TODO: We could continously dump until a file swap during active downlink.. // TODO: We could continously dump until a file swap during active downlink..
result = store.dumpNextPacket(channel, dumpedLen, fileHasSwapped); result = store.dumpNextPacket(channel, dumpedLen, fileHasSwapped);
if (result == PersistentTmStore::DUMP_DONE) { if (result == PersistentTmStore::DUMP_DONE) {
@ -34,10 +39,19 @@ bool TmStoreTaskBase::handleOneStore(PersistentTmStoreWithTmQueue& store, Event
dumpsPerformed = true; dumpsPerformed = true;
} }
} }
if (cancelDumpCd.hasTimedOut() or tmSinkBusyCd.hasTimedOut()) {
triggerEvent(persTmStore::DUMP_WAS_CANCELLED, store.getObjectId());
store.cancelDump();
}
} else { } else {
Command_t execCmd;
// Handle TC requests, for example deletion or retrieval requests. // Handle TC requests, for example deletion or retrieval requests.
result = store.handleCommandQueue(ipcStore); result = store.handleCommandQueue(ipcStore, execCmd);
if (result == returnvalue::OK) { if (result == returnvalue::OK) {
if (execCmd == TmStoreMessage::DOWNLINK_STORE_CONTENT_TIME) {
cancelDumpCd.resetTimer();
tmSinkBusyCd.resetTimer();
}
tcRequestReceived = true; tcRequestReceived = true;
} }
} }

View File

@ -28,6 +28,10 @@ class TmStoreTaskBase : public SystemObject {
StorageManagerIF& ipcStore; StorageManagerIF& ipcStore;
Countdown sdCardCheckCd = Countdown(800); 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; VirtualChannel& channel;
bool storesInitialized = false; bool storesInitialized = false;
SdCardMountedIF& sdcMan; SdCardMountedIF& sdcMan;