From b1d553870e3b1d24f6bcfc4c2e32b674c21c43dd Mon Sep 17 00:00:00 2001 From: atef Date: Mon, 2 Oct 2023 14:49:24 +0200 Subject: [PATCH] Change from control special error to Detect Alarm States Add loginfo to toCsv() --- csharp/App/SaliMax/src/Program.cs | 46 +++++-------------- .../Battery48TL/Battery48TlRecord.Api.cs | 2 +- 2 files changed, 13 insertions(+), 35 deletions(-) diff --git a/csharp/App/SaliMax/src/Program.cs b/csharp/App/SaliMax/src/Program.cs index 6c778dc89..5e2ec5581 100644 --- a/csharp/App/SaliMax/src/Program.cs +++ b/csharp/App/SaliMax/src/Program.cs @@ -172,13 +172,14 @@ internal static class Program var record = ReadStatus(); // If control Special Error return true, we must stop the system.(break;) - var specialErrorOccured = record.ControlSpecialError(); - - if (specialErrorOccured.Item1) + var alarmCondition = record.DetectAlarmStates(); + + + if (alarmCondition is not null) { //stop the system //return - specialErrorOccured.Item2.WriteLine(); + alarmCondition.LogInfo(); } record.ControlConstants(); @@ -212,36 +213,13 @@ internal static class Program // ReSharper disable once FunctionNeverReturns } - private static (Boolean, String) ControlSpecialError (this StatusRecord r) // to find a better name + private static String? DetectAlarmStates(this StatusRecord r) => r.Relays switch { - // Those errors must not occurs. Stop the system in case this is happen. - var isSpecialErrorOccured = false; - var errorMessage = "No Error"; - - // 1. relay0 is open and K2 Close. - if (r.Relays is { K2ConnectIslandBusToGridBus: false, K2IslandBusIsConnectedToGridBus: true } ) - { - isSpecialErrorOccured = true; - errorMessage = " Contradiction: R0 is opening the K2 but the K2 is still close "; - } - - // 2. If K1 is open, K2 must be open . - if (r.Relays is { K1GridBusIsConnectedToGrid: false, K2IslandBusIsConnectedToGridBus: true } ) - { - isSpecialErrorOccured = true; - errorMessage = " Contradiction: K1 is open but the K2 is still close "; - } - - // 3. If FI error is occured, K2 must be open. - if (r.Relays is { FiError: true, K2IslandBusIsConnectedToGridBus: true } ) - { - isSpecialErrorOccured = true; - errorMessage = " Contradiction: Fi error occured but the K2 is still close "; - } - - - return (isSpecialErrorOccured, errorMessage); - } + { K2ConnectIslandBusToGridBus: false, K2IslandBusIsConnectedToGridBus: true } => " Contradiction: R0 is opening the K2 but the K2 is still close ", + { K1GridBusIsConnectedToGrid : false, K2IslandBusIsConnectedToGridBus: true } => " Contradiction: K1 is open but the K2 is still close ", + { FiError: true, K2IslandBusIsConnectedToGridBus: true } => " Contradiction: Fi error occured but the K2 is still close ", + _ => null + }; private static void ControlConstants(this StatusRecord r) { @@ -338,10 +316,10 @@ internal static class Program private static async Task UploadCsv(StatusRecord status, UnixTime timeStamp) { var s3Config = status.Config.S3; + var csv = status.ToCsv().LogInfo(); if (s3Config is null) return false; - var csv = status.ToCsv().LogInfo(); var s3Path = timeStamp + ".csv"; var request = s3Config.CreatePutRequest(s3Path); var response = await request.PutAsync(new StringContent(csv)); diff --git a/csharp/Lib/Devices/Battery48TL/Battery48TlRecord.Api.cs b/csharp/Lib/Devices/Battery48TL/Battery48TlRecord.Api.cs index 56e43bc9a..c5908b95d 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:D4}{_SerialNum2:D4}{_SerialNum3:D4}{_SerialNum4:D4}".TrimStart('0'); + public String SerialNumber => $"{_SerialNum1:X4} {_SerialNum2:X4} {_SerialNum3:X4} {_SerialNum4:X4}".TrimStart('0'); public String FwVersion => _FwVersion.ToString("X4"); public Strings Warnings => ParseWarnings().OrderBy(w => w).ToList();