From 1157c58dc74805cbb7db57ab121bbb521f4c216b Mon Sep 17 00:00:00 2001
From: liusuyi <1951119284@qq.com>
Date: Fri, 25 Oct 2024 16:33:49 +0800
Subject: [PATCH] 增加 拍照 录像 相机模式设置

---
 ard-work/src/main/java/com/ard/tianyu/service/impl/TyServiceImpl.java |  126 ++++++++++++++++++++++++++++++++++--------
 1 files changed, 102 insertions(+), 24 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 e51eee5..c056263 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
@@ -8,6 +8,12 @@
 import com.ard.tianyu.model.dto.BoxHistoryDTO;
 import com.ard.tianyu.model.dto.BoxPhotosDTO;
 import com.ard.tianyu.model.dto.BoxSettingsDTO;
+import com.ard.tianyu.model.dto.camera.CameraModeDTO;
+import com.ard.tianyu.model.dto.camera.CapturePicDTO;
+import com.ard.tianyu.model.dto.camera.RecordDTO;
+import com.ard.tianyu.model.dto.control.AbsAngleControlDTO;
+import com.ard.tianyu.model.dto.control.AngleControlDTO;
+import com.ard.tianyu.model.dto.control.SpeedControlDTO;
 import com.ard.tianyu.model.dto.converter.UavSignalInfoConverter;
 import com.ard.tianyu.model.dto.converter.UavStateConverter;
 import com.ard.tianyu.model.dto.converter.UavTelemetryDataConverter;
@@ -17,9 +23,15 @@
 import com.ard.tianyu.model.receiver.*;
 import com.ard.tianyu.netty.command.*;
 import com.ard.tianyu.netty.TyNettyTcpClient;
+import com.ard.tianyu.netty.command.camera.*;
+import com.ard.tianyu.netty.command.control.AbsAngleControlCommand;
+import com.ard.tianyu.netty.command.control.AngleControlCommand;
+import com.ard.tianyu.netty.command.control.SpeedControlCommand;
+import com.ard.tianyu.netty.command.real.SignalInfoCommand;
+import com.ard.tianyu.netty.command.real.UavStateCommand;
+import com.ard.tianyu.netty.command.real.UavTelemetryDataCommand;
+import com.ard.tianyu.netty.command.register.*;
 import com.ard.tianyu.service.ITyService;
-import io.netty.buffer.ByteBuf;
-import io.netty.buffer.Unpooled;
 import io.netty.channel.Channel;
 import io.netty.channel.ChannelFuture;
 import lombok.extern.slf4j.Slf4j;
@@ -127,13 +139,6 @@
         this.sendMessage(tyConfiguration.getIpPort(), registerMessage);
     }
 
-    /**
-     * 无人机控制订阅
-     */
-    public void uavControlSubscribe(String boxSn) {
-        SubscribeCommand subscribeCommand = new SubscribeCommand(boxSn);
-        this.sendMessage(tyConfiguration.getIpPort(), subscribeCommand);
-    }
 
     /**
      * 发送消息
@@ -146,10 +151,7 @@
                 InetSocketAddress ipSocket = (InetSocketAddress) channel.remoteAddress();
                 String host = ipSocket.getHostString();
                 int port = ipSocket.getPort();
-                // 创建 ByteBuf 并编码消息
-                ByteBuf buffer = Unpooled.buffer();
-                msg.encode(buffer); // 确保对消息进行编码
-                channel.writeAndFlush(buffer); // 发送编码后的数据
+                channel.writeAndFlush(msg); // 发送编码后的数据
                 log.debug("向天宇服务器【{}:{}】发送数据,命令码:{}", host, port, String.format("0x%02X", msg.getCmdCode() & 0xFF));
             } else {
                 log.error("与天宇服务器链接断开,无法发送数据!");
@@ -163,9 +165,61 @@
      * 云台控制基于角度
      */
     @Override
-    public void controlAngle(String boxSn, Integer actionId, Integer rotationAngle) {
-        ControlAngleCommand controlAngleCommand = new ControlAngleCommand(boxSn.getBytes(), (byte) 0x00, actionId.byteValue(), rotationAngle.byteValue());
+    public void angleControl(AngleControlDTO angleControlDto) {
+        AngleControlCommand controlAngleCommand = new AngleControlCommand(angleControlDto);
         this.sendMessage(tyConfiguration.getIpPort(), controlAngleCommand);
+    }
+
+    /**
+     * 云台绝对值控制(基于角度)
+     */
+    @Override
+    public void absAngleControl(AbsAngleControlDTO absAngleControlDto) {
+        AbsAngleControlCommand absAngleControlCommand = new AbsAngleControlCommand(absAngleControlDto);
+        this.sendMessage(tyConfiguration.getIpPort(), absAngleControlCommand);
+    }
+
+    /**
+     * 云台转动(基于速度)
+     */
+    @Override
+    public void speedControl(SpeedControlDTO speedControlDto) {
+        SpeedControlCommand speedControlCommand = new SpeedControlCommand(speedControlDto);
+        this.sendMessage(tyConfiguration.getIpPort(), speedControlCommand);
+    }
+
+    /**
+     * 设置相机模式
+     */
+    @Override
+    public void updateCameraMode(CameraModeDTO cameraModeDTO) {
+        CameraModeCommand cameraModeCommand = new CameraModeCommand(cameraModeDTO);
+        this.sendMessage(tyConfiguration.getIpPort(), cameraModeCommand);
+    }
+
+    /**
+     * 拍照
+     */
+    @Override
+    public void capturePic(CapturePicDTO capturePicDto) {
+        updateCameraMode(CameraModeDTO.builder().boxSn(capturePicDto.getBoxSn()).actionParam((byte)0x01).build());
+        CapturePicCommand capturePicCommand = new CapturePicCommand(capturePicDto);
+        this.sendMessage(tyConfiguration.getIpPort(), capturePicCommand);
+    }
+
+    /**
+     * 录像
+     */
+    @Override
+    public void record(RecordDTO recordDto) {
+        BaseCommand baseCommand;
+        if (recordDto.getIsRecord()) {
+            updateCameraMode(CameraModeDTO.builder().boxSn(recordDto.getBoxSn()).actionParam((byte)0x02).build());
+            baseCommand = new RecordStartCommand(recordDto);
+        } else {
+            baseCommand = new RecordStopCommand(recordDto);
+        }
+        this.sendMessage(tyConfiguration.getIpPort(), baseCommand);
     }
 
     /**
@@ -213,13 +267,9 @@
                 break;
             case 0x03:
                 // 处理订阅消息
-                SubscribeCommand subscribeCommand = (SubscribeCommand) tyCommand;
-                log.info("收到订阅消息-->处理订阅消息{}", subscribeCommand.getBoxSn());
                 break;
             case 0x04:
                 // 处理取消订阅消息
-                subscribeCommand = (SubscribeCommand) tyCommand;
-                log.info("收到取消订阅消息-->处理取消订阅消息{}", subscribeCommand.getBoxSn());
                 break;
             case (byte) 0xA8:
                 // 处理无人机状态消息
@@ -244,11 +294,39 @@
                 break;
             case (byte) 0xD1:
                 // 处理无人机
-                DroneReadyNotificationCommand droneReadyNotificationCommand = (DroneReadyNotificationCommand) tyCommand;
-                if (droneReadyNotificationCommand.getActionCode() == (byte) 0x42) {
-                    UavInitInfoCommand uavInitCommand = new UavInitInfoCommand((byte) 0x00, (byte) 0x42, (byte) 0x01);
-                    this.sendMessage(tyConfiguration.getIpPort(), uavInitCommand);
-                    log.info("收到无人机初始化详情-回复防止再次发送");
+                if (tyCommand instanceof UavReadyNotificationCommand) {
+                    UavReadyNotificationCommand droneReadyNotificationCommand = (UavReadyNotificationCommand) tyCommand;
+                    if (droneReadyNotificationCommand.getActionCode() == (byte) 0x42) {
+                        UavInitInfoCommand uavInitCommand = new UavInitInfoCommand(droneReadyNotificationCommand.getBoxSn());
+                        this.sendMessage(tyConfiguration.getIpPort(), uavInitCommand);
+                        log.info("收到无人机初始化详情-回复防止再次发送");
+                    }
+                }
+                if (tyCommand instanceof CameraModeReplyCommand) {
+                    CameraModeReplyCommand cameraModeReplyCommand = (CameraModeReplyCommand) tyCommand;
+                    if (cameraModeReplyCommand.getActionCode() == (byte) 0x22) {
+                        log.info("收到无人机设置相机模式回复:{} 错误码:{}", String.format("0x%02X", cameraModeReplyCommand.getResult() & 0xFF), cameraModeReplyCommand.getErrorCode());
+                    }
+                }
+
+                if (tyCommand instanceof CapturePicReplyCommand) {
+                    CapturePicReplyCommand capturePicReplyCommand = (CapturePicReplyCommand) tyCommand;
+                    if (capturePicReplyCommand.getActionCode() == (byte) 0x23) {
+                        log.info("收到无人机拍照回复:{} 错误码:{}", String.format("0x%02X", capturePicReplyCommand.getResult() & 0xFF), capturePicReplyCommand.getErrorCode());
+                    }
+                }
+
+                if (tyCommand instanceof RecordStartReplyCommand) {
+                    RecordStartReplyCommand recordStartReplyCommand = (RecordStartReplyCommand) tyCommand;
+                    if (recordStartReplyCommand.getActionCode() == (byte) 0x24) {
+                        log.info("收到无人机开始录像回复:{} 错误码:{}", String.format("0x%02X", recordStartReplyCommand.getResult() & 0xFF), recordStartReplyCommand.getErrorCode());
+                    }
+                }
+                if (tyCommand instanceof RecordStopReplyCommand) {
+                    RecordStopReplyCommand recordStopReplyCommand = (RecordStopReplyCommand) tyCommand;
+                    if (recordStopReplyCommand.getActionCode() == (byte) 0x25) {
+                        log.info("收到无人机停止录像回复:{} 错误码:{}", String.format("0x%02X", recordStopReplyCommand.getResult() & 0xFF), recordStopReplyCommand.getErrorCode());
+                    }
                 }
                 break;
             default:

--
Gitblit v1.9.3