package com.ard.tianyu.component.netty.command.manual; import com.ard.tianyu.domain.dto.manual.FlyControlDTO; import com.ard.tianyu.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); // 写入执行时间 } }