From 409631fb0a433075ddbe214e9418e99951d3bde6 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sat, 1 Apr 2023 14:23:11 +0200 Subject: [PATCH 1/3] filename fixes scex --- CHANGELOG.md | 2 + common/config/eive/definitions.h | 3 + mission/payload/ScexDeviceHandler.cpp | 87 +++++++++++++-------------- mission/payload/ScexDeviceHandler.h | 1 + mission/tmtc/PersistentTmStore.cpp | 5 +- mission/tmtc/PersistentTmStore.h | 2 - 6 files changed, 50 insertions(+), 50 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 359c3718..66b50f95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,8 @@ will consitute of a breaking change warranting a new major release: - Bugfix for side lane transitions of the dual lane assemblies, which only worked when the assembly was directly commanded. - Syrlinks Handler: Bugfix so transition command is only sent once. +- SCEX file name bug: Create file name time stamp with `strftime` similarly to how it's done + for the persistent TM store. ## Added diff --git a/common/config/eive/definitions.h b/common/config/eive/definitions.h index 50a70911..8c460f53 100644 --- a/common/config/eive/definitions.h +++ b/common/config/eive/definitions.h @@ -15,6 +15,9 @@ static constexpr char OBSW_VERSION_FILE_NAME[] = "obsw_version.txt"; static constexpr char OBSW_PATH[] = "/usr/bin/eive-obsw"; static constexpr char OBSW_VERSION_FILE_PATH[] = "/usr/share/eive-obsw/obsw_version.txt"; +// ISO8601 timestamp. +static constexpr char FILE_DATE_FORMAT[] = "%FT%H%M%SZ"; + static constexpr uint16_t EIVE_PUS_APID = 0x65; static constexpr uint16_t EIVE_CFDP_APID = 0x66; static constexpr uint16_t EIVE_LOCAL_CFDP_ENTITY_ID = EIVE_CFDP_APID; diff --git a/mission/payload/ScexDeviceHandler.cpp b/mission/payload/ScexDeviceHandler.cpp index 2b3f69f7..aef6742a 100644 --- a/mission/payload/ScexDeviceHandler.cpp +++ b/mission/payload/ScexDeviceHandler.cpp @@ -11,6 +11,7 @@ #include #include +#include "eive/definitions.h" #include "fsfw/globalfunctions/CRC.h" using std::ofstream; @@ -205,50 +206,9 @@ ReturnValue_t ScexDeviceHandler::interpretDeviceReply(DeviceCommandId_t id, cons using namespace scex; ReturnValue_t status = OK; - auto oneFileHandler = [&](const char* cmdName) { - auto activeSd = sdcMan.getActiveSdCard(); - if (not activeSd) { - return HasFileSystemIF::FILESYSTEM_INACTIVE; - } - 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); - if (out.bad()) { - sif::error << "ScexDeviceHandler::interpretDeviceReply: Could not open file " << fileName - << std::endl; - return FAILED; - } - out << helper; - return OK; - }; auto multiFileHandler = [&](const char* cmdName) { if ((helper.getPacketCounter() == 1) or (not fileNameSet)) { - auto activeSd = sdcMan.getActiveSdCard(); - if (not activeSd) { - return HasFileSystemIF::FILESYSTEM_INACTIVE; - } - 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; - ofstream out(fileName, ofstream::binary); - if (out.bad()) { - sif::error << "ScexDeviceHandler::handleValidReply: Could not open file " << fileName - << std::endl; - return FAILED; - } - out << helper; + return generateNewScexFile(cmdName); } else { ofstream out(fileName, ofstream::binary | ofstream::app); // append @@ -264,19 +224,19 @@ ReturnValue_t ScexDeviceHandler::interpretDeviceReply(DeviceCommandId_t id, cons id = helper.getCmd(); switch (id) { case (PING): { - status = oneFileHandler(PING_IDLE_BASE_NAME); + status = generateNewScexFile(PING_IDLE_BASE_NAME); break; } case (ION_CMD): { - status = oneFileHandler(ION_BASE_NAME); + status = generateNewScexFile(ION_BASE_NAME); break; } case (TEMP_CMD): { - status = oneFileHandler(TEMPERATURE_BASE_NAME); + status = generateNewScexFile(TEMPERATURE_BASE_NAME); break; } case (EXP_STATUS_CMD): { - status = oneFileHandler(EXP_STATUS_BASE_NAME); + status = generateNewScexFile(EXP_STATUS_BASE_NAME); break; } case (FRAM): { @@ -383,6 +343,41 @@ std::string ScexDeviceHandler::date_time_string() { return date_time; } +ReturnValue_t ScexDeviceHandler::generateNewScexFile(const char* cmdName) { + char timeString[64]{}; + auto activeSd = sdcMan.getActiveSdCard(); + if (not activeSd) { + return HasFileSystemIF::FILESYSTEM_INACTIVE; + } + + std::ostringstream oss; + auto prefix = sdcMan.getCurrentMountPrefix(); + if (prefix == nullptr) { + return returnvalue::FAILED; + } + timeval tv; + Clock::getClock_timeval(&tv); + time_t epoch = tv.tv_sec; + struct tm* time = gmtime(&epoch); + size_t writtenBytes = strftime(reinterpret_cast(timeString), sizeof(timeString), + config::FILE_DATE_FORMAT, time); + if (writtenBytes == 0) { + sif::error << "PersistentTmStore::createMostRecentFile: Could not create file timestamp" + << std::endl; + return returnvalue::FAILED; + } + oss << prefix << "/scex/scex-" << cmdName << "-" << timeString << ".bin"; + fileName = oss.str(); + ofstream out(fileName, ofstream::binary); + if (out.bad()) { + sif::error << "ScexDeviceHandler::interpretDeviceReply: Could not open file " << fileName + << std::endl; + return FAILED; + } + out << helper; + return OK; +} + void ScexDeviceHandler::modeChanged() {} void ScexDeviceHandler::setPowerSwitcher(PowerSwitchIF& powerSwitcher, power::Switch_t switchId) { diff --git a/mission/payload/ScexDeviceHandler.h b/mission/payload/ScexDeviceHandler.h index f95169b9..9d7bd7f8 100644 --- a/mission/payload/ScexDeviceHandler.h +++ b/mission/payload/ScexDeviceHandler.h @@ -67,6 +67,7 @@ class ScexDeviceHandler : public DeviceHandlerBase { ReturnValue_t initializeLocalDataPool(localpool::DataPool &localDataPoolMap, LocalDataPoolManager &poolManager) override; ReturnValue_t initializeAfterTaskCreation() override; + ReturnValue_t generateNewScexFile(const char *cmdName); void modeChanged() override; }; diff --git a/mission/tmtc/PersistentTmStore.cpp b/mission/tmtc/PersistentTmStore.cpp index a5f0ec66..bace6025 100644 --- a/mission/tmtc/PersistentTmStore.cpp +++ b/mission/tmtc/PersistentTmStore.cpp @@ -9,6 +9,7 @@ #include #include +#include "eive/definitions.h" #include "fsfw/ipc/CommandMessage.h" #include "fsfw/ipc/QueueFactory.h" #include "fsfw/tmstorage/TmStoreMessage.h" @@ -289,7 +290,7 @@ ReturnValue_t PersistentTmStore::pathToTime(const std::filesystem::path& path, s auto pathStr = path.string(); size_t splitChar = pathStr.find('_'); auto timeOnlyStr = pathStr.substr(splitChar + 1); - if (nullptr == strptime(timeOnlyStr.c_str(), FILE_DATE_FORMAT, &time)) { + if (nullptr == strptime(timeOnlyStr.c_str(), config::FILE_DATE_FORMAT, &time)) { return returnvalue::FAILED; } return returnvalue::OK; @@ -306,7 +307,7 @@ ReturnValue_t PersistentTmStore::createMostRecentFile(std::optional suf time_t epoch = currentTv.tv_sec; struct tm* time = gmtime(&epoch); size_t writtenBytes = strftime(reinterpret_cast(fileBuf.data() + currentIdx), - fileBuf.size(), FILE_DATE_FORMAT, time); + fileBuf.size(), config::FILE_DATE_FORMAT, time); if (writtenBytes == 0) { sif::error << "PersistentTmStore::createMostRecentFile: Could not create file timestamp" << std::endl; diff --git a/mission/tmtc/PersistentTmStore.h b/mission/tmtc/PersistentTmStore.h index 4839f2fb..17d2c9e7 100644 --- a/mission/tmtc/PersistentTmStore.h +++ b/mission/tmtc/PersistentTmStore.h @@ -85,8 +85,6 @@ class PersistentTmStore : public TmStoreFrontendSimpleIF, public SystemObject { private: static constexpr uint8_t MAX_FILES_IN_ONE_SECOND = 10; static constexpr size_t MAX_FILESIZE = 8192; - // ISO8601 timestamp. - static constexpr char FILE_DATE_FORMAT[] = "%FT%H%M%SZ"; //! [EXPORT] : [SKIP] static constexpr ReturnValue_t INVALID_FILE_DETECTED_AND_DELETED = returnvalue::makeCode(2, 1); -- 2.43.0 From 2386944ed8a0d1f35337d8ecff70dc6e561e745e Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sat, 1 Apr 2023 14:32:41 +0200 Subject: [PATCH 2/3] removed unused code --- mission/payload/ScexDeviceHandler.cpp | 31 --------------------------- mission/payload/ScexDeviceHandler.h | 4 +--- 2 files changed, 1 insertion(+), 34 deletions(-) diff --git a/mission/payload/ScexDeviceHandler.cpp b/mission/payload/ScexDeviceHandler.cpp index aef6742a..d0de7919 100644 --- a/mission/payload/ScexDeviceHandler.cpp +++ b/mission/payload/ScexDeviceHandler.cpp @@ -314,35 +314,6 @@ ReturnValue_t ScexDeviceHandler::initializeLocalDataPool(localpool::DataPool& lo return OK; } -std::string ScexDeviceHandler::date_time_string() { - using namespace std; - string date_time; - Clock::TimeOfDay_t tod; - Clock::getDateAndTime(&tod); - ostringstream oss(std::ostringstream::ate); - - if (tod.hour < 10) { - oss << tod.year << tod.month << tod.day << "T0" << tod.hour; - } else { - oss << tod.year << tod.month << tod.day << "T" << tod.hour; - } - if (tod.minute < 10) { - oss << 0 << tod.minute; - - } else { - oss << tod.minute; - } - if (tod.second < 10) { - oss << 0 << tod.second; - } else { - oss << tod.second; - } - - date_time = oss.str(); - - return date_time; -} - ReturnValue_t ScexDeviceHandler::generateNewScexFile(const char* cmdName) { char timeString[64]{}; auto activeSd = sdcMan.getActiveSdCard(); @@ -378,8 +349,6 @@ ReturnValue_t ScexDeviceHandler::generateNewScexFile(const char* cmdName) { return OK; } -void ScexDeviceHandler::modeChanged() {} - void ScexDeviceHandler::setPowerSwitcher(PowerSwitchIF& powerSwitcher, power::Switch_t switchId) { DeviceHandlerBase::setPowerSwitcher(&powerSwitcher); this->switchId = switchId; diff --git a/mission/payload/ScexDeviceHandler.h b/mission/payload/ScexDeviceHandler.h index 9d7bd7f8..e7721ef6 100644 --- a/mission/payload/ScexDeviceHandler.h +++ b/mission/payload/ScexDeviceHandler.h @@ -43,8 +43,6 @@ class ScexDeviceHandler : public DeviceHandlerBase { SdCardMountedIF &sdcMan; Countdown finishCountdown = Countdown(LONG_CD); - std::string date_time_string(); - // DeviceHandlerBase private function implementation void doStartUp() override; void doShutDown() override; @@ -67,8 +65,8 @@ class ScexDeviceHandler : public DeviceHandlerBase { ReturnValue_t initializeLocalDataPool(localpool::DataPool &localDataPoolMap, LocalDataPoolManager &poolManager) override; ReturnValue_t initializeAfterTaskCreation() override; + ReturnValue_t generateNewScexFile(const char *cmdName); - void modeChanged() override; }; #endif /* MISSION_PAYLOAD_SCEXDEVICEHANDLER_H_ */ -- 2.43.0 From b58fc9087966b8c8aa341014cc85007e0146caa2 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sat, 1 Apr 2023 14:40:34 +0200 Subject: [PATCH 3/3] important correction --- mission/payload/ScexDeviceHandler.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mission/payload/ScexDeviceHandler.cpp b/mission/payload/ScexDeviceHandler.cpp index d0de7919..c4ecc9eb 100644 --- a/mission/payload/ScexDeviceHandler.cpp +++ b/mission/payload/ScexDeviceHandler.cpp @@ -28,6 +28,7 @@ void ScexDeviceHandler::doStartUp() { setMode(MODE_ON); } void ScexDeviceHandler::doShutDown() { reader.reset(); commandActive = false; + fileNameSet = false; multiFileFinishOutstanding = false; setMode(_MODE_POWER_DOWN); } @@ -208,7 +209,11 @@ ReturnValue_t ScexDeviceHandler::interpretDeviceReply(DeviceCommandId_t id, cons ReturnValue_t status = OK; auto multiFileHandler = [&](const char* cmdName) { if ((helper.getPacketCounter() == 1) or (not fileNameSet)) { - return generateNewScexFile(cmdName); + status = generateNewScexFile(cmdName); + if(status != returnvalue::OK) { + return status; + } + fileNameSet = true; } else { ofstream out(fileName, ofstream::binary | ofstream::app); // append -- 2.43.0