eive-obsw/mission/system/acs/RwAssembly.cpp

99 lines
3.0 KiB
C++
Raw Normal View History

2022-04-21 16:56:46 +02:00
#include "RwAssembly.h"
2023-04-11 22:58:13 +02:00
RwAssembly::RwAssembly(object_id_t objectId, PowerSwitchIF* pwrSwitcher, power::Switch_t switchId,
2022-09-30 14:30:30 +02:00
RwHelper helper)
2023-04-11 22:58:13 +02:00
: SharedPowerAssemblyBase(objectId, pwrSwitcher, switchId), helper(helper) {
2022-04-22 10:28:29 +02:00
ModeListEntry entry;
for (uint8_t idx = 0; idx < NUMBER_RWS; idx++) {
entry.setObject(helper.rwIds[idx]);
entry.setMode(MODE_OFF);
entry.setSubmode(SUBMODE_NONE);
modeTable.insert(entry);
}
}
ReturnValue_t RwAssembly::commandChildren(Mode_t mode, Submode_t submode) {
2022-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::OK;
2022-04-22 10:28:29 +02:00
// Initialize the mode table to ensure all devices are in a defined state
for (uint8_t idx = 0; idx < NUMBER_RWS; idx++) {
modeTable[idx].setMode(MODE_OFF);
modeTable[idx].setSubmode(SUBMODE_NONE);
}
if (recoveryState != RecoveryState::RECOVERY_STARTED) {
if (mode == DeviceHandlerIF::MODE_NORMAL or mode == MODE_ON) {
result = handleNormalOrOnModeCmd(mode, submode);
}
}
HybridIterator<ModeListEntry> tableIter(modeTable.begin(), modeTable.end());
executeTable(tableIter);
return result;
}
ReturnValue_t RwAssembly::checkChildrenStateOn(Mode_t wantedMode, Submode_t wantedSubmode) {
int devsInCorrectMode = 0;
try {
for (uint8_t idx = 0; idx < NUMBER_RWS; idx++) {
if (childrenMap.at(helper.rwIds[idx]).mode == wantedMode) {
2022-04-22 10:28:29 +02:00
devsInCorrectMode++;
}
}
} catch (const std::out_of_range& e) {
2023-04-06 19:11:26 +02:00
sif::error << "RW ASSY: Invalid children map: " << e.what() << std::endl;
2022-04-22 10:28:29 +02:00
}
if (devsInCorrectMode < 3) {
if (warningSwitch) {
2023-04-06 19:11:26 +02:00
sif::warning << "RW ASSY: Only " << devsInCorrectMode << " devices in correct mode"
<< std::endl;
2022-04-22 10:28:29 +02:00
warningSwitch = false;
}
return NOT_ENOUGH_CHILDREN_IN_CORRECT_STATE;
}
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2022-04-22 10:28:29 +02:00
}
ReturnValue_t RwAssembly::isModeCombinationValid(Mode_t mode, Submode_t submode) {
if (mode == MODE_ON or mode == MODE_OFF or mode == DeviceHandlerIF::MODE_NORMAL) {
2022-08-24 17:27:47 +02:00
return returnvalue::OK;
2022-04-22 10:28:29 +02:00
}
return HasModesIF::INVALID_MODE;
}
ReturnValue_t RwAssembly::handleNormalOrOnModeCmd(Mode_t mode, Submode_t submode) {
2022-08-24 17:27:47 +02:00
ReturnValue_t result = returnvalue::OK;
2022-04-22 10:28:29 +02:00
object_id_t objId = 0;
try {
for (uint8_t idx = 0; idx < NUMBER_RWS; idx++) {
2023-04-06 19:11:26 +02:00
if (isUseable(objId, mode)) {
2022-04-22 10:28:29 +02:00
modeTable[idx].setMode(mode);
2023-04-06 19:11:26 +02:00
modeTable[idx].setSubmode(submode);
2022-04-22 10:28:29 +02:00
}
}
} catch (const std::out_of_range& e) {
2023-04-06 19:11:26 +02:00
sif::error << "RW ASSY: Invalid children map: " << e.what() << std::endl;
2022-04-22 10:28:29 +02:00
}
return result;
}
bool RwAssembly::isUseable(object_id_t object, Mode_t mode) {
if (healthHelper.healthTable->isFaulty(object)) {
return false;
}
// Check if device is already in target mode
if (childrenMap[object].mode == mode) {
return true;
}
if (healthHelper.healthTable->isCommandable(object)) {
return true;
}
return false;
}
2023-02-17 02:10:08 +01:00
ReturnValue_t RwAssembly::initialize() {
for (auto objId : helper.rwIds) {
updateChildModeByObjId(objId, MODE_OFF, SUBMODE_NONE);
}
return AssemblyBase::initialize();
}