using System.Text.Json.Nodes; using InnovEnergy.Lib.Devices.EmuMeter; using InnovEnergy.Lib.StatusApi; using InnovEnergy.Lib.Utils; using static DecimalMath.DecimalEx; using static InnovEnergy.App.SaliMax.Log.JsonUtil; namespace InnovEnergy.App.SaliMax.Log; public static class EmuMeter { public static JsonObject? Log(this EmuMeterStatus? s, DeviceType type, String serialNb) { if (s is null) return null; // var l1 = CreateAcPhase(s.Ac.L1.Current, s.Ac.L1.Voltage, ACos(s.Ac.L1.PowerFactor)); var l2 = CreateAcPhase(s.Ac.L2.Current, s.Ac.L2.Voltage, ACos(s.Ac.L2.PowerFactor)); var l3 = CreateAcPhase(s.Ac.L3.Current, s.Ac.L3.Voltage, ACos(s.Ac.L3.PowerFactor)); var ac = new JsonObject { ["L1"] = l1, ["L2"] = l2, ["L3"] = l3, ["Frequency"] = s.Ac.Frequency }; var status = new JsonObject { ["Ac"] = ac, }; return new JsonObject { [$"EmuMeter {serialNb}"] = status }; } private static IEnumerable GetAcPhases(this EmuMeterStatus s) { yield return CreateAcPhase(s.Ac.L1.Current.Round3(),s.Ac.L1.Voltage.Round3(),s.Ac.L1.PowerFactor.Apply(ACos).Round3()); yield return CreateAcPhase(s.Ac.L2.Current.Round3(),s.Ac.L2.Voltage.Round3(),s.Ac.L2.PowerFactor.Apply(ACos).Round3()); yield return CreateAcPhase(s.Ac.L3.Current.Round3(),s.Ac.L3.Voltage.Round3(),s.Ac.L3.PowerFactor.Apply(ACos).Round3()); } }