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