updated core controller

This commit is contained in:
Robin Müller 2021-07-08 12:07:39 +02:00 committed by Robin Mueller
parent e5c3e2da53
commit 1312fe2369
4 changed files with 51 additions and 9 deletions

View File

@ -1,4 +1,5 @@
#include "CoreController.h" #include "CoreController.h"
#include "../memory/SdCardManager.h"
CoreController::CoreController(object_id_t objectId): CoreController::CoreController(object_id_t objectId):
ExtendedControllerBase(objectId, objects::NO_OBJECT, 5) { ExtendedControllerBase(objectId, objects::NO_OBJECT, 5) {
@ -20,6 +21,23 @@ LocalPoolDataSetBase* CoreController::getDataSetHandle(sid_t sid) {
return nullptr; return nullptr;
} }
ReturnValue_t CoreController::initialize() {
// Find a way to store this non-volatile outside of SD cards (ProASIC?)
sd::SdCard preferredSdCard = sd::SdCard::SLOT_0;
// Creator or update status file
ReturnValue_t result = SdCardManager::instance()->updateSdCardStateFile();
if(result != HasReturnvaluesIF::RETURN_OK) {
sif::warning << "CoreController::initialize: Updating SD card state file failed"
<< std::endl;
}
result = SdCardManager::instance()->switchOnSdCard(preferredSdCard);
if(result != HasReturnvaluesIF::RETURN_OK) {
sif::warning << "CoreController::initialize: Turning SD card on failed"
<< std::endl;
}
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t CoreController::checkModeCommand(Mode_t mode, Submode_t submode, ReturnValue_t CoreController::checkModeCommand(Mode_t mode, Submode_t submode,
uint32_t *msToReachTheMode) { uint32_t *msToReachTheMode) {
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;

View File

@ -7,6 +7,8 @@ class CoreController: public ExtendedControllerBase {
public: public:
CoreController(object_id_t objectId); CoreController(object_id_t objectId);
ReturnValue_t initialize() override;
ReturnValue_t handleCommandMessage(CommandMessage *message) override; ReturnValue_t handleCommandMessage(CommandMessage *message) override;
void performControlOperation() override; void performControlOperation() override;
private: private:

View File

@ -25,17 +25,28 @@ SdCardManager* SdCardManager::instance() {
} }
ReturnValue_t SdCardManager::switchOnSdCard(sd::SdCard sdCard) { ReturnValue_t SdCardManager::switchOnSdCard(sd::SdCard sdCard) {
// if(sdCardActive(sdCard)) { std::pair<bool, bool> active;
// return ALREADY_ON; ReturnValue_t result = sdCardActive(active);
// } if(result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
if((sdCard == sd::SdCard::SLOT_0 and active.first) or
(sdCard == sd::SdCard::SLOT_1 and active.second)) {
return ALREADY_ON;
}
return setSdCardState(sdCard, true); return setSdCardState(sdCard, true);
} }
ReturnValue_t SdCardManager::switchOffSdCard(sd::SdCard sdCard) { ReturnValue_t SdCardManager::switchOffSdCard(sd::SdCard sdCard) {
// if(not sdCardActive(sdCard)) { std::pair<bool, bool> active;
// return ALREADY_OFF; ReturnValue_t result = sdCardActive(active);
// } if(result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
if((sdCard == sd::SdCard::SLOT_0 and not active.first) or
(sdCard == sd::SdCard::SLOT_1 and not active.second)) {
return ALREADY_OFF;
}
return setSdCardState(sdCard, false); return setSdCardState(sdCard, false);
} }
@ -62,7 +73,7 @@ ReturnValue_t SdCardManager::setSdCardState(sd::SdCard sdCard, bool on) {
} }
sif::warning << "SdCardManager::setSdCardState: system call failed with code " << sif::warning << "SdCardManager::setSdCardState: system call failed with code " <<
result << std::endl; result << std::endl;
return HasReturnvaluesIF::RETURN_FAILED; return SYSTEM_CALL_ERROR;
} }
ReturnValue_t SdCardManager::sdCardActive(std::pair<bool, bool>& active) { ReturnValue_t SdCardManager::sdCardActive(std::pair<bool, bool>& active) {
@ -78,7 +89,6 @@ ReturnValue_t SdCardManager::sdCardActive(std::pair<bool, bool>& active) {
} }
string line; string line;
uint8_t idx = 0; uint8_t idx = 0;
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
bool on = false; bool on = false;
while (std::getline(sdStatus, line)) { while (std::getline(sdStatus, line)) {

View File

@ -42,8 +42,20 @@ public:
sd::SdCard getPreferredSdCard() const; sd::SdCard getPreferredSdCard() const;
/**
* Switch on the specified SD card
* @param sdCard
* @return - RETURN_OK on success, ALREADY_ON if it is already on,
* SYSTEM_CALL_ERROR on system error
*/
ReturnValue_t switchOnSdCard(sd::SdCard sdCard); ReturnValue_t switchOnSdCard(sd::SdCard sdCard);
/**
* Switch off the specified SD card
* @param sdCard
* @return - RETURN_OK on success, ALREADY_ON if it is already on,
* SYSTEM_CALL_ERROR on system error
*/
ReturnValue_t switchOffSdCard(sd::SdCard sdCard); ReturnValue_t switchOffSdCard(sd::SdCard sdCard);
/** /**