2023-06-13 11:01:01 +00:00
|
|
|
using InnovEnergy.Lib.Units;
|
|
|
|
using InnovEnergy.Lib.Units.Composite;
|
|
|
|
using InnovEnergy.Lib.Utils;
|
|
|
|
|
|
|
|
namespace InnovEnergy.Lib.Devices.Trumpf.TruConvertDc.Status;
|
|
|
|
|
|
|
|
public class DcDcStatus
|
|
|
|
{
|
|
|
|
public DcStatus Dc
|
|
|
|
{
|
|
|
|
get
|
|
|
|
{
|
|
|
|
// if battery voltage is 0, Trumpf reports a nonsensical battery current
|
|
|
|
|
|
|
|
var batteryCurrent = _Self.BatteryVoltage == 0
|
|
|
|
? 0
|
|
|
|
: _Self.BatteryCurrent;
|
|
|
|
|
|
|
|
// link current is not measured by trumpf, calculate it assuming 0 losses
|
|
|
|
// TODO: calculate losses
|
|
|
|
var linkCurrent = batteryCurrent == 0
|
|
|
|
? 0
|
|
|
|
: _Self.BatteryVoltage * _Self.BatteryCurrent / _Self.DcLinkVoltage;
|
|
|
|
|
|
|
|
return new()
|
|
|
|
{
|
|
|
|
Link = DcBus.FromVoltageCurrent
|
|
|
|
(
|
|
|
|
voltage: _Self.DcLinkVoltage,
|
2023-06-22 08:15:57 +00:00
|
|
|
current: -linkCurrent // TODO: review sign is reversed
|
2023-06-13 11:01:01 +00:00
|
|
|
),
|
|
|
|
Battery = DcBus.FromVoltageCurrent
|
|
|
|
(
|
2023-06-22 08:15:57 +00:00
|
|
|
voltage: _Self.BatteryVoltage,
|
|
|
|
current: -batteryCurrent // TODO: review sign is reversed
|
|
|
|
)
|
2023-06-13 11:01:01 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public Percent OverloadCapacity => _Self.OverloadCapacity;
|
|
|
|
public Temperatures Temperature => new(_Self);
|
|
|
|
public IReadOnlyList<BatteryPowerLimit> PowerLimitedBy => ListActivePowerLimits();
|
|
|
|
public IReadOnlyList<AlarmMessage> Alarms => ListAlarms();
|
|
|
|
public IReadOnlyList<WarningMessage> Warnings => ListWarnings();
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
private AlarmMessage[] ListAlarms() => EnumerateAlarms()
|
|
|
|
.Take(_Self.NumberOfAlarms)
|
|
|
|
.ToArray(_Self.NumberOfAlarms);
|
|
|
|
|
|
|
|
private WarningMessage[] ListWarnings() => EnumerateWarnings()
|
|
|
|
.Take(_Self.NumberOfWarnings)
|
|
|
|
.ToArray(_Self.NumberOfWarnings);
|
|
|
|
|
|
|
|
private IEnumerable<WarningMessage> EnumerateWarnings()
|
|
|
|
{
|
|
|
|
yield return _Self.Warning1;
|
|
|
|
yield return _Self.Warning2;
|
|
|
|
yield return _Self.Warning3;
|
|
|
|
yield return _Self.Warning4;
|
|
|
|
yield return _Self.Warning5;
|
|
|
|
yield return _Self.Warning6;
|
|
|
|
yield return _Self.Warning7;
|
|
|
|
yield return _Self.Warning8;
|
|
|
|
yield return _Self.Warning9;
|
|
|
|
yield return _Self.Warning10;
|
|
|
|
yield return _Self.Warning11;
|
|
|
|
yield return _Self.Warning12;
|
|
|
|
yield return _Self.Warning13;
|
|
|
|
yield return _Self.Warning14;
|
|
|
|
yield return _Self.Warning15;
|
|
|
|
yield return _Self.Warning16;
|
|
|
|
yield return _Self.Warning17;
|
|
|
|
yield return _Self.Warning18;
|
|
|
|
yield return _Self.Warning19;
|
|
|
|
yield return _Self.Warning20;
|
|
|
|
}
|
|
|
|
|
|
|
|
private IEnumerable<AlarmMessage> EnumerateAlarms()
|
|
|
|
{
|
|
|
|
yield return _Self.Alarm1;
|
|
|
|
yield return _Self.Alarm2;
|
|
|
|
yield return _Self.Alarm3;
|
|
|
|
yield return _Self.Alarm4;
|
|
|
|
yield return _Self.Alarm5;
|
|
|
|
yield return _Self.Alarm6;
|
|
|
|
yield return _Self.Alarm7;
|
|
|
|
yield return _Self.Alarm8;
|
|
|
|
yield return _Self.Alarm9;
|
|
|
|
yield return _Self.Alarm10;
|
|
|
|
yield return _Self.Alarm11;
|
|
|
|
yield return _Self.Alarm12;
|
|
|
|
yield return _Self.Alarm13;
|
|
|
|
yield return _Self.Alarm14;
|
|
|
|
yield return _Self.Alarm15;
|
|
|
|
yield return _Self.Alarm16;
|
|
|
|
yield return _Self.Alarm17;
|
|
|
|
yield return _Self.Alarm18;
|
|
|
|
yield return _Self.Alarm19;
|
|
|
|
yield return _Self.Alarm20;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private List<BatteryPowerLimit> ListActivePowerLimits()
|
|
|
|
{
|
|
|
|
return Utils
|
|
|
|
.Utils
|
|
|
|
.GetEnumValues<BatteryPowerLimit>()
|
|
|
|
.Where(t => _Self.BatteryPowerLimit.HasFlag(t))
|
|
|
|
.ToList();
|
|
|
|
}
|
|
|
|
|
|
|
|
private readonly DcDcRecord _Self;
|
|
|
|
internal DcDcStatus(DcDcRecord self) => _Self = self;
|
|
|
|
}
|