|
|
@@ -1,78 +1,92 @@
|
|
|
-using HardwareData;
|
|
|
-using MinicsConsole.Connector;
|
|
|
-using System.Diagnostics;
|
|
|
-using System.Net.NetworkInformation;
|
|
|
-using System.Threading.Channels;
|
|
|
-
|
|
|
-namespace MinicsConsole.Helper;
|
|
|
+namespace MinicsConsole.Helper;
|
|
|
|
|
|
public class Mini8DataDispatcher
|
|
|
{
|
|
|
- public Mini8DataDispatcher(ILog log)
|
|
|
+ public Mini8DataDispatcher(ILog log,
|
|
|
+ UISender uiNotifier,
|
|
|
+ RTNotifier rtNotifer,
|
|
|
+ PLCNotifier plcNotifier)
|
|
|
+ //KanbanNotifier kanbanNotifier)
|
|
|
{
|
|
|
- this.log = log;
|
|
|
+ this._log = log;
|
|
|
+ this._Connectors.TryAdd("PLC", plcNotifier);
|
|
|
+ this._Connectors.TryAdd("UI", uiNotifier);
|
|
|
+ this._Connectors.TryAdd("RT", rtNotifer);
|
|
|
+ //this._Connectors.TryAdd("Kanban", kanbanNotifier);
|
|
|
+
|
|
|
+ this._UINotifier = uiNotifier;
|
|
|
+ this._PlcNotifier = plcNotifier;
|
|
|
+ this._RTNotifier = rtNotifer;
|
|
|
+
|
|
|
+ this._UIQueue = new(UIQueueHandler);
|
|
|
+ this._RTQueue = new(RTQueueHandler);
|
|
|
+ this._PLCQueue = new(PLCQueueHandler);
|
|
|
}
|
|
|
- private readonly ILog log;
|
|
|
+
|
|
|
+ private readonly ILog _log;
|
|
|
|
|
|
private readonly ConcurrentDictionary<string, IMini8DataNotifier> _Connectors = [];
|
|
|
- private readonly ConcurrentDictionary<string, EventQueue<(string name, byte mini8, byte channel, ChannelData channelData)>> _ConnectorQueue = [];
|
|
|
|
|
|
- private void QueueHandler((string name, byte mini8, byte channel, ChannelData channelData) t)
|
|
|
+ private readonly IMini8DataNotifier _UINotifier;
|
|
|
+ private readonly IMini8DataNotifier _PlcNotifier;
|
|
|
+ private readonly IMini8DataNotifier _RTNotifier;
|
|
|
+
|
|
|
+ private readonly EventQueue<(byte mini8, byte channel, ChannelData channelData)> _UIQueue;
|
|
|
+ private readonly EventQueue<(byte mini8, byte channel, ChannelData channelData)> _PLCQueue;
|
|
|
+ private readonly EventQueue<(byte mini8, byte channel, ChannelData channelData)> _RTQueue;
|
|
|
+
|
|
|
+ private void RTQueueHandler((byte mini8, byte channel, ChannelData channelData) t)
|
|
|
{
|
|
|
- if (!_Connectors.TryGetValue(t.name, out IMini8DataNotifier? notifer) || notifer is null)
|
|
|
+ if (this._RTQueue.Count >= 2)
|
|
|
return;
|
|
|
|
|
|
try
|
|
|
{
|
|
|
- notifer.ChannelInfoNotify(t.mini8, t.channel, t.channelData);
|
|
|
+ this._RTNotifier?.ChannelInfoNotify(t.mini8, t.channel, t.channelData);
|
|
|
}
|
|
|
catch
|
|
|
{
|
|
|
- log?.Warning($"DataDispatcher try send ChannelInfoNotify failed {t.name} mini8 {t.mini8} channel {t.channel}");
|
|
|
+ _log?.Warning($"DataDispatcher try send ChannelInfoNotify failed RT mini8 {t.mini8} channel {t.channel}");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public bool TryAddNotifier(string name, IMini8DataNotifier connector)
|
|
|
+ private void UIQueueHandler((byte mini8, byte channel, ChannelData channelData) t)
|
|
|
{
|
|
|
- if (!_Connectors.TryAdd(name, connector))
|
|
|
- return false;
|
|
|
-
|
|
|
- _ConnectorQueue[name] = new(QueueHandler);
|
|
|
+ if (this._UIQueue.Count >= 2)
|
|
|
+ return;
|
|
|
|
|
|
- return true;
|
|
|
+ try
|
|
|
+ {
|
|
|
+ this._UINotifier?.ChannelInfoNotify(t.mini8, t.channel, t.channelData);
|
|
|
+ }
|
|
|
+ catch
|
|
|
+ {
|
|
|
+ _log?.Warning($"DataDispatcher try send ChannelInfoNotify failed UI mini8 {t.mini8} channel {t.channel}");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- public bool TryRemoveConnector(string name)
|
|
|
+ private void PLCQueueHandler((byte mini8, byte channel, ChannelData channelData) t)
|
|
|
{
|
|
|
- _ConnectorQueue.TryRemove(name, out _);
|
|
|
- return _Connectors.TryRemove(name, out _);
|
|
|
+ if (this._PLCQueue.Count >= 2)
|
|
|
+ return;
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ this._PlcNotifier?.ChannelInfoNotify(t.mini8, t.channel, t.channelData);
|
|
|
+ }
|
|
|
+ catch
|
|
|
+ {
|
|
|
+ _log?.Warning($"DataDispatcher try send ChannelInfoNotify failed PLC mini8 {t.mini8} channel {t.channel}");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public void ChannelInfoNotify(byte mini8, byte channel, ChannelData channelData)
|
|
|
{
|
|
|
if (channelData is null)
|
|
|
return;
|
|
|
-
|
|
|
- foreach (var item in _ConnectorQueue)
|
|
|
- {
|
|
|
- item.Value.Enqueue((item.Key, mini8, channel, channelData));
|
|
|
- }
|
|
|
-
|
|
|
- //Parallel.ForEach(_Connectors.Values, item =>
|
|
|
- //{
|
|
|
- // Task.Factory.StartNew(() =>
|
|
|
- // {
|
|
|
-
|
|
|
- // try
|
|
|
- // {
|
|
|
- // item?.ChannelInfoNotify(mini8, channel, channelData);
|
|
|
- // }
|
|
|
- // catch
|
|
|
- // {
|
|
|
- // log?.Warning($"DataDispatcher try send ChannelInfoNotify failed {item.Name} mini8 {mini8} channel {channel}");
|
|
|
- // }
|
|
|
- // });
|
|
|
- //});
|
|
|
+ _RTQueue.Enqueue((mini8, channel, channelData));
|
|
|
+ _PLCQueue.Enqueue((mini8, channel, channelData));
|
|
|
+ _UIQueue.Enqueue((mini8, channel, channelData));
|
|
|
}
|
|
|
|
|
|
public void AlarmNotify(byte mini8, byte channel, float temperature)
|
|
|
@@ -85,7 +99,7 @@ public class Mini8DataDispatcher
|
|
|
}
|
|
|
catch
|
|
|
{
|
|
|
- log.Warning($"DataDispatcher try send AlarmNotify failed {item.Name} mini8 {mini8} channel {channel}");
|
|
|
+ _log.Warning($"DataDispatcher try send AlarmNotify failed {item.Name} mini8 {mini8} channel {channel}");
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
@@ -100,7 +114,7 @@ public class Mini8DataDispatcher
|
|
|
}
|
|
|
catch
|
|
|
{
|
|
|
- log.Warning($"DataDispatcher try send AlarmTcBrockenNotify failed {item.Name} mini8 {mini8} channel {channel}");
|
|
|
+ _log.Warning($"DataDispatcher try send AlarmTcBrockenNotify failed {item.Name} mini8 {mini8} channel {channel}");
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
@@ -115,7 +129,7 @@ public class Mini8DataDispatcher
|
|
|
}
|
|
|
catch
|
|
|
{
|
|
|
- log.Warning($"DataDispatcher try send Mini8Connect to failed {item.Name} mini8 {mini8Index}");
|
|
|
+ _log.Warning($"DataDispatcher try send Mini8Connect to failed {item.Name} mini8 {mini8Index}");
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
@@ -130,7 +144,7 @@ public class Mini8DataDispatcher
|
|
|
}
|
|
|
catch
|
|
|
{
|
|
|
- log.Warning($"DataDispatcher try send Mini8Disconnect failed {item.Name} mini8 {mini8Index}");
|
|
|
+ _log.Warning($"DataDispatcher try send Mini8Disconnect failed {item.Name} mini8 {mini8Index}");
|
|
|
}
|
|
|
});
|
|
|
}
|