You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

85 lines
2.6 KiB
C#

1 month ago
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2025 WenJY
* CLR4.0.30319.42000
* Mr.Wen's MacBook Pro
* Sln.Iot.Business
* CF6CB45C-6484-468E-9853-31ADA6821183
*
* WenJY
*
* 2025-05-27 11:14:04
* V1.0.0
*
*
*--------------------------------------------------------------------
*
*
*
*
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
using System;
using Sln.Iot.Business.@base;
using Sln.Iot.Common;
using Sln.Iot.Config;
using Sln.Iot.Serilog;
using Sln.Iot.Socket.Adapter;
using TouchSocket.Core;
using TouchSocket.Sockets;
namespace Sln.Iot.Business
{
public class RfidBusiness:BaseBusiness
{
public RfidBusiness(SerilogHelper logger, AppConfig appConfig, StringChange stringChange) : base(logger, appConfig, stringChange)
{
}
public override FilterResult BufferAnalysis(ISocketClient client, BufferRequestInfo requestInfo, int bodyLength)
{
ByteBlock byteBlock = new ByteBlock(requestInfo.Body);
if (byteBlock.CanReadLen < 1)
{
return FilterResult.Cache;
}
int pos = byteBlock.Pos;
try
{
var amount = requestInfo.BufferLength / bodyLength;
_logger.Info($"收到{amount}个RFID数据开始循环解析......");
for (int i = 0; i < amount; i++)
{
byte[] ids = new byte[3];
Array.Copy(requestInfo.buffer, 1, ids, 0, ids.Length);
string idsStr = _stringChange.bytesToHexStr(ids,ids.Length);
var status = _stringChange.bytesToHexStr(requestInfo.Body, requestInfo.Body.Length);
_logger.Info($"设备编号:{idsStr};RFID:{status}");
}
return FilterResult.Success;
}
catch (Exception e)
{
base._logger.Error($"RFID数据解析异常{e.Message}");
}
return FilterResult.Cache;
}
public override void ResponseHandle(ISocketClient client, BufferRequestInfo requestInfo)
{
//throw new System.NotImplementedException();
}
}
}