From ea05474df25b91fb2568c83ee18ea27d67327edd Mon Sep 17 00:00:00 2001 From: Maxime Desroches Date: Sat, 10 Aug 2024 00:05:35 -0700 Subject: [PATCH 1/2] op.sh: consistent naming (#33249) name --- tools/op.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/op.sh b/tools/op.sh index 7d972b0c86..a133cc4348 100755 --- a/tools/op.sh +++ b/tools/op.sh @@ -118,7 +118,7 @@ function op_check_os() { fi elif [[ "$OSTYPE" == "darwin"* ]]; then - echo -e " ↳ [${GREEN}✔${NC}] macos detected.\n" + echo -e " ↳ [${GREEN}✔${NC}] macOS detected.\n" else echo -e " ↳ [${RED}✗${NC}] OS type $OSTYPE not supported!" loge "ERROR_UNKNOWN_OS" "$OSTYPE" @@ -308,14 +308,14 @@ function op_default() { echo -e "${BOLD}${UNDERLINE}Usage:${NC} op [OPTIONS] " echo "" echo -e "${BOLD}${UNDERLINE}Commands:${NC}" - echo -e " ${BOLD}venv${NC} Activate the Python virtual environment" + echo -e " ${BOLD}venv${NC} Activate the python virtual environment" echo -e " ${BOLD}check${NC} Check the development environment (git, os, python) to start using openpilot" echo -e " ${BOLD}setup${NC} Install openpilot dependencies" echo -e " ${BOLD}build${NC} Run the openpilot build system in the current working directory" echo -e " ${BOLD}sim${NC} Run openpilot in a simulator" - echo -e " ${BOLD}juggle${NC} Run Plotjuggler" - echo -e " ${BOLD}replay${NC} Run replay" - echo -e " ${BOLD}cabana${NC} Run cabana" + echo -e " ${BOLD}juggle${NC} Run PlotJuggler" + echo -e " ${BOLD}replay${NC} Run Replay" + echo -e " ${BOLD}cabana${NC} Run Cabana" echo -e " ${BOLD}lint${NC} Run the linter" echo -e " ${BOLD}test${NC} Run all unit tests from pytest" echo -e " ${BOLD}help${NC} Show this message" From ee62b9c88baf4a53f6db88381da2b8052c3fab17 Mon Sep 17 00:00:00 2001 From: Shane Smiskol Date: Sat, 10 Aug 2024 02:06:56 -0500 Subject: [PATCH 2/2] move capnp CarParams decoding out of car_helpers (#33251) * move capnp byte decoding out of car_helpers * always wanted to type this * and process replay * this does nothing * might as well --- selfdrive/car/car_helpers.py | 20 +++++++------------ selfdrive/car/card.py | 8 +++++++- .../test/process_replay/process_replay.py | 11 +++++++--- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/selfdrive/car/car_helpers.py b/selfdrive/car/car_helpers.py index d2345f1a05..823f038a9c 100644 --- a/selfdrive/car/car_helpers.py +++ b/selfdrive/car/car_helpers.py @@ -2,14 +2,13 @@ import os import time from cereal import car -from openpilot.selfdrive.car import carlog +from openpilot.selfdrive.car import carlog, gen_empty_fingerprint from openpilot.selfdrive.car.can_definitions import CanRecvCallable, CanSendCallable -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.vin import get_vin, is_valid_vin, VIN_UNKNOWN from openpilot.selfdrive.car.fw_versions import ObdCallback, get_fw_versions_ordered, get_present_ecus, match_fw_to_car +from openpilot.selfdrive.car.interfaces import get_interface_attr from openpilot.selfdrive.car.mock.values import CAR as MOCK -from openpilot.selfdrive.car import gen_empty_fingerprint +from openpilot.selfdrive.car.vin import get_vin, is_valid_vin, VIN_UNKNOWN FRAME_FINGERPRINT = 100 # 1s @@ -82,7 +81,8 @@ def can_fingerprint(can_recv: CanRecvCallable) -> tuple[str | None, dict[int, di # **** for use live only **** -def fingerprint(can_recv: CanRecvCallable, can_send: CanSendCallable, set_obd_multiplexing: ObdCallback, num_pandas: int, cached_params_raw: bytes | None): +def fingerprint(can_recv: CanRecvCallable, can_send: CanSendCallable, set_obd_multiplexing: ObdCallback, num_pandas: int, + cached_params: type[car.CarParams] | None) -> tuple[str | None, dict, str, list, int, bool]: fixed_fingerprint = os.environ.get('FINGERPRINT', "") skip_fw_query = os.environ.get('SKIP_FW_QUERY', False) disable_fw_cache = os.environ.get('DISABLE_FW_CACHE', False) @@ -90,13 +90,7 @@ def fingerprint(can_recv: CanRecvCallable, can_send: CanSendCallable, set_obd_mu start_time = time.monotonic() if not skip_fw_query: - cached_params = None - if cached_params_raw is not None: - with car.CarParams.from_bytes(cached_params_raw) as cached_params: - if cached_params.carName == "mock": - cached_params = None - - if cached_params is not None and len(cached_params.carFw) > 0 and \ + if cached_params is not None and cached_params.carName != "mock" and len(cached_params.carFw) > 0 and \ cached_params.carVin is not VIN_UNKNOWN and not disable_fw_cache: carlog.warning("Using cached CarParams") vin_rx_addr, vin_rx_bus, vin = -1, -1, cached_params.carVin @@ -160,7 +154,7 @@ def get_car_interface(CP): def get_car(can_recv: CanRecvCallable, can_send: CanSendCallable, set_obd_multiplexing: ObdCallback, experimental_long_allowed: bool, - num_pandas: int = 1, cached_params: bytes | None = None): + num_pandas: int = 1, cached_params: type[car.CarParams] | None = None): candidate, fingerprints, vin, car_fw, source, exact_match = fingerprint(can_recv, can_send, set_obd_multiplexing, num_pandas, cached_params) if candidate is None: diff --git a/selfdrive/car/card.py b/selfdrive/car/card.py index 4919be30c9..d091f31042 100755 --- a/selfdrive/car/card.py +++ b/selfdrive/car/card.py @@ -87,7 +87,13 @@ 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") + + cached_params = None + cached_params_raw = self.params.get("CarParamsCache") + if cached_params_raw is not None: + with car.CarParams.from_bytes(cached_params_raw) as _cached_params: + cached_params = _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 diff --git a/selfdrive/test/process_replay/process_replay.py b/selfdrive/test/process_replay/process_replay.py index 055293f16f..8cf7d4138a 100755 --- a/selfdrive/test/process_replay/process_replay.py +++ b/selfdrive/test/process_replay/process_replay.py @@ -349,8 +349,8 @@ def get_car_params_callback(rc, pm, msgs, fingerprint): sendcan = DummySocket() canmsgs = [msg for msg in msgs if msg.which() == "can"] - cached_params = params.get("CarParamsCache") - has_cached_cp = cached_params is not None + cached_params_raw = params.get("CarParamsCache") + has_cached_cp = cached_params_raw is not None assert len(canmsgs) != 0, "CAN messages are required for fingerprinting" 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." @@ -358,13 +358,18 @@ def get_car_params_callback(rc, pm, msgs, fingerprint): for m in canmsgs[:300]: can.send(m.as_builder().to_bytes()) can_callbacks = can_comm_callbacks(can, sendcan) + + cached_params = None + if has_cached_cp: + with car.CarParams.from_bytes(cached_params_raw) as _cached_params: + cached_params = _cached_params + CP = get_car(*can_callbacks, lambda obd: None, Params().get_bool("ExperimentalLongitudinalEnabled"), cached_params=cached_params).CP if not params.get_bool("DisengageOnAccelerator"): CP.alternativeExperience |= ALTERNATIVE_EXPERIENCE.DISABLE_DISENGAGE_ON_GAS params.put("CarParams", CP.to_bytes()) - return CP def controlsd_rcv_callback(msg, cfg, frame):