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; adcSet.processed[U_DRO_DIV_6] = static_cast<float>(adcSet.channels[11]) * SCALE_VOLTAGE;
float lowerBound = 0.0; float lowerBound = 0.0;
float upperBound = 0.0; float upperBound = 0.0;
bool adcTransition = false; bool adcTransition = adcState == AdcState::NORMAL and adcCountdown.isBusy();
adcTransition = adcState == AdcState::NORMAL and adcCountdown.isBusy(); if (NO_ADC_CHECKS or adcTransition) {
if (NO_ADC_CHECKS) {
return; return;
} }
// Now check against voltage and current limits. // Now check against voltage and current limits.
@ -441,64 +440,78 @@ void PayloadPcduHandler::checkAdcValues() {
allOnInjectRequested = false; allOnInjectRequested = false;
return; return;
} }
params.getValue(PARAM_KEY_MAP[NEG_V_LOWER_BOUND], lowerBound); uint8_t submode = getSubmode();
params.getValue(PARAM_KEY_MAP[NEG_V_UPPER_BOUND], upperBound); if (((submode >> NormalSubmodeBits::DRO_ON) & 0b1) == 0b1) {
if (not checkVoltage(adcSet.processed[U_NEG_V_FB], lowerBound, upperBound, NEG_V_OUT_OF_BOUNDS)) { params.getValue(PARAM_KEY_MAP[NEG_V_LOWER_BOUND], lowerBound);
return; params.getValue(PARAM_KEY_MAP[NEG_V_UPPER_BOUND], upperBound);
} if (not checkVoltage(adcSet.processed[U_NEG_V_FB], lowerBound, upperBound,
params.getValue(PARAM_KEY_MAP[DRO_U_LOWER_BOUND], lowerBound); NEG_V_OUT_OF_BOUNDS)) {
params.getValue(PARAM_KEY_MAP[DRO_U_UPPER_BOUND], upperBound); return;
if (not checkVoltage(adcSet.processed[U_DRO_DIV_6], lowerBound, upperBound, }
U_DRO_OUT_OF_BOUNDS)) { params.getValue(PARAM_KEY_MAP[DRO_U_LOWER_BOUND], lowerBound);
return; params.getValue(PARAM_KEY_MAP[DRO_U_UPPER_BOUND], upperBound);
} if (not checkVoltage(adcSet.processed[U_DRO_DIV_6], lowerBound, upperBound,
params.getValue(PARAM_KEY_MAP[DRO_I_UPPER_BOUND], upperBound); U_DRO_OUT_OF_BOUNDS)) {
if (not checkCurrent(adcSet.processed[I_DRO], upperBound, I_DRO_OUT_OF_BOUNDS)) { return;
}
params.getValue(PARAM_KEY_MAP[DRO_I_UPPER_BOUND], upperBound);
if (not checkCurrent(adcSet.processed[I_DRO], upperBound, I_DRO_OUT_OF_BOUNDS)) {
#if OBSW_VERBOSE_LEVEL >= 1 #if OBSW_VERBOSE_LEVEL >= 1
sif::warning << "Detected out of bounds current for DRO: " << adcSet.processed[I_DRO] sif::warning << "Detected out of bounds current for DRO: " << adcSet.processed[I_DRO]
<< ", Raw: " << adcSet.channels[I_DRO] << std::endl; << ", Raw: " << adcSet.channels[I_DRO] << std::endl;
#endif #endif
return; return;
}
} }
params.getValue(PARAM_KEY_MAP[X8_U_LOWER_BOUND], lowerBound); if (((submode >> NormalSubmodeBits::X8_ON) & 0b1) == 0b1) {
params.getValue(PARAM_KEY_MAP[X8_U_UPPER_BOUND], upperBound); params.getValue(PARAM_KEY_MAP[X8_U_LOWER_BOUND], lowerBound);
if (not checkVoltage(adcSet.processed[U_X8_DIV_6], lowerBound, upperBound, U_X8_OUT_OF_BOUNDS)) { params.getValue(PARAM_KEY_MAP[X8_U_UPPER_BOUND], upperBound);
return; 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;
}
} }
params.getValue(PARAM_KEY_MAP[X8_I_UPPER_BOUND], upperBound); if (((submode >> NormalSubmodeBits::TX_ON) & 0b1) == 0b1) {
if (not checkCurrent(adcSet.processed[I_X8], upperBound, I_X8_OUT_OF_BOUNDS)) { params.getValue(PARAM_KEY_MAP[TX_U_LOWER_BOUND], lowerBound);
return; 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)) {
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;
}
} }
params.getValue(PARAM_KEY_MAP[TX_U_LOWER_BOUND], lowerBound); if (((submode >> NormalSubmodeBits::MPA_ON) & 0b1) == 0b1) {
params.getValue(PARAM_KEY_MAP[TX_U_UPPER_BOUND], upperBound); params.getValue(PARAM_KEY_MAP[MPA_U_LOWER_BOUND], lowerBound);
if (not checkVoltage(adcSet.processed[U_TX_DIV_6], lowerBound, upperBound, U_TX_OUT_OF_BOUNDS)) { params.getValue(PARAM_KEY_MAP[MPA_U_UPPER_BOUND], upperBound);
return; if (not checkVoltage(adcSet.processed[U_MPA_DIV_6], lowerBound, upperBound,
U_MPA_OUT_OF_BOUNDS)) {
return;
}
params.getValue(PARAM_KEY_MAP[MPA_I_UPPER_BOUND], upperBound);
if (not checkCurrent(adcSet.processed[I_MPA], upperBound, I_MPA_OUT_OF_BOUNDS)) {
return;
}
} }
params.getValue(PARAM_KEY_MAP[TX_I_UPPER_BOUND], upperBound); if (((submode >> NormalSubmodeBits::HPA_ON) & 0b1) == 0b1) {
if (not checkCurrent(adcSet.processed[I_TX], upperBound, I_TX_OUT_OF_BOUNDS)) { params.getValue(PARAM_KEY_MAP[HPA_U_LOWER_BOUND], lowerBound);
return; params.getValue(PARAM_KEY_MAP[HPA_U_UPPER_BOUND], upperBound);
} if (not checkVoltage(adcSet.processed[U_HPA_DIV_6], lowerBound, upperBound,
params.getValue(PARAM_KEY_MAP[MPA_U_LOWER_BOUND], lowerBound); U_HPA_OUT_OF_BOUNDS)) {
params.getValue(PARAM_KEY_MAP[MPA_U_UPPER_BOUND], upperBound); return;
if (not checkVoltage(adcSet.processed[U_MPA_DIV_6], lowerBound, upperBound, }
U_MPA_OUT_OF_BOUNDS)) { params.getValue(PARAM_KEY_MAP[HPA_I_UPPER_BOUND], upperBound);
return; if (not checkCurrent(adcSet.processed[I_HPA], upperBound, I_HPA_OUT_OF_BOUNDS)) {
} sif::warning << "PayloadPcduHandler::checkCurrent: I HPA exceeded limit: Measured "
params.getValue(PARAM_KEY_MAP[MPA_I_UPPER_BOUND], upperBound); << adcSet.processed[I_HPA] << " mA" << std::endl;
if (not checkCurrent(adcSet.processed[I_MPA], upperBound, I_MPA_OUT_OF_BOUNDS)) { return;
return; }
}
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,
U_HPA_OUT_OF_BOUNDS)) {
return;
}
params.getValue(PARAM_KEY_MAP[HPA_I_UPPER_BOUND], upperBound);
if (not checkCurrent(adcSet.processed[I_HPA], upperBound, I_HPA_OUT_OF_BOUNDS)) {
sif::warning << "PayloadPcduHandler::checkCurrent: I HPA exceeded limit: Measured "
<< adcSet.processed[I_HPA] << " mA" << std::endl;
return;
} }
transitionOk = true; transitionOk = true;
} }
@ -518,8 +531,6 @@ void PayloadPcduHandler::checkJsonFileInit() {
bool PayloadPcduHandler::checkVoltage(float val, float lowerBound, float upperBound, Event event) { bool PayloadPcduHandler::checkVoltage(float val, float lowerBound, float upperBound, Event event) {
bool tooLarge = false; 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 < lowerBound or val > upperBound) {
if (val > upperBound) { if (val > upperBound) {
tooLarge = true; tooLarge = true;