CRC校验
This commit is contained in:
parent
ff9ee61c40
commit
7edf0df8e6
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -202,6 +202,8 @@ internal class MagnetServer
|
||||||
/// <param name="clientSocket"></param>
|
/// <param name="clientSocket"></param>
|
||||||
private static void ReceiveMsg(Socket clientSocket)
|
private static void ReceiveMsg(Socket clientSocket)
|
||||||
{
|
{
|
||||||
|
StringBuilder builder_shuju = new StringBuilder("");//需校验字节
|
||||||
|
StringBuilder builder_crc = new StringBuilder("");//收到检验位
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
byte[] bytes = new byte[1024];
|
byte[] bytes = new byte[1024];
|
||||||
|
@ -229,7 +231,27 @@ internal class MagnetServer
|
||||||
{
|
{
|
||||||
//string message = Encoding.Default.GetString(bytes, 0, length);
|
//string message = Encoding.Default.GetString(bytes, 0, length);
|
||||||
string message = ToolKit.byteArrayToHexString(bytes, length);
|
string message = ToolKit.byteArrayToHexString(bytes, length);
|
||||||
log.Info("接收到" + clientSocket.RemoteEndPoint + ": " + message);
|
|
||||||
|
//CRC校验--失败返回不解析
|
||||||
|
builder_shuju.Clear();
|
||||||
|
builder_crc.Clear();
|
||||||
|
for (int i = 0; i < message.Length - 4; i++)
|
||||||
|
{
|
||||||
|
builder_shuju.Append(message[i]);
|
||||||
|
}
|
||||||
|
for (int i = message.Length - 4; i < message.Length; i++)
|
||||||
|
{
|
||||||
|
builder_crc.Append(message[i]);
|
||||||
|
}
|
||||||
|
if (CRC.CRCForModbus(builder_shuju.ToString().ToUpper()) != builder_crc.ToString().ToUpper())
|
||||||
|
{
|
||||||
|
log.Info("接收数据校验失败: " + clientSocket.RemoteEndPoint + ": " + message);
|
||||||
|
Console.WriteLine("接收数据校验失败: " + clientSocket.RemoteEndPoint + ": " + message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//执行解析
|
||||||
|
log.Info("接收到" + clientSocket.RemoteEndPoint + ": " + message);
|
||||||
message = message.Replace(" ", "");
|
message = message.Replace(" ", "");
|
||||||
JudgmentFunction(message);
|
JudgmentFunction(message);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
------------------------------------------------
|
||||||
|
------------------------------------------------
|
||||||
|
------------------------------------------------
|
||||||
|
2023-02-22 14:08:20,199 [4] INFO loginfo - 接收数据校验失败; 172.16.1.49:52873: 01 03 04 00 08 95 91 D1 0D
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1 +1 @@
|
||||||
f65eb3423fba3e60e41a46bfb0af0337b8d3322f
|
898be911263aa5e48f96ba6f764bf3ee4a35a632
|
||||||
|
|
|
@ -9,3 +9,14 @@ D:\GaoGuoZheng_U3D\C#\Dianci\obj\Debug\ceshi.pdb
|
||||||
D:\GaoGuoZheng_U3D\C#\Dianci\bin\Debug\log4net.dll
|
D:\GaoGuoZheng_U3D\C#\Dianci\bin\Debug\log4net.dll
|
||||||
D:\GaoGuoZheng_U3D\C#\Dianci\bin\Debug\log4net.xml
|
D:\GaoGuoZheng_U3D\C#\Dianci\bin\Debug\log4net.xml
|
||||||
D:\GaoGuoZheng_U3D\C#\Dianci\obj\Debug\Dianci.csproj.CopyComplete
|
D:\GaoGuoZheng_U3D\C#\Dianci\obj\Debug\Dianci.csproj.CopyComplete
|
||||||
|
D:\GaoGuoZheng_U3D\C#\nenglaingbiao\Dianci\bin\Debug\ceshi.exe.config
|
||||||
|
D:\GaoGuoZheng_U3D\C#\nenglaingbiao\Dianci\bin\Debug\ceshi.exe
|
||||||
|
D:\GaoGuoZheng_U3D\C#\nenglaingbiao\Dianci\bin\Debug\ceshi.pdb
|
||||||
|
D:\GaoGuoZheng_U3D\C#\nenglaingbiao\Dianci\bin\Debug\log4net.dll
|
||||||
|
D:\GaoGuoZheng_U3D\C#\nenglaingbiao\Dianci\bin\Debug\log4net.xml
|
||||||
|
D:\GaoGuoZheng_U3D\C#\nenglaingbiao\Dianci\obj\Debug\Dianci.csproj.AssemblyReference.cache
|
||||||
|
D:\GaoGuoZheng_U3D\C#\nenglaingbiao\Dianci\obj\Debug\Dianci.csproj.SuggestedBindingRedirects.cache
|
||||||
|
D:\GaoGuoZheng_U3D\C#\nenglaingbiao\Dianci\obj\Debug\Dianci.csproj.CoreCompileInputs.cache
|
||||||
|
D:\GaoGuoZheng_U3D\C#\nenglaingbiao\Dianci\obj\Debug\Dianci.csproj.CopyComplete
|
||||||
|
D:\GaoGuoZheng_U3D\C#\nenglaingbiao\Dianci\obj\Debug\ceshi.exe
|
||||||
|
D:\GaoGuoZheng_U3D\C#\nenglaingbiao\Dianci\obj\Debug\ceshi.pdb
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1 +1 @@
|
||||||
2c30b29a00d23c23fe7971b86deffc378110adf1
|
73dddfdf5ddec9ab02df30c1163cfbf98d3b50f4
|
||||||
|
|
|
@ -9,3 +9,14 @@ D:\GaoGuoZheng_U3D\C#\Dianci\obj\Release\ceshi.pdb
|
||||||
D:\GaoGuoZheng_U3D\C#\Dianci\bin\Release\log4net.dll
|
D:\GaoGuoZheng_U3D\C#\Dianci\bin\Release\log4net.dll
|
||||||
D:\GaoGuoZheng_U3D\C#\Dianci\bin\Release\log4net.xml
|
D:\GaoGuoZheng_U3D\C#\Dianci\bin\Release\log4net.xml
|
||||||
D:\GaoGuoZheng_U3D\C#\Dianci\obj\Release\Dianci.csproj.CopyComplete
|
D:\GaoGuoZheng_U3D\C#\Dianci\obj\Release\Dianci.csproj.CopyComplete
|
||||||
|
D:\GaoGuoZheng_U3D\C#\nenglaingbiao\Dianci\bin\Release\ceshi.exe.config
|
||||||
|
D:\GaoGuoZheng_U3D\C#\nenglaingbiao\Dianci\bin\Release\ceshi.exe
|
||||||
|
D:\GaoGuoZheng_U3D\C#\nenglaingbiao\Dianci\bin\Release\ceshi.pdb
|
||||||
|
D:\GaoGuoZheng_U3D\C#\nenglaingbiao\Dianci\bin\Release\log4net.dll
|
||||||
|
D:\GaoGuoZheng_U3D\C#\nenglaingbiao\Dianci\bin\Release\log4net.xml
|
||||||
|
D:\GaoGuoZheng_U3D\C#\nenglaingbiao\Dianci\obj\Release\Dianci.csproj.AssemblyReference.cache
|
||||||
|
D:\GaoGuoZheng_U3D\C#\nenglaingbiao\Dianci\obj\Release\Dianci.csproj.SuggestedBindingRedirects.cache
|
||||||
|
D:\GaoGuoZheng_U3D\C#\nenglaingbiao\Dianci\obj\Release\Dianci.csproj.CoreCompileInputs.cache
|
||||||
|
D:\GaoGuoZheng_U3D\C#\nenglaingbiao\Dianci\obj\Release\Dianci.csproj.CopyComplete
|
||||||
|
D:\GaoGuoZheng_U3D\C#\nenglaingbiao\Dianci\obj\Release\ceshi.exe
|
||||||
|
D:\GaoGuoZheng_U3D\C#\nenglaingbiao\Dianci\obj\Release\ceshi.pdb
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue