FPv2 on multiple buses

fpv2-multibus
Adeeb Shihadeh 2022-03-23 17:22:13 -07:00
parent 85d8997a8a
commit bf567de5b1
6 changed files with 22 additions and 21 deletions

View File

@ -93,8 +93,8 @@ def fingerprint(logcan, sendcan):
skip_fw_query = os.environ.get('SKIP_FW_QUERY', False)
if not fixed_fingerprint and not skip_fw_query:
# Vin query only reliably works thorugh OBDII
bus = 1
# VIN query only reliably works thorugh OBDII
query_buses = (1, )
cached_params = Params().get("CarParamsCache")
if cached_params is not None:
@ -108,8 +108,8 @@ def fingerprint(logcan, sendcan):
car_fw = list(cached_params.carFw)
else:
cloudlog.warning("Getting VIN & FW versions")
_, vin = get_vin(logcan, sendcan, bus)
car_fw = get_fw_versions(logcan, sendcan, bus)
_, vin = get_vin(logcan, sendcan, query_buses)
car_fw = get_fw_versions(logcan, sendcan, query_buses)
exact_fw_match, fw_candidates = match_fw_to_car(car_fw)
else:

View File

@ -16,12 +16,12 @@ def disable_ecu(logcan, sendcan, bus=0, addr=0x7d0, com_cont_req=b'\x28\x83\x01'
for i in range(retry):
try:
query = IsoTpParallelQuery(sendcan, logcan, bus, [addr], [EXT_DIAG_REQUEST], [EXT_DIAG_RESPONSE], debug=debug)
query = IsoTpParallelQuery(sendcan, logcan, [bus], [addr], [EXT_DIAG_REQUEST], [EXT_DIAG_RESPONSE], debug=debug)
for _, _ in query.get_data(timeout).items():
cloudlog.warning("communication control disable tx/rx ...")
query = IsoTpParallelQuery(sendcan, logcan, bus, [addr], [com_cont_req], [COM_CONT_RESPONSE], debug=debug)
query = IsoTpParallelQuery(sendcan, logcan, [bus], [addr], [com_cont_req], [COM_CONT_RESPONSE], debug=debug)
query.get_data(0)
cloudlog.warning("ecu disabled")

View File

@ -286,7 +286,7 @@ def match_fw_to_car(fw_versions, allow_fuzzy=True):
return exact_match, matches
def get_fw_versions(logcan, sendcan, bus, extra=None, timeout=0.1, debug=False, progress=False):
def get_fw_versions(logcan, sendcan, buses, extra=None, timeout=0.1, debug=False, progress=False):
ecu_types = {}
# Extract ECU addresses to query from fingerprints
@ -322,7 +322,7 @@ def get_fw_versions(logcan, sendcan, bus, extra=None, timeout=0.1, debug=False,
addrs = [(a, s) for (b, a, s) in addr_chunk if b in (brand, 'any')]
if addrs:
query = IsoTpParallelQuery(sendcan, logcan, bus, addrs, request, response, response_offset, debug=debug)
query = IsoTpParallelQuery(sendcan, logcan, buses, addrs, request, response, response_offset, debug=debug)
t = 2 * timeout if i == 0 else timeout
fw_versions.update(query.get_data(t))
except Exception:

View File

@ -10,10 +10,10 @@ from panda.python.uds import CanClient, IsoTpMessage, FUNCTIONAL_ADDRS, get_rx_a
class IsoTpParallelQuery:
def __init__(self, sendcan, logcan, bus, addrs, request, response, response_offset=0x8, functional_addr=False, debug=False):
def __init__(self, sendcan, logcan, buses, addrs, request, response, response_offset=0x8, functional_addr=False, debug=False):
self.sendcan = sendcan
self.logcan = logcan
self.bus = bus
self.buses = buses
self.request = request
self.response = response
self.debug = debug
@ -35,7 +35,8 @@ class IsoTpParallelQuery:
for packet in can_packets:
for msg in packet.can:
if msg.src == self.bus:
# TODO: look into this more
if msg.src in self.buses:
if self.functional_addr:
if (0x7E8 <= msg.address <= 0x7EF) or (0x18DAF100 <= msg.address <= 0x18DAF1FF):
fn_addr = next(a for a in FUNCTIONAL_ADDRS if msg.address - a <= 32)
@ -85,14 +86,14 @@ class IsoTpParallelQuery:
# rx_addr not set when using functional tx addr
id_addr = rx_addr or tx_addr[0]
sub_addr = tx_addr[1]
can_client = CanClient(self._can_tx, partial(self._can_rx, id_addr, sub_addr=sub_addr), tx_addr[0], rx_addr,
self.bus, sub_addr=sub_addr, debug=self.debug)
max_len = 8 if sub_addr is None else 7
msg = IsoTpMessage(can_client, timeout=0, max_len=max_len, debug=self.debug)
msg.send(self.request[0])
# TODO: distinguish which bus a msg came from
for b in self.buses:
can_client = CanClient(self._can_tx, partial(self._can_rx, id_addr, sub_addr=sub_addr), tx_addr[0], rx_addr,
b, sub_addr=sub_addr, debug=self.debug)
msg = IsoTpMessage(can_client, timeout=0, max_len=max_len, debug=self.debug)
msg.send(self.request[0])
msgs[tx_addr] = msg
request_counter[tx_addr] = 0

View File

@ -11,10 +11,10 @@ VIN_RESPONSE = b'\x49\x02\x01'
VIN_UNKNOWN = "0" * 17
def get_vin(logcan, sendcan, bus, timeout=0.1, retry=5, debug=False):
def get_vin(logcan, sendcan, buses, timeout=0.1, retry=5, debug=False):
for i in range(retry):
try:
query = IsoTpParallelQuery(sendcan, logcan, bus, FUNCTIONAL_ADDRS, [VIN_REQUEST], [VIN_RESPONSE], functional_addr=True, debug=debug)
query = IsoTpParallelQuery(sendcan, logcan, buses, FUNCTIONAL_ADDRS, [VIN_REQUEST], [VIN_RESPONSE], functional_addr=True, debug=debug)
for addr, vin in query.get_data(timeout).items():
return addr[0], vin.decode()
print(f"vin query retry ({i+1}) ...")

View File

@ -15,11 +15,11 @@ def disable_ecu(ecu_addr, logcan, sendcan, bus, timeout=0.5, retry=5, debug=Fals
for i in range(retry):
try:
# enter extended diagnostic session
query = IsoTpParallelQuery(sendcan, logcan, bus, [ecu_addr], [EXT_DIAG_REQUEST], [EXT_DIAG_RESPONSE], debug=debug)
query = IsoTpParallelQuery(sendcan, logcan, [bus], [ecu_addr], [EXT_DIAG_REQUEST], [EXT_DIAG_RESPONSE], debug=debug)
for addr, dat in query.get_data(timeout).items(): # pylint: disable=unused-variable
print("ecu communication control disable tx/rx ...")
# communication control disable tx and rx
query = IsoTpParallelQuery(sendcan, logcan, bus, [ecu_addr], [COM_CONT_REQUEST], [COM_CONT_RESPONSE], debug=debug)
query = IsoTpParallelQuery(sendcan, logcan, [bus], [ecu_addr], [COM_CONT_REQUEST], [COM_CONT_RESPONSE], debug=debug)
query.get_data(0)
return True
print(f"ecu disable retry ({i+1}) ...")