123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- 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;
- }
- }
-
- }
-
- }
- }
- }
- }
- }
- }
|