continued sd card manager
This commit is contained in:
parent
834fa89e7b
commit
7600e10f1b
@ -1,5 +1,6 @@
|
|||||||
#include "SdCardManager.h"
|
#include "SdCardManager.h"
|
||||||
#include "fsfw/ipc/MutexFactory.h"
|
#include "fsfw/ipc/MutexFactory.h"
|
||||||
|
#include "fsfw/serviceinterface/ServiceInterface.h"
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
@ -35,11 +36,38 @@ ReturnValue_t SdCardManager::switchOffSdCard(sd::SdCard sdCard) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool SdCardManager::sdCardActive(sd::SdCard sdCard) {
|
bool SdCardManager::sdCardActive(sd::SdCard sdCard) {
|
||||||
if(std::filesystem::exists("/tmp/sd_status.txt")) {
|
using namespace std;
|
||||||
std::ifstream sdStatus("/tmp/sd_status.txt");
|
if(not filesystem::exists("/tmp/sd_status.txt")) {
|
||||||
return HasReturnvaluesIF::RETURN_OK;
|
ReturnValue_t result = updateSdCardStateFile();
|
||||||
|
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Now the file should exist in any case. Still check whether it exists.
|
||||||
|
fstream sdStatus("/tmp/sd_status.txt");
|
||||||
|
if (not sdStatus.good()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
string line;
|
||||||
|
uint8_t idx = 0;
|
||||||
|
while (std::getline(sdStatus, line)) {
|
||||||
|
istringstream iss(line);
|
||||||
|
string word;
|
||||||
|
if((sdCard == sd::SdCard::SLOT_0 and idx == 0) or
|
||||||
|
(sdCard == sd::SdCard::SLOT_1 and idx == 1)) {
|
||||||
|
while(iss >> word) {
|
||||||
|
if(word == "on") {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
idx++;
|
||||||
|
}
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,5 +79,12 @@ void SdCardManager::setPreferredSdCard(sd::SdCard sdCard) {
|
|||||||
preferredSdCard = sdCard;
|
preferredSdCard = sdCard;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SdCardManager::updateSdCardStateFile() {
|
ReturnValue_t SdCardManager::updateSdCardStateFile() {
|
||||||
|
int result = std::system("q7hw sd info all > /tmp/sd_status.txt");
|
||||||
|
if(result == 0) {
|
||||||
|
return HasReturnvaluesIF::RETURN_OK;
|
||||||
|
}
|
||||||
|
sif::warning << "SdCardManager::updateSdCardStateFile: system call failed with code " <<
|
||||||
|
result << std::endl;
|
||||||
|
return HasReturnvaluesIF::RETURN_FAILED;
|
||||||
}
|
}
|
||||||
|
@ -46,7 +46,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
SdCardManager();
|
SdCardManager();
|
||||||
|
|
||||||
void updateSdCardStateFile();
|
ReturnValue_t updateSdCardStateFile();
|
||||||
|
|
||||||
sd::SdCard preferredSdCard = sd::SdCard::SLOT_0;
|
sd::SdCard preferredSdCard = sd::SdCard::SLOT_0;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user