liusuyi
2024-11-01 3181d10cd687272c20252a020eeaa9974527dc14
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
46
47
package com.ard.tianyu.netty.command.control;
 
import com.ard.tianyu.model.dto.control.SpeedControlDTO;
import com.ard.tianyu.netty.command.BaseCmd;
import io.netty.buffer.ByteBuf;
import lombok.Data;
 
/**
 * 云台绝对值控制(基于角度)命令
 *
 * @author 刘苏义
 * @date 2024/10/22 16:36
 */
 
@Data
public class SpeedControlCmd extends BaseCmd {
    private final byte encryptFlag = 0x00;          // 加密标志
    private final byte actionCode = (byte) 0xF4;    // 动作编号
    private final float pitchSpeed;                 // 俯仰转速
    private final float yawSpeed;                   // 平移转速
    private final float rollSpeed;                  // 横滚转速
    private final short execTime = 200;             // 执行时间
 
 
    public SpeedControlCmd(SpeedControlDTO speedControlDto) {
        setDataHeader((short) 0x7479);
        setDataLength((short) 32);
        setBoxSn(speedControlDto.getBoxSn().getBytes());
        setCmdCode((byte) 0xD1);
        this.pitchSpeed = speedControlDto.getPitchSpeed();
        this.yawSpeed = speedControlDto.getYawSpeed();
        this.rollSpeed = speedControlDto.getRollSpeed();
    }
 
    public void encode(ByteBuf out) {
        out.writeShort(getDataHeader());    // 写入数据头
        out.writeShort(getDataLength());    // 写入数据长度
        out.writeBytes(getBoxSn());         // 写入盒子SN
        out.writeByte(getCmdCode());        // 写入命令码
        out.writeByte(encryptFlag);         // 写入加密标志
        out.writeByte(actionCode);          // 写入动作编号
        out.writeFloat(pitchSpeed);         // 写入转动角度
        out.writeFloat(yawSpeed);           // 写入转动角度
        out.writeFloat(rollSpeed);          // 写入转动角度
        out.writeShort(execTime);           // 写入执行时间
    }
}