AlarmRealtime.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. namespace MinicsUI.AlarmHandler;
  2. public class AlarmRealtime(Hardwares hardwares, Alarms alarms)
  3. {
  4. public bool InsertAlarm(byte mini8Index, byte channelIndex, double current)
  5. {
  6. if (!hardwares.Mini8s.TryGetValue(mini8Index, out Mini8Info? mini8) || mini8 is null)
  7. return false;
  8. if (!hardwares.Mini8Channels.TryGetValue(mini8Index, out var channels) || channels is null)
  9. return false;
  10. if (!channels.TryGetValue(channelIndex, out Channel? channel) || channel is null)
  11. return false;
  12. AlarmInfo alarmInfo = new()
  13. {
  14. Mini8Index = mini8.Index,
  15. EventTime = DateTime.Now,
  16. AlarmLevel = AlarmLevel.Error,
  17. AlarmMini8 = mini8.Name,
  18. AlarmChannel = channel.Name,
  19. ChannelName = channel.Name,
  20. ChannelIndex = channel.ChannelIndex,
  21. AlarmDetail = $"Current Temperature: {current:0.00}℃ Caps: {channel.Caps}℃ Floor: {channel.Floor}℃"
  22. };
  23. try
  24. {
  25. Application.Current?.Dispatcher?.Invoke(() =>
  26. {
  27. if (alarms is null)
  28. return;
  29. if (!alarms.DisplayAlarm.ContainsKey(mini8.Index))
  30. alarms.DisplayAlarm[mini8.Index] = [];
  31. alarms.DisplayAlarm[mini8.Index][channel.ChannelIndex] = alarmInfo;
  32. });
  33. }
  34. catch
  35. {
  36. }
  37. return true;
  38. }
  39. public bool CancelAlarm(byte mini8, byte channel)
  40. {
  41. try
  42. {
  43. if (Application.Current is null)
  44. return false;
  45. Application.Current.Dispatcher.Invoke(() =>
  46. {
  47. if (!alarms.DisplayAlarm.TryGetValue(mini8, out var channels) || channels is null)
  48. return;
  49. channels.Remove(channel);
  50. if (channels.Count == 0)
  51. alarms.DisplayAlarm.Remove(mini8);
  52. });
  53. }
  54. catch
  55. {
  56. }
  57. return true;
  58. }
  59. public bool InsertTcBrocken(byte mini8Index, byte channelIndex)
  60. {
  61. if (!hardwares.Mini8s.TryGetValue(mini8Index, out Mini8Info? mini8) || mini8 is null)
  62. return false;
  63. if (!hardwares.Mini8Channels.TryGetValue(mini8Index, out var channels) || channels is null)
  64. return false;
  65. if (!channels.TryGetValue(channelIndex, out Channel? channel) || channel is null)
  66. return false;
  67. AlarmInfo alarmInfo = new()
  68. {
  69. Mini8Index = mini8.Index,
  70. EventTime = DateTime.Now,
  71. AlarmLevel = AlarmLevel.Error,
  72. AlarmMini8 = mini8.Name,
  73. AlarmChannel = channel.Name,
  74. ChannelName = channel.Name,
  75. ChannelIndex = channel.ChannelIndex,
  76. AlarmDetail = $"Tc Broken"
  77. };
  78. Application.Current.Dispatcher.Invoke(() =>
  79. {
  80. if (!alarms.DisplayAlarm.ContainsKey(mini8.Index))
  81. alarms.DisplayAlarm[mini8.Index] = [];
  82. alarms.DisplayAlarm[mini8.Index][channel.ChannelIndex] = alarmInfo;
  83. });
  84. return true;
  85. }
  86. }