Merge pull request 'Update for memory management' (#159) from mueller/sdcman-mg into develop
Some checks failed
EIVE/eive-obsw/pipeline/head There was a failure building this commit
Some checks failed
EIVE/eive-obsw/pipeline/head There was a failure building this commit
Reviewed-on: #159 Reviewed-by: Jakob.Meier <meierj@irs.uni-stuttgart.de>
This commit is contained in:
commit
b6de685ea2
@ -1,5 +1,6 @@
|
||||
#include "SdCardManager.h"
|
||||
|
||||
#include <fsfw/ipc/MutexGuard.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <cstring>
|
||||
@ -15,7 +16,9 @@
|
||||
|
||||
SdCardManager* SdCardManager::factoryInstance = nullptr;
|
||||
|
||||
SdCardManager::SdCardManager() : SystemObject(objects::SDC_MANAGER), cmdExecutor(256) {}
|
||||
SdCardManager::SdCardManager() : SystemObject(objects::SDC_MANAGER), cmdExecutor(256) {
|
||||
mutex = MutexFactory::instance()->createMutex();
|
||||
}
|
||||
|
||||
SdCardManager::~SdCardManager() {}
|
||||
|
||||
@ -162,6 +165,7 @@ ReturnValue_t SdCardManager::setSdCardState(sd::SdCard sdCard, bool on) {
|
||||
|
||||
ReturnValue_t SdCardManager::getSdCardActiveStatus(SdStatePair& active) {
|
||||
using namespace std;
|
||||
MutexGuard mg(mutex);
|
||||
if (not filesystem::exists(SD_STATE_FILE)) {
|
||||
return STATUS_FILE_NEXISTS;
|
||||
}
|
||||
@ -366,6 +370,7 @@ ReturnValue_t SdCardManager::updateSdCardStateFile() {
|
||||
if (cmdExecutor.getCurrentState() == CommandExecutor::States::PENDING) {
|
||||
return CommandExecutor::COMMAND_PENDING;
|
||||
}
|
||||
MutexGuard mg(mutex);
|
||||
// Use q7hw utility and pipe the command output into the state file
|
||||
std::string updateCmd = "q7hw sd info all > " + std::string(SD_STATE_FILE);
|
||||
cmdExecutor.load(updateCmd, blocking, printCmdOutput);
|
||||
@ -440,6 +445,7 @@ void SdCardManager::setPrintCommandOutput(bool print) { this->printCmdOutput = p
|
||||
bool SdCardManager::isSdCardMounted(sd::SdCard sdCard) {
|
||||
SdCardManager::SdStatePair active;
|
||||
ReturnValue_t result = this->getSdCardActiveStatus(active);
|
||||
|
||||
if (result != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::debug << "SdCardManager::isSdCardMounted: Failed to get SD card active state";
|
||||
return false;
|
||||
|
@ -10,11 +10,12 @@
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#include "definitions.h"
|
||||
#include "events/subsystemIdRanges.h"
|
||||
#include "fsfw/events/Event.h"
|
||||
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
|
||||
#include "fsfw_hal/linux/CommandExecutor.h"
|
||||
#include "mission/memory/SdCardMountedIF.h"
|
||||
#include "mission/memory/definitions.h"
|
||||
#include "returnvalues/classIds.h"
|
||||
|
||||
class MutexIF;
|
||||
@ -23,10 +24,12 @@ class MutexIF;
|
||||
* @brief Manages handling of SD cards like switching them on or off or getting the current
|
||||
* state
|
||||
*/
|
||||
class SdCardManager : public SystemObject {
|
||||
class SdCardManager : public SystemObject, public SdCardMountedIF {
|
||||
friend class SdCardAccess;
|
||||
|
||||
public:
|
||||
using mountInitCb = ReturnValue_t (*)(void* args);
|
||||
|
||||
enum class Operations { SWITCHING_ON, SWITCHING_OFF, MOUNTING, UNMOUNTING, IDLE };
|
||||
|
||||
enum class OpStatus { IDLE, TIMEOUT, ONGOING, SUCCESS, FAIL };
|
||||
@ -88,7 +91,7 @@ class SdCardManager : public SystemObject {
|
||||
* @param sdCard
|
||||
* @return
|
||||
*/
|
||||
ReturnValue_t getPreferredSdCard(sd::SdCard& sdCard) const;
|
||||
ReturnValue_t getPreferredSdCard(sd::SdCard& sdCard) const override;
|
||||
|
||||
/**
|
||||
* Switch on the specified SD card.
|
||||
@ -170,7 +173,7 @@ class SdCardManager : public SystemObject {
|
||||
* @param prefSdCardPtr
|
||||
* @return
|
||||
*/
|
||||
std::string getCurrentMountPrefix(sd::SdCard prefSdCardPtr = sd::SdCard::NONE);
|
||||
std::string getCurrentMountPrefix(sd::SdCard prefSdCardPtr = sd::SdCard::NONE) override;
|
||||
|
||||
OpStatus checkCurrentOp(Operations& currentOp);
|
||||
|
||||
@ -183,19 +186,20 @@ class SdCardManager : public SystemObject {
|
||||
void setPrintCommandOutput(bool print);
|
||||
|
||||
/**
|
||||
* @brief Checks if an SD card is mounted
|
||||
* @brief Checks if an SD card is mounted.
|
||||
*
|
||||
* @param sdCard The SD card to check
|
||||
*
|
||||
* @return true if mounted, otherwise false
|
||||
*/
|
||||
bool isSdCardMounted(sd::SdCard sdCard);
|
||||
bool isSdCardMounted(sd::SdCard sdCard) override;
|
||||
|
||||
private:
|
||||
CommandExecutor cmdExecutor;
|
||||
Operations currentOp = Operations::IDLE;
|
||||
bool blocking = false;
|
||||
bool printCmdOutput = true;
|
||||
MutexIF* mutex = nullptr;
|
||||
|
||||
SdCardManager();
|
||||
|
||||
|
18
mission/memory/SdCardMountedIF.h
Normal file
18
mission/memory/SdCardMountedIF.h
Normal file
@ -0,0 +1,18 @@
|
||||
#ifndef MISSION_MEMORY_SDCARDMOUNTERIF_H_
|
||||
#define MISSION_MEMORY_SDCARDMOUNTERIF_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "definitions.h"
|
||||
|
||||
class SdCardMountedIF {
|
||||
public:
|
||||
virtual ~SdCardMountedIF(){};
|
||||
virtual std::string getCurrentMountPrefix(sd::SdCard prefSdCardPtr = sd::SdCard::NONE) = 0;
|
||||
virtual bool isSdCardMounted(sd::SdCard sdCard) = 0;
|
||||
virtual ReturnValue_t getPreferredSdCard(sd::SdCard& sdCard) const = 0;
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
#endif /* MISSION_MEMORY_SDCARDMOUNTERIF_H_ */
|
Loading…
Reference in New Issue
Block a user