eive-obsw/mission/tmtc/PersistentLogTmStoreTask.cpp

68 lines
2.4 KiB
C++
Raw Normal View History

2023-03-09 17:44:05 +01:00
#include "PersistentLogTmStoreTask.h"
2023-03-09 19:42:20 +01:00
#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
PersistentLogTmStoreTask::PersistentLogTmStoreTask(object_id_t objectId, StorageManagerIF& ipcStore,
LogStores stores, VirtualChannel& channel,
SdCardMountedIF& sdcMan)
2023-03-11 15:24:43 +01:00
: TmStoreTaskBase(objectId, ipcStore, channel, sdcMan),
stores(stores),
2023-03-28 15:15:38 +02:00
okStoreContext(persTmStore::DUMP_OK_STORE_DONE, persTmStore::DUMP_OK_CANCELLED),
notOkStoreContext(persTmStore::DUMP_NOK_STORE_DONE, persTmStore::DUMP_NOK_CANCELLED),
miscStoreContext(persTmStore::DUMP_MISC_STORE_DONE, persTmStore::DUMP_MISC_CANCELLED) {}
2023-03-09 19:42:20 +01:00
ReturnValue_t PersistentLogTmStoreTask::performOperation(uint8_t opCode) {
bool someonesBusy = false;
bool vcBusyDuringDump = false;
bool byteFlowControl = false;
auto stateHandlingForStore = [&](bool storeIsBusy, DumpContext& ctx) {
if (storeIsBusy) {
2023-03-09 19:42:20 +01:00
someonesBusy = true;
}
if (fileHasSwapped) {
someFileWasSwapped = fileHasSwapped;
2023-03-09 19:42:20 +01:00
}
2023-03-28 14:59:31 +02:00
if (ctx.vcBusyDuringDump) {
vcBusyDuringDump = true;
}
2023-03-28 14:59:31 +02:00
if (ctx.dumpedBytes - ctx.bytesDumpedAtLastDelay >= 2048) {
byteFlowControl = true;
ctx.bytesDumpedAtLastDelay = ctx.dumpedBytes;
}
};
while (true) {
if (not cyclicStoreCheck()) {
continue;
2023-03-09 19:42:20 +01:00
}
2023-03-23 11:32:46 +01:00
someonesBusy = false;
someFileWasSwapped = false;
vcBusyDuringDump = false;
stateHandlingForStore(handleOneStore(stores.okStore, okStoreContext), okStoreContext);
stateHandlingForStore(handleOneStore(stores.notOkStore, notOkStoreContext), notOkStoreContext);
stateHandlingForStore(handleOneStore(stores.miscStore, miscStoreContext), miscStoreContext);
2023-03-09 19:42:20 +01:00
if (not someonesBusy) {
2023-03-23 18:31:47 +01:00
TaskFactory::delayTask(100);
2023-03-27 17:02:02 +02:00
} else if (someFileWasSwapped) {
TaskFactory::delayTask(20);
2023-03-28 14:59:31 +02:00
} else if (vcBusyDuringDump) {
TaskFactory::delayTask(20);
2023-03-28 14:59:31 +02:00
} else if (byteFlowControl) {
TaskFactory::delayTask(10);
} else {
// TODO: Lower this as much as possible...
TaskFactory::delayTask(10);
2023-03-09 19:42:20 +01:00
}
}
}
2023-03-10 02:05:51 +01:00
bool PersistentLogTmStoreTask::initStoresIfPossible() {
if (sdcMan.isSdCardUsable(std::nullopt)) {
stores.okStore.initializeTmStore();
stores.miscStore.initializeTmStore();
stores.notOkStore.initializeTmStore();
2023-03-10 02:05:51 +01:00
return true;
}
2023-03-10 02:05:51 +01:00
return false;
}