From 40575b9cf3cc9676f72043eb63d6a3e46be97d70 Mon Sep 17 00:00:00 2001 From: firestar5683 <168790843+firestar5683@users.noreply.github.com> Date: Sun, 15 Nov 2026 14:29:04 -0600 Subject: [PATCH] Reduce Honda Bosch-A radar decoding overhead --- .../opendbc/car/honda/bosch_a_radar.py | 12 +++++- .../car/honda/tests/test_bosch_a_radar.py | 42 +++++++++++++++++++ prebuilt.json | 2 +- 3 files changed, 54 insertions(+), 2 deletions(-) diff --git a/opendbc_repo/opendbc/car/honda/bosch_a_radar.py b/opendbc_repo/opendbc/car/honda/bosch_a_radar.py index d1af5ceab6..30c43f4a08 100644 --- a/opendbc_repo/opendbc/car/honda/bosch_a_radar.py +++ b/opendbc_repo/opendbc/car/honda/bosch_a_radar.py @@ -1,5 +1,6 @@ import math from collections import deque +from collections.abc import Sequence from dataclasses import dataclass, field from opendbc.can import CANParser from opendbc.car import Bus, structs @@ -119,7 +120,16 @@ def _bosch_a_measurement_degraded(range_sigma_raw: int, existence_raw: int, dire def _create_bosch_a_can_parser(CP): messages = [(addr, BOSCH_A_FREQ_HZ) for addr in BOSCH_A_ALL_IDS] - return CANParser(DBC[CP.carFingerprint][Bus.radar], messages, CanBus(CP).camera) + main_signals = ( + ("FRAME_IDX", "STATUS", "RANGE_RAW", "AZIMUTH_RAW", "RANGE_SIGMA_RAW"), + ("FRAME_IDX", "OBJECT_EXISTENCE_PROBABILITY_RAW"), + ("FRAME_IDX", "LIFECYCLE_RAW"), + ("FRAME_IDX", "TRACK_ID"), + ) + signals: dict[str | int, Sequence[str]] = {addr: main_signals[index] for ids in BOSCH_A_MAIN_IDS for index, addr in enumerate(ids)} + signals.update(dict.fromkeys(BOSCH_A_AUX_IDS, ("FRAME_IDX", "REL_VELOCITY_RAW", "REL_VELOCITY_UNCERTAINTY_RAW", + "RANGE_RATIO_RAW", "FW_LID_00C9_RAW", "FW_LID_00CA_RAW"))) + return CANParser(DBC[CP.carFingerprint][Bus.radar], messages, CanBus(CP).camera, signals=signals) VERIFIED_BOSCH_A_CARS = frozenset((CAR.HONDA_CIVIC_BOSCH, CAR.HONDA_CRV_5G)) diff --git a/opendbc_repo/opendbc/car/honda/tests/test_bosch_a_radar.py b/opendbc_repo/opendbc/car/honda/tests/test_bosch_a_radar.py index 5ee13e0c9f..49adb8e9e9 100644 --- a/opendbc_repo/opendbc/car/honda/tests/test_bosch_a_radar.py +++ b/opendbc_repo/opendbc/car/honda/tests/test_bosch_a_radar.py @@ -172,3 +172,45 @@ def test_selected_bosch_a_direct_update_uses_its_actual_protocol(candidate): result = radar._update([radar.trigger_msg]) assert result.errors.canError assert not result.points + + +@pytest.mark.parametrize("identity", (CAR.HONDA_CIVIC_BOSCH, CAR.HONDA_CRV_5G)) +@pytest.mark.parametrize("alpha", (False, True)) +def test_consumed_signal_projection_matches_full_decoder_and_reduces_decode_work(identity, alpha, monkeypatch): + from opendbc.can import CANParser + from opendbc.can.dbc import Signal + from opendbc.car import Bus + from opendbc.car.honda.bosch_a_radar import BOSCH_A_ALL_IDS, BOSCH_A_FREQ_HZ + from opendbc.car.honda.values import DBC + cp = CarInterface.get_params(identity, gen_empty_fingerprint(), [], alpha, False, False) + projected, full = RadarInterface(cp), RadarInterface(cp) + assert projected.bosch_a is not None and full.bosch_a is not None + bus = CanBus(cp).camera + full.rcp = full.bosch_a.rcp = CANParser(DBC[cp.carFingerprint][Bus.radar], + [(address, BOSCH_A_FREQ_HZ) for address in BOSCH_A_ALL_IDS], bus) + batches = [sweep(bus, index, 1_000_000_000 + index * 70_000_000) for index in range(4)] + batches.append([(1_300_000_000, [])]) + batches.append([(1_600_000_000, [])]) + batches += [sweep(bus, index, 1_700_000_000 + index * 70_000_000) for index in range(4, 7)] + batches.append(sweep(bus + 1, 7, 2_300_000_000)) + batches.append(sweep(bus, 8, 2_400_000_000, with_aux=False)) + original = Signal.get_raw_value + counts = [] + outputs = [] + for receiver in (projected, full): + calls = [] + def decode(signal, data, _calls=calls): + _calls.append(1) + return original(signal, data) + monkeypatch.setattr(Signal, "get_raw_value", decode) + result = [] + for batch in batches: + value = receiver.update(batch) + result.append((value.to_bytes() if value is not None else None, receiver.rcp.can_valid, + receiver.rcp.last_nonempty_nanos, receiver.rcp._last_update_nanos, + {address: (state.counter, state.counter_fail, tuple(state.timestamps)) + for address, state in receiver.rcp.message_states.items()})) + counts.append(len(calls)) + outputs.append(result) + assert outputs[0] == outputs[1] + assert counts[0] < counts[1] diff --git a/prebuilt.json b/prebuilt.json index 2b4a0398ab..d0a26f1e2d 100644 --- a/prebuilt.json +++ b/prebuilt.json @@ -1 +1 @@ -{"protected_inventory_sha256": "8418fe1d5a7f3b47efcec4e4c95d2c5849804774af09e209c80855b141a28454", "schema_version": 1} +{"protected_inventory_sha256": "8fa3a869af4f8f0075579369382909db5b3189169578383ee53e49a9e2ea359a", "schema_version": 1}