eive-obsw/mission/tmtc/PersistentSingleTmStoreTask.cpp

38 lines
1.5 KiB
C++
Raw Normal View History

2023-03-09 17:44:05 +01:00
#include <fsfw/tasks/TaskFactory.h>
#include <mission/tmtc/PersistentSingleTmStoreTask.h>
PersistentSingleTmStoreTask::PersistentSingleTmStoreTask(object_id_t objectId,
StorageManagerIF& ipcStore,
PersistentTmStoreWithTmQueue& tmStore,
VirtualChannel& channel)
: SystemObject(objectId), ipcStore(ipcStore), storeWithQueue(tmStore), channel(channel) {}
ReturnValue_t PersistentSingleTmStoreTask::performOperation(uint8_t opCode) {
ReturnValue_t result;
auto& store = storeWithQueue.getTmStore();
bool noTmToStoreReceived = false;
bool noTcRequestReceived = false;
while (true) {
// Store TM persistently
result = storeWithQueue.handleNextTm();
if (result == MessageQueueIF::NO_QUEUE) {
noTmToStoreReceived = true;
}
// Handle TC requests, for example deletion or retrieval requests.
result = store.handleCommandQueue(ipcStore);
if (result == MessageQueueIF::NO_QUEUE) {
noTcRequestReceived = true;
}
// Dump TMs when applicable
if (store.getState() == PersistentTmStore::State::DUMPING) {
size_t dumpedLen;
// TODO: Maybe do a bit of a delay every 100-200 packets?
// TODO: handle returnvalue?
store.dumpNextPacket(channel, dumpedLen);
} else if (noTcRequestReceived and noTmToStoreReceived) {
// Nothng to do, so sleep for a bit.
TaskFactory::delayTask(5);
}
}
}