diff --git a/board/safety/safety_honda.h b/board/safety/safety_honda.h index a35689afa0..415a379076 100644 --- a/board/safety/safety_honda.h +++ b/board/safety/safety_honda.h @@ -217,8 +217,8 @@ static int honda_rx_hook(CANPacket_t *to_push) { // disable stock Honda AEB in alternative experience if (!(alternative_experience & ALT_EXP_DISABLE_STOCK_AEB)) { if ((bus == 2) && (addr == 0x1FA)) { - bool honda_stock_aeb = GET_BYTE(to_push, 3) & 0x20U; - int honda_stock_brake = (GET_BYTE(to_push, 0) << 2) + ((GET_BYTE(to_push, 1) >> 6) & 0x3U); + 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); // Forward AEB when stock braking is higher than openpilot braking // only stop forwarding when AEB event is over diff --git a/tests/libpanda/safety_helpers.h b/tests/libpanda/safety_helpers.h index 8b573041cc..99910fc068 100644 --- a/tests/libpanda/safety_helpers.h +++ b/tests/libpanda/safety_helpers.h @@ -176,6 +176,10 @@ void set_honda_fwd_brake(bool c){ honda_fwd_brake = c; } +bool get_honda_fwd_brake(void){ + return honda_fwd_brake; +} + void init_tests(void){ // get HW_TYPE from env variable set in test.sh if (getenv("HW_TYPE")) { diff --git a/tests/libpanda/safety_helpers.py b/tests/libpanda/safety_helpers.py index d10a82b004..27ef009ad9 100644 --- a/tests/libpanda/safety_helpers.py +++ b/tests/libpanda/safety_helpers.py @@ -47,6 +47,7 @@ def setup_safety_helpers(ffi): void init_tests(void); void set_honda_fwd_brake(bool c); + bool get_honda_fwd_brake(void); void set_honda_alt_brake_msg(bool c); void set_honda_bosch_long(bool c); int get_honda_hw(void); @@ -97,6 +98,7 @@ def addr_checks_valid(self) -> bool: ... def init_tests(self) -> None: ... def set_honda_fwd_brake(self, c: bool) -> None: ... + def get_honda_fwd_brake(self) -> bool: ... def set_honda_alt_brake_msg(self, c: bool) -> None: ... def set_honda_bosch_long(self, c: bool) -> None: ... def get_honda_hw(self) -> int: ... diff --git a/tests/safety/test_honda.py b/tests/safety/test_honda.py index 6164189ccc..feab1fe164 100755 --- a/tests/safety/test_honda.py +++ b/tests/safety/test_honda.py @@ -176,7 +176,7 @@ def test_buttons(self): class HondaBase(common.PandaSafetyTest): - MAX_BRAKE: float = 255 + MAX_BRAKE = 255 PT_BUS: Optional[int] = None # must be set when inherited STEER_BUS: Optional[int] = None # must be set when inherited BUTTONS_BUS: Optional[int] = None # must be set when inherited, tx on this bus, rx on PT_BUS @@ -288,9 +288,12 @@ def _interceptor_gas_cmd(self, gas): def _interceptor_user_gas(self, gas): return interceptor_msg(gas, 0x201) - def _send_brake_msg(self, brake): - values = {"COMPUTER_BRAKE": brake} - return self.packer.make_can_msg_panda("BRAKE_COMMAND", 0, values) + def _send_brake_msg(self, brake, aeb_req=0, bus=0): + values = {"COMPUTER_BRAKE": brake, "AEB_REQ_1": aeb_req} + return self.packer.make_can_msg_panda("BRAKE_COMMAND", bus, values) + + def _rx_brake_msg(self, brake, aeb_req=0): + return self._send_brake_msg(brake, aeb_req, bus=2) def _send_acc_hud_msg(self, pcm_gas, pcm_speed): # Used to control ACC on Nidec without pedal @@ -311,12 +314,35 @@ def test_fwd_hook(self): self.safety.set_honda_fwd_brake(False) super().test_fwd_hook() - # TODO: test latching until AEB event is over? # forwarding AEB brake signal self.FWD_BLACKLISTED_ADDRS = {2: [0xE4, 0x194, 0x33D, 0x30C]} self.safety.set_honda_fwd_brake(True) super().test_fwd_hook() + def test_honda_fwd_brake_latching(self): + # Shouldn't fwd stock Honda requesting brake without AEB + self.assertTrue(self._rx(self._rx_brake_msg(self.MAX_BRAKE, aeb_req=0))) + self.assertFalse(self.safety.get_honda_fwd_brake()) + + # Now allow controls and request some brake + openpilot_brake = round(self.MAX_BRAKE / 2.0) + self.safety.set_controls_allowed(True) + self.assertTrue(self._tx(self._send_brake_msg(openpilot_brake))) + + # Still shouldn't fwd stock Honda brake until it's more than openpilot's + for stock_honda_brake in range(self.MAX_BRAKE + 1): + self.assertTrue(self._rx(self._rx_brake_msg(stock_honda_brake, aeb_req=1))) + should_fwd_brake = stock_honda_brake >= openpilot_brake + self.assertEqual(should_fwd_brake, self.safety.get_honda_fwd_brake()) + + # Shouldn't stop fwding until AEB event is over + for stock_honda_brake in range(self.MAX_BRAKE + 1)[::-1]: + self.assertTrue(self._rx(self._rx_brake_msg(stock_honda_brake, aeb_req=1))) + self.assertTrue(self.safety.get_honda_fwd_brake()) + + self.assertTrue(self._rx(self._rx_brake_msg(0, aeb_req=0))) + self.assertFalse(self.safety.get_honda_fwd_brake()) + def test_brake_safety_check(self): for fwd_brake in [False, True]: self.safety.set_honda_fwd_brake(fwd_brake) @@ -330,7 +356,6 @@ def test_brake_safety_check(self): else: send = brake == 0 self.assertEqual(send, self._tx(self._send_brake_msg(brake))) - self.safety.set_honda_fwd_brake(False) class TestHondaNidecSafety(HondaPcmEnableBase, TestHondaNidecSafetyBase):