@@ -9,18 +9,16 @@ const struct lookup_t NISSAN_LOOKUP_ANGLE_RATE_DOWN = {
9
9
{2. , 7. , 17. },
10
10
{5. , 3.5 , .5 }};
11
11
12
- const struct lookup_t NISSAN_LOOKUP_MAX_ANGLE = {
13
- {3.3 , 12 , 32 },
14
- {540. , 120. , 23. }};
15
-
16
12
const int NISSAN_DEG_TO_CAN = 100 ;
17
13
18
- const AddrBus NISSAN_TX_MSGS [] = {{0x169 , 0 }, {0x2b1 , 0 }, {0x4cc , 0 }, {0x20b , 2 }};
14
+ const AddrBus NISSAN_TX_MSGS [] = {{0x169 , 0 }, {0x2b1 , 0 }, {0x4cc , 0 }, {0x20b , 2 }, { 0x280 , 2 } };
19
15
20
16
AddrCheckStruct nissan_rx_checks [] = {
21
- {.addr = {0x2 }, .bus = 0 , .expected_timestep = 10000U },
22
- {.addr = {0x29a }, .bus = 0 , .expected_timestep = 20000U },
23
- {.addr = {0x1b6 }, .bus = 1 , .expected_timestep = 10000U },
17
+ {.addr = {0x2 }, .bus = 0 , .expected_timestep = 10000U }, // STEER_ANGLE_SENSOR (100Hz)
18
+ {.addr = {0x285 }, .bus = 0 , .expected_timestep = 20000U }, // WHEEL_SPEEDS_REAR (50Hz)
19
+ {.addr = {0x30f }, .bus = 2 , .expected_timestep = 100000U }, // CRUISE_STATE (10Hz)
20
+ {.addr = {0x15c , 0x239 }, .bus = 0 , .expected_timestep = 20000U }, // GAS_PEDAL (100Hz / 50Hz)
21
+ {.addr = {0x454 , 0x1cc }, .bus = 0 , .expected_timestep = 100000U }, // DOORS_LIGHTS (10Hz) / BRAKE (100Hz)
24
22
};
25
23
const int NISSAN_RX_CHECK_LEN = sizeof (nissan_rx_checks ) / sizeof (nissan_rx_checks [0 ]);
26
24
@@ -54,15 +52,22 @@ static int nissan_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
54
52
update_sample (& nissan_angle_meas , angle_meas_new );
55
53
}
56
54
57
- if (addr == 0x29a ) {
55
+ if (addr == 0x285 ) {
58
56
// Get current speed
59
- // Factor 0.00555
60
- nissan_speed = ((GET_BYTE (to_push , 2 ) << 8 ) | (GET_BYTE (to_push , 3 ))) * 0.00555 / 3.6 ;
57
+ // Factor 0.005
58
+ nissan_speed = ((GET_BYTE (to_push , 2 ) << 8 ) | (GET_BYTE (to_push , 3 ))) * 0.005 / 3.6 ;
61
59
}
62
60
63
61
// exit controls on rising edge of gas press
64
- if (addr == 0x15c ) {
65
- bool gas_pressed = ((GET_BYTE (to_push , 5 ) << 2 ) | ((GET_BYTE (to_push , 6 ) >> 6 ) & 0x3 ));
62
+ // X-Trail 0x15c, Leaf 0x239
63
+ if ((addr == 0x15c ) || (addr == 0x239 )) {
64
+ bool gas_pressed = true;
65
+ if (addr == 0x15c ){
66
+ gas_pressed = ((GET_BYTE (to_push , 5 ) << 2 ) | ((GET_BYTE (to_push , 6 ) >> 6 ) & 0x3 )) > 1 ;
67
+ } else {
68
+ gas_pressed = GET_BYTE (to_push , 0 ) > 3 ;
69
+ }
70
+
66
71
if (gas_pressed && !gas_pressed_prev ) {
67
72
controls_allowed = 0 ;
68
73
}
@@ -75,26 +80,34 @@ static int nissan_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
75
80
}
76
81
}
77
82
78
- if (bus == 1 ) {
79
- if (addr == 0x1b6 ) {
80
- int cruise_engaged = (GET_BYTE (to_push , 4 ) >> 6 ) & 1 ;
81
- if (cruise_engaged && !nissan_cruise_engaged_last ) {
82
- controls_allowed = 1 ;
83
- }
84
- if (!cruise_engaged ) {
85
- controls_allowed = 0 ;
86
- }
87
- nissan_cruise_engaged_last = cruise_engaged ;
83
+ // exit controls on rising edge of brake press, or if speed > 0 and brake
84
+ // X-trail 0x454, Leaf 0x1cc
85
+ if ((addr == 0x454 ) || (addr == 0x1cc )) {
86
+ bool brake_pressed = true;
87
+ if (addr == 0x454 ){
88
+ brake_pressed = (GET_BYTE (to_push , 2 ) & 0x80 ) != 0 ;
89
+ } else {
90
+ brake_pressed = GET_BYTE (to_push , 0 ) > 3 ;
88
91
}
89
92
90
- // exit controls on rising edge of brake press, or if speed > 0 and brake
91
- if (addr == 0x454 ) {
92
- bool brake_pressed = (GET_BYTE (to_push , 2 ) & 0x80 ) != 0 ;
93
- if (brake_pressed && (!brake_pressed_prev || (nissan_speed > 0. ))) {
94
- controls_allowed = 0 ;
95
- }
96
- brake_pressed_prev = brake_pressed ;
93
+ if (brake_pressed && (!brake_pressed_prev || (nissan_speed > 0. ))) {
94
+ controls_allowed = 0 ;
95
+ }
96
+ brake_pressed_prev = brake_pressed ;
97
+ }
98
+
99
+
100
+ // Handle cruise enabled
101
+ if ((bus == 2 ) && (addr == 0x30f )) {
102
+ bool cruise_engaged = (GET_BYTE (to_push , 0 ) >> 3 ) & 1 ;
103
+
104
+ if (cruise_engaged && !nissan_cruise_engaged_last ) {
105
+ controls_allowed = 1 ;
97
106
}
107
+ if (!cruise_engaged ) {
108
+ controls_allowed = 0 ;
109
+ }
110
+ nissan_cruise_engaged_last = cruise_engaged ;
98
111
}
99
112
}
100
113
return valid ;
@@ -133,16 +146,6 @@ static int nissan_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
133
146
int highest_desired_angle = nissan_desired_angle_last + ((nissan_desired_angle_last > 0 ) ? delta_angle_up : delta_angle_down );
134
147
int lowest_desired_angle = nissan_desired_angle_last - ((nissan_desired_angle_last >= 0 ) ? delta_angle_down : delta_angle_up );
135
148
136
- // Limit maximum steering angle at current speed
137
- int maximum_angle = ((int )interpolate (NISSAN_LOOKUP_MAX_ANGLE , nissan_speed ));
138
-
139
- if (highest_desired_angle > (maximum_angle * NISSAN_DEG_TO_CAN )) {
140
- highest_desired_angle = (maximum_angle * NISSAN_DEG_TO_CAN );
141
- }
142
- if (lowest_desired_angle < (- maximum_angle * NISSAN_DEG_TO_CAN )) {
143
- lowest_desired_angle = (- maximum_angle * NISSAN_DEG_TO_CAN );
144
- }
145
-
146
149
// check for violation;
147
150
violation |= max_limit_check (desired_angle , highest_desired_angle , lowest_desired_angle );
148
151
@@ -183,7 +186,10 @@ static int nissan_fwd_hook(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd) {
183
186
int addr = GET_ADDR (to_fwd );
184
187
185
188
if (bus_num == 0 ) {
186
- bus_fwd = 2 ; // ADAS
189
+ int block_msg = (addr == 0x280 ); // CANCEL_MSG
190
+ if (!block_msg ) {
191
+ bus_fwd = 2 ; // ADAS
192
+ }
187
193
}
188
194
189
195
if (bus_num == 2 ) {
0 commit comments