Change LedState to SalimaxAlarmState.

Create a GetSalimaxStateAlarm that return the salimax state alarm
This commit is contained in:
atef 2023-11-02 13:42:26 +01:00
parent 8d67bea146
commit a59051dcc1
3 changed files with 45 additions and 42 deletions

View File

@ -1,8 +1,8 @@
namespace InnovEnergy.App.SaliMax.Ess;
public enum LedState
public enum SalimaxAlarmState
{
Red,
Green,
Orange,
Green
Red
}

View File

@ -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; }
}

View File

@ -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 ",