2025-04-24 19:31:28 +08:00
|
|
|
|
using JiShe.CollectBus.Common.Extensions;
|
|
|
|
|
|
using JiShe.CollectBus.Protocol.Contracts;
|
|
|
|
|
|
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;
|
|
|
|
|
|
using JiShe.CollectBus.Protocol3761;
|
2025-04-24 19:31:28 +08:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
|
|
|
|
|
|
namespace JiShe.CollectBus.Protocol.AnalysisData.AFN_0CH
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 水表抄读取
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public class AFN12_F188_Analysis : IAnalysisStrategy<TB3761, UnitDataAnalysis<AFN12_F149_AnalysisDto>>
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
private readonly ILogger<AFN12_F188_Analysis> _logger;
|
|
|
|
|
|
private readonly AnalysisStrategyContext _analysisStrategyContext;
|
|
|
|
|
|
|
|
|
|
|
|
public AFN12_F188_Analysis(ILogger<AFN12_F188_Analysis> logger, AnalysisStrategyContext analysisStrategyContext)
|
|
|
|
|
|
{
|
|
|
|
|
|
_logger = logger;
|
|
|
|
|
|
_analysisStrategyContext = analysisStrategyContext;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<UnitDataAnalysis<AFN12_F149_AnalysisDto>> ExecuteAsync(TB3761 input)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
ArgumentNullException.ThrowIfNull(input);
|
|
|
|
|
|
ArgumentNullException.ThrowIfNull(input.UnitData?.HexMessageList);
|
|
|
|
|
|
ArgumentNullException.ThrowIfNull(input.AFN_FC.AFN);
|
|
|
|
|
|
ArgumentNullException.ThrowIfNull(input.DT.Fn);
|
|
|
|
|
|
var data = GenerateFinalResult(input.UnitData.HexMessageList);
|
|
|
|
|
|
data.DataType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}";
|
|
|
|
|
|
UnitDataAnalysis<AFN12_F149_AnalysisDto> dto = new UnitDataAnalysis<AFN12_F149_AnalysisDto>
|
|
|
|
|
|
{
|
|
|
|
|
|
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_188解析失败:{input.A.Code}-{input.DT.Fn}-{input.BaseHexMessage?.HexMessageString},{ex.Message}");
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public AFN12_F149_AnalysisDto GenerateFinalResult(List<string> hexMessageList)
|
|
|
|
|
|
{
|
|
|
|
|
|
AFN12_F149_AnalysisDto dto = new AFN12_F149_AnalysisDto();
|
|
|
|
|
|
decimal value = 0;
|
|
|
|
|
|
var arr = hexMessageList.GetRange(11, 4);
|
|
|
|
|
|
var errorCodeInfo = arr.CheckErrorCode();
|
|
|
|
|
|
if (errorCodeInfo != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
dto.ValidData = false;
|
|
|
|
|
|
dto.ErrorCodeMsg = errorCodeInfo.Item2;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
decimal.TryParse($"{arr[11]}{arr[12]}{arr[13]}.{arr[14]}", out value);
|
|
|
|
|
|
|
|
|
|
|
|
dto.DataValue = value;
|
|
|
|
|
|
//dto.ReadTime = Convert.ToDateTime($"{data[0].Substring(0, 4)}-{data[0].Substring(4, 2)}-{data[0].Substring(6, 2)} {data[0].Substring(8, 2)}:{data[0].Substring(10, 2)}:00");
|
|
|
|
|
|
return dto;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|