/// <summary> /// Manage a race from real sensor data /// </summary> public void Start(RaceConfig config, List <Rider> riders) { Stop(); CommunicationManager CommunicationManager = new CommunicationManager(source.Token); SerialTimingUnit timer = new SerialTimingUnit(CommunicationManager.GetCommunicationDevice(config.TimingUnitId), "timerUnit", source.Token, config.StartTimingGateId, config.EndTimingGateId); timing = timer; displays.Add(timer); BLERiderIdUnit realStartId = new BLERiderIdUnit(CommunicationManager.GetCommunicationDevice(config.StartIdUnitId), "startUnit", config.StartIdRange, source.Token); endGate = new BLERiderIdUnit(CommunicationManager.GetCommunicationDevice(config.EndIdUnitId), "finishUnit", config.EndIdRange, source.Token); startGate = realStartId; startLight = realStartId; startGate?.ClearKnownRiders(); endGate?.ClearKnownRiders(); startLight.SetStartLightColor(StartLightColor.YELLOW); startGate.AddKnownRiders(riders); tracker = new RaceTracker(timing, startGate, endGate, config.ExtractTrackerConfig(), riders); HookEvents(tracker); CombinedTasks = tracker.Run(source.Token); }
static void Main(string[] args) { XmlConfigurator.Configure(new System.IO.FileInfo("logConfig.xml")); CancellationTokenSource source = new CancellationTokenSource(); CommunicationManager = new CommunicationManager(source.Token); if (args.Length < 2) { Console.WriteLine($"Not enough arguments: {args.Length}"); PrintUsage(); Environment.Exit(-1); } try { riders = ReadRidersFile(args[0]); } catch (Exception ex) { Log.Error($"Could not parse riders file {args[0]}", ex); Environment.Exit(-2); } if (args[1] != "none") { timer = new SerialTimingUnit(CommunicationManager.GetCommunicationDevice(args[1]), "timerUnit", source.Token, 0, 1); timer.OnTrigger += Timer_OnTrigger; if (timer is AbstractCommunicatingUnit) { //((AbstractCommunicatingUnit)timer). } } startIdUnit = new BLERiderIdUnit(CommunicationManager.GetCommunicationDevice(args[2]), "startUnit", 2.0, source.Token); startIdUnit.OnRiderId += StartIdUnit_OnRiderId; startIdUnit.OnRiderExit += StartIdUnit_OnRiderExit; if (args.Length > 3) { finishIdUnit = new BLERiderIdUnit(CommunicationManager.GetCommunicationDevice(args[3]), "finishUnit", 2.0, source.Token); finishIdUnit.OnRiderId += FinishIdUnit_OnRiderId; finishIdUnit.OnRiderExit += FinishIdUnit_OnRiderExit; unitsConnecting++; } startIdUnit.AddKnownRiders(riders); finishIdUnit.AddKnownRiders(riders); Console.ReadLine(); source.Cancel(); CommunicationManager.Dispose(); Environment.Exit(0); }
protected override int OnExecute(CommandLineApplication app) { XmlConfigurator.Configure(new System.IO.FileInfo("logConfig.xml")); CancellationTokenSource source = new CancellationTokenSource(); CommunicationManager = new CommunicationManager(source.Token); try { riders = ReadRidersFile(RidersFile); } catch (Exception ex) { Log.Error($"Could not parse riders file {RidersFile}", ex); Environment.Exit(-2); } timer = new SerialTimingUnit(CommunicationManager.GetCommunicationDevice(TimingId), "timerUnit", source.Token, StartGateId, EndGateId); timer.OnTrigger += Timer_OnTrigger; if (timer is AbstractCommunicatingUnit) { //((AbstractCommunicatingUnit)timer). } startIdUnit = new BLERiderIdUnit(CommunicationManager.GetCommunicationDevice(StartId), "startUnit", 2.0, source.Token); startIdUnit.OnRiderId += StartIdUnit_OnRiderId; startIdUnit.OnRiderExit += StartIdUnit_OnRiderExit; if (!String.IsNullOrEmpty(EndId)) { finishIdUnit = new BLERiderIdUnit(CommunicationManager.GetCommunicationDevice(EndId), "finishUnit", 2.0, source.Token); unitsConnecting++; } startIdUnit.AddKnownRiders(riders); Console.ReadLine(); source.Cancel(); CommunicationManager.Dispose(); return(0); }