Esempio n. 1
0
        public async Task <bool> SetHeaterStatus(HeaterStatus heaterStatus)
        {
            bool returnValue = false;

            // ***
            // *** Get the current register
            // ***
            byte register = await this.GetRegister();

            // ***
            // *** Set the bit
            // ***
            register = RegisterConverter.SetBit(register, REGISTER_BIT_HEATER, heaterStatus == HeaterStatus.On);

            // ***
            // *** Write the register
            // ***
            await this.WriteRegister(register);

            // ***
            // *** Check the register
            // ***
            returnValue = (await this.GetHeaterStatus()) == heaterStatus;

            return(returnValue);
        }
        public void TestCase_PwmOff_To_Low_SignalisationSequence()
        {
            FakeInitialStatusForTesting();

            bool IsOn = false;

            TestController.EActivityChanged += (sender, e) =>
            {
                TestStatus = e.Status;
                IsOn       = e.TurnOn;
            };

            for (int i = 1; i <= Settings.SignalCountsForPwmLow; i++)
            {
                MockSignal.Raise(obj => obj.Elapsed += null, new EventArgs() as ElapsedEventArgs);
                MockSignal.Verify(obj => obj.Stop(), Times.Exactly(i));
                MockSignal.Verify(obj => obj.Start(), Times.Exactly(i));

                bool EverySecondTime = (i % 2) == 0;

                if (EverySecondTime)
                {
                    Assert.IsTrue(IsOn);
                }
                else
                {
                    Assert.IsFalse(IsOn);
                }
            }
        }
		public void Heater(HeaterStatus heaterStatusStatus)
		{
			if(heaterStatusStatus==HeaterStatus.On)
				_heaterRelay.Write(SetRelayLogicOn);
			if(heaterStatusStatus==HeaterStatus.Off)
				_heaterRelay.Write(SetRelayLogicOff);
		}
        void SetupTest()
        {
            MockedDelayControllerPause = new Mock <ITimer>();
            MockedToggeling            = new Mock <ITimer>();
            MockControlOn             = new Mock <ITimer>();
            MockControlLow            = new Mock <ITimer>();
            MockControlMiddle         = new Mock <ITimer>();
            MockControlHigh           = new Mock <ITimer>();
            MockSignal                = new Mock <ITimer>();
            MockPwm                   = new Mock <ITimer>();
            MockPause                 = new Mock <ITimer>();
            MockDelayedToggeling      = new Mock <ITimer>();
            MockedHeaterControlTimers = new Mock <ControlTimers>();
            ControlTimers HeaterControlTimers = MockedHeaterControlTimers.Object;

            HeaterControlTimers.TimerOn             = MockControlOn.Object;
            HeaterControlTimers.TimerLow            = MockControlLow.Object;
            HeaterControlTimers.TimerMiddle         = MockControlMiddle.Object;
            HeaterControlTimers.TimerHigh           = MockControlHigh.Object;
            HeaterControlTimers.TimerSignal         = MockSignal.Object;
            HeaterControlTimers.TimerPwm            = MockPwm.Object;
            HeaterControlTimers.TimerPause          = MockPause.Object;
            HeaterControlTimers.TimerToggelingDelay = MockDelayedToggeling.Object;

            TestController = new HeaterControllerPulseWidhtModulation(new HeaterParameters(), HeaterControlTimers);
            TestStatus     = new HeaterStatus();
        }
 void CleanUpTest()
 {
     MockedStartStopController  = null;
     MockedDelayControllerPause = null;
     TestController             = null;
     TestStatus = null;
 }
 void Setup( )
 {
     TestParameters                 = new HeaterParameters();
     TestStatus                     = new HeaterStatus();
     MockedHeaterControlTimers      = new Mock <ControlTimers>();
     MockedBoostingTimer            = new Mock <ITimer>();
     HeaterControlTimers            = MockedHeaterControlTimers.Object;
     HeaterControlTimers.TimerBoost = MockedBoostingTimer.Object;
     TestController                 = new HeaterControllerThermostate(TestParameters, HeaterControlTimers);
 }
        void SetupTest()
        {
            MockedStartStopController  = new Mock <ITimer>();
            MockedDelayControllerPause = new Mock <ITimer>();
            MockedDelayedToggeling     = new Mock <ITimer>();
            ITimer StartStopController = MockedStartStopController.Object;
            ITimer PauseController     = MockedDelayControllerPause.Object;
            ITimer TimerForToggeling   = MockedDelayedToggeling.Object;

            TestController = new HeaterController(new HeaterParameters(), PauseController, TimerForToggeling);
            TestStatus     = new HeaterStatus();
        }
        public void TestCase_Unforce()
        {
            FakeInitialStatusForTesting();

            TestController.EActivityChanged += (sender, e) =>
            {
                TestStatus = e.Status;
            };

            TestController.Force();
            TestController.UnForce();

            Assert.AreEqual(HeaterStatus.ControllerState.ControllerUnforced, TestStatus.ActualControllerState);
        }
        public void TestCase_PwmStartedWithLowParametersIsNowLOW_CheckIfTurnedOff()
        {
            bool IsOn = true;

            TestController.EActivityChanged += (sender, e) =>
            {
                TestStatus = e.Status;
                IsOn       = e.TurnOn;
            };

            MockControlLow.Raise(obj => obj.Elapsed += null, new EventArgs() as ElapsedEventArgs);
            MockPwm.Raise(obj => obj.Elapsed        += null, new EventArgs() as ElapsedEventArgs);

            Assert.IsFalse(IsOn);
        }
        public void TestCase_InitialToggle_StatusCheck()
        {
            bool IsOn = false;

            TestController.EActivityChanged += (sender, e) =>
            {
                TestStatus = e.Status;
                IsOn       = e.TurnOn;
            };

            TestController.Toggle();

            Assert.AreEqual(HeaterStatus.ControllerState.ControllerIsOn, TestStatus.ActualControllerState);
            Assert.AreEqual(HeaterStatus.OperationState.RegularOperation, TestStatus.ActualOperationState);
            Assert.IsTrue(IsOn);
        }
        public void TestCase_Controller_Is_Off_SignalIsHigh()
        {
            bool IsOn = false;

            TestController.EActivityChanged += (sender, e) =>
            {
                TestStatus = e.Status;
                IsOn       = e.TurnOn;
            };

            TestController.Stop();

            TestController.Signal = true;

            Assert.IsFalse(IsOn);
        }
        public void TestCase_Boosting_Pause()
        {
            bool IsOn = false;

            TestController.EActivityChanged += (sender, e) =>
            {
                TestStatus = e.Status;
                IsOn       = e.TurnOn;
            };

            TestController.Start();

            TestController.Pause();

            Assert.IsFalse(IsOn);
        }
        public void TestCase_BoostingElapsed_CheckThermostateSignalHigh()
        {
            bool IsOn = false;

            TestController.EActivityChanged += (sender, e) =>
            {
                TestStatus = e.Status;
                IsOn       = e.TurnOn;
            };

            ThermostateIsNowTurnedOn();

            TestController.Signal = true;

            Assert.IsTrue(IsOn);
        }
        public void TestCase_PwmOff_To_Low_SignalisationStart()
        {
            FakeInitialStatusForTesting();

            bool IsOn = true;

            TestController.EActivityChanged += (sender, e) =>
            {
                TestStatus = e.Status;
                IsOn       = e.TurnOn;
            };


            MockControlLow.Raise(obj => obj.Elapsed += null, new EventArgs() as ElapsedEventArgs);
            MockSignal.Verify(obj => obj.Start());
        }
        public void TestCase_IgnoreForceOn()
        {
            FakeInitialStatusForTesting();

            bool IsOn = false;

            TestController.EActivityChanged += (sender, e) =>
            {
                TestStatus = e.Status;
                IsOn       = e.TurnOn;
            };

            TestController.ForcedOn();

            Assert.IsFalse(IsOn);
        }
Esempio n. 16
0
        /// <summary>
        /// Turns On or Off the internal heating element of the SHT11 IC.
        /// </summary>
        /// <param name="on">A Boolean indicating whether to turn On or Off the on-board heater.</param>
        /// <param name="duration">A Timespan to turn on the on-board heater.</param>
        /// <returns>True is successful, otherwise false.</returns>
        /// <remarks>
        /// The heater may increase the temperature of the sensor by 5 – 10°C beyond ambient temperature.
        /// For example the heater can be helpful for functional analysis: Humidity and temperature readings before and after applying the heater are compared.
        /// Temperature shall increase while relative humidity decreases at the same time. The Dew point shall remain the same.
        /// Caution: The temperature reading will display the temperature of the heated sensor element and not ambient temperature.
        /// Furthermore, the sensor is not qualified for continuous application of the heater. Use with caution.
        /// Therefore, if the duration is not specified, it will default to 15 minutes and automatically turn off the on-board heater.
        /// </remarks>
        /// <example>Example usage:
        /// <code language="C#">
        /// _sht11Click.SetHeater(SHT11Click.HeaterStatus.On, new TimeSpan(0, 0, 0, 15));
        /// </code>
        /// <code language="VB">
        /// _sht11Click.SetHeater(SHT11Click.HeaterStatus.On, new TimeSpan(0, 0, 0, 15))
        /// </code>
        /// </example>
        public bool SetHeater(HeaterStatus on, TimeSpan duration = default(TimeSpan))
        {
            var status = ReadStatusRegister();

            WriteStatusRegister(on == HeaterStatus.On ? Bits.Set(status, 2, true) : Bits.Set(status, 2, false));

            if (on == HeaterStatus.On)
            {
                _timer.Change(duration == default(TimeSpan) ? new TimeSpan(0, 15, 0) : duration, duration == default(TimeSpan) ? new TimeSpan(0, 15, 0) : duration); //Default is 15 minutes.
            }
            else
            {
                _timer.Change(-1, -1); // Change the Timer due time and period.
            }

            return(IsBitSet(ReadStatusRegister(), 2));
        }
        public void TestCase_ToggleStartStop_StatusCheck()
        {
            bool IsOn = false;

            TestController.EActivityChanged += (sender, e) =>
            {
                TestStatus = e.Status;
                IsOn       = e.TurnOn;
            };

            TestController.Toggle(); // start
            TestController.Toggle(); // stop

            Assert.AreEqual(HeaterStatus.ControllerState.ControllerIsOff, TestStatus.ActualControllerState);
            Assert.AreEqual(HeaterStatus.OperationState.Idle, TestStatus.ActualOperationState);
            Assert.IsFalse(IsOn);
        }
        public void TestCase_HeaterIsExpectingPause_AfterStarted_StatusCheck()
        {
            bool IsOn = false;

            TestController.EActivityChanged += (sender, e) =>
            {
                TestStatus = e.Status;
                IsOn       = e.TurnOn;
            };

            TestController.Start();
            TestController.DelayedPause();

            Assert.AreEqual(HeaterStatus.ControllerState.ControllerIsExpectingPause, TestStatus.ActualControllerState);
            Assert.AreEqual(HeaterStatus.OperationState.RegularOperation, TestStatus.ActualOperationState);
            Assert.IsTrue(IsOn);
        }
        public void TestCase_Controller_Is_Pause_SignalIsHigh()
        {
            bool IsOn = false;

            TestController.EActivityChanged += (sender, e) =>
            {
                TestStatus = e.Status;
                IsOn       = e.TurnOn;
            };

            ThermostateIsNowTurnedOn();

            TestController.Pause();

            TestController.Signal = true;

            Assert.IsFalse(IsOn);
        }
        public void TestCase_ForceHeaterOff_IgnorePauseResume()
        {
            FakeInitialStatusForTesting();

            bool IsOn = false;

            TestController.EActivityChanged += (sender, e) =>
            {
                TestStatus = e.Status;
                IsOn       = e.TurnOn;
            };

            TestController.Pause();  //  ignore
            TestController.Force();
            TestController.Resume(); //  ignore

            Assert.IsFalse(IsOn);
        }
        public void TestCase_HeaterIsOn_StatusCheck()
        {
            bool IsOn = false;

            TestController.EActivityChanged += (sender, e) =>
            {
                TestStatus = e.Status;
                IsOn       = e.TurnOn;
            };

            TestController.Start();

            Assert.AreEqual(HeaterStatus.ControllerState.ControllerIsOn, TestStatus.ActualControllerState);
            Assert.AreEqual(HeaterStatus.OperationState.RegularOperation, TestStatus.ActualOperationState);
            Assert.AreEqual(HeaterStatus.InformationAction.Finished, TestStatus.ActualActionInfo);

            Assert.IsTrue(IsOn);
        }
        public void TestCase_Pwm_Off_StatusCheck()
        {
            FakeInitialStatusForTesting();

            bool IsOn = true;

            TestController.EActivityChanged += (sender, e) =>
            {
                TestStatus = e.Status;
                IsOn       = e.TurnOn;
            };

            TestController.Start();

            HeaterStatus ReturnedTestedStatus = TestController.GetStatus();

            Assert.AreEqual(HeaterStatus.ControllerState.ControllerIsOff, ReturnedTestedStatus.ActualControllerState);
            Assert.AreEqual(HeaterStatus.OperationState.Idle, ReturnedTestedStatus.ActualOperationState);
        }
        public void TestCase_InitialToggleWithDelayTimeTurningOff_StatusCheck()
        {
            bool IsOn = false;

            HeaterStatus TestStatus = new HeaterStatus();

            TestController.EActivityChanged += (sender, e) =>
            {
                TestStatus = e.Status;
                IsOn       = e.TurnOn;
            };

            TestStatus.ActualControllerState = HeaterStatus.ControllerState.ControllerIsOn;

            TestController.SetStatus(TestStatus);

            TestController.DelayedToggle();

            Assert.AreEqual(HeaterStatus.InformationAction.TurningOff, TestStatus.ActualActionInfo);
        }
        public void TestCase_Off_Unforce_WithTurningOn()
        {
            FakeInitialStatusForTesting();

            bool IsOn = false;

            TestController.EActivityChanged += (sender, e) =>
            {
                TestStatus = e.Status;
                IsOn       = e.TurnOn;
            };

            TestController.Force();
            TestController.Start();//  ignore

            TestController.UnForce();
            TestController.Start();//  ignore

            Assert.IsTrue(IsOn);
        }
Esempio n. 25
0
        public async Task <HeaterStatus> GetHeaterStatus()
        {
            HeaterStatus returnValue = HeaterStatus.Off;

            // ***
            // *** Get the current register
            // ***
            byte register = await this.GetRegister();

            if (RegisterConverter.BitIsHigh(register, REGISTER_BIT_HEATER))
            {
                returnValue = HeaterStatus.On;
            }
            else
            {
                returnValue = HeaterStatus.Off;
            }

            return(returnValue);
        }
        public void TestCase_PwmStartedWithLowParametersIsNowHIGH_CheckIfTurnedOn()
        {
            bool IsOn = false;

            TestController.EActivityChanged += (sender, e) =>
            {
                TestStatus = e.Status;
                IsOn       = e.TurnOn;
            };

            MockControlLow.Raise(obj => obj.Elapsed += null, new EventArgs() as ElapsedEventArgs);
            MockPwm.Raise(obj => obj.Elapsed        += null, new EventArgs() as ElapsedEventArgs);
            // check alternating turn on/off
            Assert.IsFalse(IsOn);
            MockPwm.Raise(obj => obj.Elapsed += null, new EventArgs() as ElapsedEventArgs);
            Assert.IsTrue(IsOn);
            MockPwm.Raise(obj => obj.Elapsed += null, new EventArgs() as ElapsedEventArgs);
            Assert.IsFalse(IsOn);
            MockPwm.Raise(obj => obj.Elapsed += null, new EventArgs() as ElapsedEventArgs);
            Assert.IsTrue(IsOn);
        }
        public void TestCase_InitialToggleWithDelayTimeElapsed_StatusCheck()
        {
            bool IsOn = false;

            TestController.EActivityChanged += (sender, e) =>
            {
                TestStatus = e.Status;
                IsOn       = e.TurnOn;
            };

            TestController.DelayedToggle();

            MockedDelayedToggeling.Verify(obj => obj.SetTime(new HeaterParameters().CmdDurationForTurningStartingStopping));
            MockedDelayedToggeling.Verify(obj => obj.Start());
            MockedDelayedToggeling.Verify(obj => obj.Stop());
            MockedDelayedToggeling.Raise(obj => obj.Elapsed += null, new EventArgs() as ElapsedEventArgs);

            Assert.AreEqual(HeaterStatus.ControllerState.ControllerIsOn, TestStatus.ActualControllerState);
            Assert.AreEqual(HeaterStatus.OperationState.RegularOperation, TestStatus.ActualOperationState);
            Assert.IsTrue(IsOn);
        }
        public void TestCase_PwmOff_To_Low_InitialSignalisation()
        {
            FakeInitialStatusForTesting();

            bool IsOn = true;

            TestController.EActivityChanged += (sender, e) =>
            {
                TestStatus = e.Status;
                IsOn       = e.TurnOn;
            };

            TestController.Start();

            MakeAndVerifyControllerPwmLow();
            MakeAndVerifyControllerTimer(MockSignal, new HeaterParameters().SignalDurationSignalisation);

            HeaterStatus ReturnedTestedStatus = TestController.GetStatus();

            Assert.IsFalse(IsOn);
        }
        public void TestCase_StartThermostateWithBoosting()
        {
            bool IsOn = false;

            TestController.EActivityChanged += (sender, e) =>
            {
                TestStatus = e.Status;
                IsOn       = e.TurnOn;
            };

            TestController.Start();


            HeaterStatus ReturnedTestedStatus = TestController.GetStatus();

            Assert.AreEqual(HeaterStatus.ControllerState.ControllerIsOn, ReturnedTestedStatus.ActualControllerState);
            Assert.AreEqual(HeaterStatus.OperationState.Boosting, ReturnedTestedStatus.ActualOperationState);
            Assert.AreEqual(HeaterStatus.InformationAction.InProcess, ReturnedTestedStatus.ActualActionInfo);
            MockedBoostingTimer.Verify(obj => obj.SetTime(TestParameters.SignalDurationBoosting));
            MockedBoostingTimer.Verify(obj => obj.Start(), Times.AtLeastOnce());
            Assert.IsTrue(IsOn);
        }
        public void TestCase_BoostingElapsed_SignalHigh_Pause_SignalLow_Resume()
        {
            bool IsOn = false;

            TestController.EActivityChanged += (sender, e) =>
            {
                TestStatus = e.Status;
                IsOn       = e.TurnOn;
            };

            ThermostateIsNowTurnedOn();     // EXAMPLE: Heater was turned on via button

            TestController.Signal = true;   // EXAMPLE: Thermostate signal is ON

            TestController.Pause();         // EXAMPLE: Somebody opens the window

            TestController.Signal = false;  // EXAMPLE: Thermostate signal gets OFF

            TestController.Resume();        // EXAMPLE: Somebody closes the windown

            Assert.IsFalse(IsOn);           // EXAMPLE: Signal for heater is OFF
        }
        public void TestCase_PwmOff_To_On_StatusCheck()
        {
            FakeInitialStatusForTesting();

            bool IsOn = true;

            TestController.EActivityChanged += (sender, e) =>
            {
                TestStatus = e.Status;
                IsOn       = e.TurnOn;
            };

            TestController.Start();

            MakeAndVerifyControllerOn();

            HeaterStatus ReturnedTestedStatus = TestController.GetStatus();

            Assert.AreEqual(HeaterStatus.ControllerState.ControllerIsOn, ReturnedTestedStatus.ActualControllerState);
            Assert.AreEqual(HeaterStatus.OperationState.RegularOperation, ReturnedTestedStatus.ActualOperationState);
            Assert.AreEqual(HeaterStatus.InformationAction.ItensityChanging, ReturnedTestedStatus.ActualActionInfo);
            Assert.IsTrue(IsOn);
        }
Esempio n. 32
0
		public async Task<bool> SetHeaterStatus(HeaterStatus heaterStatus)
		{
			bool returnValue = false;

			// ***
			// *** Get the current register
			// ***
			byte register = await this.GetRegister();

			// ***
			// *** Set the bit
			// ***
			register = RegisterConverter.SetBit(register, REGISTER_BIT_HEATER, heaterStatus == HeaterStatus.On);

			// ***
			// *** Write the register
			// ***
			await this.WriteRegister(register);

			// ***
			// *** Check the register
			// ***
			returnValue = (await this.GetHeaterStatus()) == heaterStatus;

			return returnValue;
		}