76 lines
3.2 KiB
C#
76 lines
3.2 KiB
C#
using System.Text;
|
||
using JiShe.CollectBus.Common.Consts;
|
||
using JiShe.CollectBus.Common.Enums;
|
||
using JiShe.CollectBus.Common.Extensions;
|
||
using JiShe.CollectBus.IotSystems.Ammeters;
|
||
using JiShe.CollectBus.Protocol.Contracts.Protocol.Dto;
|
||
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_09H
|
||
{
|
||
/// <summary>
|
||
/// 5.9.2.4.9 F9:远程通信模块版本信息(只读解析SIM卡号)
|
||
/// </summary>
|
||
public class AFN9_F9_Analysis : IAnalysisStrategy<TB3761>
|
||
{
|
||
private readonly ILogger<AFN9_F9_Analysis> _logger;
|
||
private readonly DataStorage _dataStorage;
|
||
public AFN9_F9_Analysis(ILogger<AFN9_F9_Analysis> logger, DataStorage dataStorage)
|
||
{
|
||
_logger = logger;
|
||
_dataStorage = dataStorage;
|
||
}
|
||
|
||
public async Task<bool> ExecuteAsync(TB3761 input, Action<dynamic>? result = null)
|
||
{
|
||
try
|
||
{
|
||
ArgumentNullException.ThrowIfNull(input);
|
||
ArgumentNullException.ThrowIfNull(input.UnitData.HexMessageList);
|
||
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}"
|
||
};
|
||
// 查询电表信息
|
||
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;
|
||
}
|
||
UnitDataAnalysis<AnalysisBaseDto<string?>> dto = new UnitDataAnalysis<AnalysisBaseDto<string?>>
|
||
{
|
||
Code = input.A.Code!,
|
||
AFN = input.AFN_FC.AFN,
|
||
Fn = input.DT.Fn,
|
||
Pn = input.DA.Pn,
|
||
Data = data, //SIM卡
|
||
ReceivedHexMessage = input.BaseHexMessage.HexMessageString,
|
||
MessageId = input.MessageId,
|
||
ReceivedTime = input.ReceivedTime,
|
||
DensityUnit = DensityUnit.None,
|
||
TimeDensity = -1,
|
||
DataType= IOTDBDataTypeConst.Data
|
||
};
|
||
result?.Invoke(dto);
|
||
await _dataStorage.SaveDataToIotDbAsync(dto);
|
||
|
||
return await Task.FromResult(true);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, $"00_1解析失败:{input.A?.Code}-{input.DT?.Fn ?? 0}-{input?.BaseHexMessage?.HexMessageString},{ex.Message}");
|
||
}
|
||
return await Task.FromResult(false);
|
||
}
|
||
}
|
||
}
|