package com.ard.tianyu.netty.command;
|
|
import io.netty.buffer.ByteBuf;
|
import lombok.Data;
|
|
/**
|
* 云台转动(基于角度)命令
|
*
|
* @author 刘苏义
|
* @date 2024/10/22 16:36
|
*/
|
|
@Data
|
public class ControlAngleCommand extends BaseCommand{
|
private final byte[] boxSn; // 云盒编号
|
private final byte encryptFlag; // 加密标志
|
private final byte actionId; // 动作编号
|
private final byte rotationAngle; // 转动角度
|
|
public ControlAngleCommand(byte[] boxSn, byte encryptFlag, byte actionId, byte rotationAngle) {
|
if (boxSn.length != 15) {
|
throw new IllegalArgumentException("云盒编号长度必须为15字节");
|
}
|
setDataHeader((short)0x7479);
|
setDataLength(getDataLength());
|
setCmdCode((byte)0xD1);
|
this.boxSn = boxSn;
|
this.encryptFlag = encryptFlag;
|
this.actionId = actionId;
|
this.rotationAngle = rotationAngle;
|
}
|
|
public short getDataLength() {
|
// 计算数据长度: 云盒编号 + 指令编号 + 加密标志 + 动作编号 + 转动角度
|
return (short) (2 + 15 + 1 + 1 + 1); // 帧头 + 数据内容
|
}
|
|
public void encode(ByteBuf out) {
|
out.writeShort(getDataHeader()); // 写入帧头
|
out.writeShort(getDataLength()); // 写入数据长度
|
out.writeByte(getCmdCode()); // 写入指令编号
|
out.writeBytes(boxSn); // 写入云盒编号
|
out.writeByte(encryptFlag); // 写入加密标志
|
out.writeByte(actionId); // 写入动作编号
|
out.writeByte(rotationAngle); // 写入转动角度
|
}
|
}
|