fix bugs introduced by 'required' changes

This commit is contained in:
ig 2023-06-27 17:01:40 +02:00
parent 7f97ab8e14
commit a761e46686
5 changed files with 40 additions and 24 deletions

View File

@ -28,13 +28,19 @@ public static class Controller
var mode = s.SelectControlMode();
mode.WriteLine();
if (mode is EssMode.Off or EssMode.NoGridMeter)
return new EssControl(mode, EssLimit.NoLimit, PowerCorrection: 0, PowerSetpoint: 0);
return EssControl.Default;
var essDelta = s.ComputePowerDelta(mode);
var unlimitedControl = new EssControl(mode, EssLimit.NoLimit, essDelta, 0);
var unlimitedControl = new EssControl
{
Mode = mode,
LimitedBy = EssLimit.NoLimit,
PowerCorrection = essDelta,
PowerSetpoint = 0
};
var limitedControl = unlimitedControl
.LimitChargePower(s)

View File

@ -3,13 +3,21 @@ using InnovEnergy.Lib.Units.Power;
namespace InnovEnergy.App.SaliMax.Ess;
public record EssControl
(
EssMode Mode,
EssLimit LimitedBy,
ActivePower PowerCorrection,
ActivePower PowerSetpoint
)
{
public required EssMode Mode { get; init; }
public required EssLimit LimitedBy { get; init; }
public required ActivePower PowerCorrection { get; init; }
public required ActivePower PowerSetpoint { get; init; }
public static EssControl Default { get; } = new()
{
Mode = EssMode.Off,
LimitedBy = EssLimit.NoLimit,
PowerCorrection = 0,
PowerSetpoint = 0
};
public EssControl LimitChargePower(Double controlDelta, EssLimit reason)
{
var overload = PowerCorrection - controlDelta;

View File

@ -25,7 +25,7 @@ public record StatusRecord
public required RelaysRecord? Relays { get; init; }
public required AmptStatus PvOnDc { get; init; }
public required Config Config { get; init; }
public required EssControl EssControl { get; init; }
public required EssControl EssControl { get; set; } // TODO: init only
public required StateMachine StateMachine { get; init; }
}

View File

@ -148,7 +148,9 @@ internal static class Program
LoadOnAcIsland = loadOnAcIsland,
LoadOnDc = loadOnDc,
Config = Config.Load() // load from disk every iteration, so config can be changed while running
StateMachine = StateMachine.Default,
EssControl = EssControl.Default,
Config = Config.Load() // load from disk every iteration, so config can be changed while running
};
}
@ -228,17 +230,17 @@ internal static class Program
var islandToGridBusPower = inverterPower + islandLoadPower;
var gridLoadPower = s.LoadOnAcGrid is null ? 0: s.LoadOnAcGrid.Power.Active;
var gridPowerByPhase = TextBlock.AlignLeft(s.GridMeter.Ac.L1.Power.Active.ToStringRounded(),
s.GridMeter.Ac.L2.Power.Active.ToStringRounded(),
s.GridMeter.Ac.L3.Power.Active.ToStringRounded());
var gridPowerByPhase = TextBlock.AlignLeft(s.GridMeter.Ac.L1.Power.Active.ToDisplayString(),
s.GridMeter.Ac.L2.Power.Active.ToDisplayString(),
s.GridMeter.Ac.L3.Power.Active.ToDisplayString());
var gridVoltageByPhase = TextBlock.AlignLeft(s.GridMeter.Ac.L1.Voltage.ToStringRounded(),
s.GridMeter.Ac.L2.Voltage.ToStringRounded(),
s.GridMeter.Ac.L3.Voltage.ToStringRounded());
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.ToStringRounded(),
s.AcDc.Ac.L2.Power.Active.ToStringRounded(),
s.AcDc.Ac.L3.Power.Active.ToStringRounded());
var inverterPowerByPhase = TextBlock.AlignLeft(s.AcDc.Ac.L1.Power.Active.ToDisplayString(),
s.AcDc.Ac.L2.Power.Active.ToDisplayString(),
s.AcDc.Ac.L3.Power.Active.ToDisplayString());
// ReSharper disable once CoVariantArrayConversion
var inverterPowerByAcDc = TextBlock.AlignLeft(s.AcDc.Devices
@ -246,7 +248,7 @@ internal static class Program
.ToArray());
var dcLinkVoltage = TextBlock.CenterHorizontal("",
s.DcDc.Dc.Link.Voltage.ToStringRounded(),
s.DcDc.Dc.Link.Voltage.ToDisplayString(),
"");
//var inverterPowerByPhase = new ActivePower[(Int32)s.AcDc.Ac.L1.Power.Active, (Int32)s.AcDc.Ac.L2.Power.Active, (Int32)s.AcDc.Ac.L3.Power.Active];
@ -273,7 +275,7 @@ internal static class Program
var gridBox = TextBlock.AlignLeft(gridPowerByPhase).TitleBox("Grid");
var inverterBox = TextBlock.AlignLeft(inverterPowerByAcDc).TitleBox("Inverter");
var dcDcBox = TextBlock.AlignLeft(dc48Voltage).TitleBox("DC/DC");
var batteryBox = TextBlock.AlignLeft(batteryVoltage.ToStringRounded(), batterySoc.ToStringRounded(), batteryCurrent.ToStringRounded(), batteryTemp.ToStringRounded()).TitleBox("Battery");
var batteryBox = TextBlock.AlignLeft(batteryVoltage.ToDisplayString(), batterySoc.ToDisplayString(), batteryCurrent.ToDisplayString(), batteryTemp.ToDisplayString()).TitleBox("Battery");

View File

@ -5,8 +5,8 @@ namespace InnovEnergy.Lib.WebServer;
public static class Default
{
public static IPEndPoint EndPoint { get; } = new IPEndPoint(0, 0);
public static Url Url { get; } = new Url("");
public static IPEndPoint EndPoint { get; } = new IPEndPoint(0, 0);
public static Url Url { get; } = new Url("");
public static HttpResponse HttpNotFound { get; } = new HttpResponse { StatusCode = 404 };
public static HttpResponse HttpForbidden { get; } = new HttpResponse { StatusCode = 403 };