diff --git a/csharp/App/SaliMax/src/Program.cs b/csharp/App/SaliMax/src/Program.cs index 67387a7e0..69411008f 100644 --- a/csharp/App/SaliMax/src/Program.cs +++ b/csharp/App/SaliMax/src/Program.cs @@ -213,6 +213,9 @@ internal static class Program record.Config.Save(); + + + "===========================================".LogInfo(); return record; diff --git a/csharp/App/SaliMax/src/SaliMaxRelays/RelaysRecord.cs b/csharp/App/SaliMax/src/SaliMaxRelays/RelaysRecord.cs index 09875bbf2..0fae59c45 100644 --- a/csharp/App/SaliMax/src/SaliMaxRelays/RelaysRecord.cs +++ b/csharp/App/SaliMax/src/SaliMaxRelays/RelaysRecord.cs @@ -11,7 +11,6 @@ public class RelaysRecord public Boolean K1GridBusIsConnectedToGrid => _Regs.DigitalInput6; public Boolean K2IslandBusIsConnectedToGridBus => !_Regs.DigitalInput4; - public IEnumerable K3InverterIsConnectedToIslandBus { get @@ -28,8 +27,8 @@ public class RelaysRecord public Boolean K3Inverter3IsConnectedToIslandBus => !_Regs.DigitalInput2; public Boolean K3Inverter4IsConnectedToIslandBus => !_Regs.DigitalInput3; - public Boolean FiWarning => !_Regs.DigitalInput5; - public Boolean FiError => !_Regs.DigitalInput7; + public Boolean FiWarning => !_Regs.DigitalInput5; + public Boolean FiError => !_Regs.DigitalInput7; public Boolean K2ConnectIslandBusToGridBus { get => _Regs.Relay0; set => _Regs.Relay0 = value;} diff --git a/csharp/App/SaliMax/src/Switch.cs b/csharp/App/SaliMax/src/Switch.cs new file mode 100644 index 000000000..5011d75ee --- /dev/null +++ b/csharp/App/SaliMax/src/Switch.cs @@ -0,0 +1,15 @@ +using InnovEnergy.Lib.Utils; + +namespace InnovEnergy.App.SaliMax; + +public static class Switch +{ + public static TextBlock Open(String name) + { + return TextBlock.AlignCenterHorizontal + ( + " __╱ __ ", + name + ); + } +} \ No newline at end of file diff --git a/csharp/App/SaliMax/src/System/Controller.cs b/csharp/App/SaliMax/src/System/Controller.cs index b4559c1bd..5b827d873 100644 --- a/csharp/App/SaliMax/src/System/Controller.cs +++ b/csharp/App/SaliMax/src/System/Controller.cs @@ -20,7 +20,6 @@ public static class Controller if (acDcs.NotAvailable()) return 102; - var k4 = acDcs.AllGridTied() ? 0 : acDcs.AllIsland() ? 1 : 4; @@ -38,6 +37,7 @@ public static class Controller var k2 = relays.K2IslandBusIsConnectedToGridBus ? 1 : 0; var k3 = relays.K3InverterIsConnectedToIslandBus.Take(nInverters).Any(c => c) ? 1 : 0; + // states as defined in states excel sheet return 1 * k1 + 2 * k2 diff --git a/csharp/App/SaliMax/src/Topology.cs b/csharp/App/SaliMax/src/Topology.cs index 8a768ea41..821764182 100644 --- a/csharp/App/SaliMax/src/Topology.cs +++ b/csharp/App/SaliMax/src/Topology.cs @@ -14,13 +14,12 @@ public static class Topology { public static TextBlock CreateTopology(this StatusRecord status) { - // Topology is built up from right to left var islandTopology = status.CreateIslandTopology(); // TODO: check ACDCs if AC is available and synced to find out if grid meter OR grid is unavailable - + if (status.GridMeter is null) // no grid meter? - return islandTopology; // we're done + return islandTopology; // we're done var gridTopology = status.CreateGridTopology(); @@ -36,10 +35,13 @@ public static class Topology ActivePower islandToGridBusPower = inverterPower + islandLoadPower; + var k2 = status.Relays?.K2IslandBusIsConnectedToGridBus; + var gridToIslandConnection = SwitchedFlow(k2, islandToGridBusPower); + return TextBlock.AlignCenterVertical ( gridTopology, - Flow.Horizontal(islandToGridBusPower), + gridToIslandConnection, islandTopology ); } @@ -51,13 +53,25 @@ public static class Topology var gridBusColumn = status.CreateGridBusColumn(); var gridBox = status.GridMeter.CreateGridBox(); + var k1 = status.Relays?.K1GridBusIsConnectedToGrid; + var gridPower = status.GridMeter.Ac.Power.Active; + var gridFlow = SwitchedFlow(k1, gridPower); + return TextBlock .AlignCenterVertical ( gridBox, - Flow.Horizontal(status.GridMeter.Ac.Power.Active), + gridFlow, gridBusColumn ); + + } + + private static TextBlock SwitchedFlow(Boolean? switchClosed, ActivePower power) + { + return switchClosed is null ? TextBlock.FromString("??????????") + : !switchClosed.Value ? Switch.Open("K1") + : Flow.Horizontal(power); } private static TextBlock CreateIslandTopology(this StatusRecord status) @@ -74,18 +88,38 @@ public static class Topology var islandBusColumn = status.CreateIslandBusColumn(islandLoadPower); var inverterBox = status.CreateInverterBox(); var dcDcBox = status.CreateDcDcBox(); - + return TextBlock .AlignCenterVertical ( - islandBusColumn, Flow.Horizontal(inverterPower), - inverterBox , Flow.Horizontal(inverterPower), + islandBusColumn, status.InverterToIslandBusConnection(), + inverterBox , Flow.Horizontal(inverterPower), // inverter to DC bus dcBusColumn , Flow.Horizontal(dcdcPower), dcDcBox , Flow.Horizontal(dcBatteryPower), batteries ); } + [SuppressMessage("ReSharper", "PossibleMultipleEnumeration")] + private static TextBlock InverterToIslandBusConnection(this StatusRecord status) + { + if (status.Relays is null) + return TextBlock.FromString("????????"); + + var k3S = status + .Relays + .K3InverterIsConnectedToIslandBus + .Take(status.AcDc.Devices.Count); + + if (k3S.All(s => s)) + { + var inverterPower = status.AcDc.Ac.Power.Active; + return Flow.Horizontal(inverterPower); + } + + return Switch.Open("K3"); + } + private static TextBlock CreateGridBox(this IAc3Connection gridMeter) { return gridMeter @@ -153,7 +187,7 @@ public static class Topology return CreateTopologyColumn ( "PV" , pvOnDcPower, - "DC Bus" , dcLinkVoltage, + "DC Bus ", dcLinkVoltage, "DC Load", dcBusLoad ); } @@ -163,6 +197,9 @@ public static class Topology var bat = status.Battery; var batteryAvgBox = CreateAveragedBatteryBox(bat); + return batteryAvgBox; // TODO: individualBatteries hidden atm + + var batteryBoxes = bat .Devices .Select(CreateBatteryBox) @@ -175,8 +212,8 @@ public static class Topology return TextBlock .AlignCenterVertical ( - batteryAvgBox //, - //individualBatteries // TODO + batteryAvgBox , + individualBatteries ); } @@ -187,9 +224,10 @@ public static class Topology var current = bat.Dc.Current.ToDisplayString(); var temp = bat.Temperature.ToDisplayString(); var heatingCurrent = bat.HeatingCurrent.ToDisplayString(); - var alarms = bat.Alarms.Count + " Alarms"; - var warnings = bat.Warnings.Count + " Warnings"; - + var alarms = bat.Alarms.Count + " Alarms"; + var warnings = bat.Warnings.Count + " Warnings"; + var nBatteries = bat.Devices.Count; + return TextBlock .AlignLeft ( @@ -201,7 +239,7 @@ public static class Topology warnings, alarms ) - .TitleBox("Battery"); + .TitleBox($"Battery x{nBatteries}"); } private static TextBlock PhaseVoltages(this Ac3Bus ac)