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); }
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); }
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)); }
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); }
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); }
/// <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; } } }
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); }
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); }
/// <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); } }
/// <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); }
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)); }
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); }
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()); }
/// <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; } } }
internal void Compose(IAnalog analog, double cutoff) { this.Cutoff = cutoff; this.PolynomialCoefficients = this.iirProvider.GetIirCoefficients(analog, cutoff); }
public IPolynomialCoefficients GetIirCoefficients(IAnalog analog, double cutoff) { var digitialPoles = this.digitalPolesProvider.GetDigitalPoles(analog, cutoff, 2.0d); return(this.polynomialTransformer.Transform(digitialPoles)); }