|
@@ -10,11 +10,11 @@ using System.IO;
|
|
|
using System.Linq;
|
|
using System.Linq;
|
|
|
using System.Net;
|
|
using System.Net;
|
|
|
using System.Net.Sockets;
|
|
using System.Net.Sockets;
|
|
|
|
|
+using System.Reflection;
|
|
|
using System.Security.Cryptography;
|
|
using System.Security.Cryptography;
|
|
|
using System.Text;
|
|
using System.Text;
|
|
|
using System.Threading;
|
|
using System.Threading;
|
|
|
using System.Threading.Tasks;
|
|
using System.Threading.Tasks;
|
|
|
-using static System.Windows.Forms.AxHost;
|
|
|
|
|
|
|
|
|
|
namespace SWRIS.Core
|
|
namespace SWRIS.Core
|
|
|
{
|
|
{
|
|
@@ -38,12 +38,11 @@ namespace SWRIS.Core
|
|
|
public event EventHandler<EncoderDirectionResultReceivedEventArgs> EncoderDirectionResultReceived;
|
|
public event EventHandler<EncoderDirectionResultReceivedEventArgs> EncoderDirectionResultReceived;
|
|
|
public event EventHandler<HeartbeatReceviedEventArgs> HeartbeatReceived;
|
|
public event EventHandler<HeartbeatReceviedEventArgs> HeartbeatReceived;
|
|
|
public event EventHandler<DebugMessageReceivedEventArgs> DebugMessageReceived;
|
|
public event EventHandler<DebugMessageReceivedEventArgs> DebugMessageReceived;
|
|
|
-
|
|
|
|
|
private Socket _listener;
|
|
private Socket _listener;
|
|
|
private bool _isRunning;
|
|
private bool _isRunning;
|
|
|
private readonly string _ipAddress;
|
|
private readonly string _ipAddress;
|
|
|
private readonly int _port;
|
|
private readonly int _port;
|
|
|
- private readonly ByteTransform byteTransform;
|
|
|
|
|
|
|
+ private readonly ByteTransform _byteTransform;
|
|
|
private const string PASSWORD = "WNDTM4";
|
|
private const string PASSWORD = "WNDTM4";
|
|
|
private static ConcurrentDictionary<string, ClientState> _connectedClients;
|
|
private static ConcurrentDictionary<string, ClientState> _connectedClients;
|
|
|
private CancellationTokenSource ctsToken = new CancellationTokenSource();
|
|
private CancellationTokenSource ctsToken = new CancellationTokenSource();
|
|
@@ -51,7 +50,7 @@ namespace SWRIS.Core
|
|
|
{
|
|
{
|
|
|
_ipAddress = ipAddress;
|
|
_ipAddress = ipAddress;
|
|
|
_port = port;
|
|
_port = port;
|
|
|
- byteTransform = new ByteTransform(DataFormat.DCBA);
|
|
|
|
|
|
|
+ _byteTransform = new ByteTransform(DataFormat.DCBA);
|
|
|
_connectedClients = new ConcurrentDictionary<string, ClientState>();
|
|
_connectedClients = new ConcurrentDictionary<string, ClientState>();
|
|
|
}
|
|
}
|
|
|
public void Start()
|
|
public void Start()
|
|
@@ -176,7 +175,7 @@ namespace SWRIS.Core
|
|
|
}
|
|
}
|
|
|
}, ctsToken);
|
|
}, ctsToken);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+ [Obfuscation(Feature = "virtualization", Exclude = false)]
|
|
|
private async void OnDataReceived(IAsyncResult ar)
|
|
private async void OnDataReceived(IAsyncResult ar)
|
|
|
{
|
|
{
|
|
|
var state = (ClientState)ar.AsyncState;
|
|
var state = (ClientState)ar.AsyncState;
|
|
@@ -358,6 +357,7 @@ namespace SWRIS.Core
|
|
|
/// <param name="payload"></param>
|
|
/// <param name="payload"></param>
|
|
|
/// <param name="client"></param>
|
|
/// <param name="client"></param>
|
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
|
|
|
+ [Obfuscation(Feature = "virtualization", Exclude = false)]
|
|
|
private async Task ProcessEventByType(byte eventType, byte[] payload, ClientState client)
|
|
private async Task ProcessEventByType(byte eventType, byte[] payload, ClientState client)
|
|
|
{
|
|
{
|
|
|
switch (eventType)
|
|
switch (eventType)
|
|
@@ -497,7 +497,6 @@ namespace SWRIS.Core
|
|
|
var liveStreamData = ReceiveLiveStreamDataModel(buffer);
|
|
var liveStreamData = ReceiveLiveStreamDataModel(buffer);
|
|
|
if (liveStreamData != null && liveStreamData.Data.Any())
|
|
if (liveStreamData != null && liveStreamData.Data.Any())
|
|
|
{
|
|
{
|
|
|
- Console.WriteLine($"接收实时流数据: {liveStreamData.ToString()}");
|
|
|
|
|
// 触发事件
|
|
// 触发事件
|
|
|
LiveStreamReceived?.Invoke(this,
|
|
LiveStreamReceived?.Invoke(this,
|
|
|
new LiveStreamReceivedEventArgs(client.IpAddress, liveStreamData));
|
|
new LiveStreamReceivedEventArgs(client.IpAddress, liveStreamData));
|
|
@@ -581,6 +580,7 @@ namespace SWRIS.Core
|
|
|
if (detectionData.DamageCount <= 0)
|
|
if (detectionData.DamageCount <= 0)
|
|
|
{
|
|
{
|
|
|
DebugMessageReceived?.Invoke(this, new DebugMessageReceivedEventArgs($"检测结果未发现损伤,本次结果不记录",
|
|
DebugMessageReceived?.Invoke(this, new DebugMessageReceivedEventArgs($"检测结果未发现损伤,本次结果不记录",
|
|
|
|
|
+ ipAddress: client.IpAddress,
|
|
|
serialNo: client.SerialNo));
|
|
serialNo: client.SerialNo));
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
@@ -677,17 +677,28 @@ namespace SWRIS.Core
|
|
|
(string serialNo, byte[] bytes) = GetSerialNoAndData(buffer);
|
|
(string serialNo, byte[] bytes) = GetSerialNoAndData(buffer);
|
|
|
return bytes[0]; // 开启/关闭结果,0=成功,>0=失败-原因码
|
|
return bytes[0]; // 开启/关闭结果,0=成功,>0=失败-原因码
|
|
|
}
|
|
}
|
|
|
|
|
+ private DateTime? _lastLiveStreamReceiveTime = null;
|
|
|
|
|
+
|
|
|
public LiveStreamDataModel ReceiveLiveStreamDataModel(byte[] buffer)
|
|
public LiveStreamDataModel ReceiveLiveStreamDataModel(byte[] buffer)
|
|
|
{
|
|
{
|
|
|
(string serialNo, byte[] bytes) = GetSerialNoAndData(buffer);
|
|
(string serialNo, byte[] bytes) = GetSerialNoAndData(buffer);
|
|
|
var liveStreamData = new LiveStreamDataModel()
|
|
var liveStreamData = new LiveStreamDataModel()
|
|
|
{
|
|
{
|
|
|
SensorCount = bytes[0],
|
|
SensorCount = bytes[0],
|
|
|
- SampleCount = byteTransform.TransUInt16(bytes, 1)
|
|
|
|
|
|
|
+ SampleCount = _byteTransform.TransUInt16(bytes, 1)
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
var data = bytes.Skip(3).ToArray(); // 跳过前3个字节
|
|
var data = bytes.Skip(3).ToArray(); // 跳过前3个字节
|
|
|
liveStreamData.Data = ParseSensorData(data, liveStreamData.SensorCount, liveStreamData.SampleCount);
|
|
liveStreamData.Data = ParseSensorData(data, liveStreamData.SensorCount, liveStreamData.SampleCount);
|
|
|
|
|
+
|
|
|
|
|
+ // 计算本次接收与上次接收的时间差(毫秒)
|
|
|
|
|
+ var now = DateTime.Now;
|
|
|
|
|
+ if (_lastLiveStreamReceiveTime.HasValue)
|
|
|
|
|
+ {
|
|
|
|
|
+ liveStreamData.SampleInterval = (int)(now - _lastLiveStreamReceiveTime.Value).TotalMilliseconds;
|
|
|
|
|
+ }
|
|
|
|
|
+ _lastLiveStreamReceiveTime = now;
|
|
|
|
|
+
|
|
|
return liveStreamData;
|
|
return liveStreamData;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -697,7 +708,7 @@ namespace SWRIS.Core
|
|
|
var twistFactorData = new TwistFactorDataModel
|
|
var twistFactorData = new TwistFactorDataModel
|
|
|
{
|
|
{
|
|
|
Type = bytes[0],
|
|
Type = bytes[0],
|
|
|
- TwistFactor = byteTransform.TransSingle(bytes, 1) // 判伤捻距系数
|
|
|
|
|
|
|
+ TwistFactor = _byteTransform.TransSingle(bytes, 1) // 判伤捻距系数
|
|
|
};
|
|
};
|
|
|
return twistFactorData;
|
|
return twistFactorData;
|
|
|
}
|
|
}
|
|
@@ -707,6 +718,7 @@ namespace SWRIS.Core
|
|
|
/// <param name="serialNo"></param>
|
|
/// <param name="serialNo"></param>
|
|
|
/// <param name="client"></param>
|
|
/// <param name="client"></param>
|
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
|
|
|
+ [Obfuscation(Feature = "virtualization", Exclude = false)]
|
|
|
public bool SendGetEncoderDirectionData(string serialNo, Socket clientSocket)
|
|
public bool SendGetEncoderDirectionData(string serialNo, Socket clientSocket)
|
|
|
{
|
|
{
|
|
|
try
|
|
try
|
|
@@ -714,12 +726,14 @@ namespace SWRIS.Core
|
|
|
if (clientSocket == null || !clientSocket.Connected)
|
|
if (clientSocket == null || !clientSocket.Connected)
|
|
|
return false;
|
|
return false;
|
|
|
|
|
|
|
|
|
|
+ // 获取不含端口的IP地址
|
|
|
|
|
+ string ipAddress = ((IPEndPoint)clientSocket.RemoteEndPoint).Address.ToString();
|
|
|
using (var ms = new MemoryStream())
|
|
using (var ms = new MemoryStream())
|
|
|
{
|
|
{
|
|
|
ms.WriteByte(0x00); // 操作,0 = 获取编码器方向,1 = 设置编码器方向
|
|
ms.WriteByte(0x00); // 操作,0 = 获取编码器方向,1 = 设置编码器方向
|
|
|
ms.WriteByte(0x01); // 编码器方向,1=正向,2=反向
|
|
ms.WriteByte(0x01); // 编码器方向,1=正向,2=反向
|
|
|
byte[] buffer = CreateData(0x12, ms.ToArray(), serialNo);
|
|
byte[] buffer = CreateData(0x12, ms.ToArray(), serialNo);
|
|
|
- DebugMessageReceived?.Invoke(this, new DebugMessageReceivedEventArgs($"获取设备编码器方向", serialNo: serialNo));
|
|
|
|
|
|
|
+ DebugMessageReceived?.Invoke(this, new DebugMessageReceivedEventArgs($"获取设备编码器方向", ipAddress: ipAddress, serialNo: serialNo));
|
|
|
clientSocket.Send(buffer);
|
|
clientSocket.Send(buffer);
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
@@ -737,6 +751,7 @@ namespace SWRIS.Core
|
|
|
/// <param name="serialNo"></param>
|
|
/// <param name="serialNo"></param>
|
|
|
/// <param name="stream"></param>
|
|
/// <param name="stream"></param>
|
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
|
|
|
+ [Obfuscation(Feature = "virtualization", Exclude = false)]
|
|
|
public bool SendSetEncoderDirectionData(EncoderDirection direction, string serialNo, Socket clientSocket)
|
|
public bool SendSetEncoderDirectionData(EncoderDirection direction, string serialNo, Socket clientSocket)
|
|
|
{
|
|
{
|
|
|
try
|
|
try
|
|
@@ -744,12 +759,14 @@ namespace SWRIS.Core
|
|
|
if (clientSocket == null || !clientSocket.Connected)
|
|
if (clientSocket == null || !clientSocket.Connected)
|
|
|
return false;
|
|
return false;
|
|
|
|
|
|
|
|
|
|
+ // 获取不含端口的IP地址
|
|
|
|
|
+ string ipAddress = ((IPEndPoint)clientSocket.RemoteEndPoint).Address.ToString();
|
|
|
using (var ms = new MemoryStream())
|
|
using (var ms = new MemoryStream())
|
|
|
{
|
|
{
|
|
|
ms.WriteByte(0x01); // 操作,0 = 获取编码器方向,1 = 设置编码器方向
|
|
ms.WriteByte(0x01); // 操作,0 = 获取编码器方向,1 = 设置编码器方向
|
|
|
ms.WriteByte((byte)direction); // 编码器方向,1=正向,2=反向
|
|
ms.WriteByte((byte)direction); // 编码器方向,1=正向,2=反向
|
|
|
byte[] buffer = CreateData(0x12, ms.ToArray(), serialNo);
|
|
byte[] buffer = CreateData(0x12, ms.ToArray(), serialNo);
|
|
|
- DebugMessageReceived?.Invoke(this, new DebugMessageReceivedEventArgs($"设置设备编码器方向", serialNo: serialNo));
|
|
|
|
|
|
|
+ DebugMessageReceived?.Invoke(this, new DebugMessageReceivedEventArgs($"设置设备编码器方向", ipAddress: ipAddress, serialNo: serialNo));
|
|
|
clientSocket.Send(buffer);
|
|
clientSocket.Send(buffer);
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
@@ -766,6 +783,7 @@ namespace SWRIS.Core
|
|
|
/// <param name="serialNo"></param>
|
|
/// <param name="serialNo"></param>
|
|
|
/// <param name="clientSocket"></param>
|
|
/// <param name="clientSocket"></param>
|
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
|
|
|
+ [Obfuscation(Feature = "virtualization", Exclude = false)]
|
|
|
private bool SendGetDetectionRawData(string serialNo, Socket clientSocket)
|
|
private bool SendGetDetectionRawData(string serialNo, Socket clientSocket)
|
|
|
{
|
|
{
|
|
|
try
|
|
try
|
|
@@ -773,13 +791,17 @@ namespace SWRIS.Core
|
|
|
if (clientSocket == null || !clientSocket.Connected)
|
|
if (clientSocket == null || !clientSocket.Connected)
|
|
|
return false;
|
|
return false;
|
|
|
|
|
|
|
|
|
|
+ // 获取不含端口的IP地址
|
|
|
|
|
+ string ipAddress = ((IPEndPoint)clientSocket.RemoteEndPoint).Address.ToString();
|
|
|
using (var ms = new MemoryStream())
|
|
using (var ms = new MemoryStream())
|
|
|
{
|
|
{
|
|
|
ms.WriteByte(0); // 数据类型,0=正常,1=报警,2=故障
|
|
ms.WriteByte(0); // 数据类型,0=正常,1=报警,2=故障
|
|
|
WriteBytes(ms, (short)2048); // 单包数据大小,单位:Byte
|
|
WriteBytes(ms, (short)2048); // 单包数据大小,单位:Byte
|
|
|
ms.WriteByte(0x00); // 传输速度控制,单位:KB/s(B/ms),为0则不控速
|
|
ms.WriteByte(0x00); // 传输速度控制,单位:KB/s(B/ms),为0则不控速
|
|
|
byte[] buffer = CreateData(0x0E, ms.ToArray(), serialNo);
|
|
byte[] buffer = CreateData(0x0E, ms.ToArray(), serialNo);
|
|
|
- DebugMessageReceived?.Invoke(this, new DebugMessageReceivedEventArgs($"获取检测结果原始数据", serialNo: serialNo));
|
|
|
|
|
|
|
+ DebugMessageReceived?.Invoke(this, new DebugMessageReceivedEventArgs($"获取检测结果原始数据",
|
|
|
|
|
+ ipAddress: ipAddress,
|
|
|
|
|
+ serialNo: serialNo));
|
|
|
clientSocket.Send(buffer);
|
|
clientSocket.Send(buffer);
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
@@ -795,16 +817,17 @@ namespace SWRIS.Core
|
|
|
/// </summary>
|
|
/// </summary>
|
|
|
/// <param name="buffer"></param>
|
|
/// <param name="buffer"></param>
|
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
|
|
|
+ [Obfuscation(Feature = "virtualization", Exclude = false)]
|
|
|
public DetectionRawResultDataModel ReceiveDetectionRawResultData(byte[] buffer)
|
|
public DetectionRawResultDataModel ReceiveDetectionRawResultData(byte[] buffer)
|
|
|
{
|
|
{
|
|
|
(string serialNo, byte[] bytes) = GetSerialNoAndData(buffer);
|
|
(string serialNo, byte[] bytes) = GetSerialNoAndData(buffer);
|
|
|
var detectionRawResultData = new DetectionRawResultDataModel
|
|
var detectionRawResultData = new DetectionRawResultDataModel
|
|
|
{
|
|
{
|
|
|
Code = bytes[0],
|
|
Code = bytes[0],
|
|
|
- Timestamp = byteTransform.TransInt32(bytes, 1),
|
|
|
|
|
- SamplingStep = byteTransform.TransSingle(bytes, 5),
|
|
|
|
|
- StartAbsolutePosition = byteTransform.TransSingle(bytes, 9),
|
|
|
|
|
- EndAbsolutePosition = byteTransform.TransSingle(bytes, 13),
|
|
|
|
|
|
|
+ Timestamp = _byteTransform.TransInt32(bytes, 1),
|
|
|
|
|
+ SamplingStep = _byteTransform.TransSingle(bytes, 5),
|
|
|
|
|
+ StartAbsolutePosition = _byteTransform.TransSingle(bytes, 9),
|
|
|
|
|
+ EndAbsolutePosition = _byteTransform.TransSingle(bytes, 13),
|
|
|
SensorCount = bytes[17]
|
|
SensorCount = bytes[17]
|
|
|
};
|
|
};
|
|
|
return detectionRawResultData;
|
|
return detectionRawResultData;
|
|
@@ -814,14 +837,15 @@ namespace SWRIS.Core
|
|
|
/// </summary>
|
|
/// </summary>
|
|
|
/// <param name="buffer"></param>
|
|
/// <param name="buffer"></param>
|
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
|
|
|
+ [Obfuscation(Feature = "virtualization", Exclude = false)]
|
|
|
public DetectionRawDataModel ReceiveDetectionRawData(byte[] buffer)
|
|
public DetectionRawDataModel ReceiveDetectionRawData(byte[] buffer)
|
|
|
{
|
|
{
|
|
|
(string serialNo, byte[] bytes) = GetSerialNoAndData(buffer);
|
|
(string serialNo, byte[] bytes) = GetSerialNoAndData(buffer);
|
|
|
var detectionRawData = new DetectionRawDataModel
|
|
var detectionRawData = new DetectionRawDataModel
|
|
|
{
|
|
{
|
|
|
- PacketNumber = byteTransform.TransUInt32(bytes, 0),
|
|
|
|
|
- TotalPackets = byteTransform.TransUInt32(bytes, 4),
|
|
|
|
|
- DataLength = byteTransform.TransUInt16(bytes, 8),
|
|
|
|
|
|
|
+ PacketNumber = _byteTransform.TransUInt32(bytes, 0),
|
|
|
|
|
+ TotalPackets = _byteTransform.TransUInt32(bytes, 4),
|
|
|
|
|
+ DataLength = _byteTransform.TransUInt16(bytes, 8),
|
|
|
Data = bytes.Skip(10).ToArray() // 跳过前10个字节
|
|
Data = bytes.Skip(10).ToArray() // 跳过前10个字节
|
|
|
};
|
|
};
|
|
|
|
|
|
|
@@ -834,6 +858,7 @@ namespace SWRIS.Core
|
|
|
/// <param name="serialNo">设备序列号</param>
|
|
/// <param name="serialNo">设备序列号</param>
|
|
|
/// <param name="client"></param>
|
|
/// <param name="client"></param>
|
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
|
|
|
+ [Obfuscation(Feature = "virtualization", Exclude = false)]
|
|
|
public bool SendTurnLiveStreamData(bool isOpen, string serialNo, Socket clientSocket)
|
|
public bool SendTurnLiveStreamData(bool isOpen, string serialNo, Socket clientSocket)
|
|
|
{
|
|
{
|
|
|
try
|
|
try
|
|
@@ -841,11 +866,16 @@ namespace SWRIS.Core
|
|
|
if (clientSocket == null || !clientSocket.Connected)
|
|
if (clientSocket == null || !clientSocket.Connected)
|
|
|
return false;
|
|
return false;
|
|
|
|
|
|
|
|
|
|
+ // 获取不含端口的IP地址
|
|
|
|
|
+ string ipAddress = ((IPEndPoint)clientSocket.RemoteEndPoint).Address.ToString();
|
|
|
|
|
+
|
|
|
using (var ms = new MemoryStream())
|
|
using (var ms = new MemoryStream())
|
|
|
{
|
|
{
|
|
|
ms.WriteByte((byte)(isOpen ? 1 : 0)); // 0=关闭,1=开启
|
|
ms.WriteByte((byte)(isOpen ? 1 : 0)); // 0=关闭,1=开启
|
|
|
byte[] buffer = CreateData(0x0C, ms.ToArray(), serialNo);
|
|
byte[] buffer = CreateData(0x0C, ms.ToArray(), serialNo);
|
|
|
- DebugMessageReceived?.Invoke(this, new DebugMessageReceivedEventArgs($"{(isOpen ? "开启" : "关闭")}设备实时流", serialNo: serialNo));
|
|
|
|
|
|
|
+ DebugMessageReceived?.Invoke(this, new DebugMessageReceivedEventArgs($"{(isOpen ? "开启" : "关闭")}设备实时流",
|
|
|
|
|
+ ipAddress: ipAddress,
|
|
|
|
|
+ serialNo: serialNo));
|
|
|
clientSocket.Send(buffer);
|
|
clientSocket.Send(buffer);
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
@@ -869,13 +899,15 @@ namespace SWRIS.Core
|
|
|
if (clientSocket == null || !clientSocket.Connected)
|
|
if (clientSocket == null || !clientSocket.Connected)
|
|
|
return false;
|
|
return false;
|
|
|
|
|
|
|
|
|
|
+ // 获取不含端口的IP地址
|
|
|
|
|
+ string ipAddress = ((IPEndPoint)clientSocket.RemoteEndPoint).Address.ToString();
|
|
|
using (var ms = new MemoryStream())
|
|
using (var ms = new MemoryStream())
|
|
|
{
|
|
{
|
|
|
ms.WriteByte(0x00); // 操作,0=获取判伤捻距系数,1=设置判伤捻距系数
|
|
ms.WriteByte(0x00); // 操作,0=获取判伤捻距系数,1=设置判伤捻距系数
|
|
|
WriteBytes(ms, 0); // 判伤捻距系数
|
|
WriteBytes(ms, 0); // 判伤捻距系数
|
|
|
byte[] buffer = CreateData(0x13, ms.ToArray(), serialNo);
|
|
byte[] buffer = CreateData(0x13, ms.ToArray(), serialNo);
|
|
|
DebugMessageReceived?.Invoke(this,
|
|
DebugMessageReceived?.Invoke(this,
|
|
|
- new DebugMessageReceivedEventArgs($"获取设备判伤捻距系数", serialNo: serialNo));
|
|
|
|
|
|
|
+ new DebugMessageReceivedEventArgs($"获取设备判伤捻距系数", ipAddress: ipAddress, serialNo: serialNo));
|
|
|
clientSocket.Send(buffer);
|
|
clientSocket.Send(buffer);
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
@@ -891,7 +923,7 @@ namespace SWRIS.Core
|
|
|
/// </summary>
|
|
/// </summary>
|
|
|
/// <param name="twistFactor"></param>
|
|
/// <param name="twistFactor"></param>
|
|
|
/// <param name="serialNo"></param>
|
|
/// <param name="serialNo"></param>
|
|
|
- /// <param name="stream"></param>
|
|
|
|
|
|
|
+ /// <param name="clientSocket"></param>
|
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
|
public bool SendSetTwistFactorData(float twistFactor, string serialNo, Socket clientSocket)
|
|
public bool SendSetTwistFactorData(float twistFactor, string serialNo, Socket clientSocket)
|
|
|
{
|
|
{
|
|
@@ -945,7 +977,7 @@ namespace SWRIS.Core
|
|
|
{
|
|
{
|
|
|
Code = bytes[0],
|
|
Code = bytes[0],
|
|
|
Type = bytes[1],
|
|
Type = bytes[1],
|
|
|
- Time = byteTransform.TransInt32(bytes, 2)
|
|
|
|
|
|
|
+ Time = _byteTransform.TransInt32(bytes, 2)
|
|
|
};
|
|
};
|
|
|
return clockData;
|
|
return clockData;
|
|
|
}
|
|
}
|
|
@@ -992,12 +1024,14 @@ namespace SWRIS.Core
|
|
|
if (clientSocket == null || !clientSocket.Connected)
|
|
if (clientSocket == null || !clientSocket.Connected)
|
|
|
return false;
|
|
return false;
|
|
|
|
|
|
|
|
|
|
+ // 获取不含端口的IP地址
|
|
|
|
|
+ string ipAddress = ((IPEndPoint)clientSocket.RemoteEndPoint).Address.ToString();
|
|
|
using (var ms = new MemoryStream())
|
|
using (var ms = new MemoryStream())
|
|
|
{
|
|
{
|
|
|
ms.WriteByte(0x00); // 操作,0=获取时钟,1=设置时钟
|
|
ms.WriteByte(0x00); // 操作,0=获取时钟,1=设置时钟
|
|
|
WriteBytes(ms, 0);// 设置时间戳
|
|
WriteBytes(ms, 0);// 设置时间戳
|
|
|
byte[] buffer = CreateData(0x10, ms.ToArray(), serialNo);
|
|
byte[] buffer = CreateData(0x10, ms.ToArray(), serialNo);
|
|
|
- DebugMessageReceived?.Invoke(this, new DebugMessageReceivedEventArgs($"获取设备时钟", serialNo: serialNo));
|
|
|
|
|
|
|
+ DebugMessageReceived?.Invoke(this, new DebugMessageReceivedEventArgs($"获取设备时钟", ipAddress: ipAddress, serialNo: serialNo));
|
|
|
clientSocket.Send(buffer);
|
|
clientSocket.Send(buffer);
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
@@ -1013,7 +1047,7 @@ namespace SWRIS.Core
|
|
|
/// </summary>
|
|
/// </summary>
|
|
|
/// <param name="timestamp">时间戳</param>
|
|
/// <param name="timestamp">时间戳</param>
|
|
|
/// <param name="serialNo">序列号</param>
|
|
/// <param name="serialNo">序列号</param>
|
|
|
- /// <param name="stream">网络数据流</param>
|
|
|
|
|
|
|
+ /// <param name="clientSocket">网络数据流</param>
|
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
|
public bool SendSetClockData(int timestamp, string serialNo, Socket clientSocket)
|
|
public bool SendSetClockData(int timestamp, string serialNo, Socket clientSocket)
|
|
|
{
|
|
{
|
|
@@ -1022,12 +1056,16 @@ namespace SWRIS.Core
|
|
|
if (clientSocket == null || !clientSocket.Connected)
|
|
if (clientSocket == null || !clientSocket.Connected)
|
|
|
return false;
|
|
return false;
|
|
|
|
|
|
|
|
|
|
+ // 获取不含端口的IP地址
|
|
|
|
|
+ string ipAddress = ((IPEndPoint)clientSocket.RemoteEndPoint).Address.ToString();
|
|
|
using (var ms = new MemoryStream())
|
|
using (var ms = new MemoryStream())
|
|
|
{
|
|
{
|
|
|
ms.WriteByte(0x01); // 操作,0=获取时钟,1=设置时钟
|
|
ms.WriteByte(0x01); // 操作,0=获取时钟,1=设置时钟
|
|
|
WriteBytes(ms, timestamp);// 设置时间戳
|
|
WriteBytes(ms, timestamp);// 设置时间戳
|
|
|
byte[] buffer = CreateData(0x10, ms.ToArray(), serialNo);
|
|
byte[] buffer = CreateData(0x10, ms.ToArray(), serialNo);
|
|
|
- DebugMessageReceived?.Invoke(this, new DebugMessageReceivedEventArgs($"设置设备时钟", serialNo: serialNo));
|
|
|
|
|
|
|
+ DebugMessageReceived?.Invoke(this, new DebugMessageReceivedEventArgs($"设置设备时钟",
|
|
|
|
|
+ ipAddress: ipAddress,
|
|
|
|
|
+ serialNo: serialNo));
|
|
|
clientSocket.Send(buffer);
|
|
clientSocket.Send(buffer);
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
@@ -1049,9 +1087,9 @@ namespace SWRIS.Core
|
|
|
RealTimeDataModel realTimeData = new RealTimeDataModel
|
|
RealTimeDataModel realTimeData = new RealTimeDataModel
|
|
|
{
|
|
{
|
|
|
Status = (RunningStatus)bytes[0],
|
|
Status = (RunningStatus)bytes[0],
|
|
|
- Speed = byteTransform.TransSingle(bytes, 1),
|
|
|
|
|
- AbsolutePosition = byteTransform.TransSingle(bytes, 5),
|
|
|
|
|
- Position = byteTransform.TransSingle(bytes, 9)
|
|
|
|
|
|
|
+ Speed = _byteTransform.TransSingle(bytes, 1),
|
|
|
|
|
+ AbsolutePosition = _byteTransform.TransSingle(bytes, 5),
|
|
|
|
|
+ Position = _byteTransform.TransSingle(bytes, 9)
|
|
|
};
|
|
};
|
|
|
return realTimeData;
|
|
return realTimeData;
|
|
|
}
|
|
}
|
|
@@ -1071,13 +1109,13 @@ namespace SWRIS.Core
|
|
|
var data = verifyData.Data;
|
|
var data = verifyData.Data;
|
|
|
DetectionDataModel detectionData = new DetectionDataModel
|
|
DetectionDataModel detectionData = new DetectionDataModel
|
|
|
{
|
|
{
|
|
|
- StartTime = byteTransform.TransInt32(data, 0),
|
|
|
|
|
- EndTime = byteTransform.TransInt32(data, 4),
|
|
|
|
|
- StartPoint = byteTransform.TransSingle(data, 8),
|
|
|
|
|
- EndPoint = byteTransform.TransSingle(data, 12),
|
|
|
|
|
- DetectionLength = byteTransform.TransSingle(data, 16),
|
|
|
|
|
- DetectedSpeed = byteTransform.TransSingle(data, 20),
|
|
|
|
|
- DamageCount = byteTransform.TransInt16(data, 24),
|
|
|
|
|
|
|
+ StartTime = _byteTransform.TransInt32(data, 0),
|
|
|
|
|
+ EndTime = _byteTransform.TransInt32(data, 4),
|
|
|
|
|
+ StartPoint = _byteTransform.TransSingle(data, 8),
|
|
|
|
|
+ EndPoint = _byteTransform.TransSingle(data, 12),
|
|
|
|
|
+ DetectionLength = _byteTransform.TransSingle(data, 16),
|
|
|
|
|
+ DetectedSpeed = _byteTransform.TransSingle(data, 20),
|
|
|
|
|
+ DamageCount = _byteTransform.TransInt16(data, 24),
|
|
|
Damages = new List<DamageModel>()
|
|
Damages = new List<DamageModel>()
|
|
|
};
|
|
};
|
|
|
for (int i = 0; i < detectionData.DamageCount; i++)
|
|
for (int i = 0; i < detectionData.DamageCount; i++)
|
|
@@ -1087,8 +1125,8 @@ namespace SWRIS.Core
|
|
|
var damageData = new DamageModel
|
|
var damageData = new DamageModel
|
|
|
{
|
|
{
|
|
|
RopeNumber = data[offset],
|
|
RopeNumber = data[offset],
|
|
|
- DamagePoint = byteTransform.TransSingle(data, offset + 1),
|
|
|
|
|
- DamageValue = byteTransform.TransSingle(data, offset + 5),
|
|
|
|
|
|
|
+ DamagePoint = _byteTransform.TransSingle(data, offset + 1),
|
|
|
|
|
+ DamageValue = _byteTransform.TransSingle(data, offset + 5),
|
|
|
DamageLevel = (DamageLevel)data[offset + 9]
|
|
DamageLevel = (DamageLevel)data[offset + 9]
|
|
|
};
|
|
};
|
|
|
detectionData.Damages.Add(damageData);
|
|
detectionData.Damages.Add(damageData);
|
|
@@ -1112,8 +1150,8 @@ namespace SWRIS.Core
|
|
|
AlarmDataModel alarmData = new AlarmDataModel
|
|
AlarmDataModel alarmData = new AlarmDataModel
|
|
|
{
|
|
{
|
|
|
RopeNumber = data[1],
|
|
RopeNumber = data[1],
|
|
|
- DamagePosition = byteTransform.TransSingle(data, 2),
|
|
|
|
|
- DamageValue = byteTransform.TransSingle(data, 6),
|
|
|
|
|
|
|
+ DamagePosition = _byteTransform.TransSingle(data, 2),
|
|
|
|
|
+ DamageValue = _byteTransform.TransSingle(data, 6),
|
|
|
DamageLevel = (DamageLevel)data[10]
|
|
DamageLevel = (DamageLevel)data[10]
|
|
|
};
|
|
};
|
|
|
return alarmData;
|
|
return alarmData;
|
|
@@ -1134,7 +1172,7 @@ namespace SWRIS.Core
|
|
|
FaultDataModel faultData = new FaultDataModel();
|
|
FaultDataModel faultData = new FaultDataModel();
|
|
|
var data = verifyData.Data;
|
|
var data = verifyData.Data;
|
|
|
faultData.FaultType = (FaultType)data[0];
|
|
faultData.FaultType = (FaultType)data[0];
|
|
|
- faultData.FaultCode = byteTransform.TransInt32(data, 1);
|
|
|
|
|
|
|
+ faultData.FaultCode = _byteTransform.TransInt32(data, 1);
|
|
|
return faultData;
|
|
return faultData;
|
|
|
}
|
|
}
|
|
|
public byte ReceiveStartOrStopDetectionResultData(byte[] buffer)
|
|
public byte ReceiveStartOrStopDetectionResultData(byte[] buffer)
|
|
@@ -1158,11 +1196,15 @@ namespace SWRIS.Core
|
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
|
private void RespondHeartbeat(byte[] buffer, string ipAddress, Socket clientSocket)
|
|
private void RespondHeartbeat(byte[] buffer, string ipAddress, Socket clientSocket)
|
|
|
{
|
|
{
|
|
|
- if (buffer[1] == 0x00)
|
|
|
|
|
|
|
+ try
|
|
|
{
|
|
{
|
|
|
- byte[] response = new byte[] { 0xD0, 0x00 };
|
|
|
|
|
- clientSocket.Send(response); // 直接使用Socket发送
|
|
|
|
|
|
|
+ if (buffer[1] == 0x00)
|
|
|
|
|
+ {
|
|
|
|
|
+ byte[] response = new byte[] { 0xD0, 0x00 };
|
|
|
|
|
+ clientSocket.Send(response); // 直接使用Socket发送
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
+ finally { }
|
|
|
}
|
|
}
|
|
|
private async Task ProcessSerialNoData(byte[] buffer, ClientState client)
|
|
private async Task ProcessSerialNoData(byte[] buffer, ClientState client)
|
|
|
{
|
|
{
|
|
@@ -1204,44 +1246,44 @@ namespace SWRIS.Core
|
|
|
#endregion
|
|
#endregion
|
|
|
|
|
|
|
|
#region 基础参数
|
|
#region 基础参数
|
|
|
- parameterData.SensorCount = byteTransform.TransInt16(data, index); index += 2;
|
|
|
|
|
- parameterData.SamplingStep = byteTransform.TransSingle(data, index); index += 4;
|
|
|
|
|
- parameterData.FrequencyDivisionFactor = byteTransform.TransInt16(data, index); index += 2;
|
|
|
|
|
- parameterData.TimeDomainFrequency = byteTransform.TransInt16(data, index); index += 2;
|
|
|
|
|
|
|
+ parameterData.SensorCount = _byteTransform.TransInt16(data, index); index += 2;
|
|
|
|
|
+ parameterData.SamplingStep = _byteTransform.TransSingle(data, index); index += 4;
|
|
|
|
|
+ parameterData.FrequencyDivisionFactor = _byteTransform.TransInt16(data, index); index += 2;
|
|
|
|
|
+ parameterData.DamageInterval = _byteTransform.TransInt16(data, index); index += 2;
|
|
|
#endregion
|
|
#endregion
|
|
|
|
|
|
|
|
#region 判伤参数
|
|
#region 判伤参数
|
|
|
- parameterData.DamageThreshold = byteTransform.TransInt16(data, index); index += 2;
|
|
|
|
|
- parameterData.ScrapUpperLimit = byteTransform.TransInt16(data, index); index += 2;
|
|
|
|
|
- parameterData.FrontMagnetLength = byteTransform.TransInt16(data, index); index += 2;
|
|
|
|
|
- parameterData.BackMagnetLength = byteTransform.TransInt16(data, index); index += 2;
|
|
|
|
|
- parameterData.ValueCoefficient = byteTransform.TransSingle(data, index); index += 4;
|
|
|
|
|
|
|
+ parameterData.DamageThreshold = _byteTransform.TransInt16(data, index); index += 2;
|
|
|
|
|
+ parameterData.ScrapUpperLimit = _byteTransform.TransInt16(data, index); index += 2;
|
|
|
|
|
+ parameterData.FrontMagnetLength = _byteTransform.TransInt16(data, index); index += 2;
|
|
|
|
|
+ parameterData.BackMagnetLength = _byteTransform.TransInt16(data, index); index += 2;
|
|
|
|
|
+ parameterData.ValueCoefficient = _byteTransform.TransSingle(data, index); index += 4;
|
|
|
#endregion
|
|
#endregion
|
|
|
|
|
|
|
|
#region 零点位参数
|
|
#region 零点位参数
|
|
|
- parameterData.EffectiveStrokeLength = byteTransform.TransSingle(data, index); index += 4;
|
|
|
|
|
- parameterData.ZeroPositionCorrectionDuration = byteTransform.TransInt16(data, index); index += 2;
|
|
|
|
|
- parameterData.ZeroPositionCorrectionOffset = byteTransform.TransInt16(data, index); index += 2;
|
|
|
|
|
|
|
+ parameterData.EffectiveStrokeLength = _byteTransform.TransSingle(data, index); index += 4;
|
|
|
|
|
+ parameterData.ZeroPositionCorrectionDuration = _byteTransform.TransInt16(data, index); index += 2;
|
|
|
|
|
+ parameterData.ZeroPositionCorrectionOffset = _byteTransform.TransInt16(data, index); index += 2;
|
|
|
#endregion
|
|
#endregion
|
|
|
|
|
|
|
|
#region 报警参数
|
|
#region 报警参数
|
|
|
- parameterData.WarningValue = byteTransform.TransSingle(data, index); index += 4;
|
|
|
|
|
- parameterData.AlarmValue = byteTransform.TransSingle(data, index); index += 4;
|
|
|
|
|
- parameterData.SoundLightAlarmAutoResetMode = byteTransform.TransInt16(data, index); index += 2;
|
|
|
|
|
|
|
+ parameterData.WarningValue = _byteTransform.TransSingle(data, index); index += 4;
|
|
|
|
|
+ parameterData.AlarmValue = _byteTransform.TransSingle(data, index); index += 4;
|
|
|
|
|
+ parameterData.SoundLightAlarmAutoResetMode = _byteTransform.TransInt16(data, index); index += 2;
|
|
|
#endregion
|
|
#endregion
|
|
|
|
|
|
|
|
#region 钢丝绳信息
|
|
#region 钢丝绳信息
|
|
|
- parameterData.WireRopeType = byteTransform.TransInt16(data, index); index += 2;
|
|
|
|
|
- parameterData.WireRopeCount = byteTransform.TransInt16(data, index); index += 2;
|
|
|
|
|
- parameterData.WireRopeLength = byteTransform.TransSingle(data, index); index += 4;
|
|
|
|
|
- parameterData.WireRopeDiameter = byteTransform.TransSingle(data, index); index += 4;
|
|
|
|
|
- parameterData.WireRopeStrandCount = byteTransform.TransInt16(data, index); index += 2;
|
|
|
|
|
- parameterData.WireRopeStrandWireCount = byteTransform.TransInt16(data, index); index += 2;
|
|
|
|
|
|
|
+ parameterData.WireRopeType = _byteTransform.TransInt16(data, index); index += 2;
|
|
|
|
|
+ parameterData.WireRopeCount = _byteTransform.TransInt16(data, index); index += 2;
|
|
|
|
|
+ parameterData.WireRopeLength = _byteTransform.TransSingle(data, index); index += 4;
|
|
|
|
|
+ parameterData.WireRopeDiameter = _byteTransform.TransSingle(data, index); index += 4;
|
|
|
|
|
+ parameterData.WireRopeStrandCount = _byteTransform.TransInt16(data, index); index += 2;
|
|
|
|
|
+ parameterData.WireRopeStrandWireCount = _byteTransform.TransInt16(data, index); index += 2;
|
|
|
#endregion
|
|
#endregion
|
|
|
|
|
|
|
|
#region 限位校准位置
|
|
#region 限位校准位置
|
|
|
- parameterData.FirstCalibrationPositiont = byteTransform.TransSingle(data, index); index += 4;
|
|
|
|
|
- parameterData.SecondCalibrationPositiont = byteTransform.TransSingle(data, index); index += 4;
|
|
|
|
|
|
|
+ parameterData.FirstCalibrationPositiont = _byteTransform.TransSingle(data, index); index += 4;
|
|
|
|
|
+ parameterData.SecondCalibrationPositiont = _byteTransform.TransSingle(data, index); index += 4;
|
|
|
#endregion
|
|
#endregion
|
|
|
|
|
|
|
|
return (verifyData.SerialNo, parameterData);
|
|
return (verifyData.SerialNo, parameterData);
|
|
@@ -1264,7 +1306,7 @@ namespace SWRIS.Core
|
|
|
WriteBytes(ms, parameters.SensorCount);
|
|
WriteBytes(ms, parameters.SensorCount);
|
|
|
WriteBytes(ms, parameters.SamplingStep);
|
|
WriteBytes(ms, parameters.SamplingStep);
|
|
|
WriteBytes(ms, parameters.FrequencyDivisionFactor);
|
|
WriteBytes(ms, parameters.FrequencyDivisionFactor);
|
|
|
- WriteBytes(ms, parameters.TimeDomainFrequency);
|
|
|
|
|
|
|
+ WriteBytes(ms, parameters.DamageInterval);
|
|
|
|
|
|
|
|
// Damage judgment parameters
|
|
// Damage judgment parameters
|
|
|
WriteBytes(ms, parameters.DamageThreshold);
|
|
WriteBytes(ms, parameters.DamageThreshold);
|
|
@@ -1310,7 +1352,7 @@ namespace SWRIS.Core
|
|
|
/// <summary>
|
|
/// <summary>
|
|
|
/// 发送开始或停止检测命令
|
|
/// 发送开始或停止检测命令
|
|
|
/// </summary>
|
|
/// </summary>
|
|
|
- /// <param name="mode">检测模式 0=停止,1=启动空域检测,2=启动时域检测</param>
|
|
|
|
|
|
|
+ /// <param name="runningMode">检测模式 0=停止,1=启动空域检测,2=启动时域检测</param>
|
|
|
/// <param name="serialNo">设备序列号</param>
|
|
/// <param name="serialNo">设备序列号</param>
|
|
|
/// <param name="clientSocket">数据流</param>
|
|
/// <param name="clientSocket">数据流</param>
|
|
|
public bool SendStartOrStopDetection(byte runningMode, string serialNo, Socket clientSocket)
|
|
public bool SendStartOrStopDetection(byte runningMode, string serialNo, Socket clientSocket)
|
|
@@ -1408,11 +1450,14 @@ namespace SWRIS.Core
|
|
|
if (clientSocket == null || !clientSocket.Connected)
|
|
if (clientSocket == null || !clientSocket.Connected)
|
|
|
return;
|
|
return;
|
|
|
|
|
|
|
|
|
|
+ string ipAddress = ((IPEndPoint)clientSocket.RemoteEndPoint).Address.ToString();
|
|
|
using (var ms = new MemoryStream())
|
|
using (var ms = new MemoryStream())
|
|
|
{
|
|
{
|
|
|
ms.WriteByte((byte)(isOpen ? 1 : 0)); // 0=关闭,1=开启
|
|
ms.WriteByte((byte)(isOpen ? 1 : 0)); // 0=关闭,1=开启
|
|
|
byte[] buffer = CreateData(0x06, ms.ToArray(), serialNo);
|
|
byte[] buffer = CreateData(0x06, ms.ToArray(), serialNo);
|
|
|
- DebugMessageReceived?.Invoke(this, new DebugMessageReceivedEventArgs($"{(isOpen ? "开启" : "停止")}设备实时数据", serialNo: serialNo));
|
|
|
|
|
|
|
+ DebugMessageReceived?.Invoke(this, new DebugMessageReceivedEventArgs($"{(isOpen ? "开启" : "停止")}设备实时数据",
|
|
|
|
|
+ ipAddress: ipAddress,
|
|
|
|
|
+ serialNo: serialNo));
|
|
|
clientSocket.Send(buffer);
|
|
clientSocket.Send(buffer);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -1442,7 +1487,7 @@ namespace SWRIS.Core
|
|
|
}
|
|
}
|
|
|
private void WriteBytes(MemoryStream ms, dynamic value)
|
|
private void WriteBytes(MemoryStream ms, dynamic value)
|
|
|
{
|
|
{
|
|
|
- var bytes = byteTransform.TransByte(value);
|
|
|
|
|
|
|
+ var bytes = _byteTransform.TransByte(value);
|
|
|
ms.Write(bytes, 0, bytes.Length);
|
|
ms.Write(bytes, 0, bytes.Length);
|
|
|
}
|
|
}
|
|
|
/// <summary>
|
|
/// <summary>
|
|
@@ -1456,13 +1501,15 @@ namespace SWRIS.Core
|
|
|
{
|
|
{
|
|
|
if (clientSocket == null || !clientSocket.Connected)
|
|
if (clientSocket == null || !clientSocket.Connected)
|
|
|
return false;
|
|
return false;
|
|
|
|
|
+
|
|
|
|
|
+ string ipAddress = ((IPEndPoint)clientSocket.RemoteEndPoint).Address.ToString();
|
|
|
using (var ms = new MemoryStream())
|
|
using (var ms = new MemoryStream())
|
|
|
{
|
|
{
|
|
|
WriteBytes(ms, startTime);
|
|
WriteBytes(ms, startTime);
|
|
|
WriteBytes(ms, endTime);
|
|
WriteBytes(ms, endTime);
|
|
|
|
|
|
|
|
byte[] buffer = CreateData(0x09, ms.ToArray(), serialNo);
|
|
byte[] buffer = CreateData(0x09, ms.ToArray(), serialNo);
|
|
|
- DebugMessageReceived?.Invoke(this, new DebugMessageReceivedEventArgs($"确认设备检测结果", serialNo: serialNo));
|
|
|
|
|
|
|
+ DebugMessageReceived?.Invoke(this, new DebugMessageReceivedEventArgs($"确认设备检测结果", ipAddress: ipAddress, serialNo: serialNo));
|
|
|
clientSocket.Send(buffer);
|
|
clientSocket.Send(buffer);
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
@@ -1531,6 +1578,7 @@ namespace SWRIS.Core
|
|
|
/// </summary>
|
|
/// </summary>
|
|
|
/// <param name="buffer">数据</param>
|
|
/// <param name="buffer">数据</param>
|
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
|
|
|
+ [Obfuscation(Feature = "virtualization", Exclude = false)]
|
|
|
private VerifyDataModel GetVerifyDataAndCheckCaption(byte[] buffer)
|
|
private VerifyDataModel GetVerifyDataAndCheckCaption(byte[] buffer)
|
|
|
{
|
|
{
|
|
|
VerifyDataModel verifyData = new VerifyDataModel() { Password = PASSWORD };
|
|
VerifyDataModel verifyData = new VerifyDataModel() { Password = PASSWORD };
|
|
@@ -1551,7 +1599,7 @@ namespace SWRIS.Core
|
|
|
|
|
|
|
|
// 读取随机码
|
|
// 读取随机码
|
|
|
if (span.Length < 4) return verifyData;
|
|
if (span.Length < 4) return verifyData;
|
|
|
- verifyData.RandomCode = byteTransform.TransUInt32(span.ToArray(), 0);
|
|
|
|
|
|
|
+ verifyData.RandomCode = _byteTransform.TransUInt32(span.ToArray(), 0);
|
|
|
span = span.Slice(4);
|
|
span = span.Slice(4);
|
|
|
|
|
|
|
|
// 读取验证码长度
|
|
// 读取验证码长度
|
|
@@ -1574,27 +1622,47 @@ namespace SWRIS.Core
|
|
|
/// 验证码校验
|
|
/// 验证码校验
|
|
|
/// </summary>
|
|
/// </summary>
|
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
|
|
|
+ [Obfuscation(Feature = "virtualization", Exclude = false)]
|
|
|
private static bool VerifyCaptcha(VerifyDataModel verifyData)
|
|
private static bool VerifyCaptcha(VerifyDataModel verifyData)
|
|
|
{
|
|
{
|
|
|
|
|
+ if (verifyData == null)
|
|
|
|
|
+ throw new ArgumentNullException(nameof(verifyData));
|
|
|
|
|
+
|
|
|
|
|
+ if (verifyData.Captcha == null || verifyData.Captcha.Length < 16)
|
|
|
|
|
+ return false;
|
|
|
|
|
+
|
|
|
byte[] computedHash;
|
|
byte[] computedHash;
|
|
|
using (var md5 = MD5.Create())
|
|
using (var md5 = MD5.Create())
|
|
|
{
|
|
{
|
|
|
- computedHash = md5.ComputeHash(Encoding.UTF8.GetBytes(verifyData.SerialNo + verifyData.Password + verifyData.RandomCode));
|
|
|
|
|
- }
|
|
|
|
|
- var buffer = verifyData.Captcha;
|
|
|
|
|
- for (int i = 0; i < 16; i++)
|
|
|
|
|
- {
|
|
|
|
|
- if (buffer[i] != computedHash[i])
|
|
|
|
|
- return false;
|
|
|
|
|
|
|
+ computedHash = md5.ComputeHash(
|
|
|
|
|
+ Encoding.UTF8.GetBytes(
|
|
|
|
|
+ verifyData.SerialNo + verifyData.Password + verifyData.RandomCode));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return true;
|
|
|
|
|
|
|
+ // 常量时间比较(手动实现)
|
|
|
|
|
+ return FixedTimeEquals(verifyData.Captcha, computedHash, 16);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 常量时间比较两个字节数组,防止时序攻击
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ private static bool FixedTimeEquals(byte[] a, byte[] b, int length)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (a.Length < length || b.Length < length)
|
|
|
|
|
+ return false;
|
|
|
|
|
+
|
|
|
|
|
+ int result = 0;
|
|
|
|
|
+ for (int i = 0; i < length; i++)
|
|
|
|
|
+ {
|
|
|
|
|
+ result |= a[i] ^ b[i]; // XOR 操作,相同为0,不同为非0
|
|
|
|
|
+ }
|
|
|
|
|
+ return result == 0;
|
|
|
|
|
+ }
|
|
|
///<summary>
|
|
///<summary>
|
|
|
///创建数据验证码
|
|
///创建数据验证码
|
|
|
///</summary>
|
|
///</summary>
|
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
|
|
|
+ [Obfuscation(Feature = "virtualization", Exclude = false)]
|
|
|
protected byte[] CreateData(byte eventType, byte[] data, string serialNo)
|
|
protected byte[] CreateData(byte eventType, byte[] data, string serialNo)
|
|
|
{
|
|
{
|
|
|
using (var md5 = MD5.Create())
|
|
using (var md5 = MD5.Create())
|
|
@@ -1603,7 +1671,7 @@ namespace SWRIS.Core
|
|
|
{
|
|
{
|
|
|
// 1. 预先计算所有字段的长度
|
|
// 1. 预先计算所有字段的长度
|
|
|
uint randomCode = (uint)DateTimeOffset.UtcNow.ToUnixTimeSeconds();
|
|
uint randomCode = (uint)DateTimeOffset.UtcNow.ToUnixTimeSeconds();
|
|
|
- byte[] randomCodeBytes = byteTransform.TransByte(randomCode);
|
|
|
|
|
|
|
+ byte[] randomCodeBytes = _byteTransform.TransByte(randomCode);
|
|
|
byte[] hash = md5.ComputeHash(Encoding.ASCII.GetBytes(serialNo + PASSWORD + randomCode));
|
|
byte[] hash = md5.ComputeHash(Encoding.ASCII.GetBytes(serialNo + PASSWORD + randomCode));
|
|
|
byte[] captcha = SoftBasic.BytesToAsciiBytes(hash);
|
|
byte[] captcha = SoftBasic.BytesToAsciiBytes(hash);
|
|
|
|
|
|
|
@@ -1625,7 +1693,7 @@ namespace SWRIS.Core
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
// 假设byteTransform.TransByte将short转为2字节大端序
|
|
// 假设byteTransform.TransByte将short转为2字节大端序
|
|
|
- byte[] remainingLengthBytes = byteTransform.TransByte(remainingLength);
|
|
|
|
|
|
|
+ byte[] remainingLengthBytes = _byteTransform.TransByte(remainingLength);
|
|
|
ms.Write(remainingLengthBytes, 0, remainingLengthBytes.Length);
|
|
ms.Write(remainingLengthBytes, 0, remainingLengthBytes.Length);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -1640,7 +1708,7 @@ namespace SWRIS.Core
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+ [Obfuscation(Feature = "virtualization", Exclude = false)]
|
|
|
public ushort[][] ParseSensorData(byte[] data, int sensorCount, int sampleCount)
|
|
public ushort[][] ParseSensorData(byte[] data, int sensorCount, int sampleCount)
|
|
|
{
|
|
{
|
|
|
// 检查数据长度是否匹配
|
|
// 检查数据长度是否匹配
|
|
@@ -1678,6 +1746,7 @@ namespace SWRIS.Core
|
|
|
/// <param name="bytes"></param>
|
|
/// <param name="bytes"></param>
|
|
|
/// <param name="startIndex"></param>
|
|
/// <param name="startIndex"></param>
|
|
|
/// <returns></returns>
|
|
/// <returns></returns>
|
|
|
|
|
+ [Obfuscation(Feature = "virtualization", Exclude = false)]
|
|
|
public static (int BytesConsumed, int Length) GetRemainingLength(byte[] bytes)
|
|
public static (int BytesConsumed, int Length) GetRemainingLength(byte[] bytes)
|
|
|
{
|
|
{
|
|
|
if (bytes == null || bytes.Length < 2) return (0, 0);
|
|
if (bytes == null || bytes.Length < 2) return (0, 0);
|
|
@@ -1705,7 +1774,7 @@ namespace SWRIS.Core
|
|
|
|
|
|
|
|
return (bytesConsumed, value);
|
|
return (bytesConsumed, value);
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
|
|
+ [Obfuscation(Feature = "virtualization", Exclude = false)]
|
|
|
private static (string SerialNo, byte[] Bytes) GetSerialNoAndData(byte[] buffer)
|
|
private static (string SerialNo, byte[] Bytes) GetSerialNoAndData(byte[] buffer)
|
|
|
{
|
|
{
|
|
|
// 使用Span直接操作内存
|
|
// 使用Span直接操作内存
|