package com.ard.work.component.netty.command.control; import com.ard.work.domain.dto.control.SpeedControlDTO; import com.ard.work.component.netty.command.BaseCmd; import io.netty.buffer.ByteBuf; import lombok.Data; import lombok.EqualsAndHashCode; /** * 云台绝对值控制(基于角度)命令 * * @author 刘苏义 * @date 2024/10/22 16:36 */ @EqualsAndHashCode(callSuper = true) @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); // 写入执行时间 } }