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();