From 88fb93f0955977db96afb5987fee5376cfa9c892 Mon Sep 17 00:00:00 2001 From: atef Date: Tue, 3 Oct 2023 15:58:33 +0200 Subject: [PATCH 01/12] Update Ac3Bus to have on S3 --- csharp/Lib/Units/Composite/Ac3Bus.cs | 39 ++++++++++++++-------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/csharp/Lib/Units/Composite/Ac3Bus.cs b/csharp/Lib/Units/Composite/Ac3Bus.cs index 2301c1d97..917e98f67 100644 --- a/csharp/Lib/Units/Composite/Ac3Bus.cs +++ b/csharp/Lib/Units/Composite/Ac3Bus.cs @@ -3,7 +3,8 @@ using System.Collections; namespace InnovEnergy.Lib.Units.Composite; -public record Ac3Bus : IReadOnlyList +// removed to have it on S3. Find a better solution +public record Ac3Bus // : IReadOnlyList { public required AcPhase L1 { get; init; } public required AcPhase L2 { get; init; } @@ -20,22 +21,22 @@ public record Ac3Bus : IReadOnlyList L3 = AcPhase.Zero, }; - public IEnumerator GetEnumerator() - { - yield return L1; - yield return L2; - yield return L3; - } - - IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - - public Int32 Count => 3; - - public AcPhase this[Int32 index] => index switch - { - 0 => L1, // it's retarded - 1 => L2, - 2 => L3, - _ => throw new ArgumentOutOfRangeException(nameof(index)) - }; + // public IEnumerator GetEnumerator() + // { + // yield return L1; + // yield return L2; + // yield return L3; + // } + // + // IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + // + // public Int32 Count => 3; + // + // public AcPhase this[Int32 index] => index switch + // { + // 0 => L1, // it's retarded + // 1 => L2, + // 2 => L3, + // _ => throw new ArgumentOutOfRangeException(nameof(index)) + // }; } \ No newline at end of file From 1fb95cbb5680895f4767a55a9ad7d565f0f23848 Mon Sep 17 00:00:00 2001 From: atef Date: Tue, 3 Oct 2023 15:59:07 +0200 Subject: [PATCH 02/12] Update the S3 data in config file (in Debug mode) --- csharp/App/SaliMax/src/SystemConfig/Config.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/csharp/App/SaliMax/src/SystemConfig/Config.cs b/csharp/App/SaliMax/src/SystemConfig/Config.cs index fcbd5f869..32468ee0d 100644 --- a/csharp/App/SaliMax/src/SystemConfig/Config.cs +++ b/csharp/App/SaliMax/src/SystemConfig/Config.cs @@ -95,7 +95,15 @@ public class Config //TODO: let IE choose from config files (Json) and connect t BatteryIp = new() { Host = "localhost", Port = 5007}, BatteryNodes = new []{ 2, 3, 4, 5, 6 } }, - S3 = null + S3 = new() + { + Bucket = "1-3e5b3069-214a-43ee-8d85-57d72000c19d", + Region = "sos-ch-dk-2", + Provider = "exo.io", + ContentType = "text/plain; charset=utf-8", + Key = "EXO4ec5faf1a7650b79b5722fb5", + Secret = "LUxu1PGEA-POEIckoEyq6bYyz0RnenW6tmqccMKgkHQ" + }, }; #else public static Config Default => new() From ea5ce5617a5d86e71b0401409fdd8b967be46a3e Mon Sep 17 00:00:00 2001 From: atef Date: Tue, 3 Oct 2023 16:00:28 +0200 Subject: [PATCH 03/12] add loginfo on the toCsv() --- csharp/App/SaliMax/src/Program.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/csharp/App/SaliMax/src/Program.cs b/csharp/App/SaliMax/src/Program.cs index 78c2eeb6d..043bcacf1 100644 --- a/csharp/App/SaliMax/src/Program.cs +++ b/csharp/App/SaliMax/src/Program.cs @@ -316,14 +316,17 @@ internal static class Program private static async Task UploadCsv(StatusRecord status, DateTime timeStamp) { var s3Config = status.Config.S3; + var csv = status.ToCsv().LogInfo(); if (s3Config is null) return false; - var csv = status.ToCsv(); var s3Path = timeStamp + ".csv"; var request = s3Config.CreatePutRequest(s3Path); var response = await request.PutAsync(new StringContent(csv)); + // This is temporary for Wittman + //await File.WriteAllTextAsync("/var/www/html/status.csv", csv.SplitLines().Where(l => !l.Contains("Secret")).JoinLines()); + if (response.StatusCode != 200) { Console.WriteLine("ERROR: PUT"); From 07e0e1f95693fac201645e70cab0dfc2b227aa7f Mon Sep 17 00:00:00 2001 From: atef Date: Tue, 3 Oct 2023 16:00:54 +0200 Subject: [PATCH 04/12] Add time stamp on console --- csharp/App/SaliMax/src/Program.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/csharp/App/SaliMax/src/Program.cs b/csharp/App/SaliMax/src/Program.cs index 043bcacf1..e9a993bf3 100644 --- a/csharp/App/SaliMax/src/Program.cs +++ b/csharp/App/SaliMax/src/Program.cs @@ -174,18 +174,15 @@ internal static class Program // If control Special Error return true, we must stop the system.(break;) var alarmCondition = record.DetectAlarmStates(); - if (alarmCondition is not null) { - //stop the system - //return alarmCondition.LogInfo(); } record.ControlConstants(); record.ControlSystemState(); - $"{record.StateMachine.State}: {record.StateMachine.Message}".LogInfo(); + $"{DateTime.Now} : {record.StateMachine.State}: {record.StateMachine.Message}".WriteLine().LogInfo(); var essControl = record.ControlEss().WriteLine().LogInfo(); From 81ee127d620bf19cab189a576d9d4de21d3b5b3e Mon Sep 17 00:00:00 2001 From: atef Date: Tue, 3 Oct 2023 16:01:17 +0200 Subject: [PATCH 05/12] Update to Unix time --- csharp/App/SaliMax/src/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/csharp/App/SaliMax/src/Program.cs b/csharp/App/SaliMax/src/Program.cs index e9a993bf3..e855fc0d7 100644 --- a/csharp/App/SaliMax/src/Program.cs +++ b/csharp/App/SaliMax/src/Program.cs @@ -310,7 +310,7 @@ internal static class Program sc.ResetAlarmsAndWarnings = true; } - private static async Task UploadCsv(StatusRecord status, DateTime timeStamp) + private static async Task UploadCsv(StatusRecord status, UnixTime timeStamp) { var s3Config = status.Config.S3; var csv = status.ToCsv().LogInfo(); From 7c7fdf1eaed9f2bfbc296edd28c05807028ac8eb Mon Sep 17 00:00:00 2001 From: atef Date: Tue, 3 Oct 2023 16:01:34 +0200 Subject: [PATCH 06/12] Update to unix time 2/2 --- csharp/App/SaliMax/src/Program.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/csharp/App/SaliMax/src/Program.cs b/csharp/App/SaliMax/src/Program.cs index e855fc0d7..871cdbf08 100644 --- a/csharp/App/SaliMax/src/Program.cs +++ b/csharp/App/SaliMax/src/Program.cs @@ -16,6 +16,7 @@ using InnovEnergy.Lib.Devices.Trumpf.TruConvertAc.DataTypes; using InnovEnergy.Lib.Devices.Trumpf.TruConvertDc; using InnovEnergy.Lib.Devices.Trumpf.TruConvertDc.Control; using InnovEnergy.Lib.Protocols.Modbus.Channels; +using InnovEnergy.Lib.Time.Unix; using InnovEnergy.Lib.Units; using InnovEnergy.Lib.Utils; using static InnovEnergy.Lib.Devices.Trumpf.SystemControl.DataTypes.SystemConfig; From 21518ebd8bf9c37ee5cb24bd001f0657f0a8c882 Mon Sep 17 00:00:00 2001 From: atef Date: Wed, 4 Oct 2023 15:14:36 +0200 Subject: [PATCH 07/12] Add host List to git --- csharp/App/SaliMax/HostList.txt | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100755 csharp/App/SaliMax/HostList.txt diff --git a/csharp/App/SaliMax/HostList.txt b/csharp/App/SaliMax/HostList.txt new file mode 100755 index 000000000..41bdeb8c1 --- /dev/null +++ b/csharp/App/SaliMax/HostList.txt @@ -0,0 +1,10 @@ + +Prototype ie-entwicklung@10.2.3.115 +Salimax001 ie-entwicklung@10.2.3.104 +Salimax002 ie-entwicklung@10.2.4.29 +Salimax003 ie-entwicklung@10.2.4.33 +Salimax004 ie-entwicklung@10.2.4.32 +Salimax005 ie-entwicklung@10.2.4.36 +Salimax006 ie-entwicklung@10.2.4.35 +Salimax007 ie-entwicklung@10.2.4.37 +Salimax008 ie-entwicklung@10.2.4.113 \ No newline at end of file From 1afcbfbf4ff7433c6ef51790aefc8c778a9ca0b5 Mon Sep 17 00:00:00 2001 From: atef Date: Wed, 4 Oct 2023 15:15:13 +0200 Subject: [PATCH 08/12] Host list added --- csharp/App/SaliMax/HostList.sh | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100755 csharp/App/SaliMax/HostList.sh diff --git a/csharp/App/SaliMax/HostList.sh b/csharp/App/SaliMax/HostList.sh deleted file mode 100755 index 41bdeb8c1..000000000 --- a/csharp/App/SaliMax/HostList.sh +++ /dev/null @@ -1,10 +0,0 @@ - -Prototype ie-entwicklung@10.2.3.115 -Salimax001 ie-entwicklung@10.2.3.104 -Salimax002 ie-entwicklung@10.2.4.29 -Salimax003 ie-entwicklung@10.2.4.33 -Salimax004 ie-entwicklung@10.2.4.32 -Salimax005 ie-entwicklung@10.2.4.36 -Salimax006 ie-entwicklung@10.2.4.35 -Salimax007 ie-entwicklung@10.2.4.37 -Salimax008 ie-entwicklung@10.2.4.113 \ No newline at end of file From 04bfbfc8b9f856ce17772254deda4bac79958b5a Mon Sep 17 00:00:00 2001 From: atef Date: Wed, 4 Oct 2023 15:17:43 +0200 Subject: [PATCH 09/12] Add Log {Led and Message} for Salimax status and alarm --- csharp/App/SaliMax/src/Ess/LedState.cs | 8 ++++++++ csharp/App/SaliMax/src/Program.cs | 25 +++++++++++++------------ 2 files changed, 21 insertions(+), 12 deletions(-) create mode 100644 csharp/App/SaliMax/src/Ess/LedState.cs diff --git a/csharp/App/SaliMax/src/Ess/LedState.cs b/csharp/App/SaliMax/src/Ess/LedState.cs new file mode 100644 index 000000000..4de421c37 --- /dev/null +++ b/csharp/App/SaliMax/src/Ess/LedState.cs @@ -0,0 +1,8 @@ +namespace InnovEnergy.App.SaliMax.Ess; + +public enum LedState +{ + Red, + Orange, + Green +} \ No newline at end of file diff --git a/csharp/App/SaliMax/src/Program.cs b/csharp/App/SaliMax/src/Program.cs index 871cdbf08..e768cb80c 100644 --- a/csharp/App/SaliMax/src/Program.cs +++ b/csharp/App/SaliMax/src/Program.cs @@ -114,24 +114,25 @@ internal static class Program return new StatusRecord { - AcDc = acDc, - DcDc = dcDc, - Battery = battery, - Relays = relays, - GridMeter = gridMeter, + AcDc = acDc, + DcDc = dcDc, + Battery = battery, + Relays = relays, + GridMeter = gridMeter, - PvOnAcGrid = pvOnAcGrid, - PvOnAcIsland = pvOnAcIsland, - PvOnDc = pvOnDc, + PvOnAcGrid = pvOnAcGrid, + PvOnAcIsland = pvOnAcIsland, + PvOnDc = pvOnDc, AcGridToAcIsland = gridBusToIslandBus, LoadOnAcGrid = gridBusLoad, LoadOnAcIsland = loadOnAcIsland, LoadOnDc = dcLoad, - StateMachine = StateMachine.Default, - EssControl = EssControl.Default, - Config = Config.Load() // load from disk every iteration, so config can be changed while running + StateMachine = StateMachine.Default, + EssControl = EssControl.Default, + Log = new SystemLog{Led = LedState.Green, Message = null}, //TODO: Put real stuff + Config = Config.Load() // load from disk every iteration, so config can be changed while running }; } @@ -183,7 +184,7 @@ internal static class Program record.ControlConstants(); record.ControlSystemState(); - $"{DateTime.Now} : {record.StateMachine.State}: {record.StateMachine.Message}".WriteLine().LogInfo(); + $"{UnixTime.Now} : {record.StateMachine.State}: {record.StateMachine.Message}".WriteLine().LogInfo(); var essControl = record.ControlEss().WriteLine().LogInfo(); From 649c8b37e85d7a69028db1f1c29cddc39e87f7e5 Mon Sep 17 00:00:00 2001 From: atef Date: Wed, 4 Oct 2023 15:18:45 +0200 Subject: [PATCH 10/12] Add new battery reading for current abd bus current to test the heating current --- .../Devices/Battery48TL/Battery48TlRecord.Api.cs | 13 +++++++++---- .../Devices/Battery48TL/Battery48TlRecord.Modbus.cs | 4 ++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/csharp/Lib/Devices/Battery48TL/Battery48TlRecord.Api.cs b/csharp/Lib/Devices/Battery48TL/Battery48TlRecord.Api.cs index c5908b95d..ec8bdf9e7 100644 --- a/csharp/Lib/Devices/Battery48TL/Battery48TlRecord.Api.cs +++ b/csharp/Lib/Devices/Battery48TL/Battery48TlRecord.Api.cs @@ -28,12 +28,17 @@ public partial class Battery48TlRecord public Percent Soc => _Soc; + public Current BusCurrent => _BusCurrent; + public UInt16 BusCurrentHex => _BusCurrentHex; + + public UInt16 CellsCurrentHex => _CellsCurrentHex; + + public Current HeatingCurrent => _BusCurrent - _CellsCurrent; + public DcPower HeatingPower => HeatingCurrent * Dc.Voltage; + // 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 TimeSpan TimeSinceTOC => TimeSpan.FromMinutes(_TimeSinceToc); - public Current BusCurrent => _BusCurrent; - public Current HeatingCurrent => _BusCurrent - _CellsCurrent; - public DcPower HeatingPower => HeatingCurrent * Dc.Voltage; public Boolean CalibrationChargeRequested => TimeSinceTOC > TimeSpan.FromDays(7); @@ -215,4 +220,4 @@ public partial class Battery48TlRecord } } } - + diff --git a/csharp/Lib/Devices/Battery48TL/Battery48TlRecord.Modbus.cs b/csharp/Lib/Devices/Battery48TL/Battery48TlRecord.Modbus.cs index 312017c89..8d7882710 100644 --- a/csharp/Lib/Devices/Battery48TL/Battery48TlRecord.Modbus.cs +++ b/csharp/Lib/Devices/Battery48TL/Battery48TlRecord.Modbus.cs @@ -20,7 +20,11 @@ public partial class Battery48TlRecord [InputRegister(999, Scale = 0.01)] private Double _CellsVoltage; [InputRegister(1001, Scale = 0.01)] private Double _BusVoltage; [InputRegister(1000, Scale = 0.01, Offset = -10000)] private Double _CellsCurrent; + [InputRegister(1000)] private UInt16 _CellsCurrentHex; + + [InputRegister(1062, Scale = 0.01, Offset = -10000)] private Double _BusCurrent; + [InputRegister(1062)] private UInt16 _BusCurrentHex; [InputRegister(1053, Scale = 0.1)] private Double _Soc; [InputRegister(1052)] private UInt16 _TimeSinceToc; From 358b1f0ec13a9cf827d54e9d9c235a226dbe6f09 Mon Sep 17 00:00:00 2001 From: atef Date: Wed, 4 Oct 2023 15:19:41 +0200 Subject: [PATCH 11/12] Add System Log to the statusRecord --- csharp/App/SaliMax/src/Ess/StatusRecord.cs | 3 ++- csharp/App/SaliMax/src/Ess/SystemLog.cs | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 csharp/App/SaliMax/src/Ess/SystemLog.cs diff --git a/csharp/App/SaliMax/src/Ess/StatusRecord.cs b/csharp/App/SaliMax/src/Ess/StatusRecord.cs index fde5998e1..0d0a1da63 100644 --- a/csharp/App/SaliMax/src/Ess/StatusRecord.cs +++ b/csharp/App/SaliMax/src/Ess/StatusRecord.cs @@ -25,7 +25,8 @@ public record StatusRecord public required RelaysRecord? Relays { get; init; } public required AmptStatus? PvOnDc { get; init; } public required Config Config { get; init; } + public required SystemLog Log { get; set; } // TODO: init only public required EssControl EssControl { get; set; } // TODO: init only public required StateMachine StateMachine { get; init; } -} +} \ No newline at end of file diff --git a/csharp/App/SaliMax/src/Ess/SystemLog.cs b/csharp/App/SaliMax/src/Ess/SystemLog.cs new file mode 100644 index 000000000..ea4ca0763 --- /dev/null +++ b/csharp/App/SaliMax/src/Ess/SystemLog.cs @@ -0,0 +1,8 @@ +namespace InnovEnergy.App.SaliMax.Ess; + +public record SystemLog +{ + public required String? Message { get; init; } + public required LedState Led { get; init; } + +} \ No newline at end of file From d56abb49500d89b631703a2e99a864ff968a95e9 Mon Sep 17 00:00:00 2001 From: atef Date: Thu, 5 Oct 2023 12:53:38 +0200 Subject: [PATCH 12/12] take off the space between the Serial Number --- csharp/Lib/Devices/Battery48TL/Battery48TlRecord.Api.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/csharp/Lib/Devices/Battery48TL/Battery48TlRecord.Api.cs b/csharp/Lib/Devices/Battery48TL/Battery48TlRecord.Api.cs index ec8bdf9e7..29a35e283 100644 --- a/csharp/Lib/Devices/Battery48TL/Battery48TlRecord.Api.cs +++ b/csharp/Lib/Devices/Battery48TL/Battery48TlRecord.Api.cs @@ -20,7 +20,7 @@ public partial class Battery48TlRecord public Boolean Eoc => Leds is { Green: On, Amber: Off, Blue : Off }; - public String SerialNumber => $"{_SerialNum1:X4} {_SerialNum2:X4} {_SerialNum3:X4} {_SerialNum4:X4}".TrimStart('0'); + public String SerialNumber => $"{_SerialNum1:X4}{_SerialNum2:X4}{_SerialNum3:X4}{_SerialNum4:X4}".TrimEnd('0'); public String FwVersion => _FwVersion.ToString("X4"); public Strings Warnings => ParseWarnings().OrderBy(w => w).ToList(); @@ -219,5 +219,4 @@ public partial class Battery48TlRecord return Math.Min(pLimit, 0); } } -} - +} \ No newline at end of file