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 16:48:45 +08:00
|
|
|
|
using JiShe.CollectBus.IotSystems.Ammeters;
|
2025-05-13 17:49:12 +08:00
|
|
|
|
using JiShe.CollectBus.IotSystems.Devices;
|
2025-05-12 14:02:22 +08:00
|
|
|
|
using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto;
|
2025-04-26 19:04:50 +08:00
|
|
|
|
using JiShe.CollectBus.Protocol.Dto;
|
|
|
|
|
|
using JiShe.CollectBus.Protocol.Interfaces;
|
2025-05-12 14:02:22 +08:00
|
|
|
|
using JiShe.CollectBus.Protocol.T37612012.AnalysisData;
|
2025-04-26 19:04:50 +08:00
|
|
|
|
using JiShe.CollectBus.Protocol3761;
|
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
2025-05-12 14:02:22 +08:00
|
|
|
|
using System.Text;
|
2025-04-26 19:04:50 +08:00
|
|
|
|
|
2025-05-26 09:42:06 +08:00
|
|
|
|
namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_10H.Ammeter
|
2025-04-26 19:04:50 +08:00
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 5.16.1.2.1 F1:透明转发 读取SIM卡信息
|
|
|
|
|
|
/// </summary>
|
2025-04-29 09:16:48 +08:00
|
|
|
|
public class AFN16_F101_Analysis : IAnalysisStrategy<TB3761>
|
2025-04-26 19:04:50 +08:00
|
|
|
|
{
|
|
|
|
|
|
private readonly ILogger<AFN16_F101_Analysis> _logger;
|
2025-05-12 14:02:22 +08:00
|
|
|
|
private readonly DataStorage _dataStorage;
|
|
|
|
|
|
public AFN16_F101_Analysis(ILogger<AFN16_F101_Analysis> logger, DataStorage dataStorage)
|
2025-04-26 19:04:50 +08:00
|
|
|
|
{
|
|
|
|
|
|
_logger = logger;
|
2025-05-12 14:02:22 +08:00
|
|
|
|
_dataStorage = dataStorage;
|
2025-04-26 19:04:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-05-12 14:02:22 +08:00
|
|
|
|
public async Task<bool> ExecuteAsync(TB3761 input, Action<dynamic>? result = null)
|
2025-04-26 19:04:50 +08:00
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
|
|
|
|
|
ArgumentNullException.ThrowIfNull(input);
|
2025-05-13 17:49:12 +08:00
|
|
|
|
ArgumentNullException.ThrowIfNull(input.A.Code);
|
2025-04-26 19:04:50 +08:00
|
|
|
|
ArgumentNullException.ThrowIfNull(input.UnitData.HexMessageList);
|
2025-05-12 14:02:22 +08:00
|
|
|
|
var data = new AnalysisBaseDto<string?>()
|
|
|
|
|
|
{
|
|
|
|
|
|
FiledDesc = "透读取SIM卡信息",
|
2025-05-12 16:09:53 +08:00
|
|
|
|
DataValue = AnalysisDataUnit(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
|
|
|
|
// 查询设备信息
|
2025-06-03 11:58:17 +08:00
|
|
|
|
DeviceCacheInfo? deviceInfo = await _dataStorage.GetDeviceInfoAsync(input.A.Code, input.DA.Pn);
|
2025-05-13 17:49:12 +08:00
|
|
|
|
if (deviceInfo != null)
|
2025-05-12 16:48:45 +08:00
|
|
|
|
{
|
2025-06-03 23:01:46 +08:00
|
|
|
|
data.ProjectId = deviceInfo.ProjectId;
|
2025-05-13 17:49:12 +08:00
|
|
|
|
data.DeviceId = deviceInfo.MeterId;
|
|
|
|
|
|
data.DatabaseBusiID = deviceInfo.DatabaseBusiID;
|
|
|
|
|
|
data.DeviceAddress = deviceInfo.MeterAddress;
|
|
|
|
|
|
data.FocusId = deviceInfo.FocusId;
|
2025-05-12 16:48:45 +08:00
|
|
|
|
}
|
2025-05-12 14:02:22 +08:00
|
|
|
|
UnitDataAnalysis<AnalysisBaseDto<string?>> dto = new UnitDataAnalysis<AnalysisBaseDto<string?>>
|
2025-04-26 19:04:50 +08:00
|
|
|
|
{
|
2025-04-29 09:16:48 +08:00
|
|
|
|
Code = input.A.Code!,
|
2025-04-26 19:04:50 +08:00
|
|
|
|
AFN = input.AFN_FC.AFN,
|
|
|
|
|
|
Fn = input.DT.Fn,
|
|
|
|
|
|
Pn = input.DA.Pn,
|
2025-05-12 14:02:22 +08:00
|
|
|
|
Data = data, //SIM卡
|
|
|
|
|
|
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.Data,
|
2025-04-26 19:04:50 +08:00
|
|
|
|
};
|
2025-04-29 09:16:48 +08:00
|
|
|
|
result?.Invoke(dto);
|
2025-05-26 09:42:06 +08:00
|
|
|
|
await _dataStorage.SaveDataToIotDbAsync(dto);
|
2025-05-12 14:02:22 +08:00
|
|
|
|
return await Task.FromResult(true);
|
2025-04-26 19:04:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
_logger.LogError(ex, $"10_101解析失败:{input.A?.Code}-{input.DT?.Fn ?? 0}-{input?.BaseHexMessage?.HexMessageString},{ex.Message}");
|
2025-04-29 09:16:48 +08:00
|
|
|
|
|
2025-04-26 19:04:50 +08:00
|
|
|
|
}
|
2025-05-12 14:02:22 +08:00
|
|
|
|
return await Task.FromResult(false);
|
2025-04-26 19:04:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
private string AnalysisDataUnit(List<string> hexMessageList)
|
|
|
|
|
|
{
|
|
|
|
|
|
//TODO:转发内容
|
|
|
|
|
|
var dataArray = hexMessageList.Skip(18).ToList();
|
|
|
|
|
|
var contentLengthArr = dataArray.Skip(1).Take(2).ToList();
|
|
|
|
|
|
contentLengthArr.Reverse();
|
|
|
|
|
|
int contentLength = string.Join("", contentLengthArr).HexToDec();
|
|
|
|
|
|
var dataField = dataArray.Skip(3).Take(contentLength).ToList();
|
|
|
|
|
|
var sim = string.Join("", dataField).TrimStart('0');
|
|
|
|
|
|
return sim.Length != 20 ? "" : sim;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|