From d0e18f8b352a7294cf95384156b833d19dac9cc0 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 4 May 2022 11:11:29 +0200 Subject: [PATCH] add mutex protections for switcher states --- bsp_hosted/ObjectFactory.cpp | 2 +- bsp_q7s/boardtest/Q7STestTask.cpp | 233 +++++++++++++++--------------- bsp_q7s/boardtest/Q7STestTask.h | 1 + linux/boardtest/LibgpiodTest.cpp | 4 +- mission/devices/HeaterHandler.cpp | 49 +++++-- mission/devices/HeaterHandler.h | 26 ++-- 6 files changed, 169 insertions(+), 146 deletions(-) diff --git a/bsp_hosted/ObjectFactory.cpp b/bsp_hosted/ObjectFactory.cpp index 7ad599ea..55ebda0f 100644 --- a/bsp_hosted/ObjectFactory.cpp +++ b/bsp_hosted/ObjectFactory.cpp @@ -7,9 +7,9 @@ #include #include #include -#include "fsfw_tests/integration/task/TestTask.h" #include "OBSWConfig.h" +#include "fsfw_tests/integration/task/TestTask.h" #if OBSW_USE_TMTC_TCP_BRIDGE == 0 #include "fsfw/osal/common/UdpTcPollingTask.h" diff --git a/bsp_q7s/boardtest/Q7STestTask.cpp b/bsp_q7s/boardtest/Q7STestTask.cpp index 0f6734b6..6cf4e734 100644 --- a/bsp_q7s/boardtest/Q7STestTask.cpp +++ b/bsp_q7s/boardtest/Q7STestTask.cpp @@ -156,13 +156,13 @@ void Q7STestTask::testDummyParams() { result = param.getValue(DummyParameter::DUMMY_KEY_PARAM_1, test); if (result != HasReturnvaluesIF::RETURN_OK) { sif::warning << "Q7STestTask::testDummyParams: Key " << DummyParameter::DUMMY_KEY_PARAM_1 - << " does not exist" << std::endl; + << " does not exist" << std::endl; } std::string test2; result = param.getValue(DummyParameter::DUMMY_KEY_PARAM_2, test2); if (result != HasReturnvaluesIF::RETURN_OK) { sif::warning << "Q7STestTask::testDummyParams: Key " << DummyParameter::DUMMY_KEY_PARAM_1 - << " does not exist" << std::endl; + << " does not exist" << std::endl; } sif::info << "Test value (3 expected): " << test << std::endl; sif::info << "Test value 2 (\"blirb\" expected): " << test2 << std::endl; @@ -172,7 +172,7 @@ ReturnValue_t Q7STestTask::initialize() { coreController = ObjectManager::instance()->get(objects::CORE_CONTROLLER); if (coreController == nullptr) { sif::warning << "Q7STestTask::initialize: Could not retrieve CORE_CONTROLLER object" - << std::endl; + << std::endl; } return TestTask::initialize(); } @@ -182,14 +182,14 @@ void Q7STestTask::testProtHandler() { ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; // If any chips are unlocked, lock them here result = coreController->setBootCopyProtection(xsc::Chip::ALL_CHIP, xsc::Copy::ALL_COPY, true, - opPerformed, true); + opPerformed, true); if (result != HasReturnvaluesIF::RETURN_OK) { sif::warning << "Q7STestTask::testProtHandler: Op failed" << std::endl; } // unlock own copy result = coreController->setBootCopyProtection(xsc::Chip::SELF_CHIP, xsc::Copy::SELF_COPY, false, - opPerformed, true); + opPerformed, true); if (result != HasReturnvaluesIF::RETURN_OK) { sif::warning << "Q7STestTask::testProtHandler: Op failed" << std::endl; } @@ -203,7 +203,7 @@ void Q7STestTask::testProtHandler() { // lock own copy result = coreController->setBootCopyProtection(xsc::Chip::SELF_CHIP, xsc::Copy::SELF_COPY, true, - opPerformed, true); + opPerformed, true); if (result != HasReturnvaluesIF::RETURN_OK) { sif::warning << "Q7STestTask::testProtHandler: Op failed" << std::endl; } @@ -217,7 +217,7 @@ void Q7STestTask::testProtHandler() { // unlock specific copy result = coreController->setBootCopyProtection(xsc::Chip::CHIP_1, xsc::Copy::COPY_1, false, - opPerformed, true); + opPerformed, true); if (result != HasReturnvaluesIF::RETURN_OK) { sif::warning << "Q7STestTask::testProtHandler: Op failed" << std::endl; } @@ -231,7 +231,7 @@ void Q7STestTask::testProtHandler() { // lock specific copy result = coreController->setBootCopyProtection(xsc::Chip::CHIP_1, xsc::Copy::COPY_1, true, - opPerformed, true); + opPerformed, true); if (result != HasReturnvaluesIF::RETURN_OK) { sif::warning << "Q7STestTask::testProtHandler: Op failed" << std::endl; } @@ -273,7 +273,7 @@ void Q7STestTask::testGpsDaemonShm() { } void Q7STestTask::testGpsDaemonSocket() { - if(gpsmmShmPtr == nullptr) { + if (gpsmmShmPtr == nullptr) { gpsmmShmPtr = new gpsmm("localhost", DEFAULT_GPSD_PORT); } // The data from the device will generally be read all at once. Therefore, we @@ -283,7 +283,7 @@ void Q7STestTask::testGpsDaemonSocket() { // Opening failed #if FSFW_VERBOSE_LEVEL >= 1 sif::warning << "Q7STestTask::testGpsDaemonSocket: Opening GPSMM failed | " - << "Error " << errno << " | " << gps_errstr(errno) << std::endl; + << "Error " << errno << " | " << gps_errstr(errno) << std::endl; #endif gpsNotOpenSwitch = false; @@ -291,17 +291,16 @@ void Q7STestTask::testGpsDaemonSocket() { return; } // Stopwatch watch; - gps_data_t *gps = nullptr; + gps_data_t* gps = nullptr; gpsmmShmPtr->stream(WATCH_ENABLE | WATCH_JSON); - if(not gpsmmShmPtr->waiting(50000000)) { + if (not gpsmmShmPtr->waiting(50000000)) { return; } gps = gpsmmShmPtr->read(); if (gps == nullptr) { if (gpsReadFailedSwitch) { gpsReadFailedSwitch = false; - sif::warning << "Q7STestTask::testGpsDaemonSocket: Reading GPS data failed" - << std::endl; + sif::warning << "Q7STestTask::testGpsDaemonSocket: Reading GPS data failed" << std::endl; } return; } @@ -312,8 +311,8 @@ void Q7STestTask::testGpsDaemonSocket() { if (noModeSetCntr == 10) { // TODO: Trigger event here sif::warning << "Q7STestTask::testGpsDaemonSocket: No mode could be " - "read for 10 consecutive reads" - << std::endl; + "read for 10 consecutive reads" + << std::endl; noModeSetCntr = -1; } return; @@ -339,7 +338,7 @@ void Q7STestTask::testFileSystemHandlerDirect(FsOpCodes opCode) { auto fsHandler = ObjectManager::instance()->get(objects::FILE_SYSTEM_HANDLER); if (fsHandler == nullptr) { sif::warning << "Q7STestTask::testFileSystemHandlerDirect: No FS handler running.." - << std::endl; + << std::endl; } FileSystemHandler::FsCommandCfg cfg = {}; ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; @@ -366,115 +365,115 @@ void Q7STestTask::testFileSystemHandlerDirect(FsOpCodes opCode) { }; switch (opCode) { - case (FsOpCodes::CREATE_EMPTY_FILE_IN_TMP): { - // No mount prefix, cause file is created in tmp - cfg.useMountPrefix = false; - sif::info << "Creating empty file in /tmp folder" << std::endl; - // Do not delete file, user can check existence in shell - fsHandler->createFile("/tmp/", "test.txt", nullptr, 0, &cfg); - break; - } - case (FsOpCodes::REMOVE_TMP_FILE): { - sif::info << "Deleting /tmp/test.txt sample file" << std::endl; - // No mount prefix, cause file is created in tmp - cfg.useMountPrefix = false; - if (not std::filesystem::exists("/tmp/test.txt")) { - // Creating sample file - sif::info << "Creating sample file /tmp/test.txt to delete" << std::endl; + case (FsOpCodes::CREATE_EMPTY_FILE_IN_TMP): { + // No mount prefix, cause file is created in tmp + cfg.useMountPrefix = false; + sif::info << "Creating empty file in /tmp folder" << std::endl; + // Do not delete file, user can check existence in shell fsHandler->createFile("/tmp/", "test.txt", nullptr, 0, &cfg); + break; } - result = fsHandler->removeFile("/tmp", "test.txt", &cfg); - if (result == HasReturnvaluesIF::RETURN_OK) { - sif::info << "File removed successfully" << std::endl; - } else { - sif::warning << "File removal failed!" << std::endl; + case (FsOpCodes::REMOVE_TMP_FILE): { + sif::info << "Deleting /tmp/test.txt sample file" << std::endl; + // No mount prefix, cause file is created in tmp + cfg.useMountPrefix = false; + if (not std::filesystem::exists("/tmp/test.txt")) { + // Creating sample file + sif::info << "Creating sample file /tmp/test.txt to delete" << std::endl; + fsHandler->createFile("/tmp/", "test.txt", nullptr, 0, &cfg); + } + result = fsHandler->removeFile("/tmp", "test.txt", &cfg); + if (result == HasReturnvaluesIF::RETURN_OK) { + sif::info << "File removed successfully" << std::endl; + } else { + sif::warning << "File removal failed!" << std::endl; + } + break; } - break; - } - case (FsOpCodes::CREATE_DIR_IN_TMP): { - // No mount prefix, cause file is created in tmp - cfg.useMountPrefix = false; - sif::info << "Creating empty file in /tmp folder" << std::endl; - // Do not delete file, user can check existence in shell - ReturnValue_t result = fsHandler->createDirectory("/tmp/", "test", false, &cfg); - if (result == HasReturnvaluesIF::RETURN_OK) { - sif::info << "Directory created successfully" << std::endl; - } else { - sif::warning << "Directory creation failed!" << std::endl; + case (FsOpCodes::CREATE_DIR_IN_TMP): { + // No mount prefix, cause file is created in tmp + cfg.useMountPrefix = false; + sif::info << "Creating empty file in /tmp folder" << std::endl; + // Do not delete file, user can check existence in shell + ReturnValue_t result = fsHandler->createDirectory("/tmp/", "test", false, &cfg); + if (result == HasReturnvaluesIF::RETURN_OK) { + sif::info << "Directory created successfully" << std::endl; + } else { + sif::warning << "Directory creation failed!" << std::endl; + } + break; } - break; - } - case (FsOpCodes::REMOVE_EMPTY_DIR_IN_TMP): { - // No mount prefix, cause file is created in tmp - cfg.useMountPrefix = false; - if (not std::filesystem::exists("/tmp/test")) { - result = fsHandler->createDirectory("/tmp", "test", false, &cfg); - } else { - // Delete any leftover files to regular dir removal works - std::remove("/tmp/test/*"); + case (FsOpCodes::REMOVE_EMPTY_DIR_IN_TMP): { + // No mount prefix, cause file is created in tmp + cfg.useMountPrefix = false; + if (not std::filesystem::exists("/tmp/test")) { + result = fsHandler->createDirectory("/tmp", "test", false, &cfg); + } else { + // Delete any leftover files to regular dir removal works + std::remove("/tmp/test/*"); + } + result = fsHandler->removeDirectory("/tmp/", "test", false, &cfg); + if (result == HasReturnvaluesIF::RETURN_OK) { + sif::info << "Directory removed successfully" << std::endl; + } else { + sif::warning << "Directory removal failed!" << std::endl; + } + break; } - result = fsHandler->removeDirectory("/tmp/", "test", false, &cfg); - if (result == HasReturnvaluesIF::RETURN_OK) { - sif::info << "Directory removed successfully" << std::endl; - } else { - sif::warning << "Directory removal failed!" << std::endl; + case (FsOpCodes::REMOVE_FILLED_DIR_IN_TMP): { + result = createNonEmptyTmpDir(); + if (result != HasReturnvaluesIF::RETURN_OK) { + return; + } + result = fsHandler->removeDirectory("/tmp/", "test", true, &cfg); + if (result == HasReturnvaluesIF::RETURN_OK) { + sif::info << "Directory removed recursively successfully" << std::endl; + } else { + sif::warning << "Recursive directory removal failed!" << std::endl; + } + break; } - break; - } - case (FsOpCodes::REMOVE_FILLED_DIR_IN_TMP): { - result = createNonEmptyTmpDir(); - if (result != HasReturnvaluesIF::RETURN_OK) { - return; + case (FsOpCodes::ATTEMPT_DIR_REMOVAL_NON_EMPTY): { + result = createNonEmptyTmpDir(); + if (result != HasReturnvaluesIF::RETURN_OK) { + return; + } + result = fsHandler->removeDirectory("/tmp/", "test", false, &cfg); + if (result != HasReturnvaluesIF::RETURN_OK) { + sif::info << "Directory removal attempt failed as expected" << std::endl; + } else { + sif::warning << "Directory removal worked when it should not have!" << std::endl; + } + break; } - result = fsHandler->removeDirectory("/tmp/", "test", true, &cfg); - if (result == HasReturnvaluesIF::RETURN_OK) { - sif::info << "Directory removed recursively successfully" << std::endl; - } else { - sif::warning << "Recursive directory removal failed!" << std::endl; + case (FsOpCodes::RENAME_FILE): { + // No mount prefix, cause file is created in tmp + cfg.useMountPrefix = false; + if (std::filesystem::exists("/tmp/test.txt")) { + fsHandler->removeDirectory("/tmp/", "test", false, &cfg); + } + sif::info << "Creating empty file /tmp/test.txt and rename to /tmp/test2.txt" << std::endl; + // Do not delete file, user can check existence in shell + fsHandler->createFile("/tmp/", "test.txt", nullptr, 0, &cfg); + fsHandler->renameFile("/tmp/", "test.txt", "test2.txt", &cfg); + break; } - break; - } - case (FsOpCodes::ATTEMPT_DIR_REMOVAL_NON_EMPTY): { - result = createNonEmptyTmpDir(); - if (result != HasReturnvaluesIF::RETURN_OK) { - return; + case (FsOpCodes::APPEND_TO_FILE): { + // No mount prefix, cause file is created in tmp + cfg.useMountPrefix = false; + if (std::filesystem::exists("/tmp/test.txt")) { + fsHandler->removeDirectory("/tmp/", "test", false, &cfg); + } + if (std::filesystem::exists("/tmp/test.txt")) { + fsHandler->removeDirectory("/tmp/", "test", false, &cfg); + } + sif::info << "Creating empty file /tmp/test.txt and adding content" << std::endl; + std::string content = "Hello World\n"; + // Do not delete file, user can check existence in shell + fsHandler->createFile("/tmp/", "test.txt", nullptr, 0, &cfg); + fsHandler->appendToFile("/tmp/", "test.txt", reinterpret_cast(content.data()), + content.size(), 0, &cfg); } - result = fsHandler->removeDirectory("/tmp/", "test", false, &cfg); - if (result != HasReturnvaluesIF::RETURN_OK) { - sif::info << "Directory removal attempt failed as expected" << std::endl; - } else { - sif::warning << "Directory removal worked when it should not have!" << std::endl; - } - break; - } - case (FsOpCodes::RENAME_FILE): { - // No mount prefix, cause file is created in tmp - cfg.useMountPrefix = false; - if (std::filesystem::exists("/tmp/test.txt")) { - fsHandler->removeDirectory("/tmp/", "test", false, &cfg); - } - sif::info << "Creating empty file /tmp/test.txt and rename to /tmp/test2.txt" << std::endl; - // Do not delete file, user can check existence in shell - fsHandler->createFile("/tmp/", "test.txt", nullptr, 0, &cfg); - fsHandler->renameFile("/tmp/", "test.txt", "test2.txt", &cfg); - break; - } - case (FsOpCodes::APPEND_TO_FILE): { - // No mount prefix, cause file is created in tmp - cfg.useMountPrefix = false; - if (std::filesystem::exists("/tmp/test.txt")) { - fsHandler->removeDirectory("/tmp/", "test", false, &cfg); - } - if (std::filesystem::exists("/tmp/test.txt")) { - fsHandler->removeDirectory("/tmp/", "test", false, &cfg); - } - sif::info << "Creating empty file /tmp/test.txt and adding content" << std::endl; - std::string content = "Hello World\n"; - // Do not delete file, user can check existence in shell - fsHandler->createFile("/tmp/", "test.txt", nullptr, 0, &cfg); - fsHandler->appendToFile("/tmp/", "test.txt", reinterpret_cast(content.data()), - content.size(), 0, &cfg); - } } } diff --git a/bsp_q7s/boardtest/Q7STestTask.h b/bsp_q7s/boardtest/Q7STestTask.h index ad58889f..7fadbe6b 100644 --- a/bsp_q7s/boardtest/Q7STestTask.h +++ b/bsp_q7s/boardtest/Q7STestTask.h @@ -2,6 +2,7 @@ #define BSP_Q7S_BOARDTEST_Q7STESTTASK_H_ #include + #include "test/testtasks/TestTask.h" class CoreController; diff --git a/linux/boardtest/LibgpiodTest.cpp b/linux/boardtest/LibgpiodTest.cpp index 9a36352c..66e26e3b 100644 --- a/linux/boardtest/LibgpiodTest.cpp +++ b/linux/boardtest/LibgpiodTest.cpp @@ -29,8 +29,8 @@ ReturnValue_t LibgpiodTest::performPeriodicAction() { sif::warning << "LibgpiodTest::performPeriodicAction: Failed to read gpio " << std::endl; return RETURN_FAILED; } else { - sif::debug << "LibgpiodTest::performPeriodicAction: MIO 0 state = " << static_cast(gpioState) - << std::endl; + sif::debug << "LibgpiodTest::performPeriodicAction: MIO 0 state = " + << static_cast(gpioState) << std::endl; } break; } diff --git a/mission/devices/HeaterHandler.cpp b/mission/devices/HeaterHandler.cpp index a969ad54..eeaa0504 100644 --- a/mission/devices/HeaterHandler.cpp +++ b/mission/devices/HeaterHandler.cpp @@ -29,6 +29,10 @@ HeaterHandler::HeaterHandler(object_id_t setObjectId_, GpioIF* gpioInterface_, H if (mainLineSwitcher == nullptr) { throw std::invalid_argument("HeaterHandler::HeaterHandler: Invalid PowerSwitchIF"); } + heaterMutex = MutexFactory::instance()->createMutex(); + if (heaterMutex == nullptr) { + throw std::runtime_error("HeaterHandler::HeaterHandler: Creating Mutex failed"); + } auto mqArgs = MqArgs(setObjectId_, static_cast(this)); commandQueue = QueueFactory::instance()->createMessageQueue( cmdQueueSize, MessageQueueMessage::MAX_MESSAGE_SIZE, &mqArgs); @@ -43,9 +47,14 @@ ReturnValue_t HeaterHandler::performOperation(uint8_t operationCode) { for (const auto& heater : helper.heaters) { heater.first->performOperation(0); } - } catch(const std::out_of_range& e) { + for (const auto& heater : heaterVec) { + sif::info << heater.switchState << ","; + } + sif::info << std::endl; + } catch (const std::out_of_range& e) { sif::warning << "HeaterHandler::performOperation: " - "Out of range error | " << e.what() << std::endl; + "Out of range error | " + << e.what() << std::endl; } return RETURN_OK; } @@ -77,13 +86,7 @@ ReturnValue_t HeaterHandler::initialize() { ReturnValue_t HeaterHandler::initializeHeaterMap() { for (power::Switch_t switchNr = 0; switchNr < heater::NUMBER_OF_SWITCHES; switchNr++) { - gpio::Levels level; - gpioInterface->readGpio(helper.heaters[switchNr].second, level); - SwitchState initState = SwitchState::OFF; - if(level == gpio::Levels::HIGH) { - - } - heaterVec.push_back(HeaterWrapper(helper.heaters[switchNr], initState)); + heaterVec.push_back(HeaterWrapper(helper.heaters[switchNr], SwitchState::OFF)); } return RETURN_OK; } @@ -208,7 +211,7 @@ void HeaterHandler::handleSwitchOnCommand(heater::Switchers heaterIdx) { // Check state of main line switch ReturnValue_t mainSwitchState = mainLineSwitcher->getSwitchState(mainLineSwitch); if (mainSwitchState == PowerSwitchIF::SWITCH_ON) { - if (checkSwitchState(heaterIdx) == SwitchState::ON) { + if (checkSwitchState(heaterIdx) == SwitchState::OFF) { gpioId_t gpioId = heater.gpioId; result = gpioInterface->pullHigh(gpioId); if (result != RETURN_OK) { @@ -216,7 +219,7 @@ void HeaterHandler::handleSwitchOnCommand(heater::Switchers heaterIdx) { << " high" << std::endl; triggerEvent(GPIO_PULL_HIGH_FAILED, result); } else { - triggerEvent(HEATER_WENT_ON, heaterIdx, 0); + triggerEvent(HEATER_WENT_ON, heaterIdx, 0); heater.switchState = ON; } } else { @@ -262,8 +265,12 @@ void HeaterHandler::handleSwitchOffCommand(heater::Switchers heaterIdx) { << " low" << std::endl; triggerEvent(GPIO_PULL_LOW_FAILED, result); } else { + auto result = heaterMutex->lockMutex(); heater.switchState = OFF; - triggerEvent(HEATER_WENT_OFF, heaterIdx, 0); + if (result == HasReturnvaluesIF::RETURN_OK) { + heaterMutex->unlockMutex(); + } + triggerEvent(HEATER_WENT_OFF, heaterIdx, 0); // When all switches are off, also main line switch will be turned off if (allSwitchesOff()) { mainLineSwitcher->sendSwitchCommand(mainLineSwitch, PowerSwitchIF::SWITCH_OFF); @@ -284,12 +291,14 @@ void HeaterHandler::handleSwitchOffCommand(heater::Switchers heaterIdx) { heater.active = false; } -HeaterHandler::SwitchState HeaterHandler::checkSwitchState(heater::Switchers switchNr) { +HeaterHandler::SwitchState HeaterHandler::checkSwitchState(heater::Switchers switchNr) const { + MutexGuard mg(heaterMutex); return heaterVec.at(switchNr).switchState; } bool HeaterHandler::allSwitchesOff() { bool allSwitchesOrd = false; + MutexGuard mg(heaterMutex); /* Or all switches. As soon one switch is on, allSwitchesOrd will be true */ for (power::Switch_t switchNr = 0; switchNr < heater::NUMBER_OF_SWITCHES; switchNr++) { allSwitchesOrd = allSwitchesOrd || heaterVec.at(switchNr).switchState; @@ -301,7 +310,19 @@ MessageQueueId_t HeaterHandler::getCommandQueue() const { return commandQueue->g ReturnValue_t HeaterHandler::sendFuseOnCommand(uint8_t fuseNr) { return RETURN_OK; } -ReturnValue_t HeaterHandler::getSwitchState(uint8_t switchNr) const { return 0; } +ReturnValue_t HeaterHandler::getSwitchState(uint8_t switchNr) const { + ReturnValue_t mainSwitchState = mainLineSwitcher->getSwitchState(mainLineSwitch); + if (mainSwitchState == PowerSwitchIF::SWITCH_OFF) { + return PowerSwitchIF::SWITCH_OFF; + } + if (switchNr > 7) { + return PowerSwitchIF::RETURN_FAILED; + } + if (checkSwitchState(static_cast(switchNr)) == SwitchState::ON) { + return PowerSwitchIF::SWITCH_ON; + } + return PowerSwitchIF::SWITCH_OFF; +} ReturnValue_t HeaterHandler::getFuseState(uint8_t fuseNr) const { return 0; } diff --git a/mission/devices/HeaterHandler.h b/mission/devices/HeaterHandler.h index b88fc103..598d256a 100644 --- a/mission/devices/HeaterHandler.h +++ b/mission/devices/HeaterHandler.h @@ -54,22 +54,22 @@ class HeaterHandler : public ExecutableObjectIF, virtual ~HeaterHandler(); - virtual ReturnValue_t performOperation(uint8_t operationCode = 0) override; + ReturnValue_t performOperation(uint8_t operationCode = 0) override; - virtual ReturnValue_t sendSwitchCommand(uint8_t switchNr, ReturnValue_t onOff) override; - virtual ReturnValue_t sendFuseOnCommand(uint8_t fuseNr) override; + ReturnValue_t sendSwitchCommand(uint8_t switchNr, ReturnValue_t onOff) override; + ReturnValue_t sendFuseOnCommand(uint8_t fuseNr) override; /** * @brief This function will be called from the Heater object to check * the current switch state. */ - virtual ReturnValue_t getSwitchState(uint8_t switchNr) const override; - virtual ReturnValue_t getFuseState(uint8_t fuseNr) const override; - virtual uint32_t getSwitchDelayMs(void) const override; + ReturnValue_t getSwitchState(uint8_t switchNr) const override; + ReturnValue_t getFuseState(uint8_t fuseNr) const override; + uint32_t getSwitchDelayMs(void) const override; - virtual MessageQueueId_t getCommandQueue() const override; - virtual ReturnValue_t executeAction(ActionId_t actionId, MessageQueueId_t commandedBy, - const uint8_t* data, size_t size) override; - virtual ReturnValue_t initialize() override; + MessageQueueId_t getCommandQueue() const override; + ReturnValue_t executeAction(ActionId_t actionId, MessageQueueId_t commandedBy, + const uint8_t* data, size_t size) override; + ReturnValue_t initialize() override; private: static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::HEATER_HANDLER; @@ -98,7 +98,7 @@ class HeaterHandler : public ExecutableObjectIF, */ struct HeaterWrapper { HeaterWrapper(HeaterPair pair, SwitchState initState) - : healthDevice(pair.first), gpioId(pair.second), switchState(initState) {} + : healthDevice(pair.first), gpioId(pair.second), switchState(initState) {} HealthDevice* healthDevice = nullptr; gpioId_t gpioId = gpio::NO_GPIO; SwitchAction action = SwitchAction::NONE; @@ -113,6 +113,8 @@ class HeaterHandler : public ExecutableObjectIF, HeaterMap heaterVec = {}; + MutexIF* heaterMutex = nullptr; + HeaterHelper helper; /** Size of command queue */ @@ -141,7 +143,7 @@ class HeaterHandler : public ExecutableObjectIF, * @brief Returns the state of a switch (ON - true, or OFF - false). * @param switchNr The number of the switch to check. */ - SwitchState checkSwitchState(heater::Switchers switchNr); + SwitchState checkSwitchState(heater::Switchers switchNr) const; /** * @brief This function runs commands waiting for execution.