inject fuel & injector models so they can be mocked (#1697)

* stub injector model

* tests

* inject fuel/injector models

Co-authored-by: Matthew Kennedy <makenne@microsoft.com>
This commit is contained in:
Matthew Kennedy 2020-08-17 14:03:59 -07:00 committed by GitHub
parent d16dbb06c4
commit 33a2354e44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 8 deletions

View File

@ -49,6 +49,8 @@ class AirmassModelBase;
#define CYCLE_ALTERNATION 2
class IEtbController;
class IFuelComputer;
class IInjectorModel;
class TCU {
public:
@ -61,6 +63,8 @@ public:
Engine();
IEtbController *etbControllers[ETB_COUNT] = {nullptr};
IFuelComputer *fuelComputer = nullptr;
IInjectorModel *injectorModel = nullptr;
cyclic_buffer<int> triggerErrorDetection;

View File

@ -2,10 +2,15 @@
#include "engine.h"
class InjectorModelBase {
struct IInjectorModel {
virtual void prepare() = 0;
virtual floatms_t getInjectionDuration(float fuelMassGram) const = 0;
};
class InjectorModelBase : public IInjectorModel {
public:
void prepare();
floatms_t getInjectionDuration(float fuelMassGram) const;
void prepare() override;
floatms_t getInjectionDuration(float fuelMassGram) const override;
virtual floatms_t getDeadtime() const = 0;
virtual float getInjectorMassFlowRate() const = 0;
@ -15,7 +20,7 @@ private:
float m_massFlowRate = 0;
};
class InjectorModel : public InjectorModelBase {
class InjectorModel final : public InjectorModelBase {
public:
DECLARE_ENGINE_PTR;

View File

@ -193,9 +193,6 @@ AirmassModelBase* getAirmassModel(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
}
}
static FuelComputer fuelComputer(afrMap);
static InjectorModel injectorModel;
/**
* per-cylinder fuel amount
* todo: rename this method since it's now base+TPSaccel
@ -219,7 +216,7 @@ floatms_t getBaseFuel(int rpm DECLARE_ENGINE_PARAMETER_SUFFIX) {
// TODO: independently selectable ignition load mode
ENGINE(engineState.ignitionLoad) = airmass.EngineLoadPercent;
float baseFuelMass = fuelComputer.getCycleFuel(airmass.CylinderAirmass, rpm, airmass.EngineLoadPercent);
float baseFuelMass = ENGINE(fuelComputer)->getCycleFuel(airmass.CylinderAirmass, rpm, airmass.EngineLoadPercent);
float baseFuel = getInjectionDurationForFuelMass(baseFuelMass PASS_ENGINE_PARAMETER_SUFFIX) * 1000;
if (cisnan(baseFuel)) {
// todo: we should not have this here but https://github.com/rusefi/rusefi/issues/1690
@ -363,6 +360,9 @@ floatms_t getInjectorLag(float vBatt DECLARE_ENGINE_PARAMETER_SUFFIX) {
return interpolate2d("lag", vBatt, engineConfiguration->injector.battLagCorrBins, engineConfiguration->injector.battLagCorr);
}
static FuelComputer fuelComputer(afrMap);
static InjectorModel injectorModel;
/**
* @brief Initialize fuel map data structure
* @note this method has nothing to do with fuel map VALUES - it's job
@ -376,6 +376,9 @@ void initFuelMap(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
INJECT_ENGINE_REFERENCE(&fuelComputer);
INJECT_ENGINE_REFERENCE(&injectorModel);
ENGINE(fuelComputer) = &fuelComputer;
ENGINE(injectorModel) = &injectorModel;
#if (IGN_LOAD_COUNT == FUEL_LOAD_COUNT) && (IGN_RPM_COUNT == FUEL_RPM_COUNT)
fuelPhaseMap.init(config->injectionPhase, config->injPhaseLoadBins, config->injPhaseRpmBins);
#endif /* (IGN_LOAD_COUNT == FUEL_LOAD_COUNT) && (IGN_RPM_COUNT == FUEL_RPM_COUNT) */