2025-05-12 16:09:53 +08:00
|
|
|
|
using JiShe.CollectBus.Common.Consts;
|
|
|
|
|
|
using JiShe.CollectBus.Common.Enums;
|
2025-04-30 17:25:35 +08:00
|
|
|
|
using JiShe.CollectBus.Common.Extensions;
|
2025-05-12 14:02:22 +08:00
|
|
|
|
using JiShe.CollectBus.IotSystems.Ammeters;
|
2025-05-13 17:49:12 +08:00
|
|
|
|
using JiShe.CollectBus.IotSystems.Devices;
|
2025-04-24 19:31:28 +08:00
|
|
|
|
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-29 09:16:48 +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;
|
2025-05-12 14:02:22 +08:00
|
|
|
|
using System;
|
2025-04-24 19:31:28 +08:00
|
|
|
|
|
2025-04-27 09:16:37 +08:00
|
|
|
|
namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_0AH
|
2025-04-24 19:31:28 +08:00
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 5.5.1.3.53 F66:定时上报 2 类数据任务设置
|
|
|
|
|
|
/// </summary>
|
2025-04-29 09:16:48 +08:00
|
|
|
|
public class AFN10_F66_Analysis : IAnalysisStrategy<TB3761>
|
2025-04-24 19:31:28 +08:00
|
|
|
|
{
|
|
|
|
|
|
private readonly ILogger<AFN10_F66_Analysis> _logger;
|
|
|
|
|
|
private readonly AnalysisStrategyContext _analysisStrategyContext;
|
2025-05-12 14:02:22 +08:00
|
|
|
|
private readonly DataStorage _dataStorage;
|
|
|
|
|
|
public AFN10_F66_Analysis(ILogger<AFN10_F66_Analysis> logger, AnalysisStrategyContext analysisStrategyContext, DataStorage dataStorage)
|
2025-04-24 19:31:28 +08:00
|
|
|
|
{
|
|
|
|
|
|
_logger = logger;
|
2025-05-12 14:02:22 +08:00
|
|
|
|
_analysisStrategyContext = analysisStrategyContext;
|
|
|
|
|
|
_dataStorage = dataStorage;
|
2025-04-24 19:31:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-29 09:16:48 +08:00
|
|
|
|
public async Task<bool> ExecuteAsync(TB3761 input, Action<dynamic>? result = null)
|
2025-04-24 19:31:28 +08:00
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
ArgumentNullException.ThrowIfNull(input);
|
2025-05-13 17:49:12 +08:00
|
|
|
|
ArgumentNullException.ThrowIfNull(input.A.Code);
|
2025-04-24 19:31:28 +08:00
|
|
|
|
ArgumentNullException.ThrowIfNull(input.UnitData.HexMessageList);
|
2025-05-12 14:02:22 +08:00
|
|
|
|
|
|
|
|
|
|
var data = new AnalysisBaseDto<AFN10_F66_AnalysisDto?>()
|
|
|
|
|
|
{
|
|
|
|
|
|
FiledDesc = "终端电能表/交流采样装置配置参数",
|
2025-05-12 16:09:53 +08:00
|
|
|
|
DataValue = await GenerateFinalResult(input.UnitData.HexMessageList),
|
|
|
|
|
|
ItemType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"
|
2025-05-12 14:02:22 +08:00
|
|
|
|
};
|
2025-05-13 17:49:12 +08:00
|
|
|
|
// 查询设备信息
|
|
|
|
|
|
DeviceInfo? deviceInfo = await _dataStorage.GetDeviceInfoAsync(input.A.Code);
|
|
|
|
|
|
if (deviceInfo != null)
|
2025-05-12 14:02:22 +08:00
|
|
|
|
{
|
2025-05-13 17:49:12 +08:00
|
|
|
|
data.ProjectId = deviceInfo.ProjectID;
|
|
|
|
|
|
data.DeviceId = deviceInfo.FocusId;
|
|
|
|
|
|
data.DatabaseBusiID = deviceInfo.DatabaseBusiID;
|
|
|
|
|
|
data.DeviceAddress = deviceInfo.FocusAddress;
|
2025-05-12 14:02:22 +08:00
|
|
|
|
data.DeviceType = MeterTypeEnum.Focus;
|
2025-05-13 17:49:12 +08:00
|
|
|
|
data.FocusId = deviceInfo.FocusId;
|
2025-05-12 14:02:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
UnitDataAnalysis<AnalysisBaseDto<AFN10_F66_AnalysisDto?>> dto = new UnitDataAnalysis<AnalysisBaseDto<AFN10_F66_AnalysisDto?>>
|
2025-04-24 19:31:28 +08:00
|
|
|
|
{
|
2025-04-29 09:16:48 +08:00
|
|
|
|
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,
|
2025-04-29 11:43:16 +08:00
|
|
|
|
Data = data,
|
2025-05-12 14:02:22 +08:00
|
|
|
|
ReceivedHexMessage = input.BaseHexMessage.HexMessageString,
|
2025-04-29 11:43:16 +08:00
|
|
|
|
MessageId = input.MessageId,
|
2025-04-30 17:25:35 +08:00
|
|
|
|
ReceivedTime = input.ReceivedTime,
|
|
|
|
|
|
DensityUnit = DensityUnit.None,
|
2025-05-12 16:09:53 +08:00
|
|
|
|
TimeDensity = -1,
|
|
|
|
|
|
DataType = IOTDBDataTypeConst.Param
|
2025-04-24 19:31:28 +08:00
|
|
|
|
};
|
2025-04-29 09:16:48 +08:00
|
|
|
|
result?.Invoke(dto);
|
2025-05-12 14:02:22 +08:00
|
|
|
|
await _dataStorage.SaveDataToIotDbAsync<AFN10_F66_AnalysisDto?>(dto);
|
|
|
|
|
|
|
2025-04-29 09:16:48 +08:00
|
|
|
|
return await Task.FromResult(true);
|
2025-04-24 19:31:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
_logger.LogError(ex, $"0A_66解析失败:{input.A?.Code}-{input.DT?.Fn ?? 0}-{input?.BaseHexMessage?.HexMessageString},{ex.Message}");
|
|
|
|
|
|
}
|
2025-04-29 09:16:48 +08:00
|
|
|
|
return await Task.FromResult(false);
|
2025-04-24 19:31:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public async Task<AFN10_F66_AnalysisDto> GenerateFinalResult(List<string> hexMessageList)
|
|
|
|
|
|
{
|
|
|
|
|
|
AFN10_F66_AnalysisDto entity = new AFN10_F66_AnalysisDto();
|
|
|
|
|
|
var cycleBin = hexMessageList[4].HexToBin().PadLeft(8, '0');
|
|
|
|
|
|
var cycleUnitBin = cycleBin.Substring(0, 2);
|
|
|
|
|
|
var cycleValueBin = cycleBin.Substring(2, 6);
|
|
|
|
|
|
|
|
|
|
|
|
entity.Cycle = cycleValueBin.BinToDec();//定时发送周期
|
|
|
|
|
|
entity.Unit = cycleUnitBin.BinToDec();//定时发送周期(单位)
|
|
|
|
|
|
//TODO:发送基准时间
|
|
|
|
|
|
var arrBaseTime = hexMessageList.GetRange(5, 6);
|
|
|
|
|
|
|
2025-04-29 09:16:48 +08:00
|
|
|
|
await _analysisStrategyContext.ExecuteAsync<List<string>>(nameof(Appendix_A1), arrBaseTime, (value) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
var baseTimeArrStr = (string)value;
|
|
|
|
|
|
var baseTimeArr = baseTimeArrStr.Split('_');
|
|
|
|
|
|
//entity.BaseTime = DateTime.Parse($"{DateTime.Now.Year.ToString().Substring(0, 2)}{arrBaseTime[0]}-{arrBaseTime[1]}-{arrBaseTime[2]} {arrBaseTime[3]}:{arrBaseTime[4]}:{arrBaseTime[5]}");
|
|
|
|
|
|
entity.BaseTime = Convert.ToDateTime(baseTimeArr[0]);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-04-24 19:31:28 +08:00
|
|
|
|
entity.CurveRatio = hexMessageList[11].HexToDec();
|
|
|
|
|
|
var count = hexMessageList[12].HexToDec();
|
|
|
|
|
|
var dataArr = hexMessageList.GetRange(13, 4 * count);
|
|
|
|
|
|
for (int i = 0; i < count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
var pnfnArr = dataArr.GetRange(0, 4);
|
2025-04-25 15:21:43 +08:00
|
|
|
|
var tempPn = T37612012ProtocolPlugin.CalculatePn(pnfnArr[0], pnfnArr[1]);
|
|
|
|
|
|
var tempFn = T37612012ProtocolPlugin.CalculateFn(pnfnArr[2], pnfnArr[3]);
|
2025-04-24 19:31:28 +08:00
|
|
|
|
entity.Details.Add(new SetAutoItemCodeDetails() { Fn = tempFn, Pn = tempPn });
|
|
|
|
|
|
dataArr.RemoveRange(0, 4);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return entity;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|