|
@@ -1,12 +1,16 @@
|
|
package com.uavps.framework.websocket;
|
|
package com.uavps.framework.websocket;
|
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
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.spring.SpringUtils;
|
|
import com.uavps.common.utils.uuid.IdUtils;
|
|
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.UdpClientService;
|
|
import com.uavps.framework.udp.UdpServerService;
|
|
import com.uavps.framework.udp.UdpServerService;
|
|
import com.uavps.framework.udp.utils.UdpDataUtils;
|
|
import com.uavps.framework.udp.utils.UdpDataUtils;
|
|
|
|
+import com.uavps.framework.utils.UdpUtils;
|
|
import com.uavps.system.domain.UavpsAircraft;
|
|
import com.uavps.system.domain.UavpsAircraft;
|
|
import com.uavps.system.domain.UavpsTask;
|
|
import com.uavps.system.domain.UavpsTask;
|
|
import com.uavps.system.service.IUavpsAircraftService;
|
|
import com.uavps.system.service.IUavpsAircraftService;
|
|
@@ -19,12 +23,16 @@ import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import javax.websocket.*;
|
|
import javax.websocket.*;
|
|
import javax.websocket.server.ServerEndpoint;
|
|
import javax.websocket.server.ServerEndpoint;
|
|
|
|
+import java.io.BufferedReader;
|
|
|
|
+import java.io.FileReader;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.net.DatagramPacket;
|
|
import java.net.DatagramPacket;
|
|
import java.net.DatagramSocket;
|
|
import java.net.DatagramSocket;
|
|
import java.net.InetAddress;
|
|
import java.net.InetAddress;
|
|
|
|
+import java.util.Date;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.concurrent.CompletableFuture;
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
|
/**
|
|
* websocket 消息处理
|
|
* websocket 消息处理
|
|
@@ -92,22 +100,42 @@ public class WebSocketServer {
|
|
if (session != null) {
|
|
if (session != null) {
|
|
try {
|
|
try {
|
|
if (message.startsWith("REPLAY:")) {
|
|
if (message.startsWith("REPLAY:")) {
|
|
|
|
+ long baseTime = System.currentTimeMillis();
|
|
//重放,获取数据库轨迹数据
|
|
//重放,获取数据库轨迹数据
|
|
String bizId = message.substring(7);
|
|
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:")) {
|
|
} else if (message.startsWith("RUN:")) {
|
|
- // 初始化 坐标转换参数
|
|
|
|
- CoordinateSystem.INSTANCE.reset();
|
|
|
|
-
|
|
|
|
String paramId = message.substring(4);
|
|
String paramId = message.substring(4);
|
|
// UavpsAlgorithmParameter param = algorithmParameterService.selectUavpsAlgorithmParameterById(Long.parseLong(paramId));
|
|
// 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);
|
|
uavpsTask.setBizType(UavpsTask.START);
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
ObjectMapper mapper = new ObjectMapper();
|
|
String json = null;
|
|
String json = null;
|
|
@@ -117,15 +145,19 @@ public class WebSocketServer {
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
logger.error("WebSocketServer.onMessage to json error", 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;
|
|
assert json != null;
|
|
udpClientService.send(json);
|
|
udpClientService.send(json);
|
|
- /*String str = "BB14030101010100B6EA5F459C96C9172B0001000200030015CD5B070000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001A01B";
|
|
|
|
- udpClientService.send(str);*/
|
|
|
|
- UdpDataUtils.bizId = IdUtils.simpleUUID();
|
|
|
|
|
|
+// UdpDataUtils.bizId = IdUtils.simpleUUID();
|
|
} else if (message.startsWith("TRANSFORMATION:")) {
|
|
} else if (message.startsWith("TRANSFORMATION:")) {
|
|
- closeUdpServer();
|
|
|
|
|
|
+// closeUdpServer();
|
|
|
|
|
|
String param = message.substring(15);
|
|
String param = message.substring(15);
|
|
String[] paramAry = param.split(",");
|
|
String[] paramAry = param.split(",");
|
|
@@ -142,7 +174,7 @@ public class WebSocketServer {
|
|
}
|
|
}
|
|
assert json != null;
|
|
assert json != null;
|
|
udpClientService.send(json);
|
|
udpClientService.send(json);
|
|
- this.onOpen(session);
|
|
|
|
|
|
+// this.onOpen(session);
|
|
} else if (message.startsWith("DISAPPEAR:")) {
|
|
} else if (message.startsWith("DISAPPEAR:")) {
|
|
String param = message.substring(10);
|
|
String param = message.substring(10);
|
|
String[] paramAry = param.split(",");
|
|
String[] paramAry = param.split(",");
|
|
@@ -163,6 +195,7 @@ public class WebSocketServer {
|
|
logger.error("WebSocketServer.onMessage to json error", e);
|
|
logger.error("WebSocketServer.onMessage to json error", e);
|
|
}
|
|
}
|
|
assert json != null;
|
|
assert json != null;
|
|
|
|
+ udpClientService.send(json);
|
|
} else if (message.startsWith("SHOW:")) {
|
|
} else if (message.startsWith("SHOW:")) {
|
|
String param = message.substring(5);
|
|
String param = message.substring(5);
|
|
String[] paramAry = param.split(",");
|
|
String[] paramAry = param.split(",");
|
|
@@ -183,6 +216,26 @@ public class WebSocketServer {
|
|
logger.error("WebSocketServer.onMessage to json error", e);
|
|
logger.error("WebSocketServer.onMessage to json error", e);
|
|
}
|
|
}
|
|
assert json != null;
|
|
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 {
|
|
} else {
|
|
session.getBasicRemote().sendText(message);
|
|
session.getBasicRemote().sendText(message);
|
|
}
|
|
}
|