forked from rusefi/rusefi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathltft_sandbox.cpp
More file actions
74 lines (57 loc) · 1.87 KB
/
Copy pathltft_sandbox.cpp
File metadata and controls
74 lines (57 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include "pch.h"
#include "mlg_reader.h"
using ::testing::_;
using ::testing::StrictMock;
constexpr float executor_dt = FAST_CALLBACK_PERIOD_MS * 0.001f;
static constexpr bool verbose = false;
static bool firstRun = true;
static float prevTime = 0;
static float dt = 0 ;
static void my_log_handler(std::map<const std::string, float>& snapshot) {
//static size_t counter = 0;
//std::cout << "Lambda callback received snapshot. It has " << snapshot.size()
// << " entries.\n";
float time = snapshot["Time"];
if (!firstRun) {
dt += time - prevTime;
size_t counter = 0;
while (dt > executor_dt) {
// TODO: adjust time
// run the ignition math
engine->periodicFastCallback();
dt -= executor_dt;
counter++;
}
if (verbose) {
if (counter) {
std::cout << time << ": periodicFastCallback() executed " << counter << " times\n";
}
printf("%.3f: CLT: %3.0f, RPM %3.0f, MAP %3.0f, Lambdas: %f %f\n",
time,
snapshot["CLT"],
snapshot["RPM"],
snapshot["MAP"],
snapshot["Front Lambda"],
snapshot["Rear Lambda"]);
}
}
// TODO: find way to mock target AFR?
// now update sensors with new snapshot
Sensor::setMockValue(SensorType::Clt, snapshot["CLT"]);
Sensor::setMockValue(SensorType::Lambda1, snapshot["Front Lambda"]);
Sensor::setMockValue(SensorType::Lambda2, snapshot["Rear Lambda"]);
Sensor::setMockValue(SensorType::Rpm, snapshot["RPM"]);
Sensor::setMockValue(SensorType::Map, snapshot["MAP"]);
prevTime = time;
firstRun = false;
}
void runLtftSandbox() {
EngineTestHelper eth(engine_type_e::TEST_ENGINE);
BinarySensorReader reader;
reader.openMlg("pretty-happy-reference.mlg");
reader.readMlg(my_log_handler);
printf("LTFT test: miss: %d, hit %d, deadband %d\n",
engine->module<LongTermFuelTrim>()->ltftCntMiss,
engine->module<LongTermFuelTrim>()->ltftCntHit,
engine->module<LongTermFuelTrim>()->ltftCntDeadband);
}