2023-03-31 01:14:59 +02:00
|
|
|
#include "PersistentSingleTmStoreTask.h"
|
|
|
|
|
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-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,
|
2023-03-31 16:51:30 +02:00
|
|
|
VirtualChannel& channel, Event eventIfDumpDone, Event eventIfCancelled, SdCardMountedIF& sdcMan,
|
|
|
|
const std::atomic_bool& ptmeLocked)
|
|
|
|
: TmStoreTaskBase(objectId, ipcStore, channel, sdcMan, ptmeLocked),
|
2023-03-10 19:01:31 +01:00
|
|
|
storeWithQueue(tmStore),
|
2023-03-28 15:15:38 +02:00
|
|
|
dumpContext(eventIfDumpDone, eventIfCancelled) {}
|
2023-03-09 17:44:05 +01:00
|
|
|
|
|
|
|
ReturnValue_t PersistentSingleTmStoreTask::performOperation(uint8_t opCode) {
|
|
|
|
while (true) {
|
2023-03-31 01:14:59 +02:00
|
|
|
readCommandQueue();
|
|
|
|
|
2023-03-10 02:05:51 +01:00
|
|
|
// Delay done by the check
|
2023-03-09 20:16:00 +01:00
|
|
|
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-28 21:45:04 +02:00
|
|
|
TaskFactory::delayTask(100);
|
2023-03-27 21:39:37 +02:00
|
|
|
} else if (dumpContext.vcBusyDuringDump) {
|
2023-03-29 17:38:38 +02:00
|
|
|
sif::debug << "VC busy, delaying" << std::endl;
|
2023-03-28 21:45:04 +02:00
|
|
|
// TODO: Might not be necessary
|
|
|
|
TaskFactory::delayTask(10);
|
2023-03-31 15:12:05 +02:00
|
|
|
} else {
|
|
|
|
// TODO: Would be best to remove this, but not delaying here can lead to evil issues.
|
2023-04-06 16:51:03 +02:00
|
|
|
// Polling the PAPB of the PTME core too often leads to scheuduling issues.
|
2023-04-03 21:57:48 +02:00
|
|
|
TaskFactory::delayTask(2);
|
2023-03-28 14:59:31 +02:00
|
|
|
}
|
2023-03-09 17:44:05 +01:00
|
|
|
}
|
|
|
|
}
|
2023-03-09 20:16:00 +01:00
|
|
|
|
2023-03-10 02:05:51 +01:00
|
|
|
bool PersistentSingleTmStoreTask::initStoresIfPossible() {
|
|
|
|
if (sdcMan.isSdCardUsable(std::nullopt)) {
|
|
|
|
storeWithQueue.initializeTmStore();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2023-03-31 01:14:59 +02:00
|
|
|
|
|
|
|
void PersistentSingleTmStoreTask::startTransition(Mode_t mode, Submode_t submode) {
|
|
|
|
if (mode == MODE_OFF) {
|
|
|
|
cancelDump(dumpContext, storeWithQueue, channel.isTxOn());
|
|
|
|
this->mode = MODE_OFF;
|
|
|
|
} else if (mode == MODE_ON) {
|
|
|
|
this->mode = MODE_ON;
|
|
|
|
}
|
|
|
|
modeHelper.modeChanged(mode, submode);
|
|
|
|
announceMode(false);
|
|
|
|
}
|