maybe fix sensor init checks (#2034)

* enums

* don't collide

* auto_generated_enums

* check based on new enum val

* maybe this will make generate tool happy

* add a test

* fix test

* fix and add another test

* make clang happier

Co-authored-by: Matthew Kennedy <makenne@microsoft.com>
This commit is contained in:
Matthew Kennedy 2020-12-06 22:19:57 -06:00 committed by GitHub
parent 22c74895a6
commit 67269aa637
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 39 additions and 36 deletions

View File

@ -104,6 +104,8 @@ case EFI_ADC_9:
return "EFI_ADC_9";
case EFI_ADC_ERROR:
return "EFI_ADC_ERROR";
case EFI_ADC_LAST_CHANNEL:
return "EFI_ADC_LAST_CHANNEL";
case EFI_ADC_NONE:
return "EFI_ADC_NONE";
}

View File

@ -285,10 +285,7 @@ typedef enum __attribute__ ((__packed__)) {
EFI_ADC_29 = 30,
EFI_ADC_30 = 31,
EFI_ADC_31 = 32,
EFI_ADC_LAST_CHANNEL = 33, // Please keep this in sync with the last valid channel index!
// todo: bad choice of value since now we have ADC_CHANNEL_SENSOR and could end up with 17 and 18 also
EFI_ADC_ERROR = 33,
EFI_ADC_ERROR = 50,
} adc_channel_e;
/* Plase keep updating this define */
#define EFI_ADC_LAST EFI_ADC_31

View File

@ -72,6 +72,8 @@ case EFI_ADC_9:
return "EFI_ADC_9";
case EFI_ADC_ERROR:
return "EFI_ADC_ERROR";
case EFI_ADC_LAST_CHANNEL:
return "EFI_ADC_LAST_CHANNEL";
case EFI_ADC_NONE:
return "EFI_ADC_NONE";
}

View File

@ -176,10 +176,7 @@ typedef enum __attribute__ ((__packed__)) {
EFI_ADC_13 = 14,
EFI_ADC_14 = 15,
EFI_ADC_15 = 16,
EFI_ADC_LAST_CHANNEL = 17, // Please keep this in sync with the last valid channel index!
// todo: bad choice of value since now we have ADC_CHANNEL_SENSOR and could end up with 17 and 18 also
EFI_ADC_ERROR = 17,
EFI_ADC_ERROR = 50,
} adc_channel_e;
/* Plase keep updating this define */
#define EFI_ADC_LAST EFI_ADC_15

View File

@ -72,6 +72,8 @@ case EFI_ADC_9:
return "EFI_ADC_9";
case EFI_ADC_ERROR:
return "EFI_ADC_ERROR";
case EFI_ADC_LAST_CHANNEL:
return "EFI_ADC_LAST_CHANNEL";
case EFI_ADC_NONE:
return "EFI_ADC_NONE";
case EFI_ADC_TEMP_SENSOR:

View File

@ -270,8 +270,7 @@ typedef enum __attribute__ ((__packed__)) {
EFI_ADC_TEMP_SENSOR = 17, // Internal temp sensor
EFI_ADC_LAST_CHANNEL = 18, // Please keep this in sync with the last valid channel index!
EFI_ADC_ERROR = 50,
} adc_channel_e;
/* Plase keep updating this define */
#define EFI_ADC_LAST EFI_ADC_TEMP_SENSOR

View File

@ -39,7 +39,12 @@ LinearFunc idlePosFunc(PACK_MULT_VOLTAGE);
FunctionalSensor wastegateSens(SensorType::WastegatePosition, MS2NT(10));
FunctionalSensor idlePosSens(SensorType::IdlePosition, MS2NT(10));
static bool configureTps(LinearFunc& func, float closed, float open, float min, float max, const char* msg) {
static bool configureTps(LinearFunc& func, adc_channel_e channel, float closed, float open, float min, float max, const char* msg) {
// Only configure if we have a channel
if (channel == EFI_ADC_NONE || channel >= EFI_ADC_LAST_CHANNEL) {
return false;
}
float scaledClosed = closed / func.getDivideInput();
float scaledOpen = open / func.getDivideInput();
@ -47,13 +52,10 @@ static bool configureTps(LinearFunc& func, float closed, float open, float min,
// If the voltage for closed vs. open is very near, something is wrong with your calibration
if (split < 0.5f) {
/*
* todo: fix this, this fails HW CI at the moment
firmwareError(OBD_Throttle_Position_Sensor_Circuit_Malfunction, "Sensor \"%s\" problem: open %f/closed %f calibration values are too close together. Please check your wiring!", msg,
open,
closed);
return false;
*/
}
func.configure(
@ -66,13 +68,8 @@ static bool configureTps(LinearFunc& func, float closed, float open, float min,
}
static bool initTpsFunc(LinearFunc& func, FunctionalSensor& sensor, adc_channel_e channel, float closed, float open, float min, float max) {
// Only register if we have a sensor
if (channel == EFI_ADC_NONE) {
return false;
}
// If the configuration was invalid, don't continues to configure the sensor
if (!configureTps(func, closed, open, min, max, sensor.getSensorName())) {
// If the configuration was invalid, don't continue to configure the sensor
if (!configureTps(func, channel, closed, open, min, max, sensor.getSensorName())) {
return false;
}
@ -122,14 +119,14 @@ void reconfigureTps(DECLARE_CONFIG_PARAMETER_SIGNATURE) {
float min = CONFIG(tpsErrorDetectionTooLow);
float max = CONFIG(tpsErrorDetectionTooHigh);
configureTps(tpsFunc1p, CONFIG(tpsMin), CONFIG(tpsMax), min, max, tpsSens1p.getSensorName());
configureTps(tpsFunc1s, CONFIG(tps1SecondaryMin), CONFIG(tps1SecondaryMax), min, max, tpsSens1s.getSensorName());
configureTps(tpsFunc2p, CONFIG(tps2Min), CONFIG(tps2Max), min, max, tpsSens2p.getSensorName());
configureTps(tpsFunc2s, CONFIG(tps2SecondaryMin), CONFIG(tps2SecondaryMax), min, max, tpsSens2s.getSensorName());
configureTps(tpsFunc1p, CONFIG(tps1_1AdcChannel), CONFIG(tpsMin), CONFIG(tpsMax), min, max, tpsSens1p.getSensorName());
configureTps(tpsFunc1s, CONFIG(tps1_2AdcChannel), CONFIG(tps1SecondaryMin), CONFIG(tps1SecondaryMax), min, max, tpsSens1s.getSensorName());
configureTps(tpsFunc2p, CONFIG(tps2_1AdcChannel), CONFIG(tps2Min), CONFIG(tps2Max), min, max, tpsSens2p.getSensorName());
configureTps(tpsFunc2s, CONFIG(tps2_2AdcChannel), CONFIG(tps2SecondaryMin), CONFIG(tps2SecondaryMax), min, max, tpsSens2s.getSensorName());
configureTps(pedalFuncPrimary, CONFIG(throttlePedalUpVoltage), CONFIG(throttlePedalWOTVoltage), min, max, pedalSensorPrimary.getSensorName());
configureTps(pedalFuncSecondary, CONFIG(throttlePedalSecondaryUpVoltage), CONFIG(throttlePedalSecondaryWOTVoltage), min, max, pedalSensorSecondary.getSensorName());
configureTps(pedalFuncPrimary, CONFIG(throttlePedalPositionAdcChannel), CONFIG(throttlePedalUpVoltage), CONFIG(throttlePedalWOTVoltage), min, max, pedalSensorPrimary.getSensorName());
configureTps(pedalFuncSecondary, CONFIG(throttlePedalPositionSecondAdcChannel), CONFIG(throttlePedalSecondaryUpVoltage), CONFIG(throttlePedalSecondaryWOTVoltage), min, max, pedalSensorSecondary.getSensorName());
configureTps(wastegateFunc, CONFIG(wastegatePositionMin), CONFIG(wastegatePositionMax), min, max, wastegateSens.getSensorName());
configureTps(idlePosFunc, CONFIG(idlePositionMin), CONFIG(idlePositionMax), min, max, idlePosSens.getSensorName());
configureTps(wastegateFunc, CONFIG(wastegatePositionSensor), CONFIG(wastegatePositionMin), CONFIG(wastegatePositionMax), min, max, wastegateSens.getSensorName());
configureTps(idlePosFunc, CONFIG(idlePositionSensor), CONFIG(idlePositionMin), CONFIG(idlePositionMax), min, max, idlePosSens.getSensorName());
}

View File

@ -52,8 +52,6 @@ TEST(SensorInit, Tps) {
}
TEST(SensorInit, TpsValuesTooClose) {
/*
* todo: fix this, this fails HW CI at the moment
WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
// Should fail, 0.49 volts apart
@ -82,12 +80,21 @@ TEST(SensorInit, TpsValuesTooClose) {
// With no pin, it should be ok that they are the same
// Should succeed, -0.51 volts apart
CONFIG(tps1_1AdcChannel) = ADC_CHANNEL_NONE;
CONFIG(tps1_1AdcChannel) = EFI_ADC_NONE;
CONFIG(tpsMin) = 200; // 1.00 volt
CONFIG(tpsMax) = 200; // 1.00 volts
EXPECT_NO_FATAL_ERROR(initTps(PASS_CONFIG_PARAMETER_SIGNATURE));
Sensor::resetRegistry();
*/
// Test a random bogus pin index, shouldn't fail
CONFIG(tps1_1AdcChannel) = static_cast<adc_channel_e>(175);
CONFIG(tpsMin) = 200; // 1.00 volt
CONFIG(tpsMax) = 200; // 1.00 volt
EXPECT_NO_FATAL_ERROR(initTps(PASS_CONFIG_PARAMETER_SIGNATURE));
Sensor::resetRegistry();
// Reconfiguration should also work without error
EXPECT_NO_FATAL_ERROR(reconfigureTps(PASS_CONFIG_PARAMETER_SIGNATURE));
}
TEST(SensorInit, Pedal) {