| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- using RTCommunicatorBase;
- using RTCommunicatorTLV;
- namespace MinicsConsole.Connector;
- public class RTNotifier(Hardwares hardwares) : IMini8DataNotifier, IDisposable
- {
- private ITlvCommunicatorServer? _server;
- public string Name { get; set; } = "RT TLV";
- public bool Initialize(ITlvProvider tlvProvider)
- {
- if (this._server is not null)
- return false;
- this._server = TlvFactory.GetTlvServer();
- this._server.Initialize(tlvProvider);
- return true;
- }
- public bool Open(string IP, ushort port)
- {
- if (this._server is null)
- return false;
- return this._server.Open(IP, port);
- }
- public void Dispose()
- {
- this._server?.Dispose();
- this._server = null;
- }
- void IMini8DataNotifier.ChannelInfoNotify(byte mini8, byte channel, ChannelData channelData)
- {
- return;
- }
- void IMini8DataNotifier.AlarmNotify(byte mini8, byte channel, float temperature)
- {
- if (!hardwares.Mini8Channels.TryGetSubValue(mini8, channel, out ChannelData? channelData) || channelData is null)
- return;
- RTCommunicatorBase.AlarmType alarmType;
- if (temperature > channelData.Caps)
- alarmType = RTCommunicatorBase.AlarmType.CapsOverFlow;
- else if (temperature < channelData.Floor)
- alarmType = RTCommunicatorBase.AlarmType.FloorOverFlow;
- else
- alarmType = RTCommunicatorBase.AlarmType.Undefined;
- ST_ALARM alarm = new()
- {
- Mini8Index = mini8,
- ChannelIndex = channel,
- PV = temperature,
- Caps = channelData.Caps,
- Floor = channelData.Floor,
- AlarmType = alarmType
- };
- Task.Factory.StartNew(() =>
- {
- this._server?.Send(Tags.ChannelAlarmNotify, alarm);
- });
- }
- void IMini8DataNotifier.AlarmTcBrockenNotify(byte mini8, byte channel)
- {
- ST_ALARM alarm = new()
- {
- Mini8Index = mini8,
- ChannelIndex = channel,
- AlarmType = RTCommunicatorBase.AlarmType.TcBroken,
- };
- this._server?.Send(Tags.ChannelAlarmNotify, alarm);
- }
- void IMini8DataNotifier.Mini8ConnectNotify(byte mini8, bool connected)
- {
- byte tag = connected ? Tags.Mini8ConnectNotify : Tags.Mini8DisconnectNotify;
- this._server?.Send(tag, mini8);
- }
- }
- public class RTNotiferSignalR(Hardwares hardwares) : SenderBase_SignalR, IMini8DataNotifier
- {
- public string Name { get; set; } = "RT SignalR";
- void IMini8DataNotifier.AlarmNotify(byte mini8, byte channel, float temperature)
- {
- if (!hardwares.Mini8Channels.TryGetSubValue(mini8, channel, out ChannelData? channelData) || channelData is null)
- return;
- RTCommunicatorBase.AlarmType alarmType;
- if (temperature > channelData.Caps)
- alarmType = RTCommunicatorBase.AlarmType.CapsOverFlow;
- else if (temperature < channelData.Floor)
- alarmType = RTCommunicatorBase.AlarmType.FloorOverFlow;
- else
- alarmType = RTCommunicatorBase.AlarmType.Undefined;
- ST_ALARM alarm = new()
- {
- Mini8Index = mini8,
- ChannelIndex = channel,
- PV = temperature,
- Caps = channelData.Caps,
- Floor = channelData.Floor,
- AlarmType = alarmType
- };
- Task.Factory.StartNew(() =>
- {
- base.SendAll("AlarmNotify", alarm);
- });
- }
- void IMini8DataNotifier.AlarmTcBrockenNotify(byte mini8, byte channel)
- {
- ST_ALARM alarm = new()
- {
- Mini8Index = mini8,
- ChannelIndex = channel,
- AlarmType = RTCommunicatorBase.AlarmType.TcBroken,
- };
- base.SendAll("AlarmNotify", alarm);
- }
- void IMini8DataNotifier.ChannelInfoNotify(byte mini8, byte channel, ChannelData channelData)
- {
- if (channelData.Inhibit == Inhibit.Disable)
- return;
- ChannelRealtimeInfo channelRealtime = channelData.Adapt<ChannelRealtimeInfo>();
- base.SendAll("ChannelInfoNotify", mini8, channel, channelRealtime);
- }
- void IMini8DataNotifier.Mini8ConnectNotify(byte mini8, bool connected)
- {
- base.SendAll("Mini8ConnectNotify", mini8, connected);
- }
- }
|