From 24a07352b150c405c44e58f91998f15361f3c5ac Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Tue, 6 Aug 2024 21:43:18 -0700 Subject: [PATCH] hmm API doesn't seem great --- selfdrive/car/car_helpers.py | 3 ++- selfdrive/car/card.py | 15 ++++++--------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/selfdrive/car/car_helpers.py b/selfdrive/car/car_helpers.py index 03351fdb98..295275298f 100644 --- a/selfdrive/car/car_helpers.py +++ b/selfdrive/car/car_helpers.py @@ -138,7 +138,8 @@ def fingerprint(logcan, sendcan, set_obd_multiplexing, num_pandas, cached_params # CAN fingerprint # drain CAN socket so we get the latest messages - messaging.drain_sock_raw(logcan) + # messaging.drain_sock_raw(logcan) + logcan() car_fingerprint, finger = can_fingerprint(lambda: get_one_can(logcan)) exact_match = True diff --git a/selfdrive/car/card.py b/selfdrive/car/card.py index 76ac31fa83..e5dde9f1fc 100755 --- a/selfdrive/car/card.py +++ b/selfdrive/car/card.py @@ -13,7 +13,7 @@ from openpilot.common.realtime import config_realtime_process, Priority, Ratekee from openpilot.common.swaglog import cloudlog, ForwardingHandler from openpilot.selfdrive.pandad import can_list_to_can_capnp -from openpilot.selfdrive.car import DT_CTRL, carlog +from openpilot.selfdrive.car import DT_CTRL, carlog, make_can_msg from openpilot.selfdrive.car.fw_versions import ObdCallback from openpilot.selfdrive.car.car_helpers import get_car, get_one_can from openpilot.selfdrive.car.interfaces import CarInterfaceBase @@ -39,18 +39,16 @@ def obd_callback(params: Params) -> ObdCallback: def can_recv_callbacks(logcan: messaging.SubSocket, sendcan: messaging.PubSocket): - def can_recv(wait_for_one=False): # call rx/tx? + def can_recv(wait_for_one: bool = False) -> list[list[int, bytes, int]]: # call rx/tx? can_packets = messaging.drain_sock(logcan, wait_for_one=wait_for_one) - return can_packets + return [make_can_msg(msg.address, msg.dat, msg.src) for msg in can_packets] - # def can_send(tx_addr: int, dat: bytes, bus: int): - def can_send(msg: list[int, bytes, int]): + def can_send(msg: list[int, bytes, int]) -> None: sendcan.send(can_list_to_can_capnp([msg], msgtype='sendcan')) return can_recv, can_send - class Car: CI: CarInterfaceBase @@ -78,9 +76,8 @@ class Car: num_pandas = len(messaging.recv_one_retry(self.sm.sock['pandaStates']).pandaStates) cached_params = self.params.get("CarParamsCache") - cr, cs = can_recv_callbacks(self.can_sock, self.pm.sock['sendcan']) - - self.CI = get_car(self.can_sock, self.pm.sock['sendcan'], obd_callback(self.params), experimental_long_allowed, num_pandas, cached_params) + self.CI = get_car(*can_recv_callbacks(self.can_sock, self.pm.sock['sendcan']), obd_callback(self.params), + experimental_long_allowed, num_pandas, cached_params) self.CP = self.CI.CP # continue onto next fingerprinting step in pandad