eive-obsw/mission/tmtc/PersistentSingleTmStoreTask.cpp

53 lines
1.7 KiB
C++
Raw Normal View History

2023-03-09 17:44:05 +01:00
#include <fsfw/tasks/TaskFactory.h>
2023-03-10 02:05:51 +01:00
#include <fsfw/timemanager/Stopwatch.h>
2023-03-09 17:44:05 +01:00
#include <mission/tmtc/PersistentSingleTmStoreTask.h>
2023-03-27 21:23:09 +02:00
#include <unistd.h>
2023-03-09 17:44:05 +01:00
2023-03-10 19:01:31 +01:00
PersistentSingleTmStoreTask::PersistentSingleTmStoreTask(
object_id_t objectId, StorageManagerIF& ipcStore, PersistentTmStoreWithTmQueue& tmStore,
VirtualChannel& channel, Event eventIfDumpDone, SdCardMountedIF& sdcMan)
: TmStoreTaskBase(objectId, ipcStore, channel, sdcMan),
storeWithQueue(tmStore),
2023-03-11 14:59:55 +01:00
dumpContext(eventIfDumpDone) {}
2023-03-09 17:44:05 +01:00
ReturnValue_t PersistentSingleTmStoreTask::performOperation(uint8_t opCode) {
2023-03-27 21:23:09 +02:00
uint32_t dummy = 0;
2023-03-09 17:44:05 +01:00
while (true) {
2023-03-10 02:05:51 +01:00
// Delay done by the check
if (not cyclicStoreCheck()) {
continue;
}
2023-03-11 14:59:55 +01:00
bool busy = handleOneStore(storeWithQueue, dumpContext);
2023-03-09 19:42:20 +01:00
if (not busy) {
2023-03-23 18:31:47 +01:00
TaskFactory::delayTask(100);
2023-03-27 21:23:09 +02:00
} else if(dumpContext.vcBusyDuringDump) {
TaskFactory::delayTask(30);
2023-03-27 17:02:02 +02:00
} else if (fileHasSwapped) {
2023-03-27 21:23:09 +02:00
TaskFactory::delayTask(30);
} else if(dumpContext.packetWasDumped and dumpContext.numberOfDumpedPackets % 5 == 0) {
TaskFactory::delayTask(30);
} else {
// dummy++;
// if(dummy % 2000 == 0) {
// sif::warning << "persistent tm store is stupid" << std::endl;
// }
TaskFactory::delayTask(2);
// continue;
2023-03-09 17:44:05 +01:00
}
2023-03-27 21:23:09 +02:00
dummy = 0;
//else if(dumpContext.numberOfDumpedPackets % 20 == 0) {
// Manual load management because I don't know what the scheduler is doing..
// Removing this delay can lead to evil side effects.
//TaskFactory::delayTask(5);
//}
2023-03-09 17:44:05 +01:00
}
}
2023-03-10 02:05:51 +01:00
bool PersistentSingleTmStoreTask::initStoresIfPossible() {
if (sdcMan.isSdCardUsable(std::nullopt)) {
storeWithQueue.initializeTmStore();
return true;
}
return false;
}