From 63b0fb586604ef8cd9be48eb31fecd93a2b029dc Mon Sep 17 00:00:00 2001 From: Max Date: Tue, 11 Aug 2026 22:38:51 +1200 Subject: [PATCH] mazda: recognize CX-9 with swapped CX-5 EPS --- opendbc/car/mazda/fingerprints.py | 2 ++ .../car/mazda/tests/test_mazda_interface.py | 31 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/opendbc/car/mazda/fingerprints.py b/opendbc/car/mazda/fingerprints.py index 99e64142a65..d3ce5dcaefc 100644 --- a/opendbc/car/mazda/fingerprints.py +++ b/opendbc/car/mazda/fingerprints.py @@ -259,6 +259,8 @@ CAR.MAZDA_CX9_2021: { (Ecu.eps, 0x730, None): [ b'TC3M-3210X-A-00\x00\x00\x00\x00\x00\x00\x00\x00\x00', + # CX-9 with a supported 2022+ CX-5 EPS swap + b'KSD5-3210X-C-00\x00\x00\x00\x00\x00\x00\x00\x00\x00', ], (Ecu.engine, 0x7e0, None): [ b'PW25-188K2-\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00', diff --git a/opendbc/car/mazda/tests/test_mazda_interface.py b/opendbc/car/mazda/tests/test_mazda_interface.py index bd71e67d033..5af83976702 100644 --- a/opendbc/car/mazda/tests/test_mazda_interface.py +++ b/opendbc/car/mazda/tests/test_mazda_interface.py @@ -2,6 +2,7 @@ from opendbc.car import structs from opendbc.car.common.conversions import Conversions as CV +from opendbc.car.fw_versions import match_fw_to_car from opendbc.car.mazda.interface import CarInterface from opendbc.car.mazda.values import CAR, LKAS_LIMITS, STEER_TO_ZERO_EPS_FW @@ -21,6 +22,26 @@ def _eps_fw(version: bytes) -> list[structs.CarParams.CarFw]: return [fw] +def _fw(ecu, address: int, version: bytes) -> structs.CarParams.CarFw: + fw = structs.CarParams.CarFw() + fw.brand = 'mazda' + fw.ecu = ecu + fw.address = address + fw.subAddress = 0 + fw.fwVersion = version + return fw + + +HYBRID_CX9_FW = [ + _fw(Ecu.engine, 0x7e0, b'PXM7-188K2-E' + b'\x00' * 12), + _fw(Ecu.transmission, 0x7e1, b'PXM7-21PS1-B' + b'\x00' * 12), + _fw(Ecu.abs, 0x760, b'TA0B-437K2-C' + b'\x00' * 12), + _fw(Ecu.fwdRadar, 0x764, b'K131-67XK2-F' + b'\x00' * 12), + _fw(Ecu.fwdCamera, 0x706, b'GSH7-67XK2-S' + b'\x00' * 12), + _fw(Ecu.eps, 0x730, b'KSD5-3210X-C-00' + b'\x00' * 9), +] + + def _params(candidate, car_fw=None, alpha_long=False): return CarInterface.get_params(candidate, {0: {}, 1: {}, 2: {}}, car_fw or [], alpha_long, is_release=False, docs=False) @@ -46,6 +67,16 @@ def test_swapped_eps_lifts_dashcam_and_the_speed_floor(self): assert CP.minSteerSpeed == 0 assert CP.steerActuatorDelay == pytest.approx(0.14) + def test_hybrid_cx9_is_identified_with_the_swapped_eps(self): + exact, candidates = match_fw_to_car(HYBRID_CX9_FW, "", allow_fuzzy=False, log=False) + assert exact + assert candidates == {CAR.MAZDA_CX9_2021} + + CP = _params(CAR.MAZDA_CX9_2021, HYBRID_CX9_FW) + assert not CP.dashcamOnly + assert CP.minSteerSpeed == 0 + assert CP.steerActuatorDelay == pytest.approx(0.14) + def test_swapped_eps_does_not_unlock_longitudinal(self): # the radar and camera are not part of an EPS swap, and this car keeps its own pre-2022 pair CP = _params(CAR.MAZDA_CX5, _eps_fw(SWAPPED_EPS_FW), alpha_long=True)