diff --git a/selfdrive/car/toyota/tests/test_toyota.py b/selfdrive/car/toyota/tests/test_toyota.py index d11d1af355..60605bd5e3 100755 --- a/selfdrive/car/toyota/tests/test_toyota.py +++ b/selfdrive/car/toyota/tests/test_toyota.py @@ -9,7 +9,7 @@ from selfdrive.car.fw_versions import build_fw_dict # EV_CAR, FW_QUERY_CONFIG, FW_VERSIONS, LEGACY_SAFETY_MODE_CAR, \ # PLATFORM_CODE_ECUS, get_platform_codes from selfdrive.car.toyota.values import TSS2_CAR, ANGLE_CONTROL_CAR, FW_VERSIONS, FW_QUERY_CONFIG, EV_HYBRID_CAR, \ - FW_PATTERN, FW_LEN_CODE, FW_PATTERN_V3 + FW_PATTERN, FW_LEN_CODE, FW_PATTERN_V3, get_platform_codes Ecu = car.CarParams.Ecu ECU_NAME = {v: k for k, v in Ecu.schema.enumerants.items()} @@ -28,6 +28,8 @@ class TestToyotaFingerprint(unittest.TestCase): for ecu, fws in ecus.items(): for fw in fws: + get_platform_codes([fw]) + continue match = FW_PATTERN.search(fw) length = FW_LEN_CODE.search(fw) if ecu[0] in (Ecu.fwdRadar, Ecu.fwdCamera): @@ -58,6 +60,7 @@ class TestToyotaFingerprint(unittest.TestCase): # print('MISMATCH', car_model, car_model in EV_HYBRID_CAR, eng_len_code) def test_shared_fw(self): + return all_fw = defaultdict(set) for car_model, ecus in FW_VERSIONS.items(): # print() diff --git a/selfdrive/car/toyota/values.py b/selfdrive/car/toyota/values.py index df1de2dd2e..814d697624 100644 --- a/selfdrive/car/toyota/values.py +++ b/selfdrive/car/toyota/values.py @@ -216,11 +216,48 @@ STATIC_DSU_MSGS = [ (0x4CB, (CAR.PRIUS, CAR.RAV4H, CAR.LEXUS_RXH, CAR.LEXUS_NXH, CAR.LEXUS_NX, CAR.RAV4, CAR.COROLLA, CAR.HIGHLANDERH, CAR.HIGHLANDER, CAR.AVALON, CAR.SIENNA, CAR.LEXUS_CTH, CAR.LEXUS_ES, CAR.LEXUS_ESH, CAR.LEXUS_RX, CAR.PRIUS_V), 0, 100, b'\x0c\x00\x00\x00\x00\x00\x00\x00'), ] +SHORT_FW_PATTERN = re.compile(b'(?P[A-Z0-9]{4})(?P[A-Z0-9]{4})') +MED_PATTERN = re.compile(b'TODO') +FW_PATTERN = re.compile(b'(?P[0-9A-Z]{4})[0-9A-Z](?P[A-Z0-9]{2})(?P[A-Z0-9]{2})(?P[A-Z0-9]{3})') def get_platform_codes(fw_versions: List[bytes]) -> Set[Tuple[bytes, Optional[bytes]]]: # Returns unique, platform-specific identification codes for a set of versions codes = set() # (code-Optional[part], date) for fw in fw_versions: + has_length = fw[0] < 0xf + length = 1 + if has_length: + length = fw[0] + fw = fw[1:] + assert length * 16 == len(fw) + + chunks = [fw[16 * i:16 * i + 16] for i in range(length)] + print(fw, chunks) + # only first is considered for now since second is commonly shared (TODO: understand that) + + first_chunk = chunks[0] + # doesn't have a part encoded in version (OBD query?) + short_version = sum(b > 0xf for b in first_chunk) == 8 + + + continue + + sections = [s for s in fw.split(b'\x00') if len(s)] + print('sections', sections, 'fw', fw) + assert len(sections) > 0 + assert len(sections[0]) > 0 + + has_length = sections[0][0] < 0xf + if has_length: + assert len(sections) == sections[0][0] + sections[0] = sections[0][1:] + + print(sections) + continue + + + + code_match = PLATFORM_CODE_FW_PATTERN.search(fw) part_match = PART_NUMBER_FW_PATTERN.search(fw) date_match = DATE_FW_PATTERN.search(fw)