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,
|
2023-03-09 20:16:00 +01:00
|
|
|
LogStores stores, VirtualChannel& channel,
|
|
|
|
SdCardMountedIF& sdcMan)
|
2023-03-11 15:24:43 +01:00
|
|
|
: TmStoreTaskBase(objectId, ipcStore, channel, sdcMan),
|
|
|
|
stores(stores),
|
2023-03-11 14:59:55 +01:00
|
|
|
okStoreContext(persTmStore::DUMP_OK_STORE_DONE),
|
|
|
|
notOkStoreContext(persTmStore::DUMP_NOK_STORE_DONE),
|
|
|
|
miscStoreContext(persTmStore::DUMP_MISC_STORE_DONE) {}
|
2023-03-09 19:42:20 +01:00
|
|
|
|
|
|
|
ReturnValue_t PersistentLogTmStoreTask::performOperation(uint8_t opCode) {
|
2023-03-21 14:09:59 +01:00
|
|
|
bool someonesBusy = false;
|
|
|
|
auto stateHandlingForStore = [&](bool storeIsBusy) {
|
|
|
|
if (storeIsBusy) {
|
2023-03-09 19:42:20 +01:00
|
|
|
someonesBusy = true;
|
|
|
|
}
|
2023-03-21 14:09:59 +01:00
|
|
|
if (fileHasSwapped) {
|
|
|
|
someFileWasSwapped = fileHasSwapped;
|
2023-03-09 19:42:20 +01:00
|
|
|
}
|
2023-03-21 14:09:59 +01:00
|
|
|
};
|
|
|
|
while (true) {
|
|
|
|
if (not cyclicStoreCheck()) {
|
|
|
|
continue;
|
2023-03-09 19:42:20 +01:00
|
|
|
}
|
2023-03-21 14:09:59 +01:00
|
|
|
someFileWasSwapped = false;
|
|
|
|
bool busy = handleOneStore(stores.okStore, okStoreContext);
|
|
|
|
stateHandlingForStore(busy);
|
|
|
|
stateHandlingForStore(handleOneStore(stores.notOkStore, notOkStoreContext));
|
|
|
|
stateHandlingForStore(handleOneStore(stores.miscStore, miscStoreContext));
|
2023-03-09 19:42:20 +01:00
|
|
|
if (not someonesBusy) {
|
2023-03-10 02:05:51 +01:00
|
|
|
TaskFactory::delayTask(40);
|
2023-03-21 14:09:59 +01:00
|
|
|
} else if (someFileWasSwapped and graceDelayDuringDumping.hasTimedOut()) {
|
|
|
|
TaskFactory::delayTask(2);
|
|
|
|
graceDelayDuringDumping.resetTimer();
|
2023-03-09 19:42:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-03-09 20:16:00 +01:00
|
|
|
|
2023-03-10 02:05:51 +01:00
|
|
|
bool PersistentLogTmStoreTask::initStoresIfPossible() {
|
2023-03-09 20:16:00 +01:00
|
|
|
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-09 20:16:00 +01:00
|
|
|
}
|
2023-03-10 02:05:51 +01:00
|
|
|
return false;
|
2023-03-09 20:16:00 +01:00
|
|
|
}
|