Skip to content

Commit 5879709

Browse files
committed
Revert "from commaai#1964"
This reverts commit c325de2.
1 parent c325de2 commit 5879709

File tree

5 files changed

+76
-87
lines changed

5 files changed

+76
-87
lines changed

opendbc/safety/safety/safety_hyundai.h

+9-4
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ static const CanMsg HYUNDAI_TX_MSGS[] = {
5353
HYUNDAI_COMMON_TX_MSGS(0)
5454
};
5555

56+
static bool hyundai_legacy = false;
57+
5658
static uint8_t hyundai_get_counter(const CANPacket_t *to_push) {
5759
int addr = GET_ADDR(to_push);
5860

@@ -286,8 +288,6 @@ static int hyundai_fwd_hook(int bus_num, int addr) {
286288
}
287289

288290
static safety_config hyundai_init(uint16_t param) {
289-
hyundai_flags(param);
290-
291291
static const CanMsg HYUNDAI_LONG_TX_MSGS[] = {
292292
HYUNDAI_LONG_COMMON_TX_MSGS(0)
293293
{0x38D, 0, 8}, // FCA11 Bus 0
@@ -303,6 +303,9 @@ static safety_config hyundai_init(uint16_t param) {
303303
HYUNDAI_LONG_COMMON_TX_MSGS(2)
304304
};
305305

306+
hyundai_common_init(param);
307+
hyundai_legacy = false;
308+
306309
safety_config ret;
307310
if (hyundai_longitudinal) {
308311
static RxCheck hyundai_long_rx_checks[] = {
@@ -332,14 +335,16 @@ static safety_config hyundai_init(uint16_t param) {
332335
}
333336

334337
static safety_config hyundai_legacy_init(uint16_t param) {
335-
hyundai_flags(param);
336-
337338
// older hyundai models have less checks due to missing counters and checksums
338339
static RxCheck hyundai_legacy_rx_checks[] = {
339340
HYUNDAI_COMMON_RX_CHECKS(true)
340341
HYUNDAI_SCC12_ADDR_CHECK(0)
341342
};
342343

344+
hyundai_common_init(param);
345+
hyundai_legacy = true;
346+
hyundai_longitudinal = false;
347+
hyundai_camera_scc = false;
343348
return BUILD_SAFETY_CFG(hyundai_legacy_rx_checks, HYUNDAI_TX_MSGS);
344349
}
345350

opendbc/safety/safety/safety_hyundai_canfd.h

+11-2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939
#define HYUNDAI_CANFD_SCC_ADDR_CHECK(scc_bus) \
4040
{.msg = {{0x1a0, (scc_bus), 32, .max_counter = 0xffU, .frequency = 50U}, { 0 }, { 0 }}}, \
4141

42+
static bool hyundai_canfd_alt_buttons = false;
43+
static bool hyundai_canfd_lka_steering_alt = false;
44+
4245
static int hyundai_canfd_get_lka_addr(void) {
4346
return hyundai_canfd_lka_steering_alt ? 0x110 : 0x50;
4447
}
@@ -247,8 +250,8 @@ static int hyundai_canfd_fwd_hook(int bus_num, int addr) {
247250
}
248251

249252
static safety_config hyundai_canfd_init(uint16_t param) {
250-
hyundai_canfd_flags(param);
251-
gen_crc_lookup_table_16(0x1021, hyundai_canfd_crc_lut);
253+
const int HYUNDAI_PARAM_CANFD_LKA_STEERING_ALT = 128;
254+
const int HYUNDAI_PARAM_CANFD_ALT_BUTTONS = 32;
252255

253256
static const CanMsg HYUNDAI_CANFD_LKA_STEERING_TX_MSGS[] = {
254257
HYUNDAI_CANFD_LKA_STEERING_COMMON_TX_MSGS(0, 1)
@@ -292,6 +295,12 @@ static safety_config hyundai_canfd_init(uint16_t param) {
292295
{0x160, 0, 16}, // ADRV_0x160
293296
};
294297

298+
hyundai_common_init(param);
299+
300+
gen_crc_lookup_table_16(0x1021, hyundai_canfd_crc_lut);
301+
hyundai_canfd_alt_buttons = GET_FLAG(param, HYUNDAI_PARAM_CANFD_ALT_BUTTONS);
302+
hyundai_canfd_lka_steering_alt = GET_FLAG(param, HYUNDAI_PARAM_CANFD_LKA_STEERING_ALT);
303+
295304
safety_config ret;
296305
if (hyundai_longitudinal) {
297306
if (hyundai_canfd_lka_steering) {

opendbc/safety/safety/safety_hyundai_common.h

+54-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
#pragma once
22

33
#include "safety_declarations.h"
4-
#include "safety_hyundai_flags.h"
54

65
extern uint16_t hyundai_canfd_crc_lut[256];
76
uint16_t hyundai_canfd_crc_lut[256];
87

98
static const uint8_t HYUNDAI_PREV_BUTTON_SAMPLES = 8; // roughly 160 ms
10-
9+
//
1110
extern const uint32_t HYUNDAI_STANDSTILL_THRSLD;
1211
const uint32_t HYUNDAI_STANDSTILL_THRSLD = 12; // 0.375 kph
1312

@@ -18,8 +17,59 @@ enum {
1817
HYUNDAI_BTN_CANCEL = 4,
1918
};
2019

21-
extern uint8_t hyundai_last_button_interaction; // button messages since the user pressed an enable button
22-
uint8_t hyundai_last_button_interaction = HYUNDAI_PREV_BUTTON_SAMPLES;
20+
// common state
21+
extern bool hyundai_ev_gas_signal;
22+
bool hyundai_ev_gas_signal = false;
23+
24+
extern bool hyundai_hybrid_gas_signal;
25+
bool hyundai_hybrid_gas_signal = false;
26+
27+
extern bool hyundai_longitudinal;
28+
bool hyundai_longitudinal = false;
29+
30+
extern bool hyundai_camera_scc;
31+
bool hyundai_camera_scc = false;
32+
33+
extern bool hyundai_canfd_lka_steering;
34+
bool hyundai_canfd_lka_steering = false;
35+
36+
extern bool hyundai_alt_limits;
37+
bool hyundai_alt_limits = false;
38+
39+
extern bool hyundai_fcev_gas_signal;
40+
bool hyundai_fcev_gas_signal = false;
41+
42+
extern bool hyundai_alt_limits_2;
43+
bool hyundai_alt_limits_2 = false;
44+
45+
static uint8_t hyundai_last_button_interaction; // button messages since the user pressed an enable button
46+
47+
void hyundai_common_init(uint16_t param) {
48+
const int HYUNDAI_PARAM_EV_GAS = 1;
49+
const int HYUNDAI_PARAM_HYBRID_GAS = 2;
50+
const int HYUNDAI_PARAM_CAMERA_SCC = 8;
51+
const int HYUNDAI_PARAM_CANFD_LKA_STEERING = 16;
52+
const int HYUNDAI_PARAM_ALT_LIMITS = 64; // TODO: shift this down with the rest of the common flags
53+
const int HYUNDAI_PARAM_FCEV_GAS = 256;
54+
const int HYUNDAI_PARAM_ALT_LIMITS_2 = 512;
55+
56+
hyundai_ev_gas_signal = GET_FLAG(param, HYUNDAI_PARAM_EV_GAS);
57+
hyundai_hybrid_gas_signal = !hyundai_ev_gas_signal && GET_FLAG(param, HYUNDAI_PARAM_HYBRID_GAS);
58+
hyundai_camera_scc = GET_FLAG(param, HYUNDAI_PARAM_CAMERA_SCC);
59+
hyundai_canfd_lka_steering = GET_FLAG(param, HYUNDAI_PARAM_CANFD_LKA_STEERING);
60+
hyundai_alt_limits = GET_FLAG(param, HYUNDAI_PARAM_ALT_LIMITS);
61+
hyundai_fcev_gas_signal = GET_FLAG(param, HYUNDAI_PARAM_FCEV_GAS);
62+
hyundai_alt_limits_2 = GET_FLAG(param, HYUNDAI_PARAM_ALT_LIMITS_2);
63+
64+
hyundai_last_button_interaction = HYUNDAI_PREV_BUTTON_SAMPLES;
65+
66+
#ifdef ALLOW_DEBUG
67+
const int HYUNDAI_PARAM_LONGITUDINAL = 4;
68+
hyundai_longitudinal = GET_FLAG(param, HYUNDAI_PARAM_LONGITUDINAL);
69+
#else
70+
hyundai_longitudinal = false;
71+
#endif
72+
}
2373

2474
void hyundai_common_cruise_state_check(const bool cruise_engaged) {
2575
// some newer HKG models can re-enable after spamming cancel button,

opendbc/safety/safety/safety_hyundai_flags.h

-75
This file was deleted.

opendbc/safety/tests/test_hyundai.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ class TestHyundaiLegacySafetyEV(TestHyundaiSafety):
173173
def setUp(self):
174174
self.packer = CANPackerPanda("hyundai_kia_generic")
175175
self.safety = libsafety_py.libsafety
176-
self.safety.set_safety_hooks(CarParams.SafetyModel.hyundaiLegacy, HyundaiSafetyFlags.EV_GAS)
176+
self.safety.set_safety_hooks(CarParams.SafetyModel.hyundaiLegacy, 1)
177177
self.safety.init_tests()
178178

179179
def _user_gas_msg(self, gas):
@@ -185,7 +185,7 @@ class TestHyundaiLegacySafetyHEV(TestHyundaiSafety):
185185
def setUp(self):
186186
self.packer = CANPackerPanda("hyundai_kia_generic")
187187
self.safety = libsafety_py.libsafety
188-
self.safety.set_safety_hooks(CarParams.SafetyModel.hyundaiLegacy, HyundaiSafetyFlags.HYBRID_GAS)
188+
self.safety.set_safety_hooks(CarParams.SafetyModel.hyundaiLegacy, 2)
189189
self.safety.init_tests()
190190

191191
def _user_gas_msg(self, gas):

0 commit comments

Comments
 (0)