diff --git a/bsp_q7s/memory/SdCardManager.cpp b/bsp_q7s/memory/SdCardManager.cpp index 8c67ea2c..3a7afc42 100644 --- a/bsp_q7s/memory/SdCardManager.cpp +++ b/bsp_q7s/memory/SdCardManager.cpp @@ -117,12 +117,12 @@ ReturnValue_t SdCardManager::setSdCardState(sd::SdCard sdCard, bool on) { ReturnValue_t SdCardManager::sdCardActive(std::pair& active) { using namespace std; - if(not filesystem::exists("/tmp/sd_status.txt")) { + if(not filesystem::exists(SD_STATE_FILE)) { return STATUS_FILE_NEXISTS; } // Now the file should exist in any case. Still check whether it exists. - fstream sdStatus("/tmp/sd_status.txt"); + fstream sdStatus(SD_STATE_FILE); if (not sdStatus.good()) { return STATUS_FILE_NEXISTS; } @@ -261,7 +261,9 @@ void SdCardManager::setPreferredSdCard(sd::SdCard sdCard) { } ReturnValue_t SdCardManager::updateSdCardStateFile() { - int result = std::system("q7hw sd info all > /tmp/sd_status.txt"); + // Use q7hw utility and pipe the command output into the state file + std::string updateCmd = "q7hw sd info all > " + SD_STATE_FILE; + int result = std::system(updateCmd.c_str()); if(result == 0) { return HasReturnvaluesIF::RETURN_OK; } diff --git a/bsp_q7s/memory/SdCardManager.h b/bsp_q7s/memory/SdCardManager.h index 9052d9b0..810536fe 100644 --- a/bsp_q7s/memory/SdCardManager.h +++ b/bsp_q7s/memory/SdCardManager.h @@ -38,6 +38,7 @@ public: 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"; + static constexpr char SD_STATE_FILE[] = "/tmp/sd_status.txt"; virtual ~SdCardManager(); @@ -53,7 +54,7 @@ public: sd::SdCard getPreferredSdCard() const; /** - * Switch on the specified SD card + * Switch on the specified SD card. * @param sdCard * @param doMountSdCard Mount the SD card after switching it on, which is necessary * to use it @@ -63,7 +64,7 @@ public: ReturnValue_t switchOnSdCard(sd::SdCard sdCard, bool doMountSdCard = true); /** - * Switch off the specified SD card + * Switch off the specified SD card. * @param sdCard * @param doUnmountSdCard Unmount the SD card before switching the card off, which makes * the operation safer @@ -73,8 +74,8 @@ public: 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 - * function before calling #sdCardActiv + * Update the state file or creates one if it does not exist. You need to call this + * function before calling #sdCardActive * @return - RETURN_OK if the state file was updated successfully * - SYSTEM_CALL_ERROR if the call to create the status file failed */ @@ -93,7 +94,18 @@ public: */ ReturnValue_t sdCardActive(std::pair& active); + /** + * Mount the specified SD card. This is necessary to use it. + * @param sdCard + * @return + */ ReturnValue_t mountSdCard(sd::SdCard sdCard); + /** + * Unmount the specified SD card. This is recommended before switching it off. The SD card + * can't be used after it has been unmounted. + * @param sdCard + * @return + */ ReturnValue_t unmountSdCard(sd::SdCard sdCard); sd::SdCard getPreferedSdCard() const;