liusuyi
2026-05-18 b5cd784d0cde5b7c82ea78aef4ac0e5a161d8c5d
ard-modules/ard-modules-work/src/main/java/com/ard/work/sdk/hik/service/AbstractHikVisionSDK.java
@@ -41,6 +41,7 @@
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.util.StopWatch;
import org.springframework.web.multipart.MultipartFile;
import java.awt.geom.Point2D;
import java.io.ByteArrayInputStream;
import java.io.File;
@@ -703,34 +704,41 @@
        String cameraId = cmd.getCameraId();
        Integer chanNo = cmd.getChanNo();
        int userId = cmd.getLoginId().intValue();
        NET_DVR_PTZPOS m_ptzPosCurrent = new NET_DVR_PTZPOS();
        Pointer point = m_ptzPosCurrent.getPointer();
        IntByReference ibrBytesReturned = new IntByReference(0);
        m_ptzPosCurrent.write();
        boolean bool = hCNetSDK.NET_DVR_GetDVRConfig(userId, HCNetSDK.NET_DVR_GET_PTZPOS, chanNo, point,
                m_ptzPosCurrent.size(), ibrBytesReturned);
        if (!bool) {
            int errorCode = hCNetSDK.NET_DVR_GetLastError();
            String errorDesc = SdkErrorCodeEnum.getDescByCode(errorCode);
            String errorMsg = String.format("获取ptz失败,错误码:%s,原因:%s", errorCode, errorDesc);
            log.warn(errorMsg);
            return null;
        ArdCamera camera = getCamera(cameraId);
        if ("1".equals(camera.getType())) {
            return getPtzHigh(cmd);
        } else {
            NET_DVR_PTZPOS m_ptzPosCurrent = new NET_DVR_PTZPOS();
            Pointer point = m_ptzPosCurrent.getPointer();
            IntByReference ibrBytesReturned = new IntByReference(0);
            m_ptzPosCurrent.write();
            boolean bool = hCNetSDK.NET_DVR_GetDVRConfig(userId, HCNetSDK.NET_DVR_GET_PTZPOS, chanNo, point,
                    m_ptzPosCurrent.size(), ibrBytesReturned);
            if (!bool) {
                int errorCode = hCNetSDK.NET_DVR_GetLastError();
                String errorDesc = SdkErrorCodeEnum.getDescByCode(errorCode);
                String errorMsg = String.format("获取ptz失败,错误码:%s,原因:%s", errorCode, errorDesc);
                log.warn(errorMsg);
                return null;
            }
            m_ptzPosCurrent.read();
            // DecimalFormat df = new DecimalFormat("0.0");//设置保留位数
            //16进制转Integer后除10,保留小数点1位
            //实际显示的PTZ值是获取到的十六进制值的十分之一,
            //如获取的水平参数P的值是0x1750,实际显示的P值为175度;
            //获取到的垂直参数T的值是0x0789,实际显示的T值为78.9度;
            //获取到的变倍参数Z的值是0x1100,实际显示的Z值为110倍。
            BigDecimal b =
                    BigDecimal.valueOf((float) Integer.parseInt(Integer.toHexString(m_ptzPosCurrent.wPanPos)) / 10);
            BigDecimal c =
                    BigDecimal.valueOf((float) Integer.parseInt(Integer.toHexString(m_ptzPosCurrent.wTiltPos)) / 10);
            BigDecimal d =
                    BigDecimal.valueOf((float) Integer.parseInt(Integer.toHexString(m_ptzPosCurrent.wZoomPos)) / 10);
            float p = b.setScale(1, RoundingMode.HALF_UP).floatValue();
            float t = c.setScale(1, RoundingMode.HALF_UP).floatValue();
            float z = d.setScale(1, RoundingMode.HALF_UP).floatValue();
            return new PtzDto(p, t, z);
        }
        m_ptzPosCurrent.read();
        // DecimalFormat df = new DecimalFormat("0.0");//设置保留位数
        //16进制转Integer后除10,保留小数点1位
        //实际显示的PTZ值是获取到的十六进制值的十分之一,
        //如获取的水平参数P的值是0x1750,实际显示的P值为175度;
        //获取到的垂直参数T的值是0x0789,实际显示的T值为78.9度;
        //获取到的变倍参数Z的值是0x1100,实际显示的Z值为110倍。
        BigDecimal b = BigDecimal.valueOf((float) Integer.parseInt(Integer.toHexString(m_ptzPosCurrent.wPanPos)) / 10);
        BigDecimal c = BigDecimal.valueOf((float) Integer.parseInt(Integer.toHexString(m_ptzPosCurrent.wTiltPos)) / 10);
        BigDecimal d = BigDecimal.valueOf((float) Integer.parseInt(Integer.toHexString(m_ptzPosCurrent.wZoomPos)) / 10);
        float p = b.setScale(1, RoundingMode.HALF_UP).floatValue();
        float t = c.setScale(1, RoundingMode.HALF_UP).floatValue();
        float z = d.setScale(1, RoundingMode.HALF_UP).floatValue();
        return new PtzDto(p, t, z);
    }
    /**
@@ -741,8 +749,7 @@
     * @author 刘苏义
     * @date 2024/9/5 17:00
     */
    @Override
    public PtzDto getPtzHigh(CameraCmd cmd) {
    private PtzDto getPtzHigh(CameraCmd cmd) {
        try {
            String cameraId = cmd.getCameraId();
            Integer chanNo = cmd.getChanNo();
@@ -796,30 +803,39 @@
        Integer channelNum = cmd.getChanNo();
        PtzDto ptzDto = cmd.getPtzDto();
        int userId = cmd.getLoginId().intValue();
        NET_DVR_PTZPOS m_ptzPosCurrent = new NET_DVR_PTZPOS();
        m_ptzPosCurrent.wAction = 1;
        try {
            String p = String.valueOf((int) (ptzDto.getP() * 10));
            String t = String.valueOf((int) (ptzDto.getT() * 10));
            String z = String.valueOf((int) (ptzDto.getZ() * 10));
            m_ptzPosCurrent.wPanPos = (short) (Integer.parseInt(p, 16));
            m_ptzPosCurrent.wTiltPos = (short) (Integer.parseInt(t, 16));
            m_ptzPosCurrent.wZoomPos = (short) (Integer.parseInt(z, 16));
            Pointer point = m_ptzPosCurrent.getPointer();
            m_ptzPosCurrent.write();
            boolean bool = hCNetSDK.NET_DVR_SetDVRConfig(userId, NET_DVR_SET_PTZPOS, channelNum, point,
                    m_ptzPosCurrent.size());
            if (!bool) {
                int errorCode = hCNetSDK.NET_DVR_GetLastError();
                String errorDesc = SdkErrorCodeEnum.getDescByCode(errorCode);
                String errorMsg = String.format("设置PTZ参数失败,错误码:%s,原因:%s", errorCode, errorDesc);
                log.warn(errorMsg);
        ArdCamera camera = getCamera(cameraId);
        if ("1".equals(camera.getType())) {
            DeviceCFG systemInfo = getSystemInfo(cmd);
            if (systemInfo != null && "5.5.112".equals(systemInfo.getDwSoftwareVersion())) {
                return setPtzHighT(cmd);
            }
            return setPtzHigh(cmd);
        } else {
            NET_DVR_PTZPOS m_ptzPosCurrent = new NET_DVR_PTZPOS();
            m_ptzPosCurrent.wAction = 1;
            try {
                String p = String.valueOf((int) (ptzDto.getP() * 10));
                String t = String.valueOf((int) (ptzDto.getT() * 10));
                String z = String.valueOf((int) (ptzDto.getZ() * 10));
                m_ptzPosCurrent.wPanPos = (short) (Integer.parseInt(p, 16));
                m_ptzPosCurrent.wTiltPos = (short) (Integer.parseInt(t, 16));
                m_ptzPosCurrent.wZoomPos = (short) (Integer.parseInt(z, 16));
                Pointer point = m_ptzPosCurrent.getPointer();
                m_ptzPosCurrent.write();
                boolean bool = hCNetSDK.NET_DVR_SetDVRConfig(userId, NET_DVR_SET_PTZPOS, channelNum, point,
                        m_ptzPosCurrent.size());
                if (!bool) {
                    int errorCode = hCNetSDK.NET_DVR_GetLastError();
                    String errorDesc = SdkErrorCodeEnum.getDescByCode(errorCode);
                    String errorMsg = String.format("设置PTZ参数失败,错误码:%s,原因:%s", errorCode, errorDesc);
                    log.warn(errorMsg);
                    return false;
                }
                return true;
            } catch (Exception ex) {
                log.error(ex.getMessage());
                return false;
            }
            return true;
        } catch (Exception ex) {
            log.error(ex.getMessage());
            return false;
        }
    }
@@ -832,8 +848,7 @@
     * @author 刘苏义
     * @date 2024/9/5 17:04
     */
    @Override
    public Boolean setPtzHighT(CameraCmd cmd) {
    private Boolean setPtzHighT(CameraCmd cmd) {
        String cameraId = cmd.getCameraId();
        Integer chanNo = cmd.getChanNo();
        PtzDto ptzDto = cmd.getPtzDto();
@@ -893,8 +908,7 @@
    }
    //非透传 旧设备使用 新固件会导致2通道不自动聚焦
    @Override
    public Boolean setPtzHigh(CameraCmd cmd) {
    private Boolean setPtzHigh(CameraCmd cmd) {
        String cameraId = cmd.getCameraId();
        Integer chanNo = cmd.getChanNo();
        PtzDto ptzDto = cmd.getPtzDto();
@@ -1842,6 +1856,7 @@
            return false;
        }
    }
    @Override
    public String recordStop(CameraCmd cmd) {
        String url = "";
@@ -2434,4 +2449,15 @@
            return true;
        }
    }
    /**
     * 获取相机信息(会校验存在性)
     */
    private ArdCamera getCamera(String cameraId) {
        ArdCamera camera = redisService.getCacheMapValue(CacheConstants.CAMERA_LIST, cameraId);
        if (camera == null) {
            throw CameraSDKException.cameraNotExist(cameraId);
        }
        return camera;
    }
}