From d50cbe9e5b00504794fa744a734d7a2802e129cb Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 9 Mar 2023 20:16:00 +0100 Subject: [PATCH] added missing store initialization code --- bsp_q7s/core/ObjectFactory.cpp | 10 +++++--- bsp_q7s/fmObjectFactory.cpp | 4 +-- mission/tmtc/PersistentLogTmStoreTask.cpp | 27 +++++++++++++++----- mission/tmtc/PersistentLogTmStoreTask.h | 4 ++- mission/tmtc/PersistentSingleTmStoreTask.cpp | 10 ++++++-- mission/tmtc/PersistentSingleTmStoreTask.h | 6 +++-- mission/tmtc/TmStoreTaskBase.cpp | 25 ++++++++++++++++-- mission/tmtc/TmStoreTaskBase.h | 18 +++++++++++-- 8 files changed, 82 insertions(+), 22 deletions(-) diff --git a/bsp_q7s/core/ObjectFactory.cpp b/bsp_q7s/core/ObjectFactory.cpp index b0bab8de..721c5338 100644 --- a/bsp_q7s/core/ObjectFactory.cpp +++ b/bsp_q7s/core/ObjectFactory.cpp @@ -771,7 +771,7 @@ ReturnValue_t ObjectFactory::createCcsdsComponents(CcsdsComponentArgs& args) { auto* vcWithQueue = new VirtualChannelWithQueue(objects::PTME_VC0_LIVE_TM, ccsds::VC0, "PTME VC0 LIVE TM", *ptme, LINK_STATE, args.tmStore, 500); - args.liveDestination = vcWithQueue->getReportReceptionQueue(0); + args.liveDestination = vcWithQueue; new LiveTmTask(objects::LIVE_TM_TASK, *vcWithQueue); // Set up log store. @@ -779,17 +779,19 @@ ReturnValue_t ObjectFactory::createCcsdsComponents(CcsdsComponentArgs& args) { LINK_STATE); LogStores logStores(args.stores); // Core task which handles the LOG store and takes care of dumping it as TM using a VC directly - new PersistentLogTmStoreTask(objects::LOG_STORE_TASK, args.ipcStore, logStores, *vc); + new PersistentLogTmStoreTask(objects::LOG_STORE_TASK, args.ipcStore, logStores, *vc, + *SdCardManager::instance()); vc = new VirtualChannel(objects::PTME_VC2_HK_TM, ccsds::VC2, "PTME VC2 HK TM", *ptme, LINK_STATE); // Core task which handles the HK store and takes care of dumping it as TM using a VC directly - new PersistentSingleTmStoreTask(objects::HK_STORE_TASK, args.ipcStore, *args.stores.hkStore, *vc); + new PersistentSingleTmStoreTask(objects::HK_STORE_TASK, args.ipcStore, *args.stores.hkStore, *vc, + *SdCardManager::instance()); vc = new VirtualChannel(objects::PTME_VC3_CFDP_TM, ccsds::VC3, "PTME VC3 CFDP TM", *ptme, LINK_STATE); // Core task which handles the CFDP store and takes care of dumping it as TM using a VC directly new PersistentSingleTmStoreTask(objects::CFDP_STORE_TASK, args.ipcStore, *args.stores.cfdpStore, - *vc); + *vc, *SdCardManager::instance()); ReturnValue_t result = (*args.ipCoreHandler)->connectModeTreeParent(satsystem::com::SUBSYSTEM); if (result != returnvalue::OK) { diff --git a/bsp_q7s/fmObjectFactory.cpp b/bsp_q7s/fmObjectFactory.cpp index 68695f42..390e4e8c 100644 --- a/bsp_q7s/fmObjectFactory.cpp +++ b/bsp_q7s/fmObjectFactory.cpp @@ -80,11 +80,9 @@ void ObjectFactory::produce(void* args) { CcsdsComponentArgs ccsdsArgs(*gpioComIF, *ipcStore, *tmStore, stores, &ipCoreHandler); createCcsdsComponents(ccsdsArgs); #if OBSW_TM_TO_PTME == 1 - // TODO: Remove this if not needed anymore - if (*ccsdsArgs.liveDestination != nullptr) { + if (ccsdsArgs.liveDestination != nullptr) { pusFunnel->addLiveDestination("VC0 LIVE TM", *ccsdsArgs.liveDestination, 0); } - // addTmtcIpCoresToFunnels(*ipCoreHandler, *pusFunnel, *cfdpFunnel); #endif #endif /* OBSW_ADD_CCSDS_IP_CORES == 1 */ diff --git a/mission/tmtc/PersistentLogTmStoreTask.cpp b/mission/tmtc/PersistentLogTmStoreTask.cpp index 0410893d..5e715ca0 100644 --- a/mission/tmtc/PersistentLogTmStoreTask.cpp +++ b/mission/tmtc/PersistentLogTmStoreTask.cpp @@ -3,20 +3,26 @@ #include PersistentLogTmStoreTask::PersistentLogTmStoreTask(object_id_t objectId, StorageManagerIF& ipcStore, - LogStores stores, VirtualChannel& channel) - : TmStoreTaskBase(objectId, ipcStore, channel), stores(stores) {} + LogStores stores, VirtualChannel& channel, + SdCardMountedIF& sdcMan) + : TmStoreTaskBase(objectId, ipcStore, channel, sdcMan), stores(stores) {} ReturnValue_t PersistentLogTmStoreTask::performOperation(uint8_t opCode) { while (true) { - bool someonesBusy = false; - bool busy = handleOneStore(stores.okStore); - if (busy) { - someonesBusy = true; + if (not cyclicStoreCheck()) { + continue; } + bool someonesBusy = false; + bool busy = false; busy = handleOneStore(stores.okStore); if (busy) { someonesBusy = true; } + busy = handleOneStore(stores.notOkStore); + if (busy) { + someonesBusy = true; + } + busy = handleOneStore(stores.miscStore); if (busy) { someonesBusy = true; @@ -26,3 +32,12 @@ ReturnValue_t PersistentLogTmStoreTask::performOperation(uint8_t opCode) { } } } + +void PersistentLogTmStoreTask::initStoresIfPossible() { + if (sdcMan.isSdCardUsable(std::nullopt)) { + stores.okStore.initializeTmStore(); + stores.miscStore.initializeTmStore(); + stores.notOkStore.initializeTmStore(); + storesInitialized = true; + } +} diff --git a/mission/tmtc/PersistentLogTmStoreTask.h b/mission/tmtc/PersistentLogTmStoreTask.h index a360c35c..e106bd12 100644 --- a/mission/tmtc/PersistentLogTmStoreTask.h +++ b/mission/tmtc/PersistentLogTmStoreTask.h @@ -22,12 +22,14 @@ struct LogStores { class PersistentLogTmStoreTask : public TmStoreTaskBase, public ExecutableObjectIF { public: PersistentLogTmStoreTask(object_id_t objectId, StorageManagerIF& ipcStore, LogStores tmStore, - VirtualChannel& channel); + VirtualChannel& channel, SdCardMountedIF& sdcMan); ReturnValue_t performOperation(uint8_t opCode) override; private: LogStores stores; + + void initStoresIfPossible(); }; #endif /* MISSION_TMTC_PERSISTENTLOGTMSTORETASK_H_ */ diff --git a/mission/tmtc/PersistentSingleTmStoreTask.cpp b/mission/tmtc/PersistentSingleTmStoreTask.cpp index e3bd018b..aaac7f6e 100644 --- a/mission/tmtc/PersistentSingleTmStoreTask.cpp +++ b/mission/tmtc/PersistentSingleTmStoreTask.cpp @@ -4,14 +4,20 @@ PersistentSingleTmStoreTask::PersistentSingleTmStoreTask(object_id_t objectId, StorageManagerIF& ipcStore, PersistentTmStoreWithTmQueue& tmStore, - VirtualChannel& channel) - : TmStoreTaskBase(objectId, ipcStore, channel), storeWithQueue(tmStore) {} + VirtualChannel& channel, + SdCardMountedIF& sdcMan) + : TmStoreTaskBase(objectId, ipcStore, channel, sdcMan), storeWithQueue(tmStore) {} ReturnValue_t PersistentSingleTmStoreTask::performOperation(uint8_t opCode) { while (true) { + if (not cyclicStoreCheck()) { + continue; + } bool busy = handleOneStore(storeWithQueue); if (not busy) { TaskFactory::delayTask(5); } } } + +void PersistentSingleTmStoreTask::initStoresIfPossible() {} diff --git a/mission/tmtc/PersistentSingleTmStoreTask.h b/mission/tmtc/PersistentSingleTmStoreTask.h index 7776134a..012ba8e8 100644 --- a/mission/tmtc/PersistentSingleTmStoreTask.h +++ b/mission/tmtc/PersistentSingleTmStoreTask.h @@ -10,13 +10,15 @@ class PersistentSingleTmStoreTask : public TmStoreTaskBase, public ExecutableObjectIF { public: PersistentSingleTmStoreTask(object_id_t objectId, StorageManagerIF& ipcStore, - PersistentTmStoreWithTmQueue& storeWithQueue, - VirtualChannel& channel); + PersistentTmStoreWithTmQueue& storeWithQueue, VirtualChannel& channel, + SdCardMountedIF& sdcMan); ReturnValue_t performOperation(uint8_t opCode) override; private: PersistentTmStoreWithTmQueue& storeWithQueue; + + void initStoresIfPossible(); }; #endif /* MISSION_TMTC_PERSISTENTSINGLETMSTORETASK_H_ */ diff --git a/mission/tmtc/TmStoreTaskBase.cpp b/mission/tmtc/TmStoreTaskBase.cpp index 839cb754..325dc77c 100644 --- a/mission/tmtc/TmStoreTaskBase.cpp +++ b/mission/tmtc/TmStoreTaskBase.cpp @@ -1,8 +1,10 @@ #include "TmStoreTaskBase.h" +#include + TmStoreTaskBase::TmStoreTaskBase(object_id_t objectId, StorageManagerIF& ipcStore, - VirtualChannel& channel) - : SystemObject(objectId), ipcStore(ipcStore), channel(channel) {} + VirtualChannel& channel, SdCardMountedIF& sdcMan) + : SystemObject(objectId), ipcStore(ipcStore), channel(channel), sdcMan(sdcMan) {} bool TmStoreTaskBase::handleOneStore(PersistentTmStoreWithTmQueue& store) { bool tmToStoreReceived = true; @@ -33,3 +35,22 @@ bool TmStoreTaskBase::handleOneStore(PersistentTmStoreWithTmQueue& store) { } return false; } + +bool TmStoreTaskBase::cyclicStoreCheck() { + if (not 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; +} diff --git a/mission/tmtc/TmStoreTaskBase.h b/mission/tmtc/TmStoreTaskBase.h index b2f1f323..a1df1f5c 100644 --- a/mission/tmtc/TmStoreTaskBase.h +++ b/mission/tmtc/TmStoreTaskBase.h @@ -1,12 +1,16 @@ #ifndef MISSION_TMTC_TMSTORETASKBASE_H_ #define MISSION_TMTC_TMSTORETASKBASE_H_ +#include #include #include class TmStoreTaskBase : public SystemObject { public: - TmStoreTaskBase(object_id_t objectId, StorageManagerIF& ipcStore, VirtualChannel& channel); + TmStoreTaskBase(object_id_t objectId, StorageManagerIF& ipcStore, VirtualChannel& channel, + SdCardMountedIF& sdcMan); + + protected: /** * Handling for one store. Returns if anything was done. * @param store @@ -14,9 +18,19 @@ class TmStoreTaskBase : public SystemObject { */ bool handleOneStore(PersistentTmStoreWithTmQueue& store); - private: + /** + * 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(); + + virtual void initStoresIfPossible() = 0; + StorageManagerIF& ipcStore; + Countdown sdCardCheckCd = Countdown(800); VirtualChannel& channel; + bool storesInitialized = false; + SdCardMountedIF& sdcMan; }; #endif /* MISSION_TMTC_TMSTORETASKBASE_H_ */