| | |
| | | package com.ard.utils.tcp; |
| | | |
| | | /** |
| | | * @Description: |
| | | * @ClassName: ClientHandler |
| | | * @Author: 刘苏义 |
| | | * @Date: 2023年07月05日13:13 |
| | | * @Version: 1.0 |
| | | **/ |
| | | |
| | | 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.ByteUtils; |
| | | import com.ard.utils.GisUtils; |
| | | import com.ard.utils.other.ByteUtils; |
| | | import com.ard.utils.other.GisUtils; |
| | | import com.ard.utils.mqtt.MqttConsumer; |
| | | import io.netty.buffer.ByteBuf; |
| | | import io.netty.channel.ChannelHandlerContext; |
| | | import io.netty.channel.ChannelId; |
| | | import io.netty.channel.ChannelInboundHandlerAdapter; |
| | | import io.netty.channel.SimpleChannelInboundHandler; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | |
| | | import java.util.List; |
| | | import java.util.concurrent.ScheduledFuture; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | /** |
| | | * 客户端处理器 |
| | | * |
| | | * @author lijiamin |
| | | */ |
| | | * @Description: 客户端处理器 |
| | | * @ClassName: ClientHandler |
| | | * @Author: 刘苏义 |
| | | * @Date: 2023年07月05日13:13 |
| | | * @Version: 1.0 |
| | | **/ |
| | | |
| | | @Slf4j(topic = "netty") |
| | | public class ClientHandler extends SimpleChannelInboundHandler<ByteBuf> { |
| | | private ChannelHandlerContext context; |
| | |
| | | byte[] heart = ByteUtils.appendArrays(header, payload, payloadCrc32, footer); |
| | | // byte[] heart = {0x01, 0x02, 0x01, 0x10, 0x00, 0x00, 0x00, (byte) 0x83, (byte) 0x88, 0x5d, 0x71, 0x01, 0x02, 0x00}; |
| | | String hexString = DatatypeConverter.printHexBinary(heart); |
| | | log.info("发送心跳:" + hexString); |
| | | log.debug("发送心跳:" + hexString); |
| | | message.writeBytes(heart); |
| | | context.writeAndFlush(message); |
| | | |
| | |
| | | //region crc校验-目前仅用于显示校验结果 |
| | | Boolean crc32Check = MessageParsing.CRC32Check(data); |
| | | if (!crc32Check) { |
| | | log.info("CRC32校验不通过"); |
| | | log.debug("CRC32校验不通过"); |
| | | } else { |
| | | log.info("CRC32校验通过"); |
| | | log.debug("CRC32校验通过"); |
| | | } |
| | | //endregion |
| | | //log.info("原始数据:" + DatatypeConverter.printHexBinary(data)); |
| | |
| | | if (targetNum == 0) { |
| | | return; |
| | | } |
| | | log.info("目标总点数(转整型):" + targetNum); |
| | | log.debug("目标总点数(转整型):" + targetNum); |
| | | |
| | | //解析NET_TARGET_UNIT(64是NET_TARGET_HEAD的字节数) |
| | | int uintSize = (payloadSizeToDecimal - 64) / targetNum; |
| | |
| | | // log.info("报警类型:" + alarmType); |
| | | |
| | | byte[] szName = Arrays.copyOfRange(data, index + 64, index + 96); |
| | | int position = ByteUtils.findIndexOfDoubleZero(szName); |
| | | String alarmPointName; |
| | | if (position != -1) { |
| | | byte[] result = new byte[position]; |
| | | System.arraycopy(szName, 0, result, 0, position); |
| | | alarmPointName = new String(result, "GBK"); |
| | | } else { |
| | | alarmPointName = new String(szName, "GBK"); |
| | | } |
| | | String alarmPointName = ByteUtils.bytesToStringZh(szName); |
| | | // log.info("所属告警区域名称:" + alarmPointName); |
| | | byte[] afTx = Arrays.copyOfRange(data, index + 96, index + 100); |
| | | afTx = ByteUtils.toLittleEndian(afTx); |
| | |
| | | afTy = ByteUtils.toLittleEndian(afTy); |
| | | float fTy = ByteUtils.bytesToFloat(afTy); |
| | | // log.info("垂直角度:" + fTy); |
| | | Double[] radarXY = {radarLagitude, radarLagitude}; |
| | | Double[] radarXY = {radarLongitude, radarLagitude}; |
| | | Double[] alarmXY = GisUtils.CalculateCoordinates(radarXY, Distance, (double) fTx); |
| | | // log.info("报警信息:" + "【id】" + id + "【name】" + alarmPointName + "【alarmType】" + alarmType + "【alarmTime】" + alarmTime + "【distance】" + Distance + "【P】" + fTx + "【T】" + fTy + "【X】" + alarmXY[0] + "【Y】" + alarmXY[1]); |
| | | ArdAlarmRadar ardAlarmRadar = new ArdAlarmRadar(); |
| | |
| | | byte[] wTargetNum = Arrays.copyOfRange(data, 8, 10); |
| | | wTargetNum = ByteUtils.toLittleEndian(wTargetNum); |
| | | targetNum = ByteUtils.bytesToDecimal(wTargetNum); |
| | | log.info("目标总点数(转整型):" + targetNum); |
| | | log.debug("目标总点数(转整型):" + targetNum); |
| | | if (targetNum == 0) { |
| | | return; |
| | | } |
| | |
| | | |
| | | byte[] szName = Arrays.copyOfRange(data, index + 32, index + 64); |
| | | //log.info("所属告警区域名称:" + DatatypeConverter.printHexBinary(szName)); |
| | | int position = ByteUtils.findIndexOfDoubleZero(szName); |
| | | String alarmPointName; |
| | | if (position != -1) { |
| | | byte[] result = new byte[position]; |
| | | System.arraycopy(szName, 0, result, 0, position); |
| | | alarmPointName = new String(result, "GBK"); |
| | | } else { |
| | | alarmPointName = new String(szName, "GBK"); |
| | | } |
| | | String alarmPointName = ByteUtils.bytesToStringZh(szName); |
| | | // log.info("所属告警区域名称:" + alarmPointName); |
| | | //log.info("报警信息:" + "【id】" + id + "【name】" + alarmPointName + "【alarmType】" + alarmType + "【alarmTime】" + alarmTime); |
| | | ArdAlarmRadar ardAlarmRadar = new ArdAlarmRadar(); |