1
+ const int STEER_MAX = 150 ; // 1s
1
2
const int CADILLAC_IGNITION_TIMEOUT = 1000000 ; // 1s
3
+
2
4
int cadillac_can_seen = 0 ;
5
+ int cadillac_cruise_engaged_last = 0 ;
3
6
uint32_t cadillac_ts_last = 0 ;
4
7
5
8
static void cadillac_rx_hook (CAN_FIFOMailBox_TypeDef * to_push ) {
6
9
int bus_number = (to_push -> RDTR >> 4 ) & 0xFF ;
7
10
uint32_t addr = to_push -> RIR >> 21 ;
8
11
9
- if (addr == 0x135 && bus_number == 0 ) {
12
+ if (( addr == 0x135 ) && ( bus_number == 0 ) ) {
10
13
cadillac_can_seen = 1 ;
11
14
cadillac_ts_last = TIM2 -> CNT ; // reset timer when gear msg is received
12
15
}
16
+
17
+ // enter controls on rising edge of ACC, exit controls on ACC off
18
+ if ((addr == 0x370 ) && (bus_number == 0 )) {
19
+ int cruise_engaged = to_push -> RDLR & 0x800000 ; // bit 23
20
+ if (cruise_engaged && !cadillac_cruise_engaged_last ) {
21
+ controls_allowed = 1 ;
22
+ } else if (!cruise_engaged ) {
23
+ controls_allowed = 0 ;
24
+ }
25
+ cadillac_cruise_engaged_last = cruise_engaged ;
26
+ }
27
+ }
28
+
29
+ static int cadillac_tx_hook (CAN_FIFOMailBox_TypeDef * to_send ) {
30
+ uint32_t addr = to_send -> RIR >> 21 ;
31
+
32
+ // block steering cmd above 150
33
+ if (addr == 0x151 || addr == 0x152 || addr == 0x153 || addr == 0x154 ) {
34
+ int lkas_cmd = ((to_send -> RDLR & 0x3f ) << 8 ) + ((to_send -> RDLR & 0xff00 ) >> 8 );
35
+ lkas_cmd = to_signed (lkas_cmd , 14 );
36
+ // block message is controls are allowed and lkas command exceeds max, or
37
+ // if controls aren't allowed and lkas cmd isn't 0
38
+ if (controls_allowed && ((lkas_cmd > STEER_MAX ) || (lkas_cmd < - STEER_MAX ))) {
39
+ return 0 ;
40
+ } else if (!controls_allowed && lkas_cmd ) return 0 ;
41
+ }
42
+ return true;
13
43
}
14
44
15
45
static void cadillac_init (int16_t param ) {
16
46
cadillac_can_seen = 0 ;
17
- controls_allowed = 1 ;
18
47
}
19
48
20
49
static int cadillac_ign_hook () {
@@ -31,7 +60,7 @@ static int cadillac_ign_hook() {
31
60
const safety_hooks cadillac_hooks = {
32
61
.init = cadillac_init ,
33
62
.rx = cadillac_rx_hook ,
34
- .tx = alloutput_tx_hook ,
63
+ .tx = cadillac_tx_hook ,
35
64
.tx_lin = alloutput_tx_lin_hook ,
36
65
.ignition = cadillac_ign_hook ,
37
66
.fwd = alloutput_fwd_hook ,
0 commit comments