Skip to content

Commit

Permalink
remove CAN capnp conversion from car interfaces (commaai#33218)
Browse files Browse the repository at this point in the history
remove pandad from interfaces
  • Loading branch information
sshane authored Aug 7, 2024
1 parent 3af7747 commit ba7a60c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 11 deletions.
1 change: 0 additions & 1 deletion .importlinter
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ ignore_imports =
openpilot.selfdrive.car.ecu_addrs -> openpilot.common.params
# requires generic CAN send/receive functions
openpilot.selfdrive.car.ecu_addrs -> openpilot.selfdrive.pandad
openpilot.selfdrive.car.interfaces -> openpilot.selfdrive.pandad
openpilot.selfdrive.car.isotp_parallel_query -> openpilot.selfdrive.pandad
openpilot.selfdrive.car.tests.test_fw_fingerprint -> openpilot.selfdrive.pandad

Expand Down
4 changes: 2 additions & 2 deletions selfdrive/car/card.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from openpilot.common.realtime import config_realtime_process, Priority, Ratekeeper
from openpilot.common.swaglog import cloudlog, ForwardingHandler

from openpilot.selfdrive.pandad import can_list_to_can_capnp
from openpilot.selfdrive.pandad import can_capnp_to_list, can_list_to_can_capnp
from openpilot.selfdrive.car import DT_CTRL, carlog
from openpilot.selfdrive.car.car_helpers import get_car, get_one_can
from openpilot.selfdrive.car.interfaces import CarInterfaceBase
Expand Down Expand Up @@ -108,7 +108,7 @@ def state_update(self) -> car.CarState:

# Update carState from CAN
can_strs = messaging.drain_sock_raw(self.can_sock, wait_for_one=True)
CS = self.CI.update(self.CC_prev, can_strs)
CS = self.CI.update(self.CC_prev, can_capnp_to_list(can_strs))

self.sm.update(0)

Expand Down
6 changes: 2 additions & 4 deletions selfdrive/car/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from openpilot.selfdrive.car.helpers import clip
from openpilot.selfdrive.car.values import PLATFORMS
from openpilot.selfdrive.controls.lib.events import Events
from openpilot.selfdrive.pandad import can_capnp_to_list

ButtonType = car.CarState.ButtonEvent.Type
GearShifter = car.CarState.GearShifter
Expand Down Expand Up @@ -229,12 +228,11 @@ def configure_torque_tune(candidate, tune, steering_angle_deadzone_deg=0.0, use_
def _update(self, c: car.CarControl) -> car.CarState:
pass

def update(self, c: car.CarControl, can_strings: list[bytes]) -> car.CarState:
def update(self, c: car.CarControl, can_packets: list[int, list[int, bytes, int]]) -> car.CarState:
# parse can
can_list = can_capnp_to_list(can_strings)
for cp in self.can_parsers:
if cp is not None:
cp.update_strings(can_list)
cp.update_strings(can_packets)

# get CarState
ret = self._update(c)
Expand Down
8 changes: 4 additions & 4 deletions selfdrive/car/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def test_car_interface(self):
CC = car.CarControl.new_message().as_reader()

for i, msg in enumerate(self.can_msgs):
CS = self.CI.update(CC, (msg.as_builder().to_bytes(),))
CS = self.CI.update(CC, can_capnp_to_list((msg.as_builder().to_bytes(),)))
self.CI.apply(CC, msg.logMonoTime)

if CS.canValid:
Expand Down Expand Up @@ -358,7 +358,7 @@ def test_panda_safety_carstate_fuzzy(self, data):
can = messaging.new_message('can', 1)
can.can = [log.CanData(address=address, dat=dat, src=bus)]

CS = self.CI.update(CC, (can.to_bytes(),))
CS = self.CI.update(CC, can_capnp_to_list((can.to_bytes(),)))

if self.safety.get_gas_pressed_prev() != prev_panda_gas:
self.assertEqual(CS.gasPressed, self.safety.get_gas_pressed_prev())
Expand Down Expand Up @@ -397,7 +397,7 @@ def test_panda_safety_carstate(self):

# warm up pass, as initial states may be different
for can in self.can_msgs[:300]:
self.CI.update(CC, (can.as_builder().to_bytes(), ))
self.CI.update(CC, can_capnp_to_list((can.as_builder().to_bytes(), )))
for msg in filter(lambda m: m.src in range(64), can.can):
to_send = libpanda_py.make_CANPacket(msg.address, msg.src % 4, msg.dat)
self.safety.safety_rx_hook(to_send)
Expand All @@ -407,7 +407,7 @@ def test_panda_safety_carstate(self):
checks = defaultdict(int)
card = Car(CI=self.CI)
for idx, can in enumerate(self.can_msgs):
CS = self.CI.update(CC, (can.as_builder().to_bytes(), ))
CS = self.CI.update(CC, can_capnp_to_list((can.as_builder().to_bytes(), )))
for msg in filter(lambda m: m.src in range(64), can.can):
to_send = libpanda_py.make_CANPacket(msg.address, msg.src % 4, msg.dat)
ret = self.safety.safety_rx_hook(to_send)
Expand Down

0 comments on commit ba7a60c

Please sign in to comment.