Robin Mueller
fec6cc3ea9
All checks were successful
EIVE/eive-obsw/pipeline/pr-develop This commit looks good
106 lines
3.7 KiB
C++
106 lines
3.7 KiB
C++
#include "DualLaneAssemblyBase.h"
|
|
|
|
DualLaneAssemblyBase::DualLaneAssemblyBase(object_id_t objectId, object_id_t parentId,
|
|
PowerSwitchIF* pwrSwitcher,
|
|
pcduSwitches::Switches switch1,
|
|
pcduSwitches::Switches switch2, Event pwrTimeoutEvent)
|
|
: AssemblyBase(objectId, parentId),
|
|
pwrStateMachine(switch1, switch2, pwrSwitcher),
|
|
pwrTimeoutEvent(pwrTimeoutEvent) {}
|
|
|
|
void DualLaneAssemblyBase::performChildOperation() {
|
|
using namespace duallane;
|
|
if (pwrStateMachine.active()) {
|
|
pwrStateMachineWrapper();
|
|
}
|
|
// Only perform the regular child operation if the power state machine is not active.
|
|
// It does not make any sense to command device modes while the power switcher is busy
|
|
// switching off or on devices.
|
|
if (not pwrStateMachine.active()) {
|
|
AssemblyBase::performChildOperation();
|
|
}
|
|
}
|
|
|
|
void DualLaneAssemblyBase::startTransition(Mode_t mode, Submode_t submode) {
|
|
using namespace duallane;
|
|
pwrStateMachine.reset();
|
|
// If anything other than MODE_OFF is commanded, perform power state machine first
|
|
if (mode != MODE_OFF) {
|
|
// Cache the target modes, required by power state machine
|
|
pwrStateMachine.start(mode, submode);
|
|
// Cache these for later after the power state machine has finished
|
|
targetMode = mode;
|
|
targetSubmode = submode;
|
|
// Perform power state machine first, then start mode transition. The power state machine will
|
|
// start the transition after it has finished
|
|
pwrStateMachineWrapper();
|
|
} else {
|
|
// Command the devices to off first before switching off the power. The handleModeReached
|
|
// custom implementation will take care of starting the power state machine.
|
|
AssemblyBase::startTransition(mode, submode);
|
|
}
|
|
}
|
|
|
|
bool DualLaneAssemblyBase::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;
|
|
}
|
|
|
|
ReturnValue_t DualLaneAssemblyBase::pwrStateMachineWrapper() {
|
|
using namespace duallane;
|
|
OpCodes opCode = pwrStateMachine.powerStateMachine();
|
|
if (opCode == OpCodes::NONE) {
|
|
return RETURN_OK;
|
|
} else if (opCode == OpCodes::FINISH_OP) {
|
|
// Will be called for transitions to MODE_OFF, where everything is done after power switching
|
|
finishModeOp();
|
|
} else if (opCode == OpCodes::START_TRANSITION) {
|
|
// Will be called for transitions from MODE_OFF to anything else, where the mode still has
|
|
// to be commanded after power switching
|
|
AssemblyBase::startTransition(targetMode, targetSubmode);
|
|
} else if (opCode == OpCodes::TIMEOUT_OCCURED) {
|
|
if (powerRetryCounter == 0) {
|
|
powerRetryCounter++;
|
|
pwrStateMachine.reset();
|
|
} else {
|
|
#if OBSW_VERBOSE_LEVEL >= 1
|
|
sif::warning << "Timeout occured in power state machine" << std::endl;
|
|
#endif
|
|
triggerEvent(pwrTimeoutEvent, 0, 0);
|
|
return RETURN_FAILED;
|
|
}
|
|
}
|
|
return RETURN_OK;
|
|
}
|
|
|
|
ReturnValue_t DualLaneAssemblyBase::isModeCombinationValid(Mode_t mode, Submode_t submode) {
|
|
using namespace duallane;
|
|
if (submode != A_SIDE and submode != B_SIDE and submode != DUAL_MODE) {
|
|
return HasReturnvaluesIF::RETURN_FAILED;
|
|
}
|
|
return HasReturnvaluesIF::RETURN_OK;
|
|
}
|
|
|
|
void DualLaneAssemblyBase::handleModeReached() {
|
|
using namespace duallane;
|
|
if (targetMode == MODE_OFF) {
|
|
pwrStateMachine.start(targetMode, targetSubmode);
|
|
// Now we can switch off the power. After that, the AssemblyBase::handleModeReached function
|
|
// will be called
|
|
pwrStateMachineWrapper();
|
|
} else {
|
|
finishModeOp();
|
|
}
|
|
}
|