SDC manager non-blocking mode
All checks were successful
EIVE/eive-obsw/pipeline/head This commit looks good

This commit is contained in:
2021-08-05 10:14:17 +02:00
parent 3a88a43505
commit 1cfb9250fa
5 changed files with 180 additions and 30 deletions

View File

@ -8,10 +8,13 @@
#include "fsfw/events/Event.h"
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
#include <poll.h>
#include <cstdint>
#include <utility>
#include <string>
#include <optional>
#include <array>
class MutexIF;
@ -22,16 +25,33 @@ class MutexIF;
class SdCardManager {
friend class SdCardAccess;
public:
enum class Operations {
SWITCHING_ON,
SWITCHING_OFF,
MOUNTING,
IDLE
};
enum class OpStatus {
IDLE,
SUCCESS,
TIMEOUT,
ONGOING,
FAIL
};
using SdStatusPair = std::pair<sd::SdStatus, sd::SdStatus>;
static constexpr uint8_t INTERFACE_ID = CLASS_ID::SD_CARD_MANAGER;
static constexpr ReturnValue_t ALREADY_ON =
static constexpr ReturnValue_t OP_ONGOING =
HasReturnvaluesIF::makeReturnCode(INTERFACE_ID, 0);
static constexpr ReturnValue_t ALREADY_MOUNTED =
static constexpr ReturnValue_t ALREADY_ON =
HasReturnvaluesIF::makeReturnCode(INTERFACE_ID, 1);
static constexpr ReturnValue_t ALREADY_OFF =
static constexpr ReturnValue_t ALREADY_MOUNTED =
HasReturnvaluesIF::makeReturnCode(INTERFACE_ID, 2);
static constexpr ReturnValue_t ALREADY_OFF =
HasReturnvaluesIF::makeReturnCode(INTERFACE_ID, 3);
static constexpr ReturnValue_t STATUS_FILE_NEXISTS =
HasReturnvaluesIF::makeReturnCode(INTERFACE_ID, 10);
static constexpr ReturnValue_t STATUS_FILE_FORMAT_INVALID =
@ -42,6 +62,8 @@ public:
HasReturnvaluesIF::makeReturnCode(INTERFACE_ID, 13);
static constexpr ReturnValue_t SYSTEM_CALL_ERROR =
HasReturnvaluesIF::makeReturnCode(INTERFACE_ID, 14);
static constexpr ReturnValue_t POPEN_CALL_ERROR =
HasReturnvaluesIF::makeReturnCode(INTERFACE_ID, 15);
static constexpr uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::FILE_SYSTEM;
@ -159,7 +181,26 @@ public:
* @return
*/
std::string getCurrentMountPrefix(sd::SdCard prefSdCardPtr = sd::SdCard::NONE);
OpStatus checkCurrentOp(Operations& currentOp);
/**
* If there are issues with the state machine, it can be reset with this function
*/
void resetState();
void setBlocking(bool blocking);
private:
Operations currentOp = Operations::IDLE;
OpStatus currentOpStatus = OpStatus::IDLE;
sd::SdCard currentOpSdCard = sd::SdCard::NONE;
FILE* opFile = nullptr;
bool blocking = true;
struct pollfd waiter {};
std::array<char, 256> readBuf {};
std::string currentCmd;
int opFileNum = 0;
SdCardManager();
ReturnValue_t setSdCardState(sd::SdCard sdCard, bool on);
@ -169,6 +210,9 @@ private:
std::string currentPrefix;
ReturnValue_t handleCommand(std::string cmd, std::string funcName);
ReturnValue_t handleBlockingOperation(std::string funcName);
static SdCardManager* factoryInstance;
};