From 8fa507b6218af508b0a1b2eec2ada7aaf56039c5 Mon Sep 17 00:00:00 2001 From: Riccardo Date: Sat, 2 Jun 2018 14:06:15 -0700 Subject: [PATCH] GM: simplified max steer check logic, Cadillac: fixed can parsing bug --- board/safety/safety_cadillac.h | 2 +- board/safety/safety_gm.h | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/board/safety/safety_cadillac.h b/board/safety/safety_cadillac.h index 5dd85a7fb774eb..6c965bc734358d 100644 --- a/board/safety/safety_cadillac.h +++ b/board/safety/safety_cadillac.h @@ -23,7 +23,7 @@ static void cadillac_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) { uint32_t addr = to_push->RIR >> 21; if (addr == 356) { - int torque_driver_new = ((to_push->RDLR & 0x3) << 8) | ((to_push->RDLR >> 8) & 0xFF); + int torque_driver_new = ((to_push->RDLR & 0x7) << 8) | ((to_push->RDLR >> 8) & 0xFF); torque_driver_new = to_signed(torque_driver_new, 11); // update array of sample diff --git a/board/safety/safety_gm.h b/board/safety/safety_gm.h index 03c36d6255dcbf..12c7027a30f4b9 100644 --- a/board/safety/safety_gm.h +++ b/board/safety/safety_gm.h @@ -136,14 +136,10 @@ static int gm_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) { if (addr == 384) { int rdlr = to_send->RDLR; int steer = ((rdlr & 0x7) << 8) + ((rdlr & 0xFF00) >> 8); + steer = to_signed(steer, 11); int max_steer = 255; if (current_controls_allowed) { - // Signed arithmetic - if (steer & 0x400) { - if (steer < (0x800 - max_steer)) return 0; - } else { - if (steer > max_steer) return 0; - } + if ((steer > max_steer) || (steer < -max_steer)) return 0; } else { if (steer != 0) return 0; }