guoshilong
2023-11-15 55be62c63d9faedb48d47dd1c18cf1a74e3eea6c
src/main/java/com/dji/sample/control/service/impl/ControlServiceImpl.java
@@ -3,6 +3,7 @@
import com.alibaba.fastjson.JSONObject;
import com.dji.sample.common.error.CommonErrorEnum;
import com.dji.sample.common.model.ResponseResult;
import com.dji.sample.common.util.SpringBeanUtils;
import com.dji.sample.component.mqtt.model.*;
import com.dji.sample.component.mqtt.service.IMessageSenderService;
import com.dji.sample.component.redis.RedisConst;
@@ -13,10 +14,7 @@
import com.dji.sample.control.model.dto.PointDTO;
import com.dji.sample.control.model.dto.ResultNotifyDTO;
import com.dji.sample.control.model.dto.TakeoffProgressReceiver;
import com.dji.sample.control.model.enums.DroneAuthorityEnum;
import com.dji.sample.control.model.enums.DroneControlMethodEnum;
import com.dji.sample.control.model.enums.FlyToStatusEnum;
import com.dji.sample.control.model.enums.RemoteDebugMethodEnum;
import com.dji.sample.control.model.enums.*;
import com.dji.sample.control.model.param.*;
import com.dji.sample.control.service.IControlService;
import com.dji.sample.manage.model.dto.DeviceDTO;
@@ -189,7 +187,7 @@
    }
    @ServiceActivator(inputChannel = ChannelName.INBOUND_EVENTS_FLY_TO_POINT_PROGRESS, outputChannel = ChannelName.OUTBOUND_EVENTS)
    public CommonTopicReceiver handleFlyToPointProgress(CommonTopicReceiver receiver, MessageHeaders headers) {
    public CommonTopicReceiver handleFlyToPointProgress(CommonTopicReceiver receiver, MessageHeaders headers) throws Exception {
        String dockSn = receiver.getGateway();
        Optional<DeviceDTO> deviceOpt = deviceRedisService.getDeviceOnline(dockSn);
@@ -213,13 +211,14 @@
            if (jsonObject != null) {
                List<PointPOJO> targetList = (List<PointPOJO>) jsonObject.get("targetList");
                int curIndex = (Integer) jsonObject.get("curIndex");
                flyToNextPoint(targetList, curIndex, dockSn);
                String payloadIndex = jsonObject.getString("payloadIndex");
                flyToNextPoint(targetList, curIndex, dockSn, payloadIndex);
            }
        }
        return receiver;
    }
    private ResponseResult flyToNextPoint(List<PointPOJO> targetList, int curIndex, String sn) {
    private ResponseResult flyToNextPoint(List<PointPOJO> targetList, int curIndex, String sn, String payloadIndex) throws Exception {
        curIndex = curIndex + 1;
        //当无人机状态为人工时再发布下一个命令
        while (true) {
@@ -234,8 +233,7 @@
                    RedisOpsUtils.del("tuban:" + sn);
                    return returnHome;
                }
                else {
                } else {
                    //当前不是最后一个点,飞行到下一个点
                    FlyToPointParam flyToPointParam = new FlyToPointParam();
                    flyToPointParam.setMaxSpeed(14);
@@ -248,20 +246,65 @@
                    pointDTOS.add(pointDTO);
                    flyToPointParam.setPoints(pointDTOS);
                    //执行拍照
                    ResponseResult responseResult = takePhoto(sn, payloadIndex);
                    //发布下一个飞行指令
                    ResponseResult flyToRes = flyToPoint(sn, flyToPointParam);
                    if (flyToRes.getCode() == ResponseResult.CODE_SUCCESS) {
                        JSONObject jsonObject = new JSONObject();
                        jsonObject.put("targetList", targetList);
                        jsonObject.put("curIndex", curIndex);
                        jsonObject.put("payloadIndex",payloadIndex);
                        RedisOpsUtils.set("tuban:" + sn, jsonObject);
                    }
                    return flyToRes;
                }
            }
        }
    }
    @Override
    public ResponseResult takePhoto(String sn, String payloadIndex) throws Exception {
        //获取负载控制权
        DronePayloadParam dronePayloadParam = new DronePayloadParam();
        dronePayloadParam.setPayloadIndex(payloadIndex);
        ResponseResult seizeAuthorityRes = seizeAuthority(sn, DroneAuthorityEnum.PAYLOAD, dronePayloadParam);
        //切换为相机模式
        if (seizeAuthorityRes.getCode() != ResponseResult.CODE_SUCCESS) {
            return seizeAuthorityRes;
                }
            }
        }
        PayloadCommandsParam payloadCommandsParam = new PayloadCommandsParam();
//            DronePayloadParam switchParam = new DronePayloadParam();
//            switchParam.setCameraMode(CameraModeEnum.PHOTO);
//            switchParam.setPayloadIndex(payloadIndex);
//            payloadCommandsParam.setSn(sn);
//            payloadCommandsParam.setCmd(PayloadCommandsEnum.CAMERA_MODE_SWitCH);
//            payloadCommandsParam.setData(switchParam);
//
//            ResponseResult switchModeRes = payloadCommands(payloadCommandsParam);
//            if (switchModeRes.getCode() != ResponseResult.CODE_SUCCESS){
//                return  switchModeRes;
//            }
        //拍照
        payloadCommandsParam.setCmd(PayloadCommandsEnum.CAMERA_PHOTO_TAKE);
        DronePayloadParam takePhotoParam = new DronePayloadParam();
        takePhotoParam.setPayloadIndex(payloadIndex);
        payloadCommandsParam.setData(takePhotoParam);
        payloadCommandsParam.setSn(sn);
        ResponseResult responseResult = payloadCommands(payloadCommandsParam);
        return responseResult;
    }