extract topology related stuff into Topology.cs
This commit is contained in:
parent
633c3de5bc
commit
8a0308e441
|
@ -11,13 +11,11 @@ using InnovEnergy.Lib.Devices.Trumpf.TruConvertAc;
|
||||||
using InnovEnergy.Lib.Devices.Trumpf.TruConvertDc;
|
using InnovEnergy.Lib.Devices.Trumpf.TruConvertDc;
|
||||||
using InnovEnergy.Lib.Devices.Ampt;
|
using InnovEnergy.Lib.Devices.Ampt;
|
||||||
using InnovEnergy.Lib.Devices.Battery48TL;
|
using InnovEnergy.Lib.Devices.Battery48TL;
|
||||||
using InnovEnergy.Lib.Utils;
|
|
||||||
using InnovEnergy.SaliMax.Controller;
|
using InnovEnergy.SaliMax.Controller;
|
||||||
using InnovEnergy.SaliMax.Log;
|
using InnovEnergy.SaliMax.Log;
|
||||||
using InnovEnergy.SaliMax.SaliMaxRelays;
|
using InnovEnergy.SaliMax.SaliMaxRelays;
|
||||||
using InnovEnergy.SaliMax.SystemConfig;
|
using InnovEnergy.SaliMax.SystemConfig;
|
||||||
using InnovEnergy.Time.Unix;
|
using InnovEnergy.Time.Unix;
|
||||||
using Utils = InnovEnergy.Lib.StatusApi.Utils;
|
|
||||||
|
|
||||||
|
|
||||||
#pragma warning disable IL2026
|
#pragma warning disable IL2026
|
||||||
|
@ -148,7 +146,7 @@ internal static class Program
|
||||||
|
|
||||||
//JsonSerializer.Serialize(jsonLog, JsonOptions).WriteLine(ConsoleColor.DarkBlue);
|
//JsonSerializer.Serialize(jsonLog, JsonOptions).WriteLine(ConsoleColor.DarkBlue);
|
||||||
#endif
|
#endif
|
||||||
PrintTopology(status);
|
Topology.Print(status);
|
||||||
|
|
||||||
while (UnixTime.Now == t)
|
while (UnixTime.Now == t)
|
||||||
await Task.Delay(delayTime);
|
await Task.Delay(delayTime);
|
||||||
|
@ -157,181 +155,8 @@ internal static class Program
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static void PrintTopology(StatusRecord s)
|
|
||||||
{
|
|
||||||
const String chargingSeparator = ">>>>>>>>>>";
|
|
||||||
const String dischargingSeparator = "<<<<<<<<<";
|
|
||||||
const Int32 height = 25;
|
|
||||||
|
|
||||||
|
|
||||||
var pwr = s.InverterStatus!.Ac.ActivePower;
|
|
||||||
var pvPower = (s.AmptStatus!.Devices[0].Dc.Voltage * s.AmptStatus.Devices[0].Dc.Current + s.AmptStatus!.Devices[1].Dc.Voltage * s.AmptStatus.Devices[1].Dc.Current).Round0(); // TODO using one Ampt
|
|
||||||
var loadPower = Utils.Round3((s.GridMeterStatus!.ActivePowerL123 + pwr)); // it's a + because the pwr is inverted
|
|
||||||
|
|
||||||
var gridSeparator = s.GridMeterStatus!.ActivePowerL123 > 0 ? chargingSeparator : dischargingSeparator;
|
|
||||||
var inverterSeparator = -pwr > 0 ? chargingSeparator : dischargingSeparator;
|
|
||||||
var dcSeparator = -s.DcDcStatus!.Dc.Power > 0 ? chargingSeparator : dischargingSeparator;
|
|
||||||
#if BatteriesAllowed
|
|
||||||
var battery1Separator = s.BatteriesStatus[0]!.Power > 0 ? chargingSeparator : dischargingSeparator;
|
|
||||||
var battery2Separator = s.BatteriesStatus[1]!.Power > 0 ? chargingSeparator : dischargingSeparator;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
////////////////// Grid //////////////////////
|
|
||||||
var boxGrid = AsciiArt.CreateBox
|
|
||||||
(
|
|
||||||
"Grid",
|
|
||||||
s.GridMeterStatus.Ac.L1.Voltage.V(),
|
|
||||||
s.GridMeterStatus.Ac.L2.Voltage.V(),
|
|
||||||
s.GridMeterStatus.Ac.L3.Voltage.V()
|
|
||||||
).AlignCenterVertical(height);
|
|
||||||
|
|
||||||
var gridAcBusArrow = AsciiArt.CreateHorizontalArrow(s.GridMeterStatus!.ActivePowerL123.Round0(), gridSeparator)
|
|
||||||
.AlignCenterVertical(height);
|
|
||||||
|
|
||||||
|
|
||||||
////////////////// Ac Bus //////////////////////
|
|
||||||
var boxAcBus = AsciiArt.CreateBox
|
|
||||||
(
|
|
||||||
"AC Bus",
|
|
||||||
s.InverterStatus.Ac.L1.Voltage.V(),
|
|
||||||
s.InverterStatus.Ac.L2.Voltage.V(),
|
|
||||||
s.InverterStatus.Ac.L3.Voltage.V()
|
|
||||||
);
|
|
||||||
|
|
||||||
var boxLoad = AsciiArt.CreateBox
|
|
||||||
(
|
|
||||||
"",
|
|
||||||
"LOAD",
|
|
||||||
""
|
|
||||||
);
|
|
||||||
|
|
||||||
var loadRect = CreateRect(boxAcBus, boxLoad, loadPower).AlignBottom(height);
|
|
||||||
|
|
||||||
var acBusInvertArrow = AsciiArt.CreateHorizontalArrow(-pwr.Round0(), inverterSeparator)
|
|
||||||
.AlignCenterVertical(height);
|
|
||||||
|
|
||||||
//////////////////// Inverter /////////////////////////
|
|
||||||
var inverterBox = AsciiArt.CreateBox
|
|
||||||
(
|
|
||||||
"",
|
|
||||||
"Inverter",
|
|
||||||
""
|
|
||||||
).AlignCenterVertical(height);
|
|
||||||
|
|
||||||
var inverterArrow = AsciiArt.CreateHorizontalArrow(-pwr.Round0(), inverterSeparator)
|
|
||||||
.AlignCenterVertical(height);
|
|
||||||
|
|
||||||
|
|
||||||
//////////////////// DC Bus /////////////////////////
|
|
||||||
var dcBusBox = AsciiArt.CreateBox
|
|
||||||
(
|
|
||||||
"DC Bus",
|
|
||||||
(s.InverterStatus.ActualDcLinkVoltageLowerHalfExt + s.InverterStatus.ActualDcLinkVoltageUpperHalfExt).V(),
|
|
||||||
""
|
|
||||||
);
|
|
||||||
|
|
||||||
var pvBox = AsciiArt.CreateBox
|
|
||||||
(
|
|
||||||
"MPPT",
|
|
||||||
((s.AmptStatus!.Devices[0].Dc.Voltage + s.AmptStatus!.Devices[1].Dc.Voltage) / 2).Round0().V(),
|
|
||||||
""
|
|
||||||
);
|
|
||||||
|
|
||||||
var pvRect = CreateRect(pvBox, dcBusBox, pvPower).AlignTop(height);
|
|
||||||
|
|
||||||
var dcBusArrow = AsciiArt.CreateHorizontalArrow(-s.DcDcStatus!.Dc.Power, dcSeparator)
|
|
||||||
.AlignCenterVertical(height);
|
|
||||||
|
|
||||||
//////////////////// Dc/Dc /////////////////////////
|
|
||||||
var dcBox = AsciiArt.CreateBox
|
|
||||||
(
|
|
||||||
"Dc/Dc",
|
|
||||||
s.DcDcStatus.BatteryVoltage.V(),
|
|
||||||
""
|
|
||||||
).AlignCenterVertical(height);
|
|
||||||
#if BatteriesAllowed
|
|
||||||
var dcArrow1 = AsciiArt.CreateHorizontalArrow(s.BatteriesStatus[0]!.Power.Round0(), battery1Separator);
|
|
||||||
var dcArrow2 = AsciiArt.CreateHorizontalArrow(s.BatteriesStatus[1]!.Power.Round0(), battery2Separator);
|
|
||||||
#else
|
|
||||||
var dcArrow1 ="";
|
|
||||||
var dcArrow2 = "";
|
|
||||||
var dcArrowRect = CreateRect(dcArrow1, dcArrow2).AlignCenterVertical(height);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#if BatteriesAllowed
|
|
||||||
|
|
||||||
//////////////////// Batteries /////////////////////////
|
|
||||||
var battery1Box = AsciiArt.CreateBox
|
|
||||||
(
|
|
||||||
"Battery 1",
|
|
||||||
s.BatteriesStatus[0].Voltage.V(),
|
|
||||||
s.BatteriesStatus[0].Soc.Percent(),
|
|
||||||
s.BatteriesStatus[0].Temperature.Celsius()
|
|
||||||
);
|
|
||||||
|
|
||||||
var battery2Box = AsciiArt.CreateBox
|
|
||||||
(
|
|
||||||
"Battery 2",
|
|
||||||
s.BatteriesStatus[1].Voltage.V(),
|
|
||||||
s.BatteriesStatus[1].Soc.Percent(),
|
|
||||||
s.BatteriesStatus[1].Temperature.Celsius()
|
|
||||||
);
|
|
||||||
|
|
||||||
var batteryRect = CreateRect(battery1Box, battery2Box).AlignCenterVertical(height);
|
|
||||||
|
|
||||||
var avgBatteryBox = AsciiArt.CreateBox
|
|
||||||
(
|
|
||||||
"Batteries",
|
|
||||||
s.AvgBatteriesStatus!.Voltage.V(),
|
|
||||||
s.AvgBatteriesStatus.Soc.Percent(),
|
|
||||||
s.AvgBatteriesStatus.Temperature.Celsius()
|
|
||||||
).AlignCenterVertical(height);
|
|
||||||
|
|
||||||
|
|
||||||
var topology = boxGrid.SideBySideWith(gridAcBusArrow, "")
|
|
||||||
.SideBySideWith(loadRect, "")
|
|
||||||
.SideBySideWith(acBusInvertArrow, "")
|
|
||||||
.SideBySideWith(inverterBox, "")
|
|
||||||
.SideBySideWith(inverterArrow, "")
|
|
||||||
.SideBySideWith(pvRect, "")
|
|
||||||
.SideBySideWith(dcBusArrow, "")
|
|
||||||
.SideBySideWith(dcBox, "")
|
|
||||||
.SideBySideWith(dcArrowRect, "")
|
|
||||||
.SideBySideWith(batteryRect, "")
|
|
||||||
.SideBySideWith(avgBatteryBox, "")+ "\n";
|
|
||||||
#else
|
|
||||||
var topology = boxGrid.SideBySideWith(gridAcBusArrow, "")
|
|
||||||
.SideBySideWith(loadRect, "")
|
|
||||||
.SideBySideWith(acBusInvertArrow, "")
|
|
||||||
.SideBySideWith(inverterBox, "")
|
|
||||||
.SideBySideWith(inverterArrow, "")
|
|
||||||
.SideBySideWith(pvRect, "")
|
|
||||||
.SideBySideWith(dcBusArrow, "")
|
|
||||||
.SideBySideWith(dcBox, "")+ "\n";
|
|
||||||
#endif
|
|
||||||
Console.WriteLine(topology);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String CreateRect(String boxTop, String boxBottom, Decimal power)
|
|
||||||
{
|
|
||||||
var powerArrow = AsciiArt.CreateVerticalArrow(power);
|
|
||||||
var boxes = new[] { boxTop, powerArrow, boxBottom };
|
|
||||||
var maxWidth = boxes.Max(l => l.Width());
|
|
||||||
|
|
||||||
var rect = boxes.Select(l => l.AlignCenterHorizontal(maxWidth)).JoinLines();
|
|
||||||
return rect;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String CreateRect(String boxTop, String boxBottom)
|
|
||||||
{
|
|
||||||
var boxes = new[] { boxTop, boxBottom };
|
|
||||||
var maxWidth = boxes.Max(l => l.Width());
|
|
||||||
|
|
||||||
var rect = boxes.Select(l => l.AlignCenterHorizontal(maxWidth)).JoinLines();
|
|
||||||
return rect;
|
|
||||||
}
|
|
||||||
|
|
||||||
// to delete not used anymore
|
// to delete not used anymore
|
||||||
[Conditional("RELEASE")]
|
[Conditional("RELEASE")]
|
||||||
private static void ReleaseWriteLog(JsonObject jsonLog, UnixTime timestamp)
|
private static void ReleaseWriteLog(JsonObject jsonLog, UnixTime timestamp)
|
||||||
|
|
|
@ -0,0 +1,184 @@
|
||||||
|
using InnovEnergy.Lib.Utils;
|
||||||
|
using InnovEnergy.SaliMax.Controller;
|
||||||
|
using InnovEnergy.SaliMax.Log;
|
||||||
|
|
||||||
|
namespace InnovEnergy.SaliMax;
|
||||||
|
|
||||||
|
public static class Topology
|
||||||
|
{
|
||||||
|
public static void Print(StatusRecord s)
|
||||||
|
{
|
||||||
|
const String chargingSeparator = ">>>>>>>>>>";
|
||||||
|
const String dischargingSeparator = "<<<<<<<<<";
|
||||||
|
const Int32 height = 25;
|
||||||
|
|
||||||
|
|
||||||
|
var pwr = s.InverterStatus!.Ac.ActivePower;
|
||||||
|
var pvPower = (s.AmptStatus!.Devices[0].Dc.Voltage * s.AmptStatus.Devices[0].Dc.Current + s.AmptStatus!.Devices[1].Dc.Voltage * s.AmptStatus.Devices[1].Dc.Current).Round0(); // TODO using one Ampt
|
||||||
|
var loadPower = Utils.Round3((s.GridMeterStatus!.ActivePowerL123 + pwr)); // it's a + because the pwr is inverted
|
||||||
|
|
||||||
|
var gridSeparator = s.GridMeterStatus!.ActivePowerL123 > 0 ? chargingSeparator : dischargingSeparator;
|
||||||
|
var inverterSeparator = -pwr > 0 ? chargingSeparator : dischargingSeparator;
|
||||||
|
var dcSeparator = -s.DcDcStatus!.Dc.Power > 0 ? chargingSeparator : dischargingSeparator;
|
||||||
|
#if BatteriesAllowed
|
||||||
|
var battery1Separator = s.BatteriesStatus[0]!.Power > 0 ? chargingSeparator : dischargingSeparator;
|
||||||
|
var battery2Separator = s.BatteriesStatus[1]!.Power > 0 ? chargingSeparator : dischargingSeparator;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
////////////////// Grid //////////////////////
|
||||||
|
var boxGrid = AsciiArt.CreateBox
|
||||||
|
(
|
||||||
|
"Grid",
|
||||||
|
s.GridMeterStatus.Ac.L1.Voltage.V(),
|
||||||
|
s.GridMeterStatus.Ac.L2.Voltage.V(),
|
||||||
|
s.GridMeterStatus.Ac.L3.Voltage.V()
|
||||||
|
).AlignCenterVertical(height);
|
||||||
|
|
||||||
|
var gridAcBusArrow = AsciiArt.CreateHorizontalArrow(s.GridMeterStatus!.ActivePowerL123.Round0(), gridSeparator)
|
||||||
|
.AlignCenterVertical(height);
|
||||||
|
|
||||||
|
|
||||||
|
////////////////// Ac Bus //////////////////////
|
||||||
|
var boxAcBus = AsciiArt.CreateBox
|
||||||
|
(
|
||||||
|
"AC Bus",
|
||||||
|
s.InverterStatus.Ac.L1.Voltage.V(),
|
||||||
|
s.InverterStatus.Ac.L2.Voltage.V(),
|
||||||
|
s.InverterStatus.Ac.L3.Voltage.V()
|
||||||
|
);
|
||||||
|
|
||||||
|
var boxLoad = AsciiArt.CreateBox
|
||||||
|
(
|
||||||
|
"",
|
||||||
|
"LOAD",
|
||||||
|
""
|
||||||
|
);
|
||||||
|
|
||||||
|
var loadRect = StringUtils.AlignBottom(CreateRect(boxAcBus, boxLoad, loadPower), height);
|
||||||
|
|
||||||
|
var acBusInvertArrow = AsciiArt.CreateHorizontalArrow(-pwr.Round0(), inverterSeparator)
|
||||||
|
.AlignCenterVertical(height);
|
||||||
|
|
||||||
|
//////////////////// Inverter /////////////////////////
|
||||||
|
var inverterBox = AsciiArt.CreateBox
|
||||||
|
(
|
||||||
|
"",
|
||||||
|
"Inverter",
|
||||||
|
""
|
||||||
|
).AlignCenterVertical(height);
|
||||||
|
|
||||||
|
var inverterArrow = AsciiArt.CreateHorizontalArrow(-pwr.Round0(), inverterSeparator)
|
||||||
|
.AlignCenterVertical(height);
|
||||||
|
|
||||||
|
|
||||||
|
//////////////////// DC Bus /////////////////////////
|
||||||
|
var dcBusBox = AsciiArt.CreateBox
|
||||||
|
(
|
||||||
|
"DC Bus",
|
||||||
|
(s.InverterStatus.ActualDcLinkVoltageLowerHalfExt + s.InverterStatus.ActualDcLinkVoltageUpperHalfExt).V(),
|
||||||
|
""
|
||||||
|
);
|
||||||
|
|
||||||
|
var pvBox = AsciiArt.CreateBox
|
||||||
|
(
|
||||||
|
"MPPT",
|
||||||
|
((s.AmptStatus!.Devices[0].Dc.Voltage + s.AmptStatus!.Devices[1].Dc.Voltage) / 2).Round0().V(),
|
||||||
|
""
|
||||||
|
);
|
||||||
|
|
||||||
|
var pvRect = StringUtils.AlignTop(CreateRect(pvBox, dcBusBox, pvPower), height);
|
||||||
|
|
||||||
|
var dcBusArrow = AsciiArt.CreateHorizontalArrow(-s.DcDcStatus!.Dc.Power, dcSeparator)
|
||||||
|
.AlignCenterVertical(height);
|
||||||
|
|
||||||
|
//////////////////// Dc/Dc /////////////////////////
|
||||||
|
var dcBox = AsciiArt.CreateBox
|
||||||
|
(
|
||||||
|
"Dc/Dc",
|
||||||
|
s.DcDcStatus.BatteryVoltage.V(),
|
||||||
|
""
|
||||||
|
).AlignCenterVertical(height);
|
||||||
|
#if BatteriesAllowed
|
||||||
|
var dcArrow1 = AsciiArt.CreateHorizontalArrow(s.BatteriesStatus[0]!.Power.Round0(), battery1Separator);
|
||||||
|
var dcArrow2 = AsciiArt.CreateHorizontalArrow(s.BatteriesStatus[1]!.Power.Round0(), battery2Separator);
|
||||||
|
#else
|
||||||
|
var dcArrow1 ="";
|
||||||
|
var dcArrow2 = "";
|
||||||
|
var dcArrowRect = StringUtils.AlignCenterVertical(CreateRect(dcArrow1, dcArrow2), height);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#if BatteriesAllowed
|
||||||
|
|
||||||
|
//////////////////// Batteries /////////////////////////
|
||||||
|
var battery1Box = AsciiArt.CreateBox
|
||||||
|
(
|
||||||
|
"Battery 1",
|
||||||
|
s.BatteriesStatus[0].Voltage.V(),
|
||||||
|
s.BatteriesStatus[0].Soc.Percent(),
|
||||||
|
s.BatteriesStatus[0].Temperature.Celsius()
|
||||||
|
);
|
||||||
|
|
||||||
|
var battery2Box = AsciiArt.CreateBox
|
||||||
|
(
|
||||||
|
"Battery 2",
|
||||||
|
s.BatteriesStatus[1].Voltage.V(),
|
||||||
|
s.BatteriesStatus[1].Soc.Percent(),
|
||||||
|
s.BatteriesStatus[1].Temperature.Celsius()
|
||||||
|
);
|
||||||
|
|
||||||
|
var batteryRect = CreateRect(battery1Box, battery2Box).AlignCenterVertical(height);
|
||||||
|
|
||||||
|
var avgBatteryBox = AsciiArt.CreateBox
|
||||||
|
(
|
||||||
|
"Batteries",
|
||||||
|
s.AvgBatteriesStatus!.Voltage.V(),
|
||||||
|
s.AvgBatteriesStatus.Soc.Percent(),
|
||||||
|
s.AvgBatteriesStatus.Temperature.Celsius()
|
||||||
|
).AlignCenterVertical(height);
|
||||||
|
|
||||||
|
|
||||||
|
var topology = boxGrid.SideBySideWith(gridAcBusArrow, "")
|
||||||
|
.SideBySideWith(loadRect, "")
|
||||||
|
.SideBySideWith(acBusInvertArrow, "")
|
||||||
|
.SideBySideWith(inverterBox, "")
|
||||||
|
.SideBySideWith(inverterArrow, "")
|
||||||
|
.SideBySideWith(pvRect, "")
|
||||||
|
.SideBySideWith(dcBusArrow, "")
|
||||||
|
.SideBySideWith(dcBox, "")
|
||||||
|
.SideBySideWith(dcArrowRect, "")
|
||||||
|
.SideBySideWith(batteryRect, "")
|
||||||
|
.SideBySideWith(avgBatteryBox, "")+ "\n";
|
||||||
|
#else
|
||||||
|
var topology = boxGrid.SideBySideWith(gridAcBusArrow, "")
|
||||||
|
.SideBySideWith(loadRect, "")
|
||||||
|
.SideBySideWith(acBusInvertArrow, "")
|
||||||
|
.SideBySideWith(inverterBox, "")
|
||||||
|
.SideBySideWith(inverterArrow, "")
|
||||||
|
.SideBySideWith(pvRect, "")
|
||||||
|
.SideBySideWith(dcBusArrow, "")
|
||||||
|
.SideBySideWith(dcBox, "")+ "\n";
|
||||||
|
#endif
|
||||||
|
Console.WriteLine(topology);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String CreateRect(String boxTop, String boxBottom, Decimal power)
|
||||||
|
{
|
||||||
|
var powerArrow = AsciiArt.CreateVerticalArrow(power);
|
||||||
|
var boxes = new[] { boxTop, powerArrow, boxBottom };
|
||||||
|
var maxWidth = boxes.Max(l => l.Width());
|
||||||
|
|
||||||
|
var rect = boxes.Select(l => l.AlignCenterHorizontal(maxWidth)).JoinLines();
|
||||||
|
return rect;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String CreateRect(String boxTop, String boxBottom)
|
||||||
|
{
|
||||||
|
var boxes = new[] { boxTop, boxBottom };
|
||||||
|
var maxWidth = boxes.Max(l => l.Width());
|
||||||
|
|
||||||
|
var rect = boxes.Select(l => l.AlignCenterHorizontal(maxWidth)).JoinLines();
|
||||||
|
return rect;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue