re-introduce proper bounds checking
All checks were successful
EIVE/eive-obsw/pipeline/pr-main This commit looks good

This commit is contained in:
Robin Müller 2023-08-03 09:59:08 +02:00
parent a0e4f0a438
commit 093f7f3a31
Signed by: muellerr
GPG Key ID: A649FB78196E3849

View File

@ -410,9 +410,8 @@ void PayloadPcduHandler::checkAdcValues() {
adcSet.processed[U_DRO_DIV_6] = static_cast<float>(adcSet.channels[11]) * SCALE_VOLTAGE;
float lowerBound = 0.0;
float upperBound = 0.0;
bool adcTransition = false;
adcTransition = adcState == AdcState::NORMAL and adcCountdown.isBusy();
if (NO_ADC_CHECKS) {
bool adcTransition = adcState == AdcState::NORMAL and adcCountdown.isBusy();
if (NO_ADC_CHECKS or adcTransition) {
return;
}
// Now check against voltage and current limits.
@ -441,9 +440,12 @@ void PayloadPcduHandler::checkAdcValues() {
allOnInjectRequested = false;
return;
}
uint8_t submode = getSubmode();
if (((submode >> NormalSubmodeBits::DRO_ON) & 0b1) == 0b1) {
params.getValue(PARAM_KEY_MAP[NEG_V_LOWER_BOUND], lowerBound);
params.getValue(PARAM_KEY_MAP[NEG_V_UPPER_BOUND], upperBound);
if (not checkVoltage(adcSet.processed[U_NEG_V_FB], lowerBound, upperBound, NEG_V_OUT_OF_BOUNDS)) {
if (not checkVoltage(adcSet.processed[U_NEG_V_FB], lowerBound, upperBound,
NEG_V_OUT_OF_BOUNDS)) {
return;
}
params.getValue(PARAM_KEY_MAP[DRO_U_LOWER_BOUND], lowerBound);
@ -460,24 +462,32 @@ void PayloadPcduHandler::checkAdcValues() {
#endif
return;
}
}
if (((submode >> NormalSubmodeBits::X8_ON) & 0b1) == 0b1) {
params.getValue(PARAM_KEY_MAP[X8_U_LOWER_BOUND], lowerBound);
params.getValue(PARAM_KEY_MAP[X8_U_UPPER_BOUND], upperBound);
if (not checkVoltage(adcSet.processed[U_X8_DIV_6], lowerBound, upperBound, U_X8_OUT_OF_BOUNDS)) {
if (not checkVoltage(adcSet.processed[U_X8_DIV_6], lowerBound, upperBound,
U_X8_OUT_OF_BOUNDS)) {
return;
}
params.getValue(PARAM_KEY_MAP[X8_I_UPPER_BOUND], upperBound);
if (not checkCurrent(adcSet.processed[I_X8], upperBound, I_X8_OUT_OF_BOUNDS)) {
return;
}
}
if (((submode >> NormalSubmodeBits::TX_ON) & 0b1) == 0b1) {
params.getValue(PARAM_KEY_MAP[TX_U_LOWER_BOUND], lowerBound);
params.getValue(PARAM_KEY_MAP[TX_U_UPPER_BOUND], upperBound);
if (not checkVoltage(adcSet.processed[U_TX_DIV_6], lowerBound, upperBound, U_TX_OUT_OF_BOUNDS)) {
if (not checkVoltage(adcSet.processed[U_TX_DIV_6], lowerBound, upperBound,
U_TX_OUT_OF_BOUNDS)) {
return;
}
params.getValue(PARAM_KEY_MAP[TX_I_UPPER_BOUND], upperBound);
if (not checkCurrent(adcSet.processed[I_TX], upperBound, I_TX_OUT_OF_BOUNDS)) {
return;
}
}
if (((submode >> NormalSubmodeBits::MPA_ON) & 0b1) == 0b1) {
params.getValue(PARAM_KEY_MAP[MPA_U_LOWER_BOUND], lowerBound);
params.getValue(PARAM_KEY_MAP[MPA_U_UPPER_BOUND], upperBound);
if (not checkVoltage(adcSet.processed[U_MPA_DIV_6], lowerBound, upperBound,
@ -488,6 +498,8 @@ void PayloadPcduHandler::checkAdcValues() {
if (not checkCurrent(adcSet.processed[I_MPA], upperBound, I_MPA_OUT_OF_BOUNDS)) {
return;
}
}
if (((submode >> NormalSubmodeBits::HPA_ON) & 0b1) == 0b1) {
params.getValue(PARAM_KEY_MAP[HPA_U_LOWER_BOUND], lowerBound);
params.getValue(PARAM_KEY_MAP[HPA_U_UPPER_BOUND], upperBound);
if (not checkVoltage(adcSet.processed[U_HPA_DIV_6], lowerBound, upperBound,
@ -500,6 +512,7 @@ void PayloadPcduHandler::checkAdcValues() {
<< adcSet.processed[I_HPA] << " mA" << std::endl;
return;
}
}
transitionOk = true;
}
@ -518,8 +531,6 @@ void PayloadPcduHandler::checkJsonFileInit() {
bool PayloadPcduHandler::checkVoltage(float val, float lowerBound, float upperBound, Event event) {
bool tooLarge = false;
sif::debug << "CHecking voltage. Value: " << val << ", lower bound: " << lowerBound
<< ", upper bound: " << upperBound << std::endl;
if (val < lowerBound or val > upperBound) {
if (val > upperBound) {
tooLarge = true;