Add a communication to the middelware
This commit is contained in:
parent
22ad7b3612
commit
15d0eac3c5
|
@ -36,6 +36,7 @@ namespace InnovEnergy.App.SaliMax;
|
||||||
internal static class Program
|
internal static class Program
|
||||||
{
|
{
|
||||||
private static readonly TimeSpan UpdateInterval = TimeSpan.FromSeconds(2);
|
private static readonly TimeSpan UpdateInterval = TimeSpan.FromSeconds(2);
|
||||||
|
|
||||||
private static readonly IReadOnlyList<Byte> BatteryNodes;
|
private static readonly IReadOnlyList<Byte> BatteryNodes;
|
||||||
|
|
||||||
private static readonly Channel TruConvertAcChannel ;
|
private static readonly Channel TruConvertAcChannel ;
|
||||||
|
@ -50,11 +51,11 @@ internal static class Program
|
||||||
|
|
||||||
private static IPAddress _controllerIpAddress;
|
private static IPAddress _controllerIpAddress;
|
||||||
private static UdpClient _udpListener;
|
private static UdpClient _udpListener;
|
||||||
private const string VpnServerIp = "10.2.0.11";
|
private const String VpnServerIp = "10.2.0.11";
|
||||||
private static ConnectionFactory? _factory ;
|
private static ConnectionFactory? _factory ;
|
||||||
private static IConnection ? _connection;
|
private static IConnection ? _connection;
|
||||||
private static IModel? _channel;
|
private static IModel? _channel;
|
||||||
private static bool _subscribedToQueue = false;
|
private static Boolean _subscribedToQueue = false;
|
||||||
private static SalimaxAlarmState _prevSalimaxState = SalimaxAlarmState.Orange;
|
private static SalimaxAlarmState _prevSalimaxState = SalimaxAlarmState.Orange;
|
||||||
|
|
||||||
static Program()
|
static Program()
|
||||||
|
@ -180,6 +181,7 @@ internal static class Program
|
||||||
LoadOnAcGrid = gridBusLoad,
|
LoadOnAcGrid = gridBusLoad,
|
||||||
LoadOnAcIsland = loadOnAcIsland,
|
LoadOnAcIsland = loadOnAcIsland,
|
||||||
LoadOnDc = dcLoad,
|
LoadOnDc = dcLoad,
|
||||||
|
|
||||||
StateMachine = StateMachine.Default,
|
StateMachine = StateMachine.Default,
|
||||||
EssControl = EssControl.Default,
|
EssControl = EssControl.Default,
|
||||||
Log = new SystemLog { SalimaxAlarmState = SalimaxAlarmState.Green, Message = null }, //TODO: Put real stuff
|
Log = new SystemLog { SalimaxAlarmState = SalimaxAlarmState.Green, Message = null }, //TODO: Put real stuff
|
||||||
|
@ -216,21 +218,7 @@ internal static class Program
|
||||||
var record = ReadStatus();
|
var record = ReadStatus();
|
||||||
var currentSalimaxState = GetSalimaxStateAlarm(record);
|
var currentSalimaxState = GetSalimaxStateAlarm(record);
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------
|
SendSalimaxStateAlarm(currentSalimaxState);
|
||||||
//If already subscribed to the queue and the status has been changed, update the queue
|
|
||||||
if (_subscribedToQueue && currentSalimaxState != _prevSalimaxState)
|
|
||||||
{
|
|
||||||
_prevSalimaxState = currentSalimaxState;
|
|
||||||
InformMiddleware(Config.Load().S3.Bucket, (int)currentSalimaxState);
|
|
||||||
}
|
|
||||||
|
|
||||||
//If there is an available message, subscribe to the queue
|
|
||||||
if (_udpListener.Available > 0)
|
|
||||||
{
|
|
||||||
subscribedToQueue(currentSalimaxState);
|
|
||||||
}
|
|
||||||
//--------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
|
||||||
record.ControlConstants();
|
record.ControlConstants();
|
||||||
record.ControlSystemState();
|
record.ControlSystemState();
|
||||||
|
@ -264,7 +252,27 @@ internal static class Program
|
||||||
// ReSharper disable once FunctionNeverReturns
|
// ReSharper disable once FunctionNeverReturns
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void subscribedToQueue(SalimaxAlarmState currentSalimaxState)
|
private static void SendSalimaxStateAlarm(SalimaxAlarmState currentSalimaxState)
|
||||||
|
{
|
||||||
|
//--------------------------------------------------------------------------------------------
|
||||||
|
//If already subscribed to the queue and the status has been changed, update the queue
|
||||||
|
if (_subscribedToQueue && currentSalimaxState != _prevSalimaxState)
|
||||||
|
{
|
||||||
|
_prevSalimaxState = currentSalimaxState;
|
||||||
|
var s3Bucket = Config.Load().S3?.Bucket;
|
||||||
|
if (s3Bucket != null)
|
||||||
|
InformMiddleware(s3Bucket, (Int32)currentSalimaxState);
|
||||||
|
}
|
||||||
|
|
||||||
|
//If there is an available message, subscribe to the queue
|
||||||
|
if (_udpListener.Available > 0)
|
||||||
|
{
|
||||||
|
SubscribeToQueue(currentSalimaxState);
|
||||||
|
}
|
||||||
|
//--------------------------------------------------------------------------------------------
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void SubscribeToQueue(SalimaxAlarmState currentSalimaxState)
|
||||||
{
|
{
|
||||||
IPEndPoint serverEndpoint = null;
|
IPEndPoint serverEndpoint = null;
|
||||||
byte[] udpMessage = _udpListener.Receive(ref serverEndpoint);
|
byte[] udpMessage = _udpListener.Receive(ref serverEndpoint);
|
||||||
|
|
Loading…
Reference in New Issue