better corner case logging, also refactoring

This commit is contained in:
rusefi 2017-04-12 19:58:29 -04:00
parent e76c6e251b
commit a3b13364da
4 changed files with 15 additions and 13 deletions

View File

@ -523,7 +523,7 @@ static void showFuelInfo2(float rpm, float engineLoad) {
scheduleMsg(&logger2, "iatCorrection=%f cltCorrection=%f injectorLag=%f", iatCorrection, cltCorrection, scheduleMsg(&logger2, "iatCorrection=%f cltCorrection=%f injectorLag=%f", iatCorrection, cltCorrection,
injectorLag); injectorLag);
float value = getRunningFuel(baseFuelMs, (int) rpm PASS_ENGINE_PARAMETER); float value = getRunningFuel(baseFuelMs PASS_ENGINE_PARAMETER);
scheduleMsg(&logger2, "injection pulse width: %f", value); scheduleMsg(&logger2, "injection pulse width: %f", value);
} }
#endif #endif

View File

@ -127,16 +127,18 @@ percent_t getInjectorDutyCycle(int rpm DECLARE_ENGINE_PARAMETER_S) {
*/ */
floatms_t getInjectionDuration(int rpm DECLARE_ENGINE_PARAMETER_S) { floatms_t getInjectionDuration(int rpm DECLARE_ENGINE_PARAMETER_S) {
float theoreticalInjectionLength; float theoreticalInjectionLength;
if (isCrankingR(rpm)) { bool isCranking = isCrankingR(rpm);
int numberOfCylinders = getNumberOfInjections(engineConfiguration->crankingInjectionMode PASS_ENGINE_PARAMETER); int numberOfCylinders = getNumberOfInjections(isCranking ?
efiAssert(numberOfCylinders > 0, "cranking numberOfCylinders", 0); engineConfiguration->crankingInjectionMode :
theoreticalInjectionLength = getCrankingFuel(PASS_ENGINE_PARAMETER_F) engineConfiguration->injectionMode PASS_ENGINE_PARAMETER);
/ numberOfCylinders; if (numberOfCylinders == 0) {
return 0; // we can end up here during configuration reset
}
if (isCranking) {
theoreticalInjectionLength = getCrankingFuel(PASS_ENGINE_PARAMETER_F) / numberOfCylinders;
} else { } else {
floatms_t baseFuel = getBaseFuel(rpm PASS_ENGINE_PARAMETER); floatms_t baseFuel = getBaseFuel(rpm PASS_ENGINE_PARAMETER);
floatms_t fuelPerCycle = getRunningFuel(baseFuel, rpm PASS_ENGINE_PARAMETER); floatms_t fuelPerCycle = getRunningFuel(baseFuel PASS_ENGINE_PARAMETER);
int numberOfCylinders = getNumberOfInjections(engineConfiguration->injectionMode PASS_ENGINE_PARAMETER);
efiAssert(numberOfCylinders > 0, "running numberOfCylinders", 0);
theoreticalInjectionLength = fuelPerCycle / numberOfCylinders; theoreticalInjectionLength = fuelPerCycle / numberOfCylinders;
#if EFI_PRINTF_FUEL_DETAILS || defined(__DOXYGEN__) #if EFI_PRINTF_FUEL_DETAILS || defined(__DOXYGEN__)
printf("baseFuel=%f fuelPerCycle=%f theoreticalInjectionLength=%f\t\n", printf("baseFuel=%f fuelPerCycle=%f theoreticalInjectionLength=%f\t\n",
@ -146,7 +148,7 @@ floatms_t getInjectionDuration(int rpm DECLARE_ENGINE_PARAMETER_S) {
return theoreticalInjectionLength + ENGINE(engineState.injectorLag); return theoreticalInjectionLength + ENGINE(engineState.injectorLag);
} }
floatms_t getRunningFuel(floatms_t baseFuel, int rpm DECLARE_ENGINE_PARAMETER_S) { floatms_t getRunningFuel(floatms_t baseFuel DECLARE_ENGINE_PARAMETER_S) {
float iatCorrection = ENGINE(engineState.iatFuelCorrection); float iatCorrection = ENGINE(engineState.iatFuelCorrection);
float cltCorrection = ENGINE(engineState.cltFuelCorrection); float cltCorrection = ENGINE(engineState.cltFuelCorrection);

View File

@ -20,7 +20,7 @@ floatms_t getBaseFuel(int rpm DECLARE_ENGINE_PARAMETER_S);
/** /**
* @return baseFuel with CLT and IAT corrections * @return baseFuel with CLT and IAT corrections
*/ */
floatms_t getRunningFuel(floatms_t baseFuel, int rpm DECLARE_ENGINE_PARAMETER_S); floatms_t getRunningFuel(floatms_t baseFuel DECLARE_ENGINE_PARAMETER_S);
floatms_t getRealMafFuel(float airMass, int rpm DECLARE_ENGINE_PARAMETER_S); floatms_t getRealMafFuel(float airMass, int rpm DECLARE_ENGINE_PARAMETER_S);

View File

@ -71,7 +71,7 @@ void testFuelMap(void) {
printf("*************************************************** getRunningFuel 1\r\n"); printf("*************************************************** getRunningFuel 1\r\n");
eth.engine.periodicFastCallback(PASS_ENGINE_PARAMETER_F); eth.engine.periodicFastCallback(PASS_ENGINE_PARAMETER_F);
float baseFuel = getBaseTableFuel(eth.engine.engineConfiguration, 5, getEngineLoadT(PASS_ENGINE_PARAMETER_F)); float baseFuel = getBaseTableFuel(eth.engine.engineConfiguration, 5, getEngineLoadT(PASS_ENGINE_PARAMETER_F));
assertEqualsM("base fuel", 5.05, getRunningFuel(baseFuel, 5 PASS_ENGINE_PARAMETER)); assertEqualsM("base fuel", 5.05, getRunningFuel(baseFuel PASS_ENGINE_PARAMETER));
printf("*************************************************** setting IAT table\r\n"); printf("*************************************************** setting IAT table\r\n");
for (int i = 0; i < IAT_CURVE_SIZE; i++) { for (int i = 0; i < IAT_CURVE_SIZE; i++) {
@ -103,7 +103,7 @@ void testFuelMap(void) {
printf("*************************************************** getRunningFuel 2\r\n"); printf("*************************************************** getRunningFuel 2\r\n");
eth.engine.periodicFastCallback(PASS_ENGINE_PARAMETER_F); eth.engine.periodicFastCallback(PASS_ENGINE_PARAMETER_F);
baseFuel = getBaseTableFuel(eth.engine.engineConfiguration, 5, getEngineLoadT(PASS_ENGINE_PARAMETER_F)); baseFuel = getBaseTableFuel(eth.engine.engineConfiguration, 5, getEngineLoadT(PASS_ENGINE_PARAMETER_F));
assertEqualsM("v1", 30150, getRunningFuel(baseFuel, 5 PASS_ENGINE_PARAMETER)); assertEqualsM("v1", 30150, getRunningFuel(baseFuel PASS_ENGINE_PARAMETER));
testMafValue = 0; testMafValue = 0;