mirror of https://github.com/commaai/panda.git
Hyundai: share flags with CAN-FD platform (#1099)
* Hyundai: share flags with CAN-FD platform * update flags there
This commit is contained in:
parent
2f3e2825e5
commit
622ce923e9
|
@ -84,14 +84,9 @@ AddrCheckStruct hyundai_legacy_addr_checks[] = {
|
|||
};
|
||||
#define HYUNDAI_LEGACY_ADDR_CHECK_LEN (sizeof(hyundai_legacy_addr_checks) / sizeof(hyundai_legacy_addr_checks[0]))
|
||||
|
||||
const int HYUNDAI_PARAM_EV_GAS = 1;
|
||||
const int HYUNDAI_PARAM_HYBRID_GAS = 2;
|
||||
const int HYUNDAI_PARAM_LONGITUDINAL = 4;
|
||||
const int HYUNDAI_PARAM_CAMERA_SCC = 8;
|
||||
|
||||
bool hyundai_legacy = false;
|
||||
bool hyundai_ev_gas_signal = false;
|
||||
bool hyundai_hybrid_gas_signal = false;
|
||||
bool hyundai_camera_scc = false;
|
||||
|
||||
addr_checks hyundai_rx_checks = {hyundai_addr_checks, HYUNDAI_ADDR_CHECK_LEN};
|
||||
|
@ -331,18 +326,13 @@ static int hyundai_fwd_hook(int bus_num, CANPacket_t *to_fwd) {
|
|||
}
|
||||
|
||||
static const addr_checks* hyundai_init(uint16_t param) {
|
||||
hyundai_common_init(param);
|
||||
hyundai_legacy = false;
|
||||
hyundai_ev_gas_signal = GET_FLAG(param, HYUNDAI_PARAM_EV_GAS);
|
||||
hyundai_hybrid_gas_signal = !hyundai_ev_gas_signal && GET_FLAG(param, HYUNDAI_PARAM_HYBRID_GAS);
|
||||
hyundai_camera_scc = GET_FLAG(param, HYUNDAI_PARAM_CAMERA_SCC);
|
||||
hyundai_last_button_interaction = HYUNDAI_PREV_BUTTON_SAMPLES;
|
||||
|
||||
#ifdef ALLOW_DEBUG
|
||||
// TODO: add longitudinal support for camera-based SCC platform
|
||||
hyundai_longitudinal = GET_FLAG(param, HYUNDAI_PARAM_LONGITUDINAL) && !hyundai_camera_scc;
|
||||
#else
|
||||
hyundai_longitudinal = false;
|
||||
#endif
|
||||
if (hyundai_camera_scc) {
|
||||
hyundai_longitudinal = false;
|
||||
}
|
||||
|
||||
if (hyundai_longitudinal) {
|
||||
hyundai_rx_checks = (addr_checks){hyundai_long_addr_checks, HYUNDAI_LONG_ADDR_CHECK_LEN};
|
||||
|
@ -355,12 +345,11 @@ static const addr_checks* hyundai_init(uint16_t param) {
|
|||
}
|
||||
|
||||
static const addr_checks* hyundai_legacy_init(uint16_t param) {
|
||||
hyundai_common_init(param);
|
||||
hyundai_legacy = true;
|
||||
hyundai_longitudinal = false;
|
||||
hyundai_camera_scc = false;
|
||||
hyundai_ev_gas_signal = GET_FLAG(param, HYUNDAI_PARAM_EV_GAS);
|
||||
hyundai_hybrid_gas_signal = !hyundai_ev_gas_signal && GET_FLAG(param, HYUNDAI_PARAM_HYBRID_GAS);
|
||||
hyundai_last_button_interaction = HYUNDAI_PREV_BUTTON_SAMPLES;
|
||||
|
||||
hyundai_rx_checks = (addr_checks){hyundai_legacy_addr_checks, HYUNDAI_LEGACY_ADDR_CHECK_LEN};
|
||||
return &hyundai_rx_checks;
|
||||
}
|
||||
|
|
|
@ -63,9 +63,8 @@ addr_checks hyundai_canfd_rx_checks = {hyundai_canfd_addr_checks, HYUNDAI_CANFD_
|
|||
uint16_t hyundai_canfd_crc_lut[256];
|
||||
|
||||
|
||||
const int HYUNDAI_PARAM_CANFD_HDA2 = 1;
|
||||
const int HYUNDAI_PARAM_CANFD_ALT_BUTTONS = 2;
|
||||
const int HYUNDAI_PARAM_CANFD_LONG = 4;
|
||||
const int HYUNDAI_PARAM_CANFD_HDA2 = 8;
|
||||
const int HYUNDAI_PARAM_CANFD_ALT_BUTTONS = 16;
|
||||
bool hyundai_canfd_hda2 = false;
|
||||
bool hyundai_canfd_alt_buttons = false;
|
||||
|
||||
|
@ -287,16 +286,15 @@ static int hyundai_canfd_fwd_hook(int bus_num, CANPacket_t *to_fwd) {
|
|||
}
|
||||
|
||||
static const addr_checks* hyundai_canfd_init(uint16_t param) {
|
||||
hyundai_common_init(param);
|
||||
|
||||
gen_crc_lookup_table_16(0x1021, hyundai_canfd_crc_lut);
|
||||
hyundai_last_button_interaction = HYUNDAI_PREV_BUTTON_SAMPLES;
|
||||
hyundai_canfd_hda2 = GET_FLAG(param, HYUNDAI_PARAM_CANFD_HDA2);
|
||||
hyundai_canfd_alt_buttons = GET_FLAG(param, HYUNDAI_PARAM_CANFD_ALT_BUTTONS);
|
||||
|
||||
#ifdef ALLOW_DEBUG
|
||||
hyundai_longitudinal = GET_FLAG(param, HYUNDAI_PARAM_CANFD_LONG) && hyundai_canfd_hda2;
|
||||
#else
|
||||
hyundai_longitudinal = false;
|
||||
#endif
|
||||
if (!hyundai_canfd_hda2) {
|
||||
hyundai_longitudinal = false;
|
||||
}
|
||||
|
||||
return &hyundai_canfd_rx_checks;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
#ifndef SAFETY_HYUNDAI_COMMON_H
|
||||
#define SAFETY_HYUNDAI_COMMON_H
|
||||
|
||||
const int HYUNDAI_PARAM_EV_GAS = 1;
|
||||
const int HYUNDAI_PARAM_HYBRID_GAS = 2;
|
||||
const int HYUNDAI_PARAM_LONGITUDINAL = 4;
|
||||
|
||||
const uint8_t HYUNDAI_PREV_BUTTON_SAMPLES = 8; // roughly 160 ms
|
||||
const uint32_t HYUNDAI_STANDSTILL_THRSLD = 30; // ~1kph
|
||||
|
||||
|
@ -12,9 +16,23 @@ enum {
|
|||
};
|
||||
|
||||
// common state
|
||||
bool hyundai_ev_gas_signal = false;
|
||||
bool hyundai_hybrid_gas_signal = false;
|
||||
bool hyundai_longitudinal = false;
|
||||
uint8_t hyundai_last_button_interaction; // button messages since the user pressed an enable button
|
||||
|
||||
void hyundai_common_init(uint16_t param) {
|
||||
hyundai_ev_gas_signal = GET_FLAG(param, HYUNDAI_PARAM_EV_GAS);
|
||||
hyundai_hybrid_gas_signal = !hyundai_ev_gas_signal && GET_FLAG(param, HYUNDAI_PARAM_HYBRID_GAS);
|
||||
|
||||
hyundai_last_button_interaction = HYUNDAI_PREV_BUTTON_SAMPLES;
|
||||
|
||||
#ifdef ALLOW_DEBUG
|
||||
hyundai_longitudinal = GET_FLAG(param, HYUNDAI_PARAM_LONGITUDINAL);
|
||||
#else
|
||||
hyundai_longitudinal = false;
|
||||
#endif
|
||||
}
|
||||
|
||||
void hyundai_common_cruise_state_check(const int cruise_engaged) {
|
||||
// some newer HKG models can re-enable after spamming cancel button,
|
||||
|
|
|
@ -213,10 +213,8 @@ class Panda:
|
|||
FLAG_HYUNDAI_HYBRID_GAS = 2
|
||||
FLAG_HYUNDAI_LONG = 4
|
||||
FLAG_HYUNDAI_CAMERA_SCC = 8
|
||||
|
||||
FLAG_HYUNDAI_CANFD_HDA2 = 1
|
||||
FLAG_HYUNDAI_CANFD_ALT_BUTTONS = 2
|
||||
FLAG_HYUNDAI_CANFD_LONG = 4
|
||||
FLAG_HYUNDAI_CANFD_HDA2 = 8
|
||||
FLAG_HYUNDAI_CANFD_ALT_BUTTONS = 16
|
||||
|
||||
FLAG_TESLA_POWERTRAIN = 1
|
||||
FLAG_TESLA_LONG_CONTROL = 2
|
||||
|
|
|
@ -145,7 +145,7 @@ class TestHyundaiCanfdHDA2Long(HyundaiLongitudinalBase, TestHyundaiCanfdHDA2):
|
|||
def setUp(self):
|
||||
self.packer = CANPackerPanda("hyundai_canfd")
|
||||
self.safety = libpandasafety_py.libpandasafety
|
||||
self.safety.set_safety_hooks(Panda.SAFETY_HYUNDAI_CANFD, Panda.FLAG_HYUNDAI_CANFD_HDA2 | Panda.FLAG_HYUNDAI_CANFD_LONG)
|
||||
self.safety.set_safety_hooks(Panda.SAFETY_HYUNDAI_CANFD, Panda.FLAG_HYUNDAI_CANFD_HDA2 | Panda.FLAG_HYUNDAI_LONG)
|
||||
self.safety.init_tests()
|
||||
|
||||
def _accel_msg(self, accel, aeb_req=False, aeb_decel=0):
|
||||
|
|
Loading…
Reference in New Issue