Line | Branch | Decision | Exec | Source |
---|---|---|---|---|
1 | /* | |||
2 | * @file engine_cylinder.cpp | |||
3 | * | |||
4 | * @date: may 25, 2025 | |||
5 | * @author Matthew Kennedy, FDSoftware | |||
6 | */ | |||
7 | #include "pch.h" | |||
8 | #include "engine_cylinder.hpp" | |||
9 | ||||
10 | 5608 | void OneCylinder::updateCylinderNumber(uint8_t index, uint8_t cylinderNumber) { | ||
11 | 5608 | m_cylinderIndex = index; | ||
12 | 5608 | m_cylinderNumber = cylinderNumber; | ||
13 | ||||
14 | // base = position of this cylinder in the firing order. | |||
15 | // We get a cylinder every n-th of an engine cycle where N is the number of cylinders | |||
16 | 5608 | m_baseAngleOffset = engine->engineState.engineCycle * index / engineConfiguration->cylindersCount; | ||
17 | ||||
18 | 5608 | m_valid = true; | ||
19 | 5608 | } | ||
20 | ||||
21 | 12284 | void OneCylinder::invalidCylinder() { | ||
22 | 12284 | m_valid = false; | ||
23 | 12284 | } | ||
24 | ||||
25 | 4532 | angle_t OneCylinder::getAngleOffset() const { | ||
26 |
2/2✓ Branch 0 taken 1 time.
✓ Branch 1 taken 4531 times.
|
2/2✓ Decision 'true' taken 1 time.
✓ Decision 'false' taken 4531 times.
|
4532 | if (!m_valid) { |
27 | 1 | return 0; | ||
28 | } | |||
29 | ||||
30 | // Plus or minus any adjustment if this is an odd-fire engine | |||
31 | 4531 | auto adjustment = engineConfiguration->timing_offset_cylinder[m_cylinderNumber]; | ||
32 | ||||
33 | 4531 | auto result = m_baseAngleOffset + adjustment; | ||
34 | ||||
35 |
2/4✓ Branch 0 taken 4531 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4531 times.
|
4531 | assertAngleRange(result, "getAngleOffset", ObdCode::CUSTOM_ERR_CYL_ANGLE); | |
36 | ||||
37 | 4531 | return result; | ||
38 | } | |||
39 | ||||
40 | 1491 | void EngineCylinders::updateCylinders() { | ||
41 | // Update valid cylinders with their position in the firing order | |||
42 | 1491 | uint16_t cylinderUpdateMask = 0; | ||
43 |
2/2✓ Branch 0 taken 5608 times.
✓ Branch 1 taken 1491 times.
|
2/2✓ Decision 'true' taken 5608 times.
✓ Decision 'false' taken 1491 times.
|
7099 | for (size_t i = 0; i < engineConfiguration->cylindersCount; i++) { |
44 | 5608 | auto cylinderNumber = getCylinderNumberAtIndex(i); | ||
45 | ||||
46 | 5608 | engine->cylinders[cylinderNumber].updateCylinderNumber(i, cylinderNumber); | ||
47 | ||||
48 | 5608 | auto mask = 1 << cylinderNumber; | ||
49 | // Assert that this cylinder was not configured yet | |||
50 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5608 times.
|
5608 | efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, (cylinderUpdateMask & mask) == 0, "cylinder update err"); | |
51 | 5608 | cylinderUpdateMask |= mask; | ||
52 | } | |||
53 | ||||
54 | // Assert that all cylinders were configured | |||
55 | 1491 | uint16_t expectedMask = (1 << (engineConfiguration->cylindersCount)) - 1; | ||
56 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1491 times.
|
1491 | efiAssertVoid(ObdCode::OBD_PCM_Processor_Fault, cylinderUpdateMask == expectedMask, "cylinder update err"); | |
57 | ||||
58 | // Invalidate the remaining cylinders | |||
59 |
2/2✓ Branch 1 taken 12284 times.
✓ Branch 2 taken 1491 times.
|
2/2✓ Decision 'true' taken 12284 times.
✓ Decision 'false' taken 1491 times.
|
13775 | for (size_t i = engineConfiguration->cylindersCount; i < efi::size(engine->cylinders); i++) { |
60 | 12284 | engine->cylinders[i].invalidCylinder(); | ||
61 | } | |||
62 | } | |||
63 |