From 9d43d4f9a8d990a0dcd7d89e2e3e2f61270b03e3 Mon Sep 17 00:00:00 2001 From: Comma Device Date: Sat, 26 Sep 2026 20:53:42 +0800 Subject: [PATCH] Parse Toyota BSM from either CAN bus --- opendbc_repo/opendbc/car/toyota/carstate.py | 25 ++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/opendbc_repo/opendbc/car/toyota/carstate.py b/opendbc_repo/opendbc/car/toyota/carstate.py index 08bfb78e8..a1a788edf 100644 --- a/opendbc_repo/opendbc/car/toyota/carstate.py +++ b/opendbc_repo/opendbc/car/toyota/carstate.py @@ -179,8 +179,21 @@ class CarState(CarStateBase, CarStateExt): ret.espDisabled = cp.vl["ESP_CONTROL"]["TC_DISABLED"] != 0 if self.CP.enableBsm: - ret.leftBlindspot = (cp.vl["BSM"]["L_ADJACENT"] == 1) or (cp.vl["BSM"]["L_APPROACHING"] == 1) - ret.rightBlindspot = (cp.vl["BSM"]["R_ADJACENT"] == 1) or (cp.vl["BSM"]["R_APPROACHING"] == 1) + bsm_pt = cp.vl["BSM"] + bsm_cam = cp_cam.vl["BSM"] + + ret.leftBlindspot = any(( + bsm_pt["L_ADJACENT"] == 1, + bsm_pt["L_APPROACHING"] == 1, + bsm_cam["L_ADJACENT"] == 1, + bsm_cam["L_APPROACHING"] == 1, + )) + ret.rightBlindspot = any(( + bsm_pt["R_ADJACENT"] == 1, + bsm_pt["R_APPROACHING"] == 1, + bsm_cam["R_ADJACENT"] == 1, + bsm_cam["R_APPROACHING"] == 1, + )) if self.CP.carFingerprint != CAR.TOYOTA_PRIUS_V: self.lkas_hud = copy.copy(cp_cam.vl["LKAS_HUD"]) @@ -227,7 +240,13 @@ class CarState(CarStateBase, CarStateExt): ("RSA2", 0), ] + if CP.enableBsm: + # BSM may be present on either the powertrain or camera bus. + # Mark it optional on each bus so a missing copy does not invalidate the parser. + pt_messages.append(("BSM", float('nan'))) + cam_messages.append(("BSM", float('nan'))) + return { Bus.pt: CANParser(DBC[CP.carFingerprint][Bus.pt], pt_messages, 0), - Bus.cam: CANParser(DBC[CP.carFingerprint][Bus.pt], [] + cam_messages, 2), + Bus.cam: CANParser(DBC[CP.carFingerprint][Bus.pt], cam_messages, 2), }