| | |
| | | package com.dji.sample.control.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.dji.sample.common.model.ResponseResult; |
| | | import com.dji.sample.component.mqtt.config.MqttConfiguration; |
| | | import com.dji.sample.component.mqtt.model.*; |
| | |
| | | import com.dji.sample.control.service.IControlService; |
| | | import com.dji.sample.control.service.IDrcService; |
| | | import com.dji.sample.manage.model.dto.DeviceDTO; |
| | | import com.dji.sample.manage.model.enums.DockDrcStateEnum; |
| | | import com.dji.sample.manage.model.enums.DockModeCodeEnum; |
| | | import com.dji.sample.manage.model.enums.UserTypeEnum; |
| | | import com.dji.sample.manage.model.receiver.OsdSubDeviceReceiver; |
| | |
| | | import com.dji.sample.wayline.model.dto.WaylineTaskProgressReceiver; |
| | | import com.dji.sample.wayline.model.enums.WaylineJobStatusEnum; |
| | | import com.dji.sample.wayline.model.enums.WaylineTaskStatusEnum; |
| | | import com.dji.sample.wayline.model.param.PointPOJO; |
| | | import com.dji.sample.wayline.model.param.UpdateJobParam; |
| | | import com.dji.sample.wayline.service.IWaylineJobService; |
| | | import com.dji.sample.wayline.service.IWaylineRedisService; |
| | |
| | | |
| | | @Autowired |
| | | private IDeviceService deviceService; |
| | | |
| | | |
| | | @Autowired |
| | | private ObjectMapper mapper; |
| | | |
| | | |
| | | @Autowired |
| | | private ISendMessageService webSocketMessageService; |
| | | |
| | |
| | | if (dockOpt.isPresent() && (DockModeCodeEnum.IDLE == dockMode || DockModeCodeEnum.WORKING == dockMode)) { |
| | | Optional<OsdSubDeviceReceiver> deviceOsd = deviceRedisService.getDeviceOsd(dockOpt.get().getChildDeviceSn(), OsdSubDeviceReceiver.class); |
| | | if (deviceOsd.isEmpty() || deviceOsd.get().getElevation() <= 0) { |
| | | throw new RuntimeException("The drone is not in the sky and cannot enter command flight mode."); |
| | | throw new RuntimeException("无人机不在空中,不能进入指挥飞行模式。"); |
| | | } |
| | | } else { |
| | | throw new RuntimeException("The current state of the dock does not support entering command flight mode."); |
| | | throw new RuntimeException("当前状态不支持进入命令飞行模式。"); |
| | | } |
| | | |
| | | ResponseResult result = controlService.seizeAuthority(dockSn, DroneAuthorityEnum.FLIGHT, null); |
| | |
| | | String pubTopic = topic + TopicConst.DOWN; |
| | | String subTopic = topic + TopicConst.UP; |
| | | |
| | | // If the dock is in drc mode, refresh the permissions directly. |
| | | // If the dock is in drc mode, refresh the permissions directly. 如果dock处于drc模式,直接刷新权限 |
| | | if (deviceService.checkDockDrcMode(param.getDockSn()) |
| | | && param.getClientId().equals(this.getDrcModeInRedis(param.getDockSn()))) { |
| | | refreshAcl(param.getDockSn(), param.getClientId(), topic, subTopic); |
| | |
| | | .build()); |
| | | |
| | | if (ResponseResult.CODE_SUCCESS != reply.getResult()) { |
| | | throw new RuntimeException("SN: " + param.getDockSn() + "; Error Code:" + reply.getResult() + "; Failed to enter command flight control mode, please try again later!"); |
| | | throw new RuntimeException("SN: " + param.getDockSn() + "; Error Code:" + reply.getResult() + "; 进入命令飞行控制模式失败,请稍后再试!"); |
| | | } |
| | | |
| | | refreshAcl(param.getDockSn(), param.getClientId(), pubTopic, subTopic); |
| | |
| | | @Override |
| | | public void deviceDrcExit(String workspaceId, DrcModeParam param) { |
| | | if (!deviceService.checkDockDrcMode(param.getDockSn())) { |
| | | throw new RuntimeException("The dock is not in flight control mode."); |
| | | throw new RuntimeException("机场没有进入飞行控制模式"); |
| | | } |
| | | ServiceReply reply = messageSenderService.publishServicesTopic( |
| | | param.getDockSn(), DrcMethodEnum.DRC_MODE_EXIT.getMethod(), ""); |
| | | if (ResponseResult.CODE_SUCCESS != reply.getResult()) { |
| | | throw new RuntimeException("SN: " + param.getDockSn() + "; Error Code:" + |
| | | reply.getResult() + "; Failed to exit command flight control mode, please try again later!"); |
| | | reply.getResult() + "; 命令飞行控制模式退出失败,请稍后再试!"); |
| | | } |
| | | |
| | | String jobId = waylineRedisService.getPausedWaylineJobId(param.getDockSn()); |
| | |
| | | } |
| | | |
| | | @ServiceActivator(inputChannel = ChannelName.INBOUND_EVENTS_DRC_STATUS_NOTIFY, outputChannel = ChannelName.OUTBOUND_EVENTS) |
| | | public CommonTopicReceiver handleDrcStatusNotify(CommonTopicReceiver receiver, MessageHeaders headers) { |
| | | public CommonTopicReceiver handleDrcStatusNotify(CommonTopicReceiver receiver, MessageHeaders headers) throws Exception { |
| | | String dockSn = receiver.getGateway(); |
| | | |
| | | Optional<DeviceDTO> deviceOpt = deviceRedisService.getDeviceOnline(dockSn); |
| | |
| | | .message(eventsReceiver.getResult().getErrorMsg()) |
| | | .result(eventsReceiver.getResult().getErrorCode()).build()); |
| | | } |
| | | |
| | | //当进入控制时,停止当前的图斑飞行 |
| | | if (eventsReceiver.getDrcState()==DockDrcStateEnum.CONNECTED){ |
| | | JSONObject jsonObject = (JSONObject) RedisOpsUtils.get("tuban:" + dockSn); |
| | | if (jsonObject != null) { |
| | | controlService.flyToPointStop(dockSn); |
| | | } |
| | | } |
| | | |
| | | //当退出控制后,继续执行图斑飞行 |
| | | if(eventsReceiver.getDrcState() == DockDrcStateEnum.DISCONNECTED){ |
| | | JSONObject jsonObject = (JSONObject) RedisOpsUtils.get("tuban:" + dockSn); |
| | | if (jsonObject != null) { |
| | | List<PointPOJO> targetList = (List<PointPOJO>) jsonObject.get("targetList"); |
| | | int curIndex = (Integer) jsonObject.get("curIndex"); |
| | | String payloadIndex = jsonObject.getString("payloadIndex"); |
| | | controlService.flyToNextPoint(targetList, curIndex, dockSn, payloadIndex); |
| | | } |
| | | } |
| | | |
| | | return receiver; |
| | | } |
| | | |