namespace ClassFile
{
class BaseUtil
{
///
/// 获取LRC
///
///
public static string getLRC(string SENDMESSAGE)
{
string message = SENDMESSAGE.Trim();
if (message.Length % 2 != 0)
{
message = message + "0";
}
int LRC = 0x0;
for (int i = 0; i < message.Length; i = i + 2)
{
int inside = int.Parse(message.Substring(i, 1).ToString() + message.Substring(i + 1, 1).ToString(), System.Globalization.NumberStyles.HexNumber);
LRC += inside;
}
string _LRC = string.Format("{0:X2}", LRC);
string LRCre = "";
for (int i = 0; i < _LRC.Length; i++)
{
int index;
index = 0xF - int.Parse(_LRC.Substring(i, 1).ToString(), System.Globalization.NumberStyles.HexNumber);
LRCre += string.Format("{0:X}", index);
}
LRCre = string.Format("{0:X}", int.Parse(LRCre, System.Globalization.NumberStyles.HexNumber) + 1);
return LRCre;
}
public static string ASCIIToString(string ASCII)
{
string ReturnStr = "";
ASCII = ASCII.Replace(" ", "").Replace("3A", "").Replace("0D", "").Replace("0A", "");
System.Console.WriteLine(ASCII);
for (int i = 0; i < ASCII.Length; i = i + 2)
{
if (i + 2 < ASCII.Length)
{
switch (ASCII.Substring(i, 2))
{
case "30":
ReturnStr += "0";
break;
case "31":
ReturnStr += "1";
break;
case "32":
ReturnStr += "2";
break;
case "33":
ReturnStr += "3";
break;
case "34":
ReturnStr += "4";
break;
case "35":
ReturnStr += "5";
break;
case "36":
ReturnStr += "6";
break;
case "37":
ReturnStr += "7";
break;
case "38":
ReturnStr += "8";
break;
case "39":
ReturnStr += "9";
break;
case "41":
ReturnStr += "A";
break;
case "42":
ReturnStr += "B";
break;
case "43":
ReturnStr += "C";
break;
case "44":
ReturnStr += "D";
break;
case "45":
ReturnStr += "E";
break;
case "46":
ReturnStr += "F";
break;
default:
break;
}
}
}
return ReturnStr;
}
}
}