From b8b5a3895e741d5348ecdd39ad2e5cbd443f8e89 Mon Sep 17 00:00:00 2001
From: zhaowenyu <35589726@qq.com>
Date: Wed, 01 Apr 2026 12:17:04 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev' into dev

---
 ard-work/src/main/java/com/ard/work/service/impl/TyServiceImpl.java |  159 +++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 137 insertions(+), 22 deletions(-)

diff --git a/ard-work/src/main/java/com/ard/work/service/impl/TyServiceImpl.java b/ard-work/src/main/java/com/ard/work/service/impl/TyServiceImpl.java
index 5908682..83e24dd 100644
--- a/ard-work/src/main/java/com/ard/work/service/impl/TyServiceImpl.java
+++ b/ard-work/src/main/java/com/ard/work/service/impl/TyServiceImpl.java
@@ -1,6 +1,7 @@
 package com.ard.work.service.impl;
 
 import com.ard.common.exception.ControlException;
+import com.ard.vtdu.config.MediamtxConfig;
 import com.ard.work.aspect.annotation.CheckControlRight;
 import com.ard.work.aspect.annotation.CheckDroneStatus;
 import com.ard.work.aspect.annotation.CheckNoFlyZone;
@@ -14,7 +15,7 @@
 import com.ard.work.component.netty.command.control.SpeedControlCmd;
 import com.ard.work.component.netty.command.manual.*;
 import com.ard.work.component.netty.command.notice.BoxPowerStatusReplyCmd;
-import com.ard.work.component.netty.command.notice.FlyWayEndReplyCmd;
+import com.ard.work.component.netty.command.notice.WayLineFinishedReplyCmd;
 import com.ard.work.component.netty.command.notice.UavReadyReplyCmd;
 import com.ard.work.component.netty.command.real.SignalInfoCmd;
 import com.ard.work.component.netty.command.real.UavStateCmd;
@@ -26,12 +27,14 @@
 import com.ard.work.component.netty.handler.ErrorCodeEnum;
 import com.ard.work.component.netty.protobuf.TelemetryDataPB;
 import com.ard.work.component.websocket.utils.WebSocketUtil;
+import com.ard.work.config.RouteStateMachineService;
 import com.ard.work.domain.cache.UavSignalInfoCache;
 import com.ard.work.domain.cache.UavStateCache;
 import com.ard.work.domain.cache.UavTelemetryDataCache;
 import com.ard.work.domain.dto.BoxHistoryDTO;
 import com.ard.work.domain.dto.BoxPhotosDTO;
 import com.ard.work.domain.dto.BoxSettingsDTO;
+import com.ard.work.domain.dto.BoxVideosDTO;
 import com.ard.work.domain.dto.camera.*;
 import com.ard.work.domain.dto.control.AbsAngleControlDTO;
 import com.ard.work.domain.dto.control.AngleControlDTO;
@@ -48,17 +51,21 @@
 import com.ard.work.domain.dto.wayline.*;
 import com.ard.work.domain.entity.ArdDroneInfo;
 import com.ard.work.domain.entity.ArdServerInfo;
+import com.ard.work.domain.enums.RouteEvent;
 import com.ard.work.domain.message.ServerReplyMessage;
 import com.ard.work.domain.message.UavControlType;
 import com.ard.work.domain.receiver.*;
 import com.ard.work.service.IArdDroneInfoService;
+import com.ard.work.service.IArdFlightTaskPartService;
 import com.ard.work.service.IArdServerInfoService;
 import com.ard.work.service.ITyService;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
 import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
@@ -77,7 +84,12 @@
     private IArdDroneInfoService ardDroneService;
     @Resource
     private TyClient tyClient;
-
+    @Autowired
+    private RouteStateMachineService stateMachineService;
+    @Autowired
+    private IArdFlightTaskPartService ardFlightTaskPartService;
+    @Resource
+    private MediamtxConfig mediamtxConfig;
     /**
      * 获取边缘服务器token信息
      *
@@ -123,8 +135,8 @@
         if (ardDroneInfo == null) {
             throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
         }
-        
-        
+
+
         TyHttpCommonReceiver<BoxStreamUrlReceiver> boxLiveUrl = tyClient.getBoxLiveUrl(ardDroneInfo.getServerId(),
                 boxSn);
         return boxLiveUrl == null ? null : boxLiveUrl.getContent();
@@ -148,7 +160,7 @@
     }
 
     /**
-     * 获取盒子图片
+     * 获取任务图片
      *
      * @return List<BoxPhotosReceiver>
      */
@@ -163,7 +175,22 @@
                 boxPhotosDTO);
         return boxPhotos == null ? null : boxPhotos.getContent();
     }
-
+    /**
+     * 获取任务视频
+     *
+     * @return List<BoxVideosReceiver>
+     */
+    @Override
+    public List<BoxVideosReceiver> getBoxVideos(BoxVideosDTO boxVideosDTO) {
+        String boxSn = boxVideosDTO.getBoxSn();
+        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
+        if (ardDroneInfo == null) {
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
+        TyHttpCommonReceiver<List<BoxVideosReceiver>> boxVideos = tyClient.getBoxVideos(ardDroneInfo.getServerId(),
+                boxVideosDTO);
+        return boxVideos == null ? null : boxVideos.getContent();
+    }
     /**
      * 修改云盒设置
      */
@@ -175,7 +202,7 @@
             throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
         }
         TyHttpCommonReceiver<?> result = tyClient.updateBoxSettings(ardDroneInfo.getServerId(), boxSettingsDTO);
-        return result.getState() == 1;
+        return result.getState() == 0;
     }
 
     /**
@@ -287,6 +314,18 @@
         return true;
     }
 
+    @Override
+    public Boolean formatSdCard(FormatSdCardDTO formatSdCardDTO) {
+        String boxSn = formatSdCardDTO.getBoxSn();
+        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
+        if (ardDroneInfo == null) {
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
+        FormatSdCardCmd formatSdCardCmd = new FormatSdCardCmd(formatSdCardDTO);
+        this.sendMessage(ardDroneInfo.getServerId(), formatSdCardCmd);
+        return true;
+    }
+
     /**
      * 设置相机模式
      */
@@ -315,9 +354,10 @@
             throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
         }
         //设置相机模式为拍照模式
-        updateCameraMode(CameraModeDTO.builder().boxSn(capturePicDto.getBoxSn()).actionParam((byte) 0x01).build());
+        //updateCameraMode(CameraModeDTO.builder().boxSn(capturePicDto.getBoxSn()).actionParam((byte) 0x01).build());
         //设置拍照回传
-        photoReturnToggle(PhotoReturnToggleDTO.builder().boxSn(capturePicDto.getBoxSn()).actionParam((byte) 0x01).build());
+        //photoReturnToggle(PhotoReturnToggleDTO.builder().boxSn(capturePicDto.getBoxSn()).actionParam((byte) 0x01)
+        // .build());
 
         CapturePicCmd capturePicCommand = new CapturePicCmd(capturePicDto);
         this.sendMessage(ardDroneInfo.getServerId(), capturePicCommand);
@@ -337,7 +377,7 @@
         }
         BaseCmd baseCmd;
         if (recordDto.getIsRecord()) {
-            updateCameraMode(CameraModeDTO.builder().boxSn(recordDto.getBoxSn()).actionParam((byte) 0x02).build());
+            //updateCameraMode(CameraModeDTO.builder().boxSn(recordDto.getBoxSn()).actionParam((byte) 0x02).build());
             baseCmd = new RecordStartCmd(recordDto);
         } else {
             baseCmd = new RecordStopCmd(recordDto);
@@ -542,7 +582,7 @@
      * 方向控制
      */
     @CheckControlRight(UavControlType.FLY)
-    @CheckTakeoffAltitude(minAltitude = 30.0)
+    @CheckTakeoffAltitude
     @Override
     public Boolean flyControl(FlyControlDTO flyControlDTO) {
         String boxSn = flyControlDTO.getBoxSn();
@@ -559,7 +599,7 @@
      * 指点飞行控制
      */
     @CheckControlRight(UavControlType.FLY)
-    @CheckTakeoffAltitude(minAltitude = 30.0)
+    @CheckTakeoffAltitude
     @CheckNoFlyZone
     @Override
     public Boolean flyPointControl(FlyPointControlDTO flyPointControlDTO) {
@@ -568,6 +608,10 @@
         if (ardDroneInfo == null) {
             throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
         }
+        //打点之前先停止打点
+        FlyPointControlCancelCmd flyPointControlCancelCmd = new FlyPointControlCancelCmd(FlyPointControlCancelDTO.builder().boxSn(boxSn).build());
+        this.sendMessage(ardDroneInfo.getServerId(), flyPointControlCancelCmd);
+
         FlyPointControlCmd flyPointControlCmd = new FlyPointControlCmd(flyPointControlDTO);
         this.sendMessage(ardDroneInfo.getServerId(), flyPointControlCmd);
         return true;
@@ -584,10 +628,44 @@
         if (ardDroneInfo == null) {
             throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
         }
-        
-        
+
+
         FlyPointControlCancelCmd flyPointControlCancelCmd = new FlyPointControlCancelCmd(flyPointControlCancelDTO);
         this.sendMessage(ardDroneInfo.getServerId(), flyPointControlCancelCmd);
+        return true;
+    }
+
+
+    /**
+     * 环绕飞行控制
+     */
+//    @CheckControlRight(UavControlType.FLY)
+//    @CheckTakeoffAltitude
+//    @CheckNoFlyZone
+    @Override
+    public Boolean FlyRoundControl(FlyRoundControlDTO flyRoundControlDTO) {
+        String boxSn = flyRoundControlDTO.getBoxSn();
+        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
+        if (ardDroneInfo == null) {
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
+        FlyRoundControlCmd flyRoundControlCmd = new FlyRoundControlCmd(flyRoundControlDTO);
+        this.sendMessage(ardDroneInfo.getServerId(), flyRoundControlCmd);
+        return true;
+    }
+
+    /**
+     * 停止环绕飞行控制
+     */
+    @Override
+    public Boolean FlyRoundControlCancel(FlyRoundControlCancelDTO flyRoundControlCancelDTO) {
+        String boxSn = flyRoundControlCancelDTO.getBoxSn();
+        ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
+        if (ardDroneInfo == null) {
+            throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+        }
+        FlyRoundControlCancelCmd flyRoundControlCancelCmd = new FlyRoundControlCancelCmd(flyRoundControlCancelDTO);
+        this.sendMessage(ardDroneInfo.getServerId(), flyRoundControlCancelCmd);
         return true;
     }
 
@@ -602,8 +680,8 @@
         if (ardDroneInfo == null) {
             throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
         }
-        
-        
+
+
         EmergencyBrakeCmd emergencyBrakeCmd = new EmergencyBrakeCmd(emeragencyBrakeDTO);
         this.sendMessage(ardDroneInfo.getServerId(), emergencyBrakeCmd);
         return true;
@@ -750,9 +828,8 @@
             throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
         }
         //wayLineUploadDTO.setWayLineData(this.CreatePlanLineData());//设置航线数据
-        System.out.println("wayLineUploadDTO:-----------------" + wayLineUploadDTO);
+        log.info("打印航线上传数据 ++++++++ wayLineUploadDTO:~~~~~~~~~~~~~~~" + wayLineUploadDTO);
         WayLineUploadCmd wayLineUploadCmd = new WayLineUploadCmd(wayLineUploadDTO);
-        System.out.println("wayLineUploadCmd:-----------------" + wayLineUploadCmd);
         this.sendMessage(ardDroneInfo.getServerId(), wayLineUploadCmd);
         return true;
     }
@@ -903,7 +980,8 @@
             case (byte) 0xA9:
                 // 处理无人机遥测消息
                 UavTelemetryDataCmd uavTelemetryDataCmd = (UavTelemetryDataCmd) tyCommand;
-                UavTelemetryDataCache.put(uavTelemetryDataCmd.getTelemetryData());
+                TelemetryData telemetryData = uavTelemetryDataCmd.getTelemetryData();
+                UavTelemetryDataCache.put(telemetryData);
                 //logPrint("无人机遥测", uavTelemetryDataCmd.getTelemetryData().getBoxSn());
                 //WebSocketUtil.sendMessageAll(uavTelemetryDataCmd.getTelemetryData());
                 break;
@@ -930,9 +1008,10 @@
                     CameraModeReplyCmd cameraModeReplyCommand = (CameraModeReplyCmd) tyCommand;
                     logPrint("无人机设置相机模式", cameraModeReplyCommand.getResult(), cameraModeReplyCommand.getErrorCode());
                 }
-                if (tyCommand instanceof FlyWayEndReplyCmd) {
-                    FlyWayEndReplyCmd flyWayEndReplyCmd = (FlyWayEndReplyCmd) tyCommand;
-                    logPrint("无人机飞行结束", flyWayEndReplyCmd.getResult(), flyWayEndReplyCmd.getErrorCode());
+                //格式化存储卡
+                if (tyCommand instanceof FormatSdCardReplyCmd) {
+                    FormatSdCardReplyCmd formatSdCardReplyCmd = (FormatSdCardReplyCmd) tyCommand;
+                    logPrint("格式化存储卡", formatSdCardReplyCmd.getResult(), formatSdCardReplyCmd.getErrorCode());
                 }
                 if (tyCommand instanceof CapturePicReplyCmd) {
                     CapturePicReplyCmd capturePicReplyCommand = (CapturePicReplyCmd) tyCommand;
@@ -994,23 +1073,53 @@
                 }
                 //开始航线回复
                 if (tyCommand instanceof WayLineBeginReplyCmd) {
+
                     WayLineBeginReplyCmd wayLineBeginReplyCmd = (WayLineBeginReplyCmd) tyCommand;
                     logPrint("开始航线", wayLineBeginReplyCmd.getResult(), wayLineBeginReplyCmd.getErrorCode());
+                    if (wayLineBeginReplyCmd.getResult() == 0) {
+                        byte[] boxSnBytes = tyCommand.getBoxSn();
+                        String boxSn = new String(boxSnBytes);
+                        stateMachineService.sendEvent(boxSn, RouteEvent.START_SUCCESS);
+                    }
                 }
                 //暂停航线回复
                 if (tyCommand instanceof WayLinePauseReplyCmd) {
                     WayLinePauseReplyCmd wayLinePauseReplyCmd = (WayLinePauseReplyCmd) tyCommand;
                     logPrint("暂停航线", wayLinePauseReplyCmd.getResult(), wayLinePauseReplyCmd.getErrorCode());
+                    if (wayLinePauseReplyCmd.getResult() == 0) {
+                        byte[] boxSnBytes = tyCommand.getBoxSn();
+                        String boxSn = new String(boxSnBytes);
+                        stateMachineService.sendEvent(boxSn, RouteEvent.PAUSE_SUCCESS);
+                    }
                 }
                 //恢复航线回复
                 if (tyCommand instanceof WayLineResumeReplyCmd) {
                     WayLineResumeReplyCmd wayLineResumeReplyCmd = (WayLineResumeReplyCmd) tyCommand;
                     logPrint("恢复航线", wayLineResumeReplyCmd.getResult(), wayLineResumeReplyCmd.getErrorCode());
+                    if (wayLineResumeReplyCmd.getResult() == 0) {
+                        byte[] boxSnBytes = tyCommand.getBoxSn();
+                        String boxSn = new String(boxSnBytes);
+                        stateMachineService.sendEvent(boxSn, RouteEvent.RESUME_SUCCESS);
+                    }
                 }
                 //结束航线回复
                 if (tyCommand instanceof WayLineEndReplyCmd) {
                     WayLineEndReplyCmd wayLineEndReplyCmd = (WayLineEndReplyCmd) tyCommand;
                     logPrint("结束航线", wayLineEndReplyCmd.getResult(), wayLineEndReplyCmd.getErrorCode());
+                    if (wayLineEndReplyCmd.getResult() == 0) {
+                        byte[] boxSnBytes = tyCommand.getBoxSn();
+                        String boxSn = new String(boxSnBytes);
+                        stateMachineService.sendEvent(boxSn, RouteEvent.STOP_SUCCESS);
+                    }
+                }
+                if (tyCommand instanceof WayLineFinishedReplyCmd) {
+                    WayLineFinishedReplyCmd wayLineFinishedReplyCmd = (WayLineFinishedReplyCmd) tyCommand;
+                    logPrint("航线执行完成", wayLineFinishedReplyCmd.getResult(), wayLineFinishedReplyCmd.getErrorCode());
+                    if (wayLineFinishedReplyCmd.getResult() == 0) {
+                        byte[] boxSnBytes = tyCommand.getBoxSn();
+                        String boxSn = new String(boxSnBytes);
+                        stateMachineService.sendEvent(boxSn, RouteEvent.RESET_ROUTE);
+                    }
                 }
                 //设置返航高度回复
                 if (tyCommand instanceof ReturnHeightSettingReplyCmd) {
@@ -1024,6 +1133,12 @@
                     logPrint("设置返航点", returnPointSettingReplyCmd.getResult(),
                             returnPointSettingReplyCmd.getErrorCode());
                 }
+                //到达环绕位置回复
+                if (tyCommand instanceof FlyRoundReplyCmd) {
+                    FlyRoundReplyCmd flyRoundReplyCmd = (FlyRoundReplyCmd) tyCommand;
+                    logPrint("到达环绕位置", flyRoundReplyCmd.getResult(),
+                            flyRoundReplyCmd.getErrorCode());
+                }
                 break;
             case (byte) 0xD2:
                 //设置视频码流回复

--
Gitblit v1.9.3