this should work as well

This commit is contained in:
Robin Müller 2022-10-25 11:22:31 +02:00
parent a9096a46c0
commit f198a401f2
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
4 changed files with 25 additions and 6 deletions

View File

@ -459,7 +459,7 @@ void SdCardManager::setBlocking(bool blocking) { this->blocking = blocking; }
void SdCardManager::setPrintCommandOutput(bool print) { this->printCmdOutput = print; } void SdCardManager::setPrintCommandOutput(bool print) { this->printCmdOutput = print; }
bool SdCardManager::isSdCardUsable(sd::SdCard sdCard) { bool SdCardManager::isSdCardUsable(std::optional<sd::SdCard> sdCard) {
{ {
MutexGuard mg(mutex); MutexGuard mg(mutex);
if (markedUnusable) { if (markedUnusable) {
@ -474,20 +474,27 @@ bool SdCardManager::isSdCardUsable(sd::SdCard sdCard) {
sif::debug << "SdCardManager::isSdCardMounted: Failed to get SD card active state"; sif::debug << "SdCardManager::isSdCardMounted: Failed to get SD card active state";
return false; return false;
} }
if (not sdCard) {
sdCard == sd::BOTH;
}
if (sdCard == sd::SLOT_0) { if (sdCard == sd::SLOT_0) {
if (active.first == sd::MOUNTED) { if (active.first == sd::MOUNTED) {
return true; return true;
} else { } else {
return false; return false;
} }
} else if (sdCard == sd::SLOT_1) { }
if (sdCard == sd::SLOT_1) {
if (active.second == sd::MOUNTED) { if (active.second == sd::MOUNTED) {
return true; return true;
} else { } else {
return false; 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; return false;
} }
@ -567,6 +574,9 @@ void SdCardManager::setActiveSdCard(sd::SdCard sdCard) {
std::optional<sd::SdCard> SdCardManager::getActiveSdCard() const { std::optional<sd::SdCard> SdCardManager::getActiveSdCard() const {
MutexGuard mg(mutex); MutexGuard mg(mutex);
if(markedUnusable) {
return std::nullopt;
}
return sdInfo.active; return sdInfo.active;
} }

View File

@ -206,7 +206,7 @@ class SdCardManager : public SystemObject, public SdCardMountedIF {
* *
* @return true if mounted, otherwise false * @return true if mounted, otherwise false
*/ */
bool isSdCardUsable(sd::SdCard sdCard) override; bool isSdCardUsable(std::optional<sd::SdCard> sdCard) override;
ReturnValue_t isSdCardMountedReadOnly(sd::SdCard sdcard, bool& readOnly); ReturnValue_t isSdCardMountedReadOnly(sd::SdCard sdcard, bool& readOnly);

View File

@ -1,5 +1,6 @@
#include "ScexDeviceHandler.h" #include "ScexDeviceHandler.h"
#include <fsfw/filesystem/HasFileSystemIF.h>
#include <linux/devices/ScexHelper.h> #include <linux/devices/ScexHelper.h>
#include <mission/memory/SdCardMountedIF.h> #include <mission/memory/SdCardMountedIF.h>
@ -200,6 +201,10 @@ ReturnValue_t ScexDeviceHandler::interpretDeviceReply(DeviceCommandId_t id, cons
ReturnValue_t status = OK; ReturnValue_t status = OK;
auto oneFileHandler = [&](std::string cmdName) { auto oneFileHandler = [&](std::string cmdName) {
auto activeSd = sdcMan.getActiveSdCard();
if (not activeSd) {
return HasFileSystemIF::GENERIC_FILE_ERROR;
}
fileId = date_time_string(); fileId = date_time_string();
std::ostringstream oss; std::ostringstream oss;
auto prefix = sdcMan.getCurrentMountPrefix(); auto prefix = sdcMan.getCurrentMountPrefix();
@ -216,6 +221,10 @@ ReturnValue_t ScexDeviceHandler::interpretDeviceReply(DeviceCommandId_t id, cons
}; };
auto multiFileHandler = [&](std::string cmdName) { auto multiFileHandler = [&](std::string cmdName) {
if ((helper.getPacketCounter() == 1) or (not fileNameSet)) { if ((helper.getPacketCounter() == 1) or (not fileNameSet)) {
auto activeSd = sdcMan.getActiveSdCard();
if (not activeSd) {
return HasFileSystemIF::GENERIC_FILE_ERROR;
}
fileId = date_time_string(); fileId = date_time_string();
std::ostringstream oss; std::ostringstream oss;
auto prefix = sdcMan.getCurrentMountPrefix(); auto prefix = sdcMan.getCurrentMountPrefix();

View File

@ -10,7 +10,7 @@ class SdCardMountedIF {
public: public:
virtual ~SdCardMountedIF(){}; virtual ~SdCardMountedIF(){};
virtual const std::string& getCurrentMountPrefix() const = 0; virtual const std::string& getCurrentMountPrefix() const = 0;
virtual bool isSdCardUsable(sd::SdCard sdCard) = 0; virtual bool isSdCardUsable(std::optional<sd::SdCard> sdCard) = 0;
virtual std::optional<sd::SdCard> getPreferredSdCard() const = 0; virtual std::optional<sd::SdCard> getPreferredSdCard() const = 0;
virtual void setActiveSdCard(sd::SdCard sdCard) = 0; virtual void setActiveSdCard(sd::SdCard sdCard) = 0;
virtual std::optional<sd::SdCard> getActiveSdCard() const = 0; virtual std::optional<sd::SdCard> getActiveSdCard() const = 0;