From 165befbfdc284f873a7ab266dee772f957787947 Mon Sep 17 00:00:00 2001
From: ‘liusuyi’ <1951119284@qq.com>
Date: Sat, 16 Sep 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数组转Double
*/
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方法将长整型转换为Double类型
- return Double.longBitsToDouble(longBits);
+ // 创建一个ByteBuffer并设置字节顺序为大端
+ ByteBuffer buffer = ByteBuffer.wrap(byteArray);
+ buffer.order(ByteOrder.LITTLE_ENDIAN);
+ // 从ByteBuffer中获取double值
+ 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点坐标,长度和Y轴角度计算B点坐标
*/
- 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);
+ // 使用正弦函数计算对边长度
+ Distance = Math.sin(thetaRadians) * Distance;
+ log.debug("目标投影距离(m):" + Distance);
+
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]);
+ log.debug("报警信息:" + "【id】" + id + "【name】" + alarmPointName + "【alarmType】" + alarmType + "【alarmTime】" + alarmTime + "【distance】" + Distance + "【P】" + fTx + "【T】" + fTy + "【X】" + alarmXY[0] + "【Y】" + 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("报警信息:" + "【id】" + id + "【name】" + alarmPointName + "【alarmType】" + alarmType + "【alarmTime】" + alarmTime);
+ log.debug("报警信息:" + "【id】" + id + "【name】" + alarmPointName + "【alarmType】" + alarmType + "【alarmTime】" + alarmTime);
ArdAlarmRadar ardAlarmRadar = new ArdAlarmRadar();
ardAlarmRadar.setTargetId(id);
ardAlarmRadar.setName(alarmPointName);
--
Gitblit v1.9.3