From b9f46001860bf194601b4bdf848545bfc72eefa5 Mon Sep 17 00:00:00 2001
From: liusuyi <1951119284@qq.com>
Date: Sat, 26 Oct 2024 16:59:35 +0800
Subject: [PATCH] 增加:返航

---
 ard-work/src/main/java/com/ard/tianyu/service/impl/TyServiceImpl.java |   48 ++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 46 insertions(+), 2 deletions(-)

diff --git a/ard-work/src/main/java/com/ard/tianyu/service/impl/TyServiceImpl.java b/ard-work/src/main/java/com/ard/tianyu/service/impl/TyServiceImpl.java
index 637d878..1525c4d 100644
--- a/ard-work/src/main/java/com/ard/tianyu/service/impl/TyServiceImpl.java
+++ b/ard-work/src/main/java/com/ard/tianyu/service/impl/TyServiceImpl.java
@@ -15,6 +15,9 @@
 import com.ard.tianyu.model.dto.converter.UavSignalInfoConverter;
 import com.ard.tianyu.model.dto.converter.UavStateConverter;
 import com.ard.tianyu.model.dto.converter.UavTelemetryDataConverter;
+import com.ard.tianyu.model.dto.manual.ReturnHomeDTO;
+import com.ard.tianyu.model.dto.manual.SwitchUavControlDTO;
+import com.ard.tianyu.model.dto.manual.TakeOffDTO;
 import com.ard.tianyu.model.dto.signal.SignalInfo;
 import com.ard.tianyu.model.dto.state.UavState;
 import com.ard.tianyu.model.dto.telemetry.TelemetryData;
@@ -25,6 +28,7 @@
 import com.ard.tianyu.netty.command.control.AbsAngleControlCmd;
 import com.ard.tianyu.netty.command.control.AngleControlCmd;
 import com.ard.tianyu.netty.command.control.SpeedControlCmd;
+import com.ard.tianyu.netty.command.manual.*;
 import com.ard.tianyu.netty.command.notice.BoxPowerStatusReplyCmd;
 import com.ard.tianyu.netty.command.notice.FlyWayEndReplyCmd;
 import com.ard.tianyu.netty.command.notice.UavReadyReplyCmd;
@@ -268,6 +272,33 @@
     }
 
     /**
+     * 切换无人机控制权
+     */
+    @Override
+    public void switchUavControl(SwitchUavControlDTO switchUavControlDTO) {
+        SwitchUavControlCmd switchUavControlCmd = new SwitchUavControlCmd(switchUavControlDTO);
+        this.sendMessage(tyConfiguration.getIpPort(), switchUavControlCmd);
+    }
+
+    /**
+     * 起飞
+     */
+    @Override
+    public void takeOff(TakeOffDTO takeOffDTO) {
+        TakeOffCmd takeOffCmd = new TakeOffCmd(takeOffDTO);
+        this.sendMessage(tyConfiguration.getIpPort(), takeOffCmd);
+    }
+
+    /**
+     * 返航
+     */
+    @Override
+    public void returnHome(ReturnHomeDTO returnHomeDTO) {
+        ReturnHomeCmd returnHomeCmd=new ReturnHomeCmd(returnHomeDTO);
+        this.sendMessage(tyConfiguration.getIpPort(), returnHomeCmd);
+    }
+
+    /**
      * 获取无人机状态
      */
     @Override
@@ -355,7 +386,7 @@
                 }
                 if (tyCommand instanceof UavReadyReplyCmd) {
                     UavReadyReplyCmd uavReadyReplyCmd = (UavReadyReplyCmd) tyCommand;
-                    log.info("收到无人机准备完成通知,电池电量{} 经度{} 纬度{} 海拔{}",uavReadyReplyCmd.getBatteryPower(),uavReadyReplyCmd.getLongitude(),uavReadyReplyCmd.getLatitude(),uavReadyReplyCmd.getAltitude());
+                    log.info("收到无人机准备完成通知,电池电量{} 经度{} 纬度{} 海拔{}", uavReadyReplyCmd.getBatteryPower(), uavReadyReplyCmd.getLongitude(), uavReadyReplyCmd.getLatitude(), uavReadyReplyCmd.getAltitude());
                 }
                 if (tyCommand instanceof CameraModeReplyCmd) {
                     CameraModeReplyCmd cameraModeReplyCommand = (CameraModeReplyCmd) tyCommand;
@@ -363,7 +394,7 @@
                 }
                 if (tyCommand instanceof FlyWayEndReplyCmd) {
                     FlyWayEndReplyCmd flyWayEndReplyCmd = (FlyWayEndReplyCmd) tyCommand;
-                    log.info("收到无人机飞行结束通知:状态:{}",flyWayEndReplyCmd.getResult());
+                    log.info("收到无人机飞行结束通知:状态:{}", flyWayEndReplyCmd.getResult());
                 }
                 if (tyCommand instanceof CapturePicReplyCmd) {
                     CapturePicReplyCmd capturePicReplyCommand = (CapturePicReplyCmd) tyCommand;
@@ -377,6 +408,16 @@
                     RecordStopReplyCmd recordStopReplyCommand = (RecordStopReplyCmd) tyCommand;
                     log.info("收到无人机停止录像回复:{} 错误码:{}", String.format("0x%02X", recordStopReplyCommand.getResult() & 0xFF), recordStopReplyCommand.getErrorCode());
                 }
+                //起飞回复
+                if (tyCommand instanceof TakeOffReplyCmd) {
+                    TakeOffReplyCmd takeOffReplyCommand = (TakeOffReplyCmd) tyCommand;
+                    log.info("收到无人机起飞回复:{} 错误码:{}", String.format("0x%02X", takeOffReplyCommand.getResult() & 0xFF), takeOffReplyCommand.getErrorCode());
+                }
+                //返航回复
+                if (tyCommand instanceof ReturnHomeReplyCmd) {
+                    ReturnHomeReplyCmd returnHomeReplyCmd = (ReturnHomeReplyCmd) tyCommand;
+                    log.info("收到无人机返航回复:{} 错误码:{}", String.format("0x%02X", returnHomeReplyCmd.getResult() & 0xFF), returnHomeReplyCmd.getErrorCode());
+                }
                 break;
             default:
                 // 处理其他消息
@@ -384,6 +425,9 @@
         }
     }
 
+    /**
+     * 定时3秒发送心跳指令
+     */
     @Scheduled(fixedRate = 3000)
     public void sendHeartBeat() {
         long timestamp = System.currentTimeMillis();

--
Gitblit v1.9.3