introduce AcDcDevicesRecord.Null

This commit is contained in:
ig 2023-06-20 09:49:17 +02:00
parent cc554c1964
commit 5f54dd602f
1 changed files with 24 additions and 12 deletions

View File

@ -1,15 +1,12 @@
using InnovEnergy.Lib.Devices.Trumpf.SystemControl;
using InnovEnergy.Lib.Devices.Trumpf.TruConvertAc.DataTypes;
using InnovEnergy.Lib.StatusApi.DeviceTypes;
using InnovEnergy.Lib.Units.Composite;
namespace InnovEnergy.Lib.Devices.Trumpf.TruConvertAc;
public class AcDcDevicesRecord : IAcDc3
public class AcDcDevicesRecord
{
// private static readonly AcPhase NoAcPhase = Ac3Bus.FromPhasesAndFrequency()
// private static readonly Ac3Bus NoAcDevice = Ac3Bus.FromPhasesAndFrequency()
public static AcDcDevicesRecord Null { get; } = new AcDcDevicesRecord(null, Array.Empty<AcDcRecord>());
public AcDcDevicesRecord(SystemControlRegisters? systemControl, IReadOnlyList<AcDcRecord> devices)
{
@ -60,11 +57,26 @@ public class AcDcDevicesRecord : IAcDc3
}
}
public DcBus Dc => Devices.Count == 0
? DcBus.Null
: DcBus.FromVoltageCurrent
public DcBus Dc
{
get
{
if (Devices.Count == 0)
return DcBus.Null;
var u = Devices
.Select(d => d.Status.DcVoltages.Extern)
.Select(vs => vs.LowerHalf + vs.UpperHalf)
.Average();
var p = Ac.Power.Active.Value;
var i = u == 0 ? 0 : p / u;
return DcBus.FromVoltageCurrent
(
voltage: Devices.Average(d => d.Status.Dc.Voltage),
current: Devices.Sum(d => d.Status.Dc.Current)
voltage: u,
current: i
);
}
}
}