platform codes can just use platform hint and model year - software revision not useful

pull/31124/head
Cameron Clough 2 years ago
parent 0eee2107a6
commit 4419096c8c
  1. 17
      selfdrive/car/ford/tests/print_platform_codes.py
  2. 15
      selfdrive/car/ford/values.py

@ -10,16 +10,21 @@ ECU_NAME = {v: k for k, v in Ecu.schema.enumerants.items()}
if __name__ == "__main__":
cars_for_code: defaultdict = defaultdict(lambda: defaultdict(set))
for car_model, ecus in FW_VERSIONS.items():
print(car_model)
for ecu in sorted(ecus, key=lambda x: int(x[0])):
platform_codes = get_platform_codes(ecus[ecu])
code_versions = defaultdict(set)
for code, version in platform_codes:
code_versions[code].add(version)
for code in platform_codes:
cars_for_code[ecu][code].update({ car_model })
print(f' (Ecu.{ECU_NAME[ecu[0]]}, {hex(ecu[1])}, {ecu[2]}):')
for code, versions in code_versions.items():
print(f' {code.decode()}: {sorted({ version.decode() for version in versions })}')
print(f' Codes: {platform_codes}')
print()
print('\nCar models vs. platform codes:')
for ecu, codes in cars_for_code.items():
print(f' (Ecu.{ECU_NAME[ecu[0]]}, {hex(ecu[1])}, {ecu[2]}):')
for code, cars in codes.items():
print(f' {code!r}: {sorted(map(str, cars))}')

@ -150,28 +150,21 @@ CANFD_CAR = {CAR.F_150_MK14, CAR.F_150_LIGHTNING_MK1, CAR.MUSTANG_MACH_E_MK1}
# 2 = Platform hint
# 3 = Part number (effectively maps to ECU)
# 4 = Software version (reset to AA for each model year)
# https://regexr.com/7qu7h
FW_ALPHABET = b'A-HJ-NP-VX-Z'
FW_RE = re.compile(b'^(?P<model_year>[' + FW_ALPHABET + b'])' +
b'(?P<platform_hint>[0-9' + FW_ALPHABET + b']{3})-' +
b'(?P<part_number>[0-9' + FW_ALPHABET + b']{5,6})-' +
b'(?P<software_version>[' + FW_ALPHABET + b']{2,})$')
b'(?P<revision>[' + FW_ALPHABET + b']{2,})$')
def get_platform_codes(fw_versions: list[bytes]) -> set[tuple[bytes, bytes]]:
codes = set() # (platform_hint, model_year-software_version)
def get_platform_codes(fw_versions: list[bytes]) -> set[bytes]:
codes = set() # platform_hint-model_year
for firmware in fw_versions:
m = FW_RE.match(firmware.rstrip(b'\0'))
if m is None:
continue
# since "AAA" is higher than "ZZ", prepend "A" to two-letter versions (i.e. "ZZ" -> "AZZ")
software_version = (b'A' + m.group('software_version'))[-3:]
code = m.group('platform_hint')
version = b'-'.join([m.group('model_year'), software_version])
codes.add((code, version))
codes.add(b'-'.join([m.group('platform_hint'), m.group('model_year')]))
return codes

Loading…
Cancel
Save