Innovenergy_trunk/csharp/Lib/Devices/Trumpf/TruConvertAc/Status/AcDcStatus.cs

103 lines
3.8 KiB
C#

using InnovEnergy.Lib.Devices.Trumpf.SystemControl.DataTypes;
using InnovEnergy.Lib.Devices.Trumpf.TruConvertAc.DataTypes;
using InnovEnergy.Lib.Units.Composite;
using AlarmMessage = InnovEnergy.Lib.Devices.Trumpf.TruConvertAc.DataTypes.AlarmMessage;
using WarningMessage = InnovEnergy.Lib.Devices.Trumpf.TruConvertAc.DataTypes.WarningMessage;
using static System.Math;
namespace InnovEnergy.Lib.Devices.Trumpf.TruConvertAc.Status;
public class AcDcStatus
{
public Ac3Bus Ac => new Ac3Bus { L1 = L1, L2 = L2, L3 = L3, Frequency = _Self.GridFrequency };
public PowerLimit PowerLimitedBy => _Self.PowerLimitedBy;
public InverterStates InverterState => new(_Self);
public GridType ActiveGridType => _Self.ActiveGridType;
public Voltages DcVoltages => new(_Self);
public Temperatures Temperature => new(_Self);
public OverloadCapacity OverloadCapacity => new(_Self);
public Nominals Nominal => new(_Self);
public IReadOnlyList<AlarmMessage> Alarms => GetAlarms ().Take(_Self.NumberOfAlarms ).Where(IsAcDcAlarm ).ToList();
public IReadOnlyList<WarningMessage> Warnings => GetWarnings().Take(_Self.NumberOfWarnings).Where(IsAcDcWarning).ToList();
private IEnumerable<AlarmMessage> GetAlarms()
{
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 static Boolean IsAcDcAlarm(AlarmMessage alarm) => (UInt16)alarm is >= 50000 and < 60000;
private IEnumerable<WarningMessage> GetWarnings()
{
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;
}
// TODO: there are no AcDc Warnings defined in doc
private static Boolean IsAcDcWarning(WarningMessage warning) => warning != WarningMessage.NoWarning;
private AcPhase L1 => new()
{
Current = Abs(_Self.GridCurrentL1),
Voltage = Abs(_Self.GridVoltageL1),
Phi = Atan2(_Self.ReactivePowerL1, _Self.ActivePowerL1)
};
private AcPhase L2 => new()
{
Current = Abs(_Self.GridCurrentL2),
Voltage = Abs(_Self.GridVoltageL2),
Phi = Atan2(_Self.ReactivePowerL2, _Self.ActivePowerL2)
};
private AcPhase L3 => new()
{
Current = Abs(_Self.GridCurrentL3),
Voltage = Abs(_Self.GridVoltageL3),
Phi = Atan2(_Self.ReactivePowerL3, _Self.ActivePowerL3)
};
internal AcDcStatus(AcDcRecord self) => _Self = self;
private readonly AcDcRecord _Self;
}