package com.ard.work.sdk.fjr.netty;
|
|
import lombok.Data;
|
|
/**
|
* 红外热像仪通讯指令实体
|
*/
|
@Data
|
public class ThermalCommand {
|
|
// ================= 常量定义 =================
|
|
// 设备地址 (所有指令通用)
|
public static final byte DEVICE_ADDR = 0x26;
|
|
// 指令ID定义
|
public static final byte CMD_FOCUS = 0x01; // 调焦
|
public static final byte CMD_FOCUS_STOP = 0x10; // 调焦停止
|
public static final byte CMD_ZOOM = 0x11; // 变倍
|
public static final byte CMD_SHUTTER = 0x03; // 手动快门校正
|
public static final byte CMD_AUTO_FOCUS = 0x34; // 自动调焦
|
public static final byte CMD_MOTOR_SPEED = 0x12; // 电机速度设置指令
|
|
// 调焦动作值
|
public static final byte FOCUS_PLUS_VAL = 0x00; // 调焦+ (近)
|
public static final byte FOCUS_MINUS_VAL = 0x0F; // 调焦- (远)
|
|
// ================= 属性定义 =================
|
|
private String cameraId; // 业务ID:用于Netty Manager路由,不打包发送
|
private byte cmdId; // 指令ID
|
private byte[] data; // 附加数据
|
|
// ================= 构造方法 =================
|
|
public ThermalCommand(String cameraId, byte cmdId, byte[] data) {
|
this.cameraId = cameraId;
|
this.cmdId = cmdId;
|
this.data = data;
|
}
|
|
// ================= 业务工厂方法 (推荐使用) =================
|
|
/**
|
* 创建调焦指令
|
* @param cameraId 相机ID
|
* @param isPlus true为调焦+,false为调焦-
|
*/
|
public static ThermalCommand createFocusCmd(String cameraId, boolean isPlus) {
|
byte val = isPlus ? FOCUS_PLUS_VAL : FOCUS_MINUS_VAL;
|
return new ThermalCommand(cameraId, CMD_FOCUS, new byte[]{val});
|
}
|
|
/**
|
* 创建调焦停止指令
|
*/
|
public static ThermalCommand createFocusStopCmd(String cameraId) {
|
return new ThermalCommand(cameraId, CMD_FOCUS_STOP, null);
|
}
|
/**
|
* 创建调焦指令
|
* @param cameraId 相机ID
|
* @param isPlus true为变倍+,false为变倍-
|
*/
|
public static ThermalCommand createZoomCmd(String cameraId, boolean isPlus) {
|
byte value = isPlus ? (byte) 0x00 : (byte) 0x0F;
|
return new ThermalCommand(cameraId, CMD_ZOOM, new byte[]{value});
|
}
|
/**
|
* 创建自动调焦指令
|
*/
|
public static ThermalCommand createAutoFocusCmd(String cameraId) {
|
return new ThermalCommand(cameraId, CMD_AUTO_FOCUS, null);
|
}
|
|
/**
|
* 创建统一速度指令
|
* 变倍和调焦使用相同的速度值
|
* @param speed 速度 (0-15)
|
*/
|
public static ThermalCommand createUniformSpeedCmd(String cameraId, int speed) {
|
// 确保数据在 0-15 范围内
|
speed = Math.max(0, Math.min(15, speed));
|
|
// 位运算拼接:(speed << 4) | speed
|
// 例如 speed=10 (0xA) -> 0xAA
|
byte data = (byte) ((speed << 4) | speed);
|
|
return new ThermalCommand(cameraId, CMD_MOTOR_SPEED, new byte[]{data});
|
}
|
|
}
|