#35 unit tests

This commit is contained in:
rusefi 2019-01-19 09:40:39 -05:00
parent c6f19d77be
commit 8b66bdc86b
4 changed files with 23 additions and 18 deletions

View File

@ -299,10 +299,7 @@ void hipAdcCallback(adcsample_t adcValue) {
hipValueMax = maxF(engine->knockVolts, hipValueMax);
engine->knockLogic(engine->knockVolts);
float angleWindowWidth =
engineConfiguration->knockDetectionWindowEnd - engineConfiguration->knockDetectionWindowStart;
instance.setAngleWindowWidth(angleWindowWidth);
instance.setAngleWindowWidth();
instance.handleValue(GET_RPM() DEFINE_PARAM_SUFFIX(PASS_HIP_PARAMS));
@ -385,7 +382,7 @@ void initHip9011(Logging *sharedLogger) {
return;
instance.setAngleWindowWidth(engineConfiguration->knockDetectionWindowEnd - engineConfiguration->knockDetectionWindowStart);
instance.setAngleWindowWidth();
#if EFI_PROD_CODE
driver = getSpiDevice(engineConfiguration->hip9011SpiDevice);

View File

@ -78,7 +78,8 @@ int HIP9011::getIntegrationIndexByRpm(float rpm) {
return i == -1 ? INT_LOOKUP_SIZE - 1 : INT_LOOKUP_SIZE - i - 1;
}
void HIP9011::setAngleWindowWidth(float angleWindowWidth) {
void HIP9011::setAngleWindowWidth(DEFINE_HIP_PARAMS) {
float angleWindowWidth = GET_CONFIG_VALUE(knockDetectionWindowEnd) - GET_CONFIG_VALUE(knockDetectionWindowStart);
// float '==' is totally appropriate here
if (this->angleWindowWidth == angleWindowWidth)
return; // exit if value has not change

View File

@ -32,17 +32,24 @@ public:
#define PASS_HIP_PARAMS CONFIG(knockBandCustom), \
CONFIG(cylinderBore), \
CONFIG(hip9011Gain), \
CONFIG(hip9011PrescalerAndSDO)
CONFIG(hip9011PrescalerAndSDO), \
CONFIG(knockDetectionWindowStart), \
CONFIG(knockDetectionWindowEnd)
#define FORWARD_HIP_PARAMS knockBandCustom, \
cylinderBore, \
hip9011Gain, \
hip9011PrescalerAndSDO
hip9011PrescalerAndSDO, \
knockDetectionWindowStart, \
knockDetectionWindowEnd
#define DEFINE_HIP_PARAMS float knockBandCustom,\
float cylinderBore, \
float hip9011Gain, \
int hip9011PrescalerAndSDO
int hip9011PrescalerAndSDO, \
float knockDetectionWindowStart, \
float knockDetectionWindowEnd
#define GET_CONFIG_VALUE(x) x
#define DEFINE_PARAM_SUFFIX(x) , x
@ -54,7 +61,7 @@ public:
void prepareHip9011RpmLookup(float angleWindowWidth);
int getIntegrationIndexByRpm(float rpm);
void setStateAndCommand(unsigned char cmd);
void setAngleWindowWidth(float angleWindowWidth);
void setAngleWindowWidth(DEFINE_HIP_PARAMS);
void handleValue(int rpm DEFINE_PARAM_SUFFIX(DEFINE_HIP_PARAMS));
/**

View File

@ -18,10 +18,10 @@ TEST(hip9011, lookup) {
assertEqualsM2("240us 50 degree", 1105.2435, getRpmByAngleWindowAndTimeUs(240, 50), 0.1);
assertEqualsM2("240us 50 degree", 6631.4619, getRpmByAngleWindowAndTimeUs(40, 50), 0.1);
EXPECT_EQ(0, getHip9011GainIndex(/* knockBandCustom*/NAN, /*cylinderBore*/NAN, /*hip9011Gain*/3, 0));
EXPECT_EQ(0, getHip9011GainIndex(/* knockBandCustom*/NAN, /*cylinderBore*/NAN, /*hip9011Gain*/2, 0));
EXPECT_EQ(47, getHip9011GainIndex(/* knockBandCustom*/NAN, /*cylinderBore*/NAN, /*hip9011Gain*/0.234, 0));
EXPECT_EQ(63, getHip9011GainIndex(/* knockBandCustom*/NAN, /*cylinderBore*/NAN, /*hip9011Gain*/0.000001, 0));
EXPECT_EQ(0, getHip9011GainIndex(/* knockBandCustom*/NAN, /*cylinderBore*/NAN, /*hip9011Gain*/3, 0, NAN, NAN));
EXPECT_EQ(0, getHip9011GainIndex(/* knockBandCustom*/NAN, /*cylinderBore*/NAN, /*hip9011Gain*/2, 0, NAN, NAN));
EXPECT_EQ(47, getHip9011GainIndex(/* knockBandCustom*/NAN, /*cylinderBore*/NAN, /*hip9011Gain*/0.234, 0, NAN, NAN));
EXPECT_EQ(63, getHip9011GainIndex(/* knockBandCustom*/NAN, /*cylinderBore*/NAN, /*hip9011Gain*/0.000001, 0, NAN, NAN));
}
@ -38,10 +38,10 @@ TEST(hip9011, rpmLookup) {
TEST(hip9011, band) {
EXPECT_FLOAT_EQ(3, getHIP9011Band(/* knockBandCustom*/3, /*cylinderBore*/76, /*hip9011Gain*/NAN, 0));
EXPECT_FLOAT_EQ(7.5389242, getHIP9011Band(/* knockBandCustom*/0, /*cylinderBore*/76, /*hip9011Gain*/NAN, 0));
EXPECT_FLOAT_EQ(3, getHIP9011Band(/* knockBandCustom*/3, /*cylinderBore*/76, /*hip9011Gain*/NAN, 0, NAN, NAN));
EXPECT_FLOAT_EQ(7.5389242, getHIP9011Band(/* knockBandCustom*/0, /*cylinderBore*/76, /*hip9011Gain*/NAN, 0, NAN, NAN));
EXPECT_EQ(42, getBandIndex(/* knockBandCustom*/0, /*cylinderBore*/76, /*hip9011Gain*/NAN, 0));
EXPECT_EQ(42, getBandIndex(/* knockBandCustom*/0, /*cylinderBore*/76, /*hip9011Gain*/NAN, 0, NAN, NAN));
}
@ -63,7 +63,7 @@ TEST(hip9011, configurationCommands) {
instance.prepareHip9011RpmLookup(50);
// want to invoke method with same parameters a few times
#define PARAMETERS 600, /* knockBandCustom*/0, /*cylinderBore*/76, /*hip9011Gain*/1, _8MHZ_PRESCALER
#define PARAMETERS 600, /* knockBandCustom*/0, /*cylinderBore*/76, /*hip9011Gain*/1, _8MHZ_PRESCALER, NAN, NAN
// Not making assumptions on the message send ...
EXPECT_CALL(mock, sendSyncCommand(_)).Times(0);