using JiShe.CollectBus.Common.Extensions; using JiShe.CollectBus.Protocol.Dto; using JiShe.CollectBus.Protocol.Interfaces; using JiShe.CollectBus.Protocol3761; using Microsoft.Extensions.Logging; namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0EH { /// /// 请求重要事件 /// Item1=停电事件 /// Item2=上电事件 /// public class AFN14_F1_Analysis : IAnalysisStrategy>> { private readonly ILogger _logger; public AFN14_F1_Analysis(ILogger logger) { _logger = logger; } public Task>> ExecuteAsync(TB3761 tB3761) { try { ArgumentNullException.ThrowIfNull(nameof(tB3761)); ArgumentNullException.ThrowIfNull(nameof(tB3761.UnitData.HexMessageList)); int erc = tB3761.UnitData.HexMessageList![8].HexToDec(); bool isOnOffPower = erc.Equals(14) ? true : false; if (!isOnOffPower) { throw new Exception($"ERC{erc}非上掉电事件"); } UnitDataAnalysis> dto = new UnitDataAnalysis> { Code = tB3761.A.Code!, AFN = tB3761.AFN_FC.AFN, Fn = tB3761.DT.Fn, Pn = tB3761.DA.Pn, Data = AnalysisDataUnit(tB3761.UnitData.HexMessageList) }; // meterData.DataType = "0E_1"; return Task.FromResult(dto); } catch (Exception ex) { _logger.LogError(ex, $"0E_1解析失败:{tB3761.A.Code}-{tB3761.DT.Fn}-{tB3761.BaseHexMessage.HexMessageString},{ex.Message}"); return null; } } private Tuple AnalysisDataUnit(List hexMessageList) { /// Item1=停电事件 /// Item2=上电事件 return Tuple.Create(HandlerTime(hexMessageList.GetRange(10, 5)), HandlerTime(hexMessageList.GetRange(15, 5))); } /// /// /解析时间 /// /// /// 时间验证失败是否默认为当前时间 /// private string HandlerTime(List times) { var time = string.Empty; try { times.Reverse(); time = $"{DateTime.Now.ToString("yyyy").Substring(0, 2)}{times[0]}-{times[1]}-{times[2]} {times[3]}:{times[4]}:00"; } catch { } return time; } } }