|
|
|
|
@ -1,25 +1,25 @@
|
|
|
|
|
#region << 版 本 注 释 >>
|
|
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------------
|
|
|
|
|
* 版权所有 (c) 2025 WenJY 保留所有权利。
|
|
|
|
|
* CLR版本:4.0.30319.42000
|
|
|
|
|
* 机器名称:Mr.Wen's MacBook Pro
|
|
|
|
|
* 命名空间:Sln.Imm.Daemon.Common
|
|
|
|
|
* 唯一标识:CE4BD2CC-E101-4CF0-BB9C-C3325F54C8FE
|
|
|
|
|
*
|
|
|
|
|
* 创建者:WenJY
|
|
|
|
|
* 电子邮箱:
|
|
|
|
|
* 创建时间:2025-09-05 11:10:34
|
|
|
|
|
* 版本:V1.0.0
|
|
|
|
|
* 描述:
|
|
|
|
|
*
|
|
|
|
|
*--------------------------------------------------------------------
|
|
|
|
|
* 修改人:
|
|
|
|
|
* 时间:
|
|
|
|
|
* 修改说明:
|
|
|
|
|
*
|
|
|
|
|
* 版本:V1.0.0
|
|
|
|
|
*--------------------------------------------------------------------*/
|
|
|
|
|
* 版权所有 (c) 2025 WenJY 保留所有权利。
|
|
|
|
|
* CLR版本:4.0.30319.42000
|
|
|
|
|
* 机器名称:Mr.Wen's MacBook Pro
|
|
|
|
|
* 命名空间:Sln.Imm.Daemon.Common
|
|
|
|
|
* 唯一标识:CE4BD2CC-E101-4CF0-BB9C-C3325F54C8FE
|
|
|
|
|
*
|
|
|
|
|
* 创建者:WenJY
|
|
|
|
|
* 电子邮箱:
|
|
|
|
|
* 创建时间:2025-09-05 11:10:34
|
|
|
|
|
* 版本:V1.0.0
|
|
|
|
|
* 描述:
|
|
|
|
|
*
|
|
|
|
|
*--------------------------------------------------------------------
|
|
|
|
|
* 修改人:
|
|
|
|
|
* 时间:
|
|
|
|
|
* 修改说明:
|
|
|
|
|
*
|
|
|
|
|
* 版本:V1.0.0
|
|
|
|
|
*--------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
#endregion << 版 本 注 释 >>
|
|
|
|
|
|
|
|
|
|
@ -28,7 +28,7 @@ using System.Text;
|
|
|
|
|
namespace Sln.Imm.Daemon.Common;
|
|
|
|
|
|
|
|
|
|
public class StringChange
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 将字符串强制转换成int,转换失败则返回0
|
|
|
|
|
/// </summary>
|
|
|
|
|
@ -41,6 +41,7 @@ public class StringChange
|
|
|
|
|
{
|
|
|
|
|
return returnInt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (int.TryParse(str, out returnInt))
|
|
|
|
|
{
|
|
|
|
|
return returnInt;
|
|
|
|
|
@ -69,8 +70,7 @@ public class StringChange
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public byte[] HexStrTorbytes(string strHex)//e.g. " 01 01" ---> { 0x01, 0x01}
|
|
|
|
|
public byte[] HexStrTorbytes(string strHex) //e.g. " 01 01" ---> { 0x01, 0x01}
|
|
|
|
|
{
|
|
|
|
|
strHex = strHex.Replace(" ", "");
|
|
|
|
|
if ((strHex.Length % 2) != 0)
|
|
|
|
|
@ -89,6 +89,7 @@ public class StringChange
|
|
|
|
|
{
|
|
|
|
|
result += "%" + Convert.ToString(b[i], 16);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -102,6 +103,7 @@ public class StringChange
|
|
|
|
|
{
|
|
|
|
|
b[i] = Convert.ToByte(chars[i], 16);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//按照指定编码将字节数组变为字符串
|
|
|
|
|
return encode.GetString(b);
|
|
|
|
|
}
|
|
|
|
|
@ -131,6 +133,7 @@ public class StringChange
|
|
|
|
|
{
|
|
|
|
|
intBytes[i] = floatBytes[i * 2];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return intBytes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -145,12 +148,12 @@ public class StringChange
|
|
|
|
|
{
|
|
|
|
|
iVerify = (byte)(iVerify ^ pMessage[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return iVerify;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int HexStringToNegative(string strNumber)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
int iNegate = 0;
|
|
|
|
|
int iNumber = Convert.ToInt32(strNumber, 16);
|
|
|
|
|
if (iNumber > 127)
|
|
|
|
|
@ -169,8 +172,10 @@ public class StringChange
|
|
|
|
|
strNegate += "0";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
iNegate = -Convert.ToInt32(strNegate, 2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return iNegate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -181,7 +186,7 @@ public class StringChange
|
|
|
|
|
/// <param name="buffer"></param>
|
|
|
|
|
/// <param name="falg"></param>
|
|
|
|
|
/// <exception cref="ArgumentException"></exception>
|
|
|
|
|
public void ConvertBytesToUInt16(byte[] buffer,out uint falg)
|
|
|
|
|
public void ConvertBytesToUInt16(byte[] buffer, out uint falg)
|
|
|
|
|
{
|
|
|
|
|
if (buffer == null || buffer.Length < 2)
|
|
|
|
|
{
|
|
|
|
|
@ -190,7 +195,7 @@ public class StringChange
|
|
|
|
|
|
|
|
|
|
var input = buffer.Reverse().ToArray();
|
|
|
|
|
|
|
|
|
|
falg = (uint) ((input[1] << 8) | input[0]);
|
|
|
|
|
falg = (uint)((input[1] << 8) | input[0]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
@ -213,6 +218,7 @@ public class StringChange
|
|
|
|
|
result[j] = (byte)(swapped >> 8);
|
|
|
|
|
result[j + 1] = (byte)swapped;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
input = result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -236,6 +242,7 @@ public class StringChange
|
|
|
|
|
stb.Append("0" + Convert.ToString(data[i], 16).ToUpper());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
str = stb.ToString();
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
@ -256,6 +263,7 @@ public class StringChange
|
|
|
|
|
sb.Append(bytes[i].ToString("X2"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return sb.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -275,6 +283,7 @@ public class StringChange
|
|
|
|
|
{
|
|
|
|
|
iVerify = iVerify + pMessage[i + 1];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return BitConverter.GetBytes(Convert.ToUInt16(iVerify));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|