v1.12.0 #269

Merged
muellerr merged 493 commits from develop into main 2022-07-04 11:19:05 +02:00
6 changed files with 169 additions and 146 deletions
Showing only changes of commit d0e18f8b35 - Show all commits

View File

@ -7,9 +7,9 @@
#include <objects/systemObjectList.h> #include <objects/systemObjectList.h>
#include <tmtc/apid.h> #include <tmtc/apid.h>
#include <tmtc/pusIds.h> #include <tmtc/pusIds.h>
#include "fsfw_tests/integration/task/TestTask.h"
#include "OBSWConfig.h" #include "OBSWConfig.h"
#include "fsfw_tests/integration/task/TestTask.h"
#if OBSW_USE_TMTC_TCP_BRIDGE == 0 #if OBSW_USE_TMTC_TCP_BRIDGE == 0
#include "fsfw/osal/common/UdpTcPollingTask.h" #include "fsfw/osal/common/UdpTcPollingTask.h"

View File

@ -156,13 +156,13 @@ void Q7STestTask::testDummyParams() {
result = param.getValue<int>(DummyParameter::DUMMY_KEY_PARAM_1, test); result = param.getValue<int>(DummyParameter::DUMMY_KEY_PARAM_1, test);
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
sif::warning << "Q7STestTask::testDummyParams: Key " << DummyParameter::DUMMY_KEY_PARAM_1 sif::warning << "Q7STestTask::testDummyParams: Key " << DummyParameter::DUMMY_KEY_PARAM_1
<< " does not exist" << std::endl; << " does not exist" << std::endl;
} }
std::string test2; std::string test2;
result = param.getValue<std::string>(DummyParameter::DUMMY_KEY_PARAM_2, test2); result = param.getValue<std::string>(DummyParameter::DUMMY_KEY_PARAM_2, test2);
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
sif::warning << "Q7STestTask::testDummyParams: Key " << DummyParameter::DUMMY_KEY_PARAM_1 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 (3 expected): " << test << std::endl;
sif::info << "Test value 2 (\"blirb\" expected): " << test2 << std::endl; sif::info << "Test value 2 (\"blirb\" expected): " << test2 << std::endl;
@ -172,7 +172,7 @@ ReturnValue_t Q7STestTask::initialize() {
coreController = ObjectManager::instance()->get<CoreController>(objects::CORE_CONTROLLER); coreController = ObjectManager::instance()->get<CoreController>(objects::CORE_CONTROLLER);
if (coreController == nullptr) { if (coreController == nullptr) {
sif::warning << "Q7STestTask::initialize: Could not retrieve CORE_CONTROLLER object" sif::warning << "Q7STestTask::initialize: Could not retrieve CORE_CONTROLLER object"
<< std::endl; << std::endl;
} }
return TestTask::initialize(); return TestTask::initialize();
} }
@ -182,14 +182,14 @@ void Q7STestTask::testProtHandler() {
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
// If any chips are unlocked, lock them here // If any chips are unlocked, lock them here
result = coreController->setBootCopyProtection(xsc::Chip::ALL_CHIP, xsc::Copy::ALL_COPY, true, result = coreController->setBootCopyProtection(xsc::Chip::ALL_CHIP, xsc::Copy::ALL_COPY, true,
opPerformed, true); opPerformed, true);
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
sif::warning << "Q7STestTask::testProtHandler: Op failed" << std::endl; sif::warning << "Q7STestTask::testProtHandler: Op failed" << std::endl;
} }
// unlock own copy // unlock own copy
result = coreController->setBootCopyProtection(xsc::Chip::SELF_CHIP, xsc::Copy::SELF_COPY, false, result = coreController->setBootCopyProtection(xsc::Chip::SELF_CHIP, xsc::Copy::SELF_COPY, false,
opPerformed, true); opPerformed, true);
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
sif::warning << "Q7STestTask::testProtHandler: Op failed" << std::endl; sif::warning << "Q7STestTask::testProtHandler: Op failed" << std::endl;
} }
@ -203,7 +203,7 @@ void Q7STestTask::testProtHandler() {
// lock own copy // lock own copy
result = coreController->setBootCopyProtection(xsc::Chip::SELF_CHIP, xsc::Copy::SELF_COPY, true, result = coreController->setBootCopyProtection(xsc::Chip::SELF_CHIP, xsc::Copy::SELF_COPY, true,
opPerformed, true); opPerformed, true);
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
sif::warning << "Q7STestTask::testProtHandler: Op failed" << std::endl; sif::warning << "Q7STestTask::testProtHandler: Op failed" << std::endl;
} }
@ -217,7 +217,7 @@ void Q7STestTask::testProtHandler() {
// unlock specific copy // unlock specific copy
result = coreController->setBootCopyProtection(xsc::Chip::CHIP_1, xsc::Copy::COPY_1, false, result = coreController->setBootCopyProtection(xsc::Chip::CHIP_1, xsc::Copy::COPY_1, false,
opPerformed, true); opPerformed, true);
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
sif::warning << "Q7STestTask::testProtHandler: Op failed" << std::endl; sif::warning << "Q7STestTask::testProtHandler: Op failed" << std::endl;
} }
@ -231,7 +231,7 @@ void Q7STestTask::testProtHandler() {
// lock specific copy // lock specific copy
result = coreController->setBootCopyProtection(xsc::Chip::CHIP_1, xsc::Copy::COPY_1, true, result = coreController->setBootCopyProtection(xsc::Chip::CHIP_1, xsc::Copy::COPY_1, true,
opPerformed, true); opPerformed, true);
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
sif::warning << "Q7STestTask::testProtHandler: Op failed" << std::endl; sif::warning << "Q7STestTask::testProtHandler: Op failed" << std::endl;
} }
@ -273,7 +273,7 @@ void Q7STestTask::testGpsDaemonShm() {
} }
void Q7STestTask::testGpsDaemonSocket() { void Q7STestTask::testGpsDaemonSocket() {
if(gpsmmShmPtr == nullptr) { if (gpsmmShmPtr == nullptr) {
gpsmmShmPtr = new gpsmm("localhost", DEFAULT_GPSD_PORT); gpsmmShmPtr = new gpsmm("localhost", DEFAULT_GPSD_PORT);
} }
// The data from the device will generally be read all at once. Therefore, we // The data from the device will generally be read all at once. Therefore, we
@ -283,7 +283,7 @@ void Q7STestTask::testGpsDaemonSocket() {
// Opening failed // Opening failed
#if FSFW_VERBOSE_LEVEL >= 1 #if FSFW_VERBOSE_LEVEL >= 1
sif::warning << "Q7STestTask::testGpsDaemonSocket: Opening GPSMM failed | " sif::warning << "Q7STestTask::testGpsDaemonSocket: Opening GPSMM failed | "
<< "Error " << errno << " | " << gps_errstr(errno) << std::endl; << "Error " << errno << " | " << gps_errstr(errno) << std::endl;
#endif #endif
gpsNotOpenSwitch = false; gpsNotOpenSwitch = false;
@ -291,17 +291,16 @@ void Q7STestTask::testGpsDaemonSocket() {
return; return;
} }
// Stopwatch watch; // Stopwatch watch;
gps_data_t *gps = nullptr; gps_data_t* gps = nullptr;
gpsmmShmPtr->stream(WATCH_ENABLE | WATCH_JSON); gpsmmShmPtr->stream(WATCH_ENABLE | WATCH_JSON);
if(not gpsmmShmPtr->waiting(50000000)) { if (not gpsmmShmPtr->waiting(50000000)) {
return; return;
} }
gps = gpsmmShmPtr->read(); gps = gpsmmShmPtr->read();
if (gps == nullptr) { if (gps == nullptr) {
if (gpsReadFailedSwitch) { if (gpsReadFailedSwitch) {
gpsReadFailedSwitch = false; gpsReadFailedSwitch = false;
sif::warning << "Q7STestTask::testGpsDaemonSocket: Reading GPS data failed" sif::warning << "Q7STestTask::testGpsDaemonSocket: Reading GPS data failed" << std::endl;
<< std::endl;
} }
return; return;
} }
@ -312,8 +311,8 @@ void Q7STestTask::testGpsDaemonSocket() {
if (noModeSetCntr == 10) { if (noModeSetCntr == 10) {
// TODO: Trigger event here // TODO: Trigger event here
sif::warning << "Q7STestTask::testGpsDaemonSocket: No mode could be " sif::warning << "Q7STestTask::testGpsDaemonSocket: No mode could be "
"read for 10 consecutive reads" "read for 10 consecutive reads"
<< std::endl; << std::endl;
noModeSetCntr = -1; noModeSetCntr = -1;
} }
return; return;
@ -339,7 +338,7 @@ void Q7STestTask::testFileSystemHandlerDirect(FsOpCodes opCode) {
auto fsHandler = ObjectManager::instance()->get<FileSystemHandler>(objects::FILE_SYSTEM_HANDLER); auto fsHandler = ObjectManager::instance()->get<FileSystemHandler>(objects::FILE_SYSTEM_HANDLER);
if (fsHandler == nullptr) { if (fsHandler == nullptr) {
sif::warning << "Q7STestTask::testFileSystemHandlerDirect: No FS handler running.." sif::warning << "Q7STestTask::testFileSystemHandlerDirect: No FS handler running.."
<< std::endl; << std::endl;
} }
FileSystemHandler::FsCommandCfg cfg = {}; FileSystemHandler::FsCommandCfg cfg = {};
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
@ -366,115 +365,115 @@ void Q7STestTask::testFileSystemHandlerDirect(FsOpCodes opCode) {
}; };
switch (opCode) { switch (opCode) {
case (FsOpCodes::CREATE_EMPTY_FILE_IN_TMP): { case (FsOpCodes::CREATE_EMPTY_FILE_IN_TMP): {
// No mount prefix, cause file is created in tmp // No mount prefix, cause file is created in tmp
cfg.useMountPrefix = false; cfg.useMountPrefix = false;
sif::info << "Creating empty file in /tmp folder" << std::endl; sif::info << "Creating empty file in /tmp folder" << std::endl;
// Do not delete file, user can check existence in shell // 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;
fsHandler->createFile("/tmp/", "test.txt", nullptr, 0, &cfg); fsHandler->createFile("/tmp/", "test.txt", nullptr, 0, &cfg);
break;
} }
result = fsHandler->removeFile("/tmp", "test.txt", &cfg); case (FsOpCodes::REMOVE_TMP_FILE): {
if (result == HasReturnvaluesIF::RETURN_OK) { sif::info << "Deleting /tmp/test.txt sample file" << std::endl;
sif::info << "File removed successfully" << std::endl; // No mount prefix, cause file is created in tmp
} else { cfg.useMountPrefix = false;
sif::warning << "File removal failed!" << std::endl; 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
case (FsOpCodes::CREATE_DIR_IN_TMP): { cfg.useMountPrefix = false;
// No mount prefix, cause file is created in tmp sif::info << "Creating empty file in /tmp folder" << std::endl;
cfg.useMountPrefix = false; // Do not delete file, user can check existence in shell
sif::info << "Creating empty file in /tmp folder" << std::endl; ReturnValue_t result = fsHandler->createDirectory("/tmp/", "test", false, &cfg);
// Do not delete file, user can check existence in shell if (result == HasReturnvaluesIF::RETURN_OK) {
ReturnValue_t result = fsHandler->createDirectory("/tmp/", "test", false, &cfg); sif::info << "Directory created successfully" << std::endl;
if (result == HasReturnvaluesIF::RETURN_OK) { } else {
sif::info << "Directory created successfully" << std::endl; sif::warning << "Directory creation failed!" << 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
case (FsOpCodes::REMOVE_EMPTY_DIR_IN_TMP): { cfg.useMountPrefix = false;
// No mount prefix, cause file is created in tmp if (not std::filesystem::exists("/tmp/test")) {
cfg.useMountPrefix = false; result = fsHandler->createDirectory("/tmp", "test", false, &cfg);
if (not std::filesystem::exists("/tmp/test")) { } else {
result = fsHandler->createDirectory("/tmp", "test", false, &cfg); // Delete any leftover files to regular dir removal works
} else { std::remove("/tmp/test/*");
// 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); case (FsOpCodes::REMOVE_FILLED_DIR_IN_TMP): {
if (result == HasReturnvaluesIF::RETURN_OK) { result = createNonEmptyTmpDir();
sif::info << "Directory removed successfully" << std::endl; if (result != HasReturnvaluesIF::RETURN_OK) {
} else { return;
sif::warning << "Directory removal failed!" << std::endl; }
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::ATTEMPT_DIR_REMOVAL_NON_EMPTY): {
} result = createNonEmptyTmpDir();
case (FsOpCodes::REMOVE_FILLED_DIR_IN_TMP): { if (result != HasReturnvaluesIF::RETURN_OK) {
result = createNonEmptyTmpDir(); return;
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); case (FsOpCodes::RENAME_FILE): {
if (result == HasReturnvaluesIF::RETURN_OK) { // No mount prefix, cause file is created in tmp
sif::info << "Directory removed recursively successfully" << std::endl; cfg.useMountPrefix = false;
} else { if (std::filesystem::exists("/tmp/test.txt")) {
sif::warning << "Recursive directory removal failed!" << std::endl; 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::APPEND_TO_FILE): {
} // No mount prefix, cause file is created in tmp
case (FsOpCodes::ATTEMPT_DIR_REMOVAL_NON_EMPTY): { cfg.useMountPrefix = false;
result = createNonEmptyTmpDir(); if (std::filesystem::exists("/tmp/test.txt")) {
if (result != HasReturnvaluesIF::RETURN_OK) { fsHandler->removeDirectory("/tmp/", "test", false, &cfg);
return; }
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<const uint8_t*>(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<const uint8_t*>(content.data()),
content.size(), 0, &cfg);
}
} }
} }

View File

@ -2,6 +2,7 @@
#define BSP_Q7S_BOARDTEST_Q7STESTTASK_H_ #define BSP_Q7S_BOARDTEST_Q7STESTTASK_H_
#include <libgpsmm.h> #include <libgpsmm.h>
#include "test/testtasks/TestTask.h" #include "test/testtasks/TestTask.h"
class CoreController; class CoreController;

View File

@ -29,8 +29,8 @@ ReturnValue_t LibgpiodTest::performPeriodicAction() {
sif::warning << "LibgpiodTest::performPeriodicAction: Failed to read gpio " << std::endl; sif::warning << "LibgpiodTest::performPeriodicAction: Failed to read gpio " << std::endl;
return RETURN_FAILED; return RETURN_FAILED;
} else { } else {
sif::debug << "LibgpiodTest::performPeriodicAction: MIO 0 state = " << static_cast<int>(gpioState) sif::debug << "LibgpiodTest::performPeriodicAction: MIO 0 state = "
<< std::endl; << static_cast<int>(gpioState) << std::endl;
} }
break; break;
} }

View File

@ -29,6 +29,10 @@ HeaterHandler::HeaterHandler(object_id_t setObjectId_, GpioIF* gpioInterface_, H
if (mainLineSwitcher == nullptr) { if (mainLineSwitcher == nullptr) {
throw std::invalid_argument("HeaterHandler::HeaterHandler: Invalid PowerSwitchIF"); 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<void*>(this)); auto mqArgs = MqArgs(setObjectId_, static_cast<void*>(this));
commandQueue = QueueFactory::instance()->createMessageQueue( commandQueue = QueueFactory::instance()->createMessageQueue(
cmdQueueSize, MessageQueueMessage::MAX_MESSAGE_SIZE, &mqArgs); cmdQueueSize, MessageQueueMessage::MAX_MESSAGE_SIZE, &mqArgs);
@ -43,9 +47,14 @@ ReturnValue_t HeaterHandler::performOperation(uint8_t operationCode) {
for (const auto& heater : helper.heaters) { for (const auto& heater : helper.heaters) {
heater.first->performOperation(0); 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: " sif::warning << "HeaterHandler::performOperation: "
"Out of range error | " << e.what() << std::endl; "Out of range error | "
<< e.what() << std::endl;
} }
return RETURN_OK; return RETURN_OK;
} }
@ -77,13 +86,7 @@ ReturnValue_t HeaterHandler::initialize() {
ReturnValue_t HeaterHandler::initializeHeaterMap() { ReturnValue_t HeaterHandler::initializeHeaterMap() {
for (power::Switch_t switchNr = 0; switchNr < heater::NUMBER_OF_SWITCHES; switchNr++) { for (power::Switch_t switchNr = 0; switchNr < heater::NUMBER_OF_SWITCHES; switchNr++) {
gpio::Levels level; heaterVec.push_back(HeaterWrapper(helper.heaters[switchNr], SwitchState::OFF));
gpioInterface->readGpio(helper.heaters[switchNr].second, level);
SwitchState initState = SwitchState::OFF;
if(level == gpio::Levels::HIGH) {
}
heaterVec.push_back(HeaterWrapper(helper.heaters[switchNr], initState));
} }
return RETURN_OK; return RETURN_OK;
} }
@ -208,7 +211,7 @@ void HeaterHandler::handleSwitchOnCommand(heater::Switchers heaterIdx) {
// Check state of main line switch // Check state of main line switch
ReturnValue_t mainSwitchState = mainLineSwitcher->getSwitchState(mainLineSwitch); ReturnValue_t mainSwitchState = mainLineSwitcher->getSwitchState(mainLineSwitch);
if (mainSwitchState == PowerSwitchIF::SWITCH_ON) { if (mainSwitchState == PowerSwitchIF::SWITCH_ON) {
if (checkSwitchState(heaterIdx) == SwitchState::ON) { if (checkSwitchState(heaterIdx) == SwitchState::OFF) {
gpioId_t gpioId = heater.gpioId; gpioId_t gpioId = heater.gpioId;
result = gpioInterface->pullHigh(gpioId); result = gpioInterface->pullHigh(gpioId);
if (result != RETURN_OK) { if (result != RETURN_OK) {
@ -216,7 +219,7 @@ void HeaterHandler::handleSwitchOnCommand(heater::Switchers heaterIdx) {
<< " high" << std::endl; << " high" << std::endl;
triggerEvent(GPIO_PULL_HIGH_FAILED, result); triggerEvent(GPIO_PULL_HIGH_FAILED, result);
} else { } else {
triggerEvent(HEATER_WENT_ON, heaterIdx, 0); triggerEvent(HEATER_WENT_ON, heaterIdx, 0);
heater.switchState = ON; heater.switchState = ON;
} }
} else { } else {
@ -262,8 +265,12 @@ void HeaterHandler::handleSwitchOffCommand(heater::Switchers heaterIdx) {
<< " low" << std::endl; << " low" << std::endl;
triggerEvent(GPIO_PULL_LOW_FAILED, result); triggerEvent(GPIO_PULL_LOW_FAILED, result);
} else { } else {
auto result = heaterMutex->lockMutex();
heater.switchState = OFF; 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 // When all switches are off, also main line switch will be turned off
if (allSwitchesOff()) { if (allSwitchesOff()) {
mainLineSwitcher->sendSwitchCommand(mainLineSwitch, PowerSwitchIF::SWITCH_OFF); mainLineSwitcher->sendSwitchCommand(mainLineSwitch, PowerSwitchIF::SWITCH_OFF);
@ -284,12 +291,14 @@ void HeaterHandler::handleSwitchOffCommand(heater::Switchers heaterIdx) {
heater.active = false; 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; return heaterVec.at(switchNr).switchState;
} }
bool HeaterHandler::allSwitchesOff() { bool HeaterHandler::allSwitchesOff() {
bool allSwitchesOrd = false; bool allSwitchesOrd = false;
MutexGuard mg(heaterMutex);
/* Or all switches. As soon one switch is on, allSwitchesOrd will be true */ /* 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++) { for (power::Switch_t switchNr = 0; switchNr < heater::NUMBER_OF_SWITCHES; switchNr++) {
allSwitchesOrd = allSwitchesOrd || heaterVec.at(switchNr).switchState; 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::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<heater::Switchers>(switchNr)) == SwitchState::ON) {
return PowerSwitchIF::SWITCH_ON;
}
return PowerSwitchIF::SWITCH_OFF;
}
ReturnValue_t HeaterHandler::getFuseState(uint8_t fuseNr) const { return 0; } ReturnValue_t HeaterHandler::getFuseState(uint8_t fuseNr) const { return 0; }

View File

@ -54,22 +54,22 @@ class HeaterHandler : public ExecutableObjectIF,
virtual ~HeaterHandler(); 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; ReturnValue_t sendSwitchCommand(uint8_t switchNr, ReturnValue_t onOff) override;
virtual ReturnValue_t sendFuseOnCommand(uint8_t fuseNr) override; ReturnValue_t sendFuseOnCommand(uint8_t fuseNr) override;
/** /**
* @brief This function will be called from the Heater object to check * @brief This function will be called from the Heater object to check
* the current switch state. * the current switch state.
*/ */
virtual ReturnValue_t getSwitchState(uint8_t switchNr) const override; ReturnValue_t getSwitchState(uint8_t switchNr) const override;
virtual ReturnValue_t getFuseState(uint8_t fuseNr) const override; ReturnValue_t getFuseState(uint8_t fuseNr) const override;
virtual uint32_t getSwitchDelayMs(void) const override; uint32_t getSwitchDelayMs(void) const override;
virtual MessageQueueId_t getCommandQueue() const override; MessageQueueId_t getCommandQueue() const override;
virtual ReturnValue_t executeAction(ActionId_t actionId, MessageQueueId_t commandedBy, ReturnValue_t executeAction(ActionId_t actionId, MessageQueueId_t commandedBy,
const uint8_t* data, size_t size) override; const uint8_t* data, size_t size) override;
virtual ReturnValue_t initialize() override; ReturnValue_t initialize() override;
private: private:
static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::HEATER_HANDLER; static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::HEATER_HANDLER;
@ -98,7 +98,7 @@ class HeaterHandler : public ExecutableObjectIF,
*/ */
struct HeaterWrapper { struct HeaterWrapper {
HeaterWrapper(HeaterPair pair, SwitchState initState) HeaterWrapper(HeaterPair pair, SwitchState initState)
: healthDevice(pair.first), gpioId(pair.second), switchState(initState) {} : healthDevice(pair.first), gpioId(pair.second), switchState(initState) {}
HealthDevice* healthDevice = nullptr; HealthDevice* healthDevice = nullptr;
gpioId_t gpioId = gpio::NO_GPIO; gpioId_t gpioId = gpio::NO_GPIO;
SwitchAction action = SwitchAction::NONE; SwitchAction action = SwitchAction::NONE;
@ -113,6 +113,8 @@ class HeaterHandler : public ExecutableObjectIF,
HeaterMap heaterVec = {}; HeaterMap heaterVec = {};
MutexIF* heaterMutex = nullptr;
HeaterHelper helper; HeaterHelper helper;
/** Size of command queue */ /** Size of command queue */
@ -141,7 +143,7 @@ class HeaterHandler : public ExecutableObjectIF,
* @brief Returns the state of a switch (ON - true, or OFF - false). * @brief Returns the state of a switch (ON - true, or OFF - false).
* @param switchNr The number of the switch to check. * @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. * @brief This function runs commands waiting for execution.