zenghongyao 4f1814b8df 协议解析优化
策略模式回调采用Action方式灵活处理
2025-04-29 09:16:48 +08:00

58 lines
2.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using JiShe.CollectBus.Common.Extensions;
using JiShe.CollectBus.Protocol.Dto;
using JiShe.CollectBus.Protocol.Interfaces;
using JiShe.CollectBus.Protocol3761;
using Microsoft.Extensions.Logging;
namespace GatherService.WattMeter.AnalysisData.AFN_10H
{
/// <summary>
/// 5.16.1.2.1 F1透明转发 读取SIM卡信息
/// </summary>
public class AFN16_F101_Analysis : IAnalysisStrategy<TB3761>
{
private readonly ILogger<AFN16_F101_Analysis> _logger;
public AFN16_F101_Analysis(ILogger<AFN16_F101_Analysis> logger)
{
_logger = logger;
}
public Task<bool> ExecuteAsync(TB3761 input, Action<dynamic>? result = null)
{
try
{
ArgumentNullException.ThrowIfNull(input);
ArgumentNullException.ThrowIfNull(input.UnitData.HexMessageList);
UnitDataAnalysis<string> dto = new UnitDataAnalysis<string>
{
Code = input.A.Code!,
AFN = input.AFN_FC.AFN,
Fn = input.DT.Fn,
Pn = input.DA.Pn,
Data = AnalysisDataUnit(input.UnitData.HexMessageList) //SIM卡
};
result?.Invoke(dto);
return Task.FromResult(true);
}
catch (Exception ex)
{
_logger.LogError(ex, $"10_101解析失败:{input.A?.Code}-{input.DT?.Fn ?? 0}-{input?.BaseHexMessage?.HexMessageString},{ex.Message}");
}
return Task.FromResult(false);
}
private string AnalysisDataUnit(List<string> hexMessageList)
{
//TODO:转发内容
var dataArray = hexMessageList.Skip(18).ToList();
var contentLengthArr = dataArray.Skip(1).Take(2).ToList();
contentLengthArr.Reverse();
int contentLength = string.Join("", contentLengthArr).HexToDec();
var dataField = dataArray.Skip(3).Take(contentLength).ToList();
var sim = string.Join("", dataField).TrimStart('0');
return sim.Length != 20 ? "" : sim;
}
}
}