Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions board/safety/safety_honda.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions python/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions tests/safety/test_honda.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 **********************

Expand Down