diff --git a/bsp_q7s/fs/SdCardManager.cpp b/bsp_q7s/fs/SdCardManager.cpp index 4a6c12a1..8cea0991 100644 --- a/bsp_q7s/fs/SdCardManager.cpp +++ b/bsp_q7s/fs/SdCardManager.cpp @@ -459,7 +459,7 @@ void SdCardManager::setBlocking(bool blocking) { this->blocking = blocking; } void SdCardManager::setPrintCommandOutput(bool print) { this->printCmdOutput = print; } -bool SdCardManager::isSdCardUsable(sd::SdCard sdCard) { +bool SdCardManager::isSdCardUsable(std::optional sdCard) { { MutexGuard mg(mutex); if (markedUnusable) { @@ -474,20 +474,27 @@ bool SdCardManager::isSdCardUsable(sd::SdCard sdCard) { sif::debug << "SdCardManager::isSdCardMounted: Failed to get SD card active state"; return false; } + if (not sdCard) { + sdCard == sd::BOTH; + } if (sdCard == sd::SLOT_0) { if (active.first == sd::MOUNTED) { return true; } else { return false; } - } else if (sdCard == sd::SLOT_1) { + } + if (sdCard == sd::SLOT_1) { if (active.second == sd::MOUNTED) { return true; } else { return false; } - } else { - sif::debug << "SdCardManager::isSdCardMounted: Unknown SD card specified" << std::endl; + } + if (sdCard == sd::BOTH) { + if (active.first == sd::MOUNTED && active.second == sd::MOUNTED) { + return true; + } } return false; } @@ -567,6 +574,9 @@ void SdCardManager::setActiveSdCard(sd::SdCard sdCard) { std::optional SdCardManager::getActiveSdCard() const { MutexGuard mg(mutex); + if(markedUnusable) { + return std::nullopt; + } return sdInfo.active; } diff --git a/bsp_q7s/fs/SdCardManager.h b/bsp_q7s/fs/SdCardManager.h index 8ce13dbc..749cae62 100644 --- a/bsp_q7s/fs/SdCardManager.h +++ b/bsp_q7s/fs/SdCardManager.h @@ -206,7 +206,7 @@ class SdCardManager : public SystemObject, public SdCardMountedIF { * * @return true if mounted, otherwise false */ - bool isSdCardUsable(sd::SdCard sdCard) override; + bool isSdCardUsable(std::optional sdCard) override; ReturnValue_t isSdCardMountedReadOnly(sd::SdCard sdcard, bool& readOnly); diff --git a/mission/devices/ScexDeviceHandler.cpp b/mission/devices/ScexDeviceHandler.cpp index 1cc2cd39..db562f66 100644 --- a/mission/devices/ScexDeviceHandler.cpp +++ b/mission/devices/ScexDeviceHandler.cpp @@ -1,5 +1,6 @@ #include "ScexDeviceHandler.h" +#include #include #include @@ -200,6 +201,10 @@ ReturnValue_t ScexDeviceHandler::interpretDeviceReply(DeviceCommandId_t id, cons ReturnValue_t status = OK; auto oneFileHandler = [&](std::string cmdName) { + auto activeSd = sdcMan.getActiveSdCard(); + if (not activeSd) { + return HasFileSystemIF::GENERIC_FILE_ERROR; + } fileId = date_time_string(); std::ostringstream oss; auto prefix = sdcMan.getCurrentMountPrefix(); @@ -216,6 +221,10 @@ ReturnValue_t ScexDeviceHandler::interpretDeviceReply(DeviceCommandId_t id, cons }; auto multiFileHandler = [&](std::string cmdName) { if ((helper.getPacketCounter() == 1) or (not fileNameSet)) { + auto activeSd = sdcMan.getActiveSdCard(); + if (not activeSd) { + return HasFileSystemIF::GENERIC_FILE_ERROR; + } fileId = date_time_string(); std::ostringstream oss; auto prefix = sdcMan.getCurrentMountPrefix(); diff --git a/mission/memory/SdCardMountedIF.h b/mission/memory/SdCardMountedIF.h index d88bb57a..ac705e8d 100644 --- a/mission/memory/SdCardMountedIF.h +++ b/mission/memory/SdCardMountedIF.h @@ -10,7 +10,7 @@ class SdCardMountedIF { public: virtual ~SdCardMountedIF(){}; virtual const std::string& getCurrentMountPrefix() const = 0; - virtual bool isSdCardUsable(sd::SdCard sdCard) = 0; + virtual bool isSdCardUsable(std::optional sdCard) = 0; virtual std::optional getPreferredSdCard() const = 0; virtual void setActiveSdCard(sd::SdCard sdCard) = 0; virtual std::optional getActiveSdCard() const = 0;