Create Individual Battery

This commit is contained in:
atef 2023-06-30 10:30:18 +02:00
parent 5dfd8e69b4
commit 8fc2b8fe9d
1 changed files with 45 additions and 25 deletions

View File

@ -36,20 +36,23 @@ internal static class Program
private static readonly Byte[] BatteryNodes = { 2, 3, 4, 5, 6 }; private static readonly Byte[] BatteryNodes = { 2, 3, 4, 5, 6 };
private const String BatteryTty = "/dev/ttyUSB0"; private const String BatteryTty = "/dev/ttyUSB0";
#if DEBUG
private static readonly TcpChannel TruConvertAcChannel = new TcpChannel("localhost", 5001);
private static readonly TcpChannel TruConvertDcChannel = new TcpChannel("localhost", 5002);
private static readonly TcpChannel GridMeterChannel = new TcpChannel("localhost", 5003);
private static readonly TcpChannel AcOutLoadChannel = new TcpChannel("localhost", 5004);
private static readonly TcpChannel AmptChannel = new TcpChannel("localhost", 5005);
private static readonly TcpChannel RelaysChannel = new TcpChannel("localhost", 5006);
private static readonly TcpChannel BatteriesChannel = new TcpChannel("localhost", 5007);
#else
private static readonly TcpChannel RelaysChannel = new TcpChannel("10.0.1.1", 502); // "192.168.1.242"; private static readonly TcpChannel RelaysChannel = new TcpChannel("10.0.1.1", 502); // "192.168.1.242";
private static readonly TcpChannel TruConvertAcChannel = new TcpChannel("10.0.2.1", 502); // "192.168.1.2"; private static readonly TcpChannel TruConvertAcChannel = new TcpChannel("10.0.2.1", 502); // "192.168.1.2";
private static readonly TcpChannel TruConvertDcChannel = new TcpChannel("10.0.3.1", 502); // "192.168.1.3"; private static readonly TcpChannel TruConvertDcChannel = new TcpChannel("10.0.3.1", 502); // "192.168.1.3";
private static readonly TcpChannel GridMeterChannel = new TcpChannel("10.0.4.1", 502); // "192.168.1.241"; private static readonly TcpChannel GridMeterChannel = new TcpChannel("10.0.4.1", 502); // "192.168.1.241";
private static readonly TcpChannel AcOutLoadChannel = new TcpChannel("10.0.4.2", 502); // "192.168.1.241"; private static readonly TcpChannel AcOutLoadChannel = new TcpChannel("10.0.4.2", 502); // "192.168.1.241";
private static readonly TcpChannel AmptChannel = new TcpChannel("10.0.5.1", 502); // "192.168.1.249"; private static readonly TcpChannel AmptChannel = new TcpChannel("10.0.5.1", 502); // "192.168.1.249";
private static readonly TcpChannel BatteriesChannel = new TcpChannel("localhost", 5007);
//private static readonly TcpChannel TruConvertAcChannel = new TcpChannel("localhost", 5001); #endif
//private static readonly TcpChannel TruConvertDcChannel = new TcpChannel("localhost", 5002);
//private static readonly TcpChannel GridMeterChannel = new TcpChannel("localhost", 5003);
//private static readonly TcpChannel AcOutLoadChannel = new TcpChannel("localhost", 5004);
//private static readonly TcpChannel AmptChannel = new TcpChannel("localhost", 5005);
//private static readonly TcpChannel RelaysChannel = new TcpChannel("localhost", 5006);
//private static readonly TcpChannel BatteriesChannel = new TcpChannel("localhost", 5007);
private static readonly S3Config S3Config = new S3Config private static readonly S3Config S3Config = new S3Config
@ -165,7 +168,6 @@ internal static class Program
Console.WriteLine("press ctrl-C to stop"); Console.WriteLine("press ctrl-C to stop");
while (true) while (true)
{ {
sd_notify(0, "WATCHDOG=1"); sd_notify(0, "WATCHDOG=1");
@ -181,15 +183,6 @@ internal static class Program
if (record.Relays is not null) if (record.Relays is not null)
record.Relays.ToCsv().WriteLine(); record.Relays.ToCsv().WriteLine();
var emuMeterRegisters = record.GridMeter;
if (emuMeterRegisters is not null)
{
emuMeterRegisters.Ac.Power.Active.WriteLine("Grid Active");
//emuMeterRegisters.Ac.Power.Reactive.WriteLine("Grid Reactive");
}
record.ControlConstants(); record.ControlConstants();
record.ControlSystemState(); record.ControlSystemState();
@ -272,12 +265,25 @@ internal static class Program
var flowDcBusToDcDc = Flow.Horizontal(dcdcPower); var flowDcBusToDcDc = Flow.Horizontal(dcdcPower);
var flowDcDcToBattery = Flow.Horizontal(dcBatteryPower); var flowDcDcToBattery = Flow.Horizontal(dcBatteryPower);
var gridBox = TextBlock.AlignLeft(gridPowerByPhase).TitleBox("Grid"); var gridBox = TextBlock.AlignLeft(gridPowerByPhase).TitleBox("Grid");
var inverterBox = TextBlock.AlignLeft(inverterPowerByAcDc).TitleBox("Inverter"); var inverterBox = TextBlock.AlignLeft(inverterPowerByAcDc).TitleBox("Inverter");
var dcDcBox = TextBlock.AlignLeft(dc48Voltage).TitleBox("DC/DC"); var dcDcBox = TextBlock.AlignLeft(dc48Voltage).TitleBox("DC/DC");
var batteryBox = TextBlock.AlignLeft(batteryVoltage.ToDisplayString(), batterySoc.ToDisplayString(), batteryCurrent.ToDisplayString(), batteryTemp.ToDisplayString()).TitleBox("Battery"); var batteryAvgBox = TextBlock.AlignLeft(batteryVoltage.ToDisplayString(),
batterySoc.ToDisplayString(),
batteryCurrent.ToDisplayString(),
batteryTemp.ToDisplayString())
.TitleBox("Battery");
//////////////////// Batteries /////////////////////////
IReadOnlyList<TextBlock> batteryBoxes = s.Battery
.Devices
.Select(CreateIndividualBattery)
.ToArray(s.Battery.Devices.Count);
var individualBatteries = TextBlock.AlignLeft(batteryBoxes);
var totalBoxes = TextBlock.CenterVertical(gridBox, var totalBoxes = TextBlock.CenterVertical(gridBox,
gridBusFlow, gridBusFlow,
@ -291,11 +297,25 @@ internal static class Program
flowDcBusToDcDc, flowDcBusToDcDc,
dcDcBox, dcDcBox,
flowDcDcToBattery, flowDcDcToBattery,
batteryBox); batteryAvgBox,
individualBatteries);
totalBoxes.WriteLine(); totalBoxes.WriteLine();
} }
private static TextBlock CreateIndividualBattery(Battery48TlRecord battery, Int32 i)
{
var content = TextBlock.AlignLeft(battery.Dc.Voltage.ToDisplayString(),
battery.Soc.ToDisplayString(),
battery.Dc.Current.ToDisplayString(),
battery.Temperatures.Heating);
var box = content.TitleBox($"Battery {i + 1}");
var flow = Flow.Horizontal(battery.Dc.Power);
return TextBlock.CenterVertical(flow, box);
}
private static TextBlock ColumnBox(String pvTitle, String busTitle, String loadTitle, TextBlock dataBox) private static TextBlock ColumnBox(String pvTitle, String busTitle, String loadTitle, TextBlock dataBox)
{ {
return ColumnBox(pvTitle, busTitle, loadTitle, dataBox, 0); return ColumnBox(pvTitle, busTitle, loadTitle, dataBox, 0);