1、增加TCP空闲释放

2、bug fix: disXY空指针异常
This commit is contained in:
weidong 2024-04-05 17:16:50 +08:00
parent 4cbe5d7a78
commit 230b30dcec
3 changed files with 22 additions and 3 deletions

View File

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

View File

@ -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<ByteBuf> {
}
}
@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();
}

View File

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