# Exercise: add steering_angle to FlexRay cluster
# Requirements: 16 bytes, 5 ms rate (every 2nd cycle of a 2 ms cluster)
import vflexray_api as vfr
cluster = vfr.LoadCluster("FlexRay_Cluster_0.xml")
# Check slot 5 is free
slot = cluster.GetSlot(5)
assert slot.node is None, f"Slot 5 already assigned to {slot.node}"
# Assign: ECU_EPS in slot 5, Channel A+B, every 1st and 2nd cycle
cluster.AssignSlot(
slot_id=5,
node="ECU_EPS",
channel=vfr.CHANNEL_AB,
cycle_repetition=2, # transmit every 2nd cycle (→ 5 ms effective rate)
cycle_base_offset=0, # start transmitting from cycle 0
)
# Add I-PDU mapping
cluster.AddPDU(
slot_id=5,
pdu_name="SteeringAngle_PDU",
start_byte=0,
length=16, # 16 bytes; fits in 24-byte slot
)
# Verify no slot conflicts
conflicts = cluster.ValidateSlotMatrix()
assert len(conflicts) == 0, f"Slot conflicts: {conflicts}"
# Re-export FIBEX
cluster.ExportFIBEX("FlexRay_Cluster_0_updated.xml")
print("SteeringAngle added to slot 5 — re-import FIBEX in CANoe")