From d91c191854acb30f64d64c646ae2d1449cc0818f Mon Sep 17 00:00:00 2001 From: Rick Lan Date: Thu, 11 Jul 2019 15:40:12 +1000 Subject: [PATCH 1/4] make car fingerprint cacheable --- common/params.py | 2 + selfdrive/car/car_helpers.py | 95 +++++++++++--------- selfdrive/dragonpilot/dragonconf/__init__.py | 2 + 3 files changed, 56 insertions(+), 43 deletions(-) diff --git a/common/params.py b/common/params.py index 3747b6e35..66866c773 100755 --- a/common/params.py +++ b/common/params.py @@ -82,6 +82,8 @@ keys = { "DragonDisableDriverSafetyCheck": [TxType.PERSISTENT], "DragonAutoShutdownAt": [TxType.PERSISTENT], "DragonTempDisableSteerOnSignal": [TxType.PERSISTENT], + "DragonUseCachedCar": [TxType.PERSISTENT], + "DragonCachedCar": [TxType.PERSISTENT], } diff --git a/selfdrive/car/car_helpers.py b/selfdrive/car/car_helpers.py index f7e8c5375..18bffcc6b 100644 --- a/selfdrive/car/car_helpers.py +++ b/selfdrive/car/car_helpers.py @@ -5,6 +5,9 @@ from common.fingerprints import eliminate_incompatible_cars, all_known_cars from selfdrive.boardd.boardd import can_list_to_can_capnp from selfdrive.swaglog import cloudlog import selfdrive.messaging as messaging +import ast +from common.params import Params +params = Params() def get_startup_alert(car_recognized, controller_available): @@ -79,58 +82,64 @@ def fingerprint(logcan, sendcan): vin = "" frame = 0 - while True: - a = messaging.recv_one(logcan) - for can in a.can: - can_seen = True + if params.get("DragonUseCachedCar") == "1" and params.get("DragonCachedCar") is not None: + candidate_cars, finger, vin = ast.literal_eval(params.get("DragonCachedCar")) + else: + while True: + a = messaging.recv_one(logcan) - # have we got a VIN query response? - if can.src == 0 and can.address == 0x7e8: - vin_never_responded = False - # basic sanity checks on ISO-TP response - if is_vin_response_valid(can.dat, vin_step, vin_cnt): - vin_dat += can.dat[2:] if vin_step == 0 else can.dat[1:] - vin_cnt += 1 - if vin_cnt == vin_cnts[vin_step]: - vin_responded = True - vin_step += 1 + for can in a.can: + can_seen = True - # ignore everything not on bus 0 and with more than 11 bits, - # which are ussually sporadic and hard to include in fingerprints. - # also exclude VIN query response on 0x7e8 - if can.src == 0 and can.address < 0x800 and can.address != 0x7e8: - finger[can.address] = len(can.dat) - candidate_cars = eliminate_incompatible_cars(can, candidate_cars) + # have we got a VIN query response? + if can.src == 0 and can.address == 0x7e8: + vin_never_responded = False + # basic sanity checks on ISO-TP response + if is_vin_response_valid(can.dat, vin_step, vin_cnt): + vin_dat += can.dat[2:] if vin_step == 0 else can.dat[1:] + vin_cnt += 1 + if vin_cnt == vin_cnts[vin_step]: + vin_responded = True + vin_step += 1 - if can_seen_frame is None and can_seen: - can_seen_frame = frame + # ignore everything not on bus 0 and with more than 11 bits, + # which are ussually sporadic and hard to include in fingerprints. + # also exclude VIN query response on 0x7e8 + if can.src == 0 and can.address < 0x800 and can.address != 0x7e8: + finger[can.address] = len(can.dat) + candidate_cars = eliminate_incompatible_cars(can, candidate_cars) - # if we only have one car choice and the time_fingerprint since we got our first - # message has elapsed, exit. Toyota needs higher time_fingerprint, since DSU does not - # broadcast immediately - if len(candidate_cars) == 1 and can_seen_frame is not None: - time_fingerprint = 1.0 if ("TOYOTA" in candidate_cars[0] or "LEXUS" in candidate_cars[0]) else 0.1 - if (frame - can_seen_frame) > (time_fingerprint * 100): - break + if can_seen_frame is None and can_seen: + can_seen_frame = frame - # bail if no cars left or we've been waiting for more than 2s since can_seen - elif len(candidate_cars) == 0 or (can_seen_frame is not None and (frame - can_seen_frame) > 200): - return None, finger, "" + # if we only have one car choice and the time_fingerprint since we got our first + # message has elapsed, exit. Toyota needs higher time_fingerprint, since DSU does not + # broadcast immediately + if len(candidate_cars) == 1 and can_seen_frame is not None: + time_fingerprint = 1.0 if ("TOYOTA" in candidate_cars[0] or "LEXUS" in candidate_cars[0]) else 0.1 + if (frame - can_seen_frame) > (time_fingerprint * 100): + break - # keep sending VIN qury if ECU isn't responsing. - # sendcan is probably not ready due to the zmq slow joiner syndrome - # TODO: VIN query temporarily disabled until we have the harness - if False and can_seen and (vin_never_responded or (vin_responded and vin_step < len(vin_cnts))): - sendcan.send(can_list_to_can_capnp([vin_query_msg[vin_step]], msgtype='sendcan')) - vin_responded = False - vin_cnt = 0 + # bail if no cars left or we've been waiting for more than 2s since can_seen + elif len(candidate_cars) == 0 or (can_seen_frame is not None and (frame - can_seen_frame) > 200): + return None, finger, "" - frame += 1 + # keep sending VIN qury if ECU isn't responsing. + # sendcan is probably not ready due to the zmq slow joiner syndrome + # TODO: VIN query temporarily disabled until we have the harness + if False and can_seen and (vin_never_responded or (vin_responded and vin_step < len(vin_cnts))): + sendcan.send(can_list_to_can_capnp([vin_query_msg[vin_step]], msgtype='sendcan')) + vin_responded = False + vin_cnt = 0 - # only report vin if procedure is finished - if vin_step == len(vin_cnts) and vin_cnt == vin_cnts[-1]: - vin = "".join(vin_dat[3:]) + frame += 1 + + # only report vin if procedure is finished + if vin_step == len(vin_cnts) and vin_cnt == vin_cnts[-1]: + vin = "".join(vin_dat[3:]) + + params.put("DragonCachedCar", repr([candidate_cars, finger, vin])) cloudlog.warning("fingerprinted %s", candidate_cars[0]) cloudlog.warning("VIN %s", vin) diff --git a/selfdrive/dragonpilot/dragonconf/__init__.py b/selfdrive/dragonpilot/dragonconf/__init__.py index 51be9d3a9..e0dcc5c49 100644 --- a/selfdrive/dragonpilot/dragonconf/__init__.py +++ b/selfdrive/dragonpilot/dragonconf/__init__.py @@ -10,6 +10,8 @@ default_conf = { 'DragonDisableDriverSafetyCheck': '0', 'DragonAutoShutdownAt': '30', # in minute 'DragonTempDisableSteerOnSignal': '0', + 'DragonUseCachedCar': '1', + 'DragonCachedCar': '', } # def write_json_config(config): From ff3145215ecf04e9eee5bb57cdc8a2fc77117047 Mon Sep 17 00:00:00 2001 From: Rick Lan Date: Thu, 11 Jul 2019 16:30:06 +1000 Subject: [PATCH 2/4] use pickle instead of repr --- selfdrive/car/car_helpers.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/selfdrive/car/car_helpers.py b/selfdrive/car/car_helpers.py index 18bffcc6b..62cb3bbbe 100644 --- a/selfdrive/car/car_helpers.py +++ b/selfdrive/car/car_helpers.py @@ -5,7 +5,7 @@ from common.fingerprints import eliminate_incompatible_cars, all_known_cars from selfdrive.boardd.boardd import can_list_to_can_capnp from selfdrive.swaglog import cloudlog import selfdrive.messaging as messaging -import ast +import pickle from common.params import Params params = Params() @@ -84,7 +84,7 @@ def fingerprint(logcan, sendcan): frame = 0 if params.get("DragonUseCachedCar") == "1" and params.get("DragonCachedCar") is not None: - candidate_cars, finger, vin = ast.literal_eval(params.get("DragonCachedCar")) + candidate_cars, finger, vin = pickle.loads(params.get("DragonCachedCar")) else: while True: a = messaging.recv_one(logcan) @@ -139,7 +139,7 @@ def fingerprint(logcan, sendcan): if vin_step == len(vin_cnts) and vin_cnt == vin_cnts[-1]: vin = "".join(vin_dat[3:]) - params.put("DragonCachedCar", repr([candidate_cars, finger, vin])) + params.put("DragonCachedCar", pickle.dumps([candidate_cars, finger, vin])) cloudlog.warning("fingerprinted %s", candidate_cars[0]) cloudlog.warning("VIN %s", vin) From 2b44c2fe3d831fdb1cadaaf2d372a849a97053d4 Mon Sep 17 00:00:00 2001 From: Rick Lan Date: Fri, 12 Jul 2019 09:16:49 +1000 Subject: [PATCH 3/4] =?UTF-8?q?=E5=B0=87=E6=95=B8=E5=80=BC=E5=88=86?= =?UTF-8?q?=E9=96=8B=E5=84=B2=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- selfdrive/car/car_helpers.py | 10 +++++++--- selfdrive/dragonpilot/dragonconf/__init__.py | 4 +++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/selfdrive/car/car_helpers.py b/selfdrive/car/car_helpers.py index 62cb3bbbe..e9d5f08cc 100644 --- a/selfdrive/car/car_helpers.py +++ b/selfdrive/car/car_helpers.py @@ -83,8 +83,10 @@ def fingerprint(logcan, sendcan): frame = 0 - if params.get("DragonUseCachedCar") == "1" and params.get("DragonCachedCar") is not None: - candidate_cars, finger, vin = pickle.loads(params.get("DragonCachedCar")) + if params.get("DragonUseCachedCar") == "1" and params.get("DragonCachedFP") != "" and params.get("DragonCachedModel") != "": + candidate_cars = [params.get("DragonCachedModel")] + finger = params.get("DragonCachedFP") + vin = params.get("DragonCachedVIN") else: while True: a = messaging.recv_one(logcan) @@ -139,7 +141,9 @@ def fingerprint(logcan, sendcan): if vin_step == len(vin_cnts) and vin_cnt == vin_cnts[-1]: vin = "".join(vin_dat[3:]) - params.put("DragonCachedCar", pickle.dumps([candidate_cars, finger, vin])) + params.put("DragonCachedModel", pickle.dumps(candidate_cars)) + params.put("DragonCachedFP", pickle.dumps(finger)) + params.put("DragonCachedVIN", pickle.dumps(vin)) cloudlog.warning("fingerprinted %s", candidate_cars[0]) cloudlog.warning("VIN %s", vin) diff --git a/selfdrive/dragonpilot/dragonconf/__init__.py b/selfdrive/dragonpilot/dragonconf/__init__.py index dca90c679..8846bf7ed 100644 --- a/selfdrive/dragonpilot/dragonconf/__init__.py +++ b/selfdrive/dragonpilot/dragonconf/__init__.py @@ -13,7 +13,9 @@ default_conf = { 'DragonDisableLogger': '0', 'DragonNoctuaMode': '0', 'DragonUseCachedCar': '1', - 'DragonCachedCar': '', + 'DragonCachedModel': '', # for cache car + 'DragonCachedFP': '', # for cache car + 'DragonCachedVIN': '', # for cache car } def dragonpilot_set_params(params): From eef175d247c217754cca79d7303e3424c102c06a Mon Sep 17 00:00:00 2001 From: Rick Lan Date: Fri, 12 Jul 2019 09:35:05 +1000 Subject: [PATCH 4/4] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=8F=83=E6=95=B8?= =?UTF-8?q?=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/params.py | 6 ++++-- selfdrive/car/car_helpers.py | 2 +- selfdrive/dragonpilot/dragonconf/__init__.py | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/common/params.py b/common/params.py index c09ab963e..451a9c250 100755 --- a/common/params.py +++ b/common/params.py @@ -84,8 +84,10 @@ keys = { "DragonTempDisableSteerOnSignal": [TxType.PERSISTENT], "DragonDisableLogger": [TxType.PERSISTENT], "DragonNoctuaMode": [TxType.PERSISTENT], - "DragonUseCachedCar": [TxType.PERSISTENT], - "DragonCachedCar": [TxType.PERSISTENT], + "DragonCacheCar": [TxType.PERSISTENT], + "DragonCachedModel": [TxType.PERSISTENT], + "DragonCachedFP": [TxType.PERSISTENT], + "DragonCachedVIN": [TxType.PERSISTENT], } diff --git a/selfdrive/car/car_helpers.py b/selfdrive/car/car_helpers.py index e9d5f08cc..5977663df 100644 --- a/selfdrive/car/car_helpers.py +++ b/selfdrive/car/car_helpers.py @@ -83,7 +83,7 @@ def fingerprint(logcan, sendcan): frame = 0 - if params.get("DragonUseCachedCar") == "1" and params.get("DragonCachedFP") != "" and params.get("DragonCachedModel") != "": + if params.get("DragonCacheCar") == "1" and params.get("DragonCachedFP") != "" and params.get("DragonCachedModel") != "": candidate_cars = [params.get("DragonCachedModel")] finger = params.get("DragonCachedFP") vin = params.get("DragonCachedVIN") diff --git a/selfdrive/dragonpilot/dragonconf/__init__.py b/selfdrive/dragonpilot/dragonconf/__init__.py index 8846bf7ed..0234337b2 100644 --- a/selfdrive/dragonpilot/dragonconf/__init__.py +++ b/selfdrive/dragonpilot/dragonconf/__init__.py @@ -12,7 +12,7 @@ default_conf = { 'DragonTempDisableSteerOnSignal': '0', 'DragonDisableLogger': '0', 'DragonNoctuaMode': '0', - 'DragonUseCachedCar': '1', + 'DragonCacheCar': '1', 'DragonCachedModel': '', # for cache car 'DragonCachedFP': '', # for cache car 'DragonCachedVIN': '', # for cache car