Add a Calibration Charge Flag based on the Time Since TOC.
This commit is contained in:
parent
20c3e95666
commit
9bbccfd34b
|
@ -195,16 +195,21 @@ public static class Controller
|
|||
|
||||
private static Boolean MustDoCalibrationCharge(this StatusRecord statusRecord)
|
||||
{
|
||||
var config = statusRecord.Config;
|
||||
|
||||
if (statusRecord.Battery.Eoc)
|
||||
{
|
||||
"Batteries have reached EOC".LogInfo();
|
||||
config.LastEoc = UnixTime.Now;
|
||||
return false;
|
||||
}
|
||||
|
||||
return UnixTime.Now - statusRecord.Config.LastEoc > MaxTimeWithoutEoc;
|
||||
// var config = statusRecord.Config;
|
||||
//
|
||||
// if (statusRecord.Battery.Eoc)
|
||||
// {
|
||||
// "Batteries have reached EOC".LogInfo();
|
||||
// config.LastEoc = UnixTime.Now;
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// return UnixTime.Now - statusRecord.Config.LastEoc > MaxTimeWithoutEoc;
|
||||
|
||||
// no need to return false in case of EOC reached
|
||||
// because the BMS will set the Time Since TOC to 0 as soon a battery reach EOC
|
||||
// then Calibration Charge flag will be set false by the software
|
||||
return statusRecord.Battery.CalibrationChargeFlag;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -171,13 +171,21 @@ internal static class Program
|
|||
{
|
||||
Watchdog.NotifyAlive();
|
||||
|
||||
var t = UnixTime.Now;
|
||||
var record = ReadStatus();
|
||||
|
||||
int i = 1;
|
||||
|
||||
// For Debug purpose, will be deleted after
|
||||
foreach (var device in record.Battery.Devices)
|
||||
{
|
||||
Console.WriteLine(" Battery " + i);
|
||||
device.TimeSinceTOC.WriteLine(" : Value of register 54");
|
||||
device.Soc.WriteLine(" : SOC");
|
||||
device.CalibrationChargeFlag.WriteLine(" : Calibration Charge Flag");
|
||||
i++;
|
||||
"====================".WriteLine();
|
||||
}
|
||||
|
||||
var batteryTimeToToc = (3600 - record.Battery.TimeToToc / 60 );
|
||||
|
||||
record.Battery.TimeToToc.WriteLine(" : Value of register 54");
|
||||
batteryTimeToToc .WriteLine(" : Remaining time before next top of charge");
|
||||
|
||||
record.ControlConstants();
|
||||
record.ControlSystemState();
|
||||
|
|
|
@ -13,10 +13,11 @@ using Strings = IReadOnlyList<String>;
|
|||
[SuppressMessage("ReSharper", "ConvertToAutoProperty")]
|
||||
public partial class Battery48TlRecord
|
||||
{
|
||||
public Dc_ Dc => new Dc_(this);
|
||||
public Leds_ Leds => new Leds_(this);
|
||||
public Temperatures_ Temperatures => new Temperatures_(this);
|
||||
|
||||
private UInt16 OneWeekInMinutes => 10080;
|
||||
public Dc_ Dc => new Dc_(this);
|
||||
public Leds_ Leds => new Leds_(this);
|
||||
public Temperatures_ Temperatures => new Temperatures_(this);
|
||||
|
||||
public Boolean ConnectedToDcBus => (_IoStates & 1) == 0;
|
||||
public Boolean Eoc => Leds is { Green: On, Amber: Off, Blue : Off };
|
||||
|
||||
|
@ -25,13 +26,17 @@ public partial class Battery48TlRecord
|
|||
|
||||
public Percent Soc => _Soc;
|
||||
|
||||
public UInt16 TimeToTOC => (UInt16)_TimeToTOC;
|
||||
// Time since TOC is a counter from the last moment when the battery reached EOC
|
||||
// When The battery is full charged (reached EOC) the Time Since TOC is set to 0
|
||||
public UInt16 TimeSinceTOC => _TimeSinceToc;
|
||||
|
||||
public Current BusCurrent => _BusCurrent;
|
||||
|
||||
public Current HeatingCurrent => _BusCurrent - _CellsCurrent;
|
||||
|
||||
public DcPower HeatingPower => HeatingCurrent * Dc.Voltage;
|
||||
|
||||
public Boolean CalibrationChargeFlag => TimeSinceTOC > OneWeekInMinutes;
|
||||
|
||||
public readonly struct Leds_
|
||||
{
|
||||
|
@ -42,6 +47,7 @@ public partial class Battery48TlRecord
|
|||
|
||||
private Battery48TlRecord Self { get; }
|
||||
internal Leds_(Battery48TlRecord self) => this.Self = self;
|
||||
|
||||
}
|
||||
|
||||
public readonly struct Temperatures_
|
||||
|
|
|
@ -23,7 +23,7 @@ public partial class Battery48TlRecord
|
|||
[InputRegister(1062, Scale = 0.01, Offset = -10000)] private Double _BusCurrent;
|
||||
|
||||
[InputRegister(1053, Scale = 0.1)] private Double _Soc;
|
||||
[InputRegister(1052)] private Double _TimeToTOC;
|
||||
[InputRegister(1052)] private UInt16 _TimeSinceToc;
|
||||
|
||||
[InputRegister(1014, Scale = 0.1, Offset = -400)] private Double _TemperaturesBoard;
|
||||
[InputRegister(1015, Scale = 0.1, Offset = -400)] private Double _TemperaturesCellsCenter;
|
||||
|
|
|
@ -6,15 +6,16 @@ namespace InnovEnergy.Lib.Devices.Battery48TL;
|
|||
|
||||
public class Battery48TlRecords
|
||||
{
|
||||
public required DcBus Dc { get; init; }
|
||||
public required Boolean Eoc { get; init; }
|
||||
public required IReadOnlyList<String> Warnings { get; init; }
|
||||
public required IReadOnlyList<String> Alarms { get; init; }
|
||||
public required Percent Soc { get; init; }
|
||||
public required Percent CurrentMinSoc { get; init; }
|
||||
public required Temperature Temperature { get; init; }
|
||||
public required DcPower HeatingPower { get; init; }
|
||||
public required UInt16 TimeToToc { get; init; }
|
||||
public required DcBus Dc { get; init; }
|
||||
public required Boolean Eoc { get; init; }
|
||||
public required IReadOnlyList<String> Warnings { get; init; }
|
||||
public required IReadOnlyList<String> Alarms { get; init; }
|
||||
public required Percent Soc { get; init; }
|
||||
public required Percent CurrentMinSoc { get; init; }
|
||||
public required Temperature Temperature { get; init; }
|
||||
public required DcPower HeatingPower { get; init; }
|
||||
public required UInt16 TimeSinceToc { get; init; }
|
||||
public required Boolean CalibrationChargeFlag { get; init; }
|
||||
|
||||
public required IReadOnlyList<Battery48TlRecord> Devices { get; init; }
|
||||
|
||||
|
@ -25,15 +26,16 @@ public class Battery48TlRecords
|
|||
|
||||
return new Battery48TlRecords
|
||||
{
|
||||
Devices = records,
|
||||
Eoc = records.All(r => r.Eoc),
|
||||
Warnings = records.SelectMany(r => r.Warnings).Distinct().ToList(),
|
||||
Alarms = records.SelectMany(r => r.Alarms).Distinct().ToList(),
|
||||
Soc = records.Average(r => r.Soc.Value),
|
||||
CurrentMinSoc = records.Min(r => r.Soc.Value),
|
||||
Temperature = records.Average(b => b.Temperatures.Cells.Average.Value),
|
||||
HeatingPower = records.Sum(b => b.HeatingPower),
|
||||
TimeToToc = records.Min(r => r.TimeToTOC),
|
||||
Devices = records,
|
||||
Eoc = records.All(r => r.Eoc),
|
||||
Warnings = records.SelectMany(r => r.Warnings).Distinct().ToList(),
|
||||
Alarms = records.SelectMany(r => r.Alarms).Distinct().ToList(),
|
||||
Soc = records.Average(r => r.Soc.Value),
|
||||
CurrentMinSoc = records.Min(r => r.Soc.Value),
|
||||
Temperature = records.Average(b => b.Temperatures.Cells.Average.Value),
|
||||
HeatingPower = records.Sum(b => b.HeatingPower),
|
||||
TimeSinceToc = records.Max(r => r.TimeSinceTOC),
|
||||
CalibrationChargeFlag = records.Any(r => r.CalibrationChargeFlag),
|
||||
|
||||
Dc = new()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue