From 90c1d45f20ddd6182f17e1d33aac3d05661b2117 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 22 Feb 2023 18:06:34 +0100 Subject: [PATCH] correction for prefix handling on Q7S --- CHANGELOG.md | 4 ++++ bsp_q7s/core/CoreController.cpp | 3 +++ bsp_q7s/em/emObjectFactory.cpp | 3 ++- bsp_q7s/fs/SdCardManager.cpp | 7 ++++-- bsp_q7s/fs/SdCardManager.h | 4 ++-- bsp_q7s/fs/helpers.cpp | 3 +++ dummies/CMakeLists.txt | 1 + dummies/RtdPollingDummy.cpp | 4 +++- dummies/RtdPollingDummy.h | 6 +++-- dummies/helpers.cpp | 3 +-- linux/devices/ploc/PlocSupervisorHandler.cpp | 11 +++++---- mission/devices/PayloadPcduHandler.cpp | 3 +++ mission/devices/ScexDeviceHandler.cpp | 24 +++++++++++++------- mission/memory/SdCardMountedIF.h | 2 +- mission/tmtc/PersistentTmStore.cpp | 10 +++++--- mission/tmtc/PersistentTmStore.h | 2 +- mission/tmtc/PusTmFunnel.cpp | 2 +- mission/utility/DummySdCardManager.cpp | 2 +- mission/utility/DummySdCardManager.h | 2 +- 19 files changed, 66 insertions(+), 30 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f89175d2..bfce5b76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,10 @@ will consitute of a breaking change warranting a new major release: telemetry. PR: https://egit.irs.uni-stuttgart.de/eive/eive-obsw/pulls/320/files +## Changed + +- Changed format of `getCurrentMountPrefix` to return a `const char*`. + # [v1.30.0] eive-tmtc: v2.14.0 diff --git a/bsp_q7s/core/CoreController.cpp b/bsp_q7s/core/CoreController.cpp index d3264b73..2c74b063 100644 --- a/bsp_q7s/core/CoreController.cpp +++ b/bsp_q7s/core/CoreController.cpp @@ -159,6 +159,9 @@ ReturnValue_t CoreController::initializeAfterTaskCreation() { } sdcMan->setActiveSdCard(sdInfo.active); currMntPrefix = sdcMan->getCurrentMountPrefix(); + if (currMntPrefix == "") { + return ObjectManagerIF::CHILD_INIT_FAILED; + } if (BLOCKING_SD_INIT) { result = initSdCardBlocking(); if (result != returnvalue::OK and result != SdCardManager::ALREADY_MOUNTED) { diff --git a/bsp_q7s/em/emObjectFactory.cpp b/bsp_q7s/em/emObjectFactory.cpp index 8eb1bc5f..8364533a 100644 --- a/bsp_q7s/em/emObjectFactory.cpp +++ b/bsp_q7s/em/emObjectFactory.cpp @@ -23,7 +23,8 @@ void ObjectFactory::produce(void* args) { HealthTableIF* healthTable = nullptr; PusTmFunnel* pusFunnel = nullptr; CfdpTmFunnel* cfdpFunnel = nullptr; - ObjectFactory::produceGenericObjects(&healthTable, &pusFunnel, &cfdpFunnel, *SdCardManager::instance()); + ObjectFactory::produceGenericObjects(&healthTable, &pusFunnel, &cfdpFunnel, + *SdCardManager::instance()); LinuxLibgpioIF* gpioComIF = nullptr; SerialComIF* uartComIF = nullptr; diff --git a/bsp_q7s/fs/SdCardManager.cpp b/bsp_q7s/fs/SdCardManager.cpp index c0b1184e..9e5d05bc 100644 --- a/bsp_q7s/fs/SdCardManager.cpp +++ b/bsp_q7s/fs/SdCardManager.cpp @@ -410,9 +410,12 @@ ReturnValue_t SdCardManager::updateSdCardStateFile() { return result; } -const std::string& SdCardManager::getCurrentMountPrefix() const { +const char* SdCardManager::getCurrentMountPrefix() const { MutexGuard mg(mutex); - return currentPrefix; + if (currentPrefix.has_value()) { + return currentPrefix.value().c_str(); + } + return nullptr; } SdCardManager::OpStatus SdCardManager::checkCurrentOp(Operations& currentOp) { diff --git a/bsp_q7s/fs/SdCardManager.h b/bsp_q7s/fs/SdCardManager.h index 749cae62..77055589 100644 --- a/bsp_q7s/fs/SdCardManager.h +++ b/bsp_q7s/fs/SdCardManager.h @@ -187,7 +187,7 @@ class SdCardManager : public SystemObject, public SdCardMountedIF { * @param prefSdCardPtr * @return */ - const std::string& getCurrentMountPrefix() const override; + const char* getCurrentMountPrefix() const override; OpStatus checkCurrentOp(Operations& currentOp); @@ -232,7 +232,7 @@ class SdCardManager : public SystemObject, public SdCardMountedIF { void processSdStatusLine(SdStatePair& active, std::string& line, uint8_t& idx, sd::SdCard& currentSd); - std::string currentPrefix; + std::optional currentPrefix; static SdCardManager* INSTANCE; }; diff --git a/bsp_q7s/fs/helpers.cpp b/bsp_q7s/fs/helpers.cpp index f1f31eba..19c2f67e 100644 --- a/bsp_q7s/fs/helpers.cpp +++ b/bsp_q7s/fs/helpers.cpp @@ -3,6 +3,9 @@ std::filesystem::path fshelpers::getPrefixedPath(SdCardManager &man, std::filesystem::path pathWihtoutPrefix) { auto prefix = man.getCurrentMountPrefix(); + if (prefix == nullptr) { + return pathWihtoutPrefix; + } auto resPath = prefix / pathWihtoutPrefix; return resPath; } diff --git a/dummies/CMakeLists.txt b/dummies/CMakeLists.txt index 810cc048..9040fbb0 100644 --- a/dummies/CMakeLists.txt +++ b/dummies/CMakeLists.txt @@ -25,5 +25,6 @@ target_sources( PlocMpsocDummy.cpp PlocSupervisorDummy.cpp helpers.cpp + RtdPollingDummy.cpp MgmRm3100Dummy.cpp Tmp1075Dummy.cpp) diff --git a/dummies/RtdPollingDummy.cpp b/dummies/RtdPollingDummy.cpp index f1cd1155..82eb3ec6 100644 --- a/dummies/RtdPollingDummy.cpp +++ b/dummies/RtdPollingDummy.cpp @@ -1,3 +1,5 @@ #include "RtdPollingDummy.h" -RtdPollingDummy::RtdPollingDummy(object_id_t objectId): SystemObject(objectId) {} +RtdPollingDummy::RtdPollingDummy(object_id_t objectId) : SystemObject(objectId) {} + +ReturnValue_t RtdPollingDummy::performOperation(uint8_t operationCode) { return returnvalue::OK; } diff --git a/dummies/RtdPollingDummy.h b/dummies/RtdPollingDummy.h index 0228123b..b5ffb5f2 100644 --- a/dummies/RtdPollingDummy.h +++ b/dummies/RtdPollingDummy.h @@ -2,10 +2,12 @@ #define DUMMIES_RTDPOLLINGDUMMY_H_ #include +#include -class RtdPollingDummy: public SystemObject { -public: +class RtdPollingDummy : public ExecutableObjectIF, public SystemObject { + public: RtdPollingDummy(object_id_t objectId); + ReturnValue_t performOperation(uint8_t operationCode = 0) override; }; #endif /* DUMMIES_RTDPOLLINGDUMMY_H_ */ diff --git a/dummies/helpers.cpp b/dummies/helpers.cpp index e6faab32..8a49a592 100644 --- a/dummies/helpers.cpp +++ b/dummies/helpers.cpp @@ -46,7 +46,7 @@ void dummy::createDummies(DummyCfg cfg, PowerSwitchIF& pwrSwitcher, GpioIF* gpio new CoreControllerDummy(objects::CORE_CONTROLLER); } if (cfg.addRtdComIFDummy) { - new ComIFDummy(objects::SPI_RTD_COM_IF); + new RtdPollingDummy(objects::SPI_RTD_COM_IF); } std::array rwIds = {objects::RW1, objects::RW2, objects::RW3, objects::RW4}; std::array rws; @@ -193,7 +193,6 @@ void dummy::createDummies(DummyCfg cfg, PowerSwitchIF& pwrSwitcher, GpioIF* gpio objects::TMP1075_HANDLER_IF_BOARD, new Tmp1075Dummy(objects::TMP1075_HANDLER_IF_BOARD, objects::DUMMY_COM_IF, comCookieDummy)); - new RtdPollingDummy(objects::SPI_RTD_COM_IF); new TemperatureSensorInserter(objects::THERMAL_TEMP_INSERTER, rtdSensorDummies, tmpSensorDummies); TcsBoardAssembly* tcsBoardAssy = ObjectFactory::createTcsBoardAssy(pwrSwitcher); diff --git a/linux/devices/ploc/PlocSupervisorHandler.cpp b/linux/devices/ploc/PlocSupervisorHandler.cpp index 086ef661..06a4cf07 100644 --- a/linux/devices/ploc/PlocSupervisorHandler.cpp +++ b/linux/devices/ploc/PlocSupervisorHandler.cpp @@ -1742,18 +1742,21 @@ ReturnValue_t PlocSupervisorHandler::createMramDumpFile() { std::string filename = "mram-dump--" + timeStamp + ".bin"; #ifdef XIPHOS_Q7S - std::string currentMountPrefix = sdcMan->getCurrentMountPrefix(); + const char* currentMountPrefix = sdcMan->getCurrentMountPrefix(); #else - std::string currentMountPrefix("/mnt/sd0"); + const char* currentMountPrefix = "/mnt/sd0"; #endif /* BOARD_TE0720 == 0 */ + if (currentMountPrefix == nullptr) { + return returnvalue::FAILED; + } // Check if path to PLOC directory exists - if (not std::filesystem::exists(std::string(currentMountPrefix + "/" + supervisorFilePath))) { + if (not std::filesystem::exists(std::string(currentMountPrefix) + "/" + supervisorFilePath)) { sif::warning << "PlocSupervisorHandler::createMramDumpFile: Supervisor path does not exist" << std::endl; return result::PATH_DOES_NOT_EXIST; } - activeMramFile = currentMountPrefix + "/" + supervisorFilePath + "/" + filename; + activeMramFile = std::string(currentMountPrefix) + "/" + supervisorFilePath + "/" + filename; // Create new file std::ofstream file(activeMramFile, std::ios_base::out); file.close(); diff --git a/mission/devices/PayloadPcduHandler.cpp b/mission/devices/PayloadPcduHandler.cpp index 44dd667c..48880c6e 100644 --- a/mission/devices/PayloadPcduHandler.cpp +++ b/mission/devices/PayloadPcduHandler.cpp @@ -517,6 +517,9 @@ void PayloadPcduHandler::checkJsonFileInit() { if (not jsonFileInitComplete) { auto activeSd = sdcMan->getActiveSdCard(); if (activeSd and sdcMan->isSdCardUsable(activeSd.value())) { + if (sdcMan->getCurrentMountPrefix() == nullptr) { + return; + } params.initialize(sdcMan->getCurrentMountPrefix()); jsonFileInitComplete = true; } diff --git a/mission/devices/ScexDeviceHandler.cpp b/mission/devices/ScexDeviceHandler.cpp index 8da6d229..e2061a6b 100644 --- a/mission/devices/ScexDeviceHandler.cpp +++ b/mission/devices/ScexDeviceHandler.cpp @@ -214,6 +214,9 @@ ReturnValue_t ScexDeviceHandler::interpretDeviceReply(DeviceCommandId_t id, cons fileId = date_time_string(); std::ostringstream oss; auto prefix = sdcMan.getCurrentMountPrefix(); + if (prefix == nullptr) { + return returnvalue::FAILED; + } oss << prefix << "/scex/scex-" << cmdName << fileId << ".bin"; fileName = oss.str(); ofstream out(fileName, ofstream::binary); @@ -234,6 +237,9 @@ ReturnValue_t ScexDeviceHandler::interpretDeviceReply(DeviceCommandId_t id, cons fileId = date_time_string(); std::ostringstream oss; auto prefix = sdcMan.getCurrentMountPrefix(); + if (prefix == nullptr) { + return returnvalue::FAILED; + } oss << prefix << "/scex/scex-" << cmdName << fileId << ".bin"; fileName = oss.str(); fileNameSet = true; @@ -310,6 +316,16 @@ ReturnValue_t ScexDeviceHandler::interpretDeviceReply(DeviceCommandId_t id, cons } void ScexDeviceHandler::performOperationHook() { + auto mntPrefix = sdcMan.getCurrentMountPrefix(); + if (mntPrefix != nullptr) { + std::filesystem::path fullFilePath = mntPrefix; + fullFilePath /= "scex"; + bool fileExists = std::filesystem::exists(fullFilePath); + + if (not fileExists) { + std::filesystem::create_directory(fullFilePath); + } + } uint32_t remainingMillis = finishCountdown.getRemainingMillis(); if (commandActive and finishCountdown.hasTimedOut()) { triggerEvent(scex::EXPERIMENT_TIMEDOUT, currCmd, 0); @@ -373,13 +389,5 @@ void ScexDeviceHandler::setPowerSwitcher(PowerSwitchIF& powerSwitcher, power::Sw } ReturnValue_t ScexDeviceHandler::initializeAfterTaskCreation() { - auto mntPrefix = sdcMan.getCurrentMountPrefix(); - std::filesystem::path fullFilePath = mntPrefix; - fullFilePath /= "scex"; - bool fileExists = std::filesystem::exists(fullFilePath); - - if (not fileExists) { - std::filesystem::create_directory(fullFilePath); - } return DeviceHandlerBase::initializeAfterTaskCreation(); } diff --git a/mission/memory/SdCardMountedIF.h b/mission/memory/SdCardMountedIF.h index ac705e8d..1e76b9b7 100644 --- a/mission/memory/SdCardMountedIF.h +++ b/mission/memory/SdCardMountedIF.h @@ -9,7 +9,7 @@ class SdCardMountedIF { public: virtual ~SdCardMountedIF(){}; - virtual const std::string& getCurrentMountPrefix() const = 0; + virtual const char* getCurrentMountPrefix() const = 0; virtual bool isSdCardUsable(std::optional sdCard) = 0; virtual std::optional getPreferredSdCard() const = 0; virtual void setActiveSdCard(sd::SdCard sdCard) = 0; diff --git a/mission/tmtc/PersistentTmStore.cpp b/mission/tmtc/PersistentTmStore.cpp index 100767b9..b8f24462 100644 --- a/mission/tmtc/PersistentTmStore.cpp +++ b/mission/tmtc/PersistentTmStore.cpp @@ -52,7 +52,7 @@ ReturnValue_t PersistentTmStore::assignAndOrCreateMostRecentFile() { time_t fileEpoch = timegm(&time); // There is still a file within the active time window, so re-use that file for new TMs to // store. - if (fileEpoch + rolloverDiffSeconds > currentTv.tv_sec) { + if (fileEpoch + static_cast(rolloverDiffSeconds) > currentTv.tv_sec) { activeFileTv.tv_sec = fileEpoch; activeFile = file.path(); break; @@ -191,14 +191,18 @@ void PersistentTmStore::calcDiffSeconds(RolloverInterval intervalUnit, uint32_t } } -void PersistentTmStore::updateBaseDir() { +bool PersistentTmStore::updateBaseDir() { using namespace std::filesystem; - std::string currentPrefix = sdcMan.getCurrentMountPrefix(); + const char* currentPrefix = sdcMan.getCurrentMountPrefix(); + if (currentPrefix == nullptr) { + return false; + } basePath = path(currentPrefix) / baseDir / baseName; if (not exists(basePath)) { create_directories(basePath); } baseDirUninitialized = false; + return true; } void PersistentTmStore::addApid(uint16_t apid) { diff --git a/mission/tmtc/PersistentTmStore.h b/mission/tmtc/PersistentTmStore.h index bcd83a71..54c3b4d4 100644 --- a/mission/tmtc/PersistentTmStore.h +++ b/mission/tmtc/PersistentTmStore.h @@ -77,7 +77,7 @@ class PersistentTmStore : public TmStoreFrontendSimpleIF, public SystemObject { ReturnValue_t createMostRecentFile(); static ReturnValue_t pathToTm(const std::filesystem::path& path, struct tm& time); void fileToPackets(const std::filesystem::path& path, uint32_t unixStamp, TmFunnelBase& funnel); - void updateBaseDir(); + bool updateBaseDir(); ReturnValue_t assignAndOrCreateMostRecentFile(); ReturnValue_t storePacket(PusTmReader& reader); }; diff --git a/mission/tmtc/PusTmFunnel.cpp b/mission/tmtc/PusTmFunnel.cpp index a0f345cb..524b2e6d 100644 --- a/mission/tmtc/PusTmFunnel.cpp +++ b/mission/tmtc/PusTmFunnel.cpp @@ -144,7 +144,7 @@ ReturnValue_t PusTmFunnel::handleTmPacket(TmTcMessage &message) { const char *PusTmFunnel::getName() const { return "PUS TM Funnel"; } void PusTmFunnel::initStoresIfPossible(bool sdCardUsable) { - if (not storesInitialized and sdCardUsable) { + if (not storesInitialized and sdCardUsable and sdcMan.getCurrentMountPrefix() != nullptr) { miscStore.initializeTmStore(); okStore.initializeTmStore(); hkStore.initializeTmStore(); diff --git a/mission/utility/DummySdCardManager.cpp b/mission/utility/DummySdCardManager.cpp index 1b2a45e1..17d7ba2b 100644 --- a/mission/utility/DummySdCardManager.cpp +++ b/mission/utility/DummySdCardManager.cpp @@ -2,7 +2,7 @@ DummySdCardManager::DummySdCardManager(std::string prefix) : prefix(std::move(prefix)) {} -const std::string& DummySdCardManager::getCurrentMountPrefix() const { return prefix; } +const char* DummySdCardManager::getCurrentMountPrefix() const { return prefix.c_str(); } bool DummySdCardManager::isSdCardUsable(std::optional sdCard) { return true; } diff --git a/mission/utility/DummySdCardManager.h b/mission/utility/DummySdCardManager.h index 1a74dc10..4c985056 100644 --- a/mission/utility/DummySdCardManager.h +++ b/mission/utility/DummySdCardManager.h @@ -5,7 +5,7 @@ class DummySdCardManager : public SdCardMountedIF { public: DummySdCardManager(std::string prefix); - const std::string& getCurrentMountPrefix() const override; + const char* getCurrentMountPrefix() const override; bool isSdCardUsable(std::optional sdCard) override; std::optional getPreferredSdCard() const override; void setActiveSdCard(sd::SdCard sdCard) override;