Restructure EmuMeter Status and add AvgBatteries file
This commit is contained in:
parent
18fa0bfc36
commit
cba19ee1ed
|
@ -22,9 +22,5 @@
|
||||||
<ProjectReference Include="..\..\lib\Time\Time.csproj" />
|
<ProjectReference Include="..\..\lib\Time\Time.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Folder Include="src\StatusLog" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
|
@ -27,46 +27,13 @@ public static class AsciiArt
|
||||||
.JoinLines();
|
.JoinLines();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String CreateBox(String title, String value)
|
|
||||||
{
|
|
||||||
if (value == "0")
|
|
||||||
{
|
|
||||||
value = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
var contentWidth = Math.Max(title.Length, value.Length);
|
|
||||||
|
|
||||||
var horizontal = "".PadRight(contentWidth + 2, '-').SurroundWith("+");
|
|
||||||
|
|
||||||
var t = title.PadRight(contentWidth).SurroundWith(" ").SurroundWith("|");
|
|
||||||
|
|
||||||
var x = value.SplitLines().ToArray();
|
|
||||||
var values = "";
|
|
||||||
|
|
||||||
foreach (var line in x)
|
|
||||||
{
|
|
||||||
var temp = values;
|
|
||||||
values = line.PadRight(contentWidth).SurroundWith(" ").SurroundWith("|") + "\n";
|
|
||||||
values += temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
values = values.Remove(values.LastIndexOf(Environment.NewLine));
|
|
||||||
|
|
||||||
return StringUtils.JoinLines(
|
|
||||||
horizontal,
|
|
||||||
t,
|
|
||||||
values,
|
|
||||||
horizontal
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String CreateHorizontalArrow(Decimal value, String separator)
|
public static String CreateHorizontalArrow(Decimal value, String separator)
|
||||||
{
|
{
|
||||||
var valueToString = " " + value.W();
|
var valueToString = " " + value.W();
|
||||||
|
|
||||||
if (value == 0)
|
if (value == 0)
|
||||||
{
|
{
|
||||||
valueToString = "it's 0";
|
valueToString = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
var contentWidth = separator.Length;
|
var contentWidth = separator.Length;
|
||||||
|
|
|
@ -0,0 +1,51 @@
|
||||||
|
using InnovEnergy.Lib.Devices.Battery48TL;
|
||||||
|
|
||||||
|
namespace InnovEnergy.SaliMax.Controller;
|
||||||
|
|
||||||
|
public class AvgBatteriesStatus
|
||||||
|
{
|
||||||
|
public Decimal Soc { get; set; }
|
||||||
|
public Decimal Current { get; set; }
|
||||||
|
public Decimal Voltage { get; set; }
|
||||||
|
public Decimal Power { get; set; }
|
||||||
|
public Decimal BusVoltage { get; set; }
|
||||||
|
public Decimal BatteryTemperature { get; set; }
|
||||||
|
public IReadOnlyList<String> Warnings { get; set; }
|
||||||
|
public IReadOnlyList<String> Alarms { get; set; }
|
||||||
|
public Boolean HeaterOn { get; set; }
|
||||||
|
public Boolean EocReached { get; set; }
|
||||||
|
public Boolean BatteryCold { get; set; }
|
||||||
|
public Decimal MaxChargingPower { get; set; }
|
||||||
|
public Decimal MaxDischargingPower { get; set; }
|
||||||
|
|
||||||
|
public static AvgBatteriesStatus ReadBatteriesStatus(IReadOnlyList<Battery48TLStatus> batteriesStatus)
|
||||||
|
{
|
||||||
|
var soc = batteriesStatus.Any() ? batteriesStatus.Average(b => b.Soc) : 0;
|
||||||
|
var current = batteriesStatus.Select(b => b.Dc.Current).Aggregate(0m,(a, b) => a + b);
|
||||||
|
var voltage = batteriesStatus.Any() ? batteriesStatus.Average(b => b.Dc.Voltage) : 0;
|
||||||
|
var power = batteriesStatus.Select(b => b.Dc.Power).Aggregate(0m,(a, b) => a + b);
|
||||||
|
var busVoltage = batteriesStatus.Any() ? batteriesStatus.Average(b => b.BusVoltage): 0;
|
||||||
|
var batteryTemperature = batteriesStatus.Any() ? batteriesStatus.Average(b => b.Temperature): 0;
|
||||||
|
var heaterOn = batteriesStatus.Any() && batteriesStatus.Select(b => b.HeaterOn).Aggregate((a, b) => a | b);
|
||||||
|
var eocReached = batteriesStatus.All(b => b.EocReached);
|
||||||
|
var batteryCold = batteriesStatus.Any(b => b.BatteryCold);
|
||||||
|
var maxChargingPower = batteriesStatus.Select(b => b.MaxChargingPower).Aggregate(0m, (a, b) => a + b);
|
||||||
|
var maxDischargingPower = batteriesStatus.Select(b => b.MaxDischargingPower).Aggregate(0m, (a, b) => a + b);
|
||||||
|
|
||||||
|
|
||||||
|
return new AvgBatteriesStatus
|
||||||
|
{
|
||||||
|
Soc = soc,
|
||||||
|
Current = current,
|
||||||
|
Voltage = voltage,
|
||||||
|
Power = power,
|
||||||
|
BusVoltage = busVoltage,
|
||||||
|
BatteryTemperature = batteryTemperature,
|
||||||
|
HeaterOn = heaterOn,
|
||||||
|
EocReached = eocReached,
|
||||||
|
BatteryCold = batteryCold,
|
||||||
|
MaxChargingPower = maxChargingPower,
|
||||||
|
MaxDischargingPower = maxDischargingPower
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,5 +1,6 @@
|
||||||
{
|
{
|
||||||
"sdk": {
|
"sdk": {
|
||||||
|
"version": "6.0.0",
|
||||||
"rollForward": "latestMajor",
|
"rollForward": "latestMajor",
|
||||||
"allowPrerelease": true
|
"allowPrerelease": true
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
using InnovEnergy.Lib.Protocols.Modbus.Clients;
|
using InnovEnergy.Lib.Protocols.Modbus.Clients;
|
||||||
using InnovEnergy.Lib.Protocols.Modbus.Connections;
|
using InnovEnergy.Lib.Protocols.Modbus.Connections;
|
||||||
|
using InnovEnergy.Lib.StatusApi.Connections;
|
||||||
|
using InnovEnergy.Lib.StatusApi.Phases;
|
||||||
|
using InnovEnergy.Lib.Utils;
|
||||||
|
using static DecimalMath.DecimalEx;
|
||||||
|
|
||||||
namespace InnovEnergy.Lib.Devices.EmuMeter;
|
namespace InnovEnergy.Lib.Devices.EmuMeter;
|
||||||
|
|
||||||
|
@ -25,7 +29,7 @@ public class EmuMeterDevice
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private static Decimal GetPhi(Decimal cosPhi) => cosPhi.Clamp(-1m, 1m).Apply(ACos);
|
||||||
|
|
||||||
private EmuMeterStatus TryReadStatus()
|
private EmuMeterStatus TryReadStatus()
|
||||||
{
|
{
|
||||||
|
@ -36,53 +40,80 @@ public class EmuMeterDevice
|
||||||
var energyTotal = Modbus.ReadHoldingRegisters(6000, 24) .ToUInt64s();
|
var energyTotal = Modbus.ReadHoldingRegisters(6000, 24) .ToUInt64s();
|
||||||
var energyPhases = Modbus.ReadHoldingRegisters(6100, 104).ToUInt64s();
|
var energyPhases = Modbus.ReadHoldingRegisters(6100, 104).ToUInt64s();
|
||||||
|
|
||||||
|
var activePowerL123 = powerCurrent[0];
|
||||||
|
var activePowerL1 = powerCurrent[1];
|
||||||
|
var activePowerL2 = powerCurrent[2];
|
||||||
|
var activePowerL3 = powerCurrent[3];
|
||||||
|
var reactivePowerL123 = powerCurrent[5];
|
||||||
|
var reactivePowerL1 = powerCurrent[6];
|
||||||
|
var reactivePowerL2 = powerCurrent[7];
|
||||||
|
var reactivePowerL3 = powerCurrent[8];
|
||||||
|
var apparentPowerL123 = powerCurrent[10];
|
||||||
|
var apparentPowerL1 = powerCurrent[11];
|
||||||
|
var apparentPowerL2 = powerCurrent[12];
|
||||||
|
var apparentPowerL3 = powerCurrent[13];
|
||||||
|
var currentL123 = powerCurrent[50];
|
||||||
|
var currentL1 = powerCurrent[51];
|
||||||
|
var currentL2 = powerCurrent[52];
|
||||||
|
var currentL3 = powerCurrent[53];
|
||||||
|
var voltageL1N = voltageFreq[0];
|
||||||
|
var voltageL2N = voltageFreq[1];
|
||||||
|
var voltageL3N = voltageFreq[2];
|
||||||
|
var voltageL1L2 = voltageFreq[3];
|
||||||
|
var voltageL2L3 = voltageFreq[4];
|
||||||
|
var voltageL3L1 = voltageFreq[5];
|
||||||
|
var powerFactorL1 = voltageFreq[50];
|
||||||
|
var powerFactorL2 = voltageFreq[51];
|
||||||
|
var powerFactorL3 = voltageFreq[52];
|
||||||
|
var frequency = voltageFreq[55];
|
||||||
|
var energyImportL123 = energyTotal[0 / 4] / 1000.0m;
|
||||||
|
var energyExportL123 = energyTotal[20 / 4] / 1000.0m;
|
||||||
|
var energyImportL1 = energyPhases[0 / 4] / 1000.0m;
|
||||||
|
var energyExportL1 = energyPhases[20 / 4] / 1000.0m;
|
||||||
|
var energyImportL2 = energyPhases[40 / 4] / 1000.0m;
|
||||||
|
var energyExportL2 = energyPhases[60 / 4] / 1000.0m;
|
||||||
|
var energyImportL3 = energyPhases[80 / 4] / 1000.0m;
|
||||||
|
var energyExportL3 = energyPhases[100 / 4] / 1000.0m;
|
||||||
|
|
||||||
return new EmuMeterStatus
|
return new EmuMeterStatus
|
||||||
{
|
(
|
||||||
ActivePowerL123 = powerCurrent[0],
|
Ac: new ThreePhaseAcConnection
|
||||||
ActivePowerL1 = powerCurrent[1],
|
(
|
||||||
ActivePowerL2 = powerCurrent[2],
|
new AcPhase(
|
||||||
ActivePowerL3 = powerCurrent[3],
|
voltageL1N,
|
||||||
|
currentL1,
|
||||||
|
GetPhi(powerFactorL1)
|
||||||
|
),
|
||||||
|
|
||||||
ReactivePowerL123 = powerCurrent[5],
|
new AcPhase(
|
||||||
ReactivePowerL1 = powerCurrent[6],
|
voltageL2N,
|
||||||
ReactivePowerL2 = powerCurrent[7],
|
currentL2,
|
||||||
ReactivePowerL3 = powerCurrent[8],
|
GetPhi(powerFactorL2)
|
||||||
|
),
|
||||||
|
|
||||||
ApparentPowerL123 = powerCurrent[10],
|
new AcPhase(
|
||||||
ApparentPowerL1 = powerCurrent[11],
|
voltageL3N,
|
||||||
ApparentPowerL2 = powerCurrent[12],
|
currentL3,
|
||||||
ApparentPowerL3 = powerCurrent[13],
|
GetPhi(powerFactorL3)
|
||||||
|
),
|
||||||
CurrentL123 = powerCurrent[50],
|
frequency
|
||||||
CurrentL1 = powerCurrent[51],
|
),
|
||||||
CurrentL2 = powerCurrent[52],
|
activePowerL123,
|
||||||
CurrentL3 = powerCurrent[53],
|
reactivePowerL123,
|
||||||
|
apparentPowerL123,
|
||||||
VoltageL1N = voltageFreq[0],
|
currentL123,
|
||||||
VoltageL2N = voltageFreq[1],
|
voltageL1L2,
|
||||||
VoltageL3N = voltageFreq[2],
|
voltageL2L3,
|
||||||
VoltageL1L2 = voltageFreq[3],
|
voltageL3L1,
|
||||||
VoltageL2L3 = voltageFreq[4],
|
energyImportL123,
|
||||||
VoltageL3L1 = voltageFreq[5],
|
energyImportL1,
|
||||||
|
energyImportL2,
|
||||||
PowerFactorL1 = voltageFreq[50],
|
energyImportL3,
|
||||||
PowerFactorL2 = voltageFreq[51],
|
energyExportL123,
|
||||||
PowerFactorL3 = voltageFreq[52],
|
energyExportL1,
|
||||||
|
energyExportL2,
|
||||||
Frequency = voltageFreq[55],
|
energyExportL3
|
||||||
|
);
|
||||||
EnergyImportL123 = energyTotal[0 / 4] / 1000.0m,
|
|
||||||
EnergyExportL123 = energyTotal[20 / 4] / 1000.0m,
|
|
||||||
|
|
||||||
EnergyImportL1 = energyPhases[0 / 4] / 1000.0m,
|
|
||||||
EnergyExportL1 = energyPhases[20 / 4] / 1000.0m,
|
|
||||||
|
|
||||||
EnergyImportL2 = energyPhases[40 / 4] / 1000.0m,
|
|
||||||
EnergyExportL2 = energyPhases[60 / 4] / 1000.0m,
|
|
||||||
|
|
||||||
EnergyImportL3 = energyPhases[80 / 4] / 1000.0m,
|
|
||||||
EnergyExportL3 = energyPhases[100 / 4] / 1000.0m,
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,45 +1,26 @@
|
||||||
|
using InnovEnergy.Lib.StatusApi.Connections;
|
||||||
|
using InnovEnergy.Lib.StatusApi.Devices;
|
||||||
|
|
||||||
namespace InnovEnergy.Lib.Devices.EmuMeter;
|
namespace InnovEnergy.Lib.Devices.EmuMeter;
|
||||||
|
|
||||||
public record EmuMeterStatus
|
public record EmuMeterStatus
|
||||||
{
|
(
|
||||||
public Decimal ActivePowerL123 { get; init; }
|
ThreePhaseAcConnection Ac,
|
||||||
public Decimal ActivePowerL1 { get; init; }
|
Decimal ActivePowerL123,
|
||||||
public Decimal ActivePowerL2 { get; init; }
|
Decimal ReactivePowerL123,
|
||||||
public Decimal ActivePowerL3 { get; init; }
|
Decimal ApparentPowerL123,
|
||||||
public Decimal ReactivePowerL123 { get; init; }
|
Decimal CurrentL123,
|
||||||
public Decimal ReactivePowerL1 { get; init; }
|
Decimal VoltageL1L2,
|
||||||
public Decimal ReactivePowerL2 { get; init; }
|
Decimal VoltageL2L3,
|
||||||
public Decimal ReactivePowerL3 { get; init; }
|
Decimal VoltageL3L1,
|
||||||
public Decimal ApparentPowerL123 { get; init; }
|
Decimal EnergyImportL123,
|
||||||
public Decimal ApparentPowerL1 { get; init; }
|
Decimal EnergyImportL1,
|
||||||
public Decimal ApparentPowerL2 { get; init; }
|
Decimal EnergyImportL2,
|
||||||
public Decimal ApparentPowerL3 { get; init; }
|
Decimal EnergyImportL3,
|
||||||
|
Decimal EnergyExportL123,
|
||||||
|
Decimal EnergyExportL1,
|
||||||
|
Decimal EnergyExportL2,
|
||||||
|
Decimal EnergyExportL3
|
||||||
|
):GridMeter(Ac)
|
||||||
|
{}
|
||||||
|
|
||||||
public Decimal CurrentL123 { get; init; }
|
|
||||||
public Decimal CurrentL1 { get; init; }
|
|
||||||
public Decimal CurrentL2 { get; init; }
|
|
||||||
public Decimal CurrentL3 { get; init; }
|
|
||||||
|
|
||||||
public Decimal VoltageL1N { get; init; }
|
|
||||||
public Decimal VoltageL2N { get; init; }
|
|
||||||
public Decimal VoltageL3N { get; init; }
|
|
||||||
public Decimal VoltageL1L2 { get; init; }
|
|
||||||
public Decimal VoltageL2L3 { get; init; }
|
|
||||||
public Decimal VoltageL3L1 { get; init; }
|
|
||||||
|
|
||||||
public Decimal PowerFactorL1 { get; init; }
|
|
||||||
public Decimal PowerFactorL2 { get; init; }
|
|
||||||
public Decimal PowerFactorL3 { get; init; }
|
|
||||||
|
|
||||||
public Decimal EnergyImportL123 { get; init; }
|
|
||||||
public Decimal EnergyImportL1 { get; init; }
|
|
||||||
public Decimal EnergyImportL2 { get; init; }
|
|
||||||
public Decimal EnergyImportL3 { get; init; }
|
|
||||||
|
|
||||||
public Decimal EnergyExportL123 { get; init; }
|
|
||||||
public Decimal EnergyExportL1 { get; init; }
|
|
||||||
public Decimal EnergyExportL2 { get; init; }
|
|
||||||
public Decimal EnergyExportL3 { get; init; }
|
|
||||||
|
|
||||||
public Decimal Frequency { get; init; }
|
|
||||||
}
|
|
Loading…
Reference in New Issue