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:
parent
0b601bb4a6
commit
44b5427813
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in New Issue