Add temperature average to battery record

This commit is contained in:
atef 2023-06-22 09:50:24 +02:00
parent 8feee5db43
commit 98bdec1a36
3 changed files with 16 additions and 13 deletions

View File

@ -54,10 +54,11 @@ public partial class Battery48TlRecord
public readonly struct Cells_ public readonly struct Cells_
{ {
public Temperature Center => Self._TemperaturesCellsCenter; public Temperature Center => Self._TemperaturesCellsCenter;
public Temperature Left => Self._TemperaturesCellsLeft; public Temperature Left => Self._TemperaturesCellsLeft;
public Temperature Right => Self._TemperaturesCellsRight; public Temperature Right => Self._TemperaturesCellsRight;
public Temperature Average => Self._TemperaturesCellsAverage;
internal Cells_(Battery48TlRecord self) => Self = self; internal Cells_(Battery48TlRecord self) => Self = self;
private Battery48TlRecord Self { get; } private Battery48TlRecord Self { get; }
} }
@ -73,7 +74,7 @@ public partial class Battery48TlRecord
} }
[SuppressMessage("ReSharper", "StringLiteralTypo")] [SuppressMessage("ReSharper", "StringLiteralTypo")]
internal IEnumerable<String> ParseAlarms() private IEnumerable<String> ParseAlarms()
{ {
Boolean HasBit(Int16 bit) => (_AlarmFlags & 1uL << bit) > 0; Boolean HasBit(Int16 bit) => (_AlarmFlags & 1uL << bit) > 0;
@ -110,7 +111,7 @@ public partial class Battery48TlRecord
} }
[SuppressMessage("ReSharper", "StringLiteralTypo")] [SuppressMessage("ReSharper", "StringLiteralTypo")]
internal IEnumerable<String> ParseWarnings() private IEnumerable<String> ParseWarnings()
{ {
Boolean HasBit(Int16 bit) => (_WarningFlags & 1uL << bit) > 0; Boolean HasBit(Int16 bit) => (_WarningFlags & 1uL << bit) > 0;

View File

@ -11,7 +11,6 @@ namespace InnovEnergy.Lib.Devices.Battery48TL;
[SuppressMessage("ReSharper", "UnusedMember.Global")] [SuppressMessage("ReSharper", "UnusedMember.Global")]
[SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Local")] [SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Local")]
[BigEndian] [BigEndian]
[NestProperties("Battery48TlRecord")]
public partial class Battery48TlRecord public partial class Battery48TlRecord
{ {
[InputRegister(1004)] private UInt16 _LedStates; [InputRegister(1004)] private UInt16 _LedStates;
@ -28,7 +27,8 @@ public partial class Battery48TlRecord
[InputRegister(1015, Scale = 0.1, Offset = -400)] private Double _TemperaturesCellsCenter; [InputRegister(1015, Scale = 0.1, Offset = -400)] private Double _TemperaturesCellsCenter;
[InputRegister(1016, Scale = 0.1, Offset = -400)] private Double _TemperaturesCellsLeft; [InputRegister(1016, Scale = 0.1, Offset = -400)] private Double _TemperaturesCellsLeft;
[InputRegister(1017, Scale = 0.1, Offset = -400)] private Double _TemperaturesCellsRight; [InputRegister(1017, Scale = 0.1, Offset = -400)] private Double _TemperaturesCellsRight;
[InputRegister(1003, Scale = 0.1, Offset = -400)] private Double _TemperaturesCellsAverage;
private LedState ParseLed(LedColor led) => (LedState)((_LedStates >> (Int32)led) & 3); private LedState ParseLed(LedColor led) => (LedState)((_LedStates >> (Int32)led) & 3);
// public Decimal CellsVoltage { get; init; } // public Decimal CellsVoltage { get; init; }

View File

@ -9,12 +9,13 @@ public class Battery48TlRecords
{ {
var empty = records.Count == 0; var empty = records.Count == 0;
Devices = records; Devices = records;
Eoc = !empty && records.All(r => r.Eoc); Eoc = !empty && 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 = empty ? 0 : records.Min(r => r.Soc.Value); Soc = empty ? 0 : records.Min(r => r.Soc.Value);
Temperature = records.Any() ? records.Average(b => b.Temperatures.Cells.Average.Value) : 0;
Dc = empty Dc = empty
? DcBus.FromVoltageCurrent(0, 0) ? DcBus.FromVoltageCurrent(0, 0)
: DcBus.FromVoltageCurrent : DcBus.FromVoltageCurrent
@ -29,6 +30,7 @@ public class Battery48TlRecords
public IReadOnlyList<String> Warnings { get; init; } public IReadOnlyList<String> Warnings { get; init; }
public IReadOnlyList<String> Alarms { get; init; } public IReadOnlyList<String> Alarms { get; init; }
public Percent Soc { get; init; } public Percent Soc { get; init; }
public Temperature Temperature { get; init; }
public IReadOnlyList<Battery48TlRecord> Devices { get; init; } public IReadOnlyList<Battery48TlRecord> Devices { get; init; }