| File was renamed from src/main/java/com/ard/utils/netty/tcp/ClientHandler.java |
| | |
| | | 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; |
| | |
| | | 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; |
| | | |
| | | /** |
| | |
| | | * @Date: 2023年07月05日13:13 |
| | | * @Version: 1.0 |
| | | **/ |
| | | |
| | | @Component |
| | | //@ChannelHandler.Sharable |
| | | @Slf4j(topic = "netty") |
| | | public class ClientHandler extends SimpleChannelInboundHandler<ByteBuf> { |
| | | private ChannelHandlerContext context; |
| | |
| | | @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); |
| | | } |
| | | |
| | |
| | | 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; |
| | | } |
| | |
| | | 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位的值 |