Переглянути джерело

报警检测优化

样式分支
pry 2 роки тому
джерело
коміт
a7e645acf2
2 змінених файлів з 11 додано та 5 видалено
  1. +10
    -4
      BPASmartClient.Device/AlarmHelper.cs
  2. +1
    -1
      BPASmartClient.Device/BaseDevice.cs

+ 10
- 4
BPASmartClient.Device/AlarmHelper.cs Переглянути файл

@@ -15,6 +15,7 @@ namespace BPASmartClient.Device
public List<Alarm> Alarms { get; set; } = new List<Alarm>();
public List<Alarm> HistoryAlarms { get; set; } = new List<Alarm>();
ConcurrentDictionary<string, bool> flagbit = new ConcurrentDictionary<string, bool>();
ConcurrentDictionary<string, Delay> delays = new ConcurrentDictionary<string, Delay>();
public Action<string> AddAction { get; set; }
public Action<string> RemoveAction { get; set; }
public Action ChangeAction { get; set; }
@@ -25,20 +26,25 @@ namespace BPASmartClient.Device
/// <param name="Trigger">触发变量</param>
/// <param name="text">报警信息</param>
/// <param name="edgeType">触发类型,上升沿 或 下降沿</param>
public void EdgeAlarm(bool Trigger, string text, AlarmLevel alarmLevel = AlarmLevel.一般报警, AlarmTriggerType edgeType = AlarmTriggerType.Rising)
public void EdgeAlarm(bool Trigger, string text, int delay = 2, AlarmLevel alarmLevel = AlarmLevel.一般报警, AlarmTriggerType edgeType = AlarmTriggerType.Rising)
{
if (!flagbit.ContainsKey(text)) flagbit.TryAdd(text, false);
if (edgeType == AlarmTriggerType.Rising ? Trigger : !Trigger)
if (!delays.ContainsKey(text)) delays.TryAdd(text, Delay.GetInstance(text));
//if (edgeType == AlarmTriggerType.Rising ? Trigger : !Trigger)
if (edgeType == AlarmTriggerType.Rising ? delays[text].Start(Trigger, delay) : delays[text].Start(!Trigger, delay))
{
if (edgeType == AlarmTriggerType.Rising ? !flagbit[text] : flagbit[text])
{
AddAlarm(Trigger, text, alarmLevel);
//AddAlarm(Trigger, text, alarmLevel);
AddAlarm(Trigger, text.Substring(0, text.LastIndexOf("-")), alarmLevel);

flagbit[text] = edgeType == AlarmTriggerType.Rising ? true : false;
}
}
else
{
RemoveAlarm(text);
//RemoveAlarm(text);
RemoveAlarm(text.Substring(0, text.LastIndexOf("-")));
}
if (edgeType == AlarmTriggerType.Rising ? flagbit[text] : !flagbit[text]) flagbit[text] = Trigger;
}


+ 1
- 1
BPASmartClient.Device/BaseDevice.cs Переглянути файл

@@ -279,7 +279,7 @@ namespace BPASmartClient.Device
if (item.CustomAttributes.Count() > 0 && item.CustomAttributes.ElementAt(0)?.ConstructorArguments.Count() > 0)
{
var info = item.GetCustomAttribute<AlarmAttribute>().AlarmInfo;
if (info != null) alarmHelper.EdgeAlarm(blen, info.ToString());
if (info != null) alarmHelper.EdgeAlarm(blen, $"{info.ToString()}-{DeviceId}");
}
}
}


Завантаження…
Відмінити
Зберегти