function to get all ecus

pull/31221/head
Shane Smiskol 1 year ago
parent 3ca602becc
commit 5e20cefca4
  1. 17
      selfdrive/car/fw_query_definitions.py
  2. 13
      selfdrive/car/fw_versions.py
  3. 2
      selfdrive/car/gm/fingerprints.py

@ -1,9 +1,10 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import capnp import capnp
import copy import copy
from collections import defaultdict
from dataclasses import dataclass, field from dataclasses import dataclass, field
import struct import struct
from typing import Callable, Dict, List, Optional, Set, Tuple from typing import Callable, DefaultDict, Dict, List, Optional, Set, Tuple
import panda.python.uds as uds import panda.python.uds as uds
@ -85,7 +86,7 @@ class FwQueryConfig:
# Overrides and removes from essential ecus for specific models and ecus (exact matching) # Overrides and removes from essential ecus for specific models and ecus (exact matching)
non_essential_ecus: Dict[capnp.lib.capnp._EnumModule, List[str]] = field(default_factory=dict) non_essential_ecus: Dict[capnp.lib.capnp._EnumModule, List[str]] = field(default_factory=dict)
# Ecus added for data collection, not to be fingerprinted on # Ecus added for data collection, not to be fingerprinted on
extra_ecus: List[Tuple[capnp.lib.capnp._EnumModule, int, Optional[int]]] = field(default_factory=list) extra_ecus: list[EcuAddrSubAddr] = field(default_factory=list)
# Function a brand can implement to provide better fuzzy matching. Takes in FW versions, # Function a brand can implement to provide better fuzzy matching. Takes in FW versions,
# returns set of candidates. Only will match if one candidate is returned # returns set of candidates. Only will match if one candidate is returned
match_fw_to_car_fuzzy: Optional[Callable[[LiveFwVersions, OfflineFwVersions], Set[str]]] = None match_fw_to_car_fuzzy: Optional[Callable[[LiveFwVersions, OfflineFwVersions], Set[str]]] = None
@ -96,3 +97,15 @@ class FwQueryConfig:
new_request = copy.deepcopy(self.requests[i]) new_request = copy.deepcopy(self.requests[i])
new_request.bus += 4 new_request.bus += 4
self.requests.append(new_request) self.requests.append(new_request)
def get_all_ecus(self, fw_versions: OfflineFwVersions, include_ecu: bool = False,
include_extra_ecus: bool = True) -> set[EcuAddrSubAddr | AddrType]:
# Add ecus in database + extra ecus
brand_ecus = {ecu for ecus in fw_versions.values() for ecu in ecus}
if include_extra_ecus:
brand_ecus |= set(self.extra_ecus)
if include_ecu:
return brand_ecus
return {(addr, subaddr) for _, addr, subaddr in brand_ecus}

@ -46,13 +46,8 @@ def build_fw_dict(fw_versions: List[capnp.lib.capnp._DynamicStructBuilder],
def get_brand_addrs() -> Dict[str, Set[AddrType]]: def get_brand_addrs() -> Dict[str, Set[AddrType]]:
brand_addrs: DefaultDict[str, Set[AddrType]] = defaultdict(set) return {brand: config.get_all_ecus(VERSIONS[brand]) for
for brand, cars in VERSIONS.items(): brand, config in FW_QUERY_CONFIGS.items()}
# Add ecus in database + extra ecus to match against
brand_addrs[brand] |= {(addr, sub_addr) for _, addr, sub_addr in FW_QUERY_CONFIGS[brand].extra_ecus}
for fw in cars.values():
brand_addrs[brand] |= {(addr, sub_addr) for _, addr, sub_addr in fw.keys()}
return dict(brand_addrs)
def match_fw_to_car_fuzzy(live_fw_versions, match_brand=None, log=True, exclude=None): def match_fw_to_car_fuzzy(live_fw_versions, match_brand=None, log=True, exclude=None):
@ -119,8 +114,8 @@ def match_fw_to_car_exact(live_fw_versions, match_brand=None, log=True, extra_fw
for candidate, fws in candidates.items(): for candidate, fws in candidates.items():
config = FW_QUERY_CONFIGS[MODEL_TO_BRAND[candidate]] config = FW_QUERY_CONFIGS[MODEL_TO_BRAND[candidate]]
if not len(fws): # if not len(fws):
invalid.add(candidate) # invalid.add(candidate)
for ecu, expected_versions in fws.items(): for ecu, expected_versions in fws.items():
expected_versions = expected_versions + extra_fw_versions.get(candidate, {}).get(ecu, []) expected_versions = expected_versions + extra_fw_versions.get(candidate, {}).get(ecu, [])

@ -59,5 +59,5 @@ FINGERPRINTS = {
} }
FW_VERSIONS: dict[str, dict[tuple, list[bytes]]] = { FW_VERSIONS: dict[str, dict[tuple, list[bytes]]] = {
CAR.BOLT_EUV: {}, # CAR.BOLT_EUV: {},
} }

Loading…
Cancel
Save