‘liusuyi’
2023-09-16 165befbfdc284f873a7ab266dee772f957787947
修复雷达报警投影距离
取消雷达坐标转84坐标
已修改3个文件
55 ■■■■ 文件已修改
src/main/java/com/ard/utils/other/ByteUtils.java 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ard/utils/other/GisUtils.java 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/ard/utils/tcp/ClientHandler.java 29 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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;
    }
    /**
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();
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);