fuliqi
2025-01-16 edc7172b312e0aec94362b651e2f7145e0c357fe
ycl-server/src/main/java/com/ycl/api/DH/module/LoginModule.java
@@ -11,6 +11,8 @@
import com.ycl.api.DH.lib.structure.*;
import com.ycl.platform.domain.result.OSDResult;
import com.ycl.utils.StringUtils;
import constant.ApiConstants;
import enumeration.DeviceType;
import lombok.extern.slf4j.Slf4j;
import java.io.File;
@@ -74,7 +76,7 @@
        netsdk.CLIENT_SetAutoReconnect(haveReConnect, null);
        //设置登录超时时间和尝试次数,可选
        int waitTime = 5000; //登录请求响应超时时间设置为5S
        int waitTime = 3000; //登录请求响应超时时间设置为5S
        int tryTimes = 1;    //登录时尝试建立链接1次
        netsdk.CLIENT_SetConnectTime(waitTime, tryTimes);
@@ -82,7 +84,7 @@
        // 设置更多网络参数,NET_PARAM的nWaittime,nConnectTryNum成员与CLIENT_SetConnectTime
        // 接口设置的登录设备超时时间和尝试次数意义相同,可选
        NetSDKLib.NET_PARAM netParam = new NetSDKLib.NET_PARAM();
        netParam.nConnectTime = 10000;      // 登录时尝试建立链接的超时时间
        netParam.nConnectTime = 3000;      // 登录时尝试建立链接的超时时间
        netParam.nGetConnInfoTime = 3000;   // 设置子连接的超时时间
        netParam.nGetDevInfoTime = 3000;//获取设备信息超时时间,为0默认1000ms
        netsdk.CLIENT_SetNetworkParam(netParam);
@@ -130,7 +132,6 @@
        // 登陆句柄
        LLong m_hLoginHandle = new LLong(0);
        m_hLoginHandle = netsdk.CLIENT_LoginWithHighLevelSecurity(pstInParam, pstOutParam);
        log.info("大华登录"+m_hLoginHandle);
        if (m_hLoginHandle.longValue() == 0) {
//            System.err.printf("Login Device[%s] Port[%d]Failed. %s\n", m_strIp, m_nPort, ToolKits.getErrorCodePrint());
        } else {
@@ -152,13 +153,14 @@
        return bRet;
    }
    public static OSDResult getOsd(LLong loginId) {
    public static OSDResult getOsd(String serialNumber,LLong loginId) {
        OSDResult osdResult = new OSDResult();
        NetSDKLib.NET_TIME deviceTime = new NetSDKLib.NET_TIME();
        if (!netsdk.CLIENT_QueryDeviceTime(loginId, deviceTime, 3000)) {
//            log.error("CLIENT_QueryDeviceTime Failed!" + ToolKits.getErrorCodePrint());
            return null;
        }
        log.info("OSD时间原始数据格式,{},toString格式{}",deviceTime,deviceTime.toStringTime());
        Date checkTime = new Date();
        osdResult.setCheckTime(checkTime);
        String date = deviceTime.toStringTime();
@@ -174,7 +176,19 @@
        NET_CFG_GBMODE_INFO osdInfo = new NET_CFG_GBMODE_INFO();
        osdInfo.write();
        boolean b = netsdk.CLIENT_GetConfig(loginId, NET_EM_CFG_GBMODE, 0, osdInfo.getPointer(), osdInfo.size(), 3000, reserve.getPointer());
        boolean b = false;
        /**
         * 通过国标倒数第七位判断通道 0/全景 1/细节
         * 对于海康来说: 国标倒7: 0/全景/通道2 1/细节/通道1
         * 对于大华来说: 国标倒7: 0/全景/通道1 1/细节/通道2
         * 宇视单通道不考虑
         */
        if(serialNumber.charAt(ApiConstants.SerialNumber_Channel) == ApiConstants.SerialNumber_All ) {
            b = netsdk.CLIENT_GetConfig(loginId, NET_EM_CFG_GBMODE, 0, osdInfo.getPointer(), osdInfo.size(), 3000, reserve.getPointer());
        }else if(serialNumber.charAt(ApiConstants.SerialNumber_Channel) == ApiConstants.SerialNumber_Detail){
            b = netsdk.CLIENT_GetConfig(loginId, NET_EM_CFG_GBMODE, 1, osdInfo.getPointer(), osdInfo.size(), 3000, reserve.getPointer());
        }
        if (!b) {
//            log.error("CLIENT_GetConfig Failed!" + ToolKits.getErrorCodePrint());
            return null;
@@ -182,12 +196,14 @@
            osdInfo.read();
            NET_GBMODE_CUSTOMTITLE_INFO[] stuCustomTitle = osdInfo.stuCustomTitle;
            for (NET_GBMODE_CUSTOMTITLE_INFO title : stuCustomTitle) {
                log.info("OSD原始数据格式{}",title);
                String position = new String(title.szPositon, StandardCharsets.UTF_8).trim();
                if("LeftDown".equals(position)) {
                    NET_TITLE_OSD_INFO[] stuOSD = title.stuOSD;
                    for (NET_TITLE_OSD_INFO osd : stuOSD) {
                        String osdStr = null;
                        osdStr = new String(osd.szText, StandardCharsets.UTF_8);
                        osdStr = new String(osd.szText, StandardCharsets.UTF_8).trim();
//                        log.info("TEXT:"+osdStr);
                        if (!StringUtils.isEmpty(osdStr)) {
                            osdResult.setOSD4(osdStr);
                        }
@@ -197,7 +213,8 @@
                    int num = 0;
                    for (NET_TITLE_OSD_INFO osd : stuOSD) {
                        String osdStr = null;
                        osdStr = new String(osd.szText, StandardCharsets.UTF_8);
                        osdStr = new String(osd.szText, StandardCharsets.UTF_8).trim();
//                        log.info("TEXT:"+osdStr);
                        if (!StringUtils.isEmpty(osdStr)) {
                            if(num ==0){
                                osdResult.setOSD1(osdStr);
@@ -214,6 +231,7 @@
                }
            }
        }
        osdResult.setDeviceBrand(DeviceType.DH.getType());
        return osdResult;
    }