using InnovEnergy.Lib.Protocols.Modbus.Reflection.Attributes; using InnovEnergy.Lib.StatusApi.DeviceTypes; using InnovEnergy.Lib.Units.Composite; using static System.Math; #pragma warning disable CS0649 namespace InnovEnergy.Lib.Devices.EmuMeter; using Float32 = Single; [AddressOffset(-2)] // why? public class EmuMeterRegisters : IAc3Meter { [HoldingRegister(6004, writable: true)] private UInt64 _ActivePowerImportT1; [HoldingRegister(6024, writable: true)] private UInt64 _ActivePowerExportT1; [HoldingRegister(6008, writable: true)] private UInt64 _ActivePowerImportT2; [HoldingRegister(6028, writable: true)] private UInt64 _ActivePowerExportT2; [HoldingRegister(8002, writable: true)] private UInt32 _ActivePowerImportT3; [HoldingRegister(8012, writable: true)] private UInt32 _ActivePowerExportT3; [HoldingRegister(8000, writable: true)] private UInt32 _ActivePowerImportT4; [HoldingRegister(8010, writable: true)] private UInt32 _ActivePowerExportT4; [HoldingRegister(9002, writable: true)] private Float32 _ActivePowerL1; [HoldingRegister(9004, writable: true)] private Float32 _ActivePowerL2; [HoldingRegister(9006, writable: true)] private Float32 _ActivePowerL3; [HoldingRegister(9012, writable: true)] private Float32 _ReactivePowerL1; [HoldingRegister(9014, writable: true)] private Float32 _ReactivePowerL2; [HoldingRegister(9016, writable: true)] private Float32 _ReactivePowerL3; [HoldingRegister(9102, writable: true)] private Float32 _CurrentL1; [HoldingRegister(9104, writable: true)] private Float32 _CurrentL2; [HoldingRegister(9106, writable: true)] private Float32 _CurrentL3; [HoldingRegister(9200, writable: true)] private Float32 _VoltageL1N; [HoldingRegister(9202, writable: true)] private Float32 _VoltageL2N; [HoldingRegister(9204, writable: true)] private Float32 _VoltageL3N; [HoldingRegister(9310, writable: true)] private Float32 _Frequency; public Ac3Bus Ac => new Ac3Bus { L1 = new () { Current = Abs(_CurrentL1), Voltage = Abs(_VoltageL1N), Phi = Atan2(_ReactivePowerL1, _ActivePowerL1) }, L2 = new () { Current = Abs(_CurrentL2), Voltage = Abs(_VoltageL2N), Phi = Atan2(_ReactivePowerL2, _ActivePowerL2) }, L3 = new () { Current = Abs(_CurrentL3), Voltage = Abs(_VoltageL3N), Phi = Atan2(_ReactivePowerL3, _ActivePowerL3) }, Frequency = _Frequency }; public UInt64 ActivePowerImportT1 => _ActivePowerImportT1; public UInt64 ActivePowerExportT1 => _ActivePowerExportT1; public UInt64 ActivePowerImportT2 => _ActivePowerImportT2; public UInt64 ActivePowerExportT2 => _ActivePowerExportT2; public UInt32 ActivePowerImportT3 => _ActivePowerImportT3; public UInt32 ActivePowerExportT3 => _ActivePowerExportT3; public UInt64 ActivePowerImportT4 => _ActivePowerImportT4; public UInt64 ActivePowerExportT4 => _ActivePowerExportT4; }