selfdrive/car: ban params (#33198)

* ban params too with a callback

* all sorts of messed up

* use cloudlog

* consistent order

* order

* better type hint

* format

* this is a bit nicer

* hmm

* fix PLR1704

* no carvin

* fix process replay
old-commit-hash: 5a1596a322
pull/33302/head
Shane Smiskol 9 months ago committed by GitHub
parent 59b2f1f511
commit 1a74993ee2
  1. 6
      .importlinter
  2. 15
      selfdrive/car/car_helpers.py
  3. 6
      selfdrive/car/card.py
  4. 1
      selfdrive/car/fw_versions.py
  5. 5
      selfdrive/test/process_replay/process_replay.py

@ -8,6 +8,7 @@ type = forbidden
source_modules = source_modules =
openpilot.selfdrive.car openpilot.selfdrive.car
forbidden_modules = forbidden_modules =
openpilot.common.params
openpilot.system openpilot.system
openpilot.body openpilot.body
openpilot.docs openpilot.docs
@ -34,4 +35,9 @@ ignore_imports =
openpilot.selfdrive.car.tests.test_car_interfaces -> openpilot.selfdrive.controls.lib.longcontrol openpilot.selfdrive.car.tests.test_car_interfaces -> openpilot.selfdrive.controls.lib.longcontrol
openpilot.selfdrive.car.tests.test_car_interfaces -> openpilot.selfdrive.controls.lib.latcontrol_torque openpilot.selfdrive.car.tests.test_car_interfaces -> openpilot.selfdrive.controls.lib.latcontrol_torque
openpilot.selfdrive.car.tests.test_car_interfaces -> openpilot.selfdrive.controls.lib.latcontrol_pid openpilot.selfdrive.car.tests.test_car_interfaces -> openpilot.selfdrive.controls.lib.latcontrol_pid
openpilot.selfdrive.car.card -> openpilot.common.params
openpilot.selfdrive.car.tests.test_models -> openpilot.common.params
# these two will still live in openpilot, but require some modification
openpilot.selfdrive.car.fw_versions -> openpilot.common.params
openpilot.selfdrive.car.ecu_addrs -> openpilot.common.params
unmatched_ignore_imports_alerting = warn unmatched_ignore_imports_alerting = warn

@ -3,7 +3,6 @@ import time
from collections.abc import Callable from collections.abc import Callable
from cereal import car from cereal import car
from openpilot.common.params import Params
from openpilot.selfdrive.car import carlog from openpilot.selfdrive.car import carlog
from openpilot.selfdrive.car.interfaces import get_interface_attr from openpilot.selfdrive.car.interfaces import get_interface_attr
from openpilot.selfdrive.car.fingerprints import eliminate_incompatible_cars, all_legacy_fingerprint_cars from openpilot.selfdrive.car.fingerprints import eliminate_incompatible_cars, all_legacy_fingerprint_cars
@ -90,18 +89,17 @@ def can_fingerprint(next_can: Callable) -> tuple[str | None, dict[int, dict]]:
# **** for use live only **** # **** for use live only ****
def fingerprint(logcan, sendcan, set_obd_multiplexing, num_pandas): def fingerprint(logcan, sendcan, set_obd_multiplexing, num_pandas, cached_params_raw):
fixed_fingerprint = os.environ.get('FINGERPRINT', "") fixed_fingerprint = os.environ.get('FINGERPRINT', "")
skip_fw_query = os.environ.get('SKIP_FW_QUERY', False) skip_fw_query = os.environ.get('SKIP_FW_QUERY', False)
disable_fw_cache = os.environ.get('DISABLE_FW_CACHE', False) disable_fw_cache = os.environ.get('DISABLE_FW_CACHE', False)
ecu_rx_addrs = set() ecu_rx_addrs = set()
params = Params()
start_time = time.monotonic() start_time = time.monotonic()
if not skip_fw_query: if not skip_fw_query:
cached_params = params.get("CarParamsCache") cached_params = None
if cached_params is not None: if cached_params_raw is not None:
with car.CarParams.from_bytes(cached_params) as cached_params: with car.CarParams.from_bytes(cached_params_raw) as cached_params:
if cached_params.carName == "mock": if cached_params.carName == "mock":
cached_params = None cached_params = None
@ -135,7 +133,6 @@ def fingerprint(logcan, sendcan, set_obd_multiplexing, num_pandas):
# disable OBD multiplexing for CAN fingerprinting and potential ECU knockouts # disable OBD multiplexing for CAN fingerprinting and potential ECU knockouts
set_obd_multiplexing(False) set_obd_multiplexing(False)
params.put_bool("FirmwareQueryDone", True)
fw_query_time = time.monotonic() - start_time fw_query_time = time.monotonic() - start_time
@ -169,8 +166,8 @@ def get_car_interface(CP):
return CarInterface(CP, CarController, CarState) return CarInterface(CP, CarController, CarState)
def get_car(logcan, sendcan, set_obd_multiplexing, experimental_long_allowed, num_pandas=1): def get_car(logcan, sendcan, set_obd_multiplexing, experimental_long_allowed, num_pandas=1, cached_params=None):
candidate, fingerprints, vin, car_fw, source, exact_match = fingerprint(logcan, sendcan, set_obd_multiplexing, num_pandas) candidate, fingerprints, vin, car_fw, source, exact_match = fingerprint(logcan, sendcan, set_obd_multiplexing, num_pandas, cached_params)
if candidate is None: if candidate is None:
carlog.error({"event": "car doesn't match any fingerprints", "fingerprints": repr(fingerprints)}) carlog.error({"event": "car doesn't match any fingerprints", "fingerprints": repr(fingerprints)})

@ -62,7 +62,11 @@ class Car:
experimental_long_allowed = self.params.get_bool("ExperimentalLongitudinalEnabled") experimental_long_allowed = self.params.get_bool("ExperimentalLongitudinalEnabled")
num_pandas = len(messaging.recv_one_retry(self.sm.sock['pandaStates']).pandaStates) num_pandas = len(messaging.recv_one_retry(self.sm.sock['pandaStates']).pandaStates)
self.CI, self.CP = get_car(self.can_sock, self.pm.sock['sendcan'], obd_callback(self.params), experimental_long_allowed, num_pandas) cached_params = self.params.get("CarParamsCache")
self.CI, self.CP = get_car(self.can_sock, self.pm.sock['sendcan'], obd_callback(self.params), experimental_long_allowed, num_pandas, cached_params)
# continue onto next fingerprinting step in pandad
self.params.put_bool("FirmwareQueryDone", True)
else: else:
self.CI, self.CP = CI, CI.CP self.CI, self.CP = CI, CI.CP

@ -8,7 +8,6 @@ import capnp
import panda.python.uds as uds import panda.python.uds as uds
from cereal import car from cereal import car
from openpilot.common.params import Params
from openpilot.selfdrive.car import carlog from openpilot.selfdrive.car import carlog
from openpilot.selfdrive.car.ecu_addrs import get_ecu_addrs from openpilot.selfdrive.car.ecu_addrs import get_ecu_addrs
from openpilot.selfdrive.car.fingerprints import FW_VERSIONS from openpilot.selfdrive.car.fingerprints import FW_VERSIONS

@ -348,14 +348,15 @@ def get_car_params_callback(rc, pm, msgs, fingerprint):
sendcan = DummySocket() sendcan = DummySocket()
canmsgs = [msg for msg in msgs if msg.which() == "can"] canmsgs = [msg for msg in msgs if msg.which() == "can"]
has_cached_cp = params.get("CarParamsCache") is not None cached_params = params.get("CarParamsCache")
has_cached_cp = cached_params is not None
assert len(canmsgs) != 0, "CAN messages are required for fingerprinting" assert len(canmsgs) != 0, "CAN messages are required for fingerprinting"
assert os.environ.get("SKIP_FW_QUERY", False) or has_cached_cp, \ assert os.environ.get("SKIP_FW_QUERY", False) or has_cached_cp, \
"CarParamsCache is required for fingerprinting. Make sure to keep carParams msgs in the logs." "CarParamsCache is required for fingerprinting. Make sure to keep carParams msgs in the logs."
for m in canmsgs[:300]: for m in canmsgs[:300]:
can.send(m.as_builder().to_bytes()) can.send(m.as_builder().to_bytes())
_, CP = get_car(can, sendcan, lambda obd: None, Params().get_bool("ExperimentalLongitudinalEnabled")) _, CP = get_car(can, sendcan, lambda obd: None, Params().get_bool("ExperimentalLongitudinalEnabled"), cached_params=cached_params)
if not params.get_bool("DisengageOnAccelerator"): if not params.get_bool("DisengageOnAccelerator"):
CP.alternativeExperience |= ALTERNATIVE_EXPERIENCE.DISABLE_DISENGAGE_ON_GAS CP.alternativeExperience |= ALTERNATIVE_EXPERIENCE.DISABLE_DISENGAGE_ON_GAS

Loading…
Cancel
Save