diff --git a/board/safety/safety_honda.h b/board/safety/safety_honda.h index 968a1a446d..d86e38817b 100644 --- a/board/safety/safety_honda.h +++ b/board/safety/safety_honda.h @@ -82,6 +82,7 @@ const uint16_t HONDA_PARAM_BOSCH_LONG = 2; const uint16_t HONDA_PARAM_NIDEC_ALT = 4; const uint16_t HONDA_PARAM_RADARLESS = 8; const uint16_t HONDA_PARAM_GAS_INTERCEPTOR = 16; +const uint16_t HONDA_PARAM_NIDEC_ALT_BRAKE = 32; enum { HONDA_BTN_NONE = 0, @@ -97,6 +98,7 @@ bool honda_alt_brake_msg = false; bool honda_fwd_brake = false; bool honda_bosch_long = false; bool honda_bosch_radarless = false; +bool honda_nidec_alt_brake_msg = false; enum {HONDA_NIDEC, HONDA_BOSCH} honda_hw = HONDA_NIDEC; @@ -236,6 +238,9 @@ static void honda_rx_hook(const CANPacket_t *to_push) { if ((bus == 2) && (addr == 0x1FA)) { bool honda_stock_aeb = GET_BIT(to_push, 29U) != 0U; int honda_stock_brake = (GET_BYTE(to_push, 0) << 2) | (GET_BYTE(to_push, 1) >> 6); + if (honda_nidec_alt_brake_msg) { + honda_stock_brake = (GET_BYTE(to_push, 6) << 2) | (GET_BYTE(to_push, 7) >> 6); + } // Forward AEB when stock braking is higher than openpilot braking // only stop forwarding when AEB event is over @@ -293,6 +298,9 @@ static bool honda_tx_hook(const CANPacket_t *to_send) { // BRAKE: safety check (nidec) if ((addr == 0x1FA) && (bus == bus_pt)) { honda_brake = (GET_BYTE(to_send, 0) << 2) + ((GET_BYTE(to_send, 1) >> 6) & 0x3U); + if (honda_nidec_alt_brake_msg) { + honda_brake = (GET_BYTE(to_send, 6) << 2) + ((GET_BYTE(to_send, 7) >> 6) & 0x3U); + } if (longitudinal_brake_checks(honda_brake, HONDA_NIDEC_LONG_LIMITS)) { tx = false; } @@ -381,6 +389,7 @@ static safety_config honda_nidec_init(uint16_t param) { honda_bosch_long = false; honda_bosch_radarless = false; enable_gas_interceptor = GET_FLAG(param, HONDA_PARAM_GAS_INTERCEPTOR); + honda_nidec_alt_brake_msg = GET_FLAG(param, HONDA_PARAM_NIDEC_ALT_BRAKE); safety_config ret; diff --git a/python/__init__.py b/python/__init__.py index 08a18c9768..db7466c0b4 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -204,6 +204,7 @@ class Panda: FLAG_HONDA_NIDEC_ALT = 4 FLAG_HONDA_RADARLESS = 8 FLAG_HONDA_GAS_INTERCEPTOR = 16 + FLAG_HONDA_NIDEC_ALT_BRAKE = 32 FLAG_HYUNDAI_EV_GAS = 1 FLAG_HYUNDAI_HYBRID_GAS = 2 diff --git a/tests/safety/test_honda.py b/tests/safety/test_honda.py index 08d069b5ed..3554018ce1 100755 --- a/tests/safety/test_honda.py +++ b/tests/safety/test_honda.py @@ -27,6 +27,8 @@ class Btn: # * alt SCM messages (PCM-enable) # * gas interceptor (button-enable) # * gas interceptor with alt SCM messages (button-enable) +# * alt SCM and brake messages (PCM-enable) +# * gas interceptor with alt SCM and brake messages (button-enable) # * Bosch # * Bosch with Longitudinal Support # * Bosch Radarless @@ -416,6 +418,36 @@ def _button_msg(self, buttons, main_on=False, bus=None): return self.packer.make_can_msg_panda("SCM_BUTTONS", bus, values) +class TestHondaNidecPcmAltBrakeSafety(TestHondaNidecPcmAltSafety): + """ + Covers the Honda Nidec safety mode with alt SCM and brake messages + """ + def setUp(self): + self.packer = CANPackerPanda("honda_fit_hybrid_2018_can_generated") + self.safety = libpanda_py.libpanda + self.safety.set_safety_hooks(Panda.SAFETY_HONDA_NIDEC, Panda.FLAG_HONDA_NIDEC_ALT | Panda.FLAG_HONDA_NIDEC_ALT_BRAKE) + self.safety.init_tests() + + def _send_brake_msg(self, brake, aeb_req=0, bus=0): + values = {"COMPUTER_BRAKE_ALT": brake, "AEB_REQ_1": aeb_req} + return self.packer.make_can_msg_panda("BRAKE_COMMAND", bus, values) + + +class TestHondaNidecAltBrakeGasInterceptorSafety(TestHondaNidecAltGasInterceptorSafety): + """ + Covers the Honda Nidec safety mode with alt SCM and brake messages and gas interceptor, switches to a button-enable car + """ + def setUp(self): + self.packer = CANPackerPanda("honda_fit_hybrid_2018_can_generated") + self.safety = libpanda_py.libpanda + self.safety.set_safety_hooks(Panda.SAFETY_HONDA_NIDEC, Panda.FLAG_HONDA_NIDEC_ALT | Panda.FLAG_HONDA_NIDEC_ALT_BRAKE | Panda.FLAG_HONDA_GAS_INTERCEPTOR) + self.safety.init_tests() + + def _send_brake_msg(self, brake, aeb_req=0, bus=0): + values = {"COMPUTER_BRAKE_ALT": brake, "AEB_REQ_1": aeb_req} + return self.packer.make_can_msg_panda("BRAKE_COMMAND", bus, values) + + # ********************* Honda Bosch **********************