eive-obsw/mission/tmtc/PersistentSingleTmStoreTask.cpp

60 lines
2.2 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) {
ReturnValue_t result = returnvalue::OK;
2023-03-28 14:59:31 +02:00
uint32_t delaysVcBusyDuringDump = 0;
uint32_t delaysFlowControl = 0;
uint32_t delayNotBusy = 0;
uint32_t delayHotLoop = 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) {
result = TaskFactory::delayTask(100);
2023-03-28 14:59:31 +02:00
delayNotBusy++;
2023-03-27 21:39:37 +02:00
} else if (dumpContext.vcBusyDuringDump) {
2023-03-28 14:59:31 +02:00
delaysVcBusyDuringDump++;
result = TaskFactory::delayTask(10);
2023-03-27 21:46:12 +02:00
} else if (dumpContext.packetWasDumped and
dumpContext.dumpedBytes - dumpContext.bytesDumpedAtLastDelay >= 2048) {
2023-03-27 21:46:12 +02:00
dumpContext.bytesDumpedAtLastDelay = dumpContext.dumpedBytes;
result = TaskFactory::delayTask(10);
2023-03-28 14:59:31 +02:00
delaysFlowControl++;
2023-03-27 21:23:09 +02:00
} else {
// TODO: Lower this as much as possible...
2023-03-28 14:59:31 +02:00
result = TaskFactory::delayTask(5);
delayHotLoop++;
}
if ((delaysVcBusyDuringDump + delaysFlowControl + delayNotBusy + delayHotLoop) % 2000000 == 0) {
sif::debug << "DLY NBUSY: " << delayNotBusy << std::endl;
sif::debug << "DLY FLCTRL: " << delaysFlowControl << std::endl;
sif::debug << "DLY BUSYDUMP: " << delaysVcBusyDuringDump << std::endl;
sif::debug << "DLY HOTLOOP: " << delayHotLoop << std::endl;
}
2023-03-28 14:59:31 +02:00
if (result != returnvalue::OK) {
sif::warning << "TmStoreTask: Delay failed" << std::endl;
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;
}