| | |
| | | |
| | | @Data |
| | | public class ControlAngleCommand extends BaseCommand{ |
| | | private final byte[] boxSn; // 云盒编号 |
| | | private final byte encryptFlag; // 加密标志 |
| | | private final byte actionId; // 动作编号 |
| | | private final byte actionCode; // 动作编号 |
| | | private final byte rotationAngle; // 转动角度 |
| | | |
| | | public ControlAngleCommand(byte[] boxSn, byte encryptFlag, byte actionId, byte rotationAngle) { |
| | | if (boxSn.length != 15) { |
| | | throw new IllegalArgumentException("云盒编号长度必须为15字节"); |
| | | } |
| | | public ControlAngleCommand(String boxSn, byte actionCode, byte rotationAngle) { |
| | | setDataHeader((short)0x7479); |
| | | setDataLength(getDataLength()); |
| | | setDataLength((short)19); |
| | | setBoxSn(boxSn.getBytes()); |
| | | setCmdCode((byte)0xD1); |
| | | this.boxSn = boxSn; |
| | | this.encryptFlag = encryptFlag; |
| | | this.actionId = actionId; |
| | | |
| | | this.encryptFlag = 0x00; |
| | | this.actionCode = actionCode; |
| | | this.rotationAngle = rotationAngle; |
| | | } |
| | | |
| | | public short getDataLength() { |
| | | // 计算数据长度: 云盒编号 + 指令编号 + 加密标志 + 动作编号 + 转动角度 |
| | | return (short) (1 + 15 + 1 + 1 + 1); // 帧头 + 数据内容 |
| | | } |
| | | |
| | | public void encode(ByteBuf out) { |
| | | out.writeShort(getDataHeader()); // 写入帧头 |
| | | out.writeShort(getDataLength()); // 写入数据长度 |
| | | out.writeBytes(boxSn); // 写入云盒编号 |
| | | out.writeByte(getCmdCode()); // 写入指令编号 |
| | | out.writeByte(encryptFlag); // 写入加密标志 |
| | | out.writeByte(actionId); // 写入动作编号 |
| | | out.writeByte(actionCode); // 写入动作编号 |
| | | out.writeByte(rotationAngle); // 写入转动角度 |
| | | } |
| | | } |