From 165befbfdc284f873a7ab266dee772f957787947 Mon Sep 17 00:00:00 2001 From: ‘liusuyi’ <1951119284@qq.com> Date: 星期六, 16 九月 2023 08:58:26 +0800 Subject: [PATCH] 修复雷达报警投影距离 取消雷达坐标转84坐标 --- src/main/java/com/ard/utils/tcp/ClientHandler.java | 29 +++++++++++++++++++---------- src/main/java/com/ard/utils/other/GisUtils.java | 8 ++++---- src/main/java/com/ard/utils/other/ByteUtils.java | 18 +++++++----------- 3 files changed, 30 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/ard/utils/other/ByteUtils.java b/src/main/java/com/ard/utils/other/ByteUtils.java index 752b333..b82cd85 100644 --- a/src/main/java/com/ard/utils/other/ByteUtils.java +++ b/src/main/java/com/ard/utils/other/ByteUtils.java @@ -3,6 +3,7 @@ import java.io.ByteArrayOutputStream; import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; +import java.nio.ByteOrder; import java.util.zip.CRC32; /** @@ -62,11 +63,9 @@ */ public static int bytesToDecimal(byte[] byteArray) { int decimalValue = 0; - for (int i = 0; i < byteArray.length; i++) { decimalValue = (decimalValue << 8) | (byteArray[i] & 0xFF); } - return decimalValue; } @@ -74,15 +73,12 @@ * byte鏁扮粍杞珼ouble */ public static double bytesToDouble(byte[] byteArray) { - long longBits = 0; - - // 鏍规嵁瀛楄妭鏁扮粍鐨勯暱搴﹀拰瀛楄妭椤哄簭锛屽皢瀛楄妭鏁扮粍杞崲涓洪暱鏁村瀷 - for (int i = 0; i < byteArray.length; i++) { - longBits |= (long) (byteArray[i] & 0xFF) << (8 * (byteArray.length - 1 - i)); - } - - // 浣跨敤Double.longBitsToDouble鏂规硶灏嗛暱鏁村瀷杞崲涓篋ouble绫诲瀷 - return Double.longBitsToDouble(longBits); + // 鍒涘缓涓�涓狟yteBuffer骞惰缃瓧鑺傞『搴忎负澶х + ByteBuffer buffer = ByteBuffer.wrap(byteArray); + buffer.order(ByteOrder.LITTLE_ENDIAN); + // 浠嶣yteBuffer涓幏鍙杁ouble鍊� + double doubleValue = buffer.getDouble(); + return doubleValue; } /** diff --git a/src/main/java/com/ard/utils/other/GisUtils.java b/src/main/java/com/ard/utils/other/GisUtils.java index 17bcc3c..e58ca17 100644 --- a/src/main/java/com/ard/utils/other/GisUtils.java +++ b/src/main/java/com/ard/utils/other/GisUtils.java @@ -15,10 +15,10 @@ /** * 閫氳繃A鐐瑰潗鏍囷紝闀垮害鍜孻杞磋搴﹁绠桞鐐瑰潗鏍� */ - public static Double[] CalculateCoordinates(Double[] radarCoordinates, Double distance, Double angle) { - double[] to_wgs84 = LonlatConver.gcj02_To_Wgs84(radarCoordinates[0], radarCoordinates[1]); - double Ax = to_wgs84[0]; // A 鐐圭殑 X 鍧愭爣 - double Ay = to_wgs84[1]; // A 鐐圭殑 Y 鍧愭爣 + public static Double[] CalculateCoordinates(Double[] radarCoordinates, double distance, Double angle) { + //double[] to_wgs84 = LonlatConver.gcj02_To_Wgs84(radarCoordinates[0], radarCoordinates[1]); + double Ax = radarCoordinates[0]; // A 鐐圭殑 X 鍧愭爣 + double Ay = radarCoordinates[1]; // A 鐐圭殑 Y 鍧愭爣 double AB = distance; // AB 鐨勯暱搴� double angleWithYAxisDegrees = angle; // AB 涓� Y 杞寸殑瑙掑害锛堜互搴︽暟琛ㄧず锛� GeodeticCalculator calculator = new GeodeticCalculator(); diff --git a/src/main/java/com/ard/utils/tcp/ClientHandler.java b/src/main/java/com/ard/utils/tcp/ClientHandler.java index b7ebb4d..f472809 100644 --- a/src/main/java/com/ard/utils/tcp/ClientHandler.java +++ b/src/main/java/com/ard/utils/tcp/ClientHandler.java @@ -1,4 +1,5 @@ package com.ard.utils.tcp; + import com.alibaba.fastjson2.JSON; import com.ard.alarm.radar.domain.ArdAlarmRadar; import com.ard.alarm.radar.domain.ArdEquipRadar; @@ -21,6 +22,7 @@ import java.util.List; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; + /** * @Description: 瀹㈡埛绔鐞嗗櫒 * @ClassName: ClientHandler @@ -143,7 +145,7 @@ 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.debug("鍙戦�佸績璺�:" + hexString); + // log.debug("鍙戦�佸績璺�:" + hexString); message.writeBytes(heart); context.writeAndFlush(message); @@ -169,6 +171,7 @@ String radarName = ardEquipRadarbyte.getName(); Double radarLongitude = ardEquipRadarbyte.getLongitude(); Double radarLagitude = ardEquipRadarbyte.getLatitude(); + Double radarAltitude = ardEquipRadarbyte.getAltitude(); //region crc鏍¢獙-鐩墠浠呯敤浜庢樉绀烘牎楠岀粨鏋� Boolean crc32Check = MessageParsing.CRC32Check(data); if (!crc32Check) { @@ -221,13 +224,13 @@ // log.info("鐩爣ID:" + DatatypeConverter.printHexBinary(cmdId)); dwID = ByteUtils.toLittleEndian(dwID); int id = ByteUtils.bytesToDecimal(dwID); - // log.info("鐩爣ID鍙凤細" + id); byte[] iDistance = Arrays.copyOfRange(data, index + 8, index + 12); iDistance = ByteUtils.toLittleEndian(iDistance); - Double Distance = ByteUtils.bytesToDouble(iDistance); - // log.info("鐩爣褰撳墠璺濈(m):" + Distance); + double Distance = ByteUtils.bytesToDecimal(iDistance); + log.debug("鐩爣褰撳墠鐩寸嚎璺濈(m):" + Distance); + //region 涓嶉渶瑕佺殑瀛楁 // byte[] dwGSum = Arrays.copyOfRange(data, index + 4, index + 8); // dwGSum = toLittleEndian(dwGSum); @@ -298,10 +301,16 @@ byte[] afTy = Arrays.copyOfRange(data, index + 112, index + 116); afTy = ByteUtils.toLittleEndian(afTy); float fTy = ByteUtils.bytesToFloat(afTy); - // log.info("鍨傜洿瑙掑害:" + fTy); + log.debug("鍨傜洿瑙掑害:" + fTy); + // 灏嗚搴﹁浆鎹负寮у害 + double thetaRadians = Math.toRadians(fTy+90); + // 浣跨敤姝e鸡鍑芥暟璁$畻瀵硅竟闀垮害 + Distance = Math.sin(thetaRadians) * Distance; + log.debug("鐩爣鎶曞奖璺濈(m):" + Distance); + Double[] radarXY = {radarLongitude, radarLagitude}; Double[] alarmXY = GisUtils.CalculateCoordinates(radarXY, Distance, (double) fTx); - // log.info("鎶ヨ淇℃伅锛�" + "銆恑d銆�" + id + "銆恘ame銆�" + alarmPointName + "銆恆larmType銆�" + alarmType + "銆恆larmTime銆�" + alarmTime + "銆恉istance銆�" + Distance + "銆怭銆�" + fTx + "銆怲銆�" + fTy + "銆怷銆�" + alarmXY[0] + "銆怸銆�" + alarmXY[1]); + log.debug("鎶ヨ淇℃伅锛�" + "銆恑d銆�" + id + "銆恘ame銆�" + alarmPointName + "銆恆larmType銆�" + alarmType + "銆恆larmTime銆�" + alarmTime + "銆恉istance銆�" + Distance + "銆怭銆�" + fTx + "銆怲銆�" + fTy + "銆怷銆�" + alarmXY[0] + "銆怸銆�" + alarmXY[1]); ArdAlarmRadar ardAlarmRadar = new ArdAlarmRadar(); ardAlarmRadar.setTargetId(id); ardAlarmRadar.setName(alarmPointName); @@ -355,16 +364,16 @@ byte[] fTx = Arrays.copyOfRange(data, index + 12, index + 16); fTx = ByteUtils.toLittleEndian(fTx); float fTxAngle = ByteUtils.bytesToFloat(fTx); - //log.info("p瑙掑害:" + fTxAngle); + log.debug("p瑙掑害:" + fTxAngle); byte[] fTy = Arrays.copyOfRange(data, index + 16, index + 20); fTy = ByteUtils.toLittleEndian(fTy); float fTyAngle = ByteUtils.bytesToFloat(fTy); - //log.info("t瑙掑害:" + fTyAngle); + log.debug("t瑙掑害:" + fTyAngle); byte[] sAreaNo = Arrays.copyOfRange(data, index + 20, index + 22); sAreaNo = ByteUtils.toLittleEndian(sAreaNo); int AreaNo = ByteUtils.bytesToDecimal(sAreaNo); - //log.info("鐩爣褰掑睘鐨勫憡璀﹀尯鍩熷彿:" + AreaNo); + log.debug("鐩爣褰掑睘鐨勫憡璀﹀尯鍩熷彿:" + AreaNo); byte[] cGrp = Arrays.copyOfRange(data, index + 22, index + 23); cGrp = ByteUtils.toLittleEndian(cGrp); @@ -391,7 +400,7 @@ //log.info("鎵�灞炲憡璀﹀尯鍩熷悕绉�:" + DatatypeConverter.printHexBinary(szName)); String alarmPointName = ByteUtils.bytesToStringZh(szName); // log.info("鎵�灞炲憡璀﹀尯鍩熷悕绉�:" + alarmPointName); - //log.info("鎶ヨ淇℃伅锛�" + "銆恑d銆�" + id + "銆恘ame銆�" + alarmPointName + "銆恆larmType銆�" + alarmType + "銆恆larmTime銆�" + alarmTime); + log.debug("鎶ヨ淇℃伅锛�" + "銆恑d銆�" + id + "銆恘ame銆�" + alarmPointName + "銆恆larmType銆�" + alarmType + "銆恆larmTime銆�" + alarmTime); ArdAlarmRadar ardAlarmRadar = new ArdAlarmRadar(); ardAlarmRadar.setTargetId(id); ardAlarmRadar.setName(alarmPointName); -- Gitblit v1.9.3