From 88a385e9c9e81d2694e88bdc64e56477ff004588 Mon Sep 17 00:00:00 2001 From: Willem Melching Date: Tue, 19 May 2020 13:43:44 -0700 Subject: [PATCH] Hyundai fw query (#1540) * hyundai fw query * Change query * this works * That is not engine * hyundai fw query * Change query * this works * That is not engine * Skip FW query in test_car_models * Those routes don't fingerprint properly after speedup * only send toyota queries to subaddresses Co-authored-by: openpilot laptop old-commit-hash: bb8bbdd9ee4d610e2ae6048021407863b3f74683 --- selfdrive/car/car_helpers.py | 3 ++- selfdrive/car/fw_versions.py | 34 ++++++++++++++++++++++++++----- selfdrive/car/hyundai/values.py | 10 +++++++++ selfdrive/test/test_car_models.py | 3 +++ 4 files changed, 44 insertions(+), 6 deletions(-) diff --git a/selfdrive/car/car_helpers.py b/selfdrive/car/car_helpers.py index 434ed1ef1b..23cbd1abf5 100644 --- a/selfdrive/car/car_helpers.py +++ b/selfdrive/car/car_helpers.py @@ -77,8 +77,9 @@ def only_toyota_left(candidate_cars): # **** for use live only **** def fingerprint(logcan, sendcan, has_relay): fixed_fingerprint = os.environ.get('FINGERPRINT', "") + skip_fw_query = os.environ.get('SKIP_FW_QUERY', False) - if has_relay and not fixed_fingerprint: + if has_relay and not fixed_fingerprint and not skip_fw_query: # Vin query only reliably works thorugh OBDII bus = 1 diff --git a/selfdrive/car/fw_versions.py b/selfdrive/car/fw_versions.py index 95b970f125..16f20ca3f9 100755 --- a/selfdrive/car/fw_versions.py +++ b/selfdrive/car/fw_versions.py @@ -12,9 +12,11 @@ import panda.python.uds as uds from cereal import car Ecu = car.CarParams.Ecu + def p16(val): return struct.pack("!H", val) + TESTER_PRESENT_REQUEST = bytes([uds.SERVICE_TYPE.TESTER_PRESENT, 0x0]) TESTER_PRESENT_RESPONSE = bytes([uds.SERVICE_TYPE.TESTER_PRESENT + 0x40, 0x0]) @@ -36,6 +38,13 @@ UDS_VERSION_REQUEST = bytes([uds.SERVICE_TYPE.READ_DATA_BY_IDENTIFIER]) + \ UDS_VERSION_RESPONSE = bytes([uds.SERVICE_TYPE.READ_DATA_BY_IDENTIFIER + 0x40]) + \ p16(uds.DATA_IDENTIFIER_TYPE.APPLICATION_SOFTWARE_IDENTIFICATION) + +HYUNDAI_VERSION_REQUEST = bytes([uds.SERVICE_TYPE.READ_DATA_BY_IDENTIFIER]) + \ + p16(uds.DATA_IDENTIFIER_TYPE.VEHICLE_MANUFACTURER_SPARE_PART_NUMBER) + \ + p16(uds.DATA_IDENTIFIER_TYPE.APPLICATION_SOFTWARE_IDENTIFICATION) + \ + p16(0xf1a0) # 4 Byte version number +HYUNDAI_VERSION_RESPONSE = bytes([uds.SERVICE_TYPE.READ_DATA_BY_IDENTIFIER + 0x40]) + TOYOTA_VERSION_REQUEST = b'\x1a\x88\x01' TOYOTA_VERSION_RESPONSE = b'\x5a\x88\x01' @@ -43,24 +52,35 @@ OBD_VERSION_REQUEST = b'\x09\x04' OBD_VERSION_RESPONSE = b'\x49\x04' +# supports subaddressing, request, response REQUESTS = [ + # Hundai + ( + False, + [HYUNDAI_VERSION_REQUEST], + [HYUNDAI_VERSION_RESPONSE], + ), # Honda ( + False, [UDS_VERSION_REQUEST], - [UDS_VERSION_RESPONSE] + [UDS_VERSION_RESPONSE], ), # Toyota ( + True, [SHORT_TESTER_PRESENT_REQUEST, TOYOTA_VERSION_REQUEST], - [SHORT_TESTER_PRESENT_RESPONSE, TOYOTA_VERSION_RESPONSE] + [SHORT_TESTER_PRESENT_RESPONSE, TOYOTA_VERSION_RESPONSE], ), ( + True, [SHORT_TESTER_PRESENT_REQUEST, OBD_VERSION_REQUEST], - [SHORT_TESTER_PRESENT_RESPONSE, OBD_VERSION_RESPONSE] + [SHORT_TESTER_PRESENT_RESPONSE, OBD_VERSION_RESPONSE], ), ( + True, [TESTER_PRESENT_REQUEST, DEFAULT_DIAGNOSTIC_REQUEST, EXTENDED_DIAGNOSTIC_REQUEST, UDS_VERSION_REQUEST], - [TESTER_PRESENT_RESPONSE, DEFAULT_DIAGNOSTIC_RESPONSE, EXTENDED_DIAGNOSTIC_RESPONSE, UDS_VERSION_RESPONSE] + [TESTER_PRESENT_RESPONSE, DEFAULT_DIAGNOSTIC_RESPONSE, EXTENDED_DIAGNOSTIC_RESPONSE, UDS_VERSION_RESPONSE], ) ] @@ -134,8 +154,12 @@ def get_fw_versions(logcan, sendcan, bus, extra=None, timeout=0.1, debug=False, fw_versions = {} for i, addr in enumerate(tqdm(addrs, disable=not progress)): for addr_chunk in chunks(addr): - for request, response in REQUESTS: + for supports_sub_addr, request, response in REQUESTS: try: + # Don't send Hyundai and Honda requests to subaddress + if i != 0 and not supports_sub_addr: + continue + query = IsoTpParallelQuery(sendcan, logcan, bus, addr_chunk, request, response, debug=debug) t = 2 * timeout if i == 0 else timeout fw_versions.update(query.get_data(t)) diff --git a/selfdrive/car/hyundai/values.py b/selfdrive/car/hyundai/values.py index 480ed6f269..e072d1b294 100644 --- a/selfdrive/car/hyundai/values.py +++ b/selfdrive/car/hyundai/values.py @@ -135,6 +135,16 @@ ECU_FINGERPRINT = { Ecu.fwdCamera: [832, 1156, 1191, 1342] } +FW_VERSIONS = { + CAR.SONATA: { + (Ecu.esp, 0x7d1, None): [b'\xf1\x8758910-L0100\xf1\xa01.04'], + (Ecu.engine, 0x7e0, None): [b'\xf1\x87391162M003\xf1\xa0000F'], + (Ecu.eps, 0x7d4, None): [b'\xf1\x8756310L0010\x00\xf1\xa01.01'], + (Ecu.fwdRadar, 0x7d0, None): [b'\xf1\x8799110L0000\xf1\xa01.00'], + (Ecu.transmission, 0x7e1, None): [b'U903\x00\x00\x00\x00\x00\x00'], + } +} + CHECKSUM = { "crc8": [CAR.SANTA_FE, CAR.SONATA, CAR.PALISADE], "6B": [CAR.KIA_SORENTO, CAR.HYUNDAI_GENESIS], diff --git a/selfdrive/test/test_car_models.py b/selfdrive/test/test_car_models.py index 63f42cf556..9954612e8a 100755 --- a/selfdrive/test/test_car_models.py +++ b/selfdrive/test/test_car_models.py @@ -247,6 +247,7 @@ routes = { 'enableCamera': True, 'enableDsu': True, 'enableGasInterceptor': False, + 'fingerprintSource': 'fixed', }, "cdf2f7de565d40ae|2019-04-25--03-53-41": { 'carFingerprint': TOYOTA.RAV4_TSS2, @@ -296,6 +297,7 @@ routes = { "01b22eb2ed121565|2020-02-02--11-25-51": { 'carFingerprint': TOYOTA.LEXUS_RX_TSS2, 'enableCamera': True, + 'fingerprintSource': 'fixed', }, "ec429c0f37564e3c|2020-02-01--17-28-12": { 'carFingerprint': TOYOTA.LEXUS_NXH, @@ -426,6 +428,7 @@ if __name__ == "__main__": params.put("CommunityFeaturesToggle", "1") params.put("Passive", "1" if route in passive_routes else "0") + os.environ['SKIP_FW_QUERY'] = "1" if checks.get('fingerprintSource', None) == 'fixed': os.environ['FINGERPRINT'] = checks['carFingerprint'] else: