From 05ba868736725db54db1944ed5cf7a95d14efc37 Mon Sep 17 00:00:00 2001
From: liusuyi <1951119284@qq.com>
Date: Wed, 30 Oct 2024 17:07:51 +0800
Subject: [PATCH] 增加:手动飞行控制

---
 ard-work/src/main/java/com/ard/tianyu/netty/handler/MessageProtocolDecoder.java |  161 +++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 136 insertions(+), 25 deletions(-)

diff --git a/ard-work/src/main/java/com/ard/tianyu/netty/handler/MessageProtocolDecoder.java b/ard-work/src/main/java/com/ard/tianyu/netty/handler/MessageProtocolDecoder.java
index 4f88354..27fe205 100644
--- a/ard-work/src/main/java/com/ard/tianyu/netty/handler/MessageProtocolDecoder.java
+++ b/ard-work/src/main/java/com/ard/tianyu/netty/handler/MessageProtocolDecoder.java
@@ -1,15 +1,20 @@
 package com.ard.tianyu.netty.handler;// MessageProtocolDecoder.java
 
 import com.ard.tianyu.netty.command.*;
-import com.ard.tianyu.netty.command.camera.CapturePicReplyCommand;
-import com.ard.tianyu.netty.command.camera.RecordStartReplyCommand;
-import com.ard.tianyu.netty.command.camera.RecordStopReplyCommand;
-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.HeartbeatReplyCommand;
-import com.ard.tianyu.netty.command.register.RegisterReplyCommand;
-import com.ard.tianyu.netty.command.register.UavReadyNotificationCommand;
+import com.ard.tianyu.netty.command.camera.CameraModeReplyCmd;
+import com.ard.tianyu.netty.command.camera.CapturePicReplyCmd;
+import com.ard.tianyu.netty.command.camera.RecordStartReplyCmd;
+import com.ard.tianyu.netty.command.camera.RecordStopReplyCmd;
+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;
+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.HeartbeatReplyCmd;
+import com.ard.tianyu.netty.command.register.RegisterReplyCmd;
+import com.ard.tianyu.netty.command.register.UavInitReplyCmd;
 import com.ard.tianyu.netty.protobuf.TelemetryDataPB;
 import io.netty.buffer.ByteBuf;
 import io.netty.channel.ChannelHandlerContext;
@@ -39,33 +44,38 @@
             return;
         }
         byte cmdCode = in.readByte();
-        BaseCommand baseCommand = null;
+        BaseCmd baseCmd = null;
         switch (cmdCode) {
             case 0x01:
                 byte success = in.readByte(); // 读取是否成功
                 log.warn("注册回复: {}", success == 0x01 ? "成功" : "失败");
-                baseCommand = new RegisterReplyCommand(success);
+                baseCmd = new RegisterReplyCmd(success);
                 break;
             case 0x02:
                 long timestamp = in.readLong(); // 读取时间戳
-                baseCommand = new HeartbeatReplyCommand(timestamp);
+                baseCmd = new HeartbeatReplyCmd(timestamp);
                 log.debug("心跳回复: 时间戳 {}", timestamp);
                 break;
             case 0x03:
             case 0x04:
                 break;
+            case 0x0A:
+                byte status = in.readByte();
+                baseCmd = new BoxPowerStatusReplyCmd(status);
+                log.debug("云盒开机/关机通知回复: 状态 {}", String.format("0x%02X", status & 0xFF));
+                break;
             case (byte) 0xA8:
                 byte[] uavStatus = new byte[dataLength - 1];
                 in.readBytes(uavStatus);  // 读取 ProtoBuf 数据
                 TelemetryDataPB.UavState uavState = TelemetryDataPB.UavState.parseFrom(uavStatus);
-                baseCommand = new UavStateCommand(uavState);
+                baseCmd = new UavStateCmd(uavState);
                 log.debug("无人机状态数据: {}", uavState.getBoxSn());
                 break;
             case (byte) 0xA9:
                 byte[] uavData = new byte[dataLength - 1];
                 in.readBytes(uavData);
                 TelemetryDataPB.TelemetryData telemetryData = TelemetryDataPB.TelemetryData.parseFrom(uavData);
-                baseCommand = new UavTelemetryDataCommand(telemetryData);
+                baseCmd = new UavTelemetryDataCmd(telemetryData);
                 log.debug("遥测数据: {}", telemetryData.getBoxSn());
                 break;
             case (byte) 0x0C:
@@ -76,29 +86,110 @@
                 uavData = new byte[dataLength - 20];
                 in.readBytes(uavData);
                 TelemetryDataPB.SignalInfo signalInfo = TelemetryDataPB.SignalInfo.parseFrom(uavData);
-                baseCommand = new SignalInfoCommand(signalInfo);
+                baseCmd = new SignalInfoCmd(signalInfo);
                 log.debug("信道质量数据: {}", delayTime);
                 break;
             case (byte) 0xD1:
                 byte encryptionFlag = in.readByte();
                 byte actionCode = in.readByte();
                 switch (actionCode) {
-                    case 0x23:
+                    case 0x11:
                         byte result = in.readByte();
                         int errorCode = in.readInt();
                         uavData = new byte[15];
                         in.readBytes(uavData);
                         String boxSn = new String(uavData);
-                        baseCommand = new CapturePicReplyCommand(boxSn, result, errorCode);
+                        baseCmd = new TakeOffReplyCmd(boxSn, result, errorCode);
+                        log.debug("起飞回复: {}", boxSn);
+                        break;
+                    case 0x12:
+                        result = in.readByte();
+                        errorCode = in.readInt();
+                        uavData = new byte[15];
+                        in.readBytes(uavData);
+                        boxSn = new String(uavData);
+                        baseCmd = new ReturnHomeReplyCmd(boxSn, result, errorCode);
+                        log.debug("返航回复: {}", boxSn);
+                        break;
+                    case 0x13:
+                        result = in.readByte();
+                        errorCode = in.readInt();
+                        uavData = new byte[15];
+                        in.readBytes(uavData);
+                        boxSn = new String(uavData);
+                        baseCmd = new ReturnHomeCancelReplyCmd(boxSn, result, errorCode);
+                        log.debug("取消返航回复: {}", boxSn);
+                        break;
+                    case 0x14:
+                        result = in.readByte();
+                        errorCode = in.readInt();
+                        uavData = new byte[15];
+                        in.readBytes(uavData);
+                        boxSn = new String(uavData);
+                        baseCmd = new LandReplyCmd(boxSn, result, errorCode);
+                        log.debug("降落回复: {}", boxSn);
+                        break;
+                    case 0x15:
+                        result = in.readByte();
+                        errorCode = in.readInt();
+                        uavData = new byte[15];
+                        in.readBytes(uavData);
+                        boxSn = new String(uavData);
+                        baseCmd = new LandCancelReplyCmd(boxSn, result, errorCode);
+                        log.debug("取消降落回复: {}", boxSn);
+                        break;
+                    case 0x29:
+                        result = in.readByte();
+                        errorCode = in.readInt();
+                        uavData = new byte[15];
+                        in.readBytes(uavData);
+                        boxSn = new String(uavData);
+                        baseCmd = new LandForcedReplyCmd(boxSn, result, errorCode);
+                        log.debug("强制降落回复: {}", boxSn);
+                        break;
+                    case 0x32:
+                        result = in.readByte();
+                        errorCode = in.readInt();
+                        uavData = new byte[15];
+                        in.readBytes(uavData);
+                        boxSn = new String(uavData);
+                        baseCmd = new EmergencyBrakeReplyCmd(boxSn, result, errorCode);
+                        log.debug("紧急制动回复: {}", boxSn);
+                        break;
+                    case 0x39:
+                        result = in.readByte();
+                        errorCode = in.readInt();
+                        uavData = new byte[15];
+                        in.readBytes(uavData);
+                        boxSn = new String(uavData);
+                        baseCmd = new PointControlReachedReplyCmd(boxSn, result, errorCode);
+                        log.debug("到达指点飞行位置回复: {}", boxSn);
+                        break;
+                    case 0x22:
+                        result = in.readByte();
+                        errorCode = in.readInt();
+                        uavData = new byte[15];
+                        in.readBytes(uavData);
+                        boxSn = new String(uavData);
+                        baseCmd = new CameraModeReplyCmd(boxSn, result, errorCode);
+                        log.debug("设置相机模式回复: {}", boxSn);
+                        break;
+                    case 0x23:
+                        result = in.readByte();
+                        errorCode = in.readInt();
+                        uavData = new byte[15];
+                        in.readBytes(uavData);
+                        boxSn = new String(uavData);
+                        baseCmd = new CapturePicReplyCmd(boxSn, result, errorCode);
                         log.debug("拍照回复: {}", boxSn);
                         break;
                     case 0x24:
-                         result = in.readByte();
-                         errorCode = in.readInt();
+                        result = in.readByte();
+                        errorCode = in.readInt();
                         uavData = new byte[15];
                         in.readBytes(uavData);
-                         boxSn = new String(uavData);
-                        baseCommand = new RecordStartReplyCommand(boxSn, result, errorCode);
+                        boxSn = new String(uavData);
+                        baseCmd = new RecordStartReplyCmd(boxSn, result, errorCode);
                         log.debug("开始录像回复: {}", boxSn);
                         break;
                     case 0x25:
@@ -107,8 +198,28 @@
                         uavData = new byte[15];
                         in.readBytes(uavData);
                         boxSn = new String(uavData);
-                        baseCommand = new RecordStopReplyCommand(boxSn, result, errorCode);
+                        baseCmd = new RecordStopReplyCmd(boxSn, result, errorCode);
                         log.debug("停止录像回复: {}", boxSn);
+                        break;
+                    case 0x2E:
+                        result = in.readByte();
+                        errorCode = in.readInt();
+                        uavData = new byte[15];
+                        in.readBytes(uavData);
+                        boxSn = new String(uavData);
+                        baseCmd = new FlyWayEndReplyCmd(boxSn, result, errorCode);
+                        log.debug("航线结束通知回复: {}", boxSn);
+                        break;
+                    case 0x3D:
+                        byte batteryPower = in.readByte();
+                        double longitude = in.readDouble();
+                        double latitude = in.readDouble();
+                        int altitude = in.readInt();
+                        uavData = new byte[dataLength - 24];
+                        in.readBytes(uavData);
+                        boxSn = new String(uavData);
+                        baseCmd = new UavReadyReplyCmd(boxSn, batteryPower, longitude, latitude, altitude);
+                        log.debug("无人机准备完成通知回复: 电池电量 {}", String.format("0x%02X", batteryPower & 0xFF));
                         break;
                     case 0x42:
                         byte[] uavData1 = new byte[dataLength - 18];
@@ -117,7 +228,7 @@
                         in.readBytes(uavData2);
                         boxSn = new String(uavData2);
                         TelemetryDataPB.UavInitInfo uavInitInfo = TelemetryDataPB.UavInitInfo.parseFrom(uavData1);
-                        baseCommand = new UavReadyNotificationCommand(boxSn, uavInitInfo, actionCode);
+                        baseCmd = new UavInitReplyCmd(boxSn, uavInitInfo);
                         log.debug("无人机初始化数据: {}", boxSn);
                         break;
                     default:
@@ -134,8 +245,8 @@
                         String.format("0x%02X", actionCode & 0xFF));//String.format("0x%02X", cmdCode & 0xFF)
 
         }
-        if (baseCommand != null) {
-            out.add(baseCommand);
+        if (baseCmd != null) {
+            out.add(baseCmd);
         }
     }
 }
\ No newline at end of file

--
Gitblit v1.9.3