Files
lserp_cs_6.0/其他程序/RFIDManagement/RFIDManagement/GlobalMethod.cs
T
cyf ab56a9bcf7 基线 SVN r240
SVN-Revision: r240
2025-02-06 06:46:06 +00:00

130 lines
4.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ReaderApi.Data;
namespace RFIDManagement
{
public class GlobalMethod
{
public static string AddOneStep(int type, string str, int step, int startValue)
{
string strResult = "";
byte[] byteArray = new byte[str.Length / 2];
if (type == 16)
{
for (int i = 0; i < str.Length / 2; i++)
{
byteArray[i] = Convert.ToByte(str.Substring(2 * i, 2), 16);
}
if ((byteArray[(byteArray.Length - startValue) - 1] + step) > 0xFF)
{
byteArray[(byteArray.Length - startValue) - 1] = (byte)(byteArray[(byteArray.Length - startValue) - 1] + step);
for (int j = (byteArray.Length - startValue) - 2; j >= 0; j--)
{
if ((byteArray[j] + 1) > 0xFF)
{
byteArray[j] = (byte)(byteArray[j] + 1);
continue;
}
else
{
byteArray[j] = (byte)(byteArray[j] + 1);
break;
}
}
}
else
{
byteArray[(byteArray.Length - startValue) - 1] = (byte)(byteArray[(byteArray.Length - startValue) - 1] + step);
}
for (int i = 0; i < byteArray.Length; i++)
{
strResult += string.Format("{0:X2}", byteArray[i]);
}
}
else if (type == 10)
{
for (int i = 0; i < str.Length / 2; i++)
{
byteArray[i] = Convert.ToByte(str.Substring(2 * i, 2));
}
if ((byteArray[(byteArray.Length - startValue) - 1] + step) > 99)
{
byteArray[(byteArray.Length - startValue) - 1] = 0;
for (int j = (byteArray.Length - startValue) - 2; j >= 0; j--)
{
if ((byteArray[j] + 1) > 99)
{
byteArray[j] = 0;
continue;
}
else
{
byteArray[j] = (byte)(byteArray[j] + 1);
break;
}
}
}
else
{
byteArray[(byteArray.Length - startValue) - 1] = (byte)(byteArray[(byteArray.Length - startValue) - 1] + step);
}
for (int i = 0; i < byteArray.Length; i++)
{
strResult += byteArray[i].ToString("00");
}
}
return strResult;
}
public static bool AddTag(Tag tag, List<Tag> tags)
{
var isNewTag = true;
lock (tags)
{
if (tag.tid != null && tag.tid != "")
{
for (int index = 0; index < tags.Count; index++)
{
if (tags[index].tid == tag.tid)
{
tags[index].count++;
tags[index].rssi = tag.rssi;
tags[index].ant = tag.ant;
tags[index].frequency = tag.frequency;
isNewTag = false;
break;
}
}
if (isNewTag)
{
tags.Add(tag);
}
}
else if (tag.epc != null)
{
for (int index = 0; index < tags.Count; index++)
{
if (tags[index].epc == tag.epc)
{
tags[index].count++;
tags[index].rssi = tag.rssi;
tags[index].ant = tag.ant;
tags[index].frequency = tag.frequency;
isNewTag = false;
break;
}
}
if (isNewTag)
{
tags.Add(tag);
}
}
}
return isNewTag;
}
}
}