Add console display in island mode and replace loginfo instead console.writeline
This commit is contained in:
parent
b5b7f65384
commit
4563103572
|
@ -73,14 +73,14 @@ internal static class Program
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Console.WriteLine(e);
|
e.LogError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task Run()
|
private static async Task Run()
|
||||||
{
|
{
|
||||||
Console.WriteLine("Starting SaliMax");
|
"Starting SaliMax".LogInfo();
|
||||||
|
|
||||||
// Send the initial "service started" message to systemd
|
// Send the initial "service started" message to systemd
|
||||||
var sdNotifyReturn = sd_notify(0, "READY=1");
|
var sdNotifyReturn = sd_notify(0, "READY=1");
|
||||||
|
@ -99,25 +99,25 @@ internal static class Program
|
||||||
|
|
||||||
StatusRecord ReadStatus()
|
StatusRecord ReadStatus()
|
||||||
{
|
{
|
||||||
Console.WriteLine(" Reading AcDC");
|
"Reading AcDC".LogInfo();
|
||||||
var acDc = acDcDevices.Read();
|
var acDc = acDcDevices.Read();
|
||||||
|
|
||||||
Console.WriteLine(" Reading dcDc");
|
"Reading dcDc".LogInfo();
|
||||||
var dcDc = dcDcDevices.Read();
|
var dcDc = dcDcDevices.Read();
|
||||||
|
|
||||||
Console.WriteLine(" Reading battery");
|
"Reading battery".LogInfo();
|
||||||
var battery = batteryDevices.Read();
|
var battery = batteryDevices.Read();
|
||||||
|
|
||||||
Console.WriteLine(" Reading relays");
|
"Reading relays".LogInfo();
|
||||||
var relays = saliMaxRelaysDevice.Read();
|
var relays = saliMaxRelaysDevice.Read();
|
||||||
|
|
||||||
Console.WriteLine(" loadOnAcIsland");
|
"Reading loadOnAcIsland".LogInfo();
|
||||||
var loadOnAcIsland = acIslandLoadMeter.Read();
|
var loadOnAcIsland = acIslandLoadMeter.Read();
|
||||||
|
|
||||||
Console.WriteLine(" Reading gridMeter");
|
"Reading gridMeter".LogInfo();
|
||||||
var gridMeter = gridMeterDevice.Read();
|
var gridMeter = gridMeterDevice.Read();
|
||||||
|
|
||||||
Console.WriteLine(" Reading pvOnDc");
|
"Reading pvOnDc".LogInfo();
|
||||||
var pvOnDc = amptDevice.Read();
|
var pvOnDc = amptDevice.Read();
|
||||||
|
|
||||||
var pvOnAcGrid = AcPowerDevice.Null;
|
var pvOnAcGrid = AcPowerDevice.Null;
|
||||||
|
@ -177,30 +177,35 @@ internal static class Program
|
||||||
dcDcDevices.Write(r.DcDc);
|
dcDcDevices.Write(r.DcDc);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const Int32 delayTime = 10;
|
||||||
|
|
||||||
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");
|
||||||
|
|
||||||
var t = UnixTime.FromTicks(UnixTime.Now.Ticks / 2 * 2);
|
var t = UnixTime.Now;
|
||||||
|
while (t.Ticks % UpdateIntervalSeconds != 0)
|
||||||
//t.ToUtcDateTime().WriteLine();
|
{
|
||||||
|
await Task.Delay(delayTime);
|
||||||
|
t = UnixTime.Now;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var record = ReadStatus();
|
var record = ReadStatus();
|
||||||
|
|
||||||
PrintTopology(record);
|
|
||||||
|
|
||||||
if (record.Relays is not null)
|
if (record.Relays is not null)
|
||||||
record.Relays.ToCsv().WriteLine();
|
record.Relays.ToCsv().LogInfo();
|
||||||
|
|
||||||
record.ControlConstants();
|
record.ControlConstants();
|
||||||
|
|
||||||
record.ControlSystemState();
|
record.ControlSystemState();
|
||||||
|
|
||||||
Console.WriteLine($"{record.StateMachine.State}: {record.StateMachine.Message}");
|
(t + "\n").LogInfo();
|
||||||
|
$"{record.StateMachine.State}: {record.StateMachine.Message}".LogInfo();
|
||||||
var essControl = record.ControlEss().WriteLine();
|
$"Batteries SOC: {record.Battery.Soc}".LogInfo();
|
||||||
|
var essControl = record.ControlEss().LogInfo();
|
||||||
|
|
||||||
record.EssControl = essControl;
|
record.EssControl = essControl;
|
||||||
|
|
||||||
|
@ -211,11 +216,13 @@ internal static class Program
|
||||||
|
|
||||||
WriteControl(record);
|
WriteControl(record);
|
||||||
|
|
||||||
|
PrintTopology(record);
|
||||||
|
|
||||||
await UploadCsv(record, t);
|
await UploadCsv(record, t);
|
||||||
|
|
||||||
record.Config.Save();
|
record.Config.Save();
|
||||||
|
|
||||||
"===========================================".WriteLine();
|
"===========================================".LogInfo();
|
||||||
}
|
}
|
||||||
// ReSharper disable once FunctionNeverReturns
|
// ReSharper disable once FunctionNeverReturns
|
||||||
}
|
}
|
||||||
|
@ -234,13 +241,32 @@ internal static class Program
|
||||||
var islandToGridBusPower = inverterPower + islandLoadPower;
|
var islandToGridBusPower = inverterPower + islandLoadPower;
|
||||||
var gridLoadPower = s.LoadOnAcGrid is null ? 0: s.LoadOnAcGrid.Power.Active;
|
var gridLoadPower = s.LoadOnAcGrid is null ? 0: s.LoadOnAcGrid.Power.Active;
|
||||||
|
|
||||||
var gridPowerByPhase = TextBlock.AlignLeft(s.GridMeter.Ac.L1.Power.Active.ToDisplayString(),
|
TextBlock gridBusColumn;
|
||||||
|
TextBlock gridBox;
|
||||||
|
TextBlock totalBoxes;
|
||||||
|
|
||||||
|
|
||||||
|
if (s.GridMeter is not null)
|
||||||
|
{
|
||||||
|
var gridPowerByPhase = TextBlock.AlignLeft(s.GridMeter.Ac.L1.Power.Active.ToDisplayString(),
|
||||||
s.GridMeter.Ac.L2.Power.Active.ToDisplayString(),
|
s.GridMeter.Ac.L2.Power.Active.ToDisplayString(),
|
||||||
s.GridMeter.Ac.L3.Power.Active.ToDisplayString());
|
s.GridMeter.Ac.L3.Power.Active.ToDisplayString());
|
||||||
|
|
||||||
|
var gridVoltageByPhase = TextBlock.AlignLeft(s.GridMeter.Ac.L1.Voltage.ToDisplayString(),
|
||||||
|
s.GridMeter.Ac.L2.Voltage.ToDisplayString(),
|
||||||
|
s.GridMeter.Ac.L3.Voltage.ToDisplayString());
|
||||||
|
|
||||||
|
gridBusColumn = ColumnBox("Pv", "Grid Bus", "Load" , gridVoltageByPhase , gridLoadPower);
|
||||||
|
gridBox = TextBlock.AlignLeft(gridPowerByPhase).TitleBox("Grid");
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gridBusColumn = TextBlock.Spacer(0);
|
||||||
|
gridBox = TextBlock.Spacer(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
var gridVoltageByPhase = TextBlock.AlignLeft(s.GridMeter.Ac.L1.Voltage.ToDisplayString(),
|
|
||||||
s.GridMeter.Ac.L2.Voltage.ToDisplayString(),
|
|
||||||
s.GridMeter.Ac.L3.Voltage.ToDisplayString());
|
|
||||||
|
|
||||||
var inverterPowerByPhase = TextBlock.AlignLeft(s.AcDc.Ac.L1.Power.Active.ToDisplayString(),
|
var inverterPowerByPhase = TextBlock.AlignLeft(s.AcDc.Ac.L1.Power.Active.ToDisplayString(),
|
||||||
s.AcDc.Ac.L2.Power.Active.ToDisplayString(),
|
s.AcDc.Ac.L2.Power.Active.ToDisplayString(),
|
||||||
|
@ -264,7 +290,6 @@ internal static class Program
|
||||||
var anyBatteryAlarm = s.Battery.Alarms.Any();
|
var anyBatteryAlarm = s.Battery.Alarms.Any();
|
||||||
var anyBatteryWarning = s.Battery.Warnings.Any();
|
var anyBatteryWarning = s.Battery.Warnings.Any();
|
||||||
|
|
||||||
var gridBusColumn = ColumnBox("Pv", "Grid Bus", "Load" , gridVoltageByPhase , gridLoadPower);
|
|
||||||
var islandBusColumn = ColumnBox("Pv", "Island Bus", "Load" , inverterPowerByPhase, islandLoadPower);
|
var islandBusColumn = ColumnBox("Pv", "Island Bus", "Load" , inverterPowerByPhase, islandLoadPower);
|
||||||
var dcBusColumn = ColumnBox("Pv", "Dc Bus", "Load" , dcLinkVoltage, 0, pvOnDcPower);
|
var dcBusColumn = ColumnBox("Pv", "Dc Bus", "Load" , dcLinkVoltage, 0, pvOnDcPower);
|
||||||
var gridBusFlow = Flow.Horizontal(gridPower);
|
var gridBusFlow = Flow.Horizontal(gridPower);
|
||||||
|
@ -274,8 +299,7 @@ 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 inverterBox = TextBlock.AlignLeft(inverterPowerByAcDc).TitleBox("AC/DC");
|
||||||
var inverterBox = TextBlock.AlignLeft(inverterPowerByAcDc).TitleBox("Inverter");
|
|
||||||
var dcDcBox = TextBlock.AlignLeft(dc48Voltage).TitleBox("DC/DC");
|
var dcDcBox = TextBlock.AlignLeft(dc48Voltage).TitleBox("DC/DC");
|
||||||
var batteryAvgBox = TextBlock.AlignLeft(batteryVoltage,
|
var batteryAvgBox = TextBlock.AlignLeft(batteryVoltage,
|
||||||
batterySoc,
|
batterySoc,
|
||||||
|
@ -297,11 +321,27 @@ internal static class Program
|
||||||
var individualBatteries = batteryBoxes.Any()
|
var individualBatteries = batteryBoxes.Any()
|
||||||
? TextBlock.AlignLeft(batteryBoxes)
|
? TextBlock.AlignLeft(batteryBoxes)
|
||||||
: TextBlock.Spacer(1);
|
: TextBlock.Spacer(1);
|
||||||
|
|
||||||
var totalBoxes = TextBlock.AlignCenterVertical(gridBox,
|
if (s.GridMeter is not null)
|
||||||
gridBusFlow,
|
{
|
||||||
gridBusColumn,
|
totalBoxes = TextBlock.AlignCenterVertical(gridBox,
|
||||||
flowGridBusToIslandBus,
|
gridBusFlow,
|
||||||
|
gridBusColumn,
|
||||||
|
flowGridBusToIslandBus,
|
||||||
|
islandBusColumn,
|
||||||
|
flowIslandBusToInverter,
|
||||||
|
inverterBox,
|
||||||
|
flowInverterToDcBus,
|
||||||
|
dcBusColumn,
|
||||||
|
flowDcBusToDcDc,
|
||||||
|
dcDcBox,
|
||||||
|
flowDcDcToBattery,
|
||||||
|
batteryAvgBox,
|
||||||
|
individualBatteries);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
totalBoxes = TextBlock.AlignCenterVertical(
|
||||||
islandBusColumn,
|
islandBusColumn,
|
||||||
flowIslandBusToInverter,
|
flowIslandBusToInverter,
|
||||||
inverterBox,
|
inverterBox,
|
||||||
|
@ -312,6 +352,8 @@ internal static class Program
|
||||||
flowDcDcToBattery,
|
flowDcDcToBattery,
|
||||||
batteryAvgBox,
|
batteryAvgBox,
|
||||||
individualBatteries);
|
individualBatteries);
|
||||||
|
}
|
||||||
|
|
||||||
totalBoxes.WriteLine();
|
totalBoxes.WriteLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -363,10 +405,18 @@ internal static class Program
|
||||||
private static void ControlConstants(this StatusRecord r)
|
private static void ControlConstants(this StatusRecord r)
|
||||||
{
|
{
|
||||||
var inverters = r.AcDc.Devices;
|
var inverters = r.AcDc.Devices;
|
||||||
|
var dcDevices = r.DcDc.Devices;
|
||||||
|
|
||||||
inverters.ForEach(d => d.Control.Dc.MaxVoltage = r.Config.MaxDcBusVoltage);
|
inverters.ForEach(d => d.Control.Dc.MaxVoltage = r.Config.MaxDcBusVoltage);
|
||||||
inverters.ForEach(d => d.Control.Dc.MinVoltage = r.Config.MinDcBusVoltage);
|
inverters.ForEach(d => d.Control.Dc.MinVoltage = r.Config.MinDcBusVoltage);
|
||||||
inverters.ForEach(d => d.Control.Dc.ReferenceVoltage = r.Config.ReferenceDcBusVoltage);
|
inverters.ForEach(d => d.Control.Dc.ReferenceVoltage = r.Config.ReferenceDcBusVoltage);
|
||||||
|
|
||||||
|
// dcDevices.ForEach(d => d.Control. Dc.MaxVoltage = r.Config.MaxDcBusVoltage);
|
||||||
|
// dcDevices.ForEach(d => d.Control. Dc.MinVoltage = r.Config.MinDcBusVoltage);
|
||||||
|
// dcDevices.ForEach(d => d.Control. Dc.ReferenceVoltage = r.Config.ReferenceDcBusVoltage);
|
||||||
|
|
||||||
|
r.DcDc.ResetAlarms();
|
||||||
|
r.AcDc.ResetAlarms();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -408,11 +458,13 @@ internal static class Program
|
||||||
sc.UseSlaveIdForAddressing = true;
|
sc.UseSlaveIdForAddressing = true;
|
||||||
sc.SlaveErrorHandling = SlaveErrorHandling.Relaxed;
|
sc.SlaveErrorHandling = SlaveErrorHandling.Relaxed;
|
||||||
sc.SubSlaveErrorHandling = SubSlaveErrorHandling.Off;
|
sc.SubSlaveErrorHandling = SubSlaveErrorHandling.Off;
|
||||||
|
|
||||||
sc.ResetAlarmsAndWarnings = true;
|
sc.ResetAlarmsAndWarnings = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ApplyDcDcDefaultSettings(this SystemControlRegisters? sc)
|
private static void ApplyDcDcDefaultSettings(this SystemControlRegisters? sc)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (sc is null)
|
if (sc is null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -427,7 +479,8 @@ internal static class Program
|
||||||
sc.UseSlaveIdForAddressing = true;
|
sc.UseSlaveIdForAddressing = true;
|
||||||
sc.SlaveErrorHandling = SlaveErrorHandling.Relaxed;
|
sc.SlaveErrorHandling = SlaveErrorHandling.Relaxed;
|
||||||
sc.SubSlaveErrorHandling = SubSlaveErrorHandling.Off;
|
sc.SubSlaveErrorHandling = SubSlaveErrorHandling.Off;
|
||||||
sc.ResetAlarmsAndWarnings = true;
|
|
||||||
|
sc.ResetAlarmsAndWarnings = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task UploadCsv(StatusRecord status, UnixTime timeStamp)
|
private static async Task UploadCsv(StatusRecord status, UnixTime timeStamp)
|
||||||
|
|
Loading…
Reference in New Issue