2024-11-26 13:45:28 +08:00
|
|
|
|
using Abp.Dependency;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using ToolLibrary.LogHelper;
|
|
|
|
|
using YunDa.ISAS.Redis.Repositories;
|
|
|
|
|
using YunDa.SOMS.Commdb.Models;
|
|
|
|
|
using Yunda.SOMS.DataMonitoringServer.FTPHandle;
|
|
|
|
|
using Yunda.SOMS.DataMonitoringServer.TcpSocket.Server;
|
|
|
|
|
using YunDa.SOMS.DataTransferObject.GeneralInformation.ProtectionDeviceInfoDto;
|
|
|
|
|
using Yunda.ISAS.DataMonitoringServer.DataAnalysis;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using StackExchange.Redis;
|
|
|
|
|
using Yunda.ISAS.DataMonitoringServer.DataCenter;
|
|
|
|
|
|
|
|
|
|
namespace Yunda.SOMS.DataMonitoringServer.ProtectionDeviceHandle
|
|
|
|
|
{
|
|
|
|
|
public class ProtectionDeviceRunInfoHandle : ISingletonDependency
|
|
|
|
|
{
|
|
|
|
|
WebApiRequest _webApiRequest;
|
|
|
|
|
FtpFile _ftpFile;
|
|
|
|
|
DotNettyTcpServer _dotNettyTcpServer;
|
|
|
|
|
List<ProtectionDeviceCommInfoOutput> _devices;
|
|
|
|
|
private readonly RedisDataRepository _redisDataRepository;
|
|
|
|
|
public ProtectionDeviceRunInfoHandle(
|
|
|
|
|
FtpFile ftpFile,
|
|
|
|
|
DotNettyTcpServer dotNettyTcpServer
|
|
|
|
|
, WebApiRequest webApiRequest,
|
|
|
|
|
RedisDataRepository redisDataRepository
|
|
|
|
|
)
|
|
|
|
|
{
|
|
|
|
|
_webApiRequest = webApiRequest;
|
|
|
|
|
_ftpFile = ftpFile;
|
|
|
|
|
_dotNettyTcpServer = dotNettyTcpServer;
|
|
|
|
|
_redisDataRepository = redisDataRepository;
|
|
|
|
|
_dotNettyTcpServer.MessageReceived += OnMessageReceived; // 订阅事件
|
|
|
|
|
Task.Run(async () =>
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_devices = _webApiRequest.GetProtectionDeviceCommInfos("神池南");
|
|
|
|
|
await Task.Delay(10000);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Log4Helper.Error(this.GetType(), "初始化装置IO错误", ex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
int _commCount = 0;
|
|
|
|
|
private void OnMessageReceived(byte address, byte[] message, byte functionType)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (functionType == 6) //通信状态
|
|
|
|
|
{
|
|
|
|
|
if (_commCount == 0)
|
|
|
|
|
{
|
|
|
|
|
var device = _devices.FirstOrDefault(t => t.DeviceAddr == address);
|
2024-12-02 14:52:59 +08:00
|
|
|
|
var localFile = _ftpFile.GetFileFromFtp(device.GatewayIP1, "/nor/root/status/", "status.txt",address.ToString());
|
2024-11-26 13:45:28 +08:00
|
|
|
|
if (File.Exists(localFile))
|
|
|
|
|
{
|
|
|
|
|
var data = ParseDeviceStatus(localFile);
|
|
|
|
|
data.ProtectionDeviceId = device.ProtectionDeviceId;
|
|
|
|
|
data.EquipmentInfoId = device.EquipmentInfoId;
|
|
|
|
|
data.EquipmentInfoName = device.EquipmentInfoName;
|
|
|
|
|
string redisKey = _redisDataRepository.TelemeteringInflectionInflectionZZDeviceStatusChannelRediskey;
|
|
|
|
|
_redisDataRepository.DeviceStatusRedis.PublishAsync(redisKey, data);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
_commCount++;
|
|
|
|
|
if (_commCount == 10)
|
|
|
|
|
{
|
|
|
|
|
_commCount = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
Log4Helper.Error(this.GetType(), "初始化装置IO错误", ex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
private DeviceStatus ParseDeviceStatus(string filePath)
|
|
|
|
|
{
|
|
|
|
|
var deviceStatus = new DeviceStatus();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var networkInterfaces = new List<NetworkInterfaceStatus>();
|
|
|
|
|
|
|
|
|
|
string[] lines = File.ReadAllLines(filePath);
|
|
|
|
|
NetworkInterfaceStatus currentInterface = null;
|
|
|
|
|
|
|
|
|
|
foreach (var line in lines)
|
|
|
|
|
{
|
|
|
|
|
var parts = line.Split(':', 2);
|
|
|
|
|
if (parts.Length < 2) continue;
|
|
|
|
|
|
|
|
|
|
string key = parts[0].Trim();
|
|
|
|
|
string value = parts[1].Trim();
|
|
|
|
|
|
|
|
|
|
switch (key)
|
|
|
|
|
{
|
|
|
|
|
case "使用内存":
|
|
|
|
|
deviceStatus.UsedMemory = value;
|
|
|
|
|
break;
|
|
|
|
|
case "空闲内存":
|
|
|
|
|
deviceStatus.FreeMemory = value;
|
|
|
|
|
break;
|
|
|
|
|
case "总磁盘":
|
|
|
|
|
deviceStatus.TotalDisk = value;
|
|
|
|
|
break;
|
|
|
|
|
case "使用磁盘":
|
|
|
|
|
deviceStatus.UsedDisk = value;
|
|
|
|
|
break;
|
|
|
|
|
case "104连接状态":
|
|
|
|
|
deviceStatus.ConnectionStatus104 = int.Parse(value);
|
|
|
|
|
break;
|
|
|
|
|
case "液晶操作密码":
|
|
|
|
|
deviceStatus.LcdOperationPassword = value;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
if (key.StartsWith("网口"))
|
|
|
|
|
{
|
|
|
|
|
string[] netParts = key.Split(new[] { "网口", "IP", "状态", "速率", "累计时间", "起始时间", "发生帧数", "发送错误帧数", "接收帧数", "接收错误帧数" }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
|
if (netParts.Length > 0)
|
|
|
|
|
{
|
|
|
|
|
string interfaceName = netParts[0];
|
|
|
|
|
if (currentInterface == null || currentInterface.InterfaceName != interfaceName)
|
|
|
|
|
{
|
|
|
|
|
currentInterface = new NetworkInterfaceStatus { InterfaceName = interfaceName };
|
|
|
|
|
networkInterfaces.Add(currentInterface);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (key.EndsWith("IP")) currentInterface.IpAddress = value;
|
|
|
|
|
if (key.EndsWith("状态")) currentInterface.Status = value;
|
|
|
|
|
if (key.EndsWith("速率")) currentInterface.Speed = value;
|
|
|
|
|
if (key.EndsWith("累计时间")) currentInterface.CumulativeTime = int.Parse(value.Replace("s", "").Trim());
|
|
|
|
|
if (key.EndsWith("起始时间")) currentInterface.StartTime = value;
|
|
|
|
|
if (key.EndsWith("发生帧数")) currentInterface.SentFrames = int.Parse(value);
|
|
|
|
|
if (key.EndsWith("发送错误帧数")) currentInterface.SentErrorFrames = int.Parse(value);
|
|
|
|
|
if (key.EndsWith("接收帧数")) currentInterface.ReceivedFrames = int.Parse(value);
|
|
|
|
|
if (key.EndsWith("接收错误帧数")) currentInterface.ReceivedErrorFrames = int.Parse(value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
deviceStatus.NetworkInterfaces = networkInterfaces;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
return deviceStatus;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|