mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-12-02 06:23:40 +08:00
Restore first-generation EV6 wheel media controls
Restore the pre-rebase selected E-CAN 0x448 mapping for KIA_EV6 only, including HDA I and offset buses. Keep freshness and gesture guards and avoid borrowing Ioniq-specific AOL policy.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
"""Receive-only Ioniq 6 wheel media evidence, independent of CAN validity.
|
||||
"""Receive-only Ioniq 6 / first-generation EV6 wheel media evidence, independent of CAN validity.
|
||||
|
||||
Only exact physical-bus 0x448/8 packets establish a sample. Times come from
|
||||
the CAN receive timeline; consumers must not compare them to MONOTONIC.
|
||||
@@ -33,11 +33,11 @@ class Ioniq6MediaButtons:
|
||||
The recorded Ioniq neutral source runs at about 5 Hz. A 300 ms bound allows
|
||||
normal cadence but clears a held sequence across a missing source. Press
|
||||
transitions and their physical cadence still require vehicle qualification.
|
||||
The caller must restrict construction to the reviewed Ioniq configuration.
|
||||
The caller restricts construction to supported Ioniq 6 / EV6 configurations.
|
||||
"""
|
||||
|
||||
def __init__(self, bus: int):
|
||||
if type(bus) is not int or bus not in (0, 1, 2, 3, 5):
|
||||
if type(bus) is not int or bus not in (0, 1, 2, 3, 4, 5):
|
||||
raise ValueError("physical CAN bus required")
|
||||
self.bus = bus
|
||||
self.epoch = 0
|
||||
|
||||
@@ -50,7 +50,7 @@ class TestIoniq6Media(unittest.TestCase):
|
||||
result = source.update([packet(START + MEDIA_MAX_GAP_NS + 2, mode=True, bus=bus)])
|
||||
self.assertFalse(result.valid)
|
||||
self.assertEqual(result.samples, ())
|
||||
for bus in (True, -1, 4, 129):
|
||||
for bus in (True, -1, 6, 129):
|
||||
with self.assertRaises(ValueError):
|
||||
Ioniq6MediaButtons(bus)
|
||||
|
||||
|
||||
@@ -30,4 +30,6 @@ def configuration_wheel_policy(cp) -> WheelSettingsPolicy | None:
|
||||
|
||||
|
||||
def configuration_media_supported(cp) -> bool:
|
||||
return supports_ioniq6_configuration(cp)
|
||||
return (supports_ioniq6_configuration(cp) or
|
||||
bool(cp is not None and cp.brand == 'hyundai' and cp.carFingerprint == CAR.KIA_EV6 and
|
||||
not cp.notCar and not cp.passive and not cp.dashcamOnly))
|
||||
|
||||
@@ -14,7 +14,7 @@ from opendbc.car.gm.distance_button import DistanceObservation, DistanceSample
|
||||
from opendbc.car.hyundai.ioniq6_media import MediaObservation
|
||||
from opendbc.car.hyundai.hyundaicanfd import CanBus
|
||||
from opendbc.car.hyundai.canfd_owner import config_index
|
||||
from opendbc.car.hyundai.values import CAR as HYUNDAI_CAR
|
||||
from opendbc.car.hyundai.values import CAR as HYUNDAI_CAR, HyundaiFlags
|
||||
from openpilot.selfdrive.car.cruise import CRUISE_LONG_PRESS
|
||||
from openpilot.starpilot.conditional_mode.policy import ModeChoice, next_manual_status, restore_manual_status
|
||||
from openpilot.starpilot.conditional_mode.preferences import ManualState, manual_for_drive
|
||||
@@ -30,9 +30,17 @@ ButtonType = car.CarState.ButtonEvent.Type
|
||||
|
||||
|
||||
def ioniq6_media_eligible(CP: car.CarParams) -> bool:
|
||||
"""Only the reviewed Ioniq E-CAN topology has physical media evidence."""
|
||||
return (CP.carFingerprint == HYUNDAI_CAR.HYUNDAI_IONIQ_6 and config_index(CP) is not None and
|
||||
CanBus(CP).ECAN in (1, 5))
|
||||
"""Legacy name shared by the Ioniq 6 and restored first-generation EV6 path.
|
||||
|
||||
Pre-rebase StarPilot decoded both models' 0x448 MODE/CUSTOM signals on
|
||||
selected E-CAN. Keep the expansion model-specific, not all Hyundai CAN-FD.
|
||||
"""
|
||||
if CP.carFingerprint == HYUNDAI_CAR.HYUNDAI_IONIQ_6:
|
||||
return config_index(CP) is not None and CanBus(CP).ECAN in (1, 5)
|
||||
required = HyundaiFlags.CANFD | HyundaiFlags.EV
|
||||
return (CP.brand == 'hyundai' and CP.carFingerprint == HYUNDAI_CAR.KIA_EV6 and
|
||||
CP.flags & required == required and not CP.flags & (HyundaiFlags.CCNC | HyundaiFlags.CANFD_ANGLE_STEERING) and
|
||||
config_index(CP) is not None and CanBus(CP).ECAN in (0, 1, 4, 5))
|
||||
|
||||
|
||||
class Button(StrEnum):
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
"""Restore pre-rebase EV6 0x448 media controls without borrowing other models.
|
||||
|
||||
Legacy source: StarPilot c2e5e469, Hyundai carstate/get_can_parsers and
|
||||
hyundai_canfd.dbc (MODE bit 22, CUSTOM bit 44, selected E-CAN).
|
||||
"""
|
||||
from types import SimpleNamespace
|
||||
import unittest
|
||||
|
||||
from opendbc.car import gen_empty_fingerprint
|
||||
from opendbc.car.hyundai.interface import CarInterface
|
||||
from opendbc.car.hyundai.hyundaicanfd import CanBus
|
||||
from opendbc.car.hyundai.values import CAR, HyundaiFlags
|
||||
from opendbc.car.hyundai.ioniq6_media import Ioniq6MediaButtons
|
||||
from opendbc.car.hyundai.tests.test_ioniq6_media import packet
|
||||
from openpilot.starpilot.car.hyundai.settings import configuration_media_supported, configuration_wheel_policy
|
||||
from openpilot.starpilot.conditional_mode.manual import Button, ButtonTracker, Gesture, MEDIA_LONG_NS, Press, ioniq6_media_eligible
|
||||
from opendbc.car.structs import car
|
||||
|
||||
|
||||
def ev6(*, hda2, offset):
|
||||
fp = gen_empty_fingerprint()
|
||||
fp[offset + 2].update({0x50: 16, 0x2A4: 24} if hda2 else {0x12A: 16, 0x1A0: 32})
|
||||
fp[offset + int(hda2)].update({0x1CF: 8, 0x35: 32, 0x175: 24, 0xA0: 24, 0xEA: 24})
|
||||
return CarInterface.get_params(CAR.KIA_EV6, fp, [], False, False, False)
|
||||
|
||||
|
||||
class EV6MediaTests(unittest.TestCase):
|
||||
def test_hda1_hda2_and_offset_use_selected_bus_and_release_once(self):
|
||||
for hda2 in (False, True):
|
||||
for offset in (0, 4):
|
||||
with self.subTest(hda2=hda2, offset=offset):
|
||||
cp = ev6(hda2=hda2, offset=offset)
|
||||
self.assertTrue(ioniq6_media_eligible(cp))
|
||||
bus = CanBus(cp).ECAN
|
||||
self.assertEqual(bus, offset + int(hda2))
|
||||
receiver, tracker = Ioniq6MediaButtons(bus), ButtonTracker()
|
||||
state = car.CarState(canValid=True)
|
||||
def sample(stamp, custom=False, source_bus=bus, tracker=tracker, state=state, receiver=receiver):
|
||||
return tracker.observe(state, receiver.update([packet(stamp, custom=custom, bus=source_bus)]))
|
||||
self.assertEqual(sample(1_000_000_000), ())
|
||||
self.assertEqual(sample(1_100_000_000, True), ())
|
||||
self.assertEqual(sample(1_200_000_000), (Gesture(Button.CUSTOM, Press.SHORT),))
|
||||
self.assertEqual(sample(1_300_000_000), ())
|
||||
self.assertEqual(sample(1_400_000_000, True, (bus + 1) % 6), ())
|
||||
self.assertEqual(sample(1_500_000_000), ())
|
||||
self.assertTrue(configuration_media_supported(cp))
|
||||
# Media support must not copy Ioniq-specific AOL/cruise policy.
|
||||
self.assertIsNone(configuration_wheel_policy(cp))
|
||||
|
||||
def test_ev6_hold_and_source_loss_preserve_gesture_guards(self):
|
||||
source, tracker = Ioniq6MediaButtons(0), ButtonTracker()
|
||||
state = car.CarState(canValid=True)
|
||||
def sample(stamp, custom=False):
|
||||
return tracker.observe(state, source.update([packet(stamp, custom=custom, bus=0)]))
|
||||
start = 1_000_000_000
|
||||
sample(start)
|
||||
sample(start + 100_000_000, True)
|
||||
gestures = []
|
||||
for elapsed in range(100_000_000, MEDIA_LONG_NS + 100_000_000, 100_000_000):
|
||||
gestures.extend(sample(start + 100_000_000 + elapsed, True))
|
||||
self.assertEqual(gestures, [Gesture(Button.CUSTOM, Press.LONG)])
|
||||
self.assertEqual(sample(start + MEDIA_LONG_NS + 200_000_000), ())
|
||||
# Missing source revokes held state, not a synthetic release command.
|
||||
sample(start + MEDIA_LONG_NS + 300_000_000, True)
|
||||
self.assertEqual(tracker.observe(state, source.update([])), ())
|
||||
self.assertEqual(sample(start + MEDIA_LONG_NS + 400_000_000), ())
|
||||
|
||||
def test_other_models_and_malformed_topology_are_not_expanded(self):
|
||||
for model in (CAR.KIA_EV6_2025, CAR.KIA_EV9, CAR.HYUNDAI_IONIQ_5):
|
||||
cp = ev6(hda2=True, offset=0)
|
||||
cp.carFingerprint = model
|
||||
self.assertFalse(ioniq6_media_eligible(cp))
|
||||
self.assertFalse(configuration_media_supported(cp))
|
||||
for flag in (HyundaiFlags.CCNC, HyundaiFlags.CANFD_ANGLE_STEERING):
|
||||
cp = ev6(hda2=True, offset=0)
|
||||
cp.flags |= int(flag)
|
||||
self.assertFalse(ioniq6_media_eligible(cp))
|
||||
cp = ev6(hda2=True, offset=0)
|
||||
cp.safetyConfigs = []
|
||||
self.assertFalse(ioniq6_media_eligible(cp))
|
||||
|
||||
def test_saved_ev6_media_requires_usable_vehicle(self):
|
||||
cp = SimpleNamespace(brand='hyundai', carFingerprint=CAR.KIA_EV6, notCar=False, passive=False, dashcamOnly=False)
|
||||
self.assertTrue(configuration_media_supported(cp))
|
||||
for key in ('notCar', 'passive', 'dashcamOnly'):
|
||||
setattr(cp, key, True)
|
||||
self.assertFalse(configuration_media_supported(cp))
|
||||
setattr(cp, key, False)
|
||||
Reference in New Issue
Block a user