Add EocReached in the batteries and add percent to the Units
This commit is contained in:
parent
cb5bd91e55
commit
d8911a2a3a
|
@ -22,10 +22,13 @@ public record Battery48TLStatus : BatteryStatus
|
||||||
public IReadOnlyList<String> Warnings { get; init; } = Array.Empty<String>();
|
public IReadOnlyList<String> Warnings { get; init; } = Array.Empty<String>();
|
||||||
public IReadOnlyList<String> Alarms { 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 ConnectedToDc { get; init; }
|
||||||
public Boolean Heating { get; init; }
|
public Boolean Heating { get; init; }
|
||||||
public TemperatureState TemperatureState { get; init; } // cold | operating temperature | overheated
|
public TemperatureState TemperatureState { get; init; } // cold | operating temperature | overheated
|
||||||
|
|
||||||
|
public Current TotalCurrent { get; init; }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// TODO: strings
|
// TODO: strings
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using System.Text;
|
||||||
using InnovEnergy.Lib.Protocols.Modbus.Conversions;
|
using InnovEnergy.Lib.Protocols.Modbus.Conversions;
|
||||||
using InnovEnergy.Lib.Units.Composite;
|
using InnovEnergy.Lib.Units.Composite;
|
||||||
using InnovEnergy.Lib.Utils;
|
using InnovEnergy.Lib.Utils;
|
||||||
|
@ -17,9 +18,11 @@ public static class ModbusParser
|
||||||
|
|
||||||
var soc = data.ParseSoc();
|
var soc = data.ParseSoc();
|
||||||
|
|
||||||
var eoc = greenLed is On
|
// var eoc = greenLed is On
|
||||||
&& amberLed is Off
|
// && amberLed is Off
|
||||||
&& blueLed is Off;
|
// && blueLed is Off;
|
||||||
|
|
||||||
|
var eoc = data.ParseEocReached();
|
||||||
|
|
||||||
var maxSoc = eoc ? 100m : 99.9m;
|
var maxSoc = eoc ? 100m : 99.9m;
|
||||||
|
|
||||||
|
@ -48,6 +51,8 @@ public static class ModbusParser
|
||||||
MaxChargingPower = data.CalcMaxChargePower(),
|
MaxChargingPower = data.CalcMaxChargePower(),
|
||||||
MaxDischargingPower = data.CalcMaxDischargePower(),
|
MaxDischargingPower = data.CalcMaxDischargePower(),
|
||||||
CellsVoltage = data.ParseDecimal(register: 1000, scaleFactor: 0.01m),
|
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);
|
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)
|
internal static Boolean ParseBool(this ModbusRegisters data, Int32 baseRegister, Int16 bit)
|
||||||
{
|
{
|
||||||
var x = bit / 16;
|
var x = bit / 16;
|
||||||
|
@ -96,6 +114,21 @@ public static class ModbusParser
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
internal static Decimal ParseSoc(this ModbusRegisters data)
|
||||||
{
|
{
|
||||||
|
|
|
@ -15,6 +15,7 @@ public static class Units
|
||||||
public static Angle Rad (this Decimal value) => value;
|
public static Angle Rad (this Decimal value) => value;
|
||||||
public static Temperature Celsius(this Decimal value) => value;
|
public static Temperature Celsius(this Decimal value) => value;
|
||||||
public static Energy KWh (this Decimal value) => value;
|
public static Energy KWh (this Decimal value) => value;
|
||||||
|
public static Percent Percent(this Decimal value) => value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Prefixes
|
public static class Prefixes
|
||||||
|
|
Loading…
Reference in New Issue