"normalize" DcBus

This commit is contained in:
ig 2023-08-31 14:16:09 +02:00
parent 6c2360f0ad
commit be452d190c
12 changed files with 85 additions and 68 deletions

View File

@ -62,7 +62,11 @@ public class AmptDevices
var busVoltage = nStringOptimizers == 0 ? 0 : soStati.Average(r => r.Voltage); var busVoltage = nStringOptimizers == 0 ? 0 : soStati.Average(r => r.Voltage);
var busCurrent = nStringOptimizers == 0 ? 0 : soStati.Sum (r => r.Current); var busCurrent = nStringOptimizers == 0 ? 0 : soStati.Sum (r => r.Current);
var dc = DcBus.FromVoltageCurrent(busVoltage, busCurrent); var dc = new DcBus
{
Voltage = busVoltage,
Current = busCurrent,
};
// flatten the 2 strings of each SO into one array // flatten the 2 strings of each SO into one array
var strings = soStati.SelectMany(GetStrings).ToArray(nStrings); var strings = soStati.SelectMany(GetStrings).ToArray(nStrings);
@ -80,8 +84,16 @@ public class AmptDevices
{ {
// hardcoded: every SO has 2 strings (produced like this by AMPT) // hardcoded: every SO has 2 strings (produced like this by AMPT)
yield return DcBus.FromVoltageCurrent(r.String1Voltage, r.String1Current); yield return new()
yield return DcBus.FromVoltageCurrent(r.String2Voltage, r.String2Current); {
Voltage = r.String1Voltage,
Current = r.String1Current,
};
yield return new()
{
Voltage = r.String2Voltage,
Current = r.String2Current,
};
} }

View File

@ -35,11 +35,11 @@ public class Battery48TlRecords
HeatingPower = records.Sum(b => b.HeatingPower), HeatingPower = records.Sum(b => b.HeatingPower),
TimeToToc = records.Min(r => r.TimeToTOC), TimeToToc = records.Min(r => r.TimeToTOC),
Dc = DcBus.FromVoltageCurrent Dc = new()
( {
records.Average(r => r.Dc.Voltage), Voltage = records.Average(r => r.Dc.Voltage),
records.Sum(r => r.Dc.Current) Current = records.Sum(r => r.Dc.Current),
) }
}; };
} }

View File

@ -72,11 +72,11 @@ public class AcDcDevicesRecord
var p = Ac.Power.Active.Value; var p = Ac.Power.Active.Value;
var i = u == 0 ? 0 : p / u; var i = u == 0 ? 0 : p / u;
return DcBus.FromVoltageCurrent return new()
( {
voltage: u, Voltage = u,
current: i Current = i,
); };
} }
} }
} }

View File

@ -6,7 +6,11 @@ namespace InnovEnergy.Lib.Devices.Trumpf.TruConvertDc;
public class DcDcDevicesRecord public class DcDcDevicesRecord
{ {
private static readonly DcBus NoDevice = DcBus.FromVoltageCurrent(0, 0); private static readonly DcBus NoDevice = new()
{
Voltage = 0,
Current = 0,
};
public DcDcDevicesRecord(SystemControlRegisters? systemControl, IReadOnlyList<DcDcRecord> devices) public DcDcDevicesRecord(SystemControlRegisters? systemControl, IReadOnlyList<DcDcRecord> devices)
{ {
@ -14,15 +18,15 @@ public class DcDcDevicesRecord
Devices = devices; Devices = devices;
} }
public DcStatus Dc => new DcStatus public DcStatus Dc => new()
{ {
Battery = Devices.Count == 0 Battery = Devices.Count == 0
? NoDevice ? NoDevice
: DcBus.FromVoltageCurrent : new()
( {
Devices.Average(r => r.Status.Dc.Battery.Voltage.Value), Voltage = Devices.Average(r => r.Status.Dc.Battery.Voltage.Value),
Devices.Sum(r => r.Status.Dc.Battery.Current.Value) Current = Devices.Sum(r => r.Status.Dc.Battery.Current.Value),
), },
Link = Devices.Count == 0 Link = Devices.Count == 0
? NoDevice ? NoDevice

View File

@ -24,16 +24,16 @@ public class DcDcStatus
return new() return new()
{ {
Link = DcBus.FromVoltageCurrent Link = new()
( {
voltage: _Self.DcLinkVoltage, Voltage = _Self.DcLinkVoltage,
current: -linkCurrent // TODO: review sign is reversed Current = -linkCurrent,
), },
Battery = DcBus.FromVoltageCurrent Battery = new()
( {
voltage: _Self.BatteryVoltage, Voltage = _Self.BatteryVoltage,
current: -batteryCurrent // TODO: review sign is reversed Current = -batteryCurrent,
) }
}; };
} }
} }

View File

@ -1,5 +1,4 @@
using InnovEnergy.Lib.StatusApi.Connections; using InnovEnergy.Lib.StatusApi.Connections;
using InnovEnergy.Lib.Units.Composite;
namespace InnovEnergy.Lib.StatusApi.DeviceTypes; namespace InnovEnergy.Lib.StatusApi.DeviceTypes;

View File

@ -1,6 +1,5 @@
using InnovEnergy.Lib.StatusApi.Connections; using InnovEnergy.Lib.StatusApi.Connections;
using InnovEnergy.Lib.Units; using InnovEnergy.Lib.Units;
using InnovEnergy.Lib.Units.Composite;
namespace InnovEnergy.Lib.StatusApi.DeviceTypes; namespace InnovEnergy.Lib.StatusApi.DeviceTypes;

View File

@ -0,0 +1,7 @@
using InnovEnergy.Lib.StatusApi.Connections;
namespace InnovEnergy.Lib.StatusApi.DeviceTypes;
public interface IDcMeter : IDcConnection
{
}

View File

@ -2,9 +2,6 @@ namespace InnovEnergy.Lib.Units.Composite;
public sealed class Ac1Bus public sealed class Ac1Bus
{ {
private Ac1Bus()
{}
public required Voltage Voltage { get; init; } public required Voltage Voltage { get; init; }
public required Current Current { get; init; } public required Current Current { get; init; }
public required AcPower Power { get; init; } public required AcPower Power { get; init; }

View File

@ -6,6 +6,8 @@ namespace InnovEnergy.Lib.Units.Composite;
public sealed class AcPower public sealed class AcPower
{ {
private AcPower(){}
public required ApparentPower Apparent { get; init; } public required ApparentPower Apparent { get; init; }
public required ActivePower Active { get; init; } public required ActivePower Active { get; init; }
public required ReactivePower Reactive { get; init; } public required ReactivePower Reactive { get; init; }
@ -82,28 +84,23 @@ public sealed class AcPower
}; };
} }
public static AcPower operator +(AcPower left, AcPower right) public static AcPower operator +(AcPower left, AcPower right) => FromActiveReactive
{
return FromActiveReactive
( (
left.Active + right.Active, left.Active + right.Active,
left.Reactive + right.Reactive left.Reactive + right.Reactive
); );
}
public static AcPower operator -(AcPower left, AcPower right) public static AcPower operator -(AcPower left, AcPower right) => FromActiveReactive
{ (
return left + -right; left.Active - right.Active,
} left.Reactive - right.Reactive
);
public static AcPower operator -(AcPower p) public static AcPower operator -(AcPower p) => FromActiveReactive
{
return FromActiveReactive
( (
-p.Active, -p.Active,
-p.Reactive -p.Reactive
); );
}
public static implicit operator AcPower(Double p) => FromActiveReactive(p, 0); public static implicit operator AcPower(Double p) => FromActiveReactive(p, 0);

View File

@ -4,18 +4,20 @@ namespace InnovEnergy.Lib.Units.Composite;
public sealed class DcBus public sealed class DcBus
{ {
private DcBus() {}
public required Voltage Voltage { get; init; } public required Voltage Voltage { get; init; }
public required Current Current { get; init; } public required Current Current { get; init; }
public required DcPower Power { get; init; }
public DcPower Power => Voltage * Current;
public static DcBus FromVoltageCurrent(Voltage voltage, Current current) => new() public static DcBus FromVoltageCurrent(Voltage voltage, Current current) => new()
{ {
Voltage = voltage, Voltage = voltage,
Current = current, Current = current,
Power = current.Value * voltage.Value,
}; };
public static DcBus Null => FromVoltageCurrent(0, 0); public static DcBus Null => new()
{
Voltage = 0,
Current = 0,
};
} }