refactoring around "stopEngine" logic

This commit is contained in:
rusefi 2019-01-05 23:33:04 -05:00
parent aced64810f
commit 5b74163136
7 changed files with 30 additions and 13 deletions

View File

@ -116,6 +116,15 @@ Engine::Engine(persistent_config_s *config) {
reset();
}
/**
* @see scheduleStopEngine()
* @return true if there is a reason to stop engine
*/
bool Engine::needToStopEngine(efitick_t nowNt) {
return stopEngineRequestTimeNt != 0 &&
nowNt - stopEngineRequestTimeNt < 3 * US2NT(US_PER_SECOND_LL);
}
void Engine::reset() {
withError = isEngineChartEnabled = false;
etbAutoTune = false;
@ -270,9 +279,13 @@ void Engine::checkShutdown() {
#if EFI_MAIN_RELAY_CONTROL || defined(__DOXYGEN__)
int rpm = rpmCalculator.getRpm();
/**
* Something is weird here: "below 5.0 volts on battery" what is it about? Is this about
* Frankenso powering everything while driver has already turned ignition off? or what is this condition about?
*/
const float vBattThreshold = 5.0f;
if (isValidRpm(rpm) && sensors.vBatt < vBattThreshold && stopEngineRequestTimeNt == 0) {
stopEngine();
scheduleStopEngine();
// todo: add stepper motor parking
}
#endif /* EFI_MAIN_RELAY_CONTROL */

View File

@ -304,7 +304,7 @@ public:
float fsioLastValue[FSIO_COMMAND_COUNT];
WallFuel wallFuel;
bool needToStopEngine(efitick_t nowNt);
bool etbAutoTune;
/**
* That's the list of pending spark firing events

View File

@ -258,7 +258,7 @@ void runIoTest(int subsystem, int index) {
// call to pit
setCallFromPitStop(30000);
} else if (subsystem == 0x99) {
stopEngine();
scheduleStopEngine();
}
}

View File

@ -75,7 +75,7 @@ static MenuItem miMapV(&miSensors, LL_MAF_V);
static MenuItem miMapKgHr(&miSensors, LL_MAF_KG_HR);
static MenuItem miKnock(&miSensors, LL_KNOCK);
static MenuItem miStopEngine(&miBench, "stop engine", stopEngine);
static MenuItem miStopEngine(&miBench, "stop engine", scheduleStopEngine);
static MenuItem miTestFan(&miBench, "test fan", fanBench);
static MenuItem miTestFuelPump(&miBench, "test pump", fuelPumpBench);
static MenuItem miTestMIL(&miBench, "test MIL", milBench);

View File

@ -970,7 +970,11 @@ static void disableSpi(int index) {
setSpiMode(index, false);
}
void stopEngine(void) {
/**
* See 'Engine::needToStopEngine' for code which actually stops engine
* weird: we stop pins from here? we probably should stop engine from the code which is actually stopping engine?
*/
void scheduleStopEngine(void) {
engine->stopEngineRequestTimeNt = getTimeNowNt();
// let's close injectors or else if these happen to be open right now
enginePins.stopPins();
@ -1339,7 +1343,7 @@ void initSettings(void) {
addConsoleActionSSS("set_timing_map", setTimingMap);
addConsoleAction("stopengine", (Void) stopEngine);
addConsoleAction("stopengine", (Void) scheduleStopEngine);
// todo: refactor this - looks like all boolean flags should be controlled with less code duplication
addConsoleActionI("enable_spi", enableSpi);

View File

@ -14,7 +14,7 @@
void initSettings(void);
void printSpiState(Logging *logger, board_configuration_s *boardConfiguration);
void printConfiguration(const engine_configuration_s *engineConfiguration);
void stopEngine(void);
void scheduleStopEngine(void);
void setCallFromPitStop(int durationMs);
void setEngineType(int value);
/**

View File

@ -90,6 +90,9 @@ bool RpmCalculator::isRunning(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
return state == RUNNING;
}
/**
* @return true if engine is spinning (cranking or running)
*/
bool RpmCalculator::checkIfSpinning(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
if (lastRpmEventTimeNt == 0) {
// here we assume 64 bit time does not overflow
@ -97,12 +100,9 @@ bool RpmCalculator::checkIfSpinning(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
return false;
}
efitick_t nowNt = getTimeNowNt();
if (ENGINE(stopEngineRequestTimeNt) != 0) {
if (nowNt - ENGINE(stopEngineRequestTimeNt) < 3 * US2NT(US_PER_SECOND_LL)) {
// 'stopengine' command implementation
setStopped(PASS_ENGINE_PARAMETER_SIGNATURE);
return false;
}
if (ENGINE(needToStopEngine(nowNt))) {
setStopped(PASS_ENGINE_PARAMETER_SIGNATURE);
return false;
}
/**