| | |
| | | import java.util.concurrent.ScheduledFuture; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | import static com.ard.utils.netty.tcp.ClientInitialize.aroundScanfMap; |
| | | import static com.ard.utils.util.ByteUtils.toLittleEndian; |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Override |
| | | public void channelInactive(ChannelHandlerContext ctx) throws Exception { |
| | | ChannelId id = ctx.channel().id(); |
| | | InetSocketAddress ipSocket = (InetSocketAddress) ctx.channel().remoteAddress(); |
| | | int port = ipSocket.getPort(); |
| | | String host = ipSocket.getHostString(); |
| | | log.error("与设备" + host + ":" + port + "连接断开!"); |
| | | ArdEquipRadar ardEquipRadar = ClientInitialize.tureConnectMap.get(id); |
| | | String ipPort = ipSocket.getHostString() + ":" + ipSocket.getPort(); |
| | | log.error("与设备" + ipPort + "连接断开!"); |
| | | // 连接断开后的最后处理 |
| | | ctx.pipeline().remove(this); |
| | | ctx.deregister(); |
| | | ctx.close(); |
| | | |
| | | // 将失败信息插入Set集合 |
| | | ClientInitialize.falseConnectSet.add(ardEquipRadar); |
| | | ArdEquipRadar radar = ClientInitialize.trueConnectMap.get(ipPort); |
| | | if (radar != null) { |
| | | ClientInitialize.falseConnectSet.add(radar); |
| | | ClientInitialize.trueConnectMap.remove(ipPort); |
| | | } |
| | | super.channelInactive(ctx); |
| | | } |
| | | |
| | |
| | | * @throws Exception |
| | | */ |
| | | @Override |
| | | public void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) throws Exception { |
| | | ChannelId id = ctx.channel().id(); |
| | | ArdEquipRadar ardEquipRadar = ClientInitialize.tureConnectMap.get(id); |
| | | 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); |
| | | if (radar == null) { |
| | | return; |
| | | } |
| | | MessageHandler messageHandler = ClientInitialize.SucMessageHandlerMap.get(ipPort); |
| | | if (messageHandler == null) { |
| | | return; |
| | | } |
| | | // 处理接收到的消息 |
| | | byte[] byteArray = new byte[msg.readableBytes()]; |
| | | msg.getBytes(msg.readerIndex(), byteArray); |
| | | byte[] bytes = MessageParsing.receiveCompletePacket(byteArray); |
| | | byte[] bytes = messageHandler.receiveCompletePacket(byteArray); |
| | | if (bytes != null) { |
| | | processData(ardEquipRadar, bytes); |
| | | processData(radar, bytes); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 通道数据处理完成 |
| | |
| | | byte[] payloadCrc32 = ByteUtils.parseCrc32(payload); |
| | | byte[] footer = {0x01, 0x02, 0x00}; |
| | | 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}; |
| | | //byte[] heart = {0x01, 0x02, 0x01, 0x10, 0x00, 0x00, 0x00, (byte) 0x83, (byte) 0x88, 0x5d, 0x71, 0x01, 0x02, 0x00}; |
| | | String hexString = DatatypeConverter.printHexBinary(heart); |
| | | // log.debug("发送心跳:" + hexString); |
| | | message.writeBytes(heart); |
| | |
| | | /** |
| | | * 解析报警数据 |
| | | */ |
| | | public void processData(ArdEquipRadar ardEquipRadarbyte, byte[] data) { |
| | | public void processData(ArdEquipRadar radar, byte[] data) { |
| | | try { |
| | | String radarId = ardEquipRadarbyte.getId(); |
| | | String radarName = ardEquipRadarbyte.getName(); |
| | | Double radarLongitude = ardEquipRadarbyte.getLongitude(); |
| | | Double radarLagitude = ardEquipRadarbyte.getLatitude(); |
| | | Double radarAltitude = ardEquipRadarbyte.getAltitude(); |
| | | String radarId = radar.getId(); |
| | | String radarName = radar.getName(); |
| | | Double radarLongitude = radar.getLongitude(); |
| | | Double radarLagitude = radar.getLatitude(); |
| | | Double radarAltitude = radar.getAltitude(); |
| | | //region crc校验-目前仅用于显示校验结果 |
| | | Boolean crc32Check = MessageParsing.CRC32Check(data); |
| | | Boolean crc32Check = MessageHandler.CRC32Check(data); |
| | | if (!crc32Check) { |
| | | log.debug("CRC32校验不通过"); |
| | | } else { |
| | |
| | | //endregion |
| | | //log.info("原始数据:" + DatatypeConverter.printHexBinary(data)); |
| | | //log.info("雷达信息:" + host + "【port】" + port + "【X】" + longitude + "【Y】" + lagitude + "【Z】" + altitude); |
| | | data = MessageParsing.transferData(data);//去掉包头和包尾、校验及转义 |
| | | data = MessageHandler.transferData(data);//去掉包头和包尾、校验及转义 |
| | | //region 负载头解析 |
| | | byte[] type = Arrays.copyOfRange(data, 0, 1);//命令类型 |
| | | // log.info("命令类型:" + DatatypeConverter.printHexBinary(type)); |
| | | byte[] cmdId = Arrays.copyOfRange(data, 1, 2);//命令ID |
| | | String cmdIdStr=DatatypeConverter.printHexBinary(cmdId); |
| | | String cmdIdStr = DatatypeConverter.printHexBinary(cmdId); |
| | | //log.info("命令ID:" + DatatypeConverter.printHexBinary(cmdId)); |
| | | byte[] payloadSize = Arrays.copyOfRange(data, 2, 4);//有效负载大小 |
| | | payloadSize = toLittleEndian(payloadSize); |
| | |
| | | List<ArdAlarmRadar> well = new ArrayList<>(); |
| | | String alarmTime = ""; |
| | | Integer targetNum = 0; |
| | | log.debug("处理雷达"+radarName+"数据-->命令ID:"+cmdIdStr); |
| | | log.debug("处理雷达" + radarName + "数据-->命令ID:" + cmdIdStr); |
| | | //前端工作状态反馈 |
| | | if (Arrays.equals(cmdId, new byte[]{0x00})) { |
| | | //region 告警信息反馈 |
| | | byte[] dfScanAngV = Arrays.copyOfRange(data, 4, 12); |
| | | dfScanAngV = toLittleEndian(dfScanAngV); |
| | | double ScanAngV = ByteUtils.bytesToDouble(dfScanAngV); |
| | | log.info("设备扫描的俯仰角度:" + ScanAngV); |
| | | |
| | | byte[] dfAngDy = Arrays.copyOfRange(data, 12, 20); |
| | | dfAngDy = toLittleEndian(dfAngDy); |
| | | double AngDy = ByteUtils.bytesToDouble(dfAngDy); |
| | | log.info("周视图像的垂直视场角度:" + AngDy); |
| | | |
| | | byte[] iImgW = Arrays.copyOfRange(data, 20, 24); |
| | | iImgW = toLittleEndian(iImgW); |
| | | int ImgW = ByteUtils.bytesToDecimal(iImgW); |
| | | log.info("周视图像的宽:" + ImgW); |
| | | byte[] iImgH = Arrays.copyOfRange(data, 24, 28); |
| | | iImgH = toLittleEndian(iImgH); |
| | | int ImgH = ByteUtils.bytesToDecimal(iImgH); |
| | | log.info("周视图像的高:" + ImgH); |
| | | |
| | | byte[] cStat = Arrays.copyOfRange(data, 28, 29); |
| | | // 提取第4位至第6位的值 |
| | | cStat = toLittleEndian(cStat); |
| | | int Stat = cStat[0] & 0b00000001; |
| | | log.info("设备当前工作状态:" + Stat); |
| | | aroundScanfMap.put(radar.getIp()+":"+radar.getPort(),Stat); |
| | | |
| | | } |
| | | //雷达移动防火报警 |
| | | if (Arrays.equals(cmdId, new byte[]{0x01})) { |
| | | //region 告警信息反馈 |
| | |
| | | double thetaRadians = Math.toRadians(fTy + 90); |
| | | // 使用正弦函数计算对边长度 |
| | | Distance = Math.sin(thetaRadians) * Distance; |
| | | if(Distance<0) |
| | | { |
| | | if (Distance < 0) { |
| | | continue;//过滤距离小于0的脏数据 |
| | | } |
| | | //log.debug("目标投影距离(m):" + Distance); |
| | | |
| | | Double[] radarXY = {radarLongitude, radarLagitude}; |
| | | Double[] alarmXY = GisUtils.CalculateCoordinates(radarXY, Distance, (double) fTx); |
| | | log.debug("报警信息:" + "【radarName】" + radarName + "【targetId】"+ targetId + "【alarmType】" + alarmType + "【alarmTime】" + alarmTime + "【name】" + alarmPointName+"【Distance】"+Distance); |
| | | log.debug("报警信息:" + "【radarName】" + radarName + "【targetId】" + targetId + "【alarmType】" + alarmType + "【alarmTime】" + alarmTime + "【name】" + alarmPointName + "【Distance】" + Distance); |
| | | ArdAlarmRadar ardAlarmRadar = new ArdAlarmRadar(); |
| | | ardAlarmRadar.setTargetId(targetId); |
| | | ardAlarmRadar.setName(alarmPointName); |
| | |
| | | radarAlarmData.setAlarmTime(alarmTime); |
| | | radarAlarmData.setArdAlarmRadars(radarAlarmInfos); |
| | | MqttProducer.publish(2, false, "radar", JSON.toJSONString(radarAlarmData)); |
| | | if (radarFollowInfos.size() >0) { |
| | | if (radarFollowInfos.size() > 0) { |
| | | radarAlarmData.setArdFollowRadars(radarFollowInfos); |
| | | //当前雷达扫描存在引导跟踪数据,只保留最后一次锁定的数据 |
| | | MqttProducer.publish(2, false, "radarFollowGuide", JSON.toJSONString(radarAlarmData)); |
| | |
| | | //log.info("所属告警区域名称:" + DatatypeConverter.printHexBinary(szName)); |
| | | String alarmPointName = ByteUtils.bytesToStringZh(szName); |
| | | // log.info("所属告警区域名称:" + alarmPointName); |
| | | log.debug("报警信息:"+ "【radarName】" + radarName + "【targetId】" + targetId + "【name】" + alarmPointName + "【alarmType】" + alarmType + "【alarmTime】" + alarmTime); |
| | | log.debug("报警信息:" + "【radarName】" + radarName + "【targetId】" + targetId + "【name】" + alarmPointName + "【alarmType】" + alarmType + "【alarmTime】" + alarmTime); |
| | | ArdAlarmRadar ardAlarmRadar = new ArdAlarmRadar(); |
| | | ardAlarmRadar.setTargetId(targetId); |
| | | ardAlarmRadar.setName(alarmPointName); |
| | |
| | | log.error("雷达报文解析异常:" + ex.getMessage()); |
| | | } |
| | | } |
| | | } |
| | | } |