forked from rusefi/rusefi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_tcu.cpp
More file actions
116 lines (90 loc) · 3.9 KB
/
Copy pathtest_tcu.cpp
File metadata and controls
116 lines (90 loc) · 3.9 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
* @file test_tcu.cpp
*
* @date Oct 24, 2025
* @author David Holdeman, (c) 2025
*/
#include "gear_controller.h"
#include "pch.h"
void blipGearControllerPin(EngineTestHelper* eth, brain_pin_e pin, int time) {
engine->gearController->update();
// Close switch/button
setMockState(pin, false);
engine->gearController->update();
// update gearController every ms
for (int i = 0; i < time; i = i+1000) {
eth->moveTimeForwardAndInvokeEventsUs(minI(time - i, 1000));
engine->gearController->update();
}
// And release
setMockState(pin, true);
engine->gearController->update();
}
TEST(tcu, testButtonshift) {
EngineTestHelper eth(engine_type_e::TCU_4R70W);
engineConfiguration->gearControllerMode = GearControllerMode::ButtonShift;
initGearController();
// pinMode is PI_PULLUP, so true = off
setMockState(engineConfiguration->tcuUpshiftButtonPin, true);
setMockState(engineConfiguration->tcuDownshiftButtonPin, true);
ASSERT_NE(nullptr, engine->gearController);
ASSERT_EQ(NEUTRAL, engine->gearController->getDesiredGear());
// Press upshift button for 200ms
blipGearControllerPin(ð, engineConfiguration->tcuUpshiftButtonPin, 200000);
// and now a bounce
eth.moveTimeForwardAndInvokeEventsUs(20);
blipGearControllerPin(ð, engineConfiguration->tcuUpshiftButtonPin, 20);
ASSERT_EQ(GEAR_1, engine->gearController->getDesiredGear());
// Wait 500ms
eth.moveTimeForwardAndInvokeEventsUs(500000);
// Press upshift button for 200ms
blipGearControllerPin(ð, engineConfiguration->tcuUpshiftButtonPin, 200000);
ASSERT_EQ(GEAR_2, engine->gearController->getDesiredGear());
// Wait 500ms
eth.moveTimeForwardAndInvokeEventsUs(500000);
// Press upshift button for 1ms
blipGearControllerPin(ð, engineConfiguration->tcuUpshiftButtonPin, 1000);
ASSERT_EQ(GEAR_3, engine->gearController->getDesiredGear());
// Wait 500ms
eth.moveTimeForwardAndInvokeEventsUs(500000);
// Press upshift button for 3s
blipGearControllerPin(ð, engineConfiguration->tcuUpshiftButtonPin, 3000000);
ASSERT_EQ(GEAR_4, engine->gearController->getDesiredGear());
// Wait 10ms
// Because this is a different pin, the 500ms debounce timeout is not in play.
eth.moveTimeForwardAndInvokeEventsUs(10000);
// Press downshift button for 200ms
blipGearControllerPin(ð, engineConfiguration->tcuDownshiftButtonPin, 200000);
ASSERT_EQ(GEAR_3, engine->gearController->getDesiredGear());
// Wait 10ms
// This shouldn't be long enough for the debounce to have reset,
// so the downshift won't trigger until ~490ms after pressing the button.
eth.moveTimeForwardAndInvokeEventsUs(10000);
// Press downshift button for 1.2s
blipGearControllerPin(ð, engineConfiguration->tcuDownshiftButtonPin, 1200000);
ASSERT_EQ(GEAR_1, engine->gearController->getDesiredGear());
}
TEST(tcu, testGenericGC) {
EngineTestHelper eth(engine_type_e::TCU_4R70W);
engineConfiguration->gearControllerMode = GearControllerMode::Generic;
initGearController();
// Need to set some engine settings for airmass calc
engineConfiguration->cylindersCount = 8.0;
// pinMode is PI_PULLUP, so true = off
setMockState(engineConfiguration->tcuUpshiftButtonPin, true);
setMockState(engineConfiguration->tcuDownshiftButtonPin, true);
setMockState(engineConfiguration->tcu_rangeInput[1], true);
setMockState(engineConfiguration->tcu_rangeInput[2], true);
ASSERT_NE(nullptr, engine->gearController);
ASSERT_EQ(NEUTRAL, engine->gearController->getDesiredGear());
Sensor::setMockValue(SensorType::VehicleSpeed, 55);
Sensor::setMockValue(SensorType::Rpm, 2500);
Sensor::setMockValue(SensorType::DriverThrottleIntent, 15);
Sensor::setMockValue(SensorType::Maf, 0.1f);
engine->gearController->update();
// Make sure we stay in neutral with undefined range selector pins
ASSERT_EQ(NEUTRAL, engine->gearController->getDesiredGear());
Sensor::setMockValue(SensorType::RangeInput1, 2000);
engine->gearController->update();
ASSERT_EQ(GEAR_2, engine->gearController->getDesiredGear());
}