diff --git a/protocols/JiShe.CollectBus.Protocol.T1882018/T1882018ProtocolPlugin.cs b/protocols/JiShe.CollectBus.Protocol.T1882018/T1882018ProtocolPlugin.cs index 5aa1b1f..7e9f3a3 100644 --- a/protocols/JiShe.CollectBus.Protocol.T1882018/T1882018ProtocolPlugin.cs +++ b/protocols/JiShe.CollectBus.Protocol.T1882018/T1882018ProtocolPlugin.cs @@ -91,7 +91,7 @@ namespace JiShe.CollectBus.Protocol.T1882018 List dataUnit = new List(); //数据转发场景 10H_F1 - if (aFNStr == "10" && request.SubProtocolRequest != null && string.IsNullOrWhiteSpace(request.SubProtocolRequest.ItemCode) == false) + if (request.ItemCode == T37612012PacketItemCodeConst.AFN10HFN01H && request.SubProtocolRequest != null && string.IsNullOrWhiteSpace(request.SubProtocolRequest.ItemCode) == false) { var t188PacketHandlerName = $"{T1882018PacketItemCodeConst.BasicT1882018}_{request.SubProtocolRequest.ItemCode}_Send"; Telemetry1882018PacketResponse t645PacketResponse = null; diff --git a/protocols/JiShe.CollectBus.Protocol/Services/ProtocolService.cs b/protocols/JiShe.CollectBus.Protocol/Services/ProtocolService.cs index e391fcd..8a69307 100644 --- a/protocols/JiShe.CollectBus.Protocol/Services/ProtocolService.cs +++ b/protocols/JiShe.CollectBus.Protocol/Services/ProtocolService.cs @@ -1,10 +1,12 @@ using System.Text.RegularExpressions; +using JiShe.CollectBus.Common; using JiShe.CollectBus.Common.Consts; using JiShe.CollectBus.FreeRedis; using JiShe.CollectBus.IotSystems.Protocols; using JiShe.CollectBus.Protocol.Interfaces; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; using Volo.Abp; using Volo.Abp.DependencyInjection; @@ -15,12 +17,14 @@ namespace JiShe.CollectBus.Protocol.Services private readonly IFreeRedisProvider _freeRedisProvider; private readonly IServiceProvider _serviceProvider; private readonly ILogger _logger; + private readonly ServerApplicationOptions _serverApplicationOptions; - public ProtocolService(IFreeRedisProvider freeRedisProvider, IServiceProvider serviceProvider, ILogger logger) + public ProtocolService(IFreeRedisProvider freeRedisProvider, IServiceProvider serviceProvider, ILogger logger,IOptions serverApplicationOptions) { _freeRedisProvider = freeRedisProvider; _serviceProvider = serviceProvider; _logger= logger; + _serverApplicationOptions = serverApplicationOptions.Value; } /// @@ -36,7 +40,7 @@ namespace JiShe.CollectBus.Protocol.Services var keyValuePair = protocols.FirstOrDefault(a => ContainsExactPartRegex(deviceCode, a.Value.RegularExpression)); if (!keyValuePair.Key.IsNullOrWhiteSpace() || keyValuePair.Value != null) return keyValuePair.Value; if (isSpecial) throw new UserFriendlyException("The device protocol plugin does not exist!", ExceptionCode.NotFound); - var hasStandardProtocolPlugin = protocols.TryGetValue("T37612012ProtocolPlugin", out var protocolInfo); + var hasStandardProtocolPlugin = protocols.TryGetValue(_serverApplicationOptions.DefaultProtocolPlugin, out var protocolInfo); if (!hasStandardProtocolPlugin) throw new UserFriendlyException("Standard protocol plugin does not exist!", ExceptionCode.NotFound); return protocolInfo; } diff --git a/services/JiShe.CollectBus.Application/Plugins/TcpMonitor.cs b/services/JiShe.CollectBus.Application/Plugins/TcpMonitor.cs index ab813fc..03a1003 100644 --- a/services/JiShe.CollectBus.Application/Plugins/TcpMonitor.cs +++ b/services/JiShe.CollectBus.Application/Plugins/TcpMonitor.cs @@ -1,9 +1,11 @@ -using JiShe.CollectBus.IotSystems.Ammeters; +using JiShe.CollectBus.Common; +using JiShe.CollectBus.IotSystems.Ammeters; using JiShe.CollectBus.IotSystems.Devices; using JiShe.CollectBus.Kafka.Producer; using JiShe.CollectBus.Protocol.Interfaces; using JiShe.CollectBus.Protocol3761; using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; using System; using System.Threading.Tasks; using TouchSocket.Core; @@ -22,6 +24,7 @@ namespace JiShe.CollectBus.Plugins private readonly IDistributedCache _ammeterInfoCache; private readonly IServiceProvider _serviceProvider; private readonly IProtocolService _protocolService; + private readonly ServerApplicationOptions _serverApplicationOptions; /// /// @@ -31,10 +34,15 @@ namespace JiShe.CollectBus.Plugins /// /// /// + /// + /// public TcpMonitor(IProducerService producerService, ILogger logger, IRepository deviceRepository, - IDistributedCache ammeterInfoCache, IServiceProvider serviceProvider, IProtocolService protocolService) + IDistributedCache ammeterInfoCache, + IServiceProvider serviceProvider, + IOptions serverApplicationOptions, + IProtocolService protocolService) { _producerService = producerService; _logger = logger; @@ -42,17 +50,20 @@ namespace JiShe.CollectBus.Plugins _ammeterInfoCache = ammeterInfoCache; _serviceProvider= serviceProvider; _protocolService = protocolService; - - + _serverApplicationOptions = serverApplicationOptions.Value; } public async Task OnTcpReceived(ITcpSession client, ReceivedDataEventArgs e) { + if (string.IsNullOrWhiteSpace(_serverApplicationOptions.DefaultProtocolPlugin)) + { + _logger.LogError($"请配置默认的端到云协议插件!"); + } var messageHexString = Convert.ToHexString(e.ByteBlock.Span); - var protocolPlugin = await _protocolService.GetProtocolServiceAsync("376.1"); + var protocolPlugin = await _protocolService.GetProtocolServiceAsync(_serverApplicationOptions.DefaultProtocolPlugin); if (protocolPlugin == null) { - _logger.LogError("协议不存在!"); + _logger.LogError($"默认的端到云协议插件{_serverApplicationOptions.DefaultProtocolPlugin}不存在!"); } var tcpSessionClient = (ITcpSessionClient)client; diff --git a/shared/JiShe.CollectBus.Common/Models/ServerApplicationOptions.cs b/shared/JiShe.CollectBus.Common/Models/ServerApplicationOptions.cs index 8aed32b..228dec0 100644 --- a/shared/JiShe.CollectBus.Common/Models/ServerApplicationOptions.cs +++ b/shared/JiShe.CollectBus.Common/Models/ServerApplicationOptions.cs @@ -18,12 +18,12 @@ /// /// 首次采集时间 /// - public DateTime? FirstCollectionTime { get; set; } + public DateTime? FirstCollectionTime { get; set; } /// /// 自动验证时间 /// - public required string AutomaticVerificationTime { get; set;} + public required string AutomaticVerificationTime { get; set; } /// /// 自动获取终端版时间 @@ -34,5 +34,10 @@ /// 自动获取远程通信模块(SIM)版本时间 /// public required string AutomaticGetTelematicsModuleTime { get; set; } + + /// + /// 默认协议插件 + /// + public required string DefaultProtocolPlugin { get; set; } } } diff --git a/web/JiShe.CollectBus.Host/JiShe.CollectBus.Protocol.Test.dll b/web/JiShe.CollectBus.Host/JiShe.CollectBus.Protocol.Test.dll deleted file mode 100644 index 01d6842..0000000 Binary files a/web/JiShe.CollectBus.Host/JiShe.CollectBus.Protocol.Test.dll and /dev/null differ diff --git a/web/JiShe.CollectBus.Host/JiShe.CollectBus.Protocol.dll b/web/JiShe.CollectBus.Host/JiShe.CollectBus.Protocol.dll deleted file mode 100644 index 96cf07b..0000000 Binary files a/web/JiShe.CollectBus.Host/JiShe.CollectBus.Protocol.dll and /dev/null differ diff --git a/web/JiShe.CollectBus.Host/Pages/Monitor.cshtml b/web/JiShe.CollectBus.Host/Pages/Monitor.cshtml index 9fa48a5..795d181 100644 --- a/web/JiShe.CollectBus.Host/Pages/Monitor.cshtml +++ b/web/JiShe.CollectBus.Host/Pages/Monitor.cshtml @@ -18,7 +18,7 @@ 后端服务 - +