Udated for memory management
Some checks failed
EIVE/eive-obsw/pipeline/head There was a failure building this commit
EIVE/eive-obsw/pipeline/pr-develop There was a failure building this commit

This commit is contained in:
Robin Müller 2022-03-01 17:41:58 +01:00
parent 81915f1772
commit 711732ccd6
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
5 changed files with 36 additions and 8 deletions

View File

@ -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;

View File

@ -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();

View 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_ */

2
tmtc

@ -1 +1 @@
Subproject commit 56d414d9fc0d6b05f967c47a0bd124fc06de2ad3
Subproject commit 2c96b9ed4c3392e83251809190b2049ff685f5cc