ÎļþÃû´Ó 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ä½çå¼ |