77 lines
3.3 KiB
C#
Raw Normal View History

2025-04-27 09:16:37 +08:00
using System.Text;
using JiShe.CollectBus.Common.Consts;
2025-04-30 17:25:35 +08:00
using JiShe.CollectBus.Common.Enums;
2025-04-27 09:16:37 +08:00
using JiShe.CollectBus.Common.Extensions;
2025-05-12 14:02:22 +08:00
using JiShe.CollectBus.IotSystems.Ammeters;
using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto;
2025-04-24 19:31:28 +08:00
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;
2025-04-27 09:16:37 +08:00
namespace JiShe.CollectBus.Protocol.T37612012.AnalysisData.AFN_09H
2025-04-24 19:31:28 +08:00
{
/// <summary>
/// 5.9.2.4.9 F9远程通信模块版本信息(只读解析SIM卡号)
/// </summary>
public class AFN9_F9_Analysis : IAnalysisStrategy<TB3761>
2025-04-24 19:31:28 +08:00
{
private readonly ILogger<AFN9_F9_Analysis> _logger;
2025-05-12 14:02:22 +08:00
private readonly DataStorage _dataStorage;
public AFN9_F9_Analysis(ILogger<AFN9_F9_Analysis> logger, DataStorage dataStorage)
2025-04-24 19:31:28 +08:00
{
_logger = logger;
2025-05-12 14:02:22 +08:00
_dataStorage = dataStorage;
2025-04-24 19:31:28 +08:00
}
2025-05-12 14:02:22 +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);
ArgumentNullException.ThrowIfNull(input.UnitData.HexMessageList);
2025-05-12 14:02:22 +08:00
var data = new AnalysisBaseDto<string?>()
{
FiledDesc = "远程通信模块版本信息",
DataValue = Encoding.ASCII.GetString(string.Join("", input.UnitData.HexMessageList.Skip(30).Take(20).ToList()).HexToByte()).Replace("\0", ""),
ItemType = $"{input.AFN_FC.AFN.HexToDecStr().PadLeft(2, '0')}_{input.DT.Fn}"
2025-05-12 14:02:22 +08:00
};
// 查询电表信息
AmmeterInfo ammeterInfo = await _dataStorage.GetMeterInfoAsync(MeterTypeEnum.Focus.ToString(), "15");
if (ammeterInfo != null)
{
data.ProjectId = ammeterInfo.ProjectID;
data.DeviceId = ammeterInfo.FocusId;
data.DatabaseBusiID = ammeterInfo.DatabaseBusiID;
data.DeviceAddress = ammeterInfo.Address;
data.DeviceType = MeterTypeEnum.Focus;
2025-05-12 16:48:45 +08:00
data.FocusId = ammeterInfo.FocusId;
2025-05-12 14:02:22 +08:00
}
UnitDataAnalysis<AnalysisBaseDto<string?>> dto = new UnitDataAnalysis<AnalysisBaseDto<string?>>
2025-04-24 19:31:28 +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-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,
TimeDensity = -1,
DataType= IOTDBDataTypeConst.Data
2025-04-24 19:31:28 +08:00
};
result?.Invoke(dto);
2025-05-12 14:02:22 +08:00
await _dataStorage.SaveDataToIotDbAsync(dto);
return await Task.FromResult(true);
2025-04-24 19:31:28 +08:00
}
catch (Exception ex)
{
_logger.LogError(ex, $"00_1解析失败:{input.A?.Code}-{input.DT?.Fn ?? 0}-{input?.BaseHexMessage?.HexMessageString},{ex.Message}");
}
2025-05-12 14:02:22 +08:00
return await Task.FromResult(false);
2025-04-24 19:31:28 +08:00
}
}
}