liusuyi
2024-11-02 87cba28b3dc8389e1df61f3ba7d986b09fd89db0
ard-work/src/main/java/com/ard/tianyu/netty/handler/MessageProtocolDecoder.java
@@ -16,6 +16,10 @@
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.command.settings.ReturnHeightSettingReplyCmd;
import com.ard.tianyu.netty.command.settings.ReturnPointSettingReplyCmd;
import com.ard.tianyu.netty.command.settings.VideoStreamSettingReplyCmd;
import com.ard.tianyu.netty.command.wayline.*;
import com.ard.tianyu.netty.protobuf.TelemetryDataPB;
import com.google.protobuf.InvalidProtocolBufferException;
import io.netty.buffer.ByteBuf;
@@ -92,6 +96,11 @@
                actionCode = in.readByte();//动作编号
                baseCmd = processD1ReplyCmd(in, actionCode);
                break;
            case (byte) 0xD2:
                in.readByte();//加密标志
                actionCode = in.readByte();//动作编号
                baseCmd = processD2ReplyCmd(in, actionCode);
                break;
            default:
                in.readByte();//加密标志
                actionCode = in.readByte();
@@ -113,6 +122,8 @@
        in.readBytes(uavData);
        String boxSn = new String(uavData);
        switch (actionCode) {
            case 0x10:
                return new WayLineUploadReplyCmd(boxSn, result, errorCode);
            case 0x11:
                return new TakeOffReplyCmd(boxSn, result, errorCode);
            case 0x12:
@@ -123,8 +134,20 @@
                return new LandReplyCmd(boxSn, result, errorCode);
            case 0x15:
                return new LandCancelReplyCmd(boxSn, result, errorCode);
            case 0x17:
                return new WayLineBeginReplyCmd(boxSn, result, errorCode);
            case 0x18:
                return new WayLinePauseReplyCmd(boxSn, result, errorCode);
            case 0x19:
                return new WayLineResumeReplyCmd(boxSn, result, errorCode);
            case 0x20:
                return new WayLineEndReplyCmd(boxSn, result, errorCode);
            case 0x21:
                return new ReturnHeightSettingReplyCmd(boxSn, result, errorCode);
            case 0x29:
                return new LandForcedReplyCmd(boxSn, result, errorCode);
            case 0x31:
                return new ReturnPointSettingReplyCmd(boxSn, result, errorCode);
            case 0x32:
                return new EmergencyBrakeReplyCmd(boxSn, result, errorCode);
            case 0x39:
@@ -145,11 +168,26 @@
                return processSpecialD1ReplyCmd(in, actionCode, boxSn);
            // Add other cases...
            default:
                log.warn("无法识别的动作编号:{}", ByteUtils.byteToHex(actionCode));
                log.warn("无法识别D1的动作编号:{}", ByteUtils.byteToHex(actionCode));
        }
        return null;
    }
    //处理D1指令回复
    private BaseCmd processD2ReplyCmd(ByteBuf in, byte actionCode) {
        byte result = in.readByte();
        int errorCode = in.readInt();
        byte[] uavData = new byte[15];
        in.readBytes(uavData);
        String boxSn = new String(uavData);
        switch (actionCode) {
            case 0x05:
                return new VideoStreamSettingReplyCmd(boxSn, result, errorCode);
            // Add other cases...
            default:
                log.warn("无法识别D2的动作编号:{}", ByteUtils.byteToHex(actionCode));
        }
        return null;
    }
    //处理特殊D1指令回复
    private BaseCmd processSpecialD1ReplyCmd(ByteBuf in, byte actionCode, String boxSn) {
        switch (actionCode) {