‘liusuyi’
2024-03-26 b0926cd91651c158a3a1c070f9b6d2d8ce877cfe
src/main/java/com/ard/utils/netty/tcp/handler/ClientHandler.java
ÎļþÃû´Ó src/main/java/com/ard/utils/netty/tcp/ClientHandler.java ÐÞ¸Ä
@@ -1,18 +1,18 @@
package com.ard.utils.netty.tcp;
package com.ard.utils.netty.tcp.handler;
import com.alibaba.fastjson2.JSON;
import com.ard.alarm.radar.domain.ArdAlarmRadar;
import com.ard.alarm.radar.domain.ArdEquipRadar;
import com.ard.alarm.radar.domain.RadarAlarmData;
import com.ard.utils.netty.tcp.RadarNettyTcpClient;
import com.ard.utils.util.ByteUtils;
import com.ard.utils.util.GisUtils;
import com.ard.utils.mqtt.MqttProducer;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelId;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.channel.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import javax.xml.bind.DatatypeConverter;
import java.net.InetSocketAddress;
@@ -21,7 +21,7 @@
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import static com.ard.utils.netty.tcp.ClientInitialize.aroundScanfMap;
import static com.ard.utils.netty.tcp.RadarNettyTcpClient.aroundScanfMap;
import static com.ard.utils.util.ByteUtils.toLittleEndian;
/**
@@ -31,7 +31,8 @@
 * @Date: 2023å¹´07月05日13:13
 * @Version: 1.0
 **/
@Component
//@ChannelHandler.Sharable
@Slf4j(topic = "netty")
public class ClientHandler extends SimpleChannelInboundHandler<ByteBuf> {
    private ChannelHandlerContext context;
@@ -58,18 +59,9 @@
    @Override
    public void channelInactive(ChannelHandlerContext ctx) throws Exception {
        InetSocketAddress ipSocket = (InetSocketAddress) ctx.channel().remoteAddress();
        String ipPort = ipSocket.getHostString() + ":" + ipSocket.getPort();
        log.error("与设备" + ipPort + "连接断开!");
        // è¿žæŽ¥æ–­å¼€åŽçš„æœ€åŽå¤„理
        ctx.pipeline().remove(this);
        ctx.deregister();
        ctx.close();
        // å°†å¤±è´¥ä¿¡æ¯æ’å…¥Set集合
        ArdEquipRadar radar = ClientInitialize.trueConnectMap.get(ipPort);
        if (radar != null) {
            ClientInitialize.falseConnectSet.add(radar);
            ClientInitialize.trueConnectMap.remove(ipPort);
        }
        String ip = ipSocket.getHostString();
        int port = ipSocket.getPort();
        log.error("与雷达设备【" + ip + ":" + port + "】连接断开!");
        super.channelInactive(ctx);
    }
@@ -85,11 +77,11 @@
    public void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) {
        InetSocketAddress ipSocket = (InetSocketAddress) ctx.channel().remoteAddress();
        String ipPort = ipSocket.getHostString() + ":" + ipSocket.getPort();
        ArdEquipRadar radar = ClientInitialize.trueConnectMap.get(ipPort);
        ArdEquipRadar radar = RadarNettyTcpClient.RADAR_MAP.get(ipPort);
        if (radar == null) {
            return;
        }
        MessageHandler messageHandler = ClientInitialize.SucMessageHandlerMap.get(ipPort);
        MessageHandler messageHandler = RadarNettyTcpClient.SucMessageHandlerMap.get(ipPort);
        if (messageHandler == null) {
            return;
        }
@@ -218,21 +210,21 @@
                byte[] dfScanAngV = Arrays.copyOfRange(data, 4, 12);
                dfScanAngV = toLittleEndian(dfScanAngV);
                double ScanAngV = ByteUtils.bytesToDouble(dfScanAngV);
                log.info("设备扫描的俯仰角度:" + ScanAngV);
                //log.info("设备扫描的俯仰角度:" + ScanAngV);
                byte[] dfAngDy = Arrays.copyOfRange(data, 12, 20);
                dfAngDy = toLittleEndian(dfAngDy);
                double AngDy = ByteUtils.bytesToDouble(dfAngDy);
                log.info("周视图像的垂直视场角度:" + AngDy);
                //log.info("周视图像的垂直视场角度:" + AngDy);
                byte[] iImgW = Arrays.copyOfRange(data, 20, 24);
                iImgW = toLittleEndian(iImgW);
                int ImgW = ByteUtils.bytesToDecimal(iImgW);
                log.info("周视图像的宽:" + ImgW);
                //log.info("周视图像的宽:" + ImgW);
                byte[] iImgH = Arrays.copyOfRange(data, 24, 28);
                iImgH = toLittleEndian(iImgH);
                int ImgH = ByteUtils.bytesToDecimal(iImgH);
                log.info("周视图像的高:" + ImgH);
                //log.info("周视图像的高:" + ImgH);
                byte[] cStat = Arrays.copyOfRange(data, 28, 29);
                // æå–第4位至第6位的值