mounting SD cards now as well

This commit is contained in:
2021-07-12 11:37:10 +02:00
committed by Robin Mueller
parent 106c74ca43
commit 4fc56417bc
3 changed files with 184 additions and 34 deletions

View File

@ -8,6 +8,7 @@
#include <cstdint>
#include <utility>
#include <string>
class MutexIF;
@ -26,8 +27,17 @@ public:
HasReturnvaluesIF::makeReturnCode(INTERFACE_ID, 2);
static constexpr ReturnValue_t STATUS_FILE_FORMAT_INVALID =
HasReturnvaluesIF::makeReturnCode(INTERFACE_ID, 3);
static constexpr ReturnValue_t MOUNT_ERROR = HasReturnvaluesIF::makeReturnCode(INTERFACE_ID, 4);
static constexpr ReturnValue_t UNMOUNT_ERROR =
HasReturnvaluesIF::makeReturnCode(INTERFACE_ID, 5);
static constexpr ReturnValue_t SYSTEM_CALL_ERROR =
HasReturnvaluesIF::makeReturnCode(INTERFACE_ID, 4);
HasReturnvaluesIF::makeReturnCode(INTERFACE_ID, 6);
// C++17 does not support constexpr std::string yet
static constexpr char SD_0_DEV_NAME[] = "/dev/mmcblk0p1";
static constexpr char SD_1_DEV_NAME[] = "/dev/mmcblk1p1";
static constexpr char SD_0_MOUNT_POINT[] = "/mnt/sd0";
static constexpr char SD_1_MOUNT_POINT[] = "/mnt/sd1";
virtual ~SdCardManager();
@ -45,18 +55,22 @@ public:
/**
* Switch on the specified SD card
* @param sdCard
* @param doMountSdCard Mount the SD card after switching it on, which is necessary
* to use it
* @return - RETURN_OK on success, ALREADY_ON if it is already on,
* SYSTEM_CALL_ERROR on system error
*/
ReturnValue_t switchOnSdCard(sd::SdCard sdCard);
ReturnValue_t switchOnSdCard(sd::SdCard sdCard, bool doMountSdCard = true);
/**
* Switch off the specified SD card
* @param sdCard
* @param doUnmountSdCard Unmount the SD card before switching the card off, which makes
* the operation safer
* @return - RETURN_OK on success, ALREADY_ON if it is already on,
* SYSTEM_CALL_ERROR on system error
*/
ReturnValue_t switchOffSdCard(sd::SdCard sdCard);
ReturnValue_t switchOffSdCard(sd::SdCard sdCard, bool doUnmountSdCard = true);
/**
* Updated the state file or creates one if it does not exist. You need to call this
@ -77,7 +91,10 @@ public:
* should call #updateSdCardStateFile again in that case
* - STATUS_FILE_NEXISTS if the status file does not exist
*/
ReturnValue_t sdCardActive(std::pair<bool, bool>& active);
ReturnValue_t sdCardActive(std::pair<sd::SdStatus, sd::SdStatus>& active);
ReturnValue_t mountSdCard(sd::SdCard sdCard);
ReturnValue_t unmountSdCard(sd::SdCard sdCard);
sd::SdCard getPreferedSdCard() const;
@ -88,6 +105,9 @@ private:
sd::SdCard preferredSdCard = sd::SdCard::SLOT_0;
void processSdStatusLine(std::pair<sd::SdStatus, sd::SdStatus>& active,
std::string& line, uint8_t& idx, sd::SdCard& currentSd);
static SdCardManager* factoryInstance;
};