From 3742625e85780166f8b6dd84d7f60b4aef573dd5 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Tue, 6 Aug 2024 23:03:21 -0700 Subject: [PATCH] more sendcan -> can_send references --- selfdrive/car/card.py | 7 ++++--- selfdrive/car/disable_ecu.py | 6 +++--- selfdrive/car/honda/interface.py | 4 ++-- selfdrive/car/hyundai/interface.py | 6 +++--- selfdrive/car/interfaces.py | 4 +++- selfdrive/car/subaru/interface.py | 4 ++-- selfdrive/car/toyota/interface.py | 4 ++-- 7 files changed, 19 insertions(+), 16 deletions(-) diff --git a/selfdrive/car/card.py b/selfdrive/car/card.py index 34eef027e2..ab70b5045e 100755 --- a/selfdrive/car/card.py +++ b/selfdrive/car/card.py @@ -88,6 +88,8 @@ class Car: self.params = Params() + self.can_callbacks = can_comm_callbacks(self.can_sock, self.pm.sock['sendcan']) + if CI is None: # wait for one pandaState and one CAN packet print("Waiting for CAN messages...") @@ -96,8 +98,7 @@ class Car: experimental_long_allowed = self.params.get_bool("ExperimentalLongitudinalEnabled") num_pandas = len(messaging.recv_one_retry(self.sm.sock['pandaStates']).pandaStates) cached_params = self.params.get("CarParamsCache") - self.CI = get_car(*can_comm_callbacks(self.can_sock, self.pm.sock['sendcan']), obd_callback(self.params), - experimental_long_allowed, num_pandas, cached_params) + self.CI = get_car(*self.can_callbacks, obd_callback(self.params), experimental_long_allowed, num_pandas, cached_params) self.CP = self.CI.CP # continue onto next fingerprinting step in pandad @@ -200,7 +201,7 @@ class Car: if not self.initialized_prev: # Initialize CarInterface, once controls are ready # TODO: this can make us miss at least a few cycles when doing an ECU knockout - self.CI.init(self.CP, self.can_sock, self.pm.sock['sendcan']) + self.CI.init(self.CP, *self.can_callbacks) # signal pandad to switch to car safety mode self.params.put_bool_nonblocking("ControlsReady", True) diff --git a/selfdrive/car/disable_ecu.py b/selfdrive/car/disable_ecu.py index 5229b519a8..785716b925 100755 --- a/selfdrive/car/disable_ecu.py +++ b/selfdrive/car/disable_ecu.py @@ -8,7 +8,7 @@ EXT_DIAG_RESPONSE = b'\x50\x03' COM_CONT_RESPONSE = b'' -def disable_ecu(logcan, sendcan, bus=0, addr=0x7d0, sub_addr=None, com_cont_req=b'\x28\x83\x01', timeout=0.1, retry=10, debug=False): +def disable_ecu(logcan, can_send, bus=0, addr=0x7d0, sub_addr=None, com_cont_req=b'\x28\x83\x01', timeout=0.1, retry=10, debug=False): """Silence an ECU by disabling sending and receiving messages using UDS 0x28. The ECU will stay silent as long as openpilot keeps sending Tester Present. @@ -18,12 +18,12 @@ def disable_ecu(logcan, sendcan, bus=0, addr=0x7d0, sub_addr=None, com_cont_req= for i in range(retry): try: - query = IsoTpParallelQuery(sendcan, logcan, bus, [(addr, sub_addr)], [EXT_DIAG_REQUEST], [EXT_DIAG_RESPONSE], debug=debug) + query = IsoTpParallelQuery(can_send, logcan, bus, [(addr, sub_addr)], [EXT_DIAG_REQUEST], [EXT_DIAG_RESPONSE], debug=debug) for _, _ in query.get_data(timeout).items(): carlog.warning("communication control disable tx/rx ...") - query = IsoTpParallelQuery(sendcan, logcan, bus, [(addr, sub_addr)], [com_cont_req], [COM_CONT_RESPONSE], debug=debug) + query = IsoTpParallelQuery(can_send, logcan, bus, [(addr, sub_addr)], [com_cont_req], [COM_CONT_RESPONSE], debug=debug) query.get_data(0) carlog.warning("ecu disabled") diff --git a/selfdrive/car/honda/interface.py b/selfdrive/car/honda/interface.py index 4c9f9674d3..54337c602b 100755 --- a/selfdrive/car/honda/interface.py +++ b/selfdrive/car/honda/interface.py @@ -217,9 +217,9 @@ class CarInterface(CarInterfaceBase): return ret @staticmethod - def init(CP, logcan, sendcan): + def init(CP, logcan, can_send): if CP.carFingerprint in (HONDA_BOSCH - HONDA_BOSCH_RADARLESS) and CP.openpilotLongitudinalControl: - disable_ecu(logcan, sendcan, bus=1, addr=0x18DAB0F1, com_cont_req=b'\x28\x83\x03') + disable_ecu(logcan, can_send, bus=1, addr=0x18DAB0F1, com_cont_req=b'\x28\x83\x03') # returns a car.CarState def _update(self, c): diff --git a/selfdrive/car/hyundai/interface.py b/selfdrive/car/hyundai/interface.py index ecedf3fd7c..026c63720d 100644 --- a/selfdrive/car/hyundai/interface.py +++ b/selfdrive/car/hyundai/interface.py @@ -139,16 +139,16 @@ class CarInterface(CarInterfaceBase): return ret @staticmethod - def init(CP, logcan, sendcan): + def init(CP, logcan, can_send): if CP.openpilotLongitudinalControl and not (CP.flags & HyundaiFlags.CANFD_CAMERA_SCC.value): addr, bus = 0x7d0, 0 if CP.flags & HyundaiFlags.CANFD_HDA2.value: addr, bus = 0x730, CanBus(CP).ECAN - disable_ecu(logcan, sendcan, bus=bus, addr=addr, com_cont_req=b'\x28\x83\x01') + disable_ecu(logcan, can_send, bus=bus, addr=addr, com_cont_req=b'\x28\x83\x01') # for blinkers if CP.flags & HyundaiFlags.ENABLE_BLINKERS: - disable_ecu(logcan, sendcan, bus=CanBus(CP).ECAN, addr=0x7B1, com_cont_req=b'\x28\x83\x01') + disable_ecu(logcan, can_send, bus=CanBus(CP).ECAN, addr=0x7B1, com_cont_req=b'\x28\x83\x01') def _update(self, c): ret = self.CS.update(self.cp, self.cp_cam) diff --git a/selfdrive/car/interfaces.py b/selfdrive/car/interfaces.py index 83f3d0aa3c..3e5ad5f073 100644 --- a/selfdrive/car/interfaces.py +++ b/selfdrive/car/interfaces.py @@ -4,6 +4,7 @@ import numpy as np import tomllib from abc import abstractmethod, ABC from enum import StrEnum +from types import SimpleNamespace from typing import Any, NamedTuple from collections.abc import Callable from functools import cache @@ -12,6 +13,7 @@ from cereal import car from openpilot.common.basedir import BASEDIR from openpilot.common.simple_kalman import KF1D, get_kalman_gain from openpilot.selfdrive.car import DT_CTRL, apply_hysteresis, gen_empty_fingerprint, scale_rot_inertia, scale_tire_stiffness, get_friction, STD_CARGO_KG +from openpilot.selfdrive.car.can_definitions import CanSendCallable from openpilot.selfdrive.car.conversions import Conversions as CV from openpilot.selfdrive.car.helpers import clip from openpilot.selfdrive.car.values import PLATFORMS @@ -156,7 +158,7 @@ class CarInterfaceBase(ABC): raise NotImplementedError @staticmethod - def init(CP, logcan, sendcan): + def init(CP: car.CarParams, logcan: SimpleNamespace, can_send: CanSendCallable): pass @staticmethod diff --git a/selfdrive/car/subaru/interface.py b/selfdrive/car/subaru/interface.py index cb00934376..b8c1b28a03 100644 --- a/selfdrive/car/subaru/interface.py +++ b/selfdrive/car/subaru/interface.py @@ -106,6 +106,6 @@ class CarInterface(CarInterfaceBase): return ret @staticmethod - def init(CP, logcan, sendcan): + def init(CP, logcan, can_send): if CP.flags & SubaruFlags.DISABLE_EYESIGHT: - disable_ecu(logcan, sendcan, bus=2, addr=GLOBAL_ES_ADDR, com_cont_req=b'\x28\x03\x01') + disable_ecu(logcan, can_send, bus=2, addr=GLOBAL_ES_ADDR, com_cont_req=b'\x28\x03\x01') diff --git a/selfdrive/car/toyota/interface.py b/selfdrive/car/toyota/interface.py index 6487257bbc..c3500d4b83 100644 --- a/selfdrive/car/toyota/interface.py +++ b/selfdrive/car/toyota/interface.py @@ -138,11 +138,11 @@ class CarInterface(CarInterfaceBase): return ret @staticmethod - def init(CP, logcan, sendcan): + def init(CP, logcan, can_send): # disable radar if alpha longitudinal toggled on radar-ACC car if CP.flags & ToyotaFlags.DISABLE_RADAR.value: communication_control = bytes([uds.SERVICE_TYPE.COMMUNICATION_CONTROL, uds.CONTROL_TYPE.ENABLE_RX_DISABLE_TX, uds.MESSAGE_TYPE.NORMAL]) - disable_ecu(logcan, sendcan, bus=0, addr=0x750, sub_addr=0xf, com_cont_req=communication_control) + disable_ecu(logcan, can_send, bus=0, addr=0x750, sub_addr=0xf, com_cont_req=communication_control) # returns a car.CarState def _update(self, c):