152 lines
7.6 KiB
C#
152 lines
7.6 KiB
C#
![]() |
using Abp.Dependency;
|
|||
|
using DotNetty.Common;
|
|||
|
using Newtonsoft.Json.Linq;
|
|||
|
using System;
|
|||
|
using System.Collections.Concurrent;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using Yunda.ISAS.DataMonitoringServer.DataAnalysis;
|
|||
|
using Yunda.ISAS.DataMonitoringServer.DataAnalysis.Helper;
|
|||
|
using YunDa.ISAS.DataTransferObject.DataMonitoring.TelemeteringConfigurationDto;
|
|||
|
using YunDa.ISAS.DataTransferObject.DataMonitoring.TelemeteringConfigurationDto.SearchCondition;
|
|||
|
using YunDa.ISAS.DataTransferObject.DataMonitoring.TelesignalisationConfigurationDto;
|
|||
|
using YunDa.ISAS.DataTransferObject.EquipmentLiveData;
|
|||
|
using YunDa.ISAS.DataTransferObject.Iec104;
|
|||
|
using YunDa.ISAS.Entities.DataMonitoring;
|
|||
|
using ConstantModel = Yunda.ISAS.DataMonitoringServer.DataAnalysis.Model.ConstantModel;
|
|||
|
|
|||
|
namespace Yunda.ISAS.DataMonitoringServer.DataCenter
|
|||
|
{
|
|||
|
public class TelecomDataCenter : ISingletonDependency
|
|||
|
{
|
|||
|
private List<TelemeteringConfigurationOutput> _telemeteringConfigurationRepo = new List<TelemeteringConfigurationOutput>();
|
|||
|
private List<TelesignalisationConfigurationOutput> _telesignalisationConfigurationRepo = new List<TelesignalisationConfigurationOutput>();
|
|||
|
private ConfigurationHepler _configurationHepler;
|
|||
|
private DataRepository _dataRepository;
|
|||
|
private readonly RedisDataRepository _redisDataRepository;
|
|||
|
private readonly RunningDataCache _runningDataCache;
|
|||
|
/// <summary>
|
|||
|
/// 已经发送的104数据,使用地址判断
|
|||
|
/// </summary>
|
|||
|
private readonly List<IecServerData> _sendediecServerDatas = new List<IecServerData>();
|
|||
|
public TelecomDataCenter(ConfigurationHepler configurationHepler,
|
|||
|
DataRepository dataRepository,
|
|||
|
RunningDataCache runningDataCache,
|
|||
|
RedisDataRepository redisDataRepository)
|
|||
|
{
|
|||
|
_configurationHepler = configurationHepler;
|
|||
|
_dataRepository = dataRepository;
|
|||
|
_redisDataRepository = redisDataRepository;
|
|||
|
_runningDataCache = runningDataCache;
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 自检判定
|
|||
|
/// </summary>
|
|||
|
public void ExcuteSelfChecking()
|
|||
|
{
|
|||
|
Task.Factory.StartNew(async () =>
|
|||
|
{
|
|||
|
while (true)
|
|||
|
{
|
|||
|
|
|||
|
try
|
|||
|
{
|
|||
|
ResetTimeoutHandle(_runningDataCache.EquipmentDataDic.ToDictionary(kv => kv.Key, kv => kv.Value));
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
MonitoringEventBus.LogHandler(ex.Message, "异常信息");
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
Task.Delay(2000).Wait();
|
|||
|
}
|
|||
|
|
|||
|
}, TaskCreationOptions.LongRunning);
|
|||
|
}
|
|||
|
|
|||
|
private void ResetTimeoutHandle(Dictionary<Guid, EquipmentDataModel> dic)
|
|||
|
{
|
|||
|
foreach (EquipmentDataModel item in dic.Values)
|
|||
|
{
|
|||
|
var selfChecking = item.Telesignalisations.FirstOrDefault(t => t.IsSelfCheckingValue && t.SelfCheckingConfigurationId.HasValue);
|
|||
|
if (selfChecking != null)
|
|||
|
{
|
|||
|
|
|||
|
var virtualDevice = item.Telesignalisations.FirstOrDefault(t => t.IsVirtualDevice);
|
|||
|
if (virtualDevice != null)
|
|||
|
{
|
|||
|
var teleData = _sendediecServerDatas.FirstOrDefault(t =>
|
|||
|
t.devAddr == (byte)virtualDevice.InfoDeviceAddress
|
|||
|
&& t.devCpu == (byte)virtualDevice.InfoCPUSector
|
|||
|
&& t.inf == virtualDevice.InfoAddress);
|
|||
|
if (teleData.inf == 0)
|
|||
|
{
|
|||
|
var iecdata = new IecServerData();
|
|||
|
iecdata.devAddr = (byte)virtualDevice.InfoDeviceAddress;
|
|||
|
iecdata.dateTime = DateTime.Now;
|
|||
|
iecdata.devCpu = (byte)virtualDevice.InfoCPUSector;
|
|||
|
iecdata.inf = virtualDevice.InfoAddress;
|
|||
|
iecdata.dataType = 2;
|
|||
|
iecdata.devName = "visual";
|
|||
|
iecdata.yxValue = selfChecking.SelfCheckingConfiguration.SendTelesignalisationValue - 1;
|
|||
|
_sendediecServerDatas.Add(iecdata);
|
|||
|
var res = ToolLibrary.HttpHelper.HttpPostRequest<bool>(_runningDataCache._transformerSubstation.Iec104ServerUrl + "SendData", iecdata);
|
|||
|
MonitoringEventBus.LogHandler($"发送遥信:装置地址:{iecdata.devAddr} 扇区号:{iecdata.devCpu} 信息地址:{iecdata.inf} 值:{iecdata.yxValue}", "虚拟点位信息");
|
|||
|
}
|
|||
|
|
|||
|
if (selfChecking.SelfCheckingConfiguration.DataType == DataTypeEnum.Telesignalisation
|
|||
|
&& selfChecking.SelfCheckingConfiguration.JudgmentMode == JudgmentModeEnum.ResetTimeout)
|
|||
|
{
|
|||
|
//是否发送自检信息
|
|||
|
bool isSendErrorData = false;
|
|||
|
if (DateTime.Now - selfChecking.ResultTime > TimeSpan.FromSeconds(selfChecking.SelfCheckingConfiguration.TimeOfJudgment))
|
|||
|
{
|
|||
|
isSendErrorData = true;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
selfChecking.IsSendSelfCheck = false;
|
|||
|
}
|
|||
|
|
|||
|
if (selfChecking.RemoteType == RemoteTypeEnum.SinglePoint ? selfChecking.ResultValue == 1 : selfChecking.ResultValue == 2)
|
|||
|
{
|
|||
|
isSendErrorData = true;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
isSendErrorData = false;
|
|||
|
}
|
|||
|
if (!selfChecking.IsSendSelfCheck)
|
|||
|
{
|
|||
|
if (teleData.inf != 0)
|
|||
|
{
|
|||
|
var iecdata = new IecServerData();
|
|||
|
iecdata.devAddr = (byte)virtualDevice.InfoDeviceAddress;
|
|||
|
iecdata.dateTime = DateTime.Now;
|
|||
|
iecdata.devCpu = (byte)virtualDevice.InfoCPUSector;
|
|||
|
iecdata.inf = virtualDevice.InfoAddress;
|
|||
|
iecdata.dataType = 2;
|
|||
|
iecdata.devName = "visual";
|
|||
|
iecdata.yxValue = isSendErrorData ? selfChecking.SelfCheckingConfiguration.SendTelesignalisationValue : selfChecking.SelfCheckingConfiguration.SendTelesignalisationValue - 1;
|
|||
|
_sendediecServerDatas.Add(iecdata);
|
|||
|
var res = ToolLibrary.HttpHelper.HttpPostRequest<bool>(_runningDataCache._transformerSubstation.Iec104ServerUrl + "SendData", iecdata);
|
|||
|
MonitoringEventBus.LogHandler($"发送遥信:装置地址:{iecdata.devAddr} 扇区号:{iecdata.devCpu} 信息地址:{iecdata.inf} 值:{iecdata.yxValue}", "虚拟点位信息");
|
|||
|
selfChecking.IsSendSelfCheck = true;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|