浏览代码

按照开发新的发送协议修改发送逻辑

allen 1 周之前
父节点
当前提交
628cc30c1c

+ 1 - 1
sql/update20250415.sql

@@ -4,7 +4,7 @@ CREATE TABLE `uavps_task`  (
   `biz_name` varchar(127) COMMENT '任务名称',
   `biz_type` varchar(7) COMMENT '业务类型(start:开始,change:队形转换,disappear:消失出现)',
   `multi_target` varchar(7) COMMENT '多目标类型',
-  `nose_type` varchar(127) COMMENT '噪声类型',
+  `noise_type` varchar(127) COMMENT '噪声类型',
   `noise_variance` DECIMAL(10,6) COMMENT '噪声方差',
   `noise_mean` DECIMAL(12,6) COMMENT '噪声均值',
   `platform_uav_str` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci COMMENT '固定翼平台无人机数据',

+ 6 - 0
uavps-common/src/main/java/com/uavps/common/config/RuoYiConfig.java

@@ -116,4 +116,10 @@ public class RuoYiConfig {
     public static String getUploadPath() {
         return getProfile() + "/upload";
     }
+    /**
+     * 获取上传路径
+     */
+    public static String getTaskPath() {
+        return getProfile() + "/task";
+    }
 }

+ 14 - 0
uavps-framework/src/main/java/com/uavps/framework/FileUtils.java

@@ -0,0 +1,14 @@
+package com.uavps.framework;
+
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+public class FileUtils {
+    public static void addFileAndSave(String path, String message){
+
+    }
+    public static void addFileAndSave(FileOutputStream fos, byte[] message) throws IOException {
+        fos.write(message);
+        fos.flush();
+    }
+}

+ 41 - 3
uavps-framework/src/main/java/com/uavps/framework/udp/CoordinateSystem.java → uavps-framework/src/main/java/com/uavps/framework/udp/TaskInfo.java

@@ -1,6 +1,6 @@
 package com.uavps.framework.udp;
 
-public enum CoordinateSystem {
+public enum TaskInfo {
     // 枚举实例,包含初始化坐标和转化比率
     INSTANCE(0.0f, 0.0f, true, 1.0f);
 
@@ -10,9 +10,13 @@ public enum CoordinateSystem {
     private boolean initFlag;
     private float conversionRate;
     private final int initCenterPixel = 500;
+    private Long bizId;
+    private String filePath;
+    private Long lastTime = 0L;
+
 
     // 枚举构造函数
-    private CoordinateSystem(float x, float y, boolean initFlag, float conversionRate) {
+    private TaskInfo(float x, float y, boolean initFlag, float conversionRate) {
         this.x = x;
         this.y = y;
         this.initFlag = initFlag;
@@ -20,12 +24,14 @@ public enum CoordinateSystem {
     }
 
     // 重置方法
-    public void reset() {
+    public void reset(Long bizId, String filePath) {
         // 初始化
         this.x = 0f;
         this.y = 0f;
         this.initFlag = true;
         this.conversionRate = 0.00001f;
+        this.bizId = bizId;
+        this.filePath = filePath;
     }
 
     // Getter和Setter方法
@@ -70,6 +76,38 @@ public enum CoordinateSystem {
         return initCenterPixel * conversionRate;
     }
 
+    public Long getBizId() {
+        return bizId;
+    }
+
+    public void setBizId(Long bizId) {
+        this.bizId = bizId;
+    }
+
+    public String getFilePath() {
+        return filePath;
+    }
+
+    public void setFilePath(String filePath) {
+        this.filePath = filePath;
+    }
+
+    public boolean isInitFlag() {
+        return initFlag;
+    }
+
+    public int getInitCenterPixel() {
+        return initCenterPixel;
+    }
+
+    public Long getLastTime() {
+        return lastTime;
+    }
+
+    public void setLastTime(Long lastTime) {
+        this.lastTime = lastTime;
+    }
+
     // 显示坐标信息
     public void displayCoordinates() {
         System.out.printf("%s 坐标系 - X: %.2f, Y: %.2f (初始化标识: %s, 转化比率: %.6f)%n",

+ 3 - 7
uavps-framework/src/main/java/com/uavps/framework/udp/UdpClientService.java

@@ -60,16 +60,12 @@ public class UdpClientService {
             }
 
             // 发送结束包(序号为总块数,内容为 "END")
-            String endIndexStr = String.format("%04d", totalChunks);
+//            String endIndexStr = String.format("%04d", totalChunks);
             byte[] endDataBytes = "END".getBytes(StandardCharsets.UTF_8);
 
-            ByteArrayOutputStream endBaos = new ByteArrayOutputStream(BUFF_SIZE);
-            endBaos.write(endDataBytes);  // 写入 "END"
-
-            byte[] endPacketData = endBaos.toByteArray();
-            DatagramPacket endPacket = new DatagramPacket(endPacketData, endPacketData.length, address, PORT);
+            DatagramPacket endPacket = new DatagramPacket(endDataBytes, endDataBytes.length, address, PORT);
             socket.send(endPacket);
-            logger.info("Sent END chunk: {}", endIndexStr);
+            logger.info("Sent END chunk: {}", endDataBytes);
 
         } catch (IOException e) {
             logger.error("UdpClientService send error", e);

+ 87 - 91
uavps-framework/src/main/java/com/uavps/framework/udp/UdpServerService.java

@@ -1,9 +1,12 @@
 package com.uavps.framework.udp;
 
+import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.uavps.common.utils.spring.SpringUtils;
+import com.uavps.framework.FileUtils;
 import com.uavps.framework.config.UdpConfig;
 import com.uavps.framework.udp.utils.UdpDataUtils;
+import com.uavps.framework.utils.UdpUtils;
 import com.uavps.system.service.IUavpsAircraftService;
 import com.uavps.system.udp.vo.Aircraft;
 import com.uavps.system.udp.vo.AircraftFormation;
@@ -13,9 +16,14 @@ import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Component;
 
 import javax.websocket.Session;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.net.DatagramPacket;
 import java.net.DatagramSocket;
+import java.net.SocketException;
+import java.util.Date;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
 
 
 /**
@@ -34,118 +42,106 @@ public class UdpServerService {
 
     private IUavpsAircraftService uavpsAircraftService = SpringUtils.getBean(IUavpsAircraftService.class);
 
-    /*public void receive(Session session) {
+    private static final DatagramSocket INSTANCE;
+
+    static {
         try {
-            //创建一个服务端对象,注册端口
-            DatagramSocket socket = new DatagramSocket(udpConfig.getPort());
+            Integer port = SpringUtils.getBean(UdpConfig.class).getPort();
+            INSTANCE = new DatagramSocket(port);
+            log.info("UDP Server started on port:  {}", port);
+        } catch (SocketException e) {
+            throw new RuntimeException("Failed to start UDP server", e);
+        }
+    }
 
-            //创建一个数据包对象,用于接收数据,限制64kb
-            byte[] data = new byte[1024 * 64];
-            DatagramPacket packet = new DatagramPacket(data, data.length);
+    // 用于存储待写入的UDP包数据
+    private static final BlockingQueue<LogEntry> logQueue = new LinkedBlockingQueue<>();
 
-            String uavData = "";
-            boolean exit = false;
-            while (true) {
-                //使用数据包接收客户端发送的数据
-                socket.receive(packet);
-                uavData = new String(data, 0, packet.getLength());
-                //websocket 退出,关闭upd服务
-                if (uavData.length() == 4 && "EXIT".equals(uavData)) {
-                    socket.close();
-                    break;
-                }
-                JSONArray dataAry = JSON.parseArray(uavData);
-                if (dataAry != null) {
-                    UavpsAircraft uavpsAircraft = null;
-                    for (int i = 0; i < dataAry.size(); i++) {
-                        UdpData udpData = JSON.parseObject(dataAry.getString(i), UdpData.class);
-                        uavpsAircraft = new UavpsAircraft();
-                        uavpsAircraft.setBizId(udpData.getBizId());
-                        uavpsAircraft.setDataTime(BigDecimal.valueOf(udpData.getTime()));
-                        uavpsAircraft.setAircraftData(dataAry.getString(i));
-                        uavpsAircraft.setCreateBy("python");
-
-                        //入库
-                        //uavpsAircraftService.insertUavpsAircraft(uavpsAircraft);
-
-                        //数据发送页面展示
-                        session.getBasicRemote().sendText(dataAry.getString(i));
-                        Thread.sleep(20);
-
-                        //判断数据是否发送完毕
-                        if ("true".equals(udpData.getFinished())) {
-                            exit = true;
-                            break;
-                        }
-                    }
-                }
-                if (exit) {
-                    socket.close();
-                    break;
-                }
-            }
-        } catch (IOException | InterruptedException e) {
-            e.printStackTrace();
+    // 日志条目类
+    private static class LogEntry {
+        final byte[] data;
+        final int length;
+        final long time;
+
+        LogEntry(byte[] data, int length, long time) {
+            this.data = data;
+            this.length = length;
+            this.time = time;
         }
-    }*/
+    }
 
     public void receive(Session session) {
         try {
             //创建一个服务端对象,注册端口
-            DatagramSocket socket = new DatagramSocket(udpConfig.getPort());
             //创建一个数据包对象,用于接收数据
             byte[] data = new byte[1024];
             DatagramPacket packet = new DatagramPacket(data, data.length);
 
             String uavData = "";
-            int i = 0;
+            Date initDate = new Date();
+            String json = "";
             while (true) {
+                json = "";
+                // 设置初始时间,用于计算每个数据的时间差
+                if(TaskInfo.INSTANCE.getInitFlag()){
+                    initDate = new Date();
+                    log.info("任务Id:{},任务开始,开始时间是:{}", TaskInfo.INSTANCE.getBizId(), initDate);
+                }
+
                 //使用数据包接收客户端发送的数据
-                socket.receive(packet);
+                INSTANCE.receive(packet);
                 uavData = new String(data, 0, packet.getLength());
-                //websocket 退出,关闭upd服务
-                if (uavData.length() == 4 && "EXIT".equals(uavData)) {
-                    socket.close();
-                    break;
-                }
                 byte[] remoteData = UdpDataUtils.hexStringToBytes(uavData);
-                //byte[] remoteData = packet.getData();
-                if (remoteData != null && remoteData.length > 3) {
-                    UdpData udpData = UdpDataUtils.parseFrame(remoteData);
-                    //System.out.println(UdpDataUtils.bizId);
-                    if (udpData != null) {
-                        UdpDataUtils.time += 1;
-                        udpData.setTime(UdpDataUtils.time);
-                        if(udpData.getTargetAircraft() != null){
-                            for (AircraftFormation aircraftFormation : udpData.getTargetAircraft()) {
-                                for (Aircraft aircraft : aircraftFormation.getAircrafts()) {
-                                    if(CoordinateSystem.INSTANCE.getInitFlag()){
-                                        CoordinateSystem.INSTANCE.setX(aircraft.getCoordinateX() - CoordinateSystem.INSTANCE.getConversionCenterPixel());
-                                        CoordinateSystem.INSTANCE.setY(aircraft.getCoordinateY() - CoordinateSystem.INSTANCE.getConversionCenterPixel());
-                                        CoordinateSystem.INSTANCE.setInitFlag(false);
-                                    }
-                                    getNewXYAircraftCoordinate(aircraft);
-                                }
-                            }
-                        }
-                        ObjectMapper mapper = new ObjectMapper();
-                        String json = mapper.writeValueAsString(udpData);
-                        session.getBasicRemote().sendText(json);
-                        //System.out.println(json);
-                    }
-//                    log.info("loop:"+(i++)+":"+udpData.getTargetAircraftsString());
-                }
+                // 将日志条目放入队列
+                // 复制数据以避免后续修改影响
+                int length = remoteData.length;
+                byte[] dataCopy = new byte[length];
+                System.arraycopy(remoteData, 0, dataCopy, 0, length);
+                long lastTime = new Date().getTime() - initDate.getTime();
+                logQueue.add(new LogEntry(dataCopy, length, lastTime));
+                TaskInfo.INSTANCE.setLastTime(lastTime);
+                session.getBasicRemote().sendText(UdpUtils.getJson(remoteData));
             }
         } catch (IOException e) {
-            e.printStackTrace();
+            log.error("UdpServerService.receive error", e);
+            throw new RuntimeException(e);
         }
     }
 
-    private void getNewXYAircraftCoordinate(Aircraft aircraft) {
-        aircraft.setCoordinateOX(aircraft.getCoordinateX());
-        aircraft.setCoordinateOY(aircraft.getCoordinateY());
-        aircraft.setCoordinateOZ(aircraft.getCoordinateZ());
-        aircraft.setCoordinateX((aircraft.getCoordinateX()-CoordinateSystem.INSTANCE.getX())/CoordinateSystem.INSTANCE.getConversionRate());
-        aircraft.setCoordinateY((aircraft.getCoordinateY()-CoordinateSystem.INSTANCE.getY())/CoordinateSystem.INSTANCE.getConversionRate());
+    // 文件写入线程
+    private static class FileWriterThread extends Thread {
+        private volatile boolean running = true;
+
+        @Override
+        public void run() {
+            try (FileOutputStream fos = new FileOutputStream(TaskInfo.INSTANCE.getFilePath(), true)) {
+                while (running || !logQueue.isEmpty()) {
+                    LogEntry entry = logQueue.take(); // 阻塞直到有数据
+
+                    // 格式化时间戳(10位数字 + 冒号)
+                    String timestamp = String.format("%010d:", entry.time);
+
+                    // 先写入时间戳
+                    fos.write(timestamp.getBytes());
+
+                    // 再写入实际数据
+                    fos.write(entry.data, 0, entry.length);
+
+                    // 可选: 每条记录后加换行
+                    fos.write('\n');
+
+                    fos.flush();
+                }
+            } catch (IOException | InterruptedException e) {
+                if (running) { // 仅在非正常关闭时打印错误
+                    System.err.println("File writer error: " + e.getMessage());
+                }
+            }
+        }
+
+        public void shutdown() {
+            running = false;
+            this.interrupt(); // 中断阻塞的take操作
+        }
     }
 }

+ 0 - 55
uavps-framework/src/main/java/com/uavps/framework/udp/UdpUtils.java

@@ -1,55 +0,0 @@
-package com.uavps.framework.udp;
-
-import com.uavps.common.utils.uuid.IdUtils;
-import com.uavps.system.udp.vo.TargetAircraft;
-import com.uavps.system.udp.vo.UdpInitParameter;
-import com.uavps.system.udp.vo.UnmannedAerialVehicle;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * @Author MBQ
- * @Date: 2025/1/15
- * @Description:
- * @Version: 1.0
- **/
-public class UdpUtils {
-    public UdpInitParameter initParameter() {
-        UdpInitParameter parameter = new UdpInitParameter();
-        parameter.setBizId(IdUtils.simpleUUID());
-        parameter.setRefreshRate("20");
-
-        UnmannedAerialVehicle unmannedAerialVehicle = new UnmannedAerialVehicle();
-        unmannedAerialVehicle.setInitialPositionX(135);
-        unmannedAerialVehicle.setInitialPositionY(175);
-        unmannedAerialVehicle.setInitialPositionZ(100);
-        unmannedAerialVehicle.setInitialSpeed(20.33f);
-        unmannedAerialVehicle.setInitialPoseX(2.33f);
-        unmannedAerialVehicle.setInitialPoseY(2.33f);
-        unmannedAerialVehicle.setInitialPoseZ(2.33f);
-        parameter.setUnmannedAerialVehicle(unmannedAerialVehicle);
-
-        TargetAircraft targetAircraft = new TargetAircraft();
-        targetAircraft.setAircraftType("固定翼无人机");
-        targetAircraft.setFormationAircraftCount(50);
-        targetAircraft.setLeadAircraftSpeed(11.20f);
-        targetAircraft.setInitialPositionX(100.00f);
-        targetAircraft.setInitialPositionY(100.00f);
-        targetAircraft.setInitialPositionZ(100.00f);
-        targetAircraft.setFlightPathType("直线");
-        targetAircraft.setPositionNoise(18.20f);
-        targetAircraft.setFormationShape("V");
-        targetAircraft.setFollowAircraftDistance(20.00f);
-
-        List<TargetAircraft> multiTargetFormation = new ArrayList<>();
-        multiTargetFormation.add(targetAircraft);
-
-        parameter.setMultiTargetFormation(multiTargetFormation);
-        return parameter;
-    }
-
-    public static void main(String[] args) {
-        System.out.printf(IdUtils.simpleUUID());
-    }
-}

+ 93 - 0
uavps-framework/src/main/java/com/uavps/framework/utils/UdpUtils.java

@@ -0,0 +1,93 @@
+package com.uavps.framework.utils;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.uavps.common.utils.uuid.IdUtils;
+import com.uavps.framework.udp.TaskInfo;
+import com.uavps.framework.udp.utils.UdpDataUtils;
+import com.uavps.system.udp.vo.*;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @Author MBQ
+ * @Date: 2025/1/15
+ * @Description:
+ * @Version: 1.0
+ **/
+public class UdpUtils {
+    public UdpInitParameter initParameter() {
+        UdpInitParameter parameter = new UdpInitParameter();
+        parameter.setBizId(IdUtils.simpleUUID());
+        parameter.setRefreshRate("20");
+
+        UnmannedAerialVehicle unmannedAerialVehicle = new UnmannedAerialVehicle();
+        unmannedAerialVehicle.setInitialPositionX(135);
+        unmannedAerialVehicle.setInitialPositionY(175);
+        unmannedAerialVehicle.setInitialPositionZ(100);
+        unmannedAerialVehicle.setInitialSpeed(20.33f);
+        unmannedAerialVehicle.setInitialPoseX(2.33f);
+        unmannedAerialVehicle.setInitialPoseY(2.33f);
+        unmannedAerialVehicle.setInitialPoseZ(2.33f);
+        parameter.setUnmannedAerialVehicle(unmannedAerialVehicle);
+
+        TargetAircraft targetAircraft = new TargetAircraft();
+        targetAircraft.setAircraftType("固定翼无人机");
+        targetAircraft.setFormationAircraftCount(50);
+        targetAircraft.setLeadAircraftSpeed(11.20f);
+        targetAircraft.setInitialPositionX(100.00f);
+        targetAircraft.setInitialPositionY(100.00f);
+        targetAircraft.setInitialPositionZ(100.00f);
+        targetAircraft.setFlightPathType("直线");
+        targetAircraft.setPositionNoise(18.20f);
+        targetAircraft.setFormationShape("V");
+        targetAircraft.setFollowAircraftDistance(20.00f);
+
+        List<TargetAircraft> multiTargetFormation = new ArrayList<>();
+        multiTargetFormation.add(targetAircraft);
+
+        parameter.setMultiTargetFormation(multiTargetFormation);
+        return parameter;
+    }
+
+    public static void main(String[] args) {
+        System.out.printf(IdUtils.simpleUUID());
+    }
+
+    public static String getJson(byte[] remoteData) throws JsonProcessingException {
+//        uavData = new String(data, 0, packet.getLength());
+        //byte[] remoteData = packet.getData();
+        String json = "";
+        if (remoteData != null && remoteData.length > 3) {
+            UdpData udpData = UdpDataUtils.parseFrame(remoteData);
+            if (udpData != null) {
+//                        UdpDataUtils.time += 1;
+//                        udpData.setTime(UdpDataUtils.time);
+                if(udpData.getTargetAircraft() != null){
+                    for (AircraftFormation aircraftFormation : udpData.getTargetAircraft()) {
+                        for (Aircraft aircraft : aircraftFormation.getAircrafts()) {
+                            if(TaskInfo.INSTANCE.getInitFlag()){
+                                TaskInfo.INSTANCE.setX(aircraft.getCoordinateX() - TaskInfo.INSTANCE.getConversionCenterPixel());
+                                TaskInfo.INSTANCE.setY(aircraft.getCoordinateY() - TaskInfo.INSTANCE.getConversionCenterPixel());
+                                TaskInfo.INSTANCE.setInitFlag(false);
+                            }
+                            getNewXYAircraftCoordinate(aircraft);
+                        }
+                    }
+                }
+                ObjectMapper mapper = new ObjectMapper();
+                json = mapper.writeValueAsString(udpData);
+            }
+        }
+        return json;
+    }
+
+    private static void getNewXYAircraftCoordinate(Aircraft aircraft) {
+        aircraft.setCoordinateOX(aircraft.getCoordinateX());
+        aircraft.setCoordinateOY(aircraft.getCoordinateY());
+        aircraft.setCoordinateOZ(aircraft.getCoordinateZ());
+        aircraft.setCoordinateX((aircraft.getCoordinateX()- TaskInfo.INSTANCE.getX())/ TaskInfo.INSTANCE.getConversionRate());
+        aircraft.setCoordinateY((aircraft.getCoordinateY()- TaskInfo.INSTANCE.getY())/ TaskInfo.INSTANCE.getConversionRate());
+    }
+}

+ 70 - 17
uavps-framework/src/main/java/com/uavps/framework/websocket/WebSocketServer.java

@@ -1,12 +1,16 @@
 package com.uavps.framework.websocket;
 
 import com.fasterxml.jackson.databind.ObjectMapper;
+import com.uavps.common.config.RuoYiConfig;
+import com.uavps.common.utils.StringUtils;
 import com.uavps.common.utils.spring.SpringUtils;
 import com.uavps.common.utils.uuid.IdUtils;
-import com.uavps.framework.udp.CoordinateSystem;
+import com.uavps.common.utils.uuid.Seq;
+import com.uavps.framework.udp.TaskInfo;
 import com.uavps.framework.udp.UdpClientService;
 import com.uavps.framework.udp.UdpServerService;
 import com.uavps.framework.udp.utils.UdpDataUtils;
+import com.uavps.framework.utils.UdpUtils;
 import com.uavps.system.domain.UavpsAircraft;
 import com.uavps.system.domain.UavpsTask;
 import com.uavps.system.service.IUavpsAircraftService;
@@ -19,12 +23,16 @@ import org.springframework.util.CollectionUtils;
 
 import javax.websocket.*;
 import javax.websocket.server.ServerEndpoint;
+import java.io.BufferedReader;
+import java.io.FileReader;
 import java.io.IOException;
 import java.net.DatagramPacket;
 import java.net.DatagramSocket;
 import java.net.InetAddress;
+import java.util.Date;
 import java.util.List;
 import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.TimeUnit;
 
 /**
  * websocket 消息处理
@@ -92,22 +100,42 @@ public class WebSocketServer {
         if (session != null) {
             try {
                 if (message.startsWith("REPLAY:")) {
+                    long baseTime = System.currentTimeMillis();
                     //重放,获取数据库轨迹数据
                     String bizId = message.substring(7);
-                    List<UavpsAircraft> dataList = uavpsAircraftService.selectUavpsAircraftByBizId(bizId);
-                    if (!CollectionUtils.isEmpty(dataList)) {
-                        for (UavpsAircraft data : dataList) {
-                            session.getBasicRemote().sendText(data.getAircraftData());
-                            Thread.sleep(20);
+                    UavpsTask uavpsTask = uavpsTaskService.selectUavpsTaskByBizId(Long.parseLong(bizId));
+                    String filePath = uavpsTask.getFilePath();
+                    try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
+                        String line;
+                        while ((line = reader.readLine()) != null) {
+                            // 解析时间戳和数据
+                            if (line.length() > 11 && line.charAt(10) == ':') {
+                                    long timestamp = Long.parseLong(line.substring(0, 10));
+                                    byte[] data = line.substring(11).getBytes();
+                                    String json = UdpUtils.getJson(data);
+                                    long currentTime = System.currentTimeMillis();
+                                    long targetTime = baseTime + timestamp;
+
+                                    // 计算需要等待的时间
+                                    long waitTime = targetTime - currentTime;
+
+                                    if (waitTime > 0) {
+                                        TimeUnit.MILLISECONDS.sleep(waitTime);
+                                    }
+                                    session.getBasicRemote().sendText(json);
+                            } else {
+                                System.err.println("Invalid line format: " + line);
+                            }
                         }
+                    } catch (IOException e) {
+                        log.error("File reading error id : {}", bizId, e);
                     }
                 } else if (message.startsWith("RUN:")) {
-                    // 初始化 坐标转换参数
-                    CoordinateSystem.INSTANCE.reset();
-
                     String paramId = message.substring(4);
 //                    UavpsAlgorithmParameter param = algorithmParameterService.selectUavpsAlgorithmParameterById(Long.parseLong(paramId));
-                    UavpsTask uavpsTask = uavpsTaskService.selectUavpsTaskByBizId(Long.parseLong(paramId));
+                    long bizId = Long.parseLong(paramId);
+
+                    UavpsTask uavpsTask = uavpsTaskService.selectUavpsTaskByBizId(bizId);
                     uavpsTask.setBizType(UavpsTask.START);
                     ObjectMapper mapper = new ObjectMapper();
                     String json = null;
@@ -117,15 +145,19 @@ public class WebSocketServer {
                     } catch (Exception e) {
                         logger.error("WebSocketServer.onMessage to json error", e);
                     }
-//                    String parameter = UdpDataUtils.initAlgorithmParams(param);
-
+                    String filePath = StringUtils.format("{}/{}/{}.{}", RuoYiConfig.getTaskPath(),
+                            bizId, Seq.getId(Seq.uploadSeqType), "txt");
+                    uavpsTask.setFilePath(filePath);
+                    uavpsTask.setStartTime(new Date());
+                    uavpsTask.setStatus(UavpsTask.RUNNING);
+                    uavpsTaskService.updateUavpsTask(uavpsTask);
+                    // 初始化 坐标转换参数
+                    TaskInfo.INSTANCE.reset(bizId, filePath);
                     assert json != null;
                     udpClientService.send(json);
-                    /*String str = "BB14030101010100B6EA5F459C96C9172B0001000200030015CD5B070000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001A01B";
-                    udpClientService.send(str);*/
-                    UdpDataUtils.bizId = IdUtils.simpleUUID();
+//                    UdpDataUtils.bizId = IdUtils.simpleUUID();
                 } else if (message.startsWith("TRANSFORMATION:")) {
-                    closeUdpServer();
+//                    closeUdpServer();
 
                     String param = message.substring(15);
                     String[] paramAry = param.split(",");
@@ -142,7 +174,7 @@ public class WebSocketServer {
                     }
                     assert json != null;
                     udpClientService.send(json);
-                    this.onOpen(session);
+//                    this.onOpen(session);
                 } else if (message.startsWith("DISAPPEAR:")) {
                     String param = message.substring(10);
                     String[] paramAry = param.split(",");
@@ -163,6 +195,7 @@ public class WebSocketServer {
                         logger.error("WebSocketServer.onMessage to json error", e);
                     }
                     assert json != null;
+                    udpClientService.send(json);
                 } else if (message.startsWith("SHOW:")) {
                     String param = message.substring(5);
                     String[] paramAry = param.split(",");
@@ -183,6 +216,26 @@ public class WebSocketServer {
                         logger.error("WebSocketServer.onMessage to json error", e);
                     }
                     assert json != null;
+                    udpClientService.send(json);
+                } else if (message.startsWith("END:")) {
+                    Long bizId = Long.parseLong(message.substring(5));
+                    UavpsTask uavpsTask = new UavpsTask();
+                    uavpsTask.setBizId(bizId);
+                    uavpsTask.setBizType(UavpsTask.END);
+                    ObjectMapper mapper = new ObjectMapper();
+                    String json = null;
+                    try {
+                        json = mapper.writeValueAsString(uavpsTask);
+                        logger.info("json :{}", json);
+                    } catch (Exception e) {
+                        logger.error("WebSocketServer.onMessage to json error", e);
+                    }
+                    assert json != null;
+                    udpClientService.send(json);
+                    uavpsTask = uavpsTaskService.selectUavpsTaskByBizId(bizId);
+                    uavpsTask.setEndTime(new Date());
+                    uavpsTask.setStatus(UavpsTask.COMPLETED);
+                    uavpsTaskService.updateUavpsTask(uavpsTask);
                 } else {
                     session.getBasicRemote().sendText(message);
                 }

+ 31 - 14
uavps-system/src/main/java/com/uavps/system/domain/UavpsTask.java

@@ -35,6 +35,15 @@ public class UavpsTask extends BaseEntity
     public static final String CHANGE = "change";
     public static final String DISAPPEAR = "disappear";
     public static final String SHOW = "show";
+    public static final String END = "end";
+    // 未开始
+    public static final String NOT_STARTED = "0";
+    // 进行中
+    public static final String RUNNING = "1";
+    // 已完成
+    public static final String COMPLETED = "2";
+    // 失败
+    public static final String FAILED = "3";
 
     /** 业务ID */
     private Long bizId;
@@ -50,7 +59,7 @@ public class UavpsTask extends BaseEntity
     private String multiTarget;
 
     /** 噪声类型 */
-    private String noseType;
+    private String noiseType;
 
     /** 噪声方差 */
     private BigDecimal noiseVariance;
@@ -75,13 +84,13 @@ public class UavpsTask extends BaseEntity
     private String status;
 
     /** 开始时间 */
-    @JsonFormat(pattern = "yyyy-MM-dd")
-    @Excel(name = "开始时间", width = 30, dateFormat = "yyyy-MM-dd")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @Excel(name = "开始时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
     private Date startTime;
 
     /** 结束时间 */
-    @JsonFormat(pattern = "yyyy-MM-dd")
-    @Excel(name = "结束时间", width = 30, dateFormat = "yyyy-MM-dd")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @Excel(name = "结束时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm:ss")
     private Date endTime;
 
     /** 噪声数据文件路径 */
@@ -134,30 +143,30 @@ public class UavpsTask extends BaseEntity
     {
         return multiTarget;
     }
-    public void setNoseType(String noseType) 
+    public void setNoiseType(String noiseType)
     {
-        this.noseType = noseType;
+        this.noiseType = noiseType;
     }
 
-    public String getNoseType() 
+    public String getNoiseType()
     {
-        return noseType;
+        return noiseType;
     }
-    public void setNoiseVariance(BigDecimal noiseVariance) 
+    public void setNoiseVariance(BigDecimal noiseVariance)
     {
         this.noiseVariance = noiseVariance;
     }
 
-    public BigDecimal getNoiseVariance() 
+    public BigDecimal getNoiseVariance()
     {
         return noiseVariance;
     }
-    public void setNoiseMean(BigDecimal noiseMean) 
+    public void setNoiseMean(BigDecimal noiseMean)
     {
         this.noiseMean = noiseMean;
     }
 
-    public BigDecimal getNoiseMean() 
+    public BigDecimal getNoiseMean()
     {
         return noiseMean;
     }
@@ -309,6 +318,14 @@ public class UavpsTask extends BaseEntity
         this.numbers = numbers;
     }
 
+    public Long getTotalDuration() {
+        if (COMPLETED.equals(this.status) && startTime != null && endTime != null) {
+            return endTime.getTime() - startTime.getTime();
+        } else {
+            return null;
+        }
+    }
+
     @Override
     public String toString() {
         return "UavpsTask{" +
@@ -316,7 +333,7 @@ public class UavpsTask extends BaseEntity
                 ", bizName='" + bizName + '\'' +
                 ", bizType='" + bizType + '\'' +
                 ", multiTarget='" + multiTarget + '\'' +
-                ", noseType='" + noseType + '\'' +
+                ", noiseType='" + noiseType + '\'' +
                 ", noiseVariance=" + noiseVariance +
                 ", noiseMean=" + noiseMean +
                 ", platformUavStr='" + platformUavStr + '\'' +

+ 5 - 5
uavps-system/src/main/resources/mapper/system/UavpsTaskMapper.xml

@@ -9,7 +9,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
         <result property="bizName"    column="biz_name"    />
         <result property="bizType"    column="biz_type"    />
         <result property="multiTarget"    column="multi_target"    />
-        <result property="noseType"    column="nose_type"    />
+        <result property="noiseType"    column="noise_type"    />
         <result property="noiseVariance"    column="noise_variance"    />
         <result property="noiseMean"    column="noise_mean"    />
         <result property="platformUavStr"    column="platform_uav_str"    />
@@ -26,7 +26,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     </resultMap>
 
     <sql id="selectUavpsTaskVo">
-        select biz_id, biz_name, biz_type, multi_target, nose_type, noise_variance, noise_mean, platform_uav_str, fixed_multi_target_formation_str, customized_multi_target_formation_str, status, start_time, end_time, file_path, create_by, create_time, update_by, update_time from uavps_task
+        select biz_id, biz_name, biz_type, multi_target, noise_type, noise_variance, noise_mean, platform_uav_str, fixed_multi_target_formation_str, customized_multi_target_formation_str, status, start_time, end_time, file_path, create_by, create_time, update_by, update_time from uavps_task
     </sql>
 
     <select id="selectUavpsTaskList" parameterType="UavpsTask" resultMap="UavpsTaskResult">
@@ -51,7 +51,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="bizName != null">biz_name,</if>
             <if test="bizType != null">biz_type,</if>
             <if test="multiTarget != null">multi_target,</if>
-            <if test="noseType != null">nose_type,</if>
+            <if test="noiseType != null">noise_type,</if>
             <if test="noiseVariance != null">noise_variance,</if>
             <if test="noiseMean != null">noise_mean,</if>
             <if test="platformUavStr != null">platform_uav_str,</if>
@@ -70,7 +70,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="bizName != null">#{bizName},</if>
             <if test="bizType != null">#{bizType},</if>
             <if test="multiTarget != null">#{multiTarget},</if>
-            <if test="noseType != null">#{noseType},</if>
+            <if test="noiseType != null">#{noiseType},</if>
             <if test="noiseVariance != null">#{noiseVariance},</if>
             <if test="noiseMean != null">#{noiseMean},</if>
             <if test="platformUavStr != null">#{platformUavStr},</if>
@@ -93,7 +93,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="bizName != null">biz_name = #{bizName},</if>
             <if test="bizType != null">biz_type = #{bizType},</if>
             <if test="multiTarget != null">multi_target = #{multiTarget},</if>
-            <if test="noseType != null">nose_type = #{noseType},</if>
+            <if test="noiseType != null">noise_type = #{noiseType},</if>
             <if test="noiseVariance != null">noise_variance = #{noiseVariance},</if>
             <if test="noiseMean != null">noise_mean = #{noiseMean},</if>
             <if test="platformUavStr != null">platform_uav_str = #{platformUavStr},</if>

+ 69 - 5
uavps-web/src/views/system/task/index.vue

@@ -242,8 +242,8 @@
             ></el-option>
           </el-select>
         </el-form-item>
-        <el-form-item label="噪声类型" prop="noseType">
-          <el-select v-model="form.noseType" placeholder="请选择噪声类型">
+        <el-form-item label="噪声类型" prop="noiseType">
+          <el-select v-model="form.noiseType" placeholder="请选择噪声类型">
             <el-option
               v-for="dict in dict.type.uavps_task_nose_type"
               :key="dict.value"
@@ -272,7 +272,61 @@
       :fullscreen="true"
       append-to-body
       destroy-on-close
-    ></el-dialog>
+    >
+      <div class="container">
+        <div>
+          <el-row type="flex" align="middle" style="height: 40px">
+            <el-col :span="7">
+              <el-button @click="transFormation" type="danger"
+                >转换队形</el-button
+              >
+              <el-button @click="" type="success">回放</el-button>
+            </el-col>
+            <el-col :span="17">
+              <!--              <el-progress v-show="isShow" :percentage="percentage"></el-progress>-->
+            </el-col>
+          </el-row>
+          <el-row>
+            <div ref="pixiContainer" class="pixi-container"></div>
+          </el-row>
+        </div>
+        <!-- <div class="right-board">
+          <div style="float: right">
+            <el-link type="primary" @click="showConfig">显示配置</el-link>
+          </div>
+          <el-divider content-position="left">目标无人机群</el-divider>
+          <li v-for="(item, index) in targetLblAry" :key="index">
+            <div @click="showSprite(item.id)" style="cursor: pointer">
+              <span>编号:&nbsp;&nbsp;</span><label>{{ item.showNo }}</label>
+              <span style="margin-left: 10px" v-if="hideList.includes(item.id)"
+                >( 隐 藏 )</span
+              >
+            </div>
+            <div v-if="configList.includes('经度')">
+              <span>经度:&nbsp;&nbsp;</span><label>{{ item.longitude }}</label>
+            </div>
+            <div v-if="configList.includes('纬度')">
+              <span>纬度:&nbsp;&nbsp;</span><label>{{ item.latitude }}</label>
+            </div>
+            <div v-if="configList.includes('海拔')">
+              <span>海拔:&nbsp;&nbsp;</span><label>{{ item.altitude }}</label>
+            </div>
+            <div v-if="configList.includes('东向速度')">
+              <span>东向速度:&nbsp;&nbsp;</span
+              ><label>{{ item.eastSpeed }}</label>
+            </div>
+            <div v-if="configList.includes('北向速度')">
+              <span>北向速度:&nbsp;&nbsp;</span
+              ><label>{{ item.northSpeed }}</label>
+            </div>
+            <div v-if="configList.includes('天向速度')">
+              <span>天向速度:&nbsp;&nbsp;</span
+              ><label>{{ item.skySpeed }}</label>
+            </div>
+          </li>
+        </div> -->
+      </div>
+    </el-dialog>
   </div>
 </template>
 
@@ -364,7 +418,7 @@ export default {
         bizName: null,
         bizType: null,
         multiTarget: null,
-        noseType: null,
+        noiseType: null,
         noiseVariance: null,
         noiseMean: null,
         platformUavStr: null,
@@ -467,7 +521,6 @@ export default {
       const wsUri = "ws://127.0.0.1:8080/websocket/message";
       this.webSocket = new WebSocket(wsUri);
       const self = this;
-      debugger;
       this.webSocket.onopen = function (event) {
         self.webSocket.send("RUN:" + self.parameterId);
         console.log("WebSocket连接成功!");
@@ -492,6 +545,14 @@ export default {
         );
       };
     },
+    transFormation() {
+      // debugger;
+      let msg = "TRANSFORMATION:" + this.parameterId;
+      console.info("transFormation", msg);
+      this.webSocket.send(msg);
+      // this.pixiApp.stage.removeChildren();
+      // this.clearAllAry();
+    },
     destroyTrajectory() {
       if (this.webSocket) {
         this.webSocket.close();
@@ -501,6 +562,9 @@ export default {
     initTrajectory() {
       this.initWebSocket();
     },
+    processMessage(json) {
+      console.info(json);
+    },
   },
 };
 </script>