@@ -42,78 +42,84 @@ uint32_t gm_ts_last = 0;
42
42
struct sample_t gm_torque_driver ; // last few driver torques measured
43
43
44
44
static int gm_rx_hook (CAN_FIFOMailBox_TypeDef * to_push ) {
45
- int bus = GET_BUS (to_push );
46
- int addr = GET_ADDR (to_push );
47
-
48
- if (addr == 388 ) {
49
- int torque_driver_new = ((GET_BYTE (to_push , 6 ) & 0x7 ) << 8 ) | GET_BYTE (to_push , 7 );
50
- torque_driver_new = to_signed (torque_driver_new , 11 );
51
- // update array of samples
52
- update_sample (& gm_torque_driver , torque_driver_new );
53
- }
54
45
55
- // sample speed, really only care if car is moving or not
56
- // rear left wheel speed
57
- if (addr == 842 ) {
58
- gm_moving = GET_BYTE (to_push , 0 ) | GET_BYTE (to_push , 1 );
59
- }
46
+ bool valid = addr_safety_check (to_push , gm_rx_checks , GM_RX_CHECK_LEN ,
47
+ NULL , NULL , NULL );
60
48
61
- // ACC steering wheel buttons
62
- if (addr == 481 ) {
63
- int button = (GET_BYTE (to_push , 5 ) & 0x70 ) >> 4 ;
64
- switch (button ) {
65
- case 2 : // resume
66
- case 3 : // set
67
- controls_allowed = 1 ;
68
- break ;
69
- case 6 : // cancel
70
- controls_allowed = 0 ;
71
- break ;
72
- default :
73
- break ; // any other button is irrelevant
49
+ if (valid ) {
50
+ int bus = GET_BUS (to_push );
51
+ int addr = GET_ADDR (to_push );
52
+
53
+ if (addr == 388 ) {
54
+ int torque_driver_new = ((GET_BYTE (to_push , 6 ) & 0x7 ) << 8 ) | GET_BYTE (to_push , 7 );
55
+ torque_driver_new = to_signed (torque_driver_new , 11 );
56
+ // update array of samples
57
+ update_sample (& gm_torque_driver , torque_driver_new );
74
58
}
75
- }
76
59
77
- // exit controls on rising edge of brake press or on brake press when
78
- // speed > 0
79
- if (addr == 241 ) {
80
- int brake = GET_BYTE (to_push , 1 );
81
- // Brake pedal's potentiometer returns near-zero reading
82
- // even when pedal is not pressed
83
- if (brake < 10 ) {
84
- brake = 0 ;
60
+ // sample speed, really only care if car is moving or not
61
+ // rear left wheel speed
62
+ if (addr == 842 ) {
63
+ gm_moving = GET_BYTE (to_push , 0 ) | GET_BYTE (to_push , 1 );
85
64
}
86
- if (brake && (!gm_brake_prev || gm_moving )) {
87
- controls_allowed = 0 ;
65
+
66
+ // ACC steering wheel buttons
67
+ if (addr == 481 ) {
68
+ int button = (GET_BYTE (to_push , 5 ) & 0x70 ) >> 4 ;
69
+ switch (button ) {
70
+ case 2 : // resume
71
+ case 3 : // set
72
+ controls_allowed = 1 ;
73
+ break ;
74
+ case 6 : // cancel
75
+ controls_allowed = 0 ;
76
+ break ;
77
+ default :
78
+ break ; // any other button is irrelevant
79
+ }
88
80
}
89
- gm_brake_prev = brake ;
90
- }
91
81
92
- // exit controls on rising edge of gas press
93
- if (addr == 417 ) {
94
- int gas = GET_BYTE (to_push , 6 );
95
- if (gas && !gm_gas_prev ) {
96
- controls_allowed = 0 ;
82
+ // exit controls on rising edge of brake press or on brake press when
83
+ // speed > 0
84
+ if (addr == 241 ) {
85
+ int brake = GET_BYTE (to_push , 1 );
86
+ // Brake pedal's potentiometer returns near-zero reading
87
+ // even when pedal is not pressed
88
+ if (brake < 10 ) {
89
+ brake = 0 ;
90
+ }
91
+ if (brake && (!gm_brake_prev || gm_moving )) {
92
+ controls_allowed = 0 ;
93
+ }
94
+ gm_brake_prev = brake ;
97
95
}
98
- gm_gas_prev = gas ;
99
- }
100
96
101
- // exit controls on regen paddle
102
- if (addr == 189 ) {
103
- bool regen = GET_BYTE (to_push , 0 ) & 0x20 ;
104
- if (regen ) {
105
- controls_allowed = 0 ;
97
+ // exit controls on rising edge of gas press
98
+ if (addr == 417 ) {
99
+ int gas = GET_BYTE (to_push , 6 );
100
+ if (gas && !gm_gas_prev ) {
101
+ controls_allowed = 0 ;
102
+ }
103
+ gm_gas_prev = gas ;
106
104
}
107
- }
108
105
109
- // Check if ASCM or LKA camera are online
110
- // on powertrain bus.
111
- // 384 = ASCMLKASteeringCmd
112
- // 715 = ASCMGasRegenCmd
113
- if ((safety_mode_cnt > RELAY_TRNS_TIMEOUT ) && (bus == 0 ) && ((addr == 384 ) || (addr == 715 ))) {
114
- relay_malfunction = true;
106
+ // exit controls on regen paddle
107
+ if (addr == 189 ) {
108
+ bool regen = GET_BYTE (to_push , 0 ) & 0x20 ;
109
+ if (regen ) {
110
+ controls_allowed = 0 ;
111
+ }
112
+ }
113
+
114
+ // Check if ASCM or LKA camera are online
115
+ // on powertrain bus.
116
+ // 384 = ASCMLKASteeringCmd
117
+ // 715 = ASCMGasRegenCmd
118
+ if ((safety_mode_cnt > RELAY_TRNS_TIMEOUT ) && (bus == 0 ) && ((addr == 384 ) || (addr == 715 ))) {
119
+ relay_malfunction = true;
120
+ }
115
121
}
116
- return 1 ;
122
+ return valid ;
117
123
}
118
124
119
125
// all commands: gas/regen, friction brake and steering
0 commit comments