#include "PersistentLogTmStoreTask.h" #include #include PersistentLogTmStoreTask::PersistentLogTmStoreTask(object_id_t objectId, StorageManagerIF& ipcStore, LogStores stores, VirtualChannel& channel, SdCardMountedIF& sdcMan) : TmStoreTaskBase(objectId, ipcStore, channel, sdcMan), stores(stores), okStoreContext(persTmStore::DUMP_OK_STORE_DONE), notOkStoreContext(persTmStore::DUMP_NOK_STORE_DONE), miscStoreContext(persTmStore::DUMP_MISC_STORE_DONE) {} ReturnValue_t PersistentLogTmStoreTask::performOperation(uint8_t opCode) { bool someonesBusy = false; bool vcBusyDuringDump = false; bool byteFlowControl = false; auto stateHandlingForStore = [&](bool storeIsBusy, DumpContext& ctx) { if (storeIsBusy) { someonesBusy = true; } if (fileHasSwapped) { someFileWasSwapped = fileHasSwapped; } if(ctx.vcBusyDuringDump) { vcBusyDuringDump = true; } if(ctx.dumpedBytes - ctx.bytesDumpedAtLastDelay >= 2048) { byteFlowControl = true; ctx.bytesDumpedAtLastDelay = ctx.dumpedBytes; } }; while (true) { if (not cyclicStoreCheck()) { continue; } someonesBusy = false; someFileWasSwapped = false; vcBusyDuringDump = false; stateHandlingForStore(handleOneStore(stores.okStore, okStoreContext), okStoreContext); stateHandlingForStore(handleOneStore(stores.notOkStore, notOkStoreContext), notOkStoreContext); stateHandlingForStore(handleOneStore(stores.miscStore, miscStoreContext), miscStoreContext); if (not someonesBusy) { TaskFactory::delayTask(100); } else if (someFileWasSwapped) { TaskFactory::delayTask(20); } else if(vcBusyDuringDump) { TaskFactory::delayTask(20); } else if(byteFlowControl) { TaskFactory::delayTask(10); } else { // TODO: Lower this as much as possible... TaskFactory::delayTask(10); } } } bool PersistentLogTmStoreTask::initStoresIfPossible() { if (sdcMan.isSdCardUsable(std::nullopt)) { stores.okStore.initializeTmStore(); stores.miscStore.initializeTmStore(); stores.notOkStore.initializeTmStore(); return true; } return false; }