mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-12-02 03:13:44 +08:00
Recognize Sportage camera warnings across one frame of timing skew
This commit is contained in:
@@ -46,8 +46,9 @@ class CANFDLfaStatus:
|
||||
LENGTH = 16
|
||||
MAX_AGE_NS = MAX_AGE_NS
|
||||
|
||||
def __init__(self, bus):
|
||||
def __init__(self, bus, *, eps_response_margin_ns=0):
|
||||
self.bus = bus
|
||||
self.eps_response_margin_ns = eps_response_margin_ns
|
||||
self.last_packet_ns = 0
|
||||
self.counter = None
|
||||
self.body = None
|
||||
@@ -161,7 +162,7 @@ class CANFDLfaStatus:
|
||||
qualified = (self.eps_active and 0 < self.request_since_ns <= self.eps_active_since_ns <= self.camera_fault_since_ns and
|
||||
((0 < self.camera_fault_since_ns - self.camera_healthy_ns <= MAX_AGE_NS) or
|
||||
(self.camera_fault_since_ns == self.camera_healthy_ns and self.camera_fault_same_batch_healthy)) and
|
||||
self.camera_fault_since_ns - self.eps_active_since_ns <= OWNERSHIP_RESPONSE_NS)
|
||||
self.camera_fault_since_ns - self.eps_active_since_ns <= OWNERSHIP_RESPONSE_NS + self.eps_response_margin_ns)
|
||||
if qualified:
|
||||
self.display_fault_since_ns = self.camera_fault_since_ns
|
||||
self.display_last_active_ns = now_ns
|
||||
|
||||
@@ -64,7 +64,9 @@ class CarState(CarStateBase):
|
||||
def __init__(self, CP):
|
||||
super().__init__(CP)
|
||||
preserve_status = preserves_stock_lfa(CP)
|
||||
self.stock_lfa_status = CANFDLfaStatus(CanBus(CP).CAM) if preserve_status else None
|
||||
sportage_eps_margin_ns = 10_000_000 if CP.carFingerprint == CAR.KIA_SPORTAGE_5TH_GEN else 0
|
||||
self.stock_lfa_status = (CANFDLfaStatus(CanBus(CP).CAM, eps_response_margin_ns=sportage_eps_margin_ns)
|
||||
if preserve_status else None)
|
||||
self.stock_cluster_status = CANFDClusterStatus(CanBus(CP).CAM) if preserve_status else None
|
||||
self.stock_lkas_damping = (CANFDLkasDamping(CanBus(CP).CAM, bool(CP.flags & HyundaiFlags.CANFD_LKA_STEER_MSG_ALT))
|
||||
if preserves_stock_lkas_damping(CP) else None)
|
||||
|
||||
@@ -1009,3 +1009,40 @@ def test_ccnc_fault_handover_preserves_obstruction_and_unknown_codes(fault, owne
|
||||
for field in ('COUNTER', 'FAULT_FCA', 'FAULT_FSS', 'FAULT_ESS', 'FAULT_SCC'):
|
||||
assert decoder.vl['CCNC_0x162'][field] == original[field]
|
||||
assert decoder.vl['CCNC_0x161']['LFA_ICON'] == decoder.vl['CCNC_0x161']['CENTERLINE'] == 0
|
||||
|
||||
|
||||
@pytest.mark.parametrize('alpha', (False, True))
|
||||
@pytest.mark.parametrize('vehicle,case,owned', [
|
||||
(CAR.KIA_SPORTAGE_5TH_GEN, 'recorded', True),
|
||||
(CAR.KIA_SPORTAGE_5TH_GEN, 'late', False),
|
||||
(CAR.KIA_SPORTAGE_5TH_GEN, 'idle', False),
|
||||
(CAR.KIA_SPORTAGE_5TH_GEN, 'eps_fault', False),
|
||||
(CAR.KIA_SPORTAGE_5TH_GEN, 'camera_fault', False),
|
||||
(CAR.KIA_NIRO_EV_2ND_GEN, 'recorded', False),
|
||||
])
|
||||
def test_sportage_display_ownership_accepts_one_camera_frame_of_timing_skew(vehicle, case, owned, alpha, clock):
|
||||
cp = params(vehicle, alpha=alpha, alternate=True)
|
||||
ci = CarInterface(cp)
|
||||
ci.update([])
|
||||
packer = CANPacker(DBC[vehicle][Bus.pt])
|
||||
bus = ci.CC.CAN
|
||||
command = structs.CarControl.new_message()
|
||||
observed = {}
|
||||
for tick in range(28):
|
||||
clock[0] = 30_000_000_000 + tick * 10_000_000 + (310_000 if tick >= 19 else 0)
|
||||
command.enabled = command.latActive = tick >= 2 and case != 'idle'
|
||||
warning = tick >= (21 if case == 'late' else 19)
|
||||
stock = template(packer, bus.CAM, tick, warning=15 if warning else 0, fault=int(warning and case == 'camera_fault'))
|
||||
frames = [frame for frame in physical_frames(ci, packer, tick, stock) if frame[0] != 0xEA]
|
||||
frames.append(packer.make_can_msg('MDPS', bus.ECAN, {'COUNTER': tick,
|
||||
'MDPS_LkaToiActvSta': int(tick >= 4 and case != 'idle'), 'MDPS_LkaFailSta': int(warning and case == 'eps_fault')}))
|
||||
if tick % 5 == 0:
|
||||
frame = packer.make_can_msg('LFAHDA_CLUSTER', bus.CAM, {'COUNTER': tick // 5, 'NEW_SIGNAL_1': 3 if warning else 0})
|
||||
frames.append(frame)
|
||||
assert ci.update([(clock[0], frames)]).canValid
|
||||
_, packets = ci.apply(command.as_reader(), clock[0])
|
||||
if tick >= 25:
|
||||
observed.update((address, body) for address, body, src in packets if src == bus.ECAN and address in (0x12A, 0x1E0))
|
||||
assert observed[0x12A][7] >> 4 == (0 if owned else 15)
|
||||
assert observed[0x12A][6] >> 6 == int(case == 'camera_fault')
|
||||
assert observed[0x1E0][4] & 7 == (0 if owned else 3)
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
{"protected_inventory_sha256": "2b8ed241b0d68d5f9cba8a33d31a064555bc8f1abeaeadf5de340dd3f0926338", "schema_version": 1}
|
||||
{"protected_inventory_sha256": "6f1e8214cbe56baf57dfeda0ce3e285e24fc911f6a622fd0e124cb09a0a3a011", "schema_version": 1}
|
||||
|
||||
Reference in New Issue
Block a user