Exemple #1
0
        public void ShouldRaiseEventWhenClusterRequiresUpdating()
        {
            var configuration = new TrafficLightConfig();

            configuration.Add(TrafficLightState.Go, 3);

            var light = new TrafficLight
            {
                Name          = "State Expired Test Light",
                Configuration = configuration
            };

            var cluster = new TetheredTrafficLightCluster {
                light
            };

            var receivedEvents = new List <TetheredClusterRequiresUpdateEventArg>();

            cluster.ClusterRequiresUpdateEvent += (sender, e)
                                                  => receivedEvents.Add(e);

            light.State = TrafficLightState.Go;
            Thread.Sleep(4000);

            Assert.AreEqual(1, receivedEvents.Count);
        }
 public PedestrianTrafficLightController(
     int redSignalDurationSeconds,
     int greenSignalDurationSeconds)
     : base(TrafficLightConfig.Create()
            .AddCycledState(new LightConfig(RedLightName, TimeSpan.FromSeconds(redSignalDurationSeconds)))
            .AddCycledState(new LightConfig(GreenLightName, TimeSpan.FromSeconds(greenSignalDurationSeconds), 3, TimeSpan.FromMilliseconds(500))))
 {
 }
 protected StandartTrafficLightController(
     int redSignalDurationSeconds,
     int yellowSignalDurationSeconds,
     int greenSignalDurationSeconds,
     TrafficLightConfig config)
     : base(TrafficLightConfig.BasedOn(config)
            .AddCycledState(new LightConfig(RedLightName, TimeSpan.FromSeconds(redSignalDurationSeconds)))
            .AddCycledState(new LightConfig(YellowLightName, TimeSpan.FromSeconds(yellowSignalDurationSeconds)))
            .AddCycledState(new LightConfig(GreenLightName, TimeSpan.FromSeconds(greenSignalDurationSeconds), 3, TimeSpan.FromMilliseconds(500))))
 {
 }
 public StandartTrafficLightController(
     int redSignalDurationSeconds,
     int yellowSignalDurationSeconds,
     int greenSignalDurationSeconds)
     : this(
         redSignalDurationSeconds,
         yellowSignalDurationSeconds,
         greenSignalDurationSeconds,
         TrafficLightConfig.Create())
 {
 }
Exemple #5
0
        public void ShouldStartTrafficLightCycle()
        {
            var configuration = new TrafficLightConfig();

            configuration.Add(TrafficLightState.Go, 4);
            configuration.Add(TrafficLightState.Stop, 4);
            SetTrafficLightConfiguration(configuration);

            var lights = new TrafficLights {
                _l1, _l2, _l3, _l4
            };
            var timer = new TrafficLightTimer();

            var tc1 = new TetheredTrafficLightCluster {
                _l1, _l2
            };

            tc1.Name = "TC-1";

            var pc1 = new PolarTrafficLightCluster(_l3)
            {
                { _l4 }
            };

            pc1.Name = "TC-2";

            Assert.IsTrue(lights.Add(tc1));
            Assert.IsTrue(lights.Add(pc1));

            var controller = new TrafficLightController(lights, timer);

            //Assert initial state is where expected
            Assert.AreEqual(TrafficLightState.StopThenGo, _l1.State);
            Assert.AreEqual(TrafficLightState.StopThenGo, _l2.State);
            Assert.AreEqual(TrafficLightState.StopThenGo, _l3.State);
            Assert.AreEqual(TrafficLightState.StopThenGo, _l4.State);

            controller.Start();  //Will trigger traffic light state changes

            Thread.Sleep(2000);
            Assert.AreEqual(TrafficLightState.Go, _l1.State);
            Assert.AreEqual(TrafficLightState.Go, _l2.State);
            Assert.AreEqual(TrafficLightState.Go, _l3.State);
            Assert.AreEqual(TrafficLightState.Stop, _l4.State);

            Thread.Sleep(5000);
            Assert.AreEqual(TrafficLightState.Stop, _l1.State);
            Assert.AreEqual(TrafficLightState.Stop, _l2.State);
            Assert.AreEqual(TrafficLightState.Stop, _l3.State);
            Assert.AreEqual(TrafficLightState.Go, _l4.State);

            controller.Stop();
        }
Exemple #6
0
 static Program()
 {
     RedLightRelay    = new OutputPort(Pins.GPIO_PIN_D4, Off);
     YellowLightRelay = new OutputPort(Pins.GPIO_PIN_D3, Off);
     GreenLightRelay  = new OutputPort(Pins.GPIO_PIN_D2, Off);
     _currentConfig   = _updatedConfig = new TrafficLightConfig
     {
         Red    = 10,
         Green  = 10,
         Yellow = 5
     };
 }
    // Use this for initialization
    private void Start()
    {
        // CurrentState = TrafficLightState.Red;
        m_MeshRen = GetComponent <MeshRenderer>();

        // m_Config.Add(new TrafficLightConfig());  // Create a default config line (is created by the default constructor)
        m_Config.Add(new TrafficLightConfig(new DateTime(1900, 1, 1, 00, 00, 00),
                                            new DateTime(1900, 1, 1, 00, 15, 00), 5, 3, 10, 5));
        m_Config.Add(new TrafficLightConfig(new DateTime(1900, 1, 1, 00, 16, 00), new DateTime(1900, 1, 1, 00, 10, 00), 5, 3, 30, 5));
        m_Config.Add(new TrafficLightConfig(new DateTime(1900, 1, 1, 00, 31, 00), new DateTime(1900, 1, 1, 23, 59, 00), 8, 5, 5, 8));

        m_currentConfig = m_Config[0]; // Set the config to the first one, will get updated on first update to the right config based on time of day
    }
 public LeftSectionStandartTrafficLightController(
     int redSignalDurationSeconds,
     int yellowSignalDurationSeconds,
     int greenSignalDurationSeconds,
     int leftGreenSignalDurationSeconds)
     : base(
         redSignalDurationSeconds,
         yellowSignalDurationSeconds,
         greenSignalDurationSeconds,
         TrafficLightConfig.Create()
         .AddState(new LightConfig(LeftGreenLightName, TimeSpan.FromSeconds(leftGreenSignalDurationSeconds), 4, TimeSpan.FromMilliseconds(500))))
 {
 }
Exemple #9
0
        public void ShouldRevertToSafeStateAfterStateTimerExpires()
        {
            var config = new TrafficLightConfig();

            config.Add(TrafficLightState.Go, 1); //Set to one second

            var light = new TrafficLight {
                Configuration = config, State = TrafficLightState.Go
            };

            Assert.AreEqual(TrafficLightState.Go, light.State);

            Thread.Sleep(7000);    //Wait for fail-safe to kick in

            Assert.AreEqual(TrafficLightState.StopThenGo, light.State);
        }
Exemple #10
0
 public static void Main()
 {
     _timer = new Timer(CheckForConfigurationChanges, null, 0, 10 * 1000);
     while (true)
     {
         _currentConfig = _updatedConfig.Clone();
         if (_currentConfig.MaintenanceMode)
         {
             TurnLightOn(RedLightRelay, 1000 * 1);
             continue;
         }
         TurnLightOn(RedLightRelay, _currentConfig.Red);
         TurnLightOn(GreenLightRelay, _currentConfig.Green);
         TurnLightOn(YellowLightRelay, _currentConfig.Yellow);
     }
 }
Exemple #11
0
        public void ShouldRaiseEventWhenStateExpires()
        {
            var configuration = new TrafficLightConfig();

            configuration.Add(TrafficLightState.Go, 3);

            var light = new TrafficLight
            {
                Name          = "State Expired Test Light",
                Configuration = configuration
            };

            var receivedEvents = new List <TrafficLightStateExpirationEventArgs>();

            light.StateExpirationEvent += (sender, e)
                                          => receivedEvents.Add(e);

            light.State = TrafficLightState.Go;
            Thread.Sleep(4000);

            Assert.AreEqual(1, receivedEvents.Count);
            Assert.AreEqual(light.Id, receivedEvents[0].TrafficLightId);
        }
 public GenericTrafficLightController(TrafficLightConfig config)
 {
     LightControllers = config.Select(lc => new LightController(lc, OnLightStateChanged));
     _cycledLights    = LightControllers.Where(l => l.Config.IncludedInCycle);
 }
Exemple #13
0
 private static void CheckForConfigurationChanges(object state)
 {
     _updatedConfig = TrafficLightConfigService.GetConfiguration();
 }