modes for VC/stores
This commit is contained in:
@ -1,2 +1,11 @@
|
||||
target_sources(${LIB_EIVE_MISSION} PRIVATE SyrlinksHandler.cpp
|
||||
CcsdsIpCoreHandler.cpp)
|
||||
target_sources(
|
||||
${LIB_EIVE_MISSION}
|
||||
PRIVATE SyrlinksHandler.cpp
|
||||
CcsdsIpCoreHandler.cpp
|
||||
LiveTmTask.cpp
|
||||
PersistentLogTmStoreTask.cpp
|
||||
TmStoreTaskBase.cpp
|
||||
VirtualChannel.cpp
|
||||
VirtualChannelWithQueue.cpp
|
||||
PersistentSingleTmStoreTask.cpp
|
||||
LiveTmTask.cpp)
|
||||
|
@ -2,7 +2,7 @@
|
||||
#define CCSDSHANDLER_H_
|
||||
|
||||
#include <fsfw/modes/HasModesIF.h>
|
||||
#include <mission/tmtc/VirtualChannelWithQueue.h>
|
||||
#include <mission/com/VirtualChannelWithQueue.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <unordered_map>
|
||||
|
101
mission/com/LiveTmTask.cpp
Normal file
101
mission/com/LiveTmTask.cpp
Normal file
@ -0,0 +1,101 @@
|
||||
#include "LiveTmTask.h"
|
||||
|
||||
#include <fsfw/ipc/QueueFactory.h>
|
||||
#include <fsfw/subsystem/helper.h>
|
||||
#include <fsfw/tasks/TaskFactory.h>
|
||||
#include <fsfw/timemanager/Stopwatch.h>
|
||||
|
||||
LiveTmTask::LiveTmTask(object_id_t objectId, PusTmFunnel& pusFunnel, CfdpTmFunnel& cfdpFunnel,
|
||||
VirtualChannelWithQueue& channel)
|
||||
: SystemObject(objectId),
|
||||
modeHelper(this),
|
||||
pusFunnel(pusFunnel),
|
||||
cfdpFunnel(cfdpFunnel),
|
||||
channel(channel) {
|
||||
requestQueue = QueueFactory::instance()->createMessageQueue();
|
||||
}
|
||||
|
||||
ReturnValue_t LiveTmTask::performOperation(uint8_t opCode) {
|
||||
readCommandQueue();
|
||||
while (true) {
|
||||
bool performWriteOp = true;
|
||||
if (mode == MODE_OFF) {
|
||||
performWriteOp = false;
|
||||
}
|
||||
|
||||
// The funnel tasks are scheduled here directly as well.
|
||||
ReturnValue_t result = channel.handleNextTm(performWriteOp);
|
||||
if (result == DirectTmSinkIF::IS_BUSY) {
|
||||
sif::error << "Lost live TM, PAPB busy" << std::endl;
|
||||
}
|
||||
if (result == MessageQueueIF::EMPTY) {
|
||||
if (tmFunnelCd.hasTimedOut()) {
|
||||
pusFunnel.performOperation(0);
|
||||
cfdpFunnel.performOperation(0);
|
||||
tmFunnelCd.resetTimer();
|
||||
}
|
||||
// Read command queue during idle times.
|
||||
readCommandQueue();
|
||||
// 40 ms IDLE delay. Might tweak this in the future.
|
||||
TaskFactory::delayTask(40);
|
||||
} else {
|
||||
packetCounter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MessageQueueId_t LiveTmTask::getCommandQueue() const { return requestQueue->getId(); }
|
||||
|
||||
void LiveTmTask::getMode(Mode_t* mode, Submode_t* submode) {
|
||||
if (mode != nullptr) {
|
||||
*mode = this->mode;
|
||||
}
|
||||
if (submode != nullptr) {
|
||||
*submode = SUBMODE_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t LiveTmTask::checkModeCommand(Mode_t mode, Submode_t submode,
|
||||
uint32_t* msToReachTheMode) {
|
||||
if (mode == MODE_ON or mode == MODE_OFF) {
|
||||
return returnvalue::OK;
|
||||
}
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
|
||||
void LiveTmTask::startTransition(Mode_t mode, Submode_t submode) {
|
||||
this->mode = mode;
|
||||
modeHelper.modeChanged(mode, submode);
|
||||
announceMode(false);
|
||||
}
|
||||
|
||||
void LiveTmTask::announceMode(bool recursive) { triggerEvent(MODE_INFO, mode, SUBMODE_NONE); }
|
||||
|
||||
object_id_t LiveTmTask::getObjectId() const { return SystemObject::getObjectId(); }
|
||||
|
||||
const HasHealthIF* LiveTmTask::getOptHealthIF() const { return nullptr; }
|
||||
|
||||
const HasModesIF& LiveTmTask::getModeIF() const { return *this; }
|
||||
|
||||
ReturnValue_t LiveTmTask::connectModeTreeParent(HasModeTreeChildrenIF& parent) {
|
||||
return modetree::connectModeTreeParent(parent, *this, nullptr, modeHelper);
|
||||
}
|
||||
|
||||
void LiveTmTask::readCommandQueue(void) {
|
||||
CommandMessage commandMessage;
|
||||
ReturnValue_t result = returnvalue::FAILED;
|
||||
|
||||
result = requestQueue->receiveMessage(&commandMessage);
|
||||
if (result == returnvalue::OK) {
|
||||
result = modeHelper.handleModeCommand(&commandMessage);
|
||||
if (result == returnvalue::OK) {
|
||||
return;
|
||||
}
|
||||
CommandMessage reply;
|
||||
reply.setReplyRejected(CommandMessage::UNKNOWN_COMMAND, commandMessage.getCommand());
|
||||
requestQueue->reply(&reply);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ModeTreeChildIF& LiveTmTask::getModeTreeChildIF() { return *this; }
|
55
mission/com/LiveTmTask.h
Normal file
55
mission/com/LiveTmTask.h
Normal file
@ -0,0 +1,55 @@
|
||||
#ifndef MISSION_TMTC_LIVETMTASK_H_
|
||||
#define MISSION_TMTC_LIVETMTASK_H_
|
||||
|
||||
#include <fsfw/modes/HasModesIF.h>
|
||||
#include <fsfw/objectmanager/SystemObject.h>
|
||||
#include <fsfw/subsystem/ModeTreeChildIF.h>
|
||||
#include <fsfw/subsystem/ModeTreeConnectionIF.h>
|
||||
#include <fsfw/tasks/ExecutableObjectIF.h>
|
||||
#include <fsfw/timemanager/Countdown.h>
|
||||
#include <mission/com/VirtualChannelWithQueue.h>
|
||||
#include <mission/tmtc/CfdpTmFunnel.h>
|
||||
#include <mission/tmtc/PusTmFunnel.h>
|
||||
|
||||
class LiveTmTask : public SystemObject,
|
||||
public HasModesIF,
|
||||
public ExecutableObjectIF,
|
||||
public ModeTreeChildIF,
|
||||
public ModeTreeConnectionIF {
|
||||
public:
|
||||
LiveTmTask(object_id_t objectId, PusTmFunnel& pusFunnel, CfdpTmFunnel& cfdpFunnel,
|
||||
VirtualChannelWithQueue& channel);
|
||||
|
||||
ReturnValue_t performOperation(uint8_t opCode) override;
|
||||
|
||||
private:
|
||||
MessageQueueIF* requestQueue;
|
||||
ModeHelper modeHelper;
|
||||
Mode_t mode = HasModesIF::MODE_OFF;
|
||||
Countdown tmFunnelCd = Countdown(100);
|
||||
PusTmFunnel& pusFunnel;
|
||||
CfdpTmFunnel& cfdpFunnel;
|
||||
VirtualChannelWithQueue& channel;
|
||||
uint32_t packetCounter = 0;
|
||||
|
||||
void readCommandQueue(void);
|
||||
|
||||
MessageQueueId_t getCommandQueue() const override;
|
||||
|
||||
void getMode(Mode_t* mode, Submode_t* submode) override;
|
||||
|
||||
ReturnValue_t checkModeCommand(Mode_t mode, Submode_t submode,
|
||||
uint32_t* msToReachTheMode) override;
|
||||
|
||||
void startTransition(Mode_t mode, Submode_t submode) override;
|
||||
|
||||
void announceMode(bool recursive) override;
|
||||
|
||||
object_id_t getObjectId() const override;
|
||||
const HasHealthIF* getOptHealthIF() const override;
|
||||
const HasModesIF& getModeIF() const override;
|
||||
ReturnValue_t connectModeTreeParent(HasModeTreeChildrenIF& parent) override;
|
||||
ModeTreeChildIF& getModeTreeChildIF() override;
|
||||
};
|
||||
|
||||
#endif /* MISSION_TMTC_LIVETMTASK_H_ */
|
72
mission/com/PersistentLogTmStoreTask.cpp
Normal file
72
mission/com/PersistentLogTmStoreTask.cpp
Normal file
@ -0,0 +1,72 @@
|
||||
#include "PersistentLogTmStoreTask.h"
|
||||
|
||||
#include <fsfw/tasks/TaskFactory.h>
|
||||
#include <fsfw/timemanager/Stopwatch.h>
|
||||
|
||||
PersistentLogTmStoreTask::PersistentLogTmStoreTask(object_id_t objectId, StorageManagerIF& ipcStore,
|
||||
LogStores stores, VirtualChannel& channel,
|
||||
SdCardMountedIF& sdcMan)
|
||||
: TmStoreTaskBase(objectId, ipcStore, channel, sdcMan),
|
||||
stores(stores),
|
||||
okStoreContext(persTmStore::DUMP_OK_STORE_DONE, persTmStore::DUMP_OK_CANCELLED),
|
||||
notOkStoreContext(persTmStore::DUMP_NOK_STORE_DONE, persTmStore::DUMP_NOK_CANCELLED),
|
||||
miscStoreContext(persTmStore::DUMP_MISC_STORE_DONE, persTmStore::DUMP_MISC_CANCELLED) {}
|
||||
|
||||
ReturnValue_t PersistentLogTmStoreTask::performOperation(uint8_t opCode) {
|
||||
bool someonesBusy = false;
|
||||
bool vcBusyDuringDump = false;
|
||||
auto stateHandlingForStore = [&](bool storeIsBusy, DumpContext& ctx) {
|
||||
if (storeIsBusy) {
|
||||
someonesBusy = true;
|
||||
}
|
||||
if (fileHasSwapped) {
|
||||
someFileWasSwapped = fileHasSwapped;
|
||||
}
|
||||
if (ctx.vcBusyDuringDump) {
|
||||
vcBusyDuringDump = true;
|
||||
}
|
||||
};
|
||||
while (true) {
|
||||
readCommandQueue();
|
||||
|
||||
if (not cyclicStoreCheck()) {
|
||||
continue;
|
||||
}
|
||||
someonesBusy = false;
|
||||
someFileWasSwapped = false;
|
||||
vcBusyDuringDump = false;
|
||||
stateHandlingForStore(handleOneStore(stores.okStore, okStoreContext), okStoreContext);
|
||||
stateHandlingForStore(handleOneStore(stores.notOkStore, notOkStoreContext), notOkStoreContext);
|
||||
stateHandlingForStore(handleOneStore(stores.miscStore, miscStoreContext), miscStoreContext);
|
||||
if (not someonesBusy) {
|
||||
TaskFactory::delayTask(100);
|
||||
} else if (vcBusyDuringDump) {
|
||||
// TODO: Might not be necessary
|
||||
TaskFactory::delayTask(10);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool PersistentLogTmStoreTask::initStoresIfPossible() {
|
||||
if (sdcMan.isSdCardUsable(std::nullopt)) {
|
||||
stores.okStore.initializeTmStore();
|
||||
stores.miscStore.initializeTmStore();
|
||||
stores.notOkStore.initializeTmStore();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void PersistentLogTmStoreTask::startTransition(Mode_t mode, Submode_t submode) {
|
||||
if (mode == MODE_OFF) {
|
||||
bool channelIsOn = channel.isTxOn();
|
||||
cancelDump(okStoreContext, stores.okStore, channelIsOn);
|
||||
cancelDump(notOkStoreContext, stores.notOkStore, channelIsOn);
|
||||
cancelDump(miscStoreContext, stores.miscStore, channelIsOn);
|
||||
this->mode = MODE_OFF;
|
||||
} else if (mode == MODE_ON) {
|
||||
this->mode = MODE_ON;
|
||||
}
|
||||
modeHelper.modeChanged(mode, submode);
|
||||
announceMode(false);
|
||||
}
|
42
mission/com/PersistentLogTmStoreTask.h
Normal file
42
mission/com/PersistentLogTmStoreTask.h
Normal file
@ -0,0 +1,42 @@
|
||||
#ifndef MISSION_TMTC_PERSISTENTLOGTMSTORETASK_H_
|
||||
#define MISSION_TMTC_PERSISTENTLOGTMSTORETASK_H_
|
||||
|
||||
#include <fsfw/objectmanager/SystemObject.h>
|
||||
#include <fsfw/storagemanager/StorageManagerIF.h>
|
||||
#include <fsfw/tasks/ExecutableObjectIF.h>
|
||||
#include <fsfw/tmtcservices/AcceptsTelemetryIF.h>
|
||||
#include <mission/com/TmStoreTaskBase.h>
|
||||
#include <mission/com/VirtualChannelWithQueue.h>
|
||||
#include <mission/genericFactory.h>
|
||||
#include <mission/tmtc/PersistentTmStore.h>
|
||||
#include <mission/tmtc/PersistentTmStoreWithTmQueue.h>
|
||||
|
||||
struct LogStores {
|
||||
LogStores(PersistentTmStores& stores)
|
||||
: okStore(*stores.okStore), notOkStore(*stores.notOkStore), miscStore(*stores.miscStore) {}
|
||||
PersistentTmStoreWithTmQueue& okStore;
|
||||
PersistentTmStoreWithTmQueue& notOkStore;
|
||||
PersistentTmStoreWithTmQueue& miscStore;
|
||||
};
|
||||
|
||||
class PersistentLogTmStoreTask : public TmStoreTaskBase, public ExecutableObjectIF {
|
||||
public:
|
||||
PersistentLogTmStoreTask(object_id_t objectId, StorageManagerIF& ipcStore, LogStores tmStore,
|
||||
VirtualChannel& channel, SdCardMountedIF& sdcMan);
|
||||
|
||||
ReturnValue_t performOperation(uint8_t opCode) override;
|
||||
|
||||
private:
|
||||
LogStores stores;
|
||||
DumpContext okStoreContext;
|
||||
DumpContext notOkStoreContext;
|
||||
DumpContext miscStoreContext;
|
||||
Countdown tcHandlingCd = Countdown(400);
|
||||
Countdown graceDelayDuringDumping = Countdown(200);
|
||||
bool someFileWasSwapped = false;
|
||||
|
||||
bool initStoresIfPossible() override;
|
||||
void startTransition(Mode_t mode, Submode_t submode) override;
|
||||
};
|
||||
|
||||
#endif /* MISSION_TMTC_PERSISTENTLOGTMSTORETASK_H_ */
|
50
mission/com/PersistentSingleTmStoreTask.cpp
Normal file
50
mission/com/PersistentSingleTmStoreTask.cpp
Normal file
@ -0,0 +1,50 @@
|
||||
#include "PersistentSingleTmStoreTask.h"
|
||||
|
||||
#include <fsfw/tasks/TaskFactory.h>
|
||||
#include <fsfw/timemanager/Stopwatch.h>
|
||||
#include <unistd.h>
|
||||
|
||||
PersistentSingleTmStoreTask::PersistentSingleTmStoreTask(
|
||||
object_id_t objectId, StorageManagerIF& ipcStore, PersistentTmStoreWithTmQueue& tmStore,
|
||||
VirtualChannel& channel, Event eventIfDumpDone, Event eventIfCancelled, SdCardMountedIF& sdcMan)
|
||||
: TmStoreTaskBase(objectId, ipcStore, channel, sdcMan),
|
||||
modeHelper(this),
|
||||
storeWithQueue(tmStore),
|
||||
dumpContext(eventIfDumpDone, eventIfCancelled) {}
|
||||
|
||||
ReturnValue_t PersistentSingleTmStoreTask::performOperation(uint8_t opCode) {
|
||||
while (true) {
|
||||
readCommandQueue();
|
||||
|
||||
// Delay done by the check
|
||||
if (not cyclicStoreCheck()) {
|
||||
continue;
|
||||
}
|
||||
bool busy = handleOneStore(storeWithQueue, dumpContext);
|
||||
if (not busy) {
|
||||
TaskFactory::delayTask(100);
|
||||
} else if (dumpContext.vcBusyDuringDump) {
|
||||
// TODO: Might not be necessary
|
||||
TaskFactory::delayTask(10);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool PersistentSingleTmStoreTask::initStoresIfPossible() {
|
||||
if (sdcMan.isSdCardUsable(std::nullopt)) {
|
||||
storeWithQueue.initializeTmStore();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
31
mission/com/PersistentSingleTmStoreTask.h
Normal file
31
mission/com/PersistentSingleTmStoreTask.h
Normal file
@ -0,0 +1,31 @@
|
||||
#ifndef MISSION_TMTC_PERSISTENTSINGLETMSTORETASK_H_
|
||||
#define MISSION_TMTC_PERSISTENTSINGLETMSTORETASK_H_
|
||||
|
||||
#include <fsfw/objectmanager/SystemObject.h>
|
||||
#include <fsfw/tasks/ExecutableObjectIF.h>
|
||||
#include <mission/com/TmStoreTaskBase.h>
|
||||
#include <mission/com/VirtualChannel.h>
|
||||
#include <mission/tmtc/PersistentTmStoreWithTmQueue.h>
|
||||
|
||||
class PersistentSingleTmStoreTask : public TmStoreTaskBase, public ExecutableObjectIF {
|
||||
public:
|
||||
PersistentSingleTmStoreTask(object_id_t objectId, StorageManagerIF& ipcStore,
|
||||
PersistentTmStoreWithTmQueue& storeWithQueue, VirtualChannel& channel,
|
||||
Event eventIfDumpDone, Event eventIfCancelled,
|
||||
SdCardMountedIF& sdcMan);
|
||||
|
||||
ReturnValue_t performOperation(uint8_t opCode) override;
|
||||
|
||||
private:
|
||||
ModeHelper modeHelper;
|
||||
PersistentTmStoreWithTmQueue& storeWithQueue;
|
||||
DumpContext dumpContext;
|
||||
Countdown tcHandlingCd = Countdown(400);
|
||||
Countdown graceDelayDuringDumping = Countdown(100);
|
||||
|
||||
bool initStoresIfPossible() override;
|
||||
|
||||
void startTransition(Mode_t mode, Submode_t submode) override;
|
||||
};
|
||||
|
||||
#endif /* MISSION_TMTC_PERSISTENTSINGLETMSTORETASK_H_ */
|
193
mission/com/TmStoreTaskBase.cpp
Normal file
193
mission/com/TmStoreTaskBase.cpp
Normal file
@ -0,0 +1,193 @@
|
||||
#include "TmStoreTaskBase.h"
|
||||
|
||||
#include <fsfw/ipc/CommandMessageIF.h>
|
||||
#include <fsfw/ipc/QueueFactory.h>
|
||||
#include <fsfw/subsystem/helper.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),
|
||||
modeHelper(this),
|
||||
ipcStore(ipcStore),
|
||||
channel(channel),
|
||||
sdcMan(sdcMan) {
|
||||
requestQueue = QueueFactory::instance()->createMessageQueue(10);
|
||||
}
|
||||
|
||||
bool TmStoreTaskBase::handleOneStore(PersistentTmStoreWithTmQueue& store,
|
||||
DumpContext& dumpContext) {
|
||||
ReturnValue_t result;
|
||||
bool tmToStoreReceived = false;
|
||||
bool tcRequestReceived = false;
|
||||
bool dumpPerformed = 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 and allowed (mode is on)
|
||||
if (mode == MODE_ON and store.getState() == PersistentTmStore::State::DUMPING) {
|
||||
if (handleOneDump(store, dumpContext, dumpPerformed) != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
} 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 dumpPerformed) {
|
||||
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) {
|
||||
triggerEvent(ctx.eventIfCancelled, ctx.numberOfDumpedPackets, ctx.dumpedBytes);
|
||||
ctx.reset();
|
||||
store.cancelDump();
|
||||
if (isTxOn) {
|
||||
channel.cancelTransfer();
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t TmStoreTaskBase::handleOneDump(PersistentTmStoreWithTmQueue& store,
|
||||
DumpContext& dumpContext, bool& dumpPerformed) {
|
||||
ReturnValue_t result = returnvalue::OK;
|
||||
// The PTME might have been reset an transmitter state change, so there is no point in continuing
|
||||
// the dump.
|
||||
if (not channel.isTxOn()) {
|
||||
cancelDump(dumpContext, store, false);
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
size_t dumpedLen = 0;
|
||||
if (not channel.isBusy()) {
|
||||
// Dump the next packet into the PTME.
|
||||
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)) {
|
||||
dumpPerformed = true;
|
||||
if (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();
|
||||
}
|
||||
} else {
|
||||
// The PTME might be at full load, so it might sense to delay for a bit to let it do
|
||||
// its work until some more bandwidth is available. Set a flag here so the upper layer can
|
||||
// do ths.
|
||||
dumpContext.vcBusyDuringDump = true;
|
||||
dumpContext.ptmeBusyCounter++;
|
||||
if (dumpContext.ptmeBusyCounter == 100) {
|
||||
// If this happens, something is probably wrong.
|
||||
sif::warning << "PTME busy for longer period. Cancelling dump" << std::endl;
|
||||
cancelDump(dumpContext, store, channel.isTxOn());
|
||||
}
|
||||
}
|
||||
if (cancelDumpCd.hasTimedOut() or tmSinkBusyCd.hasTimedOut()) {
|
||||
cancelDump(dumpContext, store, channel.isTxOn());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
ReturnValue_t TmStoreTaskBase::initialize() {
|
||||
modeHelper.initialize();
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
void TmStoreTaskBase::getMode(Mode_t* mode, Submode_t* submode) {
|
||||
if (mode != nullptr) {
|
||||
*mode = this->mode;
|
||||
}
|
||||
if (submode != nullptr) {
|
||||
*submode = SUBMODE_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t TmStoreTaskBase::checkModeCommand(Mode_t mode, Submode_t submode,
|
||||
uint32_t* msToReachTheMode) {
|
||||
if (mode == MODE_ON or mode == MODE_OFF) {
|
||||
return returnvalue::OK;
|
||||
}
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
|
||||
MessageQueueId_t TmStoreTaskBase::getCommandQueue() const { return requestQueue->getId(); }
|
||||
|
||||
void TmStoreTaskBase::announceMode(bool recursive) { triggerEvent(MODE_INFO, mode, SUBMODE_NONE); }
|
||||
|
||||
object_id_t TmStoreTaskBase::getObjectId() const { return SystemObject::getObjectId(); }
|
||||
|
||||
const HasHealthIF* TmStoreTaskBase::getOptHealthIF() const { return nullptr; }
|
||||
|
||||
const HasModesIF& TmStoreTaskBase::getModeIF() const { return *this; }
|
||||
|
||||
ReturnValue_t TmStoreTaskBase::connectModeTreeParent(HasModeTreeChildrenIF& parent) {
|
||||
return modetree::connectModeTreeParent(parent, *this, nullptr, modeHelper);
|
||||
}
|
||||
|
||||
ModeTreeChildIF& TmStoreTaskBase::getModeTreeChildIF() { return *this; }
|
||||
void TmStoreTaskBase::readCommandQueue(void) {
|
||||
CommandMessage commandMessage;
|
||||
ReturnValue_t result = returnvalue::FAILED;
|
||||
|
||||
result = requestQueue->receiveMessage(&commandMessage);
|
||||
if (result == returnvalue::OK) {
|
||||
result = modeHelper.handleModeCommand(&commandMessage);
|
||||
if (result == returnvalue::OK) {
|
||||
return;
|
||||
}
|
||||
CommandMessage reply;
|
||||
reply.setReplyRejected(CommandMessage::UNKNOWN_COMMAND, commandMessage.getCommand());
|
||||
requestQueue->reply(&reply);
|
||||
return;
|
||||
}
|
||||
}
|
98
mission/com/TmStoreTaskBase.h
Normal file
98
mission/com/TmStoreTaskBase.h
Normal file
@ -0,0 +1,98 @@
|
||||
#ifndef MISSION_TMTC_TMSTORETASKBASE_H_
|
||||
#define MISSION_TMTC_TMSTORETASKBASE_H_
|
||||
|
||||
#include <fsfw/modes/HasModesIF.h>
|
||||
#include <fsfw/subsystem/ModeTreeChildIF.h>
|
||||
#include <fsfw/subsystem/ModeTreeConnectionIF.h>
|
||||
#include <fsfw/timemanager/Countdown.h>
|
||||
#include <mission/com/VirtualChannel.h>
|
||||
#include <mission/tmtc/PersistentTmStoreWithTmQueue.h>
|
||||
|
||||
/**
|
||||
* Generic class which composes a Virtual Channel and a persistent TM stores. This allows dumping
|
||||
* the TM store into the virtual channel directly.
|
||||
*/
|
||||
class TmStoreTaskBase : public SystemObject,
|
||||
public HasModesIF,
|
||||
public ModeTreeChildIF,
|
||||
public ModeTreeConnectionIF {
|
||||
public:
|
||||
struct DumpContext {
|
||||
DumpContext(Event eventIfDone, Event eventIfCancelled)
|
||||
: eventIfDone(eventIfDone), eventIfCancelled(eventIfCancelled) {}
|
||||
void reset() {
|
||||
numberOfDumpedPackets = 0;
|
||||
dumpedBytes = 0;
|
||||
vcBusyDuringDump = false;
|
||||
packetWasDumped = false;
|
||||
bytesDumpedAtLastDelay = 0;
|
||||
ptmeBusyCounter = 0;
|
||||
}
|
||||
const Event eventIfDone;
|
||||
const Event eventIfCancelled;
|
||||
size_t numberOfDumpedPackets = 0;
|
||||
size_t bytesDumpedAtLastDelay = 0;
|
||||
size_t dumpedBytes = 0;
|
||||
uint32_t ptmeBusyCounter = 0;
|
||||
bool packetWasDumped = false;
|
||||
bool vcBusyDuringDump = false;
|
||||
};
|
||||
|
||||
TmStoreTaskBase(object_id_t objectId, StorageManagerIF& ipcStore, VirtualChannel& channel,
|
||||
SdCardMountedIF& sdcMan);
|
||||
|
||||
ReturnValue_t initialize() override;
|
||||
|
||||
protected:
|
||||
MessageQueueIF* requestQueue;
|
||||
ModeHelper modeHelper;
|
||||
StorageManagerIF& ipcStore;
|
||||
Mode_t mode = HasModesIF::MODE_OFF;
|
||||
Countdown sdCardCheckCd = Countdown(800);
|
||||
// 20 minutes are allowed as maximum dump time.
|
||||
Countdown cancelDumpCd = Countdown(60 * 20 * 1000);
|
||||
// If the TM sink is busy for 1 minute for whatever reason, cancel the dump.
|
||||
Countdown tmSinkBusyCd = Countdown(60 * 1000);
|
||||
VirtualChannel& channel;
|
||||
bool storesInitialized = false;
|
||||
bool fileHasSwapped = false;
|
||||
SdCardMountedIF& sdcMan;
|
||||
|
||||
void readCommandQueue(void);
|
||||
|
||||
virtual bool initStoresIfPossible() = 0;
|
||||
virtual void startTransition(Mode_t mode, Submode_t submode) = 0;
|
||||
|
||||
void cancelDump(DumpContext& ctx, PersistentTmStore& store, bool isTxOn);
|
||||
/**
|
||||
*
|
||||
* Handling for one store. Returns if anything was done.
|
||||
* @param store
|
||||
* @return
|
||||
*/
|
||||
bool handleOneStore(PersistentTmStoreWithTmQueue& store, DumpContext& dumpContext);
|
||||
|
||||
ReturnValue_t handleOneDump(PersistentTmStoreWithTmQueue& store, DumpContext& dumpContext,
|
||||
bool& dumpPerformed);
|
||||
|
||||
/**
|
||||
* Occasionally check whether SD card is okay to be used. If not, poll whether it is ready to
|
||||
* be used again and re-initialize stores. Returns whether store is okay to be used.
|
||||
*/
|
||||
bool cyclicStoreCheck();
|
||||
|
||||
MessageQueueId_t getCommandQueue() const override;
|
||||
|
||||
void getMode(Mode_t* mode, Submode_t* submode) override;
|
||||
|
||||
ReturnValue_t checkModeCommand(Mode_t mode, Submode_t submode,
|
||||
uint32_t* msToReachTheMode) override;
|
||||
void announceMode(bool recursive) override;
|
||||
object_id_t getObjectId() const override;
|
||||
const HasHealthIF* getOptHealthIF() const override;
|
||||
const HasModesIF& getModeIF() const override;
|
||||
ReturnValue_t connectModeTreeParent(HasModeTreeChildrenIF& parent) override;
|
||||
ModeTreeChildIF& getModeTreeChildIF() override;
|
||||
};
|
||||
|
||||
#endif /* MISSION_TMTC_TMSTORETASKBASE_H_ */
|
34
mission/com/VirtualChannel.cpp
Normal file
34
mission/com/VirtualChannel.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
#include "VirtualChannel.h"
|
||||
|
||||
VirtualChannel::VirtualChannel(object_id_t objectId, uint8_t vcId, const char* vcName, PtmeIF& ptme,
|
||||
const std::atomic_bool& txOn)
|
||||
: SystemObject(objectId), ptme(ptme), vcId(vcId), vcName(vcName), txOn(txOn) {}
|
||||
|
||||
ReturnValue_t VirtualChannel::initialize() { return returnvalue::OK; }
|
||||
|
||||
ReturnValue_t VirtualChannel::sendNextTm(const uint8_t* data, size_t size) {
|
||||
return write(data, size);
|
||||
}
|
||||
|
||||
ReturnValue_t VirtualChannel::write(const uint8_t* data, size_t size) {
|
||||
if (txOn) {
|
||||
return ptme.writeToVc(vcId, data, size);
|
||||
}
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
uint8_t VirtualChannel::getVcid() const { return vcId; }
|
||||
|
||||
const char* VirtualChannel::getName() const { return vcName.c_str(); }
|
||||
|
||||
bool VirtualChannel::isBusy() const {
|
||||
// Data is discarded, so channel is not busy.
|
||||
if (not txOn) {
|
||||
return false;
|
||||
}
|
||||
return ptme.isBusy(vcId);
|
||||
}
|
||||
|
||||
void VirtualChannel::cancelTransfer() { ptme.cancelTransfer(vcId); }
|
||||
|
||||
bool VirtualChannel::isTxOn() const { return txOn; }
|
42
mission/com/VirtualChannel.h
Normal file
42
mission/com/VirtualChannel.h
Normal file
@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
#include <fsfw/objectmanager/SystemObject.h>
|
||||
#include <linux/ipcore/PtmeIF.h>
|
||||
#include <linux/ipcore/VirtualChannelIF.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <string>
|
||||
|
||||
/**
|
||||
* @brief This class represents a virtual channel. Sending a tm message to an object of this class
|
||||
* will forward the tm packet to the respective virtual channel of the PTME IP Core.
|
||||
*
|
||||
* @author J. Meier
|
||||
*/
|
||||
class VirtualChannel : public SystemObject, public VirtualChannelIF {
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor
|
||||
*
|
||||
* @param vcId The virtual channel id assigned to this object
|
||||
* @param tmQueueDepth Queue depth of queue receiving telemetry from other objects
|
||||
*/
|
||||
VirtualChannel(object_id_t objectId, uint8_t vcId, const char* vcName, PtmeIF& ptme,
|
||||
const std::atomic_bool& linkStateProvider);
|
||||
|
||||
ReturnValue_t initialize() override;
|
||||
ReturnValue_t sendNextTm(const uint8_t* data, size_t size);
|
||||
bool isBusy() const override;
|
||||
ReturnValue_t write(const uint8_t* data, size_t size) override;
|
||||
void cancelTransfer() override;
|
||||
uint8_t getVcid() const;
|
||||
bool isTxOn() const;
|
||||
|
||||
const char* getName() const;
|
||||
|
||||
private:
|
||||
PtmeIF& ptme;
|
||||
uint8_t vcId = 0;
|
||||
std::string vcName;
|
||||
const std::atomic_bool& txOn;
|
||||
};
|
50
mission/com/VirtualChannelWithQueue.cpp
Normal file
50
mission/com/VirtualChannelWithQueue.cpp
Normal file
@ -0,0 +1,50 @@
|
||||
#include "VirtualChannelWithQueue.h"
|
||||
|
||||
#include "OBSWConfig.h"
|
||||
#include "fsfw/ipc/QueueFactory.h"
|
||||
#include "fsfw/objectmanager/ObjectManager.h"
|
||||
#include "fsfw/serviceinterface/ServiceInterfaceStream.h"
|
||||
#include "fsfw/tmtcservices/TmTcMessage.h"
|
||||
#include "mission/com/CcsdsIpCoreHandler.h"
|
||||
|
||||
VirtualChannelWithQueue::VirtualChannelWithQueue(object_id_t objectId, uint8_t vcId,
|
||||
const char* vcName, PtmeIF& ptme,
|
||||
const std::atomic_bool& linkStateProvider,
|
||||
StorageManagerIF& tmStore, uint32_t tmQueueDepth)
|
||||
: VirtualChannel(objectId, vcId, vcName, ptme, linkStateProvider), tmStore(tmStore) {
|
||||
auto mqArgs = MqArgs(getObjectId(), reinterpret_cast<void*>(getVcid()));
|
||||
tmQueue = QueueFactory::instance()->createMessageQueue(
|
||||
tmQueueDepth, MessageQueueMessage::MAX_MESSAGE_SIZE, &mqArgs);
|
||||
}
|
||||
|
||||
const char* VirtualChannelWithQueue::getName() const { return VirtualChannel::getName(); }
|
||||
|
||||
ReturnValue_t VirtualChannelWithQueue::handleNextTm(bool performWriteOp) {
|
||||
TmTcMessage message;
|
||||
ReturnValue_t result = tmQueue->receiveMessage(&message);
|
||||
if (result == MessageQueueIF::EMPTY) {
|
||||
return result;
|
||||
}
|
||||
store_address_t storeId = message.getStorageId();
|
||||
const uint8_t* data = nullptr;
|
||||
size_t size = 0;
|
||||
result = tmStore.getData(storeId, &data, &size);
|
||||
if (result != returnvalue::OK) {
|
||||
sif::warning << "VirtualChannel::performOperation: Failed to read data from TM store"
|
||||
<< std::endl;
|
||||
tmStore.deleteData(storeId);
|
||||
return result;
|
||||
}
|
||||
|
||||
if (performWriteOp) {
|
||||
result = write(data, size);
|
||||
}
|
||||
// Try delete in any case, ignore failures (which should not happen), it is more important to
|
||||
// propagate write errors.
|
||||
tmStore.deleteData(storeId);
|
||||
return result;
|
||||
}
|
||||
|
||||
MessageQueueId_t VirtualChannelWithQueue::getReportReceptionQueue(uint8_t virtualChannel) const {
|
||||
return tmQueue->getId();
|
||||
}
|
42
mission/com/VirtualChannelWithQueue.h
Normal file
42
mission/com/VirtualChannelWithQueue.h
Normal file
@ -0,0 +1,42 @@
|
||||
#pragma once
|
||||
|
||||
#include <fsfw/ipc/MessageQueueIF.h>
|
||||
#include <fsfw/objectmanager/SystemObject.h>
|
||||
#include <fsfw/tasks/ExecutableObjectIF.h>
|
||||
#include <linux/ipcore/PtmeIF.h>
|
||||
#include <mission/com/VirtualChannel.h>
|
||||
|
||||
#include <atomic>
|
||||
|
||||
#include "OBSWConfig.h"
|
||||
#include "fsfw/returnvalues/returnvalue.h"
|
||||
#include "fsfw/tmtcservices/AcceptsTelemetryIF.h"
|
||||
|
||||
class StorageManagerIF;
|
||||
|
||||
/**
|
||||
* @brief This class represents a virtual channel. Sending a tm message to an object of this class
|
||||
* will forward the tm packet to the respective virtual channel of the PTME IP Core.
|
||||
*
|
||||
* @author J. Meier
|
||||
*/
|
||||
class VirtualChannelWithQueue : public VirtualChannel, public AcceptsTelemetryIF {
|
||||
public:
|
||||
/**
|
||||
* @brief Constructor
|
||||
*
|
||||
* @param vcId The virtual channel id assigned to this object
|
||||
* @param tmQueueDepth Queue depth of queue receiving telemetry from other objects
|
||||
*/
|
||||
VirtualChannelWithQueue(object_id_t objectId, uint8_t vcId, const char* vcName, PtmeIF& ptme,
|
||||
const std::atomic_bool& linkStateProvider, StorageManagerIF& tmStore,
|
||||
uint32_t tmQueueDepth);
|
||||
|
||||
MessageQueueId_t getReportReceptionQueue(uint8_t virtualChannel = 0) const override;
|
||||
[[nodiscard]] const char* getName() const override;
|
||||
ReturnValue_t handleNextTm(bool performWriteOp);
|
||||
|
||||
private:
|
||||
MessageQueueIF* tmQueue = nullptr;
|
||||
StorageManagerIF& tmStore;
|
||||
};
|
Reference in New Issue
Block a user