From 230b30dcecda54574fa598ab8a85d2967272f800 Mon Sep 17 00:00:00 2001 From: weidong Date: Fri, 5 Apr 2024 17:16:50 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E5=A2=9E=E5=8A=A0TCP=E7=A9=BA?= =?UTF-8?q?=E9=97=B2=E9=87=8A=E6=94=BE=202=E3=80=81bug=20fix:=20disXY?= =?UTF-8?q?=E7=A9=BA=E6=8C=87=E9=92=88=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../calc/SingleLineGNSSCalcService.java | 2 +- .../sideslope/server/tcp/RtcmTcpHandler.java | 18 +++++++++++++++++- .../sideslope/server/tcp/RtcmTcpServer.java | 5 ++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/calc/SingleLineGNSSCalcService.java b/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/calc/SingleLineGNSSCalcService.java index fb591513..baa553e7 100644 --- a/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/calc/SingleLineGNSSCalcService.java +++ b/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/calc/SingleLineGNSSCalcService.java @@ -114,7 +114,7 @@ public class SingleLineGNSSCalcService implements GNSSDataCalcService { double[] b562Result = focusCalculator.resultB562(lastEfk); double[] r9250Result = null; //判断 取到的b562 和上次融合坐标做判断,如果距离>100mm 不计算9250 - if (lastEfk != null && FocusCalculator1.disXY(b562Result,lastEfk)<100){ + if (lastEfk != null && b562Result!=null && FocusCalculator1.disXY(b562Result,lastEfk)<100){ r9250Result = focusCalculator.result9250(); } double[] result = focusCalculator.ekfResult(b562Result,r9250Result); diff --git a/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/server/tcp/RtcmTcpHandler.java b/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/server/tcp/RtcmTcpHandler.java index acf5306a..536e2b8c 100644 --- a/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/server/tcp/RtcmTcpHandler.java +++ b/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/server/tcp/RtcmTcpHandler.java @@ -6,9 +6,12 @@ import com.imdroid.sideslope.executor.MessageParser; import com.imdroid.sideslope.message.BaseMessage; import com.imdroid.sideslope.server.OnlineChannels; import io.netty.buffer.ByteBuf; +import io.netty.channel.Channel; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; +import io.netty.handler.timeout.IdleState; +import io.netty.handler.timeout.IdleStateEvent; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; @@ -34,16 +37,29 @@ public class RtcmTcpHandler extends SimpleChannelInboundHandler { } } + @Override + public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { + if(evt instanceof IdleStateEvent) { + IdleStateEvent event = (IdleStateEvent) evt; + + if (event.state() == IdleState.READER_IDLE) { + Channel channel = ctx.channel(); + logger.info(channel.remoteAddress() + " idle too long to be closed"); + channel.close(); + } + } + } + @Override public void channelInactive(ChannelHandlerContext ctx) throws Exception { logger.info("channel inactive"); + ctx.close(); } @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { cause.printStackTrace(); - ctx.close(); } diff --git a/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/server/tcp/RtcmTcpServer.java b/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/server/tcp/RtcmTcpServer.java index 96fbb148..c3834021 100644 --- a/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/server/tcp/RtcmTcpServer.java +++ b/sec-beidou-rtcm/src/main/java/com/imdroid/sideslope/server/tcp/RtcmTcpServer.java @@ -6,6 +6,7 @@ import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.handler.logging.LogLevel; import io.netty.handler.logging.LoggingHandler; +import io.netty.handler.timeout.IdleStateHandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; @@ -38,7 +39,9 @@ public class RtcmTcpServer implements ApplicationRunner { .childHandler(new ChannelInitializer() { @Override protected void initChannel(Channel channel) throws Exception { - channel.pipeline().addLast(new RtcmTcpHandler()); + ChannelPipeline p = channel.pipeline(); + p.addLast(new IdleStateHandler(300, 300, 300)); //设置心跳超时时间,秒 + p.addLast(new RtcmTcpHandler()); } }); Channel ch = b.bind(port).sync().channel();