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