From f0bbc1d09026ed9532113cc909da5e9183e0a0e1 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 2 Aug 2023 09:39:42 +0200 Subject: [PATCH] added filesystem down event --- mission/payload/ScexDeviceHandler.cpp | 23 +++++++++++++++++++---- mission/payload/ScexDeviceHandler.h | 2 ++ mission/payload/scexHelpers.h | 1 + 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/mission/payload/ScexDeviceHandler.cpp b/mission/payload/ScexDeviceHandler.cpp index 40cbfbab..6281142d 100644 --- a/mission/payload/ScexDeviceHandler.cpp +++ b/mission/payload/ScexDeviceHandler.cpp @@ -19,7 +19,9 @@ using namespace returnvalue; ScexDeviceHandler::ScexDeviceHandler(object_id_t objectId, ScexUartReader& reader, CookieIF* cookie, SdCardMountedIF& sdcMan) - : DeviceHandlerBase(objectId, reader.getObjectId(), cookie), sdcMan(sdcMan), reader(reader) {} + : DeviceHandlerBase(objectId, reader.getObjectId(), cookie), sdcMan(sdcMan), reader(reader) { + fsUnusableEventCd.timeOut(); +} ScexDeviceHandler::~ScexDeviceHandler() {} @@ -218,8 +220,12 @@ ReturnValue_t ScexDeviceHandler::interpretDeviceReply(DeviceCommandId_t id, cons } fileNameSet = true; } else { - ofstream out(fileName, - ofstream::binary | ofstream::app); // append + if (!sdcMan.isSdCardUsable(std::nullopt)) { + fsUnsableEvent(); + return returnvalue::FAILED; + } + // Append to existing file. + ofstream out(fileName, ofstream::binary | ofstream::app); if (out.bad()) { sif::error << "ScexDeviceHandler::handleValidReply: Could not open file " << fileName << std::endl; @@ -330,6 +336,14 @@ void ScexDeviceHandler::filesystemChecks() { } } +void ScexDeviceHandler::fsUnsableEvent() { + if (fsUnusableEventCd.isBusy()) { + return; + } + triggerEvent(scex::FS_UNUSABLE); + fsUnusableEventCd.resetTimer(); +} + ReturnValue_t ScexDeviceHandler::generateNewScexFile(const char* cmdName) { char timeString[64]{}; auto activeSd = sdcMan.getActiveSdCard(); @@ -339,7 +353,8 @@ ReturnValue_t ScexDeviceHandler::generateNewScexFile(const char* cmdName) { std::ostringstream oss; auto prefix = sdcMan.getCurrentMountPrefix(); - if (prefix == nullptr) { + if (prefix == nullptr or !sdcMan.isSdCardUsable(std::nullopt)) { + fsUnsableEvent(); return returnvalue::FAILED; } timeval tv; diff --git a/mission/payload/ScexDeviceHandler.h b/mission/payload/ScexDeviceHandler.h index 6e1924e3..ed30668f 100644 --- a/mission/payload/ScexDeviceHandler.h +++ b/mission/payload/ScexDeviceHandler.h @@ -42,6 +42,7 @@ class ScexDeviceHandler : public DeviceHandlerBase { scex::Cmds currCmd = scex::Cmds::PING; SdCardMountedIF &sdcMan; Countdown finishCountdown = Countdown(LONG_CD); + Countdown fsUnusableEventCd = Countdown(60000); // DeviceHandlerBase private function implementation void doStartUp() override; @@ -49,6 +50,7 @@ class ScexDeviceHandler : public DeviceHandlerBase { ScexHelper helper; ScexUartReader &reader; + void fsUnsableEvent(); void performOperationHook() override; ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t *id) override; ReturnValue_t buildTransitionDeviceCommand(DeviceCommandId_t *id) override; diff --git a/mission/payload/scexHelpers.h b/mission/payload/scexHelpers.h index aa0f320b..9b9e8f14 100644 --- a/mission/payload/scexHelpers.h +++ b/mission/payload/scexHelpers.h @@ -17,6 +17,7 @@ static constexpr uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::SCEX_HANDLER; static constexpr Event MISSING_PACKET = event::makeEvent(SUBSYSTEM_ID, 0, severity::LOW); static constexpr Event EXPERIMENT_TIMEDOUT = event::makeEvent(SUBSYSTEM_ID, 1, severity::LOW); +static constexpr Event FS_UNUSABLE = event::makeEvent(SUBSYSTEM_ID, 2, severity::LOW); //! FRAM, One Cell or All cells command finished. P1: Command ID static constexpr Event MULTI_PACKET_COMMAND_DONE = event::makeEvent(SUBSYSTEM_ID, 2, severity::INFO);