Compare commits
No commits in common. "fff1ba1a7b6f65851e3151437c9d87c6d6c5570b" and "039a1a8b891ae888af8991923b5806ea30901aba" have entirely different histories.
fff1ba1a7b
...
039a1a8b89
@ -18,13 +18,5 @@ namespace JiShe.CollectBus.Protocol.Contracts.Interfaces
|
||||
/// <returns></returns>
|
||||
/// <exception cref="UserFriendlyException"></exception>
|
||||
Task<ProtocolInfo> FirstOrDefaultByDeviceAsync(string deviceCode, bool isSpecial = false);
|
||||
|
||||
/// <summary>
|
||||
/// 获取协议池服务
|
||||
/// </summary>
|
||||
/// <param name="deviceCode"></param>
|
||||
/// <param name="isSpecial"></param>
|
||||
/// <returns></returns>
|
||||
Task<IProtocolPlugin?> GetProtocolServiceAsync(string deviceCode, bool isSpecial = false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,12 +18,10 @@ namespace JiShe.CollectBus.Protocol.Contracts.Services
|
||||
public class ProtocolService : IProtocolService, ISingletonDependency
|
||||
{
|
||||
private readonly IFreeRedisProvider _freeRedisProvider;
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
|
||||
public ProtocolService(IFreeRedisProvider freeRedisProvider, IServiceProvider serviceProvider)
|
||||
public ProtocolService(IFreeRedisProvider freeRedisProvider)
|
||||
{
|
||||
_freeRedisProvider = freeRedisProvider;
|
||||
_serviceProvider = serviceProvider;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -44,27 +42,6 @@ namespace JiShe.CollectBus.Protocol.Contracts.Services
|
||||
return protocolInfo;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取协议池服务
|
||||
/// </summary>
|
||||
/// <param name="deviceCode"></param>
|
||||
/// <param name="isSpecial"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<IProtocolPlugin?> GetProtocolServiceAsync(string deviceCode, bool isSpecial = false)
|
||||
{
|
||||
try
|
||||
{
|
||||
ProtocolInfo protocolInfo= await FirstOrDefaultByDeviceAsync(deviceCode, isSpecial);
|
||||
if(protocolInfo==null)
|
||||
return null;
|
||||
return _serviceProvider.GetKeyedService<IProtocolPlugin>(protocolInfo.Name);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static bool ContainsExactPartRegex(string searchPattern, string fullString)
|
||||
{
|
||||
// 构建正则表达式 - 匹配以逗号或开头为边界,以逗号或结尾为边界的部分
|
||||
|
||||
@ -18,7 +18,6 @@ using JiShe.CollectBus.Protocol.Contracts;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Abstracts;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Interfaces;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Models;
|
||||
using JiShe.CollectBus.Protocol.Contracts.Services;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using TouchSocket.Core;
|
||||
@ -39,7 +38,6 @@ namespace JiShe.CollectBus.Plugins
|
||||
private readonly IRepository<Device, Guid> _deviceRepository;
|
||||
private readonly IDistributedCache<AmmeterInfo> _ammeterInfoCache;
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
private readonly IProtocolService _protocolService;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
@ -52,14 +50,13 @@ namespace JiShe.CollectBus.Plugins
|
||||
public TcpMonitor(IProducerService producerService,
|
||||
ILogger<TcpMonitor> logger,
|
||||
IRepository<Device, Guid> deviceRepository,
|
||||
IDistributedCache<AmmeterInfo> ammeterInfoCache, IServiceProvider serviceProvider, IProtocolService protocolService)
|
||||
IDistributedCache<AmmeterInfo> ammeterInfoCache, IServiceProvider serviceProvider)
|
||||
{
|
||||
_producerService = producerService;
|
||||
_logger = logger;
|
||||
_deviceRepository = deviceRepository;
|
||||
_ammeterInfoCache = ammeterInfoCache;
|
||||
_serviceProvider= serviceProvider;
|
||||
_protocolService = protocolService;
|
||||
|
||||
|
||||
}
|
||||
@ -67,12 +64,14 @@ namespace JiShe.CollectBus.Plugins
|
||||
public async Task OnTcpReceived(ITcpSession client, ReceivedDataEventArgs e)
|
||||
{
|
||||
var messageHexString = Convert.ToHexString(e.ByteBlock.Span);
|
||||
var protocolPlugin = await _protocolService.GetProtocolServiceAsync("376.1");
|
||||
|
||||
var tcpSessionClient = (ITcpSessionClient)client;
|
||||
var protocolPlugin = _serviceProvider.GetKeyedService<IProtocolPlugin>("StandardProtocolPlugin");
|
||||
if (protocolPlugin == null)
|
||||
{
|
||||
_logger.LogError("协议不存在!");
|
||||
}
|
||||
var tcpSessionClient = (ITcpSessionClient)client;
|
||||
|
||||
TB3761? tB3761 = await protocolPlugin!.AnalyzeAsync<TB3761>(tcpSessionClient, messageHexString);
|
||||
if (tB3761 == null)
|
||||
{
|
||||
@ -132,6 +131,13 @@ namespace JiShe.CollectBus.Plugins
|
||||
/// <returns></returns>
|
||||
private async Task OnTcpNormalReceived(ITcpSessionClient tcpSessionClient,string messageHexString, TB3761? tB3761)
|
||||
{
|
||||
//var _protocolPlugin = _serviceProvider.GetKeyedService<IProtocolPlugin>("StandardProtocolPlugin");
|
||||
//if (_protocolPlugin == null)
|
||||
//{
|
||||
// _logger.LogError("376.1协议插件不存在!");
|
||||
//}
|
||||
|
||||
|
||||
//await _producerBus.Publish(new MessageReceived
|
||||
//{
|
||||
// ClientId = client.Id,
|
||||
|
||||
@ -24,7 +24,6 @@ using JiShe.CollectBus.Kafka.Internal;
|
||||
using JiShe.CollectBus.IoTDB.Provider;
|
||||
using JiShe.CollectBus.Protocol.Dto;
|
||||
using System.Collections;
|
||||
using JiShe.CollectBus.Interfaces;
|
||||
|
||||
namespace JiShe.CollectBus.Subscribers
|
||||
{
|
||||
@ -37,7 +36,6 @@ namespace JiShe.CollectBus.Subscribers
|
||||
private readonly IRepository<MessageReceivedHeartbeat, Guid> _messageReceivedHeartbeatEventRepository;
|
||||
private readonly IMeterReadingRecordRepository _meterReadingRecordsRepository;
|
||||
private readonly IIoTDbProvider _dbProvider;
|
||||
private readonly IProtocolService _protocolService;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="SubscriberAppService"/> class.
|
||||
@ -54,7 +52,7 @@ namespace JiShe.CollectBus.Subscribers
|
||||
IRepository<MessageReceivedLogin, Guid> messageReceivedLoginEventRepository,
|
||||
IRepository<MessageReceivedHeartbeat, Guid> messageReceivedHeartbeatEventRepository,
|
||||
IIoTDbProvider dbProvider,
|
||||
IMeterReadingRecordRepository meterReadingRecordsRepository, IProtocolService protocolService)
|
||||
IMeterReadingRecordRepository meterReadingRecordsRepository)
|
||||
{
|
||||
_logger = logger;
|
||||
_tcpService = tcpService;
|
||||
@ -63,7 +61,6 @@ namespace JiShe.CollectBus.Subscribers
|
||||
_messageReceivedHeartbeatEventRepository = messageReceivedHeartbeatEventRepository;
|
||||
_meterReadingRecordsRepository = meterReadingRecordsRepository;
|
||||
_dbProvider = dbProvider;
|
||||
_protocolService = protocolService;
|
||||
}
|
||||
|
||||
[LogIntercept]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user