|
@@ -1,5 +1,6 @@
|
|
package com.uavps.framework.websocket;
|
|
package com.uavps.framework.websocket;
|
|
|
|
|
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
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.framework.udp.CoordinateSystem;
|
|
@@ -8,10 +9,13 @@ import com.uavps.framework.udp.UdpServerService;
|
|
import com.uavps.framework.udp.utils.UdpDataUtils;
|
|
import com.uavps.framework.udp.utils.UdpDataUtils;
|
|
import com.uavps.system.domain.UavpsAircraft;
|
|
import com.uavps.system.domain.UavpsAircraft;
|
|
import com.uavps.system.domain.UavpsAlgorithmParameter;
|
|
import com.uavps.system.domain.UavpsAlgorithmParameter;
|
|
|
|
+import com.uavps.system.domain.UavpsTask;
|
|
import com.uavps.system.service.IUavpsAircraftService;
|
|
import com.uavps.system.service.IUavpsAircraftService;
|
|
import com.uavps.system.service.IUavpsAlgorithmParameterService;
|
|
import com.uavps.system.service.IUavpsAlgorithmParameterService;
|
|
|
|
+import com.uavps.system.service.IUavpsTaskService;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.util.CollectionUtils;
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
@@ -37,6 +41,8 @@ import java.util.concurrent.CompletableFuture;
|
|
@Component
|
|
@Component
|
|
@ServerEndpoint("/websocket/message")
|
|
@ServerEndpoint("/websocket/message")
|
|
public class WebSocketServer {
|
|
public class WebSocketServer {
|
|
|
|
+
|
|
|
|
+ protected final Logger logger = LoggerFactory.getLogger(this.getClass());
|
|
private static final Logger log = LoggerFactory.getLogger(WebSocketServer.class);
|
|
private static final Logger log = LoggerFactory.getLogger(WebSocketServer.class);
|
|
|
|
|
|
UdpServerService udpServerService = new UdpServerService();
|
|
UdpServerService udpServerService = new UdpServerService();
|
|
@@ -47,6 +53,9 @@ public class WebSocketServer {
|
|
|
|
|
|
private IUavpsAlgorithmParameterService algorithmParameterService = SpringUtils.getBean(IUavpsAlgorithmParameterService.class);
|
|
private IUavpsAlgorithmParameterService algorithmParameterService = SpringUtils.getBean(IUavpsAlgorithmParameterService.class);
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private IUavpsTaskService uavpsTaskService;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 连接建立成功调用的方法
|
|
* 连接建立成功调用的方法
|
|
*/
|
|
*/
|
|
@@ -105,11 +114,21 @@ public class WebSocketServer {
|
|
CoordinateSystem.INSTANCE.reset();
|
|
CoordinateSystem.INSTANCE.reset();
|
|
|
|
|
|
String paramId = message.substring(4);
|
|
String paramId = message.substring(4);
|
|
- UavpsAlgorithmParameter param = algorithmParameterService.selectUavpsAlgorithmParameterById(Long.parseLong(paramId));
|
|
|
|
- String parameter = UdpDataUtils.initAlgorithmParams(param);
|
|
|
|
- System.out.println("parameter:====" + parameter);
|
|
|
|
- System.out.println("param.toString():====" + param);
|
|
|
|
- udpClientService.send(parameter);
|
|
|
|
|
|
+// UavpsAlgorithmParameter param = algorithmParameterService.selectUavpsAlgorithmParameterById(Long.parseLong(paramId));
|
|
|
|
+ UavpsTask uavpsTask = uavpsTaskService.selectUavpsTaskByBizId(Long.parseLong(paramId));
|
|
|
|
+ uavpsTask.setBizType(UavpsTask.START);
|
|
|
|
+ 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);
|
|
|
|
+ }
|
|
|
|
+// String parameter = UdpDataUtils.initAlgorithmParams(param);
|
|
|
|
+
|
|
|
|
+ assert json != null;
|
|
|
|
+ udpClientService.send(json);
|
|
/*String str = "BB14030101010100B6EA5F459C96C9172B0001000200030015CD5B070000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001A01B";
|
|
/*String str = "BB14030101010100B6EA5F459C96C9172B0001000200030015CD5B070000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001A01B";
|
|
udpClientService.send(str);*/
|
|
udpClientService.send(str);*/
|
|
UdpDataUtils.bizId = IdUtils.simpleUUID();
|
|
UdpDataUtils.bizId = IdUtils.simpleUUID();
|
|
@@ -118,22 +137,60 @@ public class WebSocketServer {
|
|
|
|
|
|
String param = message.substring(15);
|
|
String param = message.substring(15);
|
|
String[] paramAry = param.split(",");
|
|
String[] paramAry = param.split(",");
|
|
- UavpsAlgorithmParameter parameter = algorithmParameterService.selectUavpsAlgorithmParameterById(Long.parseLong(paramAry[0]));
|
|
|
|
- if(!"null".equals(paramAry[1])){
|
|
|
|
- parameter.setLongitude(new BigDecimal(paramAry[1]));
|
|
|
|
|
|
+ UavpsTask uavpsTask = new UavpsTask();
|
|
|
|
+ uavpsTask.setBizId(Long.parseLong(paramAry[0]));
|
|
|
|
+ uavpsTask.setBizType(UavpsTask.CHANGE);
|
|
|
|
+ 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);
|
|
|
|
+ this.onOpen(session);
|
|
|
|
+ } else if (message.startsWith("DISAPPEAR:")) {
|
|
|
|
+ String param = message.substring(10);
|
|
|
|
+ String[] paramAry = param.split(",");
|
|
|
|
+ UavpsTask uavpsTask = new UavpsTask();
|
|
|
|
+ uavpsTask.setBizId(Long.parseLong(paramAry[0]));
|
|
|
|
+ uavpsTask.setBizType(UavpsTask.DISAPPEAR);
|
|
|
|
+ for (int i = 0; i <= paramAry.length; i++) {
|
|
|
|
+ if (i != 0) {
|
|
|
|
+ uavpsTask.getNumbers().add(Integer.parseInt(paramAry[i]));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ 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);
|
|
}
|
|
}
|
|
- if(!"null".equals(paramAry[2])){
|
|
|
|
- parameter.setLatitude(new BigDecimal(paramAry[2]));
|
|
|
|
|
|
+ assert json != null;
|
|
|
|
+ } else if (message.startsWith("SHOW:")) {
|
|
|
|
+ String param = message.substring(5);
|
|
|
|
+ String[] paramAry = param.split(",");
|
|
|
|
+ UavpsTask uavpsTask = new UavpsTask();
|
|
|
|
+ uavpsTask.setBizId(Long.parseLong(paramAry[0]));
|
|
|
|
+ uavpsTask.setBizType(UavpsTask.SHOW);
|
|
|
|
+ for (int i = 0; i <= paramAry.length; i++) {
|
|
|
|
+ if (i != 0) {
|
|
|
|
+ uavpsTask.getNumbers().add(Integer.parseInt(paramAry[i]));
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- if(!"null".equals(paramAry[3])){
|
|
|
|
- parameter.setAltitude(Long.parseLong(paramAry[3]));
|
|
|
|
|
|
+ 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);
|
|
}
|
|
}
|
|
- String transParam = UdpDataUtils.initAlgorithmParams(parameter);
|
|
|
|
- System.out.println("transParam:====" + transParam);
|
|
|
|
- System.out.println("param.toString():====" + parameter);
|
|
|
|
- udpClientService.send(transParam);
|
|
|
|
- this.onOpen(session);
|
|
|
|
- //String str = "BB14030101010100B6EA5F459C96C9172B0001000200030015CD5B070000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001A01B";
|
|
|
|
|
|
+ assert json != null;
|
|
} else {
|
|
} else {
|
|
session.getBasicRemote().sendText(message);
|
|
session.getBasicRemote().sendText(message);
|
|
}
|
|
}
|