Add a Calibration Charge Flag based on the Time Since TOC.

This commit is contained in:
atef 2023-09-01 10:48:44 +02:00
parent 20c3e95666
commit 9bbccfd34b
5 changed files with 60 additions and 39 deletions

View File

@ -195,16 +195,21 @@ public static class Controller
private static Boolean MustDoCalibrationCharge(this StatusRecord statusRecord) private static Boolean MustDoCalibrationCharge(this StatusRecord statusRecord)
{ {
var config = statusRecord.Config; // var config = statusRecord.Config;
//
if (statusRecord.Battery.Eoc) // if (statusRecord.Battery.Eoc)
{ // {
"Batteries have reached EOC".LogInfo(); // "Batteries have reached EOC".LogInfo();
config.LastEoc = UnixTime.Now; // config.LastEoc = UnixTime.Now;
return false; // return false;
} // }
//
return UnixTime.Now - statusRecord.Config.LastEoc > MaxTimeWithoutEoc; // 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;
} }

View File

@ -171,13 +171,21 @@ internal static class Program
{ {
Watchdog.NotifyAlive(); Watchdog.NotifyAlive();
var t = UnixTime.Now;
var record = ReadStatus(); 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.ControlConstants();
record.ControlSystemState(); record.ControlSystemState();

View File

@ -13,10 +13,11 @@ using Strings = IReadOnlyList<String>;
[SuppressMessage("ReSharper", "ConvertToAutoProperty")] [SuppressMessage("ReSharper", "ConvertToAutoProperty")]
public partial class Battery48TlRecord public partial class Battery48TlRecord
{ {
public Dc_ Dc => new Dc_(this); private UInt16 OneWeekInMinutes => 10080;
public Leds_ Leds => new Leds_(this); public Dc_ Dc => new Dc_(this);
public Temperatures_ Temperatures => new Temperatures_(this); public Leds_ Leds => new Leds_(this);
public Temperatures_ Temperatures => new Temperatures_(this);
public Boolean ConnectedToDcBus => (_IoStates & 1) == 0; public Boolean ConnectedToDcBus => (_IoStates & 1) == 0;
public Boolean Eoc => Leds is { Green: On, Amber: Off, Blue : Off }; public Boolean Eoc => Leds is { Green: On, Amber: Off, Blue : Off };
@ -25,13 +26,17 @@ public partial class Battery48TlRecord
public Percent Soc => _Soc; 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 BusCurrent => _BusCurrent;
public Current HeatingCurrent => _BusCurrent - _CellsCurrent; public Current HeatingCurrent => _BusCurrent - _CellsCurrent;
public DcPower HeatingPower => HeatingCurrent * Dc.Voltage; public DcPower HeatingPower => HeatingCurrent * Dc.Voltage;
public Boolean CalibrationChargeFlag => TimeSinceTOC > OneWeekInMinutes;
public readonly struct Leds_ public readonly struct Leds_
{ {
@ -42,6 +47,7 @@ public partial class Battery48TlRecord
private Battery48TlRecord Self { get; } private Battery48TlRecord Self { get; }
internal Leds_(Battery48TlRecord self) => this.Self = self; internal Leds_(Battery48TlRecord self) => this.Self = self;
} }
public readonly struct Temperatures_ public readonly struct Temperatures_

View File

@ -23,7 +23,7 @@ public partial class Battery48TlRecord
[InputRegister(1062, Scale = 0.01, Offset = -10000)] private Double _BusCurrent; [InputRegister(1062, Scale = 0.01, Offset = -10000)] private Double _BusCurrent;
[InputRegister(1053, Scale = 0.1)] private Double _Soc; [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(1014, Scale = 0.1, Offset = -400)] private Double _TemperaturesBoard;
[InputRegister(1015, Scale = 0.1, Offset = -400)] private Double _TemperaturesCellsCenter; [InputRegister(1015, Scale = 0.1, Offset = -400)] private Double _TemperaturesCellsCenter;

View File

@ -6,15 +6,16 @@ namespace InnovEnergy.Lib.Devices.Battery48TL;
public class Battery48TlRecords public class Battery48TlRecords
{ {
public required DcBus Dc { get; init; } public required DcBus Dc { get; init; }
public required Boolean Eoc { get; init; } public required Boolean Eoc { get; init; }
public required IReadOnlyList<String> Warnings { get; init; } public required IReadOnlyList<String> Warnings { get; init; }
public required IReadOnlyList<String> Alarms { get; init; } public required IReadOnlyList<String> Alarms { get; init; }
public required Percent Soc { get; init; } public required Percent Soc { get; init; }
public required Percent CurrentMinSoc { get; init; } public required Percent CurrentMinSoc { get; init; }
public required Temperature Temperature { get; init; } public required Temperature Temperature { get; init; }
public required DcPower HeatingPower { get; init; } public required DcPower HeatingPower { get; init; }
public required UInt16 TimeToToc { get; init; } public required UInt16 TimeSinceToc { get; init; }
public required Boolean CalibrationChargeFlag { get; init; }
public required IReadOnlyList<Battery48TlRecord> Devices { get; init; } public required IReadOnlyList<Battery48TlRecord> Devices { get; init; }
@ -25,15 +26,16 @@ public class Battery48TlRecords
return new Battery48TlRecords return new Battery48TlRecords
{ {
Devices = records, Devices = records,
Eoc = records.All(r => r.Eoc), Eoc = records.All(r => r.Eoc),
Warnings = records.SelectMany(r => r.Warnings).Distinct().ToList(), Warnings = records.SelectMany(r => r.Warnings).Distinct().ToList(),
Alarms = records.SelectMany(r => r.Alarms).Distinct().ToList(), Alarms = records.SelectMany(r => r.Alarms).Distinct().ToList(),
Soc = records.Average(r => r.Soc.Value), Soc = records.Average(r => r.Soc.Value),
CurrentMinSoc = records.Min(r => r.Soc.Value), CurrentMinSoc = records.Min(r => r.Soc.Value),
Temperature = records.Average(b => b.Temperatures.Cells.Average.Value), Temperature = records.Average(b => b.Temperatures.Cells.Average.Value),
HeatingPower = records.Sum(b => b.HeatingPower), HeatingPower = records.Sum(b => b.HeatingPower),
TimeToToc = records.Min(r => r.TimeToTOC), TimeSinceToc = records.Max(r => r.TimeSinceTOC),
CalibrationChargeFlag = records.Any(r => r.CalibrationChargeFlag),
Dc = new() Dc = new()
{ {