using JiShe.CollectBus.Common.Extensions; using JiShe.CollectBus.Protocol.T37612012.AnalysisData.Appendix; using JiShe.CollectBus.Protocol.Contracts; using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto; using JiShe.CollectBus.Protocol.Dto; using JiShe.CollectBus.Protocol.Interfaces; using JiShe.CollectBus.Protocol.T37612012.Appendix; using JiShe.CollectBus.Protocol3761; using Microsoft.Extensions.Logging; namespace JiShe.CollectBus.Protocol.T37612012.AFN_0CH { /// /// 5.12.2.4.1 F2:终端日历时钟 /// public class AFN12_F2_Analysis : IAnalysisStrategy> { private readonly ILogger _logger; private readonly AnalysisStrategyContext _analysisStrategyContext; public AFN12_F2_Analysis(ILogger logger, AnalysisStrategyContext analysisStrategyContext) { _logger = logger; _analysisStrategyContext = analysisStrategyContext; } public async Task> ExecuteAsync(TB3761 input) { 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 dto = new UnitDataAnalysis { Code = input.A.Code, AFN = input.AFN_FC.AFN, Fn = input.DT.Fn, Pn = input.DA.Pn, Data = data }; return await Task.FromResult(dto); } catch (Exception ex) { _logger.LogError(ex, $"0C_2解析失败:{input.A?.Code}-{input.DT?.Fn ?? 0}-{input?.BaseHexMessage?.HexMessageString},{ex.Message}"); return null; } } public async Task GenerateFinalResultAsync(List 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 dto.DataValue = await _analysisStrategyContext.ExecuteAsync, string>(nameof(Appendix_A1), arr); dto.FiledName = "TerminalTime"; dto.FiledDesc = "召读终端时间"; return await Task.FromResult(dto); } } }