diff --git a/cereal/log.capnp b/cereal/log.capnp index d849f4840b44bd..dcf9463ac8bee9 100644 --- a/cereal/log.capnp +++ b/cereal/log.capnp @@ -336,9 +336,9 @@ enum LaneChangeDirection { struct CanData { address @0 :UInt32; - busTime @1 :UInt16; dat @2 :Data; src @3 :UInt8; + busTimeDEPRECATED @1 :UInt16; } struct DeviceState @0xa4d8b5af2aa492eb { diff --git a/opendbc b/opendbc index ae5801898c5aca..c6ba3edd0760a9 160000 --- a/opendbc +++ b/opendbc @@ -1 +1 @@ -Subproject commit ae5801898c5aca878470b4d3d373095682b57448 +Subproject commit c6ba3edd0760a9dd9d8f0bebcc4467d310d4fad5 diff --git a/panda b/panda index f6375848ca393a..8c3bb0151e8907 160000 --- a/panda +++ b/panda @@ -1 +1 @@ -Subproject commit f6375848ca393a9483921665b6a2d131d7ec9b20 +Subproject commit 8c3bb0151e8907ade344ccb293d58cd543e28baa diff --git a/selfdrive/car/__init__.py b/selfdrive/car/__init__.py index b685c6a4354b5d..28ec4ad18797f0 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 @@ -188,7 +189,17 @@ def get_friction(lateral_accel_error: float, lateral_accel_deadzone: float, fric def make_can_msg(addr, dat, bus): - return [addr, 0, dat, bus] + return [addr, 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): 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/ford/fordcan.py b/selfdrive/car/ford/fordcan.py index 2cfd61a1919973..46d09ec22d830e 100644 --- a/selfdrive/car/ford/fordcan.py +++ b/selfdrive/car/ford/fordcan.py @@ -112,7 +112,7 @@ def create_lat_ctl2_msg(packer, CAN: CanBus, mode: int, path_offset: float, path } # calculate checksum - dat = packer.make_can_msg("LateralMotionControl2", 0, values)[2] + dat = packer.make_can_msg("LateralMotionControl2", 0, values)[1] values["LatCtlPath_No_Cs"] = calculate_lat_ctl2_checksum(mode, counter, dat) return packer.make_can_msg("LateralMotionControl2", CAN.main, values) diff --git a/selfdrive/car/gm/gmcan.py b/selfdrive/car/gm/gmcan.py index e833e77636a551..a70bcccd063d13 100644 --- a/selfdrive/car/gm/gmcan.py +++ b/selfdrive/car/gm/gmcan.py @@ -64,7 +64,7 @@ def create_gas_regen_command(packer, bus, throttle, idx, enabled, at_full_stop): "GasRegenAlwaysOne3": 1, } - dat = packer.make_can_msg("ASCMGasRegenCmd", bus, values)[2] + dat = packer.make_can_msg("ASCMGasRegenCmd", bus, values)[1] values["GasRegenChecksum"] = (((0xff - dat[1]) & 0xff) << 16) | \ (((0xff - dat[2]) & 0xff) << 8) | \ ((0x100 - dat[3] - idx) & 0xff) 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/hyundai/hyundaican.py b/selfdrive/car/hyundai/hyundaican.py index b4b951f89e173b..d2002e23e0afc2 100644 --- a/selfdrive/car/hyundai/hyundaican.py +++ b/selfdrive/car/hyundai/hyundaican.py @@ -77,7 +77,7 @@ def create_lkas11(packer, frame, CP, apply_steer, steer_req, # Genesis and Optima fault when forwarding while engaged values["CF_Lkas_LdwsActivemode"] = 2 - dat = packer.make_can_msg("LKAS11", 0, values)[2] + dat = packer.make_can_msg("LKAS11", 0, values)[1] if CP.flags & HyundaiFlags.CHECKSUM_CRC8: # CRC Checksum as seen on 2019 Hyundai Santa Fe @@ -156,7 +156,7 @@ def create_acc_commands(packer, enabled, accel, upper_jerk, idx, hud_control, se scc12_values["CF_VSM_ConfMode"] = 1 scc12_values["AEB_Status"] = 1 # AEB disabled - scc12_dat = packer.make_can_msg("SCC12", 0, scc12_values)[2] + scc12_dat = packer.make_can_msg("SCC12", 0, scc12_values)[1] scc12_values["CR_VSM_ChkSum"] = 0x10 - sum(sum(divmod(i, 16)) for i in scc12_dat) % 0x10 commands.append(packer.make_can_msg("SCC12", 0, scc12_values)) @@ -181,7 +181,7 @@ def create_acc_commands(packer, enabled, accel, upper_jerk, idx, hud_control, se "FCA_DrvSetStatus": 1, "FCA_Status": 1, # AEB disabled } - fca11_dat = packer.make_can_msg("FCA11", 0, fca11_values)[2] + fca11_dat = packer.make_can_msg("FCA11", 0, fca11_values)[1] fca11_values["CR_FCA_ChkSum"] = hyundai_checksum(fca11_dat[:7]) commands.append(packer.make_can_msg("FCA11", 0, fca11_values)) diff --git a/selfdrive/car/isotp_parallel_query.py b/selfdrive/car/isotp_parallel_query.py index 447c7093c5b4fc..b5158f212681d1 100644 --- a/selfdrive/car/isotp_parallel_query.py +++ b/selfdrive/car/isotp_parallel_query.py @@ -27,7 +27,7 @@ def __init__(self, sendcan: messaging.PubSocket, logcan: messaging.SubSocket, bu assert tx_addr not in FUNCTIONAL_ADDRS, f"Functional address should be defined in functional_addrs: {hex(tx_addr)}" self.msg_addrs = {tx_addr: get_rx_addr_for_tx_addr(tx_addr[0], rx_offset=response_offset) for tx_addr in real_addrs} - self.msg_buffer: dict[int, list[tuple[int, int, bytes, int]]] = defaultdict(list) + self.msg_buffer: dict[int, list[tuple[int, bytes, int]]] = defaultdict(list) def rx(self): """Drain can socket and sort messages into buffers based on address""" @@ -36,11 +36,11 @@ def rx(self): for packet in can_packets: for msg in packet.can: if msg.src == self.bus and msg.address in self.msg_addrs.values(): - self.msg_buffer[msg.address].append((msg.address, msg.busTime, msg.dat, msg.src)) + self.msg_buffer[msg.address].append((msg.address, msg.dat, msg.src)) def _can_tx(self, tx_addr, dat, bus): """Helper function to send single message""" - msg = [tx_addr, 0, dat, bus] + msg = [tx_addr, dat, bus] self.sendcan.send(can_list_to_can_capnp([msg], msgtype='sendcan')) def _can_rx(self, addr, sub_addr=None): @@ -53,7 +53,7 @@ def _can_rx(self, addr, sub_addr=None): # Filter based on subadress msgs = [] for m in self.msg_buffer[addr]: - first_byte = m[2][0] + first_byte = m[1][0] if first_byte == sub_addr: msgs.append(m) else: diff --git a/selfdrive/car/nissan/nissancan.py b/selfdrive/car/nissan/nissancan.py index b9a1b4f843217e..28fb01d7e39df8 100644 --- a/selfdrive/car/nissan/nissancan.py +++ b/selfdrive/car/nissan/nissancan.py @@ -15,7 +15,7 @@ def create_steering_control(packer, apply_steer, frame, steer_on, lkas_max_torqu "LKA_ACTIVE": steer_on, } - dat = packer.make_can_msg("LKAS", 0, values)[2] + dat = packer.make_can_msg("LKAS", 0, values)[1] values["CHECKSUM"] = nissan_checksum(dat[:7]) return packer.make_can_msg("LKAS", 0, values) 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/subaru/subarucan.py b/selfdrive/car/subaru/subarucan.py index 86d39ff885f74a..41bd177ff2de76 100644 --- a/selfdrive/car/subaru/subarucan.py +++ b/selfdrive/car/subaru/subarucan.py @@ -279,7 +279,7 @@ def create_es_static_2(packer): # *** Subaru Pre-global *** def subaru_preglobal_checksum(packer, values, addr, checksum_byte=7): - dat = packer.make_can_msg(addr, 0, values)[2] + dat = packer.make_can_msg(addr, 0, values)[1] return (sum(dat[:checksum_byte]) + sum(dat[checksum_byte+1:])) % 256 diff --git a/selfdrive/car/tesla/teslacan.py b/selfdrive/car/tesla/teslacan.py index 6bb27b995f79d5..f8cd138e776bd9 100644 --- a/selfdrive/car/tesla/teslacan.py +++ b/selfdrive/car/tesla/teslacan.py @@ -25,7 +25,7 @@ def create_steering_control(self, angle, enabled, counter): "DAS_steeringControlCounter": counter, } - data = self.packer.make_can_msg("DAS_steeringControl", CANBUS.chassis, values)[2] + data = self.packer.make_can_msg("DAS_steeringControl", CANBUS.chassis, values)[1] values["DAS_steeringControlChecksum"] = self.checksum(0x488, data[:3]) return self.packer.make_can_msg("DAS_steeringControl", CANBUS.chassis, values) @@ -69,7 +69,7 @@ def create_action_request(self, msg_stw_actn_req, cancel, bus, counter): values["SpdCtrlLvr_Stat"] = 1 values["MC_STW_ACTN_RQ"] = counter - data = self.packer.make_can_msg("STW_ACTN_RQ", bus, values)[2] + data = self.packer.make_can_msg("STW_ACTN_RQ", bus, values)[1] values["CRC_STW_ACTN_RQ"] = self.crc(data[:7]) return self.packer.make_can_msg("STW_ACTN_RQ", bus, values) @@ -88,7 +88,7 @@ def create_longitudinal_commands(self, acc_state, speed, min_accel, max_accel, c } for packer, bus in [(self.packer, CANBUS.chassis), (self.pt_packer, CANBUS.powertrain)]: - data = packer.make_can_msg("DAS_control", bus, values)[2] + data = packer.make_can_msg("DAS_control", bus, values)[1] values["DAS_controlChecksum"] = self.checksum(0x2b9, data[:7]) messages.append(packer.make_can_msg("DAS_control", bus, values)) return messages diff --git a/selfdrive/car/tests/test_models.py b/selfdrive/car/tests/test_models.py index 52cc5eabf169b4..22a80f359a93af 100644 --- a/selfdrive/car/tests/test_models.py +++ b/selfdrive/car/tests/test_models.py @@ -298,7 +298,7 @@ def test_car_controller(car_control): now_nanos += DT_CTRL * 1e9 msgs_sent += len(sendcan) - for addr, _, dat, bus in sendcan: + for addr, dat, bus in sendcan: to_send = libpanda_py.make_CANPacket(addr, bus % 4, dat) self.assertTrue(self.safety.safety_tx_hook(to_send), (addr, dat, bus)) 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 diff --git a/selfdrive/controls/tests/test_startup.py b/selfdrive/controls/tests/test_startup.py index 14b0788a3d594c..51b9887c96bfff 100644 --- a/selfdrive/controls/tests/test_startup.py +++ b/selfdrive/controls/tests/test_startup.py @@ -90,7 +90,7 @@ def test_startup_alert(expected_event, car_model, fw_versions, brand): managed_processes['card'].start() assert pm.wait_for_readers_to_update('can', 5) - pm.send('can', can_list_to_can_capnp([[0, 0, b"", 0]])) + pm.send('can', can_list_to_can_capnp([[0, b"", 0]])) assert pm.wait_for_readers_to_update('pandaStates', 5) msg = messaging.new_message('pandaStates', 1) @@ -103,7 +103,7 @@ def test_startup_alert(expected_event, car_model, fw_versions, brand): else: finger = _FINGERPRINTS[car_model][0] - msgs = [[addr, 0, b'\x00'*length, 0] for addr, length in finger.items()] + msgs = [[addr, b'\x00'*length, 0] for addr, length in finger.items()] for _ in range(1000): # card waits for pandad to echo back that it has changed the multiplexing mode if not params.get_bool("ObdMultiplexingChanged"): diff --git a/selfdrive/pandad/__init__.py b/selfdrive/pandad/__init__.py index c2df28e00fc296..b72c8ccb57dd14 100644 --- a/selfdrive/pandad/__init__.py +++ b/selfdrive/pandad/__init__.py @@ -7,5 +7,5 @@ def can_capnp_to_can_list(can, src_filter=None): ret = [] for msg in can: if src_filter is None or msg.src in src_filter: - ret.append((msg.address, msg.busTime, msg.dat, msg.src)) + ret.append((msg.address, msg.dat, msg.src)) return ret diff --git a/selfdrive/pandad/can_list_to_can_capnp.cc b/selfdrive/pandad/can_list_to_can_capnp.cc index 232287bec98223..83068e77985b35 100644 --- a/selfdrive/pandad/can_list_to_can_capnp.cc +++ b/selfdrive/pandad/can_list_to_can_capnp.cc @@ -11,7 +11,6 @@ void can_list_to_can_capnp_cpp(const std::vector &can_list, std::stri for (auto it = can_list.begin(); it != can_list.end(); it++, j++) { auto c = canData[j]; c.setAddress(it->address); - c.setBusTime(it->busTime); c.setDat(kj::arrayPtr((uint8_t*)it->dat.data(), it->dat.size())); c.setSrc(it->src); } diff --git a/selfdrive/pandad/panda.cc b/selfdrive/pandad/panda.cc index fcb4ac67a41279..ed5ee62501948f 100644 --- a/selfdrive/pandad/panda.cc +++ b/selfdrive/pandad/panda.cc @@ -257,7 +257,6 @@ bool Panda::unpack_can_buffer(uint8_t *data, uint32_t &size, std::vector pandas) { auto canData = evt.initCan(raw_can_data.size()); for (uint i = 0; i