78 lines
2.8 KiB
C#
Raw Normal View History

2025-04-24 19:31:28 +08:00
using JiShe.CollectBus.Common.Extensions;
using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto;
using JiShe.CollectBus.Protocol.Dto;
2025-04-25 14:35:59 +08:00
using JiShe.CollectBus.Protocol.Interfaces;
2025-04-27 09:16:37 +08:00
using JiShe.CollectBus.Protocol.T37612012.Appendix;
2025-04-25 14:35:59 +08:00
using JiShe.CollectBus.Protocol3761;
2025-04-24 19:31:28 +08:00
using Microsoft.Extensions.Logging;
namespace JiShe.CollectBus.Protocol.T37612012.AFN_0CH
2025-04-24 19:31:28 +08:00
{
/// <summary>
/// 5.12.2.4.1 F2终端日历时钟
/// </summary>
public class AFN12_F2_Analysis : IAnalysisStrategy<TB3761>
2025-04-24 19:31:28 +08:00
{
private readonly ILogger<AFN12_F2_Analysis> _logger;
private readonly AnalysisStrategyContext _analysisStrategyContext;
public AFN12_F2_Analysis(ILogger<AFN12_F2_Analysis> logger, AnalysisStrategyContext analysisStrategyContext)
{
_logger = logger;
_analysisStrategyContext = analysisStrategyContext;
}
public async Task<bool> ExecuteAsync(TB3761 input, Action<dynamic>? result = null)
2025-04-24 19:31:28 +08:00
{
try
{
ArgumentNullException.ThrowIfNull(input);
ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList);
var data= await GenerateFinalResultAsync(input.UnitData.HexMessageList);
data.DataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}";
UnitDataAnalysis<AFN12_F2_AnalysisDto> dto = new UnitDataAnalysis<AFN12_F2_AnalysisDto>
{
Code = input.A.Code!,
2025-04-24 19:31:28 +08:00
AFN = input.AFN_FC.AFN,
Fn = input.DT.Fn,
Pn = input.DA.Pn,
Data = data
};
result?.Invoke(dto);
return await Task.FromResult(true);
2025-04-24 19:31:28 +08:00
}
catch (Exception ex)
{
_logger.LogError(ex, $"0C_2解析失败:{input.A?.Code}-{input.DT?.Fn ?? 0}-{input?.BaseHexMessage?.HexMessageString},{ex.Message}");
2025-04-24 19:31:28 +08:00
}
return await Task.FromResult(false);
2025-04-24 19:31:28 +08:00
}
public async Task<AFN12_F2_AnalysisDto> GenerateFinalResultAsync(List<string> hexMessageList)
{
AFN12_F2_AnalysisDto dto = new AFN12_F2_AnalysisDto();
var arr = hexMessageList.GetRange(4, 6);
var errorCodeInfo = arr.CheckErrorCode();
if (errorCodeInfo != null)
{
dto.ValidData = false;
dto.ErrorCodeMsg = errorCodeInfo.Item2;
}
else
{
await _analysisStrategyContext.ExecuteAsync<List<string>>(nameof(Appendix_A1), arr, (value) =>
{
dto.DataValue = value;
});
}
2025-04-24 19:31:28 +08:00
dto.FiledName = "TerminalTime";
dto.FiledDesc = "召读终端时间";
return await Task.FromResult(dto);
}
}
}