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 class StatusMessage
|
||||||
{
|
{
|
||||||
|
|
||||||
public required Int32 InstallationId { get; set; }
|
public required Int32 InstallationId { get; set; }
|
||||||
public required Int32 Status { get; set; }
|
public required Int32 Status { get; set; }
|
||||||
public List<AlarmOrWarning> Warnings { get; set; }
|
public List<AlarmOrWarning>? Warnings { get; set; }
|
||||||
public List<AlarmOrWarning> Alarms { get; set; }
|
public List<AlarmOrWarning>? Alarms { get; set; }
|
||||||
}
|
}
|
|
@ -59,7 +59,7 @@ internal static class Program
|
||||||
private static IModel? _channel;
|
private static IModel? _channel;
|
||||||
private static Boolean _subscribedToQueue = false;
|
private static Boolean _subscribedToQueue = false;
|
||||||
private static Boolean _subscribeToQueueForTheFirstTime = false;
|
private static Boolean _subscribeToQueueForTheFirstTime = false;
|
||||||
private static SalimaxAlarmState _prevSalimaxState = SalimaxAlarmState.Green;
|
private static Int32 _prevSalimaxState = 0; // 0 is a green status
|
||||||
|
|
||||||
static Program()
|
static Program()
|
||||||
{
|
{
|
||||||
|
@ -257,7 +257,7 @@ internal static class Program
|
||||||
// ReSharper disable once FunctionNeverReturns
|
// ReSharper disable once FunctionNeverReturns
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void SendSalimaxStateAlarm(SalimaxAlarmState currentSalimaxState)
|
private static void SendSalimaxStateAlarm(StatusMessage currentSalimaxState)
|
||||||
{
|
{
|
||||||
var s3Bucket = Config.Load().S3?.Bucket;
|
var s3Bucket = Config.Load().S3?.Bucket;
|
||||||
|
|
||||||
|
@ -267,17 +267,17 @@ internal static class Program
|
||||||
_subscribeToQueueForTheFirstTime = true;
|
_subscribeToQueueForTheFirstTime = true;
|
||||||
SubscribeToQueue(currentSalimaxState, s3Bucket);
|
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
|
//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)
|
if (s3Bucket != null)
|
||||||
InformMiddleware(s3Bucket, (Int32)currentSalimaxState);
|
InformMiddleware(s3Bucket, currentSalimaxState);
|
||||||
}
|
}
|
||||||
|
|
||||||
//If there is an available message from the RabbitMQ Broker, subscribe to the queue
|
//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
|
try
|
||||||
{
|
{
|
||||||
|
@ -313,7 +313,7 @@ internal static class Program
|
||||||
|
|
||||||
Console.WriteLine("The controller sends its status to the middleware for the first time");
|
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;
|
_subscribedToQueue = true;
|
||||||
}
|
}
|
||||||
|
@ -345,31 +345,11 @@ internal static class Program
|
||||||
return IPAddress.None;
|
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);
|
int.TryParse(bucket[0].ToString(), out var installationId);
|
||||||
var jsonObject = new StatusMessage
|
|
||||||
{
|
|
||||||
InstallationId = installationId,
|
|
||||||
Status = status,
|
|
||||||
};
|
|
||||||
|
|
||||||
if (status == 2)
|
var message = JsonSerializer.Serialize(status);
|
||||||
{
|
|
||||||
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 body = Encoding.UTF8.GetBytes(message);
|
||||||
|
|
||||||
_channel.BasicPublish(exchange: string.Empty,
|
_channel.BasicPublish(exchange: string.Empty,
|
||||||
|
@ -380,20 +360,98 @@ internal static class Program
|
||||||
Console.WriteLine($"Producer sent message: {message}");
|
Console.WriteLine($"Producer sent message: {message}");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static SalimaxAlarmState GetSalimaxStateAlarm(StatusRecord record)
|
private static StatusMessage GetSalimaxStateAlarm(StatusRecord record)
|
||||||
{
|
{
|
||||||
var alarmCondition = record.DetectAlarmStates();
|
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)
|
if (alarmCondition is not null)
|
||||||
{
|
{
|
||||||
alarmCondition.LogInfo();
|
alarmCondition.LogInfo();
|
||||||
|
|
||||||
|
alarmList.Add(new AlarmOrWarning
|
||||||
|
{
|
||||||
|
Date = DateTime.Now.ToString("yyyy-MM-dd"),
|
||||||
|
Time = DateTime.Now.ToString("HH:mm:ss"),
|
||||||
|
CreatedBy = "Salimax",
|
||||||
|
Description = alarmCondition
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// record.Log = new SystemLog
|
foreach (var alarm in record.AcDc.Alarms)
|
||||||
// {
|
{
|
||||||
// Led = alarmCondition is null ? LedState.Green : LedState.Red,
|
alarmList.Add(new AlarmOrWarning
|
||||||
// Message = alarmCondition
|
{
|
||||||
// };
|
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())
|
var salimaxAlarmsState = (record.Battery is not null && record.Battery.Warnings.Any())
|
||||||
| record.AcDc.Warnings.Any()
|
| record.AcDc.Warnings.Any()
|
||||||
|
@ -410,8 +468,17 @@ internal static class Program
|
||||||
? SalimaxAlarmState.Red
|
? SalimaxAlarmState.Red
|
||||||
: salimaxAlarmsState; // this will be replaced by LedState
|
: salimaxAlarmsState; // this will be replaced by LedState
|
||||||
|
|
||||||
|
int.TryParse(s3Bucket[0].ToString(), out var installationId);
|
||||||
|
|
||||||
return salimaxAlarmsState;
|
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
|
private static String? DetectAlarmStates(this StatusRecord r) => r.Relays switch
|
||||||
|
|
Loading…
Reference in New Issue