@@ -4,18 +4,23 @@ const uint32_t CHRYSLER_RT_INTERVAL = 250000; // 250ms between real time checks
4
4
const int CHRYSLER_MAX_RATE_UP = 3 ;
5
5
const int CHRYSLER_MAX_RATE_DOWN = 3 ;
6
6
const int CHRYSLER_MAX_TORQUE_ERROR = 80 ; // max torque cmd in excess of torque motor
7
+ const int CHRYSLER_GAS_THRSLD = 30 ; // 7% more than 2m/s
7
8
const AddrBus CHRYSLER_TX_MSGS [] = {{571 , 0 }, {658 , 0 }, {678 , 0 }};
8
9
9
10
// TODO: do checksum and counter checks
10
11
AddrCheckStruct chrysler_rx_checks [] = {
11
12
{.addr = {544 }, .bus = 0 , .expected_timestep = 10000U },
13
+ {.addr = {514 }, .bus = 0 , .expected_timestep = 10000U },
12
14
{.addr = {500 }, .bus = 0 , .expected_timestep = 20000U },
15
+ {.addr = {308 }, .bus = 0 , .expected_timestep = 20000U }, // verify ts
13
16
};
14
17
const int CHRYSLER_RX_CHECK_LEN = sizeof (chrysler_rx_checks ) / sizeof (chrysler_rx_checks [0 ]);
15
18
16
19
int chrysler_rt_torque_last = 0 ;
17
20
int chrysler_desired_torque_last = 0 ;
18
21
int chrysler_cruise_engaged_last = 0 ;
22
+ bool chrysler_gas_prev = false;
23
+ int chrysler_speed = 0 ;
19
24
uint32_t chrysler_ts_last = 0 ;
20
25
struct sample_t chrysler_torque_meas ; // last few torques measured
21
26
@@ -29,15 +34,15 @@ static int chrysler_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
29
34
int addr = GET_ADDR (to_push );
30
35
31
36
// Measured eps torque
32
- if (addr == 544 ) {
37
+ if (( addr == 544 ) && ( bus == 0 ) ) {
33
38
int torque_meas_new = ((GET_BYTE (to_push , 4 ) & 0x7U ) << 8 ) + GET_BYTE (to_push , 5 ) - 1024U ;
34
39
35
40
// update array of samples
36
41
update_sample (& chrysler_torque_meas , torque_meas_new );
37
42
}
38
43
39
44
// enter controls on rising edge of ACC, exit controls on ACC off
40
- if (addr == 0x1F4 ) {
45
+ if (( addr == 500 ) && ( bus == 0 ) ) {
41
46
int cruise_engaged = ((GET_BYTE (to_push , 2 ) & 0x38 ) >> 3 ) == 7 ;
42
47
if (cruise_engaged && !chrysler_cruise_engaged_last ) {
43
48
controls_allowed = 1 ;
@@ -48,7 +53,21 @@ static int chrysler_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
48
53
chrysler_cruise_engaged_last = cruise_engaged ;
49
54
}
50
55
51
- // TODO: add gas pressed check
56
+ // update speed
57
+ if ((addr == 514 ) && (bus == 0 )) {
58
+ int speed_l = (GET_BYTE (to_push , 0 ) << 4 ) + (GET_BYTE (to_push , 1 ) >> 4 );
59
+ int speed_r = (GET_BYTE (to_push , 2 ) << 4 ) + (GET_BYTE (to_push , 3 ) >> 4 );
60
+ chrysler_speed = (speed_l + speed_r ) / 2 ;
61
+ }
62
+
63
+ // exit controls on rising edge of gas press
64
+ if ((addr == 308 ) && (bus == 0 )) {
65
+ bool gas = (GET_BYTE (to_push , 5 ) & 0x7F ) != 0 ;
66
+ if (gas && !chrysler_gas_prev && (chrysler_speed > CHRYSLER_GAS_THRSLD )) {
67
+ controls_allowed = 0 ;
68
+ }
69
+ chrysler_gas_prev = gas ;
70
+ }
52
71
53
72
// check if stock camera ECU is on bus 0
54
73
if ((safety_mode_cnt > RELAY_TRNS_TIMEOUT ) && (bus == 0 ) && (addr == 0x292 )) {
0 commit comments