From 9a5cb565e95a44db38f68208d3c7097bf62b50b3 Mon Sep 17 00:00:00 2001 From: cli <377476583@qq.com> Date: Wed, 12 Mar 2025 17:10:00 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Plugins/TcpMonitor.cs | 14 +++++--------- .../CollectBusHostModule.Configure.cs | 4 ++-- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/JiShe.CollectBus.Application/Plugins/TcpMonitor.cs b/src/JiShe.CollectBus.Application/Plugins/TcpMonitor.cs index b4b6079..d5c95c6 100644 --- a/src/JiShe.CollectBus.Application/Plugins/TcpMonitor.cs +++ b/src/JiShe.CollectBus.Application/Plugins/TcpMonitor.cs @@ -55,15 +55,12 @@ namespace JiShe.CollectBus.Plugins var aTuple = (Tuple)hexStringList.GetAnalyzeValue(CommandChunkEnum.A); if (aFn.HasValue && fn.HasValue && aTuple != null && !string.IsNullOrWhiteSpace(aTuple.Item1)) { - string oldClinetId = client.Id; - await client.ResetIdAsync(aTuple.Item1); - if ((AFN)aFn == AFN.链路接口检测) { switch (fn) { case 1: - await OnTcpLoginReceived(client, messageHexString, aTuple.Item1, oldClinetId); + await OnTcpLoginReceived(client, messageHexString, aTuple.Item1); break; case 3: await OnTcpHeartbeatReceived(client, messageHexString, aTuple.Item1); @@ -123,13 +120,12 @@ namespace JiShe.CollectBus.Plugins /// /// /// 集中器编号 - /// TCP首次连接时的Id /// - private async Task OnTcpLoginReceived(ITcpSessionClient client, string messageHexString, string deviceNo,string oldClinetId) + private async Task OnTcpLoginReceived(ITcpSessionClient client, string messageHexString, string deviceNo) { var messageReceivedLoginEvent = new MessageReceivedLogin { - ClientId = oldClinetId, + ClientId = client.Id, ClientIp = client.IP, ClientPort = client.Port, MessageHexString = messageHexString, @@ -140,11 +136,11 @@ namespace JiShe.CollectBus.Plugins var entity = await _deviceRepository.FindAsync(a => a.Number == deviceNo); if (entity == null) { - await _deviceRepository.InsertAsync(new Device(deviceNo, oldClinetId, DateTime.Now, DateTime.Now, DeviceStatus.Online)); + await _deviceRepository.InsertAsync(new Device(deviceNo, client.Id,DateTime.Now, DateTime.Now, DeviceStatus.Online)); } else { - entity.UpdateByLoginAndHeartbeat(oldClinetId); + entity.UpdateByLoginAndHeartbeat(client.Id); await _deviceRepository.UpdateAsync(entity); } } diff --git a/src/JiShe.CollectBus.Host/CollectBusHostModule.Configure.cs b/src/JiShe.CollectBus.Host/CollectBusHostModule.Configure.cs index 699ba43..3a0390a 100644 --- a/src/JiShe.CollectBus.Host/CollectBusHostModule.Configure.cs +++ b/src/JiShe.CollectBus.Host/CollectBusHostModule.Configure.cs @@ -222,9 +222,9 @@ namespace JiShe.CollectBus.Host { context.Services.AddTcpService(config => { - config.SetListenIPHosts(int.Parse(configuration["TCP:ClientPort"] ?? "32580")) + config.SetListenIPHosts(int.Parse(configuration["TCP:ClientPort"] ?? "10500")) //.SetTcpDataHandlingAdapter(()=>new StandardFixedHeaderDataHandlingAdapter()) - .SetGetDefaultNewId(() => Guid.NewGuid().ToString())//定义ClinetId的生成策略 + //.SetGetDefaultNewId(() => Guid.NewGuid().ToString())//定义ClinetId的生成策略 .ConfigurePlugins(a => { a.Add();