using InnovEnergy.Lib.Devices.Trumpf.TruConvertAc.DataTypes; using InnovEnergy.Lib.Units.Composite; using InnovEnergy.Lib.Utils; namespace InnovEnergy.Lib.Devices.Trumpf.TruConvertAc.Control; public class AcPowerControl { public AcPower L1 { get { var s = _Self.PowerSetpointL1; var cosPhi = _Self.CosPhiSetpointL1.Clamp(-1, 1); var rpk = _Self.ReactivePowerKindL1; var phi = cosPhi.Apply(Math.Acos) * (rpk == ReactivePowerKind.Inductive ? 1 : -1); var sinPhi = Math.Sin(phi); return AcPower.FromActiveReactive(s * cosPhi, s * sinPhi); } set { _Self.PowerSetpointL1 = value.Apparent.Value; _Self.CosPhiSetpointL1 = value.CosPhi; _Self.SinPhiSetpointL1 = Math.Sin(value.Phi); _Self.ReactivePowerKindL1 = value.Reactive >= 0 ? ReactivePowerKind.Inductive : ReactivePowerKind.Capacitive; } } public AcPower L2 { get { var s = _Self.PowerSetpointL2; var cosPhi = _Self.CosPhiSetpointL2.Clamp(-1, 1); var rpk = _Self.ReactivePowerKindL2; var phi = cosPhi.Apply(Math.Acos) * (rpk == ReactivePowerKind.Inductive ? 1 : -1); var sinPhi = Math.Sin(phi); return AcPower.FromActiveReactive(s * cosPhi, s * sinPhi); } set { _Self.PowerSetpointL2 = value.Apparent.Value; _Self.CosPhiSetpointL2 = value.CosPhi; _Self.SinPhiSetpointL2 = Math.Sin(value.Phi); _Self.ReactivePowerKindL2 = value.Reactive >= 0 ? ReactivePowerKind.Inductive : ReactivePowerKind.Capacitive; } } public AcPower L3 { get { var s = _Self.PowerSetpointL3; var cosPhi = _Self.CosPhiSetpointL3.Clamp(-1, 1); var rpk = _Self.ReactivePowerKindL3; var phi = cosPhi.Apply(Math.Acos) * (rpk == ReactivePowerKind.Inductive ? 1 : -1); var sinPhi = Math.Sin(phi); return AcPower.FromActiveReactive(s * cosPhi, s * sinPhi); } set { _Self.PowerSetpointL3 = value.Apparent.Value; _Self.CosPhiSetpointL3 = value.CosPhi; _Self.SinPhiSetpointL3 = Math.Sin(value.Phi); _Self.ReactivePowerKindL3 = value.Reactive >= 0 ? ReactivePowerKind.Inductive : ReactivePowerKind.Capacitive; } } internal AcPowerControl(AcDcRecord self) => _Self = self; private readonly AcDcRecord _Self; // public IEnumerator GetEnumerator() // { // yield return L1; // yield return L2; // yield return L3; // } // // IEnumerator IEnumerable.GetEnumerator() // { // return GetEnumerator(); // } }