eive-obsw/mission/com/TmStoreTaskBase.h

109 lines
3.8 KiB
C
Raw Normal View History

2023-03-09 19:42:20 +01:00
#ifndef MISSION_TMTC_TMSTORETASKBASE_H_
#define MISSION_TMTC_TMSTORETASKBASE_H_
2023-03-31 01:14:59 +02:00
#include <fsfw/modes/HasModesIF.h>
#include <fsfw/subsystem/ModeTreeChildIF.h>
#include <fsfw/subsystem/ModeTreeConnectionIF.h>
2023-03-31 13:21:38 +02:00
#include <fsfw/timemanager/CdsShortTimeStamper.h>
#include <fsfw/timemanager/Countdown.h>
2023-03-31 01:14:59 +02:00
#include <mission/com/VirtualChannel.h>
2023-03-09 19:42:20 +01:00
#include <mission/tmtc/PersistentTmStoreWithTmQueue.h>
2023-03-28 15:03:34 +02:00
/**
* Generic class which composes a Virtual Channel and a persistent TM stores. This allows dumping
* the TM store into the virtual channel directly.
*/
2023-03-31 01:14:59 +02:00
class TmStoreTaskBase : public SystemObject,
public HasModesIF,
public ModeTreeChildIF,
public ModeTreeConnectionIF {
2023-03-09 19:42:20 +01:00
public:
2023-03-11 14:59:55 +01:00
struct DumpContext {
2023-03-28 15:15:38 +02:00
DumpContext(Event eventIfDone, Event eventIfCancelled)
: eventIfDone(eventIfDone), eventIfCancelled(eventIfCancelled) {}
2023-03-11 14:59:55 +01:00
void reset() {
numberOfDumpedPackets = 0;
dumpedBytes = 0;
2023-03-27 21:39:37 +02:00
vcBusyDuringDump = false;
packetWasDumped = false;
2023-03-27 21:46:12 +02:00
bytesDumpedAtLastDelay = 0;
2023-03-27 21:39:37 +02:00
ptmeBusyCounter = 0;
2023-03-11 14:59:55 +01:00
}
const Event eventIfDone;
2023-03-28 15:15:38 +02:00
const Event eventIfCancelled;
2023-03-27 21:46:12 +02:00
size_t numberOfDumpedPackets = 0;
size_t bytesDumpedAtLastDelay = 0;
size_t dumpedBytes = 0;
2023-03-23 18:31:47 +01:00
uint32_t ptmeBusyCounter = 0;
2023-03-27 21:23:09 +02:00
bool packetWasDumped = false;
bool vcBusyDuringDump = false;
2023-03-11 14:59:55 +01:00
};
TmStoreTaskBase(object_id_t objectId, StorageManagerIF& ipcStore, VirtualChannel& channel,
SdCardMountedIF& sdcMan, const std::atomic_bool& ptmeLocked);
2023-03-31 01:14:59 +02:00
ReturnValue_t initialize() override;
2023-03-31 12:11:31 +02:00
ReturnValue_t connectModeTreeParent(HasModeTreeChildrenIF& parent) override;
2023-03-31 01:14:59 +02:00
protected:
2023-03-31 01:14:59 +02:00
ModeHelper modeHelper;
2023-03-31 13:17:15 +02:00
MessageQueueIF* requestQueue;
2023-03-28 15:03:34 +02:00
StorageManagerIF& ipcStore;
2023-03-31 13:17:15 +02:00
PusTmReader tmReader;
CdsShortTimeStamper timeReader;
VirtualChannel& channel;
SdCardMountedIF& sdcMan;
const std::atomic_bool& ptmeLocked;
2023-03-31 13:17:15 +02:00
2023-03-31 01:14:59 +02:00
Mode_t mode = HasModesIF::MODE_OFF;
2023-03-28 15:03:34 +02:00
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.
2023-03-28 21:59:38 +02:00
Countdown tmSinkBusyCd = Countdown(60 * 1000);
2023-03-31 13:17:15 +02:00
2023-03-28 15:03:34 +02:00
bool storesInitialized = false;
bool fileHasSwapped = false;
2023-03-31 01:14:59 +02:00
void readCommandQueue(void);
virtual bool initStoresIfPossible() = 0;
virtual void startTransition(Mode_t mode, Submode_t submode) = 0;
2023-03-28 15:03:34 +02:00
void cancelDump(DumpContext& ctx, PersistentTmStore& store, bool isTxOn);
2023-03-09 19:42:20 +01:00
/**
2023-03-28 15:03:34 +02:00
*
2023-03-09 19:42:20 +01:00
* Handling for one store. Returns if anything was done.
* @param store
* @return
*/
2023-03-11 14:59:55 +01:00
bool handleOneStore(PersistentTmStoreWithTmQueue& store, DumpContext& dumpContext);
2023-03-09 19:42:20 +01:00
2023-03-28 14:59:31 +02:00
ReturnValue_t handleOneDump(PersistentTmStoreWithTmQueue& store, DumpContext& dumpContext,
bool& dumpPerformed);
2023-03-31 13:17:15 +02:00
ReturnValue_t performDump(PersistentTmStoreWithTmQueue& store, DumpContext& dumpContext,
bool& dumpPerformed);
2023-03-28 14:59:31 +02:00
/**
* Occasionally check whether SD card is okay to be used. If not, poll whether it is ready to
* be used again and re-initialize stores. Returns whether store is okay to be used.
*/
bool cyclicStoreCheck();
2023-03-31 01:14:59 +02:00
MessageQueueId_t getCommandQueue() const override;
void getMode(Mode_t* mode, Submode_t* submode) override;
ReturnValue_t checkModeCommand(Mode_t mode, Submode_t submode,
uint32_t* msToReachTheMode) override;
2023-06-29 01:28:40 +02:00
void dumpDoneHandler(PersistentTmStore& store, DumpContext& dumpContext);
2023-03-31 01:14:59 +02:00
void announceMode(bool recursive) override;
object_id_t getObjectId() const override;
const HasHealthIF* getOptHealthIF() const override;
const HasModesIF& getModeIF() const override;
ModeTreeChildIF& getModeTreeChildIF() override;
2023-03-09 19:42:20 +01:00
};
#endif /* MISSION_TMTC_TMSTORETASKBASE_H_ */