liusuyi
2025-12-08 3e64fc031eb42fb66f78104d0ff0f6cf797db0f0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package com.ard.work.component.netty.command.manual;
 
import com.ard.work.domain.dto.manual.FlyControlDTO;
import com.ard.work.component.netty.command.BaseCmd;
import io.netty.buffer.ByteBuf;
 
/**
 * 方向控制指令
 *
 * @author liusuyi
 * @date 2024年10月26日15:43
 **/
public class FlyControlCmd extends BaseCmd {
    private final float frSpeed;                    // 前后速度
    private final float lrSpeed;                    // 左右速度
    private final float udSpeed;                    // 上下速度
    private final float yaw;                        // 偏航角
    private final short execTime = 200;             // 执行时间
 
    public FlyControlCmd(FlyControlDTO flyControlDTO) {
        setDataHeader((short) 0x7479);
        setDataLength((short) 36);
        setBoxSn(flyControlDTO.getBoxSn().getBytes());
        setCmdCode((byte) 0xD1);
        this.frSpeed = flyControlDTO.getFrSpeed();
        this.lrSpeed = flyControlDTO.getLrSpeed();
        this.udSpeed = flyControlDTO.getUdSpeed();
        this.yaw = flyControlDTO.getYaw();
    }
 
 
    public void encode(ByteBuf out) {
        out.writeShort(getDataHeader());    // 写入数据头
        out.writeShort(getDataLength());    // 写入数据长度
        out.writeBytes(getBoxSn());         // 写入盒子SN
        out.writeByte(getCmdCode());        // 写入命令码
        out.writeByte(0x00);          // 写入加密标志
        out.writeByte(0x28);          // 写入动作编号
        out.writeFloat(frSpeed);            // 写入前后速度
        out.writeFloat(lrSpeed);            // 写入左右速度
        out.writeFloat(udSpeed);            // 写入上下速度
        out.writeFloat(yaw);                // 写入偏航角
        out.writeShort(execTime);           // 写入执行时间
    }
}