Skip to content

Commit 8fa507b

Browse files
committed
GM: simplified max steer check logic, Cadillac: fixed can parsing bug
1 parent c7e2c2d commit 8fa507b

File tree

2 files changed

+3
-7
lines changed

2 files changed

+3
-7
lines changed

board/safety/safety_cadillac.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ static void cadillac_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
2323
uint32_t addr = to_push->RIR >> 21;
2424

2525
if (addr == 356) {
26-
int torque_driver_new = ((to_push->RDLR & 0x3) << 8) | ((to_push->RDLR >> 8) & 0xFF);
26+
int torque_driver_new = ((to_push->RDLR & 0x7) << 8) | ((to_push->RDLR >> 8) & 0xFF);
2727
torque_driver_new = to_signed(torque_driver_new, 11);
2828

2929
// update array of sample

board/safety/safety_gm.h

+2-6
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,10 @@ static int gm_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
136136
if (addr == 384) {
137137
int rdlr = to_send->RDLR;
138138
int steer = ((rdlr & 0x7) << 8) + ((rdlr & 0xFF00) >> 8);
139+
steer = to_signed(steer, 11);
139140
int max_steer = 255;
140141
if (current_controls_allowed) {
141-
// Signed arithmetic
142-
if (steer & 0x400) {
143-
if (steer < (0x800 - max_steer)) return 0;
144-
} else {
145-
if (steer > max_steer) return 0;
146-
}
142+
if ((steer > max_steer) || (steer < -max_steer)) return 0;
147143
} else {
148144
if (steer != 0) return 0;
149145
}

0 commit comments

Comments
 (0)