Honda: cleanup remnants of Bosch giraffe safety (#792)

This commit is contained in:
Adeeb Shihadeh 2021-11-21 14:49:44 -08:00 committed by GitHub
parent 3b653af70e
commit 801fd4997d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 55 additions and 74 deletions

View File

@ -33,7 +33,7 @@
#define SAFETY_ALLOUTPUT 17U
#define SAFETY_GM_ASCM 18U
#define SAFETY_NOOUTPUT 19U
#define SAFETY_HONDA_BOSCH_HARNESS 20U
#define SAFETY_HONDA_BOSCH 20U
#define SAFETY_VOLKSWAGEN_PQ 21U
#define SAFETY_SUBARU_LEGACY 22U
#define SAFETY_HYUNDAI_LEGACY 23U
@ -241,7 +241,7 @@ const safety_hook_config safety_hook_registry[] = {
{SAFETY_TOYOTA, &toyota_hooks},
{SAFETY_ELM327, &elm327_hooks},
{SAFETY_GM, &gm_hooks},
{SAFETY_HONDA_BOSCH_HARNESS, &honda_bosch_harness_hooks},
{SAFETY_HONDA_BOSCH, &honda_bosch_hooks},
{SAFETY_HYUNDAI, &hyundai_hooks},
{SAFETY_CHRYSLER, &chrysler_hooks},
{SAFETY_SUBARU, &subaru_hooks},

View File

@ -7,8 +7,8 @@
// brake rising edge
// brake > 0mph
const CanMsg HONDA_N_TX_MSGS[] = {{0xE4, 0, 5}, {0x194, 0, 4}, {0x1FA, 0, 8}, {0x200, 0, 6}, {0x30C, 0, 8}, {0x33D, 0, 5}};
const CanMsg HONDA_BH_TX_MSGS[] = {{0xE4, 0, 5}, {0xE5, 0, 8}, {0x296, 1, 4}, {0x33D, 0, 5}}; // Bosch Harness
const CanMsg HONDA_BH_LONG_TX_MSGS[] = {{0xE4, 1, 5}, {0x1DF, 1, 8}, {0x1EF, 1, 8}, {0x1FA, 1, 8}, {0x30C, 1, 8}, {0x33D, 1, 5}, {0x39F, 1, 8}, {0x18DAB0F1, 1, 8}}; // Bosch Harness w/ gas and brakes
const CanMsg HONDA_BOSCH_TX_MSGS[] = {{0xE4, 0, 5}, {0xE5, 0, 8}, {0x296, 1, 4}, {0x33D, 0, 5}}; // Bosch
const CanMsg HONDA_BOSCH_LONG_TX_MSGS[] = {{0xE4, 1, 5}, {0x1DF, 1, 8}, {0x1EF, 1, 8}, {0x1FA, 1, 8}, {0x30C, 1, 8}, {0x33D, 1, 5}, {0x39F, 1, 8}, {0x18DAB0F1, 1, 8}}; // Bosch w/ gas and brakes
// Roughly calculated using the offsets in openpilot +5%:
// In openpilot: ((gas1_norm + gas2_norm)/2) > 15
@ -41,15 +41,15 @@ AddrCheckStruct honda_nidec_alt_addr_checks[] = {
};
#define HONDA_NIDEC_ALT_ADDR_CHECKS_LEN (sizeof(honda_nidec_alt_addr_checks) / sizeof(honda_nidec_alt_addr_checks[0]))
// Bosch harness has pt on bus 1
AddrCheckStruct honda_bh_addr_checks[] = {
// Bosch has pt on bus 1
AddrCheckStruct honda_bosch_addr_checks[] = {
{.msg = {{0x296, 1, 4, .check_checksum = true, .max_counter = 3U, .expected_timestep = 40000U}, { 0 }, { 0 }}},
{.msg = {{0x158, 1, 8, .check_checksum = true, .max_counter = 3U, .expected_timestep = 10000U}, { 0 }, { 0 }}},
{.msg = {{0x17C, 1, 8, .check_checksum = true, .max_counter = 3U, .expected_timestep = 10000U},
{0x1BE, 1, 3, .check_checksum = true, .max_counter = 3U, .expected_timestep = 20000U}, { 0 }}},
{.msg = {{0x326, 1, 8, .check_checksum = true, .max_counter = 3U, .expected_timestep = 100000U}, { 0 }, { 0 }}},
};
#define HONDA_BH_ADDR_CHECKS_LEN (sizeof(honda_bh_addr_checks) / sizeof(honda_bh_addr_checks[0]))
#define HONDA_BOSCH_ADDR_CHECKS_LEN (sizeof(honda_bosch_addr_checks) / sizeof(honda_bosch_addr_checks[0]))
const uint16_t HONDA_PARAM_ALT_BRAKE = 1;
const uint16_t HONDA_PARAM_BOSCH_LONG = 2;
@ -59,7 +59,7 @@ int honda_brake = 0;
bool honda_alt_brake_msg = false;
bool honda_fwd_brake = false;
bool honda_bosch_long = false;
enum {HONDA_N_HW, HONDA_BH_HW} honda_hw = HONDA_N_HW;
enum {HONDA_NIDEC, HONDA_BOSCH} honda_hw = HONDA_NIDEC;
addr_checks honda_rx_checks = {honda_nidec_addr_checks, HONDA_NIDEC_ADDR_CHECKS_LEN};
@ -180,14 +180,14 @@ static int honda_rx_hook(CANPacket_t *to_push) {
}
bool stock_ecu_detected = false;
int bus_rdr_car = (honda_hw == HONDA_BH_HW) ? 0 : 2; // radar bus, car side
int pt_bus = (honda_hw == HONDA_BH_HW) ? 1 : 0;
int bus_rdr_car = (honda_hw == HONDA_BOSCH) ? 0 : 2; // radar bus, car side
int pt_bus = (honda_hw == HONDA_BOSCH) ? 1 : 0;
if (safety_mode_cnt > RELAY_TRNS_TIMEOUT) {
// If steering controls messages are received on the destination bus, it's an indication
// that the relay might be malfunctioning
if ((addr == 0xE4) || (addr == 0x194)) {
if (((honda_hw != HONDA_N_HW) && (bus == bus_rdr_car)) || ((honda_hw == HONDA_N_HW) && (bus == 0))) {
if (((honda_hw != HONDA_NIDEC) && (bus == bus_rdr_car)) || ((honda_hw == HONDA_NIDEC) && (bus == 0))) {
stock_ecu_detected = true;
}
}
@ -215,10 +215,10 @@ static int honda_tx_hook(CANPacket_t *to_send) {
int addr = GET_ADDR(to_send);
int bus = GET_BUS(to_send);
if ((honda_hw == HONDA_BH_HW) && !honda_bosch_long) {
tx = msg_allowed(to_send, HONDA_BH_TX_MSGS, sizeof(HONDA_BH_TX_MSGS)/sizeof(HONDA_BH_TX_MSGS[0]));
} else if ((honda_hw == HONDA_BH_HW) && honda_bosch_long) {
tx = msg_allowed(to_send, HONDA_BH_LONG_TX_MSGS, sizeof(HONDA_BH_LONG_TX_MSGS)/sizeof(HONDA_BH_LONG_TX_MSGS[0]));
if ((honda_hw == HONDA_BOSCH) && !honda_bosch_long) {
tx = msg_allowed(to_send, HONDA_BOSCH_TX_MSGS, sizeof(HONDA_BOSCH_TX_MSGS)/sizeof(HONDA_BOSCH_TX_MSGS[0]));
} else if ((honda_hw == HONDA_BOSCH) && honda_bosch_long) {
tx = msg_allowed(to_send, HONDA_BOSCH_LONG_TX_MSGS, sizeof(HONDA_BOSCH_LONG_TX_MSGS)/sizeof(HONDA_BOSCH_LONG_TX_MSGS[0]));
} else {
tx = msg_allowed(to_send, HONDA_N_TX_MSGS, sizeof(HONDA_N_TX_MSGS)/sizeof(HONDA_N_TX_MSGS[0]));
}
@ -231,7 +231,7 @@ static int honda_tx_hook(CANPacket_t *to_send) {
pedal_pressed = pedal_pressed || gas_pressed_prev || (gas_interceptor_prev > HONDA_GAS_INTERCEPTOR_THRESHOLD);
}
bool current_controls_allowed = controls_allowed && !(pedal_pressed);
int bus_pt = (honda_hw == HONDA_BH_HW)? 1 : 0;
int bus_pt = (honda_hw == HONDA_BOSCH)? 1 : 0;
// BRAKE: safety check (nidec)
if ((addr == 0x1FA) && (bus == bus_pt)) {
@ -325,7 +325,7 @@ static const addr_checks* honda_nidec_init(int16_t param) {
controls_allowed = false;
relay_malfunction_reset();
gas_interceptor_detected = 0;
honda_hw = HONDA_N_HW;
honda_hw = HONDA_NIDEC;
honda_alt_brake_msg = false;
honda_bosch_long = false;
@ -337,10 +337,10 @@ static const addr_checks* honda_nidec_init(int16_t param) {
return &honda_rx_checks;
}
static const addr_checks* honda_bosch_harness_init(int16_t param) {
static const addr_checks* honda_bosch_init(int16_t param) {
controls_allowed = false;
relay_malfunction_reset();
honda_hw = HONDA_BH_HW;
honda_hw = HONDA_BOSCH;
// Checking for alternate brake override from safety parameter
honda_alt_brake_msg = GET_FLAG(param, HONDA_PARAM_ALT_BRAKE);
@ -349,7 +349,7 @@ static const addr_checks* honda_bosch_harness_init(int16_t param) {
honda_bosch_long = GET_FLAG(param, HONDA_PARAM_BOSCH_LONG);
#endif
honda_rx_checks = (addr_checks){honda_bh_addr_checks, HONDA_BH_ADDR_CHECKS_LEN};
honda_rx_checks = (addr_checks){honda_bosch_addr_checks, HONDA_BOSCH_ADDR_CHECKS_LEN};
return &honda_rx_checks;
}
@ -380,17 +380,15 @@ static int honda_nidec_fwd_hook(int bus_num, CANPacket_t *to_fwd) {
static int honda_bosch_fwd_hook(int bus_num, CANPacket_t *to_fwd) {
int bus_fwd = -1;
int bus_rdr_cam = (honda_hw == HONDA_BH_HW) ? 2 : 1; // radar bus, camera side
int bus_rdr_car = (honda_hw == HONDA_BH_HW) ? 0 : 2; // radar bus, car side
if (bus_num == bus_rdr_car) {
bus_fwd = bus_rdr_cam;
if (bus_num == 0) {
bus_fwd = 2;
}
if (bus_num == bus_rdr_cam) {
if (bus_num == 2) {
int addr = GET_ADDR(to_fwd);
int is_lkas_msg = (addr == 0xE4) || (addr == 0xE5) || (addr == 0x33D);
if (!is_lkas_msg) {
bus_fwd = bus_rdr_car;
bus_fwd = 0;
}
}
@ -405,8 +403,8 @@ const safety_hooks honda_nidec_hooks = {
.fwd = honda_nidec_fwd_hook,
};
const safety_hooks honda_bosch_harness_hooks = {
.init = honda_bosch_harness_init,
const safety_hooks honda_bosch_hooks = {
.init = honda_bosch_init,
.rx = honda_rx_hook,
.tx = honda_tx_hook,
.tx_lin = nooutput_tx_lin_hook,

View File

@ -12,16 +12,20 @@ class Btn:
SET = 3
RESUME = 4
HONDA_N_HW = 0
HONDA_BG_HW = 1
HONDA_BH_HW = 2
HONDA_NIDEC = 0
HONDA_BOSCH = 1
class TestHondaSafety(common.PandaSafetyTest):
class TestHondaSafetyBase(common.PandaSafetyTest):
MAX_BRAKE: float = 255
PT_BUS: Optional[int] = None # must be set when inherited
STEER_BUS: Optional[int] = None # must be set when inherited
STANDSTILL_THRESHOLD = 0
RELAY_MALFUNCTION_ADDR = 0xE4
RELAY_MALFUNCTION_BUS = 0
FWD_BUS_LOOKUP = {0: 2, 2: 0}
cnt_speed = 0
cnt_gas = 0
cnt_button = 0
@ -30,7 +34,7 @@ class TestHondaSafety(common.PandaSafetyTest):
@classmethod
def setUpClass(cls):
if cls.__name__ == "TestHondaSafety":
if cls.__name__ == "TestHondaSafetyBase":
cls.packer = None
cls.safety = None
raise unittest.SkipTest
@ -185,7 +189,7 @@ class TestHondaSafety(common.PandaSafetyTest):
self.safety.set_controls_allowed(1)
hw = self.safety.get_honda_hw()
if hw == HONDA_N_HW:
if hw == HONDA_NIDEC:
self.safety.set_honda_fwd_brake(False)
self.assertEqual(allow_ctrl, self._tx(self._send_brake_msg(self.MAX_BRAKE)))
self.assertEqual(allow_ctrl, self._tx(self._send_steer_msg(0x1000)))
@ -193,7 +197,7 @@ class TestHondaSafety(common.PandaSafetyTest):
# reset status
self.safety.set_controls_allowed(0)
self.safety.set_unsafe_mode(UNSAFE_MODE.DEFAULT)
if hw == HONDA_N_HW:
if hw == HONDA_NIDEC:
self._tx(self._send_brake_msg(0))
self._tx(self._send_steer_msg(0))
if pedal == 'brake':
@ -203,13 +207,9 @@ class TestHondaSafety(common.PandaSafetyTest):
self._rx(self._gas_msg(0))
class TestHondaNidecSafety(TestHondaSafety, common.InterceptorSafetyTest):
class TestHondaNidecSafety(TestHondaSafetyBase, common.InterceptorSafetyTest):
TX_MSGS = [[0xE4, 0], [0x194, 0], [0x1FA, 0], [0x200, 0], [0x30C, 0], [0x33D, 0]]
STANDSTILL_THRESHOLD = 0
RELAY_MALFUNCTION_ADDR = 0xE4
RELAY_MALFUNCTION_BUS = 0
FWD_BLACKLISTED_ADDRS = {2: [0xE4, 0x194, 0x33D, 0x30C]}
FWD_BUS_LOOKUP = {0: 2, 2: 0}
PT_BUS = 0
STEER_BUS = 0
@ -304,13 +304,16 @@ class TestHondaNidecAltSafety(TestHondaNidecSafety, common.InterceptorSafetyTest
return self.packer.make_can_msg_panda("SCM_BUTTONS", self.PT_BUS, values)
class TestHondaBoschSafety(TestHondaSafety):
STANDSTILL_THRESHOLD = 0
RELAY_MALFUNCTION_ADDR = 0xE4
class TestHondaBoschSafetyBase(TestHondaSafetyBase):
PT_BUS = 1
STEER_BUS = 0
TX_MSGS = [[0xE4, 0], [0xE5, 0], [0x296, 1], [0x33D, 0]]
FWD_BLACKLISTED_ADDRS = {2: [0xE4, 0xE5, 0x33D]}
@classmethod
def setUpClass(cls):
if cls.__name__ == "TestHondaBoschSafety":
if cls.__name__ == "TestHondaBoschSafetyBase":
cls.packer = None
cls.safety = None
raise unittest.SkipTest
@ -348,15 +351,7 @@ class TestHondaBoschSafety(TestHondaSafety):
self.assertTrue(self.safety.get_controls_allowed())
class TestHondaBoschHarnessSafety(TestHondaBoschSafety):
TX_MSGS = [[0xE4, 0], [0xE5, 0], [0x296, 1], [0x33D, 0]] # Bosch Harness
RELAY_MALFUNCTION_BUS = 0
FWD_BLACKLISTED_ADDRS = {2: [0xE4, 0xE5, 0x33D]}
FWD_BUS_LOOKUP = {0: 2, 2: 0}
PT_BUS = 1
STEER_BUS = 0
class TestHondaBosch(TestHondaBoschSafetyBase):
def setUp(self):
super().setUp()
self.safety.set_safety_hooks(Panda.SAFETY_HONDA_BOSCH_HARNESS, 0)
@ -372,17 +367,19 @@ class TestHondaBoschHarnessSafety(TestHondaBoschSafety):
self.assertTrue(self._tx(self._button_msg(Btn.RESUME)))
class TestHondaBoschLongSafety(TestHondaBoschSafety):
class TestHondaBoschLongSafety(TestHondaBoschSafetyBase):
NO_GAS = -30000
MAX_GAS = 2000
MAX_BRAKE = -3.5
@classmethod
def setUpClass(cls):
if cls.__name__ == "TestHondaBoschLongSafety":
cls.packer = None
cls.safety = None
raise unittest.SkipTest
STEER_BUS = 1
TX_MSGS = [[0xE4, 1], [0x1DF, 1], [0x1EF, 1], [0x1FA, 1], [0x30C, 1], [0x33D, 1], [0x39F, 1], [0x18DAB0F1, 1]] # Bosch w/ gas and brakes
FWD_BLACKLISTED_ADDRS = {2: [0xE4, 0xE5, 0x33D]}
def setUp(self):
super().setUp()
self.safety.set_safety_hooks(Panda.SAFETY_HONDA_BOSCH_HARNESS, Panda.FLAG_HONDA_BOSCH_LONG)
self.safety.init_tests_honda()
def _send_gas_brake_msg(self, gas, accel):
values = {
@ -421,20 +418,6 @@ class TestHondaBoschLongSafety(TestHondaBoschSafety):
send = self.MAX_BRAKE <= accel <= 0 if controls_allowed else accel == 0
self.assertEqual(send, self._tx(self._send_gas_brake_msg(self.NO_GAS, accel)), (controls_allowed, accel))
class TestHondaBoschLongHarnessSafety(TestHondaBoschLongSafety):
TX_MSGS = [[0xE4, 1], [0x1DF, 1], [0x1EF, 1], [0x1FA, 1], [0x30C, 1], [0x33D, 1], [0x39F, 1], [0x18DAB0F1, 1]] # Bosch Harness w/ gas and brakes
RELAY_MALFUNCTION_BUS = 0
FWD_BLACKLISTED_ADDRS = {2: [0xE4, 0xE5, 0x33D]}
FWD_BUS_LOOKUP = {0: 2, 2: 0}
PT_BUS = 1
STEER_BUS = 1
def setUp(self):
super().setUp()
self.safety.set_safety_hooks(Panda.SAFETY_HONDA_BOSCH_HARNESS, 2)
self.safety.init_tests_honda()
if __name__ == "__main__":
unittest.main()