2022-02-25 11:58:02 +01:00
|
|
|
#include "AcsBoardAssembly.h"
|
2022-03-02 17:56:54 +01:00
|
|
|
|
2022-03-04 00:55:51 +01:00
|
|
|
#include <devices/gpioIds.h>
|
2022-03-02 17:56:54 +01:00
|
|
|
#include <fsfw/power/PowerSwitchIF.h>
|
|
|
|
#include <fsfw/serviceinterface.h>
|
|
|
|
|
|
|
|
AcsBoardAssembly::AcsBoardAssembly(object_id_t objectId, object_id_t parentId,
|
2022-03-04 00:55:51 +01:00
|
|
|
PowerSwitchIF* switcher, AcsBoardHelper helper, GpioIF* gpioIF)
|
2022-03-05 03:02:09 +01:00
|
|
|
: AssemblyBase(objectId, parentId),
|
2022-03-07 18:39:33 +01:00
|
|
|
pwrStateMachine(SWITCH_A, SWITCH_B, switcher),
|
2022-03-05 03:02:09 +01:00
|
|
|
helper(helper),
|
|
|
|
gpioIF(gpioIF) {
|
2022-03-02 17:56:54 +01:00
|
|
|
if (switcher == nullptr) {
|
|
|
|
sif::error << "AcsBoardAssembly::AcsBoardAssembly: Invalid Power Switcher "
|
|
|
|
"IF passed"
|
|
|
|
<< std::endl;
|
|
|
|
}
|
2022-03-04 00:55:51 +01:00
|
|
|
if (gpioIF == nullptr) {
|
|
|
|
sif::error << "AcsBoardAssembly::AcsBoardAssembly: Invalid GPIO IF passed" << std::endl;
|
|
|
|
}
|
2022-03-02 17:56:54 +01:00
|
|
|
ModeListEntry entry;
|
|
|
|
initModeTableEntry(helper.mgm0Lis3IdSideA, entry);
|
|
|
|
initModeTableEntry(helper.mgm1Rm3100IdSideA, entry);
|
|
|
|
initModeTableEntry(helper.mgm2Lis3IdSideB, entry);
|
|
|
|
initModeTableEntry(helper.mgm3Rm3100IdSideB, entry);
|
|
|
|
initModeTableEntry(helper.gyro0AdisIdSideA, entry);
|
|
|
|
initModeTableEntry(helper.gyro1L3gIdSideA, entry);
|
|
|
|
initModeTableEntry(helper.gyro2AdisIdSideB, entry);
|
|
|
|
initModeTableEntry(helper.gyro3L3gIdSideB, entry);
|
|
|
|
initModeTableEntry(helper.gpsId, entry);
|
|
|
|
}
|
|
|
|
|
2022-03-05 03:02:09 +01:00
|
|
|
void AcsBoardAssembly::performChildOperation() {
|
|
|
|
using namespace duallane;
|
2022-03-07 18:39:33 +01:00
|
|
|
if (pwrStateMachine.active()) {
|
|
|
|
pwrStateMachineWrapper();
|
2022-03-05 03:02:09 +01:00
|
|
|
// This state is the indicator that the power state machine is done
|
2022-03-07 18:39:33 +01:00
|
|
|
}
|
|
|
|
if (not pwrStateMachine.active()) {
|
2022-03-05 03:02:09 +01:00
|
|
|
AssemblyBase::performChildOperation();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AcsBoardAssembly::startTransition(Mode_t mode, Submode_t submode) {
|
|
|
|
using namespace duallane;
|
2022-03-07 18:39:33 +01:00
|
|
|
pwrStateMachine.reset();
|
2022-03-05 03:02:09 +01:00
|
|
|
// 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
|
2022-03-07 18:39:33 +01:00
|
|
|
pwrStateMachine.start(mode, submode);
|
|
|
|
// Cache these for later after the power state machine has finished
|
2022-03-05 03:02:09 +01:00
|
|
|
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
|
2022-03-07 18:39:33 +01:00
|
|
|
pwrStateMachineWrapper();
|
2022-03-05 03:02:09 +01:00
|
|
|
} 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);
|
2022-03-04 18:12:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-02 17:56:54 +01:00
|
|
|
ReturnValue_t AcsBoardAssembly::commandChildren(Mode_t mode, Submode_t submode) {
|
2022-03-05 03:02:09 +01:00
|
|
|
using namespace duallane;
|
2022-03-02 17:56:54 +01:00
|
|
|
ReturnValue_t result = RETURN_OK;
|
2022-03-03 10:28:55 +01:00
|
|
|
refreshHelperModes();
|
2022-03-07 18:39:33 +01:00
|
|
|
if (mode == DeviceHandlerIF::MODE_NORMAL or mode == MODE_ON) {
|
|
|
|
result = handleNormalOrOnModeCmd(mode, submode);
|
|
|
|
} else {
|
|
|
|
modeTable[ModeTableIdx::GYRO_0_A].setMode(MODE_OFF);
|
|
|
|
modeTable[ModeTableIdx::GYRO_0_A].setSubmode(SUBMODE_NONE);
|
|
|
|
modeTable[ModeTableIdx::GYRO_1_A].setMode(MODE_OFF);
|
|
|
|
modeTable[ModeTableIdx::GYRO_1_A].setSubmode(SUBMODE_NONE);
|
|
|
|
modeTable[ModeTableIdx::GYRO_2_B].setMode(MODE_OFF);
|
|
|
|
modeTable[ModeTableIdx::GYRO_2_B].setSubmode(SUBMODE_NONE);
|
|
|
|
modeTable[ModeTableIdx::GYRO_3_B].setMode(MODE_OFF);
|
|
|
|
modeTable[ModeTableIdx::GYRO_3_B].setSubmode(SUBMODE_NONE);
|
|
|
|
modeTable[ModeTableIdx::MGM_0_A].setMode(MODE_OFF);
|
|
|
|
modeTable[ModeTableIdx::MGM_0_A].setSubmode(SUBMODE_NONE);
|
|
|
|
modeTable[ModeTableIdx::MGM_1_A].setMode(MODE_OFF);
|
|
|
|
modeTable[ModeTableIdx::MGM_1_A].setSubmode(SUBMODE_NONE);
|
|
|
|
modeTable[ModeTableIdx::MGM_2_B].setMode(MODE_OFF);
|
|
|
|
modeTable[ModeTableIdx::MGM_2_B].setSubmode(SUBMODE_NONE);
|
|
|
|
modeTable[ModeTableIdx::MGM_3_B].setMode(MODE_OFF);
|
|
|
|
modeTable[ModeTableIdx::MGM_3_B].setSubmode(SUBMODE_NONE);
|
|
|
|
modeTable[ModeTableIdx::GPS].setMode(MODE_OFF);
|
|
|
|
modeTable[ModeTableIdx::GPS].setSubmode(SUBMODE_NONE);
|
2022-03-02 17:56:54 +01:00
|
|
|
}
|
2022-03-07 18:39:33 +01:00
|
|
|
HybridIterator<ModeListEntry> tableIter(modeTable.begin(), modeTable.end());
|
|
|
|
executeTable(tableIter);
|
2022-03-02 17:56:54 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t AcsBoardAssembly::checkChildrenStateOn(Mode_t wantedMode, Submode_t wantedSubmode) {
|
2022-03-05 03:02:09 +01:00
|
|
|
using namespace duallane;
|
2022-03-03 10:28:55 +01:00
|
|
|
refreshHelperModes();
|
2022-03-07 18:39:33 +01:00
|
|
|
// if (state == PwrStates::SWITCHING_POWER) {
|
|
|
|
// // Wrong mode
|
|
|
|
// sif::error << "Wrong mode, currently switching power" << std::endl;
|
|
|
|
// return RETURN_OK;
|
|
|
|
// }
|
2022-03-04 18:33:23 +01:00
|
|
|
if (wantedSubmode == A_SIDE) {
|
2022-03-03 15:37:36 +01:00
|
|
|
if ((helper.gyro0SideAMode != wantedMode and helper.gyro1SideAMode != wantedMode) or
|
2022-03-03 10:28:55 +01:00
|
|
|
(helper.mgm0SideAMode != wantedMode and helper.mgm1SideAMode != wantedMode) or
|
2022-03-05 03:02:09 +01:00
|
|
|
helper.gpsMode != MODE_ON) {
|
2022-03-03 10:28:55 +01:00
|
|
|
return NOT_ENOUGH_CHILDREN_IN_CORRECT_STATE;
|
|
|
|
}
|
|
|
|
return RETURN_OK;
|
2022-03-04 18:33:23 +01:00
|
|
|
} else if (wantedSubmode == B_SIDE) {
|
2022-03-03 15:37:36 +01:00
|
|
|
if ((helper.gyro2SideBMode != wantedMode and helper.gyro3SideBMode != wantedMode) or
|
2022-03-03 10:28:55 +01:00
|
|
|
(helper.mgm2SideBMode != wantedMode and helper.mgm3SideBMode != wantedMode) or
|
2022-03-05 03:02:09 +01:00
|
|
|
helper.gpsMode != MODE_ON) {
|
2022-03-03 10:28:55 +01:00
|
|
|
return NOT_ENOUGH_CHILDREN_IN_CORRECT_STATE;
|
|
|
|
}
|
|
|
|
return RETURN_OK;
|
2022-03-04 18:33:23 +01:00
|
|
|
} else if (wantedSubmode == DUAL_MODE) {
|
2022-03-03 15:37:36 +01:00
|
|
|
if ((helper.gyro0SideAMode != wantedMode and helper.gyro1SideAMode != wantedMode and
|
|
|
|
helper.gyro2AdisIdSideB != wantedMode and helper.gyro3SideBMode != wantedMode) or
|
2022-03-03 10:28:55 +01:00
|
|
|
(helper.mgm0SideAMode != wantedMode and helper.mgm1SideAMode != wantedMode and
|
2022-03-03 15:37:36 +01:00
|
|
|
helper.mgm2SideBMode != wantedMode and helper.mgm3SideBMode != wantedMode) or
|
2022-03-05 03:02:09 +01:00
|
|
|
helper.gpsMode != MODE_ON) {
|
2022-03-04 00:55:51 +01:00
|
|
|
// Trigger event, but don't start any other transitions. This is the last fallback mode.
|
|
|
|
if (dualModeErrorSwitch) {
|
|
|
|
triggerEvent(NOT_ENOUGH_DEVICES_DUAL_MODE, 0, 0);
|
|
|
|
dualModeErrorSwitch = false;
|
|
|
|
}
|
|
|
|
return RETURN_OK;
|
2022-03-03 10:28:55 +01:00
|
|
|
}
|
|
|
|
return RETURN_OK;
|
2022-03-02 17:56:54 +01:00
|
|
|
}
|
2022-03-03 10:28:55 +01:00
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
2022-03-02 17:56:54 +01:00
|
|
|
}
|
|
|
|
|
2022-03-03 10:12:59 +01:00
|
|
|
ReturnValue_t AcsBoardAssembly::handleNormalOrOnModeCmd(Mode_t mode, Submode_t submode) {
|
2022-03-05 03:02:09 +01:00
|
|
|
using namespace duallane;
|
2022-03-02 17:56:54 +01:00
|
|
|
ReturnValue_t result = RETURN_OK;
|
2022-03-03 20:11:12 +01:00
|
|
|
auto cmdSeq = [&](object_id_t objectId, Mode_t devMode, ModeTableIdx tableIdx) {
|
|
|
|
if (mode == DeviceHandlerIF::MODE_NORMAL) {
|
|
|
|
if (isUseable(objectId, devMode)) {
|
2022-03-07 14:46:46 +01:00
|
|
|
if (devMode == MODE_ON) {
|
|
|
|
modeTable[tableIdx].setMode(mode);
|
2022-03-02 17:56:54 +01:00
|
|
|
modeTable[tableIdx].setSubmode(SUBMODE_NONE);
|
2022-03-07 14:46:46 +01:00
|
|
|
|
2022-03-02 17:56:54 +01:00
|
|
|
} else {
|
2022-03-07 14:46:46 +01:00
|
|
|
modeTable[tableIdx].setMode(MODE_ON);
|
2022-03-02 17:56:54 +01:00
|
|
|
modeTable[tableIdx].setSubmode(SUBMODE_NONE);
|
|
|
|
}
|
|
|
|
}
|
2022-03-04 18:33:23 +01:00
|
|
|
} else if (mode == MODE_ON) {
|
2022-03-03 20:11:12 +01:00
|
|
|
if (isUseable(objectId, devMode)) {
|
2022-03-03 10:12:59 +01:00
|
|
|
modeTable[tableIdx].setMode(MODE_ON);
|
|
|
|
modeTable[tableIdx].setSubmode(SUBMODE_NONE);
|
2022-03-02 17:56:54 +01:00
|
|
|
}
|
|
|
|
}
|
2022-03-03 10:12:59 +01:00
|
|
|
};
|
2022-03-05 03:02:09 +01:00
|
|
|
if (this->mode == MODE_OFF and mode == DeviceHandlerIF::MODE_NORMAL) {
|
|
|
|
if (internalState != STATE_SECOND_STEP) {
|
|
|
|
result = NEED_SECOND_STEP;
|
|
|
|
}
|
|
|
|
}
|
2022-03-04 18:33:23 +01:00
|
|
|
switch (submode) {
|
2022-03-03 10:12:59 +01:00
|
|
|
case (A_SIDE): {
|
2022-03-03 20:11:12 +01:00
|
|
|
cmdSeq(helper.gyro0AdisIdSideA, helper.gyro0SideAMode, ModeTableIdx::GYRO_0_A);
|
|
|
|
cmdSeq(helper.gyro1L3gIdSideA, helper.gyro1SideAMode, ModeTableIdx::GYRO_1_A);
|
|
|
|
cmdSeq(helper.mgm0Lis3IdSideA, helper.mgm0SideAMode, ModeTableIdx::MGM_0_A);
|
|
|
|
cmdSeq(helper.mgm1Rm3100IdSideA, helper.mgm1SideAMode, ModeTableIdx::MGM_1_A);
|
2022-03-05 03:02:09 +01:00
|
|
|
modeTable[ModeTableIdx::GPS].setMode(MODE_ON);
|
|
|
|
modeTable[ModeTableIdx::GPS].setSubmode(SUBMODE_NONE);
|
|
|
|
if (gpioIF->pullLow(gpioIds::GNSS_SELECT) != HasReturnvaluesIF::RETURN_OK) {
|
2022-03-04 00:55:51 +01:00
|
|
|
#if OBSW_VERBOSE_LEVEL >= 1
|
|
|
|
sif::error << "AcsBoardAssembly::handleNormalOrOnModeCmd: Could not pull GNSS select low"
|
|
|
|
<< std::endl;
|
|
|
|
#endif
|
|
|
|
}
|
2022-03-03 10:12:59 +01:00
|
|
|
modeTable[ModeTableIdx::GYRO_2_B].setMode(MODE_OFF);
|
|
|
|
modeTable[ModeTableIdx::GYRO_2_B].setSubmode(SUBMODE_NONE);
|
|
|
|
modeTable[ModeTableIdx::GYRO_3_B].setMode(MODE_OFF);
|
|
|
|
modeTable[ModeTableIdx::GYRO_3_B].setSubmode(SUBMODE_NONE);
|
|
|
|
modeTable[ModeTableIdx::MGM_2_B].setMode(MODE_OFF);
|
|
|
|
modeTable[ModeTableIdx::MGM_2_B].setSubmode(SUBMODE_NONE);
|
|
|
|
modeTable[ModeTableIdx::MGM_3_B].setMode(MODE_OFF);
|
|
|
|
modeTable[ModeTableIdx::MGM_3_B].setSubmode(SUBMODE_NONE);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
case (B_SIDE): {
|
2022-03-03 20:11:12 +01:00
|
|
|
cmdSeq(helper.gyro2AdisIdSideB, helper.gyro2SideBMode, ModeTableIdx::GYRO_2_B);
|
|
|
|
cmdSeq(helper.gyro3L3gIdSideB, helper.gyro3SideBMode, ModeTableIdx::GYRO_3_B);
|
|
|
|
cmdSeq(helper.mgm2Lis3IdSideB, helper.mgm2SideBMode, ModeTableIdx::MGM_2_B);
|
|
|
|
cmdSeq(helper.mgm3Rm3100IdSideB, helper.mgm3SideBMode, ModeTableIdx::MGM_3_B);
|
|
|
|
cmdSeq(helper.gpsId, helper.gpsMode, ModeTableIdx::GPS);
|
2022-03-05 03:02:09 +01:00
|
|
|
if (gpioIF->pullHigh(gpioIds::GNSS_SELECT) != HasReturnvaluesIF::RETURN_OK) {
|
2022-03-04 00:55:51 +01:00
|
|
|
#if OBSW_VERBOSE_LEVEL >= 1
|
|
|
|
sif::error << "AcsBoardAssembly::handleNormalOrOnModeCmd: Could not pull GNSS select high"
|
|
|
|
<< std::endl;
|
|
|
|
#endif
|
|
|
|
}
|
2022-03-03 10:12:59 +01:00
|
|
|
modeTable[ModeTableIdx::GYRO_0_A].setMode(MODE_OFF);
|
|
|
|
modeTable[ModeTableIdx::GYRO_0_A].setSubmode(SUBMODE_NONE);
|
|
|
|
modeTable[ModeTableIdx::GYRO_1_A].setMode(MODE_OFF);
|
|
|
|
modeTable[ModeTableIdx::GYRO_1_A].setSubmode(SUBMODE_NONE);
|
|
|
|
modeTable[ModeTableIdx::MGM_0_A].setMode(MODE_OFF);
|
|
|
|
modeTable[ModeTableIdx::MGM_0_A].setSubmode(SUBMODE_NONE);
|
|
|
|
modeTable[ModeTableIdx::MGM_1_A].setMode(MODE_OFF);
|
|
|
|
modeTable[ModeTableIdx::MGM_1_A].setSubmode(SUBMODE_NONE);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
case (DUAL_MODE): {
|
2022-03-03 20:11:12 +01:00
|
|
|
cmdSeq(helper.gpsId, helper.gpsMode, ModeTableIdx::GPS);
|
|
|
|
cmdSeq(helper.gyro0AdisIdSideA, helper.gyro0SideAMode, ModeTableIdx::GYRO_0_A);
|
|
|
|
cmdSeq(helper.gyro1L3gIdSideA, helper.gyro1SideAMode, ModeTableIdx::GYRO_1_A);
|
|
|
|
cmdSeq(helper.mgm0Lis3IdSideA, helper.mgm0SideAMode, ModeTableIdx::MGM_0_A);
|
|
|
|
cmdSeq(helper.mgm1Rm3100IdSideA, helper.mgm1SideAMode, ModeTableIdx::MGM_1_A);
|
|
|
|
cmdSeq(helper.gyro2AdisIdSideB, helper.gyro2SideBMode, ModeTableIdx::GYRO_2_B);
|
|
|
|
cmdSeq(helper.gyro3L3gIdSideB, helper.gyro3SideBMode, ModeTableIdx::GYRO_3_B);
|
|
|
|
cmdSeq(helper.mgm2Lis3IdSideB, helper.mgm2SideBMode, ModeTableIdx::MGM_2_B);
|
|
|
|
cmdSeq(helper.mgm3Rm3100IdSideB, helper.mgm3SideBMode, ModeTableIdx::MGM_3_B);
|
2022-03-05 03:02:09 +01:00
|
|
|
ReturnValue_t status = RETURN_OK;
|
2022-03-04 00:55:51 +01:00
|
|
|
if (defaultSubmode == Submodes::A_SIDE) {
|
2022-03-05 03:02:09 +01:00
|
|
|
status = gpioIF->pullLow(gpioIds::GNSS_SELECT);
|
2022-03-04 00:55:51 +01:00
|
|
|
} else {
|
2022-03-05 03:02:09 +01:00
|
|
|
status = gpioIF->pullHigh(gpioIds::GNSS_SELECT);
|
2022-03-04 00:55:51 +01:00
|
|
|
}
|
2022-03-05 03:02:09 +01:00
|
|
|
if (status != HasReturnvaluesIF::RETURN_OK) {
|
2022-03-04 00:55:51 +01:00
|
|
|
#if OBSW_VERBOSE_LEVEL >= 1
|
|
|
|
sif::error << "AcsBoardAssembly::handleNormalOrOnModeCmd: Could not pull GNSS select to"
|
|
|
|
"default side for dual mode"
|
|
|
|
<< std::endl;
|
|
|
|
#endif
|
|
|
|
}
|
2022-03-03 10:12:59 +01:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
sif::error << "AcsBoardAssembly::handleNormalModeCmd: Unknown submode" << std::endl;
|
|
|
|
}
|
2022-03-02 17:56:54 +01:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2022-03-03 10:28:55 +01:00
|
|
|
ReturnValue_t AcsBoardAssembly::isModeCombinationValid(Mode_t mode, Submode_t submode) {
|
2022-03-05 03:02:09 +01:00
|
|
|
using namespace duallane;
|
2022-03-03 15:37:36 +01:00
|
|
|
if (submode != A_SIDE and submode != B_SIDE and submode != DUAL_MODE) {
|
2022-03-03 10:28:55 +01:00
|
|
|
return HasReturnvaluesIF::RETURN_FAILED;
|
|
|
|
}
|
|
|
|
return HasReturnvaluesIF::RETURN_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AcsBoardAssembly::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;
|
|
|
|
}
|
|
|
|
|
2022-03-03 15:37:36 +01:00
|
|
|
void AcsBoardAssembly::handleModeReached() {
|
2022-03-05 03:02:09 +01:00
|
|
|
using namespace duallane;
|
|
|
|
if (targetMode == MODE_OFF) {
|
2022-03-07 18:39:33 +01:00
|
|
|
pwrStateMachine.start(targetMode, targetSubmode);
|
2022-03-05 03:02:09 +01:00
|
|
|
// Now we can switch off the power. After that, the AssemblyBase::handleModeReached function
|
|
|
|
// will be called
|
2022-03-07 18:39:33 +01:00
|
|
|
pwrStateMachineWrapper();
|
2022-03-05 03:02:09 +01:00
|
|
|
} else {
|
|
|
|
finishModeOp();
|
|
|
|
}
|
2022-03-03 15:37:36 +01:00
|
|
|
}
|
|
|
|
|
2022-03-04 00:55:51 +01:00
|
|
|
void AcsBoardAssembly::handleChildrenLostMode(ReturnValue_t result) {
|
2022-03-05 03:02:09 +01:00
|
|
|
using namespace duallane;
|
2022-03-03 20:11:12 +01:00
|
|
|
// Some ACS board components are required for Safe-Mode. It would be good if the software
|
|
|
|
// transitions from A side to B side and from B side to dual mode autonomously
|
2022-03-04 00:55:51 +01:00
|
|
|
// to ensure that that enough sensors are available without an operators intervention.
|
|
|
|
// Therefore, the lost mode handler was overwritten to start these transitions
|
|
|
|
Submode_t nextSubmode = Submodes::A_SIDE;
|
|
|
|
if (submode == Submodes::A_SIDE) {
|
|
|
|
nextSubmode = Submodes::B_SIDE;
|
|
|
|
}
|
|
|
|
if (not tryingOtherSide) {
|
|
|
|
triggerEvent(CANT_KEEP_MODE, mode, submode);
|
|
|
|
startTransition(mode, nextSubmode);
|
|
|
|
tryingOtherSide = true;
|
|
|
|
} else {
|
|
|
|
// Not sure when this would happen. This flag is reset if the mode was reached. If it
|
|
|
|
// was not reached, the transition failure handler should be called.
|
|
|
|
sif::error << "AcsBoardAssembly::handleChildrenLostMode: Wrong handler called" << std::endl;
|
|
|
|
triggerEvent(TRANSITION_OTHER_SIDE_FAILED, mode, targetSubmode);
|
|
|
|
startTransition(mode, Submodes::DUAL_MODE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void AcsBoardAssembly::handleModeTransitionFailed(ReturnValue_t result) {
|
2022-03-05 03:02:09 +01:00
|
|
|
using namespace duallane;
|
2022-03-04 00:55:51 +01:00
|
|
|
Submode_t nextSubmode = Submodes::A_SIDE;
|
|
|
|
if (submode == Submodes::A_SIDE) {
|
|
|
|
nextSubmode = Submodes::B_SIDE;
|
|
|
|
}
|
|
|
|
// Check whether the transition was started because the mode could not be kept (not commanded).
|
|
|
|
// If this is not the case, start transition to other side. If it is the case, start
|
|
|
|
// transition to dual mode.
|
|
|
|
if (not tryingOtherSide) {
|
|
|
|
triggerEvent(CANT_KEEP_MODE, mode, submode);
|
|
|
|
startTransition(mode, nextSubmode);
|
|
|
|
tryingOtherSide = true;
|
|
|
|
} else {
|
|
|
|
triggerEvent(TRANSITION_OTHER_SIDE_FAILED, mode, targetSubmode);
|
|
|
|
startTransition(mode, Submodes::DUAL_MODE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-05 03:02:09 +01:00
|
|
|
void AcsBoardAssembly::setPreferredSide(duallane::Submodes submode) {
|
|
|
|
using namespace duallane;
|
2022-03-04 00:55:51 +01:00
|
|
|
if (submode != Submodes::A_SIDE and submode != Submodes::B_SIDE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this->defaultSubmode = submode;
|
|
|
|
}
|
|
|
|
|
2022-03-05 03:02:09 +01:00
|
|
|
void AcsBoardAssembly::selectGpsInDualMode(duallane::Submodes side) {
|
|
|
|
using namespace duallane;
|
2022-03-04 00:55:51 +01:00
|
|
|
if (submode != Submodes::DUAL_MODE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
ReturnValue_t result = RETURN_OK;
|
|
|
|
if (side == Submodes::A_SIDE) {
|
|
|
|
result = gpioIF->pullLow(gpioIds::GNSS_SELECT);
|
|
|
|
} else {
|
|
|
|
result = gpioIF->pullHigh(gpioIds::GNSS_SELECT);
|
|
|
|
}
|
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
#if OBSW_VERBOSE_LEVEL >= 1
|
|
|
|
sif::error << "AcsBoardAssembly::switchGpsInDualMode: Switching GPS failed" << std::endl;
|
|
|
|
#endif
|
|
|
|
}
|
2022-03-03 20:11:12 +01:00
|
|
|
}
|
|
|
|
|
2022-03-03 10:28:55 +01:00
|
|
|
void AcsBoardAssembly::refreshHelperModes() {
|
2022-03-05 03:02:09 +01:00
|
|
|
try {
|
|
|
|
helper.gyro0SideAMode = childrenMap.at(helper.gyro0AdisIdSideA).mode;
|
|
|
|
helper.gyro1SideAMode = childrenMap.at(helper.gyro1L3gIdSideA).mode;
|
|
|
|
helper.gyro2SideBMode = childrenMap.at(helper.gyro2AdisIdSideB).mode;
|
|
|
|
helper.gyro3SideBMode = childrenMap.at(helper.gyro2AdisIdSideB).mode;
|
|
|
|
helper.mgm0SideAMode = childrenMap.at(helper.mgm0Lis3IdSideA).mode;
|
|
|
|
helper.mgm1SideAMode = childrenMap.at(helper.mgm1Rm3100IdSideA).mode;
|
|
|
|
helper.mgm2SideBMode = childrenMap.at(helper.mgm2Lis3IdSideB).mode;
|
|
|
|
helper.mgm3SideBMode = childrenMap.at(helper.mgm3Rm3100IdSideB).mode;
|
|
|
|
helper.gpsMode = childrenMap.at(helper.gpsId).mode;
|
|
|
|
} catch (const std::out_of_range& e) {
|
|
|
|
sif::error << "AcsBoardAssembly::refreshHelperModes: Invalid map: " << e.what() << std::endl;
|
|
|
|
}
|
2022-03-03 10:28:55 +01:00
|
|
|
}
|
2022-03-03 20:11:12 +01:00
|
|
|
|
|
|
|
void AcsBoardAssembly::initModeTableEntry(object_id_t id, ModeListEntry& entry) {
|
|
|
|
entry.setObject(id);
|
|
|
|
entry.setMode(MODE_OFF);
|
|
|
|
entry.setSubmode(SUBMODE_NONE);
|
|
|
|
entry.setInheritSubmode(false);
|
|
|
|
modeTable.insert(entry);
|
|
|
|
}
|
2022-03-05 03:02:09 +01:00
|
|
|
|
|
|
|
void AcsBoardAssembly::finishModeOp() {
|
|
|
|
using namespace duallane;
|
|
|
|
AssemblyBase::handleModeReached();
|
2022-03-07 16:47:15 +01:00
|
|
|
pwrStateMachine.reset();
|
|
|
|
powerRetryCounter = 0;
|
2022-03-05 03:02:09 +01:00
|
|
|
tryingOtherSide = false;
|
|
|
|
dualModeErrorSwitch = true;
|
|
|
|
}
|
|
|
|
|
2022-03-07 18:39:33 +01:00
|
|
|
ReturnValue_t AcsBoardAssembly::pwrStateMachineWrapper() {
|
2022-03-05 03:02:09 +01:00
|
|
|
using namespace duallane;
|
2022-03-07 18:39:33 +01:00
|
|
|
OpCodes opCode = pwrStateMachine.powerStateMachine();
|
2022-03-05 03:02:09 +01:00
|
|
|
if (opCode == OpCodes::NONE) {
|
2022-03-07 16:47:15 +01:00
|
|
|
return RETURN_OK;
|
2022-03-05 03:02:09 +01:00
|
|
|
} else if (opCode == OpCodes::FINISH_OP) {
|
|
|
|
finishModeOp();
|
|
|
|
} else if (opCode == OpCodes::START_TRANSITION) {
|
2022-03-07 18:39:33 +01:00
|
|
|
AssemblyBase::startTransition(targetMode, targetSubmode);
|
2022-03-07 16:47:15 +01:00
|
|
|
} 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(POWER_STATE_MACHINE_TIMEOUT, 0, 0);
|
|
|
|
return RETURN_FAILED;
|
|
|
|
}
|
2022-03-05 03:02:09 +01:00
|
|
|
}
|
2022-03-07 16:47:15 +01:00
|
|
|
return RETURN_OK;
|
2022-03-05 03:02:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ReturnValue_t AcsBoardAssembly::initialize() {
|
|
|
|
ReturnValue_t result = registerChild(helper.gyro0AdisIdSideA);
|
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
result = registerChild(helper.gyro1L3gIdSideA);
|
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
result = registerChild(helper.gyro2AdisIdSideB);
|
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
result = registerChild(helper.gyro3L3gIdSideB);
|
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
result = registerChild(helper.mgm0Lis3IdSideA);
|
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
result = registerChild(helper.mgm1Rm3100IdSideA);
|
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
result = registerChild(helper.mgm2Lis3IdSideB);
|
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
result = registerChild(helper.mgm3Rm3100IdSideB);
|
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
result = registerChild(helper.gpsId);
|
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
return AssemblyBase::initialize();
|
|
|
|
}
|