mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-12-02 08:03:40 +08:00
Auto-detect the 2018 SASCM Volt CAN layout
This commit is contained in:
@@ -10,7 +10,8 @@ from opendbc.car.fw_versions import (ObdCallback, get_fw_versions, get_fw_versio
|
||||
get_present_ecus, match_fw_to_car)
|
||||
from opendbc.car.mock.values import CAR as MOCK
|
||||
from opendbc.car.gm.pedal_capability import automatic_bolt_candidate
|
||||
from opendbc.car.gm.discovery import automatic_trax_candidate, automatic_volt_candidate, normal_bus0_topology as gm_normal_bus0_topology
|
||||
from opendbc.car.gm.discovery import (automatic_trax_candidate, automatic_volt_ascm_candidate, automatic_volt_candidate,
|
||||
normal_bus0_topology as gm_normal_bus0_topology)
|
||||
from opendbc.car.ford.discovery import (normal_bus0_selection as ford_normal_bus0_selection,
|
||||
normal_bus0_queries as ford_normal_bus0_queries, normal_bus_query_brand)
|
||||
from opendbc.car.volvo.discovery import normal_bus_topology as volvo_normal_bus_topology, v60_bus_topology as volvo_v60_bus_topology
|
||||
@@ -96,6 +97,7 @@ def can_fingerprint(can_recv: CanRecvCallable, *, vin: str = VIN_UNKNOWN,
|
||||
frame += 1
|
||||
|
||||
car_fingerprint = automatic_volt_candidate(car_fingerprint, finger, candidate_cars)
|
||||
car_fingerprint = automatic_volt_ascm_candidate(car_fingerprint, finger, candidate_cars, vin)
|
||||
car_fingerprint = automatic_trax_candidate(car_fingerprint, finger, candidate_cars, vin)
|
||||
return automatic_bolt_candidate(car_fingerprint, finger, camera_cruise_messages, vin), finger
|
||||
|
||||
|
||||
@@ -46,6 +46,25 @@ def automatic_volt_candidate(candidate, fingerprint, candidates):
|
||||
return CAR.CHEVROLET_VOLT_CC
|
||||
|
||||
|
||||
def automatic_volt_ascm_candidate(candidate, fingerprint, candidates, vin):
|
||||
# The recorded 2018 SASCM Volt falls out of both legacy CAN candidate lists.
|
||||
if (candidate is not None or any(candidates.values()) or not isinstance(vin, str) or not is_valid_vin(vin) or
|
||||
not vin.startswith('1G1RD6S5') or vin[9] != 'J'):
|
||||
return candidate
|
||||
|
||||
pt = fingerprint.get(CanBus.POWERTRAIN, {})
|
||||
camera = fingerprint.get(CanBus.CAMERA, {})
|
||||
radar = fingerprint.get(CanBus.OBSTACLE, {})
|
||||
required = {0xC9: 8, 0x180: 4, 0x184: 8, 0x1C4: 8, 0x1E1: 7,
|
||||
0x2FF: 4, 0x348: 5, 0x34A: 5, 0x370: 6}
|
||||
if (pt != camera or any(pt.get(address) != size for address, size in required.items()) or
|
||||
radar.get(0x460) != 8 or radar.get(0x474) != 8 or
|
||||
any(address in pt for address in (0xBE, 0x201)) or pt.get(0x320) not in (None, 3) or
|
||||
any(messages for bus, messages in fingerprint.items() if bus not in (CanBus.POWERTRAIN, CanBus.OBSTACLE, CanBus.CAMERA))):
|
||||
return candidate
|
||||
return CAR.CHEVROLET_VOLT_ASCM
|
||||
|
||||
|
||||
# Frequent normal-bus frames observed on mirrored pedal installations. This is
|
||||
# only diagnostic query-family evidence, never a vehicle/control fingerprint.
|
||||
PEDAL_NORMAL_BUS_LAYOUT = {0xD3: 2, 0xBE: 6, 0xC9: 8, 0x1C4: 8,
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
import json
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
from opendbc.car import car_helpers, structs
|
||||
from opendbc.car.can_definitions import CanData
|
||||
from opendbc.car.gm.values import CAR
|
||||
|
||||
VIN = '1G1RD6S50JU000001'
|
||||
RECORDED = Path(__file__).parent / 'testdata/volt_2018_ascm_fingerprint.json'
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def fingerprint():
|
||||
return {int(bus): {int(address): size for address, size in messages.items()}
|
||||
for bus, messages in json.loads(RECORDED.read_text()).items()}
|
||||
|
||||
|
||||
def receive(fingerprint):
|
||||
packets = [CanData(address, bytes(size), bus)
|
||||
for bus, messages in fingerprint.items() for address, size in messages.items()]
|
||||
return lambda **kwargs: [packets]
|
||||
|
||||
|
||||
def test_recorded_startup_selects_ascm_and_preserves_manual_override(fingerprint):
|
||||
fw = structs.CarParams.CarFw.new_message(brand='gm', logging=True)
|
||||
cache = SimpleNamespace(carFingerprint='MOCK', carVin=VIN, carFw=[fw], brand='mock')
|
||||
with patch.dict(car_helpers.os.environ, {'FINGERPRINT': '', 'SKIP_FW_QUERY': '', 'DISABLE_FW_CACHE': ''}), \
|
||||
patch.object(car_helpers, 'get_vin', return_value=(0x64B, 0, VIN)), \
|
||||
patch.object(car_helpers, 'get_fw_versions', return_value=[fw]):
|
||||
args = (receive(fingerprint), lambda _: None, lambda _: None, False, True)
|
||||
auto = car_helpers.get_car(*args, cached_params=cache).CP
|
||||
manual = car_helpers.get_car(*args, forced_candidate=CAR.CHEVROLET_VOLT).CP
|
||||
assert auto.carFingerprint == CAR.CHEVROLET_VOLT_ASCM
|
||||
assert auto.fingerprintSource == structs.CarParams.FingerprintSource.can
|
||||
assert auto.pcmCruise and not auto.openpilotLongitudinalControl and not auto.dashcamOnly
|
||||
assert auto.safetyConfigs[0].safetyParam == 0xE05
|
||||
assert manual.carFingerprint == CAR.CHEVROLET_VOLT
|
||||
assert manual.fingerprintSource == structs.CarParams.FingerprintSource.fixed
|
||||
|
||||
|
||||
@pytest.mark.parametrize('vin', ['0' * 17, '1G1RD6S50KU000001', '1G1FX6S50JU000001'])
|
||||
def test_layout_alone_does_not_match(fingerprint, vin):
|
||||
assert car_helpers.can_fingerprint(receive(fingerprint), vin=vin)[0] is None
|
||||
|
||||
|
||||
@pytest.mark.parametrize('bus,address,size', [(0, 0x2FF, 8), (0, 0x201, 6), (0, 0x320, 6),
|
||||
(2, 0x180, None), (1, 0x474, None)])
|
||||
def test_other_harness_or_control_sources_do_not_match(fingerprint, bus, address, size):
|
||||
for target in (0, 2) if bus == 0 else (bus,):
|
||||
if size is None:
|
||||
fingerprint[target].pop(address)
|
||||
else:
|
||||
fingerprint[target][address] = size
|
||||
assert car_helpers.can_fingerprint(receive(fingerprint), vin=VIN)[0] != CAR.CHEVROLET_VOLT_ASCM
|
||||
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"0": {"189": 7, "193": 8, "197": 8, "201": 8, "209": 7, "211": 2, "241": 6, "298": 8, "304": 1, "308": 4, "309": 8, "311": 8, "313": 8, "320": 3, "328": 1, "352": 5, "381": 6, "384": 4, "386": 8, "388": 8, "451": 8, "452": 8, "453": 6, "479": 3, "481": 7, "485": 8, "489": 8, "493": 8, "497": 8, "500": 6, "501": 8, "528": 4, "532": 6, "560": 8, "562": 8, "563": 5, "565": 5, "566": 5, "608": 8, "609": 6, "610": 6, "611": 6, "612": 8, "613": 8, "707": 8, "715": 8, "717": 5, "761": 7, "767": 4, "810": 8, "840": 5, "842": 5, "844": 8, "869": 4, "880": 6, "977": 8, "1001": 8, "1017": 8, "1020": 8, "1033": 7, "1034": 7, "1217": 8, "1221": 5, "1233": 8, "1249": 8, "1265": 8, "1267": 1, "1280": 4, "1296": 4, "1300": 8, "1922": 7, "1930": 7},
|
||||
"1": {"161": 7, "262": 5, "309": 1, "768": 8, "771": 2, "774": 8, "776": 7, "784": 6, "848": 8, "849": 8, "850": 8, "851": 8, "852": 8, "853": 8, "854": 3, "1033": 7, "1034": 7, "1056": 6, "1057": 8, "1058": 8, "1059": 8, "1060": 8, "1061": 8, "1062": 8, "1063": 8, "1064": 8, "1065": 8, "1066": 8, "1067": 8, "1068": 8, "1088": 8, "1089": 8, "1090": 8, "1091": 8, "1092": 8, "1093": 8, "1094": 8, "1095": 8, "1096": 8, "1097": 8, "1098": 8, "1099": 8, "1100": 8, "1120": 8, "1121": 8, "1122": 8, "1123": 8, "1124": 8, "1125": 8, "1126": 8, "1127": 8, "1128": 8, "1129": 8, "1130": 8, "1131": 8, "1132": 8, "1133": 8, "1134": 8, "1135": 8, "1136": 8, "1137": 8, "1138": 8, "1139": 8, "1140": 8, "1141": 8, "1142": 8, "1143": 8, "1146": 8, "1147": 8, "1148": 8, "1149": 8, "1150": 8, "1151": 8, "1362": 8, "1857": 8, "1859": 8, "1920": 7},
|
||||
"2": {"189": 7, "193": 8, "197": 8, "201": 8, "209": 7, "211": 2, "241": 6, "298": 8, "304": 1, "308": 4, "309": 8, "311": 8, "313": 8, "320": 3, "328": 1, "352": 5, "381": 6, "384": 4, "386": 8, "388": 8, "451": 8, "452": 8, "453": 6, "479": 3, "481": 7, "485": 8, "489": 8, "493": 8, "497": 8, "500": 6, "501": 8, "528": 4, "532": 6, "560": 8, "562": 8, "563": 5, "565": 5, "566": 5, "608": 8, "609": 6, "610": 6, "611": 6, "612": 8, "613": 8, "707": 8, "715": 8, "717": 5, "761": 7, "767": 4, "810": 8, "840": 5, "842": 5, "844": 8, "869": 4, "880": 6, "977": 8, "1001": 8, "1017": 8, "1020": 8, "1033": 7, "1034": 7, "1217": 8, "1221": 5, "1233": 8, "1249": 8, "1265": 8, "1267": 1, "1280": 4, "1296": 4, "1300": 8, "1922": 7, "1930": 7}
|
||||
}
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"protected_inventory_sha256": "89caa189ae62ee32e0ebd5a2e6ff43b2c571194b6941e9d65862d5a95bf3e115", "schema_version": 1}
|
||||
{"protected_inventory_sha256": "cbd35189096c5a77ef088856429ee9cdef492cbd055885141a3f4b776329993e", "schema_version": 1}
|
||||
|
||||
Reference in New Issue
Block a user