From 98bdec1a3660330eec34bd0728f909de443c3493 Mon Sep 17 00:00:00 2001 From: atef Date: Thu, 22 Jun 2023 09:50:24 +0200 Subject: [PATCH] Add temperature average to battery record --- .../Devices/Battery48TL/Battery48TlRecord.Api.cs | 13 +++++++------ .../Devices/Battery48TL/Battery48TlRecord.Modbus.cs | 4 ++-- .../Lib/Devices/Battery48TL/Battery48TlRecords.cs | 12 +++++++----- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/csharp/Lib/Devices/Battery48TL/Battery48TlRecord.Api.cs b/csharp/Lib/Devices/Battery48TL/Battery48TlRecord.Api.cs index 9a3f57fad..40d925310 100644 --- a/csharp/Lib/Devices/Battery48TL/Battery48TlRecord.Api.cs +++ b/csharp/Lib/Devices/Battery48TL/Battery48TlRecord.Api.cs @@ -54,10 +54,11 @@ public partial class Battery48TlRecord public readonly struct Cells_ { - public Temperature Center => Self._TemperaturesCellsCenter; - public Temperature Left => Self._TemperaturesCellsLeft; - public Temperature Right => Self._TemperaturesCellsRight; - + public Temperature Center => Self._TemperaturesCellsCenter; + public Temperature Left => Self._TemperaturesCellsLeft; + public Temperature Right => Self._TemperaturesCellsRight; + public Temperature Average => Self._TemperaturesCellsAverage; + internal Cells_(Battery48TlRecord self) => Self = self; private Battery48TlRecord Self { get; } } @@ -73,7 +74,7 @@ public partial class Battery48TlRecord } [SuppressMessage("ReSharper", "StringLiteralTypo")] - internal IEnumerable ParseAlarms() + private IEnumerable ParseAlarms() { Boolean HasBit(Int16 bit) => (_AlarmFlags & 1uL << bit) > 0; @@ -110,7 +111,7 @@ public partial class Battery48TlRecord } [SuppressMessage("ReSharper", "StringLiteralTypo")] - internal IEnumerable ParseWarnings() + private IEnumerable ParseWarnings() { Boolean HasBit(Int16 bit) => (_WarningFlags & 1uL << bit) > 0; diff --git a/csharp/Lib/Devices/Battery48TL/Battery48TlRecord.Modbus.cs b/csharp/Lib/Devices/Battery48TL/Battery48TlRecord.Modbus.cs index e2b92832f..f595e95f8 100644 --- a/csharp/Lib/Devices/Battery48TL/Battery48TlRecord.Modbus.cs +++ b/csharp/Lib/Devices/Battery48TL/Battery48TlRecord.Modbus.cs @@ -11,7 +11,6 @@ namespace InnovEnergy.Lib.Devices.Battery48TL; [SuppressMessage("ReSharper", "UnusedMember.Global")] [SuppressMessage("ReSharper", "UnusedAutoPropertyAccessor.Local")] [BigEndian] -[NestProperties("Battery48TlRecord")] public partial class Battery48TlRecord { [InputRegister(1004)] private UInt16 _LedStates; @@ -28,7 +27,8 @@ public partial class Battery48TlRecord [InputRegister(1015, Scale = 0.1, Offset = -400)] private Double _TemperaturesCellsCenter; [InputRegister(1016, Scale = 0.1, Offset = -400)] private Double _TemperaturesCellsLeft; [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); // public Decimal CellsVoltage { get; init; } diff --git a/csharp/Lib/Devices/Battery48TL/Battery48TlRecords.cs b/csharp/Lib/Devices/Battery48TL/Battery48TlRecords.cs index 516ffc46f..3669d5e9a 100644 --- a/csharp/Lib/Devices/Battery48TL/Battery48TlRecords.cs +++ b/csharp/Lib/Devices/Battery48TL/Battery48TlRecords.cs @@ -9,12 +9,13 @@ public class Battery48TlRecords { var empty = records.Count == 0; - Devices = records; - Eoc = !empty && records.All(r => r.Eoc); - Warnings = records.SelectMany(r => r.Warnings).Distinct().ToList(); - Alarms = records.SelectMany(r => r.Alarms).Distinct().ToList(); + Devices = records; + Eoc = !empty && records.All(r => r.Eoc); + Warnings = records.SelectMany(r => r.Warnings).Distinct().ToList(); + Alarms = records.SelectMany(r => r.Alarms).Distinct().ToList(); Soc = empty ? 0 : records.Min(r => r.Soc.Value); - + Temperature = records.Any() ? records.Average(b => b.Temperatures.Cells.Average.Value) : 0; + Dc = empty ? DcBus.FromVoltageCurrent(0, 0) : DcBus.FromVoltageCurrent @@ -29,6 +30,7 @@ public class Battery48TlRecords public IReadOnlyList Warnings { get; init; } public IReadOnlyList Alarms { get; init; } public Percent Soc { get; init; } + public Temperature Temperature { get; init; } public IReadOnlyList Devices { get; init; }