better error checking of thermistor config (#2199)

* add bounds check on result

* validate thermistor config

Co-authored-by: Matthew Kennedy <makenne@microsoft.com>
This commit is contained in:
Matthew Kennedy 2021-01-07 17:37:15 -08:00 committed by GitHub
parent 0b601bb4a6
commit 44b5427813
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View File

@ -25,6 +25,12 @@ SensorResult ThermistorFunc::convert(float ohms) const {
float celsius = convertKelvinToCelcius(kelvin);
// bounds check result - please don't try to run rusEfi when colder than -50C
// high end limit is required as this could be an oil temp sensor
if (celsius < -50 || celsius > 200) {
return unexpected;
}
return celsius;
}

View File

@ -27,12 +27,25 @@ static CCM_OPTIONAL FunctionalSensor aux2(SensorType::AuxTemp2, MS2NT(10));
static FuncPair fclt, fiat, faux1, faux2;
void validateThermistorConfig(thermistor_conf_s& cfg) {
if (
cfg.tempC_1 >= cfg.tempC_2 ||
cfg.tempC_2 >= cfg.tempC_3 ||
cfg.resistance_1 < cfg.resistance_2 ||
cfg.resistance_2 < cfg.resistance_3
) {
firmwareError(OBD_Engine_Coolant_Temperature_Circuit_Malfunction, "Invalid thermistor configuration: please check that temperatures & resistances are in the correct order.");
}
}
static SensorConverter& configureTempSensorFunction(thermistor_conf_s& cfg, FuncPair& p, bool isLinear) {
if (isLinear) {
p.linear.configure(cfg.resistance_1, cfg.tempC_1, cfg.resistance_2, cfg.tempC_2, -50, 250);
return p.linear;
} else /* sensor is thermistor */ {
validateThermistorConfig(cfg);
p.thermistor.get<resist>().configure(5.0f, cfg.bias_resistor);
p.thermistor.get<therm>().configure(cfg);