From 0ea148029b354b6e91a6d51c32ea49645d792dbb Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Tue, 30 Jul 2024 18:00:50 -0700 Subject: [PATCH] use helper --- selfdrive/car/__init__.py | 11 +++++++++++ selfdrive/car/ecu_addrs.py | 13 ++----------- selfdrive/car/honda/carcontroller.py | 4 ++-- selfdrive/car/hyundai/carcontroller.py | 6 +++--- selfdrive/car/subaru/carcontroller.py | 4 ++-- selfdrive/car/toyota/carcontroller.py | 4 ++-- 6 files changed, 22 insertions(+), 20 deletions(-) diff --git a/selfdrive/car/__init__.py b/selfdrive/car/__init__.py index b685c6a4354b5d..87d43831e64361 100644 --- a/selfdrive/car/__init__.py +++ b/selfdrive/car/__init__.py @@ -7,6 +7,7 @@ import capnp from cereal import car +from panda.python.uds import SERVICE_TYPE from openpilot.common.numpy_fast import clip, interp from openpilot.common.utils import Freezable from openpilot.selfdrive.car.docs_definitions import CarDocs @@ -191,6 +192,16 @@ def make_can_msg(addr, dat, bus): return [addr, 0, dat, bus] +def make_tester_present_msg(addr, bus, subaddr=None, suppress_response=False): + dat = [0x02, SERVICE_TYPE.TESTER_PRESENT] + if subaddr is not None: + dat.insert(0, subaddr) + dat.append(0x80 if suppress_response else 0x0) # sub-function + + dat.extend([0x0] * (8 - len(dat))) + return make_can_msg(addr, bytes(dat), bus) + + def get_safety_config(safety_model, safety_param = None): ret = car.CarParams.SafetyConfig.new_message() ret.safetyModel = safety_model diff --git a/selfdrive/car/ecu_addrs.py b/selfdrive/car/ecu_addrs.py index 0fd4bbd0beffac..0ff827593ec9ad 100755 --- a/selfdrive/car/ecu_addrs.py +++ b/selfdrive/car/ecu_addrs.py @@ -4,21 +4,12 @@ import cereal.messaging as messaging from panda.python.uds import SERVICE_TYPE -from openpilot.selfdrive.car import make_can_msg +from openpilot.selfdrive.car import make_tester_present_msg from openpilot.selfdrive.car.fw_query_definitions import EcuAddrBusType from openpilot.selfdrive.pandad import can_list_to_can_capnp from openpilot.common.swaglog import cloudlog -def _make_tester_present_msg(addr, bus, subaddr=None): - dat = [0x02, SERVICE_TYPE.TESTER_PRESENT, 0x0] - if subaddr is not None: - dat.insert(0, subaddr) - - dat.extend([0x0] * (8 - len(dat))) - return make_can_msg(addr, bytes(dat), bus) - - def _is_tester_present_response(msg: capnp.lib.capnp._DynamicStructReader, subaddr: int = None) -> bool: # ISO-TP messages are always padded to 8 bytes # tester present response is always a single frame @@ -44,7 +35,7 @@ def get_ecu_addrs(logcan: messaging.SubSocket, sendcan: messaging.PubSocket, que responses: set[EcuAddrBusType], timeout: float = 1, debug: bool = False) -> set[EcuAddrBusType]: ecu_responses: set[EcuAddrBusType] = set() # set((addr, subaddr, bus),) try: - msgs = [_make_tester_present_msg(addr, bus, subaddr) for addr, subaddr, bus in queries] + msgs = [make_tester_present_msg(addr, bus, subaddr) for addr, subaddr, bus in queries] messaging.drain_sock_raw(logcan) sendcan.send(can_list_to_can_capnp(msgs, msgtype='sendcan')) diff --git a/selfdrive/car/honda/carcontroller.py b/selfdrive/car/honda/carcontroller.py index dc42c41e63d09f..84ccf29d18dd91 100644 --- a/selfdrive/car/honda/carcontroller.py +++ b/selfdrive/car/honda/carcontroller.py @@ -3,7 +3,7 @@ from cereal import car from openpilot.common.numpy_fast import clip, interp from opendbc.can.packer import CANPacker -from openpilot.selfdrive.car import DT_CTRL, rate_limit +from openpilot.selfdrive.car import DT_CTRL, rate_limit, make_tester_present_msg from openpilot.selfdrive.car.honda import hondacan from openpilot.selfdrive.car.honda.values import CruiseButtons, VISUAL_HUD, HONDA_BOSCH, HONDA_BOSCH_RADARLESS, HONDA_NIDEC_ALT_PCM_ACCEL, CarControllerParams from openpilot.selfdrive.car.interfaces import CarControllerBase @@ -164,7 +164,7 @@ def update(self, CC, CS, now_nanos): # tester present - w/ no response (keeps radar disabled) if self.CP.carFingerprint in (HONDA_BOSCH - HONDA_BOSCH_RADARLESS) and self.CP.openpilotLongitudinalControl: if self.frame % 10 == 0: - can_sends.append((0x18DAB0F1, 0, b"\x02\x3E\x80\x00\x00\x00\x00\x00", 1)) + can_sends.append(make_tester_present_msg(0x18DAB0F1, 1, suppress_response=True)) # Send steering command. can_sends.append(hondacan.create_steering_control(self.packer, self.CAN, apply_steer, CC.latActive, self.CP.carFingerprint, diff --git a/selfdrive/car/hyundai/carcontroller.py b/selfdrive/car/hyundai/carcontroller.py index 3d7768a83b6037..75aeb0efd6ba31 100644 --- a/selfdrive/car/hyundai/carcontroller.py +++ b/selfdrive/car/hyundai/carcontroller.py @@ -2,7 +2,7 @@ from openpilot.common.conversions import Conversions as CV from openpilot.common.numpy_fast import clip from opendbc.can.packer import CANPacker -from openpilot.selfdrive.car import DT_CTRL, apply_driver_steer_torque_limits, common_fault_avoidance +from openpilot.selfdrive.car import DT_CTRL, apply_driver_steer_torque_limits, common_fault_avoidance, make_tester_present_msg from openpilot.selfdrive.car.hyundai import hyundaicanfd, hyundaican from openpilot.selfdrive.car.hyundai.hyundaicanfd import CanBus from openpilot.selfdrive.car.hyundai.values import HyundaiFlags, Buttons, CarControllerParams, CANFD_CAR, CAR @@ -96,11 +96,11 @@ def update(self, CC, CS, now_nanos): addr, bus = 0x7d0, 0 if self.CP.flags & HyundaiFlags.CANFD_HDA2.value: addr, bus = 0x730, self.CAN.ECAN - can_sends.append([addr, 0, b"\x02\x3E\x80\x00\x00\x00\x00\x00", bus]) + can_sends.append(make_tester_present_msg(addr, bus, suppress_response=True)) # for blinkers if self.CP.flags & HyundaiFlags.ENABLE_BLINKERS: - can_sends.append([0x7b1, 0, b"\x02\x3E\x80\x00\x00\x00\x00\x00", self.CAN.ECAN]) + can_sends.append(make_tester_present_msg(0x7b1, self.CAN.ECAN, suppress_response=True)) # CAN-FD platforms if self.CP.carFingerprint in CANFD_CAR: diff --git a/selfdrive/car/subaru/carcontroller.py b/selfdrive/car/subaru/carcontroller.py index d89ae8c6397157..3e1b62c9744f1d 100644 --- a/selfdrive/car/subaru/carcontroller.py +++ b/selfdrive/car/subaru/carcontroller.py @@ -1,6 +1,6 @@ from openpilot.common.numpy_fast import clip, interp from opendbc.can.packer import CANPacker -from openpilot.selfdrive.car import apply_driver_steer_torque_limits, common_fault_avoidance +from openpilot.selfdrive.car import apply_driver_steer_torque_limits, common_fault_avoidance, make_tester_present_msg from openpilot.selfdrive.car.interfaces import CarControllerBase from openpilot.selfdrive.car.subaru import subarucan from openpilot.selfdrive.car.subaru.values import DBC, GLOBAL_ES_ADDR, CanBus, CarControllerParams, SubaruFlags @@ -124,7 +124,7 @@ def update(self, CC, CS, now_nanos): if self.CP.flags & SubaruFlags.DISABLE_EYESIGHT: # Tester present (keeps eyesight disabled) if self.frame % 100 == 0: - can_sends.append([GLOBAL_ES_ADDR, 0, b"\x02\x3E\x80\x00\x00\x00\x00\x00", CanBus.camera]) + can_sends.append(make_tester_present_msg(GLOBAL_ES_ADDR, CanBus.camera, suppress_response=True)) # Create all of the other eyesight messages to keep the rest of the car happy when eyesight is disabled if self.frame % 5 == 0: diff --git a/selfdrive/car/toyota/carcontroller.py b/selfdrive/car/toyota/carcontroller.py index f9b7a478e0baec..ea71dd536b06ae 100644 --- a/selfdrive/car/toyota/carcontroller.py +++ b/selfdrive/car/toyota/carcontroller.py @@ -1,6 +1,6 @@ from cereal import car from openpilot.common.numpy_fast import clip -from openpilot.selfdrive.car import apply_meas_steer_torque_limits, apply_std_steer_angle_limits, common_fault_avoidance, make_can_msg +from openpilot.selfdrive.car import apply_meas_steer_torque_limits, apply_std_steer_angle_limits, common_fault_avoidance, make_can_msg, make_tester_present_msg from openpilot.selfdrive.car.interfaces import CarControllerBase from openpilot.selfdrive.car.toyota import toyotacan from openpilot.selfdrive.car.toyota.values import CAR, STATIC_DSU_MSGS, NO_STOP_TIMER_CAR, TSS2_CAR, \ @@ -166,7 +166,7 @@ def update(self, CC, CS, now_nanos): # keep radar disabled if self.frame % 20 == 0 and self.CP.flags & ToyotaFlags.DISABLE_RADAR.value: - can_sends.append([0x750, 0, b"\x0F\x02\x3E\x00\x00\x00\x00\x00", 0]) + can_sends.append(make_tester_present_msg(0x750, 0, 0xF)) new_actuators = actuators.as_builder() new_actuators.steer = apply_steer / self.params.STEER_MAX