Add EocReached in the batteries and add percent to the Units

This commit is contained in:
atef 2023-04-20 13:22:41 +02:00
parent cb5bd91e55
commit d8911a2a3a
3 changed files with 41 additions and 4 deletions

View File

@ -22,9 +22,12 @@ public record Battery48TLStatus : BatteryStatus
public IReadOnlyList<String> Warnings { get; init; } = Array.Empty<String>();
public IReadOnlyList<String> Alarms { get; init; } = Array.Empty<String>();
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; }

View File

@ -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)
{

View File

@ -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