Update the statusMessage and edit the required changes in the informmiddleware function
This commit is contained in:
parent
229321cd1c
commit
6301cf38a0
|
@ -3,9 +3,8 @@ namespace InnovEnergy.App.SaliMax.MiddlewareClasses;
|
|||
|
||||
public class StatusMessage
|
||||
{
|
||||
|
||||
public required Int32 InstallationId { get; set; }
|
||||
public required Int32 Status { get; set; }
|
||||
public List<AlarmOrWarning> Warnings { get; set; }
|
||||
public List<AlarmOrWarning> Alarms { get; set; }
|
||||
public required Int32 InstallationId { get; set; }
|
||||
public required Int32 Status { get; set; }
|
||||
public List<AlarmOrWarning>? Warnings { get; set; }
|
||||
public List<AlarmOrWarning>? Alarms { get; set; }
|
||||
}
|
|
@ -59,7 +59,7 @@ internal static class Program
|
|||
private static IModel? _channel;
|
||||
private static Boolean _subscribedToQueue = false;
|
||||
private static Boolean _subscribeToQueueForTheFirstTime = false;
|
||||
private static SalimaxAlarmState _prevSalimaxState = SalimaxAlarmState.Green;
|
||||
private static Int32 _prevSalimaxState = 0; // 0 is a green status
|
||||
|
||||
static Program()
|
||||
{
|
||||
|
@ -257,7 +257,7 @@ internal static class Program
|
|||
// ReSharper disable once FunctionNeverReturns
|
||||
}
|
||||
|
||||
private static void SendSalimaxStateAlarm(SalimaxAlarmState currentSalimaxState)
|
||||
private static void SendSalimaxStateAlarm(StatusMessage currentSalimaxState)
|
||||
{
|
||||
var s3Bucket = Config.Load().S3?.Bucket;
|
||||
|
||||
|
@ -267,17 +267,17 @@ internal static class Program
|
|||
_subscribeToQueueForTheFirstTime = true;
|
||||
SubscribeToQueue(currentSalimaxState, s3Bucket);
|
||||
|
||||
if (_subscribedToQueue && currentSalimaxState != _prevSalimaxState)
|
||||
if (_subscribedToQueue && currentSalimaxState.Status != _prevSalimaxState)
|
||||
{
|
||||
_prevSalimaxState = currentSalimaxState;
|
||||
_prevSalimaxState = currentSalimaxState.Status;
|
||||
}
|
||||
}
|
||||
//If already subscribed to the queue and the status has been changed, update the queue
|
||||
else if (_subscribedToQueue && currentSalimaxState != _prevSalimaxState)
|
||||
else if (_subscribedToQueue && currentSalimaxState.Status != _prevSalimaxState)
|
||||
{
|
||||
_prevSalimaxState = currentSalimaxState;
|
||||
_prevSalimaxState = currentSalimaxState.Status;
|
||||
if (s3Bucket != null)
|
||||
InformMiddleware(s3Bucket, (Int32)currentSalimaxState);
|
||||
InformMiddleware(s3Bucket, currentSalimaxState);
|
||||
}
|
||||
|
||||
//If there is an available message from the RabbitMQ Broker, subscribe to the queue
|
||||
|
@ -301,7 +301,7 @@ internal static class Program
|
|||
}
|
||||
}
|
||||
|
||||
private static void SubscribeToQueue(SalimaxAlarmState currentSalimaxState, String? s3Bucket)
|
||||
private static void SubscribeToQueue(StatusMessage currentSalimaxState, String? s3Bucket)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
@ -313,7 +313,7 @@ internal static class Program
|
|||
|
||||
Console.WriteLine("The controller sends its status to the middleware for the first time");
|
||||
|
||||
if (s3Bucket != null) InformMiddleware(s3Bucket, (Int32)currentSalimaxState);
|
||||
if (s3Bucket != null) InformMiddleware(s3Bucket, currentSalimaxState);
|
||||
|
||||
_subscribedToQueue = true;
|
||||
}
|
||||
|
@ -345,32 +345,12 @@ internal static class Program
|
|||
return IPAddress.None;
|
||||
}
|
||||
|
||||
private static void InformMiddleware(String? bucket, int status)
|
||||
private static void InformMiddleware(String? bucket, StatusMessage status)
|
||||
{
|
||||
int.TryParse(bucket[0].ToString(), out var installationId);
|
||||
var jsonObject = new StatusMessage
|
||||
{
|
||||
InstallationId = installationId,
|
||||
Status = status,
|
||||
};
|
||||
|
||||
if (status == 2)
|
||||
{
|
||||
jsonObject.Date = DateTime.Now.ToString("yyyy-MM-dd");
|
||||
jsonObject.Time = DateTime.Now.ToString("HH:mm:ss");
|
||||
jsonObject.Description = "Battery Overvoltage";
|
||||
jsonObject.CreatedBy = "Battery/4";
|
||||
}
|
||||
else if (status == 1)
|
||||
{
|
||||
jsonObject.Date = DateTime.Now.ToString("yyyy-MM-dd");
|
||||
jsonObject.Time = DateTime.Now.ToString("HH:mm:ss");
|
||||
jsonObject.Description = "Temp warning message";
|
||||
jsonObject.CreatedBy = "Battery/4";
|
||||
}
|
||||
|
||||
var message = JsonSerializer.Serialize(jsonObject);
|
||||
var body = Encoding.UTF8.GetBytes(message);
|
||||
var message = JsonSerializer.Serialize(status);
|
||||
var body = Encoding.UTF8.GetBytes(message);
|
||||
|
||||
_channel.BasicPublish(exchange: string.Empty,
|
||||
routingKey: "statusQueue",
|
||||
|
@ -380,38 +360,125 @@ internal static class Program
|
|||
Console.WriteLine($"Producer sent message: {message}");
|
||||
}
|
||||
|
||||
private static SalimaxAlarmState GetSalimaxStateAlarm(StatusRecord record)
|
||||
private static StatusMessage GetSalimaxStateAlarm(StatusRecord record)
|
||||
{
|
||||
var alarmCondition = record.DetectAlarmStates();
|
||||
var s3Bucket = Config.Load().S3?.Bucket;
|
||||
|
||||
var alarmList = new List<AlarmOrWarning>();
|
||||
var warningList = new List<AlarmOrWarning>();
|
||||
|
||||
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.AcDc.SystemControl.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.AcDc.SystemControl.Alarms.Any()
|
||||
| record.DcDc.Alarms.Any()
|
||||
| alarmCondition is not null
|
||||
? SalimaxAlarmState.Red
|
||||
: salimaxAlarmsState; // this will be replaced by LedState
|
||||
|
||||
|
||||
return salimaxAlarmsState;
|
||||
alarmList.Add(new AlarmOrWarning
|
||||
{
|
||||
Date = DateTime.Now.ToString("yyyy-MM-dd"),
|
||||
Time = DateTime.Now.ToString("HH:mm:ss"),
|
||||
CreatedBy = "Salimax",
|
||||
Description = alarmCondition
|
||||
});
|
||||
}
|
||||
|
||||
foreach (var alarm in record.AcDc.Alarms)
|
||||
{
|
||||
alarmList.Add(new AlarmOrWarning
|
||||
{
|
||||
Date = DateTime.Now.ToString("yyyy-MM-dd"),
|
||||
Time = DateTime.Now.ToString("HH:mm:ss"),
|
||||
CreatedBy = "AcDc",
|
||||
Description = alarm.ToString()
|
||||
});
|
||||
}
|
||||
|
||||
foreach (var alarm in record.DcDc.Alarms)
|
||||
{
|
||||
alarmList.Add(new AlarmOrWarning
|
||||
{
|
||||
Date = DateTime.Now.ToString("yyyy-MM-dd"),
|
||||
Time = DateTime.Now.ToString("HH:mm:ss"),
|
||||
CreatedBy = "DcDc",
|
||||
Description = alarm.ToString()
|
||||
});
|
||||
}
|
||||
|
||||
if (record.Battery != null)
|
||||
{
|
||||
foreach (var alarm in record.Battery.Alarms)
|
||||
{
|
||||
alarmList.Add(new AlarmOrWarning
|
||||
{
|
||||
Date = DateTime.Now.ToString("yyyy-MM-dd"),
|
||||
Time = DateTime.Now.ToString("HH:mm:ss"),
|
||||
CreatedBy = "Battery",
|
||||
Description = alarm
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var warning in record.AcDc.Alarms)
|
||||
{
|
||||
warningList.Add(new AlarmOrWarning
|
||||
{
|
||||
Date = DateTime.Now.ToString("yyyy-MM-dd"),
|
||||
Time = DateTime.Now.ToString("HH:mm:ss"),
|
||||
CreatedBy = "AcDc",
|
||||
Description = warning.ToString()
|
||||
});
|
||||
}
|
||||
|
||||
foreach (var warning in record.DcDc.Alarms)
|
||||
{
|
||||
warningList.Add(new AlarmOrWarning
|
||||
{
|
||||
Date = DateTime.Now.ToString("yyyy-MM-dd"),
|
||||
Time = DateTime.Now.ToString("HH:mm:ss"),
|
||||
CreatedBy = "DcDc",
|
||||
Description = warning.ToString()
|
||||
});
|
||||
}
|
||||
|
||||
if (record.Battery != null)
|
||||
{
|
||||
foreach (var warning in record.Battery.Alarms)
|
||||
{
|
||||
warningList.Add(new AlarmOrWarning
|
||||
{
|
||||
Date = DateTime.Now.ToString("yyyy-MM-dd"),
|
||||
Time = DateTime.Now.ToString("HH:mm:ss"),
|
||||
CreatedBy = "Battery",
|
||||
Description = warning
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
var salimaxAlarmsState = (record.Battery is not null && record.Battery.Warnings.Any())
|
||||
| record.AcDc.Warnings.Any()
|
||||
| record.AcDc.SystemControl.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.AcDc.SystemControl.Alarms.Any()
|
||||
| record.DcDc.Alarms.Any()
|
||||
| alarmCondition is not null
|
||||
? SalimaxAlarmState.Red
|
||||
: salimaxAlarmsState; // this will be replaced by LedState
|
||||
|
||||
int.TryParse(s3Bucket[0].ToString(), out var installationId);
|
||||
|
||||
var returnedStatus = new StatusMessage
|
||||
{
|
||||
InstallationId = installationId,
|
||||
Status = (Int16)salimaxAlarmsState,
|
||||
Alarms = alarmList,
|
||||
Warnings = warningList
|
||||
};
|
||||
|
||||
return returnedStatus;
|
||||
}
|
||||
|
||||
private static String? DetectAlarmStates(this StatusRecord r) => r.Relays switch
|
||||
|
|
Loading…
Reference in New Issue