2023-03-09 19:42:20 +01:00
|
|
|
#include "TmStoreTaskBase.h"
|
|
|
|
|
2023-03-10 20:32:11 +01:00
|
|
|
#include <fsfw/ipc/CommandMessageIF.h>
|
2023-03-09 20:16:00 +01:00
|
|
|
#include <fsfw/tasks/TaskFactory.h>
|
2023-03-10 02:05:51 +01:00
|
|
|
#include <fsfw/timemanager/Stopwatch.h>
|
2023-03-10 20:32:11 +01:00
|
|
|
#include <fsfw/tmstorage/TmStoreMessage.h>
|
|
|
|
|
|
|
|
#include "mission/persistentTmStoreDefs.h"
|
2023-03-09 20:16:00 +01:00
|
|
|
|
2023-03-09 19:42:20 +01:00
|
|
|
TmStoreTaskBase::TmStoreTaskBase(object_id_t objectId, StorageManagerIF& ipcStore,
|
2023-03-09 20:16:00 +01:00
|
|
|
VirtualChannel& channel, SdCardMountedIF& sdcMan)
|
|
|
|
: SystemObject(objectId), ipcStore(ipcStore), channel(channel), sdcMan(sdcMan) {}
|
2023-03-09 19:42:20 +01:00
|
|
|
|
2023-03-10 21:13:11 +01:00
|
|
|
bool TmStoreTaskBase::handleOneStore(PersistentTmStoreWithTmQueue& store, Event eventIfDone,
|
|
|
|
uint32_t& numberOfDumpedPackets) {
|
2023-03-10 02:05:51 +01:00
|
|
|
ReturnValue_t result;
|
2023-03-10 20:13:36 +01:00
|
|
|
bool tmToStoreReceived = false;
|
|
|
|
bool tcRequestReceived = false;
|
2023-03-09 19:42:20 +01:00
|
|
|
bool dumpsPerformed = false;
|
|
|
|
// Store TM persistently
|
2023-03-10 02:05:51 +01:00
|
|
|
result = store.handleNextTm();
|
2023-03-10 20:13:36 +01:00
|
|
|
if (result == returnvalue::OK) {
|
|
|
|
tmToStoreReceived = true;
|
2023-03-09 19:42:20 +01:00
|
|
|
}
|
|
|
|
// Dump TMs when applicable
|
|
|
|
if (store.getState() == PersistentTmStore::State::DUMPING) {
|
|
|
|
size_t dumpedLen;
|
2023-03-09 20:44:55 +01:00
|
|
|
bool fileHasSwapped;
|
2023-03-10 18:04:04 +01:00
|
|
|
if (not channel.isBusy()) {
|
2023-03-10 20:32:11 +01:00
|
|
|
tmSinkBusyCd.resetTimer();
|
2023-03-10 18:04:04 +01:00
|
|
|
// TODO: We could continously dump until a file swap during active downlink..
|
|
|
|
result = store.dumpNextPacket(channel, dumpedLen, fileHasSwapped);
|
2023-03-10 19:01:31 +01:00
|
|
|
if (result == PersistentTmStore::DUMP_DONE) {
|
|
|
|
uint32_t startTime;
|
|
|
|
uint32_t endTime;
|
|
|
|
store.getStartAndEndTimeCurrentOrLastDump(startTime, endTime);
|
2023-03-10 21:13:11 +01:00
|
|
|
triggerEvent(eventIfDone, numberOfDumpedPackets);
|
2023-03-10 19:01:31 +01:00
|
|
|
dumpsPerformed = true;
|
|
|
|
} else if (result == returnvalue::OK) {
|
2023-03-10 18:04:04 +01:00
|
|
|
dumpsPerformed = true;
|
|
|
|
}
|
2023-03-09 19:42:20 +01:00
|
|
|
}
|
2023-03-10 20:32:11 +01:00
|
|
|
if (cancelDumpCd.hasTimedOut() or tmSinkBusyCd.hasTimedOut()) {
|
|
|
|
triggerEvent(persTmStore::DUMP_WAS_CANCELLED, store.getObjectId());
|
|
|
|
store.cancelDump();
|
|
|
|
}
|
2023-03-10 02:05:51 +01:00
|
|
|
} else {
|
2023-03-10 20:32:11 +01:00
|
|
|
Command_t execCmd;
|
2023-03-10 02:05:51 +01:00
|
|
|
// Handle TC requests, for example deletion or retrieval requests.
|
2023-03-10 20:32:11 +01:00
|
|
|
result = store.handleCommandQueue(ipcStore, execCmd);
|
2023-03-10 20:13:36 +01:00
|
|
|
if (result == returnvalue::OK) {
|
2023-03-10 20:32:11 +01:00
|
|
|
if (execCmd == TmStoreMessage::DOWNLINK_STORE_CONTENT_TIME) {
|
|
|
|
cancelDumpCd.resetTimer();
|
|
|
|
tmSinkBusyCd.resetTimer();
|
|
|
|
}
|
2023-03-10 20:13:36 +01:00
|
|
|
tcRequestReceived = true;
|
2023-03-10 02:05:51 +01:00
|
|
|
}
|
2023-03-09 19:42:20 +01:00
|
|
|
}
|
|
|
|
if (tcRequestReceived or tmToStoreReceived or dumpsPerformed) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2023-03-09 20:16:00 +01:00
|
|
|
|
|
|
|
bool TmStoreTaskBase::cyclicStoreCheck() {
|
|
|
|
if (not storesInitialized) {
|
2023-03-10 02:05:51 +01:00
|
|
|
storesInitialized = initStoresIfPossible();
|
2023-03-09 20:16:00 +01:00
|
|
|
if (not storesInitialized) {
|
|
|
|
TaskFactory::delayTask(400);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else if (sdCardCheckCd.hasTimedOut()) {
|
|
|
|
if (not sdcMan.isSdCardUsable(std::nullopt)) {
|
|
|
|
// Might be due to imminent shutdown or SD card switch.
|
|
|
|
storesInitialized = false;
|
|
|
|
TaskFactory::delayTask(100);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
sdCardCheckCd.resetTimer();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|