mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-09-30 19:33:42 +08:00
make car fingerprint cacheable
This commit is contained in:
@@ -82,6 +82,8 @@ keys = {
|
|||||||
"DragonDisableDriverSafetyCheck": [TxType.PERSISTENT],
|
"DragonDisableDriverSafetyCheck": [TxType.PERSISTENT],
|
||||||
"DragonAutoShutdownAt": [TxType.PERSISTENT],
|
"DragonAutoShutdownAt": [TxType.PERSISTENT],
|
||||||
"DragonTempDisableSteerOnSignal": [TxType.PERSISTENT],
|
"DragonTempDisableSteerOnSignal": [TxType.PERSISTENT],
|
||||||
|
"DragonUseCachedCar": [TxType.PERSISTENT],
|
||||||
|
"DragonCachedCar": [TxType.PERSISTENT],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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.boardd.boardd import can_list_to_can_capnp
|
||||||
from selfdrive.swaglog import cloudlog
|
from selfdrive.swaglog import cloudlog
|
||||||
import selfdrive.messaging as messaging
|
import selfdrive.messaging as messaging
|
||||||
|
import ast
|
||||||
|
from common.params import Params
|
||||||
|
params = Params()
|
||||||
|
|
||||||
|
|
||||||
def get_startup_alert(car_recognized, controller_available):
|
def get_startup_alert(car_recognized, controller_available):
|
||||||
@@ -79,58 +82,64 @@ def fingerprint(logcan, sendcan):
|
|||||||
vin = ""
|
vin = ""
|
||||||
|
|
||||||
frame = 0
|
frame = 0
|
||||||
while True:
|
|
||||||
a = messaging.recv_one(logcan)
|
|
||||||
|
|
||||||
for can in a.can:
|
if params.get("DragonUseCachedCar") == "1" and params.get("DragonCachedCar") is not None:
|
||||||
can_seen = True
|
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?
|
for can in a.can:
|
||||||
if can.src == 0 and can.address == 0x7e8:
|
can_seen = True
|
||||||
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
|
|
||||||
|
|
||||||
# ignore everything not on bus 0 and with more than 11 bits,
|
# have we got a VIN query response?
|
||||||
# which are ussually sporadic and hard to include in fingerprints.
|
if can.src == 0 and can.address == 0x7e8:
|
||||||
# also exclude VIN query response on 0x7e8
|
vin_never_responded = False
|
||||||
if can.src == 0 and can.address < 0x800 and can.address != 0x7e8:
|
# basic sanity checks on ISO-TP response
|
||||||
finger[can.address] = len(can.dat)
|
if is_vin_response_valid(can.dat, vin_step, vin_cnt):
|
||||||
candidate_cars = eliminate_incompatible_cars(can, candidate_cars)
|
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:
|
# ignore everything not on bus 0 and with more than 11 bits,
|
||||||
can_seen_frame = frame
|
# 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
|
if can_seen_frame is None and can_seen:
|
||||||
# message has elapsed, exit. Toyota needs higher time_fingerprint, since DSU does not
|
can_seen_frame = frame
|
||||||
# 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
|
|
||||||
|
|
||||||
# bail if no cars left or we've been waiting for more than 2s since can_seen
|
# if we only have one car choice and the time_fingerprint since we got our first
|
||||||
elif len(candidate_cars) == 0 or (can_seen_frame is not None and (frame - can_seen_frame) > 200):
|
# message has elapsed, exit. Toyota needs higher time_fingerprint, since DSU does not
|
||||||
return None, finger, ""
|
# 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.
|
# bail if no cars left or we've been waiting for more than 2s since can_seen
|
||||||
# sendcan is probably not ready due to the zmq slow joiner syndrome
|
elif len(candidate_cars) == 0 or (can_seen_frame is not None and (frame - can_seen_frame) > 200):
|
||||||
# TODO: VIN query temporarily disabled until we have the harness
|
return None, finger, ""
|
||||||
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
|
|
||||||
|
|
||||||
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
|
frame += 1
|
||||||
if vin_step == len(vin_cnts) and vin_cnt == vin_cnts[-1]:
|
|
||||||
vin = "".join(vin_dat[3:])
|
# 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("fingerprinted %s", candidate_cars[0])
|
||||||
cloudlog.warning("VIN %s", vin)
|
cloudlog.warning("VIN %s", vin)
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ default_conf = {
|
|||||||
'DragonDisableDriverSafetyCheck': '0',
|
'DragonDisableDriverSafetyCheck': '0',
|
||||||
'DragonAutoShutdownAt': '30', # in minute
|
'DragonAutoShutdownAt': '30', # in minute
|
||||||
'DragonTempDisableSteerOnSignal': '0',
|
'DragonTempDisableSteerOnSignal': '0',
|
||||||
|
'DragonUseCachedCar': '1',
|
||||||
|
'DragonCachedCar': '',
|
||||||
}
|
}
|
||||||
|
|
||||||
# def write_json_config(config):
|
# def write_json_config(config):
|
||||||
|
|||||||
Reference in New Issue
Block a user