public DeviceAnalog(Analog a)
 {
     log.DebugFormat("DeviceAnalog()");
     dataAnalog     = a;
     hardwareAnalog = new SPIAnalog(a.Id, a.Name, a.Multiplier, a.Units, a.Address);
     log.DebugFormat("DeviceAnalog() {0}", a.Name);
 }
示例#2
0
        internal void GetIirCoefficients_CorrectlyCallsTheDigitalPolesProvider_Test(
            [Frozen] Mock <IDigitalPolesProvider> digitialPolesProvider, IAnalog analog,
            double cutoff, IirProvider iirProvider)
        {
            iirProvider.GetIirCoefficients(analog, cutoff);

            digitialPolesProvider.Verify(mock => mock.GetDigitalPoles(analog, cutoff, 2.0d), Times.Once);
        }
示例#3
0
        public IPolesCoefficients GetDigitalPoles(IAnalog analog, double cutoff, double sampleRate)
        {
            var warped = sampleRate * 2.0d * Tan
                             (PI * cutoff / sampleRate);

            var transformedPoles = this.transformer.Transform(analog, warped);

            return(this.digitalTransformer.Transform(transformedPoles, sampleRate * 2.0d));
        }
示例#4
0
        public IPolesCoefficients Transform(IAnalog analog, double cutoff)
        {
            var degree = analog.Coefficients.P.Count - analog.Coefficients.Z.Count;

            var zLp = analog.Coefficients.Z.Multiply(cutoff).ToList();
            var pLp = analog.Coefficients.P.Multiply(cutoff).ToList();
            var kLp = analog.Coefficients.K * Math.Pow(cutoff, degree);

            return(this.polesCoefficientsFactory.Build(kLp, pLp, zLp));
        }
        internal void GetDigitalPoles_CorrectlyCallsTheTransformer_Test(
            [Frozen] Mock <ITransformer> transformer, IAnalog analog, double cutoff,
            double sampleRate, DigitalPolesProvider digitalPolesProvider)
        {
            var expectedCutoff = sampleRate * 2.0d * Math.Tan(Math.PI * cutoff / sampleRate);

            digitalPolesProvider.GetDigitalPoles(analog, cutoff, sampleRate);

            transformer.Verify(mock => mock.Transform(analog, expectedCutoff), Times.Once);
        }
示例#6
0
        internal void GetIirCoefficients_CorrectlyCallsThePolynomialTransformer_Test(
            [Frozen] Mock <IDigitalPolesProvider> digitialPolesProvider,
            [Frozen] Mock <IPolynomialTransformer> polynomialTransformer, IPolesCoefficients polesCoefficients,
            IAnalog analog, double cutoff, IirProvider iirProvider)
        {
            digitialPolesProvider.Setup(mock => mock.GetDigitalPoles(analog, cutoff, 2.0d)).Returns(polesCoefficients);

            iirProvider.GetIirCoefficients(analog, cutoff);

            polynomialTransformer.Verify(mock => mock.Transform(polesCoefficients), Times.Once);
        }
        internal void GetDigitalPoles_ReturnsTheResultsOfTheDigitalTransformer_Test(
            [Frozen] Mock <ITransformer> transformer, [Frozen] Mock <IDigitalTransformer> digitalTransformer,
            IPolesCoefficients transformedCoefficients, IPolesCoefficients expectedCoefficients,
            IAnalog analog, double cutoff, double sampleRate, DigitalPolesProvider digitalPolesProvider)
        {
            transformer.Setup(mock => mock.Transform(analog, It.IsAny <double>())).Returns(transformedCoefficients);
            digitalTransformer.Setup(mock => mock.Transform(transformedCoefficients, It.IsAny <double>()))
            .Returns(expectedCoefficients);

            Assert.Equal(expectedCoefficients, digitalPolesProvider.GetDigitalPoles(analog, cutoff, sampleRate));
        }
        internal void GetDigitalPoles_CorrectlyCallsTheDigitalTransformer_Test(
            [Frozen] Mock <ITransformer> transformer, [Frozen] Mock <IDigitalTransformer> digitalTransformer,
            IPolesCoefficients polesCoefficients, IAnalog analog, double cutoff, double sampleRate,
            DigitalPolesProvider digitalPolesProvider)
        {
            transformer.Setup(mock => mock.Transform(analog, It.IsAny <double>())).Returns(polesCoefficients);

            digitalPolesProvider.GetDigitalPoles(analog, cutoff, sampleRate);

            digitalTransformer.Verify(mock => mock.Transform(polesCoefficients, sampleRate * 2.0d), Times.Once);
        }
示例#9
0
 /// <summary>
 /// Adds the given element to the collection
 /// </summary>
 /// <param name="item">The item to add</param>
 public override void Add(IModelElement item)
 {
     if ((this._parent.Analog == null))
     {
         IAnalog analogCasted = item.As <IAnalog>();
         if ((analogCasted != null))
         {
             this._parent.Analog = analogCasted;
             return;
         }
     }
 }
示例#10
0
        internal void GetIirCoefficients_CorrectlyReturnsTheValueOfThePolynomialTransformer_Test(
            [Frozen] Mock <IDigitalPolesProvider> digitialPolesProvider,
            [Frozen] Mock <IPolynomialTransformer> polynomialTransformer, IPolesCoefficients polesCoefficients,
            IPolynomialCoefficients polynomialCoefficients, IAnalog analog, double cutoff,
            IirProvider iirProvider)
        {
            digitialPolesProvider.Setup(mock => mock.GetDigitalPoles(analog, cutoff, 2.0d)).Returns(polesCoefficients);
            polynomialTransformer.Setup(mock => mock.Transform(polesCoefficients)).Returns(polynomialCoefficients);

            var actual = iirProvider.GetIirCoefficients(analog, cutoff);

            Assert.Equal(polynomialCoefficients, actual);
        }
示例#11
0
        internal void Transform_ReturnsTheResultOfThePolesFactory_Test(
            [Frozen] Mock <IPolesCoefficientsFactory> polesCoefficientsFactory, IAnalog analog,
            double cutoff, IPolesCoefficients expected, LowPassTransformer lowPassTransformer)
        {
            polesCoefficientsFactory.Setup(
                mock =>
                mock.Build(It.IsAny <double>(), It.IsAny <IReadOnlyList <Complex> >(),
                           It.IsAny <IReadOnlyList <Complex> >())).Returns(expected);

            var actual = lowPassTransformer.Transform(analog, cutoff);

            Assert.Equal(expected, actual);
        }
示例#12
0
            /// <summary>
            /// Adds the given element to the collection
            /// </summary>
            /// <param name="item">The item to add</param>
            public override void Add(IModelElement item)
            {
                IAnalog measurementsCasted = item.As <IAnalog>();

                if ((measurementsCasted != null))
                {
                    this._parent.Measurements.Add(measurementsCasted);
                }
                IAnalogLimit limitsCasted = item.As <IAnalogLimit>();

                if ((limitsCasted != null))
                {
                    this._parent.Limits.Add(limitsCasted);
                }
            }
示例#13
0
            /// <summary>
            /// Removes the given item from the collection
            /// </summary>
            /// <returns>True, if the item was removed, otherwise False</returns>
            /// <param name="item">The item that should be removed</param>
            public override bool Remove(IModelElement item)
            {
                IAnalog analogItem = item.As <IAnalog>();

                if (((analogItem != null) &&
                     this._parent.Measurements.Remove(analogItem)))
                {
                    return(true);
                }
                IAnalogLimit analogLimitItem = item.As <IAnalogLimit>();

                if (((analogLimitItem != null) &&
                     this._parent.Limits.Remove(analogLimitItem)))
                {
                    return(true);
                }
                return(false);
            }
示例#14
0
        public IPolesCoefficients Transform(IAnalog analog, double cutoff)
        {
            var degree = analog.Coefficients.P.Count - analog.Coefficients.Z.Count;

            var zHp = analog.Coefficients.Z.RhsDivide(cutoff);
            var pHp = analog.Coefficients.P.RhsDivide(cutoff);

            var z = new List <Complex>(zHp);

            for (var i = 0; i < degree; i++)
            {
                z.Add(0.0d);
            }

            var kHp = analog.Coefficients.K *
                      (analog.Coefficients.Z.Negative().Product() / analog.Coefficients.P.Negative().Product());

            return(this.polesCoefficientsFactory.Build(kHp.Real, pHp.ToList(), z));
        }
示例#15
0
        private void Analog_ValueChanged(object sender, AnalogValueChangedEventArgs e)
        {
            IAnalog analog = sender as IAnalog;

            foreach (AnalogTuple at in Analogs)
            {
                if (at.Hardware.Name == analog.Name)
                {
                    at.Data.RawValue = analog.RawValue;
                    at.Data.Value    = analog.Value;
                    dataServer.PutAnalog(at.Data);
                }
            }
            string s = string.Format("Analog '{0}' {1} {2}", analog.Name, e.Value, analog.Units);

            log.Debug(s);
            CreateEvent(EventTypes.IO, s);
            //dataServer.PutAnalog(analog.Data);
        }
示例#16
0
        protected void LoadAnalogs()
        {
            log.InfoFormat("LoadAnalogs()");
            Analogs.Clear();
            log.Debug("Debug 1");
            List <Analog> analogs = dataServer.GetAnalogs(device.Id);

            foreach (Analog a in analogs)
            {
                IAnalog analog = CreateAnalog(a);
                log.InfoFormat("Registering ValueChanged on {0}", a.Name);
                analog.ValueChanged += Analog_ValueChanged;
                Analogs.Add(new AnalogTuple {
                    Data = a, Hardware = analog
                });
                //log.Info(analog.Report());
            }
            log.DebugFormat("{0} Analogs configured", Analogs.Count());
        }
示例#17
0
            /// <summary>
            /// Adds the given element to the collection
            /// </summary>
            /// <param name="item">The item to add</param>
            public override void Add(IModelElement item)
            {
                IAltGeneratingUnitMeas altGeneratingUnitCasted = item.As <IAltGeneratingUnitMeas>();

                if ((altGeneratingUnitCasted != null))
                {
                    this._parent.AltGeneratingUnit.Add(altGeneratingUnitCasted);
                }
                IAltTieMeas altTieMeasCasted = item.As <IAltTieMeas>();

                if ((altTieMeasCasted != null))
                {
                    this._parent.AltTieMeas.Add(altTieMeasCasted);
                }
                if ((this._parent.Analog == null))
                {
                    IAnalog analogCasted = item.As <IAnalog>();
                    if ((analogCasted != null))
                    {
                        this._parent.Analog = analogCasted;
                        return;
                    }
                }
            }
示例#18
0
 internal void Compose(IAnalog analog, double cutoff)
 {
     this.Cutoff = cutoff;
     this.PolynomialCoefficients = this.iirProvider.GetIirCoefficients(analog, cutoff);
 }
示例#19
0
        public IPolynomialCoefficients GetIirCoefficients(IAnalog analog, double cutoff)
        {
            var digitialPoles = this.digitalPolesProvider.GetDigitalPoles(analog, cutoff, 2.0d);

            return(this.polynomialTransformer.Transform(digitialPoles));
        }