eive-obsw/mission/tmtc/TmStoreTaskBase.cpp

62 lines
2.0 KiB
C++
Raw Normal View History

2023-03-09 19:42:20 +01:00
#include "TmStoreTaskBase.h"
#include <fsfw/tasks/TaskFactory.h>
2023-03-10 02:05:51 +01:00
#include <fsfw/timemanager/Stopwatch.h>
2023-03-09 19:42:20 +01:00
TmStoreTaskBase::TmStoreTaskBase(object_id_t objectId, StorageManagerIF& ipcStore,
VirtualChannel& channel, SdCardMountedIF& sdcMan)
: SystemObject(objectId), ipcStore(ipcStore), channel(channel), sdcMan(sdcMan) {}
2023-03-09 19:42:20 +01:00
2023-03-10 02:05:51 +01:00
bool TmStoreTaskBase::handleOneStore(PersistentTmStoreWithTmQueue& store, Countdown& tcHandlingCd) {
ReturnValue_t result;
2023-03-09 19:42:20 +01:00
bool tmToStoreReceived = true;
bool tcRequestReceived = true;
bool dumpsPerformed = false;
// Store TM persistently
2023-03-10 02:05:51 +01:00
result = store.handleNextTm();
if (result == MessageQueueIF::EMPTY) {
2023-03-09 19:42:20 +01:00
tmToStoreReceived = false;
}
// Dump TMs when applicable
if (store.getState() == PersistentTmStore::State::DUMPING) {
size_t dumpedLen;
2023-03-09 20:44:55 +01:00
bool fileHasSwapped;
2023-03-09 19:42:20 +01:00
// TODO: Maybe do a bit of a delay every 100-200 packets?
2023-03-09 20:44:55 +01:00
// TODO: We could continously dump until a file swap during active downlink..
2023-03-09 19:42:20 +01:00
// TODO: handle returnvalue?
2023-03-09 20:44:55 +01:00
result = store.dumpNextPacket(channel, dumpedLen, fileHasSwapped);
2023-03-09 19:42:20 +01:00
if (result == returnvalue::OK) {
dumpsPerformed = true;
}
2023-03-10 02:05:51 +01:00
} else {
// Handle TC requests, for example deletion or retrieval requests.
result = store.handleCommandQueue(ipcStore);
if (result == MessageQueueIF::EMPTY) {
tcRequestReceived = false;
}
2023-03-09 19:42:20 +01:00
}
if (tcRequestReceived or tmToStoreReceived or dumpsPerformed) {
return true;
}
return false;
}
bool TmStoreTaskBase::cyclicStoreCheck() {
if (not storesInitialized) {
2023-03-10 02:05:51 +01:00
storesInitialized = initStoresIfPossible();
if (not storesInitialized) {
TaskFactory::delayTask(400);
return false;
}
} else if (sdCardCheckCd.hasTimedOut()) {
if (not sdcMan.isSdCardUsable(std::nullopt)) {
// Might be due to imminent shutdown or SD card switch.
storesInitialized = false;
TaskFactory::delayTask(100);
return false;
}
sdCardCheckCd.resetTimer();
}
return true;
}