Browse Source

报警检测优化

样式分支
pry 2 years ago
parent
commit
a7e645acf2
2 changed files with 11 additions and 5 deletions
  1. +10
    -4
      BPASmartClient.Device/AlarmHelper.cs
  2. +1
    -1
      BPASmartClient.Device/BaseDevice.cs

+ 10
- 4
BPASmartClient.Device/AlarmHelper.cs View File

@@ -15,6 +15,7 @@ namespace BPASmartClient.Device
public List<Alarm> Alarms { get; set; } = new List<Alarm>(); public List<Alarm> Alarms { get; set; } = new List<Alarm>();
public List<Alarm> HistoryAlarms { get; set; } = new List<Alarm>(); public List<Alarm> HistoryAlarms { get; set; } = new List<Alarm>();
ConcurrentDictionary<string, bool> flagbit = new ConcurrentDictionary<string, bool>(); 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> AddAction { get; set; }
public Action<string> RemoveAction { get; set; } public Action<string> RemoveAction { get; set; }
public Action ChangeAction { get; set; } public Action ChangeAction { get; set; }
@@ -25,20 +26,25 @@ namespace BPASmartClient.Device
/// <param name="Trigger">触发变量</param> /// <param name="Trigger">触发变量</param>
/// <param name="text">报警信息</param> /// <param name="text">报警信息</param>
/// <param name="edgeType">触发类型,上升沿 或 下降沿</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 (!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]) 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; flagbit[text] = edgeType == AlarmTriggerType.Rising ? true : false;
} }
} }
else else
{ {
RemoveAlarm(text);
//RemoveAlarm(text);
RemoveAlarm(text.Substring(0, text.LastIndexOf("-")));
} }
if (edgeType == AlarmTriggerType.Rising ? flagbit[text] : !flagbit[text]) flagbit[text] = Trigger; if (edgeType == AlarmTriggerType.Rising ? flagbit[text] : !flagbit[text]) flagbit[text] = Trigger;
} }


+ 1
- 1
BPASmartClient.Device/BaseDevice.cs View File

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


Loading…
Cancel
Save