auto-sync

This commit is contained in:
rusEfi 2015-05-12 16:04:48 -04:00
parent 6ad3564c72
commit ee89b572be
7 changed files with 33 additions and 26 deletions

View File

@ -81,13 +81,17 @@ Engine::Engine(persistent_config_s *config) {
clt.config = NULL;
clt.channel = EFI_ADC_NONE;
injectorLagMs = advance = dwellAngle = fuelMs = 0;
injectorLagMs = fuelMs = 0;
clutchDownState = clutchUpState = false;
memset(&m, 0, sizeof(m));
addConfigurationListener(invokeEnginePreCalculate);
}
EngineState::EngineState() {
advance = dwellAngle = 0;
}
/**
* Here we have a bunch of stuff which should invoked after configuration change
* so that we can prepare some helper structures
@ -174,16 +178,12 @@ void Engine::periodicFastCallback(DECLARE_ENGINE_PARAMETER_F) {
engineState.sparkDwell = getSparkDwellMsT(rpm PASS_ENGINE_PARAMETER);
// todo: move this field to engineState
dwellAngle = engineState.sparkDwell / getOneDegreeTimeMs(rpm);
engine->engineState.dwellAngle = engineState.sparkDwell / getOneDegreeTimeMs(rpm);
engine->engineState.iatFuelCorrection = getIatCorrection(engine->engineState.iat PASS_ENGINE_PARAMETER);
engine->engineState.cltFuelCorrection = getCltCorrection(engine->engineState.clt PASS_ENGINE_PARAMETER);
if (hasBaroSensor()) {
engine->engineState.baroCorrection = getBaroCorrection(PASS_ENGINE_PARAMETER_F);
} else {
engine->engineState.baroCorrection = 1;
}
engine->engineState.baroCorrection = getBaroCorrection(PASS_ENGINE_PARAMETER_F);
engine->engineState.injectionAngle = getInjectionAngle(rpm PASS_ENGINE_PARAMETER);
engine->engineState.timingAdvance = getAdvance(rpm, engineLoad PASS_ENGINE_PARAMETER);

View File

@ -72,6 +72,7 @@ public:
class EngineState {
public:
EngineState();
/**
* WIP: accessing these values here would be a performance optimization since log() function needed for
* thermistor logic is relatively heavy
@ -84,8 +85,15 @@ public:
angle_t mapAveragingDuration;
// spark-related
float sparkDwell;
float timingAdvance;
floatms_t sparkDwell;
angle_t timingAdvance;
/**
* ignition dwell duration as crankshaft angle
*/
angle_t dwellAngle;
angle_t advance;
// fuel-related;
float iatFuelCorrection;
@ -176,11 +184,6 @@ public:
*/
floatms_t fuelMs;
/**
* ignition dwell duration as crankshaft angle
*/
angle_t dwellAngle;
angle_t advance;
void periodicFastCallback(DECLARE_ENGINE_PARAMETER_F);

View File

@ -100,7 +100,7 @@ void incrementGlobalConfigurationVersion(void) {
/**
* @brief Sets the same dwell time across the whole getRpm() range
*/
void setConstantDwell(float dwellMs DECLARE_ENGINE_PARAMETER_S) {
void setConstantDwell(floatms_t dwellMs DECLARE_ENGINE_PARAMETER_S) {
for (int i = 0; i < DWELL_CURVE_SIZE; i++) {
engineConfiguration->sparkDwellBins[i] = 1000 * i;
engineConfiguration->sparkDwell[i] = dwellMs;
@ -141,7 +141,7 @@ void setWholeIatCorrTimingTable(float value DECLARE_ENGINE_PARAMETER_S) {
setTimingMap(config->ignitionIatCorrTable, value);
}
void setWholeTimingTable(float value DECLARE_ENGINE_PARAMETER_S) {
void setWholeTimingTable(angle_t value DECLARE_ENGINE_PARAMETER_S) {
setTimingMap(config->ignitionTable, value);
}

View File

@ -51,8 +51,8 @@ void setMap(fuel_table_t table, float value);
void setWholeFuelMap(float value DECLARE_ENGINE_PARAMETER_S);
void setFuelTablesLoadBin(float minValue, float maxValue DECLARE_ENGINE_PARAMETER_S);
void setWholeIatCorrTimingTable(float value DECLARE_ENGINE_PARAMETER_S);
void setWholeTimingTable(float value DECLARE_ENGINE_PARAMETER_S);
void setConstantDwell(float dwellMs DECLARE_ENGINE_PARAMETER_S);
void setWholeTimingTable(angle_t value DECLARE_ENGINE_PARAMETER_S);
void setConstantDwell(floatms_t dwellMs DECLARE_ENGINE_PARAMETER_S);
void printFloatArray(const char *prefix, float array[], int size);
void incrementGlobalConfigurationVersion(void);

View File

@ -189,7 +189,11 @@ floatms_t getBaseTableFuel(engine_configuration_s *engineConfiguration, int rpm,
}
float getBaroCorrection(DECLARE_ENGINE_PARAMETER_F) {
return baroCorrMap.getValue(getBaroPressure(), getRpm());
if (hasBaroSensor(PASS_ENGINE_PARAMETER_F)) {
return baroCorrMap.getValue(getBaroPressure(PASS_ENGINE_PARAMETER_F), getRpm());
} else {
return 1;
}
}
#if EFI_ENGINE_CONTROL

View File

@ -293,7 +293,7 @@ static void ignitionCalc(int rpm DECLARE_ENGINE_PARAMETER_S) {
return;
}
// todo: eliminate this field
engine->advance = -ENGINE(engineState.timingAdvance);
engine->engineState.advance = -ENGINE(engineState.timingAdvance);
}
#if EFI_PROD_CODE
@ -382,20 +382,20 @@ void mainTriggerCallback(trigger_event_e ckpSignalType, uint32_t eventIndex DECL
maxAllowedDwellAngle = engineConfiguration->engineCycle / engineConfiguration->specs.cylindersCount / 1.1;
}
if (engine->dwellAngle == 0) {
if (engine->engineState.dwellAngle == 0) {
warning(OBD_PCM_Processor_Fault, "dwell is zero?");
}
if (engine->dwellAngle > maxAllowedDwellAngle) {
warning(OBD_PCM_Processor_Fault, "dwell angle too long: %f", engine->dwellAngle);
if (engine->engineState.dwellAngle > maxAllowedDwellAngle) {
warning(OBD_PCM_Processor_Fault, "dwell angle too long: %f", engine->engineState.dwellAngle);
}
// todo: add some check for dwell overflow? like 4 times 6 ms while engine cycle is less then that
if (cisnan(engine->advance)) {
if (cisnan(engine->engineState.advance)) {
// error should already be reported
return;
}
initializeIgnitionActions(engine->advance, engine->dwellAngle,
initializeIgnitionActions(engine->engineState.advance, engine->engineState.dwellAngle,
&engine->engineConfiguration2->ignitionEvents[revolutionIndex] PASS_ENGINE_PARAMETER);
engine->m.ignitionSchTime = GET_TIMESTAMP() - engine->m.beforeIgnitionSch;

View File

@ -410,7 +410,7 @@ static void testRpmCalculator(void) {
eth.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_UP PASS_ENGINE_PARAMETER);
assertEqualsM("dwell", 4.5, eth.engine.dwellAngle);
assertEqualsM("dwell", 4.5, eth.engine.engineState.dwellAngle);
assertEqualsM("fuel", 3.03, eth.engine.fuelMs);
assertEqualsM("one degree", 111.1111, eth.engine.rpmCalculator.oneDegreeUs);
assertEqualsM("size", 6, ilist->size);