separate between bosch giraffe and harness hooks. Make tests more thorough
parent
38fc1d39ff
commit
c08b480cea
|
@ -79,8 +79,8 @@ const safety_hook_config safety_hook_registry[] = {
|
|||
{SAFETY_TOYOTA, &toyota_hooks},
|
||||
{SAFETY_ELM327, &elm327_hooks},
|
||||
{SAFETY_GM, &gm_hooks},
|
||||
{SAFETY_HONDA_BOSCH_GIRAFFE, &honda_bosch_hooks},
|
||||
{SAFETY_HONDA_BOSCH_HARNESS, &honda_bosch_hooks}, // TODO: distinguish from above
|
||||
{SAFETY_HONDA_BOSCH_GIRAFFE, &honda_bosch_giraffe_hooks},
|
||||
{SAFETY_HONDA_BOSCH_HARNESS, &honda_bosch_harness_hooks},
|
||||
{SAFETY_HYUNDAI, &hyundai_hooks},
|
||||
{SAFETY_CHRYSLER, &chrysler_hooks},
|
||||
{SAFETY_SUBARU, &subaru_hooks},
|
||||
|
|
|
@ -14,9 +14,10 @@ int honda_brake = 0;
|
|||
int honda_gas_prev = 0;
|
||||
bool honda_brake_pressed_prev = false;
|
||||
bool honda_moving = false;
|
||||
bool honda_bosch_hardware = false;
|
||||
bool honda_alt_brake_msg = false;
|
||||
bool honda_fwd_brake = false;
|
||||
enum {HONDA_N_HW, HONDA_BG_HW, HONDA_BH_HW} honda_hw = HONDA_N_HW;
|
||||
|
||||
|
||||
static void honda_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
|
||||
|
||||
|
@ -102,10 +103,10 @@ static void honda_rx_hook(CAN_FIFOMailBox_TypeDef *to_push) {
|
|||
|
||||
// if steering controls messages are received on the destination bus, it's an indication
|
||||
// that the relay might be malfunctioning
|
||||
int bus_rdr_car = (board_has_relay()) ? 0 : 2; // radar bus, car side
|
||||
int bus_rdr_car = (honda_hw == HONDA_BH_HW) ? 0 : 2; // radar bus, car side
|
||||
if ((safety_mode_cnt > RELAY_TRNS_TIMEOUT) && ((addr == 0xE4) || (addr == 0x194))) {
|
||||
if ((honda_bosch_hardware && (bus == bus_rdr_car)) ||
|
||||
(!honda_bosch_hardware && (bus == 0))) {
|
||||
if (((honda_hw != HONDA_N_HW) && (bus == bus_rdr_car)) ||
|
||||
((honda_hw == HONDA_N_HW) && (bus == 0))) {
|
||||
relay_malfunction = true;
|
||||
}
|
||||
}
|
||||
|
@ -123,16 +124,16 @@ static int honda_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
|
|||
int addr = GET_ADDR(to_send);
|
||||
int bus = GET_BUS(to_send);
|
||||
|
||||
if (honda_bosch_hardware) {
|
||||
if (board_has_relay() && !msg_allowed(addr, bus, HONDA_BH_TX_MSGS, sizeof(HONDA_BH_TX_MSGS)/sizeof(HONDA_BH_TX_MSGS[0]))) {
|
||||
tx = 0;
|
||||
}
|
||||
if (!board_has_relay() && !msg_allowed(addr, bus, HONDA_BG_TX_MSGS, sizeof(HONDA_BG_TX_MSGS)/sizeof(HONDA_BG_TX_MSGS[0]))) {
|
||||
tx = 0;
|
||||
}
|
||||
}
|
||||
if (!honda_bosch_hardware && !msg_allowed(addr, bus, HONDA_N_TX_MSGS, sizeof(HONDA_N_TX_MSGS)/sizeof(HONDA_N_TX_MSGS[0]))) {
|
||||
tx = 0;
|
||||
switch (honda_hw) {
|
||||
case HONDA_BG_HW:
|
||||
tx = msg_allowed(addr, bus, HONDA_BG_TX_MSGS, sizeof(HONDA_BG_TX_MSGS)/sizeof(HONDA_BG_TX_MSGS[0]));
|
||||
break;
|
||||
case HONDA_BH_HW:
|
||||
tx = msg_allowed(addr, bus, HONDA_BH_TX_MSGS, sizeof(HONDA_BH_TX_MSGS)/sizeof(HONDA_BH_TX_MSGS[0]));
|
||||
break;
|
||||
default: // nidec
|
||||
tx = msg_allowed(addr, bus, HONDA_N_TX_MSGS, sizeof(HONDA_N_TX_MSGS)/sizeof(HONDA_N_TX_MSGS[0]));
|
||||
break;
|
||||
}
|
||||
|
||||
if (relay_malfunction) {
|
||||
|
@ -183,9 +184,8 @@ static int honda_tx_hook(CAN_FIFOMailBox_TypeDef *to_send) {
|
|||
// FORCE CANCEL: safety check only relevant when spamming the cancel button in Bosch HW
|
||||
// ensuring that only the cancel button press is sent (VAL 2) when controls are off.
|
||||
// This avoids unintended engagements while still allowing resume spam
|
||||
int bus_pt = ((board_has_relay()) && honda_bosch_hardware)? 1 : 0;
|
||||
if ((addr == 0x296) && honda_bosch_hardware &&
|
||||
!current_controls_allowed && (bus == bus_pt)) {
|
||||
int bus_pt = (honda_hw == HONDA_BH_HW)? 1 : 0;
|
||||
if ((addr == 0x296) && !current_controls_allowed && (bus == bus_pt)) {
|
||||
if (((GET_BYTE(to_send, 0) >> 5) & 0x7) != 2) {
|
||||
tx = 0;
|
||||
}
|
||||
|
@ -199,14 +199,22 @@ static void honda_nidec_init(int16_t param) {
|
|||
UNUSED(param);
|
||||
controls_allowed = false;
|
||||
relay_malfunction = false;
|
||||
honda_bosch_hardware = false;
|
||||
honda_hw = HONDA_N_HW;
|
||||
honda_alt_brake_msg = false;
|
||||
}
|
||||
|
||||
static void honda_bosch_init(int16_t param) {
|
||||
static void honda_bosch_giraffe_init(int16_t param) {
|
||||
controls_allowed = false;
|
||||
relay_malfunction = false;
|
||||
honda_bosch_hardware = true;
|
||||
honda_hw = HONDA_BG_HW;
|
||||
// Checking for alternate brake override from safety parameter
|
||||
honda_alt_brake_msg = (param == 1) ? true : false;
|
||||
}
|
||||
|
||||
static void honda_bosch_harness_init(int16_t param) {
|
||||
controls_allowed = false;
|
||||
relay_malfunction = false;
|
||||
honda_hw = HONDA_BH_HW;
|
||||
// Checking for alternate brake override from safety parameter
|
||||
honda_alt_brake_msg = (param == 1) ? true : false;
|
||||
}
|
||||
|
@ -239,8 +247,8 @@ static int honda_nidec_fwd_hook(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd) {
|
|||
|
||||
static int honda_bosch_fwd_hook(int bus_num, CAN_FIFOMailBox_TypeDef *to_fwd) {
|
||||
int bus_fwd = -1;
|
||||
int bus_rdr_cam = (board_has_relay()) ? 2 : 1; // radar bus, camera side
|
||||
int bus_rdr_car = (board_has_relay()) ? 0 : 2; // radar bus, car side
|
||||
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 (!relay_malfunction) {
|
||||
if (bus_num == bus_rdr_car) {
|
||||
|
@ -265,8 +273,16 @@ const safety_hooks honda_nidec_hooks = {
|
|||
.fwd = honda_nidec_fwd_hook,
|
||||
};
|
||||
|
||||
const safety_hooks honda_bosch_hooks = {
|
||||
.init = honda_bosch_init,
|
||||
const safety_hooks honda_bosch_giraffe_hooks = {
|
||||
.init = honda_bosch_giraffe_init,
|
||||
.rx = honda_rx_hook,
|
||||
.tx = honda_tx_hook,
|
||||
.tx_lin = nooutput_tx_lin_hook,
|
||||
.fwd = honda_bosch_fwd_hook,
|
||||
};
|
||||
|
||||
const safety_hooks honda_bosch_harness_hooks = {
|
||||
.init = honda_bosch_harness_init,
|
||||
.rx = honda_rx_hook,
|
||||
.tx = honda_tx_hook,
|
||||
.tx_lin = nooutput_tx_lin_hook,
|
||||
|
|
|
@ -30,8 +30,6 @@ typedef struct
|
|||
uint32_t CNT;
|
||||
} TIM_TypeDef;
|
||||
|
||||
bool board_has_relay(void);
|
||||
|
||||
void set_controls_allowed(bool c);
|
||||
bool get_controls_allowed(void);
|
||||
void set_relay_malfunction(bool c);
|
||||
|
@ -62,8 +60,8 @@ bool get_honda_brake_pressed_prev(void);
|
|||
int get_honda_gas_prev(void);
|
||||
void set_honda_fwd_brake(bool);
|
||||
void set_honda_alt_brake_msg(bool);
|
||||
void set_honda_bosch_hardware(bool);
|
||||
int get_honda_bosch_hardware(void);
|
||||
void set_honda_hw(int);
|
||||
int get_honda_hw(void);
|
||||
|
||||
void init_tests_cadillac(void);
|
||||
void set_cadillac_desired_torque_last(int t);
|
||||
|
|
|
@ -47,11 +47,6 @@ TIM_TypeDef *TIM2 = &timer;
|
|||
// from main_declarations.h
|
||||
uint8_t hw_type = HW_TYPE_UNKNOWN;
|
||||
|
||||
// from board.h
|
||||
bool board_has_relay(void) {
|
||||
return hw_type == HW_TYPE_BLACK_PANDA || hw_type == HW_TYPE_UNO;
|
||||
}
|
||||
|
||||
// from config.h
|
||||
#define MIN(a,b) \
|
||||
({ __typeof__ (a) _a = (a); \
|
||||
|
@ -249,12 +244,12 @@ void set_honda_alt_brake_msg(bool c){
|
|||
honda_alt_brake_msg = c;
|
||||
}
|
||||
|
||||
void set_honda_bosch_hardware(bool c){
|
||||
honda_bosch_hardware = c;
|
||||
void set_honda_hw(int c){
|
||||
honda_hw = c;
|
||||
}
|
||||
|
||||
int get_honda_bosch_hardware(void) {
|
||||
return honda_bosch_hardware;
|
||||
int get_honda_hw(void) {
|
||||
return honda_hw;
|
||||
}
|
||||
|
||||
void set_honda_fwd_brake(bool c){
|
||||
|
|
|
@ -10,6 +10,10 @@ MAX_BRAKE = 255
|
|||
INTERCEPTOR_THRESHOLD = 328
|
||||
TX_MSGS = [[0xE4, 0], [0x194, 0], [0x1FA, 0], [0x200, 0], [0x30C, 0], [0x33D, 0], [0x39F, 0]]
|
||||
|
||||
HONDA_N_HW = 0
|
||||
HONDA_BG_HW = 1
|
||||
HONDA_BH_HW = 2
|
||||
|
||||
class TestHondaSafety(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUp(cls):
|
||||
|
@ -23,9 +27,8 @@ class TestHondaSafety(unittest.TestCase):
|
|||
return to_send
|
||||
|
||||
def _button_msg(self, buttons, msg):
|
||||
has_relay = self.safety.board_has_relay()
|
||||
honda_bosch_hardware = self.safety.get_honda_bosch_hardware()
|
||||
bus = 1 if has_relay and honda_bosch_hardware else 0
|
||||
honda_hw = self.safety.get_honda_hw()
|
||||
bus = 1 if honda_hw == HONDA_BH_HW else 0
|
||||
to_send = make_msg(bus, msg)
|
||||
to_send[0].RDLR = buttons << 5
|
||||
return to_send
|
||||
|
@ -63,6 +66,7 @@ class TestHondaSafety(unittest.TestCase):
|
|||
return to_send
|
||||
|
||||
def test_spam_can_buses(self):
|
||||
self.safety.set_honda_hw(HONDA_N_HW)
|
||||
test_spam_can_buses(self, TX_MSGS)
|
||||
|
||||
def test_relay_malfunction(self):
|
||||
|
@ -215,7 +219,8 @@ class TestHondaSafety(unittest.TestCase):
|
|||
SET_BTN = 3
|
||||
CANCEL_BTN = 2
|
||||
BUTTON_MSG = 0x296
|
||||
self.safety.set_honda_bosch_hardware(1)
|
||||
for hw in [HONDA_BG_HW, HONDA_BH_HW]:
|
||||
self.safety.set_honda_hw(hw)
|
||||
self.safety.set_controls_allowed(0)
|
||||
self.assertTrue(self.safety.safety_tx_hook(self._button_msg(CANCEL_BTN, BUTTON_MSG)))
|
||||
self.assertFalse(self.safety.safety_tx_hook(self._button_msg(RESUME_BTN, BUTTON_MSG)))
|
||||
|
@ -229,7 +234,7 @@ class TestHondaSafety(unittest.TestCase):
|
|||
msgs = list(range(0x1, 0x800))
|
||||
fwd_brake = [False, True]
|
||||
|
||||
self.safety.set_honda_bosch_hardware(0)
|
||||
self.safety.set_honda_hw(HONDA_N_HW)
|
||||
|
||||
for f in fwd_brake:
|
||||
self.safety.set_honda_fwd_brake(f)
|
||||
|
|
|
@ -3,6 +3,7 @@ import unittest
|
|||
from panda import Panda
|
||||
from panda.tests.safety import libpandasafety_py
|
||||
from panda.tests.safety.common import make_msg, test_spam_can_buses
|
||||
from panda.tests.safety.test_honda import HONDA_BG_HW, HONDA_BH_HW
|
||||
|
||||
MAX_BRAKE = 255
|
||||
|
||||
|
@ -18,18 +19,18 @@ class TestHondaSafety(unittest.TestCase):
|
|||
cls.safety.init_tests_honda()
|
||||
|
||||
def test_spam_can_buses(self):
|
||||
if self.safety.board_has_relay():
|
||||
test_spam_can_buses(self, H_TX_MSGS)
|
||||
else:
|
||||
test_spam_can_buses(self, G_TX_MSGS)
|
||||
for hw in [HONDA_BG_HW, HONDA_BH_HW]:
|
||||
self.safety.set_honda_hw(hw)
|
||||
test_spam_can_buses(self, H_TX_MSGS if hw == HONDA_BH_HW else G_TX_MSGS)
|
||||
|
||||
def test_fwd_hook(self):
|
||||
buss = range(0x0, 0x3)
|
||||
msgs = range(0x1, 0x800)
|
||||
has_relay = self.safety.board_has_relay()
|
||||
bus_rdr_cam = 2 if has_relay else 1
|
||||
bus_rdr_car = 0 if has_relay else 2
|
||||
bus_pt = 1 if has_relay else 0
|
||||
for hw in [HONDA_BG_HW, HONDA_BH_HW]:
|
||||
self.safety.set_honda_hw(hw)
|
||||
bus_rdr_cam = 2 if hw == HONDA_BH_HW else 1
|
||||
bus_rdr_car = 0 if hw == HONDA_BH_HW else 2
|
||||
bus_pt = 1 if hw == HONDA_BH_HW else 0
|
||||
|
||||
blocked_msgs = [0xE4, 0x33D]
|
||||
for b in buss:
|
||||
|
|
Loading…
Reference in New Issue