diff --git a/csharp/Lib/Devices/Battery48TL/Battery48TLStatusRecord.cs b/csharp/Lib/Devices/Battery48TL/Battery48TLStatusRecord.cs index c42532fc6..da885cb32 100644 --- a/csharp/Lib/Devices/Battery48TL/Battery48TLStatusRecord.cs +++ b/csharp/Lib/Devices/Battery48TL/Battery48TLStatusRecord.cs @@ -22,9 +22,12 @@ public record Battery48TLStatus : BatteryStatus public IReadOnlyList Warnings { get; init; } = Array.Empty(); public IReadOnlyList Alarms { get; init; } = Array.Empty(); + public Boolean EocReached { get; init; } public Boolean ConnectedToDc { get; init; } public Boolean Heating { get; init; } public TemperatureState TemperatureState { get; init; } // cold | operating temperature | overheated + + public Current TotalCurrent { get; init; } diff --git a/csharp/Lib/Devices/Battery48TL/ModbusParser.cs b/csharp/Lib/Devices/Battery48TL/ModbusParser.cs index af2c3568a..6877c6a05 100644 --- a/csharp/Lib/Devices/Battery48TL/ModbusParser.cs +++ b/csharp/Lib/Devices/Battery48TL/ModbusParser.cs @@ -1,4 +1,5 @@ using System.Diagnostics.CodeAnalysis; +using System.Text; using InnovEnergy.Lib.Protocols.Modbus.Conversions; using InnovEnergy.Lib.Units.Composite; using InnovEnergy.Lib.Utils; @@ -17,9 +18,11 @@ public static class ModbusParser var soc = data.ParseSoc(); - var eoc = greenLed is On - && amberLed is Off - && blueLed is Off; + // var eoc = greenLed is On + // && amberLed is Off + // && blueLed is Off; + + var eoc = data.ParseEocReached(); var maxSoc = eoc ? 100m : 99.9m; @@ -48,6 +51,8 @@ public static class ModbusParser MaxChargingPower = data.CalcMaxChargePower(), MaxDischargingPower = data.CalcMaxDischargePower(), CellsVoltage = data.ParseDecimal(register: 1000, scaleFactor: 0.01m), + TotalCurrent = data.ReadTotalCurrent(), + EocReached = eoc }; } @@ -72,6 +77,19 @@ public static class ModbusParser return data.ParseDecimal(register: 1002, scaleFactor: 0.01m); } + internal static Decimal ReadTotalCurrent(this ModbusRegisters data) + { + try + { + return ParseDecimal(data, register: 1063, scaleFactor: 0.01m, offset: -100); + } + catch (Exception e) + { + Console.WriteLine(e + " Read Total current fail "); + throw; + } + } + internal static Boolean ParseBool(this ModbusRegisters data, Int32 baseRegister, Int16 bit) { var x = bit / 16; @@ -95,7 +113,22 @@ public static class ModbusParser (true, true) => BlinkingFast, }; } - + + internal static String ParseString(this ModbusRegisters data, Int32 register, Int16 count) + { + return Enumerable + .Range(register, count) + .Select(i => data[i]) + .Select(BitConverter.GetBytes) + .Select(Encoding.ASCII.GetString) + .Aggregate("", (a, b) => a + b[1] + b[0]); // endian swap + } + + internal static Boolean ParseEocReached(this ModbusRegisters data) + { + var s = ParseString(data, 1061, 2); + return "EOC_" == s; + } internal static Decimal ParseSoc(this ModbusRegisters data) { diff --git a/csharp/Lib/Units/Units.cs b/csharp/Lib/Units/Units.cs index d9ee297c5..a18e4292d 100644 --- a/csharp/Lib/Units/Units.cs +++ b/csharp/Lib/Units/Units.cs @@ -15,6 +15,7 @@ public static class Units public static Angle Rad (this Decimal value) => value; public static Temperature Celsius(this Decimal value) => value; public static Energy KWh (this Decimal value) => value; + public static Percent Percent(this Decimal value) => value; } public static class Prefixes