Files
YuPu-OrpaonEMS/OrpaonEMS.App/Models/PcsAlarmModel.cs
2025-02-28 22:23:13 +08:00

378 lines
15 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using OrpaonEMS.Core.ChannelModel;
using OrpaonEMS.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Channels;
using System.Threading.Tasks;
using Prism.Mvvm;
using System.Collections.ObjectModel;
namespace OrpaonEMS.App.Models
{
/// <summary>
/// PCS报警模型
/// </summary>
public class PcsAlarmModel : BindableBase
{
/// <summary>
/// 报警通道数据
/// </summary>
public Channel<AlarmChannelData> AlarmChannel { get; set; }
/// <summary>
/// 实例化函数
/// </summary>
public PcsAlarmModel(Channel<AlarmChannelData> channel)
{
AlarmChannel = channel;
foreach (var itemAlarmCell in ListAlarmWord1)
{
itemAlarmCell.PubPcsAlarmEventHandler += ItemAlarmCell_PubPcsAlarmEventHandler;
}
foreach (var itemAlarmCell in ListAlarmWord2)
{
itemAlarmCell.PubPcsAlarmEventHandler += ItemAlarmCell_PubPcsAlarmEventHandler;
}
foreach (var itemAlarmCell in ListAlarmWord3)
{
itemAlarmCell.PubPcsAlarmEventHandler += ItemAlarmCell_PubPcsAlarmEventHandler;
}
foreach (var itemAlarmCell in ListAlarmWord4)
{
itemAlarmCell.PubPcsAlarmEventHandler += ItemAlarmCell_PubPcsAlarmEventHandler;
}
foreach (var itemAlarmCell in ListAlarmWord5)
{
itemAlarmCell.PubPcsAlarmEventHandler += ItemAlarmCell_PubPcsAlarmEventHandler;
}
}
private ObservableCollection<string> _ListAlarmContent=new ObservableCollection<string>();
/// <summary>
///报警内容
/// </summary>
public ObservableCollection<string> ListAlarmContent
{
get { return _ListAlarmContent; }
set { _ListAlarmContent = value; RaisePropertyChanged(); }
}
public string _CurAlarmMsg;
/// <summary>
/// 当前报警数据
/// </summary>
public string CurAlarmMsg
{
get { return _CurAlarmMsg; }
set { _CurAlarmMsg = value; RaisePropertyChanged(); }
}
private int _AlarmCount;
/// <summary>
/// 报警个数
/// </summary>
public int AlarmCount
{
get { return _AlarmCount; }
set { _AlarmCount = value; RaisePropertyChanged(); }
}
/// <summary>
/// 报警发布事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
/// <exception cref="NotImplementedException"></exception>
private void ItemAlarmCell_PubPcsAlarmEventHandler(object sender, Core.EventHandMsg.PcsAlarmCellEventHandMsg AlarmData)
{
//统计个数
var Count1 = ListAlarmWord1.Where(a => a.State == true).Count();
var Count2 = ListAlarmWord2.Where(a => a.State == true).Count();
var Count3 = ListAlarmWord3.Where(a => a.State == true).Count();
var Count4 = ListAlarmWord4.Where(a => a.State == true).Count();
var Count5 = ListAlarmWord5.Where(a => a.State == true).Count();
AlarmCount = Count1 + Count2 + Count3 + Count4 + Count5;
if (AlarmData.State)//报警发生
{
CurAlarmMsg = AlarmData.Content;
if (!ListAlarmContent.Contains(AlarmData.Content))
{
ListAlarmContent.Add(AlarmData.Content);
}
Console.WriteLine($"时间:{DateTime.Now.ToString()}PCS报警激活{AlarmData.Content} ");
}
else//报警消失
{
if (AlarmData.Content== CurAlarmMsg)
{
CurAlarmMsg ="";
}
Console.WriteLine($"时间:{DateTime.Now.ToString()}PCS报警消失{AlarmData.Content} ");
if (ListAlarmContent.Contains(AlarmData.Content))
{
ListAlarmContent.Remove(AlarmData.Content);
}
//报警结束,可以采集数据
AlarmChannel.Writer.WriteAsync(new AlarmChannelData()
{
MsgTime = DateTime.Now,
alarmChannel = new AlarmChannel()
{
Content = AlarmData.Content,
StartTime = AlarmData.CurTimeInfo.StartTime,
EndTime = AlarmData.CurTimeInfo.EndTime,
AlarmDur = (decimal)AlarmData.CurTimeInfo.AlarmDur,
Level = AlarmData.Level,
}
});
}
//报警个数为0那么就清空报警数据了
if (AlarmCount == 0)
{
ListAlarmContent.Clear();
return;
}
}
#region
private ushort _AlarmWord1;
/// <summary>
/// 报警字1
/// </summary>
public ushort AlarmWord1
{
get { return _AlarmWord1; }
set
{
if (_AlarmWord1 != value)
{
foreach (var itemAlarm in ListAlarmWord1)
{
itemAlarm.State = ComHelper.GetBitValue(value, itemAlarm.BitIndex);
}
_AlarmWord1 = value;
}
}
}
private ushort _AlarmWord2;
/// <summary>
/// 报警字1
/// </summary>
public ushort AlarmWord2
{
get { return _AlarmWord2; }
set
{
if (_AlarmWord2 != value)
{
foreach (var itemAlarm in ListAlarmWord2)
{
itemAlarm.State = ComHelper.GetBitValue(value, itemAlarm.BitIndex);
}
_AlarmWord2 = value;
}
}
}
private ushort _AlarmWord3;
/// <summary>
/// 报警字3
/// </summary>
public ushort AlarmWord3
{
get { return _AlarmWord3; }
set
{
if (_AlarmWord3 != value)
{
foreach (var itemAlarm in ListAlarmWord3)
{
itemAlarm.State = ComHelper.GetBitValue(value, itemAlarm.BitIndex);
}
_AlarmWord3 = value;
}
}
}
private ushort _AlarmWord4;
/// <summary>
/// 报警字4
/// </summary>
public ushort AlarmWord4
{
get { return _AlarmWord4; }
set
{
if (_AlarmWord4 != value)
{
foreach (var itemAlarm in ListAlarmWord4)
{
itemAlarm.State = ComHelper.GetBitValue(value, itemAlarm.BitIndex);
}
_AlarmWord4 = value;
}
}
}
private ushort _AlarmWord5;
/// <summary>
/// 报警字5
/// </summary>
public ushort AlarmWord5
{
get { return _AlarmWord5; }
set
{
if (_AlarmWord5 != value)
{
foreach (var itemAlarm in ListAlarmWord5)
{
itemAlarm.State = ComHelper.GetBitValue(value, itemAlarm.BitIndex);
}
_AlarmWord5 = value;
}
}
}
#endregion
#region
/// <summary>
/// PCS 故障字 1
/// 集合
/// </summary>
public List<PcsAlarmCell> ListAlarmWord1 { get; set; } = new List<PcsAlarmCell>()
{
new PcsAlarmCell(){Content="FPGA 硬件故障-A 相硬件过流",BitIndex=0 },
new PcsAlarmCell(){Content="FPGA 硬件故障-B 相硬件过流",BitIndex=1 },
new PcsAlarmCell(){Content="FPGA 硬件故障-C 相硬件过流",BitIndex=2 },
new PcsAlarmCell(){Content="FPGA 硬件故障-N 相硬件过流",BitIndex=3 },
new PcsAlarmCell(){Content="FPGA 硬件故障-单元直压故障",BitIndex=6 },
new PcsAlarmCell(){Content="FPGA 硬件故障-开关电源欠压",BitIndex=9 },
new PcsAlarmCell(){Content="FPGA 软件故障-A 相 IGBT 故障",BitIndex=10 },
new PcsAlarmCell(){Content="FPGA 硬件故障-B 相 IGBT 故障",BitIndex=11 },
new PcsAlarmCell(){Content="FPGA 硬件故障-C 相 IGBT 故障",BitIndex=12 },
new PcsAlarmCell(){Content="FPGA 硬件故障-N 相 IGBT 故障",BitIndex=13 },
new PcsAlarmCell(){Content="FPGA 硬件故障-过温故障",BitIndex=14 },
};
/// <summary>
/// PCS 故障字 2
/// 集合
/// </summary>
public List<PcsAlarmCell> ListAlarmWord2 { get; set; } = new List<PcsAlarmCell>()
{
new PcsAlarmCell(){Content="ARM 软件故障-A 相输出过流",BitIndex=0 },
new PcsAlarmCell(){Content="ARM 软件故障-A 相输出速断",BitIndex=1 },
new PcsAlarmCell(){Content="ARM 软件故障-B 相输出过流",BitIndex=2 },
new PcsAlarmCell(){Content="ARM 软件故障-B 相输出速断",BitIndex=3 },
new PcsAlarmCell(){Content="ARM 软件故障-C 相输出过流",BitIndex=4 },
new PcsAlarmCell(){Content="ARM 软件故障-C 相输出速断",BitIndex=5 },
new PcsAlarmCell(){Content="ARM 软件故障-N 相输出速断",BitIndex=6 },
new PcsAlarmCell(){Content="ARM 软件故障-N 相输出速断",BitIndex=7 },
new PcsAlarmCell(){Content="ARM 软件故障-交流过压",BitIndex=8 },
new PcsAlarmCell(){Content="ARM 软件故障-交流欠压",BitIndex=9 },
new PcsAlarmCell(){Content="ARM 软件故障-交流过频",BitIndex=10 },
new PcsAlarmCell(){Content="ARM 软件故障-交流欠频",BitIndex=11 },
new PcsAlarmCell(){Content="ARM 软件故障-电压 THDU 超限",BitIndex=12 },
new PcsAlarmCell(){Content="ARM 软件故障-系统缺相",BitIndex=13 },
new PcsAlarmCell(){Content="ARM 软件故障-系统相序错误",BitIndex=14 },
new PcsAlarmCell(){Content="ARM 软件故障-直流极性反接",BitIndex=15 },
};
/// <summary>
/// PCS 故障字 3
/// 集合
/// </summary>
public List<PcsAlarmCell> ListAlarmWord3 { get; set; } = new List<PcsAlarmCell>()
{
new PcsAlarmCell(){Content="ARM 软件故障-直流母线软件过压",BitIndex=0 },
new PcsAlarmCell(){Content="ARM 软件故障-直流母线软件欠压",BitIndex=1 },
new PcsAlarmCell(){Content="ARM 软件故障-系统过频率",BitIndex=2 },
new PcsAlarmCell(){Content="ARM 软件故障-系统欠频率",BitIndex=3 },
new PcsAlarmCell(){Content="ARM 软件故障-直流充电过流",BitIndex=4 },
new PcsAlarmCell(){Content="ARM 软件故障-直流放电过流",BitIndex=5 },
new PcsAlarmCell(){Content="ARM 软件故障-孤岛保护",BitIndex=6 },
new PcsAlarmCell(){Content="ARM 软件故障-保留",BitIndex=7 },
new PcsAlarmCell(){Content="ARM 软件故障-交流主接合闸故障",BitIndex=8 },
new PcsAlarmCell(){Content="ARM 软件故障-交流主接分闸故障",BitIndex=9 },
new PcsAlarmCell(){Content="ARM 软件故障-交流软启合闸故障",BitIndex=10 },
new PcsAlarmCell(){Content="ARM 软件故障-交流软启分闸故障",BitIndex=11 },
new PcsAlarmCell(){Content="ARM 软件故障-直流主接合闸故障",BitIndex=12 },
new PcsAlarmCell(){Content="ARM 软件故障-直流主接分闸故障",BitIndex=13 },
new PcsAlarmCell(){Content="ARM 软件故障-直流软启合闸故障",BitIndex=14 },
new PcsAlarmCell(){Content="ARM 软件故障-直流软启合闸故障",BitIndex=15 },
};
/// <summary>
/// PCS 故障字 4
/// 集合
/// </summary>
public List<PcsAlarmCell> ListAlarmWord4 { get; set; } = new List<PcsAlarmCell>()
{
new PcsAlarmCell(){Content="ARM 软件故障-铁电参数存储错误",BitIndex=0 },
new PcsAlarmCell(){Content="ARM 软件故障-直流软起失败",BitIndex=1 },
new PcsAlarmCell(){Content="ARM 软件故障-保留",BitIndex=2 },
new PcsAlarmCell(){Content="ARM 软件故障-保留",BitIndex=3 },
new PcsAlarmCell(){Content="ARM 软件故障-起机条件不满足",BitIndex=4 },
new PcsAlarmCell(){Content="ARM 软件故障-运行中开关故障",BitIndex=5 },
new PcsAlarmCell(){Content="ARM 软件故障-逆变启动超时",BitIndex=6 },
new PcsAlarmCell(){Content="ARM 软件故障-参数下发设置错误",BitIndex=7 },
new PcsAlarmCell(){Content="ARM 软件故障-BMS 通讯故障",BitIndex=8 },
new PcsAlarmCell(){Content="ARM 软件故障-BMS 温度异常",BitIndex=9 },
new PcsAlarmCell(){Content="ARM 软件故障-BMS 跳机",BitIndex=10 },
new PcsAlarmCell(){Content="ARM 软件故障-BMS 电池告警",BitIndex=11 },
new PcsAlarmCell(){Content="ARM 软件故障-DCDC 通讯故障",BitIndex=12 },
new PcsAlarmCell(){Content="ARM 软件故障-EMS 通讯故障",BitIndex=13 },
new PcsAlarmCell(){Content="ARM 软件故障-急停或熔芯故障",BitIndex=14 },
new PcsAlarmCell(){Content="ARM 软件故障-保留",BitIndex=15 },
};
/// <summary>
/// PCS 故障字 5
/// 集合
/// </summary>
public List<PcsAlarmCell> ListAlarmWord5 { get; set; } = new List<PcsAlarmCell>()
{
new PcsAlarmCell(){Content="ARM 软件故障-保留",BitIndex=0 },
new PcsAlarmCell(){Content="ARM 软件故障-电池软件过压",BitIndex=1 },
new PcsAlarmCell(){Content="ARM 软件故障-电池软件欠压",BitIndex=2 },
new PcsAlarmCell(){Content="ARM 软件故障-母线不平衡异常",BitIndex=3 },
new PcsAlarmCell(){Content="ARM 软件故障-母线半直压过压",BitIndex=4 },
new PcsAlarmCell(){Content="ARM 软件故障-DCDC 启动超时",BitIndex=5 },
new PcsAlarmCell(){Content="ARM 软件故障-保留",BitIndex=6 },
//new PcsAlarmCell(){Content="xxx",BitIndex=7 },
//new PcsAlarmCell(){Content="xxx",BitIndex=8 },
//new PcsAlarmCell(){Content="xxx",BitIndex=9 },
//new PcsAlarmCell(){Content="xxx",BitIndex=10 },
//new PcsAlarmCell(){Content="xxx",BitIndex=11 },
//new PcsAlarmCell(){Content="xxx",BitIndex=12 },
//new PcsAlarmCell(){Content="xxx",BitIndex=13 },
//new PcsAlarmCell(){Content="xxx",BitIndex=14 },
//new PcsAlarmCell(){Content="xxx",BitIndex=15 },
};
#endregion
}
}