From f8a09d564aeba26eb9d729fee5e7fbcab3811de1 Mon Sep 17 00:00:00 2001
From: liusuyi <1951119284@qq.com>
Date: Sat, 26 Oct 2024 14:14:49 +0800
Subject: [PATCH] 优化

---
 ard-work/src/main/java/com/ard/tianyu/service/impl/TyServiceImpl.java |  177 +++++++++++++++++++++++++++++++++++++---------------------
 1 files changed, 113 insertions(+), 64 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 c056263..637d878 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,9 +8,7 @@
 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.camera.*;
 import com.ard.tianyu.model.dto.control.AbsAngleControlDTO;
 import com.ard.tianyu.model.dto.control.AngleControlDTO;
 import com.ard.tianyu.model.dto.control.SpeedControlDTO;
@@ -24,12 +22,15 @@
 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.control.AbsAngleControlCmd;
+import com.ard.tianyu.netty.command.control.AngleControlCmd;
+import com.ard.tianyu.netty.command.control.SpeedControlCmd;
+import com.ard.tianyu.netty.command.notice.BoxPowerStatusReplyCmd;
+import com.ard.tianyu.netty.command.notice.FlyWayEndReplyCmd;
+import com.ard.tianyu.netty.command.notice.UavReadyReplyCmd;
+import com.ard.tianyu.netty.command.real.SignalInfoCmd;
+import com.ard.tianyu.netty.command.real.UavStateCmd;
+import com.ard.tianyu.netty.command.real.UavTelemetryDataCmd;
 import com.ard.tianyu.netty.command.register.*;
 import com.ard.tianyu.service.ITyService;
 import io.netty.channel.Channel;
@@ -135,15 +136,14 @@
     @Override
     public void registerMessage() {
         AccessTokenReceiver tyToken = tyConfiguration.getAccessToken();
-        RegisterCommand registerMessage = new RegisterCommand(tyToken.getCompanyId(), tyToken.getAccessToken().getBytes());
+        RegisterCmd registerMessage = new RegisterCmd(tyToken.getCompanyId(), tyToken.getAccessToken().getBytes());
         this.sendMessage(tyConfiguration.getIpPort(), registerMessage);
     }
-
 
     /**
      * 发送消息
      */
-    public void sendMessage(String key, BaseCommand msg) {
+    public void sendMessage(String key, BaseCmd msg) {
         try {
             ChannelFuture future = TyNettyTcpClient.channels.get(key).getChannelFuture();
             Channel channel = future.channel();
@@ -166,7 +166,7 @@
      */
     @Override
     public void angleControl(AngleControlDTO angleControlDto) {
-        AngleControlCommand controlAngleCommand = new AngleControlCommand(angleControlDto);
+        AngleControlCmd controlAngleCommand = new AngleControlCmd(angleControlDto);
         this.sendMessage(tyConfiguration.getIpPort(), controlAngleCommand);
     }
 
@@ -175,7 +175,7 @@
      */
     @Override
     public void absAngleControl(AbsAngleControlDTO absAngleControlDto) {
-        AbsAngleControlCommand absAngleControlCommand = new AbsAngleControlCommand(absAngleControlDto);
+        AbsAngleControlCmd absAngleControlCommand = new AbsAngleControlCmd(absAngleControlDto);
         this.sendMessage(tyConfiguration.getIpPort(), absAngleControlCommand);
     }
 
@@ -184,7 +184,7 @@
      */
     @Override
     public void speedControl(SpeedControlDTO speedControlDto) {
-        SpeedControlCommand speedControlCommand = new SpeedControlCommand(speedControlDto);
+        SpeedControlCmd speedControlCommand = new SpeedControlCmd(speedControlDto);
         this.sendMessage(tyConfiguration.getIpPort(), speedControlCommand);
     }
 
@@ -193,7 +193,7 @@
      */
     @Override
     public void updateCameraMode(CameraModeDTO cameraModeDTO) {
-        CameraModeCommand cameraModeCommand = new CameraModeCommand(cameraModeDTO);
+        CameraModeCmd cameraModeCommand = new CameraModeCmd(cameraModeDTO);
         this.sendMessage(tyConfiguration.getIpPort(), cameraModeCommand);
     }
 
@@ -202,8 +202,8 @@
      */
     @Override
     public void capturePic(CapturePicDTO capturePicDto) {
-        updateCameraMode(CameraModeDTO.builder().boxSn(capturePicDto.getBoxSn()).actionParam((byte)0x01).build());
-        CapturePicCommand capturePicCommand = new CapturePicCommand(capturePicDto);
+        updateCameraMode(CameraModeDTO.builder().boxSn(capturePicDto.getBoxSn()).actionParam((byte) 0x01).build());
+        CapturePicCmd capturePicCommand = new CapturePicCmd(capturePicDto);
         this.sendMessage(tyConfiguration.getIpPort(), capturePicCommand);
     }
 
@@ -212,14 +212,59 @@
      */
     @Override
     public void record(RecordDTO recordDto) {
-        BaseCommand baseCommand;
+        BaseCmd baseCmd;
         if (recordDto.getIsRecord()) {
-            updateCameraMode(CameraModeDTO.builder().boxSn(recordDto.getBoxSn()).actionParam((byte)0x02).build());
-            baseCommand = new RecordStartCommand(recordDto);
+            updateCameraMode(CameraModeDTO.builder().boxSn(recordDto.getBoxSn()).actionParam((byte) 0x02).build());
+            baseCmd = new RecordStartCmd(recordDto);
         } else {
-            baseCommand = new RecordStopCommand(recordDto);
+            baseCmd = new RecordStopCmd(recordDto);
         }
-        this.sendMessage(tyConfiguration.getIpPort(), baseCommand);
+        this.sendMessage(tyConfiguration.getIpPort(), baseCmd);
+    }
+
+    /**
+     * 变倍
+     */
+    @Override
+    public void zoom(ZoomDTO zoomDTO) {
+        ZoomCmd zoomCommand = new ZoomCmd(zoomDTO);
+        this.sendMessage(tyConfiguration.getIpPort(), zoomCommand);
+    }
+
+    /**
+     * 变倍到指定倍数
+     */
+    @Override
+    public void zoomToLevel(ZoomToLevelDTO zoomToLevelDTO) {
+        ZoomToLevelCmd zoomToLevelCommand = new ZoomToLevelCmd(zoomToLevelDTO);
+        this.sendMessage(tyConfiguration.getIpPort(), zoomToLevelCommand);
+    }
+
+    /**
+     * 切换摄像头
+     */
+    @Override
+    public void switchCamera(SwitchCameraDTO switchCameraDTO) {
+        SwitchCameraCmd switchCameraCmd = new SwitchCameraCmd(switchCameraDTO);
+        this.sendMessage(tyConfiguration.getIpPort(), switchCameraCmd);
+    }
+
+    /**
+     * 切换视频源
+     */
+    @Override
+    public void switchSource(SwitchSourceDTO switchSourceDTO) {
+        SwitchSourceCmd switchSourceCmd = new SwitchSourceCmd(switchSourceDTO);
+        this.sendMessage(tyConfiguration.getIpPort(), switchSourceCmd);
+    }
+
+    /**
+     * 打开或关闭照片回传
+     */
+    @Override
+    public void photoReturnToggle(PhotoReturnToggleDTO photoReturnToggleDTO) {
+        PhotoReturnToggleCmd photoReturnToggleCmd = new PhotoReturnToggleCmd(photoReturnToggleDTO);
+        this.sendMessage(tyConfiguration.getIpPort(), photoReturnToggleCmd);
     }
 
     /**
@@ -246,14 +291,17 @@
         return UavSignalInfoCache.getUavSignalInfo(boxSn);
     }
 
+    /**
+     * 处理天宇服务器返回的消息
+     */
     @Override
-    public void processMessage(String key, BaseCommand tyCommand) {
+    public void processMessage(String key, BaseCmd tyCommand) {
         byte cmdCode = tyCommand.getCmdCode();
         switch (cmdCode) {
             case 0x01:
                 // 处理心跳消息
-                RegisterReplyCommand registerReplyCommand = (RegisterReplyCommand) tyCommand;
-                log.info("收到注册消息-->处理注册消息{}", registerReplyCommand.getSuccess());
+                RegisterReplyCmd registerReplyCommand = (RegisterReplyCmd) tyCommand;
+                log.debug("收到注册消息-->处理注册消息:{}", registerReplyCommand.getSuccess());
                 if (registerReplyCommand.getSuccess() != 1) {
                     // 注册失败,重新注册
                     log.info("注册失败,重新注册");
@@ -262,8 +310,8 @@
                 break;
             case 0x02:
                 // 处理注册消息
-                HeartbeatReplyCommand heartbeatReplyCommand = (HeartbeatReplyCommand) tyCommand;
-                log.debug("收到心跳消息-->处理心跳消息{}", heartbeatReplyCommand.getTimestamp());
+                HeartbeatReplyCmd heartbeatReplyCmd = (HeartbeatReplyCmd) tyCommand;
+                log.debug("收到心跳消息-->处理心跳消息:{}", heartbeatReplyCmd.getTimestamp());
                 break;
             case 0x03:
                 // 处理订阅消息
@@ -271,62 +319,63 @@
             case 0x04:
                 // 处理取消订阅消息
                 break;
+            case 0x0A:
+                // 处理云盒开关机通知消息
+                BoxPowerStatusReplyCmd boxPowerStatusReplyCmd = (BoxPowerStatusReplyCmd) tyCommand;
+                log.debug("收到云盒开关机通知消息-->状态:{}", boxPowerStatusReplyCmd.getStatus());
+                break;
             case (byte) 0xA8:
                 // 处理无人机状态消息
                 log.debug("收到无人机状态消息-->无人机状态消息");
-                UavStateCommand uavStateCommand = (UavStateCommand) tyCommand;
-                UavState uavState = UavStateConverter.convertProtoToEntity(uavStateCommand.getUavState());
+                UavStateCmd uavStateCmd = (UavStateCmd) tyCommand;
+                UavState uavState = UavStateConverter.convertProtoToEntity(uavStateCmd.getUavState());
                 UavStateCache.putUavState(uavState);
                 break;
             case (byte) 0xA9:
                 // 处理无人机遥测消息
                 log.debug("收到无人机遥测消息-->无人机遥测消息");
-                UavTelemetryDataCommand uavTelemetryDataCommand = (UavTelemetryDataCommand) tyCommand;
-                TelemetryData telemetryData = UavTelemetryDataConverter.convertProtoToEntity(uavTelemetryDataCommand.getTelemetryData());
+                UavTelemetryDataCmd uavTelemetryDataCmd = (UavTelemetryDataCmd) tyCommand;
+                TelemetryData telemetryData = UavTelemetryDataConverter.convertProtoToEntity(uavTelemetryDataCmd.getTelemetryData());
                 UavTelemetryDataCache.putUavTelemetryData(telemetryData);
                 break;
             case (byte) 0x0C:
                 // 处理无人机信道质量数据
                 log.debug("收到无人机信道质量数据消息-->无人机信道质量数据消息");
-                SignalInfoCommand signalInfoCommand = (SignalInfoCommand) tyCommand;
-                SignalInfo signalInfo = UavSignalInfoConverter.convertProtoToEntity(signalInfoCommand.getSignalInfo());
+                SignalInfoCmd signalInfoCmd = (SignalInfoCmd) tyCommand;
+                SignalInfo signalInfo = UavSignalInfoConverter.convertProtoToEntity(signalInfoCmd.getSignalInfo());
                 UavSignalInfoCache.putUavSignalInfoCache(signalInfo);
                 break;
             case (byte) 0xD1:
                 // 处理无人机
-                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 UavInitReplyCmd) {
+                    UavInitReplyCmd uavInitReplyCmd = (UavInitReplyCmd) tyCommand;
+                    UavInitInfoCmd uavInitCommand = new UavInitInfoCmd(uavInitReplyCmd.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 UavReadyReplyCmd) {
+                    UavReadyReplyCmd uavReadyReplyCmd = (UavReadyReplyCmd) tyCommand;
+                    log.info("收到无人机准备完成通知,电池电量{} 经度{} 纬度{} 海拔{}",uavReadyReplyCmd.getBatteryPower(),uavReadyReplyCmd.getLongitude(),uavReadyReplyCmd.getLatitude(),uavReadyReplyCmd.getAltitude());
                 }
-
-                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 CameraModeReplyCmd) {
+                    CameraModeReplyCmd cameraModeReplyCommand = (CameraModeReplyCmd) tyCommand;
+                    log.info("收到无人机设置相机模式回复:{} 错误码:{}", String.format("0x%02X", cameraModeReplyCommand.getResult() & 0xFF), cameraModeReplyCommand.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 FlyWayEndReplyCmd) {
+                    FlyWayEndReplyCmd flyWayEndReplyCmd = (FlyWayEndReplyCmd) tyCommand;
+                    log.info("收到无人机飞行结束通知:状态:{}",flyWayEndReplyCmd.getResult());
                 }
-                if (tyCommand instanceof RecordStopReplyCommand) {
-                    RecordStopReplyCommand recordStopReplyCommand = (RecordStopReplyCommand) tyCommand;
-                    if (recordStopReplyCommand.getActionCode() == (byte) 0x25) {
-                        log.info("收到无人机停止录像回复:{} 错误码:{}", String.format("0x%02X", recordStopReplyCommand.getResult() & 0xFF), recordStopReplyCommand.getErrorCode());
-                    }
+                if (tyCommand instanceof CapturePicReplyCmd) {
+                    CapturePicReplyCmd capturePicReplyCommand = (CapturePicReplyCmd) tyCommand;
+                    log.info("收到无人机拍照回复:{} 错误码:{}", String.format("0x%02X", capturePicReplyCommand.getResult() & 0xFF), capturePicReplyCommand.getErrorCode());
+                }
+                if (tyCommand instanceof RecordStartReplyCmd) {
+                    RecordStartReplyCmd recordStartReplyCommand = (RecordStartReplyCmd) tyCommand;
+                    log.info("收到无人机开始录像回复:{} 错误码:{}", String.format("0x%02X", recordStartReplyCommand.getResult() & 0xFF), recordStartReplyCommand.getErrorCode());
+                }
+                if (tyCommand instanceof RecordStopReplyCmd) {
+                    RecordStopReplyCmd recordStopReplyCommand = (RecordStopReplyCmd) tyCommand;
+                    log.info("收到无人机停止录像回复:{} 错误码:{}", String.format("0x%02X", recordStopReplyCommand.getResult() & 0xFF), recordStopReplyCommand.getErrorCode());
                 }
                 break;
             default:
@@ -339,7 +388,7 @@
     public void sendHeartBeat() {
         long timestamp = System.currentTimeMillis();
         log.debug("定时向天宇发送⼼跳,时间戳{}", timestamp);
-        HeartbeatCommand heartbeatMessage = new HeartbeatCommand(timestamp);
+        HeartbeatCmd heartbeatMessage = new HeartbeatCmd(timestamp);
         this.sendMessage(tyConfiguration.getIpPort(), heartbeatMessage);
     }
 }
\ No newline at end of file

--
Gitblit v1.9.3