/// <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);
        }
Пример #2
0
        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);
        }
Пример #3
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);
        }
        /// <summary>
        /// Simulates a race from a json that contains all the race events
        /// </summary>
        /// <param name="simulationData"></param>
        public void Start(RaceSummary simulationData)
        {
            Stop();

            XmlConfigurator.Configure(new FileInfo("logConfig.xml"));

            //we need the simulation specific methods in the constructor
            SimulationRiderIdUnit startId    = new SimulationRiderIdUnit(simulationData.StartId, simulationData);
            SimulationRiderIdUnit endId      = new SimulationRiderIdUnit(simulationData.EndId, simulationData);
            SimulationTimingUnit  timingUnit = new SimulationTimingUnit(simulationData);

            displays.Add(timingUnit);
            startGate = startId;
            endGate   = endId;
            timing    = timingUnit;

            startId.Initialize();
            endId.Initialize();
            timingUnit.Initialize();

            tracker = new RaceTracker(timing, startId, endId, simulationData.Config, simulationData.Riders);
            HookEvents(tracker);

            var trackTask = tracker.Run(source.Token);

            var startTask = startId.Run(source.Token);
            var endTask   = endId.Run(source.Token);
            var timeTask  = timingUnit.Run(source.Token);

            //will complete when all units run out of events to simulate
            var unitsTask = Task.WhenAll(startTask, endTask, timeTask);

            CombinedTasks = Task.Run(() =>
            {
                unitsTask.Wait();
                source.Cancel();
                trackTask.Wait();
            });
        }