# FlexRay slot allocation: assign I-PDUs to static slots
# Safety-critical signals → static slots
# High-bandwidth non-critical → dynamic segment
messages = [
# (name, payload_bytes, rate_ms, safety_critical)
("SteeringTorqueCmd", 4, 2, True), # → 1 slot per cycle (2ms cycle)
("BrakePressureFB", 8, 2, True), # → 1 slot per cycle
("WheelSpeed_FL", 4, 2, True), # → 1 slot per cycle
("WheelSpeed_FR", 4, 2, True), # → 1 slot per cycle
("EngineSpeed", 4, 5, False), # → every 2nd or 3rd cycle
("XCP_Calibration", 24, 10, False), # → dynamic segment preferred
]
GDCYCLE_MS = 2
PAYLOAD_MAX = 12 # words = 24 bytes per static slot
static_slots_needed = 0
for name, payload, rate, critical in messages:
if critical:
slots_per_cycle = 1 # rate must be ≤ gdCycle for critical
static_slots_needed += slots_per_cycle
print(f"Static slot {static_slots_needed}: {name} ({payload}B, {rate}ms, every cycle)")
else:
cycles_per_msg = rate // GDCYCLE_MS
print(f" Optional static (every {cycles_per_msg} cycles) or dynamic: {name}")
print(f"\nTotal static slots required: {static_slots_needed}")
print(f"Bandwidth: {static_slots_needed} × 24B × 8 / {GDCYCLE_MS}ms = "
f"{static_slots_needed * 24 * 8 / (GDCYCLE_MS/1000) / 1e6:.1f} Mbps")