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,
|
2023-03-31 16:51:30 +02:00
|
|
|
SdCardMountedIF& sdcMan,
|
|
|
|
const std::atomic_bool& ptmeLocked)
|
|
|
|
: TmStoreTaskBase(objectId, ipcStore, channel, sdcMan, ptmeLocked),
|
2023-03-11 15:24:43 +01:00
|
|
|
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) {
|
2023-03-21 14:09:59 +01:00
|
|
|
bool someonesBusy = false;
|
2023-03-27 22:06:16 +02:00
|
|
|
bool vcBusyDuringDump = false;
|
|
|
|
auto stateHandlingForStore = [&](bool storeIsBusy, DumpContext& ctx) {
|
2023-03-21 14:09:59 +01:00
|
|
|
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-28 14:59:31 +02:00
|
|
|
if (ctx.vcBusyDuringDump) {
|
2023-03-27 22:06:16 +02:00
|
|
|
vcBusyDuringDump = true;
|
|
|
|
}
|
2023-03-21 14:09:59 +01:00
|
|
|
};
|
|
|
|
while (true) {
|
2023-03-31 01:14:59 +02:00
|
|
|
readCommandQueue();
|
|
|
|
|
2023-03-21 14:09:59 +01:00
|
|
|
if (not cyclicStoreCheck()) {
|
|
|
|
continue;
|
2023-03-09 19:42:20 +01:00
|
|
|
}
|
2023-03-23 11:32:46 +01:00
|
|
|
someonesBusy = false;
|
2023-03-21 14:09:59 +01:00
|
|
|
someFileWasSwapped = false;
|
2023-03-27 22:06:16 +02:00
|
|
|
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-28 14:59:31 +02:00
|
|
|
} else if (vcBusyDuringDump) {
|
2023-03-28 21:45:04 +02:00
|
|
|
// TODO: Might not be necessary
|
2023-03-31 17:39:13 +02:00
|
|
|
sif::debug << "VC busy, delaying" << std::endl;
|
2023-03-28 21:58:04 +02:00
|
|
|
TaskFactory::delayTask(10);
|
2023-04-06 16:51:03 +02:00
|
|
|
} else {
|
|
|
|
// TODO: Would be best to remove this, but not delaying here can lead to evil issues.
|
|
|
|
// Polling the PAPB of the PTME core too often leads to scheuduling issues.
|
|
|
|
TaskFactory::delayTask(2);
|
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
|
|
|
}
|
2023-03-31 01:14:59 +02:00
|
|
|
|
|
|
|
void PersistentLogTmStoreTask::startTransition(Mode_t mode, Submode_t submode) {
|
|
|
|
if (mode == MODE_OFF) {
|
|
|
|
bool channelIsOn = channel.isTxOn();
|
|
|
|
cancelDump(okStoreContext, stores.okStore, channelIsOn);
|
|
|
|
cancelDump(notOkStoreContext, stores.notOkStore, channelIsOn);
|
|
|
|
cancelDump(miscStoreContext, stores.miscStore, channelIsOn);
|
|
|
|
this->mode = MODE_OFF;
|
|
|
|
} else if (mode == MODE_ON) {
|
|
|
|
this->mode = MODE_ON;
|
|
|
|
}
|
|
|
|
modeHelper.modeChanged(mode, submode);
|
|
|
|
announceMode(false);
|
|
|
|
}
|