Keep legacy Mazda discovery on normal CAN wiring

This commit is contained in:
firestar5683
2026-11-22 12:54:46 -06:00
parent 972dd457c5
commit a3c73c70e5
5 changed files with 73 additions and 3 deletions
+4 -2
View File
@@ -17,6 +17,7 @@ from opendbc.car.volvo.discovery import normal_bus_topology as volvo_normal_bus_
from opendbc.car.hyundai.discovery import normal_bus_topology
from opendbc.car.honda.discovery import nidec_bus0_topology, normal_bus_topology as honda_normal_bus_topology
from opendbc.car.honda.values import CAR as HONDA, HondaFlags
from opendbc.car.mazda.discovery import normal_bus0_topology as mazda_normal_bus0_topology
from opendbc.car.chrysler.discovery import normal_bus_topology as chrysler_normal_bus_topology
from opendbc.car.tesla.discovery import normal_bus0_topology as tesla_normal_bus0_topology
from opendbc.car.values import BRANDS
@@ -185,13 +186,14 @@ def fingerprint(can_recv: CanRecvCallable, can_send: CanSendCallable, set_obd_mu
tesla_probe=tesla_normal_bus0_topology if _tesla_fw_uses_normal_bus0() else None) or
('honda' if honda_normal_bus_topology(normal_bus_packets) else None) or
('honda_nidec' if nidec_bus0_topology(normal_bus_packets) else None) or
('chrysler' if chrysler_normal_bus_topology(normal_bus_packets) else None)) is not None:
('chrysler' if chrysler_normal_bus_topology(normal_bus_packets) else None) or
('mazda' if mazda_normal_bus0_topology(normal_bus_packets) else None)) is not None:
set_obd_multiplexing(False)
warmup_remaining = 0.1 - (time.monotonic() - start_time)
if warmup_remaining > 0:
time.sleep(warmup_remaining)
vin_buses = (0,) if normal_brand in ('ford', 'gm', 'volvo', 'tesla', 'chrysler', 'honda_nidec') else (0, 1)
vin_buses = (0,) if normal_brand in ('ford', 'gm', 'volvo', 'tesla', 'chrysler', 'honda_nidec', 'mazda') else (0, 1)
vin_rx_addr, vin_rx_bus, vin = get_vin(can_recv, can_send, vin_buses)
if normal_brand == 'honda_nidec':
car_fw = get_fw_versions(can_recv, can_send, set_obd_multiplexing, query_brand='honda', query_bus=0)
@@ -0,0 +1,16 @@
# Legacy Mazda powertrain and camera traffic selects diagnostic wiring only.
# Identification still requires the normal live firmware/CAN match.
NORMAL_BUS0_LAYOUT = {(0, 0x09D), (0, 0x165), (0, 0x202),
(0, 0x21C), (0, 0x240), (2, 0x243)}
def normal_bus0_topology(packets):
seen = set()
for packet in packets:
for frame in packet:
key = (frame.src, frame.address)
if key in NORMAL_BUS0_LAYOUT:
if len(frame.dat) != 8:
return False
seen.add(key)
return seen == NORMAL_BUS0_LAYOUT
@@ -78,6 +78,7 @@ FW_VERSIONS = {
b'PX2G-188K2-D\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00',
b'PX2H-188K2-B\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00',
b'PX2H-188K2-D\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00',
b'PX2H-188K2-E\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00',
b'PX2H-188K2-G\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00',
b'PX2K-188K2-B\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00',
b'PX38-188K2-B\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00',
@@ -0,0 +1,51 @@
from unittest.mock import patch
import pytest
from opendbc.car.can_definitions import CanData
from opendbc.car.car_helpers import fingerprint
from opendbc.car.mazda.values import CAR
from opendbc.car.structs import CarParams
from opendbc.car.vin import VIN_UNKNOWN
def legacy_frames():
return [CanData(address, bytes(8), bus) for bus, address in (
(0, 0x09D), (0, 0x165), (0, 0x202), (0, 0x21C), (0, 0x240), (2, 0x243),
)]
@pytest.mark.parametrize('layout', ['normal', 'missing_camera', 'camera_echo', 'wrong_dlc'])
@pytest.mark.parametrize('observed_engine', [True, False])
def test_legacy_mazda_discovery_selects_normal_wiring_and_requires_firmware(layout, observed_engine):
frames = legacy_frames()
if layout != 'normal':
frame = frames.pop()
if layout == 'camera_echo':
frames.append(CanData(frame.address, frame.dat, frame.src + 128))
if layout == 'wrong_dlc':
frames.extend((frame, CanData(frame.address, frame.dat[:-1], frame.src)))
firmware = [CarParams.CarFw(address=address, brand='mazda', fwVersion=version.ljust(24, b'\0')) for address, version in (
(0x7E1, b'PYB2-21PS1-G'), (0x730, b'KSD5-3210X-C-00'),
)]
if observed_engine:
firmware.append(CarParams.CarFw(address=0x7E0, brand='mazda', fwVersion=b'PX2H-188K2-E'.ljust(24, b'\0')))
mux = []
with patch('opendbc.car.car_helpers.get_vin', return_value=(-1, -1, VIN_UNKNOWN)) as vin, \
patch('opendbc.car.car_helpers.get_fw_versions', return_value=firmware) as fw, \
patch('opendbc.car.car_helpers.get_present_ecus', return_value=set()), \
patch('opendbc.car.car_helpers.get_fw_versions_ordered', return_value=[]), \
patch('opendbc.car.car_helpers.can_fingerprint', return_value=(None, {})), \
patch('opendbc.car.car_helpers.time.sleep'):
result = fingerprint(lambda **kwargs: [frames], lambda _: None, mux.append, None)
if layout == 'normal':
assert mux and not any(mux)
assert vin.call_args.args[2] == (0,)
assert fw.call_args.kwargs == {'query_brand': 'mazda', 'normal_bus_only': True}
assert result[0] == (CAR.MAZDA_CX5 if observed_engine else None)
else:
fw.assert_not_called()
assert result[0] is None
+1 -1
View File
@@ -1 +1 @@
{"protected_inventory_sha256": "419f51cf6ff8059afd08687934fab81df5eec165f7550aa56ffd5359dc194b2e", "schema_version": 1}
{"protected_inventory_sha256": "0866182e6c1de9219c8770775b38e8f8a7283062b7e4b382ecf9f474e7e01457", "schema_version": 1}