|
|
@@ -1,10 +1,16 @@
|
|
|
package com.dji.sample.manage.service.impl;
|
|
|
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
+import com.dji.sample.component.mqtt.model.EventsReceiver;
|
|
|
import com.dji.sample.manage.model.dto.OsdDroneDTO;
|
|
|
import com.dji.sample.map.model.dto.FlightTrackDTO;
|
|
|
+import com.dji.sample.wayline.model.enums.WaylineJobStatusEnum;
|
|
|
+import com.dji.sample.wayline.service.IWaylineRedisService;
|
|
|
import com.dji.sdk.cloudapi.property.DockDroneCommanderFlightHeight;
|
|
|
+import com.dji.sdk.cloudapi.property.DockDroneCommanderModeLostAction;
|
|
|
import com.dji.sdk.cloudapi.property.DockDroneRthMode;
|
|
|
+import com.dji.sdk.cloudapi.wayline.FlighttaskProgress;
|
|
|
+import com.dji.sdk.cloudapi.wayline.FlighttaskProgressExt;
|
|
|
import com.dji.sdk.common.CoordinateUtil;
|
|
|
import com.dji.sample.common.util.UserRequest;
|
|
|
import com.dji.sample.component.websocket.model.BizCodeEnum;
|
|
|
@@ -77,6 +83,9 @@ public class SDKDeviceService extends AbstractDeviceService {
|
|
|
@Autowired
|
|
|
private IFlightTrackTaskService flightTaskService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IWaylineRedisService waylineRedisService;
|
|
|
+
|
|
|
@Override
|
|
|
public TopicStatusResponse<MqttReply> updateTopoOnline(TopicStatusRequest<UpdateTopo> request, MessageHeaders headers) {
|
|
|
UpdateTopoSubDevice updateTopoSubDevice = request.getData().getSubDevices().get(0);
|
|
|
@@ -201,7 +210,17 @@ public class SDKDeviceService extends AbstractDeviceService {
|
|
|
OsdDroneDTO data = toDroneDto(request.getData());
|
|
|
deviceService.pushOsdDataToWeb(device.getWorkspaceId(), BizCodeEnum.DEVICE_OSD, from, request.getData());
|
|
|
//添加航点轨迹信息
|
|
|
- toAddFilghtPoint(from, device, data);
|
|
|
+ String jobId = null;
|
|
|
+ Optional<EventsReceiver<FlighttaskProgress>> runningDataOpt = waylineRedisService.getRunningWaylineJob(request.getGateway());
|
|
|
+ if (runningDataOpt.isPresent()) {
|
|
|
+ log.info("======jobId getSn:" + runningDataOpt.map(EventsReceiver::getSn).get());
|
|
|
+ jobId = runningDataOpt.map(EventsReceiver::getOutput)
|
|
|
+ .map(FlighttaskProgress::getExt)
|
|
|
+ .map(FlighttaskProgressExt::getFlightId)
|
|
|
+ .orElse(null);
|
|
|
+ log.info("======FlightId:" + jobId);
|
|
|
+ }
|
|
|
+ toAddFilghtPoint(from, device, data,jobId);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -262,11 +281,11 @@ public class SDKDeviceService extends AbstractDeviceService {
|
|
|
.setVerticalSpeed(data.getVerticalSpeed()));
|
|
|
deviceService.pushOsdDataToWeb(device.getWorkspaceId(), BizCodeEnum.DEVICE_OSD, from, data);
|
|
|
//添加航点轨迹信息
|
|
|
- toAddFilghtPoint(from, device, data);
|
|
|
+ toAddFilghtPoint(from, device, data,null);
|
|
|
|
|
|
}
|
|
|
|
|
|
- private void toAddFilghtPoint(String from, DeviceDTO device, OsdDroneDTO data) {
|
|
|
+ private void toAddFilghtPoint(String from, DeviceDTO device, OsdDroneDTO data,String jobId) {
|
|
|
|
|
|
switch (data.getModeCode()) {
|
|
|
case TAKEOFF_FINISHED:
|
|
|
@@ -291,7 +310,7 @@ public class SDKDeviceService extends AbstractDeviceService {
|
|
|
flightTask = createFlightTask(device);
|
|
|
}
|
|
|
//添加飞行轨迹
|
|
|
- addFlightPoint(flightTask, device,data);
|
|
|
+ addFlightPoint(flightTask, device,data,false);
|
|
|
//推送实时轨迹信息
|
|
|
List<FlightTrackDTO> trackList = getRedisFlightPoint(flightTask,device,data);
|
|
|
pushFlyTrackToWeb(from,device,trackList);
|
|
|
@@ -309,7 +328,7 @@ public class SDKDeviceService extends AbstractDeviceService {
|
|
|
flightTask = opt.get();
|
|
|
log.info("==============飞机降落 执行添加飞行轨迹====:" + flightTask.toString());
|
|
|
//添加飞行轨迹
|
|
|
- FlightTaskDTO task = addFlightPoint(flightTask,device,data);
|
|
|
+ FlightTaskDTO task = addFlightPoint(flightTask,device,data,true);
|
|
|
log.info("==============飞机降落 更新飞行任务====:" + task.toString());
|
|
|
//更新飞行任务
|
|
|
updateFlightTask(task);
|
|
|
@@ -361,7 +380,7 @@ public class SDKDeviceService extends AbstractDeviceService {
|
|
|
deviceRedisService.setDroneFlyTrack(device.getDeviceSn(),flightPoints);
|
|
|
}
|
|
|
|
|
|
- private FlightTaskDTO addFlightPoint(FlightTaskDTO task, DeviceDTO device,OsdDroneDTO data) {
|
|
|
+ private FlightTaskDTO addFlightPoint(FlightTaskDTO task, DeviceDTO device,OsdDroneDTO data,boolean isFinished) {
|
|
|
synchronized (device.getDeviceSn().intern()) {
|
|
|
Optional<FlightTrackEntity> lastPoint = deviceRedisService.getLastDroneTrack(device.getDeviceSn());
|
|
|
long curTime = System.currentTimeMillis();
|
|
|
@@ -383,26 +402,18 @@ public class SDKDeviceService extends AbstractDeviceService {
|
|
|
+ ",飞行器状态:" + data.getModeCode().name() + ",经度:" + data.getLongitude() + ",维度:" + data.getLatitude()
|
|
|
+ "高度:" + data.getHeight());
|
|
|
}
|
|
|
- if(data.getModeCode().getCode() == 10) {
|
|
|
- isAdd = true;
|
|
|
- log.info("添加结束飞行轨迹: workspaceID:" + device.getWorkspaceId() + ",sn:" + device.getDeviceSn()
|
|
|
- + ",间隔时间(毫秒):" + btwTime + ",采集频率(秒)" + CustomConfiguration.frequency
|
|
|
- + ",飞行器状态:" + data.getModeCode().name() + ",经度:" + data.getLongitude() + ",维度:" + data.getLatitude()
|
|
|
- + "高度:" + data.getHeight());
|
|
|
- }
|
|
|
- if(isSamePoint(data,lastPoint.get())) {
|
|
|
+ if(isSamePoint(data,lastPoint.get()) || isEqualsPoint(data,lastPoint.get())) {
|
|
|
log.info("添加飞行轨迹:workspaceID:" + device.getWorkspaceId() + ",sn:" + device.getDeviceSn() +
|
|
|
"相同坐标,不做记录" + data.toString());
|
|
|
isAdd = false;
|
|
|
}
|
|
|
}
|
|
|
- if(isAdd) {
|
|
|
+ if(isAdd || isFinished) {
|
|
|
log.info("获取飞行轨迹任务:" + task.toString());
|
|
|
+ Optional<AMap> homeOpt = deviceRedisService.getDroneHomeChange(device.getDeviceSn());
|
|
|
//添加Home信息
|
|
|
- if(!lastPoint.isPresent()) {
|
|
|
- Optional<AMap> homeOpt = deviceRedisService.getDroneHomeChange(device.getDeviceSn());
|
|
|
- if(homeOpt.isPresent()) {
|
|
|
- FlightTrackEntity flightTrackEntity = FlightTrackEntity.builder()
|
|
|
+ if(!lastPoint.isPresent() && homeOpt.isPresent()) {
|
|
|
+ FlightTrackEntity flightTrackEntity = FlightTrackEntity.builder()
|
|
|
.taskId(task.getId())
|
|
|
.modeCode(data.getModeCode().getCode())
|
|
|
.longitude(CoordinateUtil.checkValidVal(homeOpt.get().getLongitude()))
|
|
|
@@ -410,17 +421,10 @@ public class SDKDeviceService extends AbstractDeviceService {
|
|
|
.type(FlightPointTypeEnum.HOME.getType())
|
|
|
.createTime(System.currentTimeMillis()).build();
|
|
|
flightTaskService.addHomePoint(flightTrackEntity);
|
|
|
- //记录添加时间
|
|
|
- deviceRedisService.setLastDroneTrack(device.getDeviceSn(), flightTrackEntity);
|
|
|
- }
|
|
|
- }
|
|
|
- if(!lastPoint.isPresent()) {
|
|
|
- return null;
|
|
|
}
|
|
|
- long btwTime = System.currentTimeMillis() - lastPoint.get().getCreateTime();
|
|
|
- if(btwTime >= CustomConfiguration.frequency * 1000 || 10 == data.getModeCode().getCode()) {
|
|
|
- //添加轨迹信息
|
|
|
- FlightTrackEntity flightTrackEntity = FlightTrackEntity.builder()
|
|
|
+
|
|
|
+ //添加轨迹信息
|
|
|
+ FlightTrackEntity flightTrackEntity = FlightTrackEntity.builder()
|
|
|
.taskId(task.getId())
|
|
|
.modeCode(data.getModeCode().getCode())
|
|
|
.longitude(data.getLongitude().doubleValue())
|
|
|
@@ -429,12 +433,11 @@ public class SDKDeviceService extends AbstractDeviceService {
|
|
|
.elevation(data.getElevation().doubleValue())
|
|
|
.type(FlightPointTypeEnum.HAND.getType())
|
|
|
.createTime(System.currentTimeMillis()).build();
|
|
|
- flightTaskService.addFlightPoint(flightTrackEntity);
|
|
|
- log.info("添加轨迹完成: task:" + task.getTaskName());
|
|
|
- //记录添加时间
|
|
|
- deviceRedisService.setLastDroneTrack(device.getDeviceSn(), flightTrackEntity);
|
|
|
- return task;
|
|
|
- }
|
|
|
+ flightTaskService.addFlightPoint(flightTrackEntity);
|
|
|
+ log.info("添加轨迹完成: task:" + task.getTaskName());
|
|
|
+ //记录添加时间
|
|
|
+ deviceRedisService.setLastDroneTrack(device.getDeviceSn(), flightTrackEntity);
|
|
|
+ return task;
|
|
|
|
|
|
}
|
|
|
return null;
|
|
|
@@ -449,6 +452,13 @@ public class SDKDeviceService extends AbstractDeviceService {
|
|
|
&& data.getElevation().doubleValue() == lastPoint.getElevation();
|
|
|
}
|
|
|
|
|
|
+ private boolean isEqualsPoint(OsdDroneDTO data,FlightTrackEntity lastPoint) {
|
|
|
+ return new BigDecimal(data.getLongitude().doubleValue()).compareTo(new BigDecimal(lastPoint.getLongitude().doubleValue())) == 0
|
|
|
+ && new BigDecimal(data.getLatitude().doubleValue()).compareTo(new BigDecimal(lastPoint.getLatitude())) == 0
|
|
|
+ && new BigDecimal(data.getHeight().doubleValue()).compareTo(new BigDecimal(lastPoint.getAltitude())) == 0
|
|
|
+ && new BigDecimal(data.getElevation().doubleValue() ).compareTo(new BigDecimal(lastPoint.getElevation())) == 0;
|
|
|
+ }
|
|
|
+
|
|
|
private int updateFlightTask(FlightTaskDTO task) {
|
|
|
if(task != null && task.getId() != null) {
|
|
|
log.info("飞行结束 更新轨迹任务: " + task.toString());
|
|
|
@@ -616,23 +626,47 @@ public class SDKDeviceService extends AbstractDeviceService {
|
|
|
@Override
|
|
|
public TopicStateResponse<MqttReply> dockDroneCurrentRthMode(TopicStateRequest<DockDroneCurrentRthMode> request, MessageHeaders headers) {
|
|
|
log.info("==========dockDroneCurrentRthMode=========request:"+ request.toString() + ",headers:" + headers.toString());
|
|
|
- return null;
|
|
|
+ return new TopicStateResponse<MqttReply>().setData(MqttReply.success());
|
|
|
}
|
|
|
@Override
|
|
|
public TopicStateResponse<MqttReply> dockDroneCurrentCommanderFlightMode(TopicStateRequest<DockDroneCurrentCommanderFlightMode> request, MessageHeaders headers) {
|
|
|
log.info("==========dockDroneCurrentCommanderFlightMode=========request:"+ request.toString() + ",headers:" + headers.toString());
|
|
|
- return null;
|
|
|
+ return new TopicStateResponse<MqttReply>().setData(MqttReply.success());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public TopicStateResponse<MqttReply> dockDroneCommanderFlightHeight(TopicStateRequest<DockDroneCommanderFlightHeight> request, MessageHeaders headers) {
|
|
|
log.info("==========dockDroneCommanderFlightHeight=========request:"+ request.toString() + ",headers:" + headers.toString());
|
|
|
- return null;
|
|
|
+ return new TopicStateResponse<MqttReply>().setData(MqttReply.success());
|
|
|
}
|
|
|
@Override
|
|
|
public TopicStateResponse<MqttReply> dockDroneRthMode(TopicStateRequest<DockDroneRthMode> request, MessageHeaders headers) {
|
|
|
log.info("==========dockDroneRthMode=========request:"+ request.toString() + ",headers:" + headers.toString());
|
|
|
- return null;
|
|
|
+ return new TopicStateResponse<MqttReply>().setData(MqttReply.success());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void dockWpmzVersionUpdate(TopicStateRequest<DockDroneWpmzVersion> request, MessageHeaders headers) {
|
|
|
+ log.info("==========dockWpmzVersionUpdate=========request:"+ request.toString() + ",headers:" + headers.toString());
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public void dockLiveStatusUpdate(TopicStateRequest<DockLiveStatus> request, MessageHeaders headers) {
|
|
|
+ log.info("==========dockLiveStatusUpdate=========request:"+ request.toString() + ",headers:" + headers.toString());
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public TopicStateResponse<MqttReply> dongleInfos(TopicStateRequest<DongleInfos> request, MessageHeaders headers) {
|
|
|
+ log.info("==========dongleInfos=========request:"+ request.toString() + ",headers:" + headers.toString());
|
|
|
+ return new TopicStateResponse<MqttReply>().setData(MqttReply.success());
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public TopicStateResponse<MqttReply> dockDroneCommanderModeLostAction(TopicStateRequest<DockDroneCommanderModeLostAction> request, MessageHeaders headers) {
|
|
|
+ log.info("==========dockDroneCommanderModeLostAction=========request:"+ request.toString() + ",headers:" + headers.toString());
|
|
|
+ return new TopicStateResponse<MqttReply>().setData(MqttReply.success());
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public TopicStateResponse<MqttReply> dockDroneModeCodeReason(TopicStateRequest<DockDroneModeCodeReason> request, MessageHeaders headers) {
|
|
|
+ log.info("==========dockDroneModeCodeReason=========request:"+ request.toString() + ",headers:" + headers.toString());
|
|
|
+ return new TopicStateResponse<MqttReply>().setData(MqttReply.success());
|
|
|
}
|
|
|
|
|
|
private void dockGoOnline(DeviceDTO gateway, DeviceDTO subDevice) {
|