From 9aeaf593c32af2e82ce1a06d3e44e9f3e3b7f711 Mon Sep 17 00:00:00 2001 From: firestar5683 <168790843+firestar5683@users.noreply.github.com> Date: Sun, 14 Jun 2026 21:02:31 -0500 Subject: [PATCH] son day I'll get this --- opendbc_repo/opendbc/car/hyundai/carstate.py | 6 +++- .../opendbc/car/hyundai/tests/test_hyundai.py | 31 +++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/opendbc_repo/opendbc/car/hyundai/carstate.py b/opendbc_repo/opendbc/car/hyundai/carstate.py index bcf174058..27652e1cd 100644 --- a/opendbc_repo/opendbc/car/hyundai/carstate.py +++ b/opendbc_repo/opendbc/car/hyundai/carstate.py @@ -204,8 +204,12 @@ class CarState(CarStateBase): return button_events def create_lkas_button_events(self, cp: CANParser, prev_lda_button: int) -> list[structs.CarState.ButtonEvent]: + if self.CP.carFingerprint == CAR.HYUNDAI_SONATA_HYBRID and cp.ts_nanos["BCM_PO_11"]["LDA_BTN"] > 0: + # Route-proven: late-model Sonata Hybrid publishes a live LKAS button on BCM_PO_11 + # while CLU13 is present on the main bus but does not carry the LKAS state. + self.lda_button = int(cp.vl["BCM_PO_11"]["LDA_BTN"]) # Some classic HKG platforms publish the LKAS button on the cluster bus instead of BCM_PO_11. - if cp.ts_nanos["CLU13"]["CF_Clu_LdwsLkasSW"] > 0: + elif cp.ts_nanos["CLU13"]["CF_Clu_LdwsLkasSW"] > 0: self.lda_button = int(cp.vl["CLU13"]["CF_Clu_LdwsLkasSW"]) elif cp.ts_nanos["BCM_PO_11"]["LDA_BTN"] > 0: self.lda_button = int(cp.vl["BCM_PO_11"]["LDA_BTN"]) diff --git a/opendbc_repo/opendbc/car/hyundai/tests/test_hyundai.py b/opendbc_repo/opendbc/car/hyundai/tests/test_hyundai.py index 0b2de66b2..1edc70705 100644 --- a/opendbc_repo/opendbc/car/hyundai/tests/test_hyundai.py +++ b/opendbc_repo/opendbc/car/hyundai/tests/test_hyundai.py @@ -771,6 +771,37 @@ class TestHyundaiFingerprint: ret = update(0, 3) assert any(be.type == ButtonType.lkas and not be.pressed for be in ret.buttonEvents) + def test_sonata_hybrid_prefers_bcm_lkas_button_over_dead_main_bus_clu13(self): + toggles = get_test_toggles() + fingerprint = gen_empty_fingerprint() + fingerprint[0][0x391] = 8 + fingerprint[1][0x50C] = 8 + CP = CarInterface.get_params(CAR.HYUNDAI_SONATA_HYBRID, fingerprint, [], False, False, False, toggles) + FPCP = CarInterface.get_starpilot_params(CAR.HYUNDAI_SONATA_HYBRID, fingerprint, [], CP, toggles) + + car_state = CarState(CP, FPCP) + can_parsers = car_state.get_can_parsers(CP) + packer = CANPacker(DBC[CP.carFingerprint][Bus.pt]) + + def update(clu13_lkas_button: int, bcm_lkas_button: int, frame: int): + msgs = [ + packer.make_can_msg("CLU13", 0, { + "CF_Clu_LdwsLkasSW": clu13_lkas_button, + }), + packer.make_can_msg("BCM_PO_11", 0, { + "LDA_BTN": bcm_lkas_button, + }), + ] + can_parsers[Bus.pt].update([(frame, msgs)]) + return car_state.update(can_parsers, toggles)[0] + + update(0, 0, 1) + ret = update(0, 1, 2) + assert any(be.type == ButtonType.lkas and be.pressed for be in ret.buttonEvents) + + ret = update(0, 0, 3) + assert any(be.type == ButtonType.lkas and not be.pressed for be in ret.buttonEvents) + def test_sonata_hybrid_ignores_noisy_alt_bus_clu13_lkas_button(self): toggles = get_test_toggles() fingerprint = gen_empty_fingerprint()