2021-07-07 20:50:11 +02:00
|
|
|
#ifndef BSP_Q7S_MEMORY_SDCARDACCESSMANAGER_H_
|
|
|
|
#define BSP_Q7S_MEMORY_SDCARDACCESSMANAGER_H_
|
|
|
|
|
|
|
|
#include "definitions.h"
|
|
|
|
#include "returnvalues/classIds.h"
|
|
|
|
|
|
|
|
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
|
|
|
|
|
|
|
|
#include <cstdint>
|
2021-07-08 11:23:08 +02:00
|
|
|
#include <utility>
|
2021-07-12 11:37:10 +02:00
|
|
|
#include <string>
|
2021-07-07 20:50:11 +02:00
|
|
|
|
|
|
|
class MutexIF;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Manages handling of SD cards like switching them on or off or getting the current
|
|
|
|
* state
|
|
|
|
*/
|
|
|
|
class SdCardManager {
|
|
|
|
friend class SdCardAccess;
|
|
|
|
public:
|
|
|
|
static constexpr uint8_t INTERFACE_ID = CLASS_ID::SD_CARD_MANAGER;
|
|
|
|
|
|
|
|
static constexpr ReturnValue_t ALREADY_ON = HasReturnvaluesIF::makeReturnCode(INTERFACE_ID, 0);
|
|
|
|
static constexpr ReturnValue_t ALREADY_OFF = HasReturnvaluesIF::makeReturnCode(INTERFACE_ID, 1);
|
2021-07-08 11:23:08 +02:00
|
|
|
static constexpr ReturnValue_t STATUS_FILE_NEXISTS =
|
|
|
|
HasReturnvaluesIF::makeReturnCode(INTERFACE_ID, 2);
|
|
|
|
static constexpr ReturnValue_t STATUS_FILE_FORMAT_INVALID =
|
|
|
|
HasReturnvaluesIF::makeReturnCode(INTERFACE_ID, 3);
|
2021-07-12 11:37:10 +02:00
|
|
|
static constexpr ReturnValue_t MOUNT_ERROR = HasReturnvaluesIF::makeReturnCode(INTERFACE_ID, 4);
|
|
|
|
static constexpr ReturnValue_t UNMOUNT_ERROR =
|
|
|
|
HasReturnvaluesIF::makeReturnCode(INTERFACE_ID, 5);
|
2021-07-08 11:23:08 +02:00
|
|
|
static constexpr ReturnValue_t SYSTEM_CALL_ERROR =
|
2021-07-12 11:37:10 +02:00
|
|
|
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";
|
2021-07-07 20:50:11 +02:00
|
|
|
|
|
|
|
virtual ~SdCardManager();
|
|
|
|
|
|
|
|
static void create();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the single instance of the SD card manager.
|
|
|
|
*/
|
|
|
|
static SdCardManager* instance();
|
|
|
|
|
|
|
|
void setPreferredSdCard(sd::SdCard sdCard);
|
|
|
|
|
|
|
|
sd::SdCard getPreferredSdCard() const;
|
|
|
|
|
2021-07-08 12:07:39 +02:00
|
|
|
/**
|
|
|
|
* Switch on the specified SD card
|
|
|
|
* @param sdCard
|
2021-07-12 11:37:10 +02:00
|
|
|
* @param doMountSdCard Mount the SD card after switching it on, which is necessary
|
|
|
|
* to use it
|
2021-07-08 12:07:39 +02:00
|
|
|
* @return - RETURN_OK on success, ALREADY_ON if it is already on,
|
|
|
|
* SYSTEM_CALL_ERROR on system error
|
|
|
|
*/
|
2021-07-12 11:37:10 +02:00
|
|
|
ReturnValue_t switchOnSdCard(sd::SdCard sdCard, bool doMountSdCard = true);
|
2021-07-07 20:50:11 +02:00
|
|
|
|
2021-07-08 12:07:39 +02:00
|
|
|
/**
|
|
|
|
* Switch off the specified SD card
|
|
|
|
* @param sdCard
|
2021-07-12 11:37:10 +02:00
|
|
|
* @param doUnmountSdCard Unmount the SD card before switching the card off, which makes
|
|
|
|
* the operation safer
|
2021-07-08 12:07:39 +02:00
|
|
|
* @return - RETURN_OK on success, ALREADY_ON if it is already on,
|
|
|
|
* SYSTEM_CALL_ERROR on system error
|
|
|
|
*/
|
2021-07-12 11:37:10 +02:00
|
|
|
ReturnValue_t switchOffSdCard(sd::SdCard sdCard, bool doUnmountSdCard = true);
|
2021-07-07 20:50:11 +02:00
|
|
|
|
2021-07-08 11:23:08 +02:00
|
|
|
/**
|
|
|
|
* Updated the state file or creates one if it does not exist. You need to call this
|
|
|
|
* function before calling #sdCardActiv
|
|
|
|
* @return - RETURN_OK if the state file was updated successfully
|
|
|
|
* - SYSTEM_CALL_ERROR if the call to create the status file failed
|
|
|
|
*/
|
|
|
|
ReturnValue_t updateSdCardStateFile();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the state of the SD cards. If the state file does not exist, this function will
|
|
|
|
* take care of updating it. If it does not, the function will use the state file to get
|
|
|
|
* the status of the SD cards and set the field of the provided boolean pair.
|
|
|
|
* @param active Pair of booleans, where the first entry is the state of the first SD card
|
|
|
|
* and the second one the state of the second SD card
|
|
|
|
* @return - RETURN_OK if the state was read successfully
|
|
|
|
* - STATUS_FILE_FORMAT_INVALID if there was an issue with the state file. The user
|
|
|
|
* should call #updateSdCardStateFile again in that case
|
|
|
|
* - STATUS_FILE_NEXISTS if the status file does not exist
|
|
|
|
*/
|
2021-07-12 11:37:10 +02:00
|
|
|
ReturnValue_t sdCardActive(std::pair<sd::SdStatus, sd::SdStatus>& active);
|
|
|
|
|
|
|
|
ReturnValue_t mountSdCard(sd::SdCard sdCard);
|
|
|
|
ReturnValue_t unmountSdCard(sd::SdCard sdCard);
|
2021-07-07 20:50:11 +02:00
|
|
|
|
|
|
|
sd::SdCard getPreferedSdCard() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
SdCardManager();
|
|
|
|
|
2021-07-08 11:23:08 +02:00
|
|
|
ReturnValue_t setSdCardState(sd::SdCard sdCard, bool on);
|
2021-07-07 20:50:11 +02:00
|
|
|
|
|
|
|
sd::SdCard preferredSdCard = sd::SdCard::SLOT_0;
|
|
|
|
|
2021-07-12 11:37:10 +02:00
|
|
|
void processSdStatusLine(std::pair<sd::SdStatus, sd::SdStatus>& active,
|
|
|
|
std::string& line, uint8_t& idx, sd::SdCard& currentSd);
|
|
|
|
|
2021-07-07 20:50:11 +02:00
|
|
|
static SdCardManager* factoryInstance;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* BSP_Q7S_MEMORY_SDCARDACCESSMANAGER_H_ */
|