mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-12-03 22:23:41 +08:00
Avoid unused Sonata Hybrid CAN receipt decoding
This commit is contained in:
@@ -5,6 +5,18 @@ from opendbc.car.hyundai.classic_scc_aol import CLASSIC_SCC_IDS, stock_word
|
||||
AOL_MARKER = 0x0400
|
||||
AOL_EXPERIENCE = 32
|
||||
_EXCLUDED = int(HyundaiFlags.LEGACY | HyundaiFlags.UNSUPPORTED_LONGITUDINAL | HyundaiFlags.ALT_LIMITS_2 | HyundaiFlags.CAMERA_SCC | HyundaiFlags.FCEV)
|
||||
_DYNAMIC_FLAGS = int(HyundaiFlags.HAS_LDA_BUTTON | HyundaiFlags.USE_FCA | HyundaiFlags.SEND_LFA)
|
||||
_IDENTITY_MASK = int(
|
||||
HyundaiFlags.CANFD
|
||||
| HyundaiFlags.NON_SCC
|
||||
| HyundaiFlags.FCEV
|
||||
| HyundaiFlags.LEGACY
|
||||
| HyundaiFlags.EV
|
||||
| HyundaiFlags.HYBRID
|
||||
| HyundaiFlags.ALT_LIMITS
|
||||
| HyundaiFlags.ALT_LIMITS_2
|
||||
| HyundaiFlags.CAMERA_SCC
|
||||
)
|
||||
CLASSIC_LONG_IDS = frozenset(identity for identity in CLASSIC_SCC_IDS if not int(identity.config.flags) & _EXCLUDED)
|
||||
LONG_AOL_WORDS = frozenset(AOL_MARKER | 4 | gas | limits | lda for gas in (0, 1, 2) for limits in (0, 64) for lda in (0, 2048))
|
||||
|
||||
@@ -24,33 +36,22 @@ def aol_word(cp):
|
||||
|
||||
|
||||
def qualified(cp, *, marked_only=False):
|
||||
if not cp.openpilotLongitudinalControl or cp.pcmCruise:
|
||||
return False
|
||||
from opendbc.car.hyundai.legacy_long_aol import CARS, qualified as legacy_qualified
|
||||
if cp.carFingerprint in CARS:
|
||||
return legacy_qualified(cp, marked_only=marked_only)
|
||||
if cp.brand != 'hyundai' or cp.carFingerprint not in CLASSIC_LONG_IDS:
|
||||
return False
|
||||
declared = int(CAR[cp.carFingerprint].config.flags)
|
||||
allowed = declared | int(HyundaiFlags.HAS_LDA_BUTTON | HyundaiFlags.USE_FCA | HyundaiFlags.SEND_LFA)
|
||||
identity_mask = int(
|
||||
HyundaiFlags.CANFD
|
||||
| HyundaiFlags.NON_SCC
|
||||
| HyundaiFlags.FCEV
|
||||
| HyundaiFlags.LEGACY
|
||||
| HyundaiFlags.EV
|
||||
| HyundaiFlags.HYBRID
|
||||
| HyundaiFlags.ALT_LIMITS
|
||||
| HyundaiFlags.ALT_LIMITS_2
|
||||
| HyundaiFlags.CAMERA_SCC
|
||||
)
|
||||
allowed = declared | _DYNAMIC_FLAGS
|
||||
if (
|
||||
int(cp.flags) & identity_mask != declared & identity_mask
|
||||
int(cp.flags) & _IDENTITY_MASK != declared & _IDENTITY_MASK
|
||||
or int(cp.flags) & ~allowed
|
||||
or is_blended(cp)
|
||||
or cp.passive
|
||||
or cp.notCar
|
||||
or cp.dashcamOnly
|
||||
or not cp.openpilotLongitudinalControl
|
||||
or cp.pcmCruise
|
||||
or cp.steerControlType != structs.CarParams.SteerControlType.torque
|
||||
or not cp.alphaLongitudinalAvailable
|
||||
or cp.alternativeExperience not in (0, AOL_EXPERIENCE)
|
||||
|
||||
@@ -12,9 +12,21 @@ from opendbc.car.hyundai.values import CAR, HyundaiFlags, HyundaiSafetyFlags, is
|
||||
AOL_MARKER = 0x0400
|
||||
AOL_EXPERIENCE = 32
|
||||
_EXCLUDED = int(HyundaiFlags.CANFD | HyundaiFlags.NON_SCC | HyundaiFlags.FCEV)
|
||||
_DYNAMIC_FLAGS = int(HyundaiFlags.HAS_LDA_BUTTON | HyundaiFlags.USE_FCA | HyundaiFlags.SEND_LFA)
|
||||
_IDENTITY_MASK = _EXCLUDED | int(
|
||||
HyundaiFlags.EV | HyundaiFlags.HYBRID | HyundaiFlags.ALT_LIMITS | HyundaiFlags.ALT_LIMITS_2 | HyundaiFlags.CAMERA_SCC | HyundaiFlags.LEGACY
|
||||
)
|
||||
CLASSIC_SCC_IDS = frozenset(identity for identity in CAR if not int(identity.config.flags) & _EXCLUDED and identity != CAR.HYUNDAI_PALISADE_2023) | frozenset(
|
||||
(CAR.HYUNDAI_NEXO_1ST_GEN,)
|
||||
)
|
||||
_STOCK_FLAGS = tuple((int(flag), int(safety)) for flag, safety in (
|
||||
(HyundaiFlags.FCEV, HyundaiSafetyFlags.FCEV_GAS),
|
||||
(HyundaiFlags.EV, HyundaiSafetyFlags.EV_GAS),
|
||||
(HyundaiFlags.HYBRID, HyundaiSafetyFlags.HYBRID_GAS),
|
||||
(HyundaiFlags.ALT_LIMITS, HyundaiSafetyFlags.ALT_LIMITS),
|
||||
(HyundaiFlags.ALT_LIMITS_2, HyundaiSafetyFlags.ALT_LIMITS_2),
|
||||
(HyundaiFlags.CAMERA_SCC, HyundaiSafetyFlags.CAMERA_SCC),
|
||||
))
|
||||
_MODELS = (structs.CarParams.SafetyModel.hyundai, structs.CarParams.SafetyModel.hyundaiLegacy)
|
||||
FCEV_AOL_WORDS = frozenset((0x0500, 0x0D00))
|
||||
NORMAL_AOL_WORDS = (
|
||||
@@ -31,16 +43,10 @@ def native_profile_supported(model, param):
|
||||
|
||||
def stock_word(cp):
|
||||
word = int(HyundaiSafetyFlags.CAN_REFRESH_MSGS) if cp.carFingerprint in (CAR.HYUNDAI_ELANTRA_2024, CAR.HYUNDAI_ELANTRA_HEV_2024) else 0
|
||||
for flag, safety in (
|
||||
(HyundaiFlags.FCEV, HyundaiSafetyFlags.FCEV_GAS),
|
||||
(HyundaiFlags.EV, HyundaiSafetyFlags.EV_GAS),
|
||||
(HyundaiFlags.HYBRID, HyundaiSafetyFlags.HYBRID_GAS),
|
||||
(HyundaiFlags.ALT_LIMITS, HyundaiSafetyFlags.ALT_LIMITS),
|
||||
(HyundaiFlags.ALT_LIMITS_2, HyundaiSafetyFlags.ALT_LIMITS_2),
|
||||
(HyundaiFlags.CAMERA_SCC, HyundaiSafetyFlags.CAMERA_SCC),
|
||||
):
|
||||
if int(cp.flags) & int(flag):
|
||||
word |= int(safety)
|
||||
flags = int(cp.flags)
|
||||
for flag, safety in _STOCK_FLAGS:
|
||||
if flags & flag:
|
||||
word |= safety
|
||||
return word
|
||||
|
||||
|
||||
@@ -52,12 +58,9 @@ def qualified(cp, *, marked_only=False):
|
||||
if cp.brand != "hyundai" or cp.carFingerprint not in CLASSIC_SCC_IDS:
|
||||
return False
|
||||
declared = int(CAR[cp.carFingerprint].config.flags)
|
||||
allowed = declared | int(HyundaiFlags.HAS_LDA_BUTTON | HyundaiFlags.USE_FCA | HyundaiFlags.SEND_LFA)
|
||||
identity_mask = _EXCLUDED | int(
|
||||
HyundaiFlags.EV | HyundaiFlags.HYBRID | HyundaiFlags.ALT_LIMITS | HyundaiFlags.ALT_LIMITS_2 | HyundaiFlags.CAMERA_SCC | HyundaiFlags.LEGACY
|
||||
)
|
||||
allowed = declared | _DYNAMIC_FLAGS
|
||||
if (
|
||||
int(cp.flags) & identity_mask != declared & identity_mask
|
||||
int(cp.flags) & _IDENTITY_MASK != declared & _IDENTITY_MASK
|
||||
or int(cp.flags) & ~allowed
|
||||
or is_blended(cp)
|
||||
or cp.passive
|
||||
|
||||
@@ -484,7 +484,11 @@ class Car:
|
||||
|
||||
can_strs = messaging.drain_sock_raw(self.can_sock, wait_for_one=True)
|
||||
can_received_ns = time.monotonic_ns()
|
||||
can_list = can_capnp_to_list(can_strs)
|
||||
if (self.CP.carFingerprint == HYUNDAI_CAR.HYUNDAI_SONATA_HYBRID and self.CP.pcmCruise and
|
||||
not self.CP.openpilotLongitudinalControl):
|
||||
can_list = can_capnp_to_list(can_strs, include_tx_receipts=False)
|
||||
else:
|
||||
can_list = can_capnp_to_list(can_strs)
|
||||
|
||||
observe_controller_can(self.CI, can_list)
|
||||
CS = self.CI.update(can_list)
|
||||
|
||||
@@ -32,6 +32,7 @@ def can_list_to_can_capnp(can_msgs, msgtype='can', valid=True, *, source_observe
|
||||
Args:
|
||||
can_msgs: List of tuples [(address, data_bytes, src), ...]
|
||||
msgtype: 'can' or 'sendcan'
|
||||
include_tx_receipts: retain Panda TX receipts (sources 128 and above)
|
||||
valid: Whether the event is valid
|
||||
|
||||
Returns:
|
||||
@@ -64,12 +65,13 @@ def can_list_to_can_capnp(can_msgs, msgtype='can', valid=True, *, source_observe
|
||||
return dat.to_bytes()
|
||||
|
||||
|
||||
def can_capnp_to_list(strings, msgtype='can'):
|
||||
def can_capnp_to_list(strings, msgtype='can', *, include_tx_receipts=True):
|
||||
"""Convert Cap'n Proto serialized bytes to list of CAN messages.
|
||||
|
||||
Args:
|
||||
strings: Tuple/list of serialized Cap'n Proto bytes
|
||||
msgtype: 'can' or 'sendcan'
|
||||
include_tx_receipts: retain Panda TX receipts (sources 128 and above)
|
||||
|
||||
Returns:
|
||||
List of tuples [(nanos, [(address, data, src), ...]), ...]
|
||||
@@ -87,7 +89,14 @@ def can_capnp_to_list(strings, msgtype='can'):
|
||||
|
||||
if _cached_reader_fields is not None:
|
||||
addr_f, dat_f, src_f = _cached_reader_fields
|
||||
frame_list = [(f._get_by_field(addr_f), f._get_by_field(dat_f), f._get_by_field(src_f)) for f in frames]
|
||||
if include_tx_receipts:
|
||||
frame_list = [(f._get_by_field(addr_f), f._get_by_field(dat_f), f._get_by_field(src_f)) for f in frames]
|
||||
else:
|
||||
frame_list = []
|
||||
for f in frames:
|
||||
src = f._get_by_field(src_f)
|
||||
if src < 128:
|
||||
frame_list.append((f._get_by_field(addr_f), f._get_by_field(dat_f), src))
|
||||
else:
|
||||
frame_list = []
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
from openpilot.cereal import messaging
|
||||
from openpilot.selfdrive.pandad import can_capnp_to_list, can_list_to_can_capnp
|
||||
|
||||
|
||||
def test_optional_receipt_filter_preserves_physical_frames_and_batch_stamps():
|
||||
frames = [(0x340, b'physical', 0), (0x340, b'returned', 128),
|
||||
(0x421, b'physical', 2), (0x421, b'rejected', 194)]
|
||||
receipts = [frames[1], frames[3]]
|
||||
packets = [can_list_to_can_capnp(batch) for batch in (frames, receipts, [])]
|
||||
stamps = [int(messaging.log_from_bytes(packet).logMonoTime) for packet in packets]
|
||||
|
||||
assert can_capnp_to_list(packets) == list(zip(stamps, (frames, receipts, []), strict=True))
|
||||
assert can_capnp_to_list(packets, include_tx_receipts=False) == list(zip(stamps, ([frames[0], frames[2]], [], []), strict=True))
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"protected_inventory_sha256": "5e7644be6ae196180c4077920cc19767980f7ec01245dbfe2f1f3b08afde9fe4", "schema_version": 1}
|
||||
{"protected_inventory_sha256": "b98964d19057291306da4bc7b734281def0f1ad7bf9b7002343843e347018bb9", "schema_version": 1}
|
||||
|
||||
Reference in New Issue
Block a user