Change from control special error to Detect Alarm States

Add loginfo to toCsv()
This commit is contained in:
atef 2023-10-02 14:49:24 +02:00
parent 3affba7899
commit b1d553870e
2 changed files with 13 additions and 35 deletions

View File

@ -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<Boolean> 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));

View File

@ -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();