rusefi-1/unit_tests/engine_test_helper.cpp

119 lines
4.7 KiB
C++
Raw Normal View History

2015-07-10 06:01:56 -07:00
/**
* @file engine_test_helper.cpp
*
* @date Jun 26, 2014
* @author Andrey Belomutskiy, (c) 2012-2014
*/
#include "engine_test_helper.h"
#include "stddef.h"
#include "trigger_decoder.h"
#include "speed_density.h"
#include "fuel_math.h"
2016-03-11 08:03:18 -08:00
#include "accel_enrichment.h"
2016-08-26 14:02:37 -07:00
#include "thermistors.h"
2016-08-26 15:02:39 -07:00
#include "advance_map.h"
2016-11-07 19:02:21 -08:00
#include "event_queue.h"
2015-07-10 06:01:56 -07:00
2018-03-04 13:30:03 -08:00
extern int timeNowUs;
2016-11-03 20:02:58 -07:00
extern EnginePins enginePins;
2016-11-07 19:02:21 -08:00
extern EventQueue schedulingQueue;
2017-03-28 15:59:42 -07:00
extern int unitTestWarningCounter;
2018-03-04 17:14:47 -08:00
extern float testMafValue;
2018-03-04 18:10:00 -08:00
extern engine_configuration_s activeConfiguration;
2015-07-10 06:01:56 -07:00
EngineTestHelper::EngineTestHelper(engine_type_e engineType) : engine (&persistentConfig) {
ec = &persistentConfig.engineConfiguration;
2017-03-28 15:59:42 -07:00
unitTestWarningCounter = 0;
2015-07-10 06:01:56 -07:00
2018-03-04 17:14:47 -08:00
testMafValue = 0;
2018-03-04 18:10:00 -08:00
memset(&activeConfiguration, 0, sizeof(activeConfiguration));
2018-03-04 17:14:47 -08:00
2016-11-07 19:02:21 -08:00
schedulingQueue.clear();
2016-11-01 06:02:29 -07:00
enginePins.reset();
2016-09-03 16:02:42 -07:00
2015-07-10 06:01:56 -07:00
engineConfiguration = ec;
board_configuration_s * boardConfiguration = &engineConfiguration->bc;
persistent_config_s *config = &persistentConfig;
2017-06-11 12:12:41 -07:00
setCurveValue(config->cltFuelCorrBins, config->cltFuelCorr, CLT_CURVE_SIZE, -40, 1.5);
setCurveValue(config->cltFuelCorrBins, config->cltFuelCorr, CLT_CURVE_SIZE, -30, 1.5);
setCurveValue(config->cltFuelCorrBins, config->cltFuelCorr, CLT_CURVE_SIZE, -20, 1.42);
setCurveValue(config->cltFuelCorrBins, config->cltFuelCorr, CLT_CURVE_SIZE, -10, 1.36);
setCurveValue(config->cltFuelCorrBins, config->cltFuelCorr, CLT_CURVE_SIZE, 0, 1.28);
setCurveValue(config->cltFuelCorrBins, config->cltFuelCorr, CLT_CURVE_SIZE, 10, 1.19);
setCurveValue(config->cltFuelCorrBins, config->cltFuelCorr, CLT_CURVE_SIZE, 20, 1.12);
setCurveValue(config->cltFuelCorrBins, config->cltFuelCorr, CLT_CURVE_SIZE, 30, 1.10);
setCurveValue(config->cltFuelCorrBins, config->cltFuelCorr, CLT_CURVE_SIZE, 40, 1.06);
setCurveValue(config->cltFuelCorrBins, config->cltFuelCorr, CLT_CURVE_SIZE, 50, 1.06);
setCurveValue(config->cltFuelCorrBins, config->cltFuelCorr, CLT_CURVE_SIZE, 60, 1.03);
setCurveValue(config->cltFuelCorrBins, config->cltFuelCorr, CLT_CURVE_SIZE, 70, 1.01);
2015-07-10 06:01:56 -07:00
Engine *engine = &this->engine;
2017-05-15 20:28:49 -07:00
prepareFuelMap(PASS_ENGINE_PARAMETER_SIGNATURE);
2015-07-10 06:01:56 -07:00
2017-05-15 20:28:49 -07:00
initAccelEnrichment(NULL PASS_ENGINE_PARAMETER_SUFFIX);
2015-07-10 06:01:56 -07:00
2017-05-15 20:28:49 -07:00
initSpeedDensity(PASS_ENGINE_PARAMETER_SIGNATURE);
2015-07-10 06:01:56 -07:00
2017-05-15 20:28:49 -07:00
resetConfigurationExt(NULL, engineType PASS_ENGINE_PARAMETER_SUFFIX);
prepareShapes(PASS_ENGINE_PARAMETER_SIGNATURE);
2015-07-10 06:01:56 -07:00
engine->engineConfiguration->mafAdcChannel = (adc_channel_e)TEST_MAF_CHANNEL;
2016-08-26 14:02:37 -07:00
2017-05-15 20:28:49 -07:00
initThermistors(NULL PASS_ENGINE_PARAMETER_SUFFIX);
2016-08-26 14:02:37 -07:00
// this is needed to have valid CLT and IAT.
2017-05-15 20:28:49 -07:00
engine->updateSlowSensors(PASS_ENGINE_PARAMETER_SIGNATURE);
prepareTimingMap(PASS_ENGINE_PARAMETER_SIGNATURE);
2016-08-26 17:03:06 -07:00
engine_configuration_s *engineConfiguration = engine->engineConfiguration;
2017-05-15 20:28:49 -07:00
engine->triggerCentral.triggerShape.initializeTriggerShape(NULL PASS_ENGINE_PARAMETER_SUFFIX);
2016-08-26 17:03:06 -07:00
engine->triggerCentral.addEventListener(rpmShaftPositionCallback, "rpm reporter", engine);
2016-08-26 20:02:24 -07:00
engine->triggerCentral.addEventListener(mainTriggerCallback, "main loop", engine);
2015-07-10 06:01:56 -07:00
}
2016-08-27 16:02:43 -07:00
void EngineTestHelper::firePrimaryTriggerRise() {
board_configuration_s * boardConfiguration = &engine.engineConfiguration->bc;
engine.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_RISING, &engine, engine.engineConfiguration, &persistentConfig, boardConfiguration);
}
void EngineTestHelper::firePrimaryTriggerFall() {
board_configuration_s * boardConfiguration = &engine.engineConfiguration->bc;
engine.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_FALLING, &engine, engine.engineConfiguration, &persistentConfig, boardConfiguration);
}
2018-03-04 13:34:23 -08:00
/**
* Sends specified number of rise/fall trigger events, with specified amount of time between those.
*
* This is helpful for TT_ONE trigger wheel decoder and probably other decoders as well.
*/
void EngineTestHelper::fireTriggerEvents2(int count, int durationUs) {
2016-01-24 22:02:55 -08:00
for (int i = 0; i < count; i++) {
2018-03-04 13:34:23 -08:00
timeNowUs += durationUs;
2016-08-27 16:02:43 -07:00
firePrimaryTriggerRise();
2018-03-04 13:34:23 -08:00
timeNowUs += durationUs;
2016-08-27 16:02:43 -07:00
firePrimaryTriggerFall();
2015-07-10 06:01:56 -07:00
}
}
2018-03-04 13:38:01 -08:00
void EngineTestHelper::clearQueue() {
2018-03-04 13:39:33 -08:00
schedulingQueue.executeAll(99999999); // this is needed to clear 'isScheduled' flag
assertEqualsM("queue size/0", 0, schedulingQueue.size());
2018-03-04 13:38:01 -08:00
engine.iHead = NULL; // let's drop whatever was scheduled just to start from a clean state
}
2016-08-26 15:02:39 -07:00
void EngineTestHelper::fireTriggerEvents(int count) {
2018-03-04 13:38:01 -08:00
fireTriggerEvents2(count, MS2US(5)); // 5ms
2016-08-26 15:02:39 -07:00
}
2016-08-26 17:03:06 -07:00
void EngineTestHelper::applyTriggerShape() {
2015-07-10 06:01:56 -07:00
Engine *engine = &this->engine;
engine_configuration_s *engineConfiguration = engine->engineConfiguration;
persistent_config_s *config = engine->config;
board_configuration_s *boardConfiguration = &engineConfiguration->bc;
2017-05-15 20:28:49 -07:00
engine->triggerCentral.triggerShape.initializeTriggerShape(NULL PASS_ENGINE_PARAMETER_SUFFIX);
2015-07-10 06:01:56 -07:00
2017-05-15 20:28:49 -07:00
incrementGlobalConfigurationVersion(PASS_ENGINE_PARAMETER_SIGNATURE);
2015-07-10 06:01:56 -07:00
}