diff --git a/csharp/App/SaliMax/src/Ess/LedState.cs b/csharp/App/SaliMax/src/Ess/SalimaxAlarmState.cs similarity index 51% rename from csharp/App/SaliMax/src/Ess/LedState.cs rename to csharp/App/SaliMax/src/Ess/SalimaxAlarmState.cs index 4de421c37..3eb4f0d95 100644 --- a/csharp/App/SaliMax/src/Ess/LedState.cs +++ b/csharp/App/SaliMax/src/Ess/SalimaxAlarmState.cs @@ -1,8 +1,8 @@ namespace InnovEnergy.App.SaliMax.Ess; -public enum LedState +public enum SalimaxAlarmState { - Red, + Green, Orange, - Green + Red } \ No newline at end of file diff --git a/csharp/App/SaliMax/src/Ess/SystemLog.cs b/csharp/App/SaliMax/src/Ess/SystemLog.cs index ea4ca0763..da111a77a 100644 --- a/csharp/App/SaliMax/src/Ess/SystemLog.cs +++ b/csharp/App/SaliMax/src/Ess/SystemLog.cs @@ -2,7 +2,7 @@ namespace InnovEnergy.App.SaliMax.Ess; public record SystemLog { - public required String? Message { get; init; } - public required LedState Led { get; init; } + public required String? Message { get; init; } + public required SalimaxAlarmState SalimaxAlarmState { get; init; } } \ No newline at end of file diff --git a/csharp/App/SaliMax/src/Program.cs b/csharp/App/SaliMax/src/Program.cs index d23041ae2..b3cf2c582 100644 --- a/csharp/App/SaliMax/src/Program.cs +++ b/csharp/App/SaliMax/src/Program.cs @@ -152,7 +152,7 @@ internal static class Program StateMachine = StateMachine.Default, EssControl = EssControl.Default, - Log = new SystemLog { Led = LedState.Green, Message = null }, //TODO: Put real stuff + Log = new SystemLog { SalimaxAlarmState = SalimaxAlarmState.Green, Message = null }, //TODO: Put real stuff Config = config // load from disk every iteration, so config can be changed while running }; } @@ -183,45 +183,13 @@ internal static class Program { Watchdog.NotifyAlive(); - var record = ReadStatus(); - - - // var i = 2; - // if (record.Battery is not null) - // { - // foreach (var r in record.Battery.Devices) - // { - // //var y = r.BusCurrentHex; - // //var x = r.CellsCurrentHex; - // - // r.FwVersion.WriteLine(" serial number " + i); - // - // ("--------------").WriteLine(); - // - // i++; - // } - // }i - - - //record.Log = new SystemLog - //{ - // Led = alarmCondition is null ? LedState.Green : LedState.Orange, - // Message = alarmCondition - //}; - - var alarmCondition = record.DetectAlarmStates(); - - if (alarmCondition is not null) - { - alarmCondition.LogInfo(); - } + var record = ReadStatus(); + + var salimaxAlarmsState = GetSalimaxStateAlarm(record); record.ControlConstants(); record.ControlSystemState(); - $"{DateTime.Now.Round(UpdateInterval).ToUnixTime()} : {record.StateMachine.State}: {record.StateMachine.Message}".WriteLine() - .LogInfo(); - var essControl = record.ControlEss().WriteLine().LogInfo(); record.EssControl = essControl; @@ -233,8 +201,11 @@ internal static class Program WriteControl(record); + $"{DateTime.Now.Round(UpdateInterval).ToUnixTime()} : {record.StateMachine.State}: {record.StateMachine.Message}".WriteLine() + .LogInfo(); + record.CreateTopologyTextBlock().WriteLine(); - + (record.Relays is null ? "No relay Data available" : record.Relays.FiWarning ? "Alert: Fi Warning Detected" : "No Fi Warning Detected").WriteLine(); (record.Relays is null ? "No relay Data available" : record.Relays.FiError ? "Alert: Fi Error Detected" : "No Fi Error Detected") .WriteLine(); @@ -248,6 +219,38 @@ internal static class Program // ReSharper disable once FunctionNeverReturns } + private static SalimaxAlarmState GetSalimaxStateAlarm(StatusRecord record) + { + var alarmCondition = record.DetectAlarmStates(); + + if (alarmCondition is not null) + { + alarmCondition.LogInfo(); + } + + // record.Log = new SystemLog + // { + // Led = alarmCondition is null ? LedState.Green : LedState.Red, + // Message = alarmCondition + // }; + + var salimaxAlarmsState = (record.Battery is not null && record.Battery.Warnings.Any()) + | record.AcDc.Warnings.Any() + | record.DcDc.Warnings.Any() + ? SalimaxAlarmState.Orange + : SalimaxAlarmState.Green; // this will be replaced by LedState + + salimaxAlarmsState = (record.Battery is not null && record.Battery.Alarms.Any()) + | record.AcDc.Alarms.Any() + | record.DcDc.Alarms.Any() + | alarmCondition is not null + ? SalimaxAlarmState.Red + : salimaxAlarmsState; // this will be replaced by LedState + + + return salimaxAlarmsState; + } + private static String? DetectAlarmStates(this StatusRecord r) => r.Relays switch { { K2ConnectIslandBusToGridBus: false, K2IslandBusIsConnectedToGridBus: true } => " Contradiction: R0 is opening the K2 but the K2 is still close ",