Change LedState to SalimaxAlarmState.
Create a GetSalimaxStateAlarm that return the salimax state alarm
This commit is contained in:
parent
8d67bea146
commit
a59051dcc1
|
@ -1,8 +1,8 @@
|
||||||
namespace InnovEnergy.App.SaliMax.Ess;
|
namespace InnovEnergy.App.SaliMax.Ess;
|
||||||
|
|
||||||
public enum LedState
|
public enum SalimaxAlarmState
|
||||||
{
|
{
|
||||||
Red,
|
Green,
|
||||||
Orange,
|
Orange,
|
||||||
Green
|
Red
|
||||||
}
|
}
|
|
@ -3,6 +3,6 @@ namespace InnovEnergy.App.SaliMax.Ess;
|
||||||
public record SystemLog
|
public record SystemLog
|
||||||
{
|
{
|
||||||
public required String? Message { get; init; }
|
public required String? Message { get; init; }
|
||||||
public required LedState Led { get; init; }
|
public required SalimaxAlarmState SalimaxAlarmState { get; init; }
|
||||||
|
|
||||||
}
|
}
|
|
@ -152,7 +152,7 @@ internal static class Program
|
||||||
|
|
||||||
StateMachine = StateMachine.Default,
|
StateMachine = StateMachine.Default,
|
||||||
EssControl = EssControl.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
|
Config = config // load from disk every iteration, so config can be changed while running
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -185,43 +185,11 @@ internal static class Program
|
||||||
|
|
||||||
var record = ReadStatus();
|
var record = ReadStatus();
|
||||||
|
|
||||||
|
var salimaxAlarmsState = GetSalimaxStateAlarm(record);
|
||||||
// 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();
|
|
||||||
}
|
|
||||||
|
|
||||||
record.ControlConstants();
|
record.ControlConstants();
|
||||||
record.ControlSystemState();
|
record.ControlSystemState();
|
||||||
|
|
||||||
$"{DateTime.Now.Round(UpdateInterval).ToUnixTime()} : {record.StateMachine.State}: {record.StateMachine.Message}".WriteLine()
|
|
||||||
.LogInfo();
|
|
||||||
|
|
||||||
var essControl = record.ControlEss().WriteLine().LogInfo();
|
var essControl = record.ControlEss().WriteLine().LogInfo();
|
||||||
|
|
||||||
record.EssControl = essControl;
|
record.EssControl = essControl;
|
||||||
|
@ -233,6 +201,9 @@ internal static class Program
|
||||||
|
|
||||||
WriteControl(record);
|
WriteControl(record);
|
||||||
|
|
||||||
|
$"{DateTime.Now.Round(UpdateInterval).ToUnixTime()} : {record.StateMachine.State}: {record.StateMachine.Message}".WriteLine()
|
||||||
|
.LogInfo();
|
||||||
|
|
||||||
record.CreateTopologyTextBlock().WriteLine();
|
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.FiWarning ? "Alert: Fi Warning Detected" : "No Fi Warning Detected").WriteLine();
|
||||||
|
@ -248,6 +219,38 @@ internal static class Program
|
||||||
// ReSharper disable once FunctionNeverReturns
|
// 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
|
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 ",
|
{ K2ConnectIslandBusToGridBus: false, K2IslandBusIsConnectedToGridBus: true } => " Contradiction: R0 is opening the K2 but the K2 is still close ",
|
||||||
|
|
Loading…
Reference in New Issue