Robin Mueller
746254a838
All checks were successful
EIVE/eive-obsw/pipeline/pr-develop This commit looks good
121 lines
4.1 KiB
C++
121 lines
4.1 KiB
C++
#include "TmStoreTaskBase.h"
|
|
|
|
#include <fsfw/ipc/CommandMessageIF.h>
|
|
#include <fsfw/tasks/TaskFactory.h>
|
|
#include <fsfw/timemanager/Stopwatch.h>
|
|
#include <fsfw/tmstorage/TmStoreMessage.h>
|
|
|
|
#include "mission/persistentTmStoreDefs.h"
|
|
|
|
TmStoreTaskBase::TmStoreTaskBase(object_id_t objectId, StorageManagerIF& ipcStore,
|
|
VirtualChannel& channel, SdCardMountedIF& sdcMan)
|
|
: SystemObject(objectId), ipcStore(ipcStore), channel(channel), sdcMan(sdcMan) {}
|
|
|
|
bool TmStoreTaskBase::handleOneStore(PersistentTmStoreWithTmQueue& store,
|
|
DumpContext& dumpContext) {
|
|
ReturnValue_t result;
|
|
bool tmToStoreReceived = false;
|
|
bool tcRequestReceived = false;
|
|
bool dumpsPerformed = false;
|
|
fileHasSwapped = false;
|
|
dumpContext.packetWasDumped = false;
|
|
dumpContext.vcBusyDuringDump = false;
|
|
|
|
// Store TM persistently
|
|
result = store.handleNextTm();
|
|
if (result == returnvalue::OK) {
|
|
tmToStoreReceived = true;
|
|
}
|
|
// Dump TMs when applicable
|
|
if (store.getState() == PersistentTmStore::State::DUMPING) {
|
|
// The PTME might have been reset an transmitter state change, so there is
|
|
// not point in continuing the dump.
|
|
if(not channel.isTxOn()) {
|
|
cancelDump(dumpContext, store, false);
|
|
return returnvalue::OK;
|
|
}
|
|
size_t dumpedLen = 0;
|
|
if (not channel.isBusy()) {
|
|
dumpContext.ptmeBusyCounter = 0;
|
|
tmSinkBusyCd.resetTimer();
|
|
result = store.dumpNextPacket(channel, dumpedLen, fileHasSwapped);
|
|
if (result == DirectTmSinkIF::IS_BUSY) {
|
|
sif::warning << "Unexpected PAPB busy" << std::endl;
|
|
}
|
|
if ((result == PersistentTmStore::DUMP_DONE or result == returnvalue::OK) and dumpedLen > 0) {
|
|
dumpContext.dumpedBytes += dumpedLen;
|
|
dumpContext.numberOfDumpedPackets += 1;
|
|
dumpContext.packetWasDumped = true;
|
|
}
|
|
if (result == PersistentTmStore::DUMP_DONE) {
|
|
uint32_t startTime;
|
|
uint32_t endTime;
|
|
store.getStartAndEndTimeCurrentOrLastDump(startTime, endTime);
|
|
triggerEvent(dumpContext.eventIfDone, dumpContext.numberOfDumpedPackets,
|
|
dumpContext.dumpedBytes);
|
|
dumpContext.reset();
|
|
dumpsPerformed = true;
|
|
} else if (result == returnvalue::OK) {
|
|
dumpsPerformed = true;
|
|
}
|
|
} else {
|
|
dumpContext.vcBusyDuringDump = true;
|
|
dumpContext.ptmeBusyCounter++;
|
|
if (dumpContext.ptmeBusyCounter == 100) {
|
|
// If this happens, something is probably wrong.
|
|
sif::warning << "PTME busy for longer period. Dumped length so far: "
|
|
<< dumpContext.dumpedBytes << std::endl;
|
|
triggerEvent(persTmStore::DUMP_WAS_CANCELLED, store.getObjectId());
|
|
cancelDump(dumpContext, store, channel.isTxOn());
|
|
}
|
|
}
|
|
if (cancelDumpCd.hasTimedOut() or tmSinkBusyCd.hasTimedOut()) {
|
|
triggerEvent(persTmStore::DUMP_WAS_CANCELLED, store.getObjectId());
|
|
cancelDump(dumpContext, store, channel.isTxOn());
|
|
}
|
|
} else {
|
|
Command_t execCmd;
|
|
// Handle TC requests, for example deletion or retrieval requests.
|
|
result = store.handleCommandQueue(ipcStore, execCmd);
|
|
if (result == returnvalue::OK) {
|
|
if (execCmd == TmStoreMessage::DOWNLINK_STORE_CONTENT_TIME) {
|
|
cancelDumpCd.resetTimer();
|
|
tmSinkBusyCd.resetTimer();
|
|
dumpContext.reset();
|
|
}
|
|
tcRequestReceived = true;
|
|
}
|
|
}
|
|
if (tcRequestReceived or tmToStoreReceived or dumpsPerformed) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
bool TmStoreTaskBase::cyclicStoreCheck() {
|
|
if (not storesInitialized) {
|
|
storesInitialized = initStoresIfPossible();
|
|
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;
|
|
}
|
|
|
|
void TmStoreTaskBase::cancelDump(DumpContext& ctx, PersistentTmStore& store, bool isTxOn) {
|
|
ctx.reset();
|
|
store.cancelDump();
|
|
if(isTxOn) {
|
|
channel.cancelTransfer();
|
|
}
|
|
}
|