add visual representation of relay states to topology

This commit is contained in:
ig 2023-08-23 16:11:27 +02:00
parent 4435fb9774
commit d4fdf92009
5 changed files with 74 additions and 19 deletions

View File

@ -213,6 +213,9 @@ internal static class Program
record.Config.Save();
"===========================================".LogInfo();
return record;

View File

@ -11,7 +11,6 @@ public class RelaysRecord
public Boolean K1GridBusIsConnectedToGrid => _Regs.DigitalInput6;
public Boolean K2IslandBusIsConnectedToGridBus => !_Regs.DigitalInput4;
public IEnumerable<Boolean> K3InverterIsConnectedToIslandBus
{
get

View File

@ -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
);
}
}

View File

@ -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

View File

@ -14,7 +14,6 @@ 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
@ -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)
@ -78,14 +92,34 @@ public static class Topology
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
@ -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
);
}
@ -189,6 +226,7 @@ public static class Topology
var heatingCurrent = bat.HeatingCurrent.ToDisplayString();
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)