| | |
| | | |
| | | import com.sun.jna.Native; |
| | | import com.sun.jna.Pointer; |
| | | import com.sun.jna.ptr.IntByReference; |
| | | import com.ycl.api.DH.lib.NetSDKLib; |
| | | import com.ycl.api.DH.lib.NetSDKLib.LLong; |
| | | import com.ycl.api.DH.lib.NetSDKLib.NET_IN_LOGIN_WITH_HIGHLEVEL_SECURITY; |
| | | import com.ycl.api.DH.lib.NetSDKLib.NET_OUT_LOGIN_WITH_HIGHLEVEL_SECURITY; |
| | | import com.ycl.api.DH.lib.ToolKits; |
| | | import com.ycl.api.DH.lib.structure.NET_CFG_GBMODE_INFO; |
| | | import com.ycl.api.DH.lib.structure.NET_GBMODE_CUSTOMTITLE_INFO; |
| | | import com.ycl.api.DH.lib.structure.NET_TITLE_OSD_INFO; |
| | | 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; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.text.ParseException; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Arrays; |
| | | import java.util.Date; |
| | | |
| | | import static com.ycl.api.DH.lib.NetSDKLib.NET_EM_OSD_BLEND_TYPE.NET_EM_OSD_BLEND_TYPE_MAIN; |
| | | import static com.ycl.api.DH.lib.enumeration.NET_EM_CFG_OPERATE_TYPE.NET_EM_CFG_CUSTOMTITLE; |
| | |
| | | |
| | | public static NetSDKLib netsdk = NetSDKLib.NETSDK_INSTANCE; |
| | | public static NetSDKLib configsdk = NetSDKLib.CONFIG_INSTANCE; |
| | | |
| | | // 设备信息 |
| | | public static NetSDKLib.NET_DEVICEINFO_Ex m_stDeviceInfo = new NetSDKLib.NET_DEVICEINFO_Ex(); |
| | | |
| | | // 登陆句柄 |
| | | public static LLong m_hLoginHandle = new LLong(0); |
| | | |
| | | private static boolean bInit = false; |
| | | private static boolean bLogopen = false; |
| | |
| | | netsdk.CLIENT_SetAutoReconnect(haveReConnect, null); |
| | | |
| | | //设置登录超时时间和尝试次数,可选 |
| | | int waitTime = 5000; //登录请求响应超时时间设置为5S |
| | | int waitTime = 3000; //登录请求响应超时时间设置为5S |
| | | int tryTimes = 1; //登录时尝试建立链接1次 |
| | | netsdk.CLIENT_SetConnectTime(waitTime, tryTimes); |
| | | |
| | |
| | | // 设置更多网络参数,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); |
| | |
| | | * 登录设备 |
| | | * \endif |
| | | */ |
| | | public static long login(String m_strIp, int m_nPort, String m_strUser, String m_strPassword) { |
| | | public static LLong login(String m_strIp, int m_nPort, String m_strUser, String m_strPassword) { |
| | | //IntByReference nError = new IntByReference(0); |
| | | //入参 |
| | | NET_IN_LOGIN_WITH_HIGHLEVEL_SECURITY pstInParam = new NET_IN_LOGIN_WITH_HIGHLEVEL_SECURITY(); |
| | |
| | | pstInParam.szPassword = m_strPassword.getBytes(); |
| | | pstInParam.szUserName = m_strUser.getBytes(); |
| | | //出参 |
| | | //设备信息 |
| | | NetSDKLib.NET_DEVICEINFO_Ex m_stDeviceInfo = new NetSDKLib.NET_DEVICEINFO_Ex(); |
| | | NET_OUT_LOGIN_WITH_HIGHLEVEL_SECURITY pstOutParam = new NET_OUT_LOGIN_WITH_HIGHLEVEL_SECURITY(); |
| | | pstOutParam.stuDeviceInfo = m_stDeviceInfo; |
| | | //m_hLoginHandle = netsdk.CLIENT_LoginEx2(m_strIp, m_nPort, m_strUser, m_strPassword, 0, null, m_stDeviceInfo, nError); |
| | | // 登陆句柄 |
| | | LLong m_hLoginHandle = new LLong(0); |
| | | m_hLoginHandle = netsdk.CLIENT_LoginWithHighLevelSecurity(pstInParam, pstOutParam); |
| | | if (m_hLoginHandle.longValue() == 0) { |
| | | System.err.printf("Login Device[%s] Port[%d]Failed. %s\n", m_strIp, m_nPort, ToolKits.getErrorCodePrint()); |
| | | // System.err.printf("Login Device[%s] Port[%d]Failed. %s\n", m_strIp, m_nPort, ToolKits.getErrorCodePrint()); |
| | | } else { |
| | | System.out.println("Login Success [ " + m_strIp + " ]"); |
| | | log.info("登录成功"); |
| | | // System.out.println("Login Success [ " + m_strIp + " ]"); |
| | | // log.info("登录成功"); |
| | | } |
| | | |
| | | return m_hLoginHandle.longValue(); |
| | | return m_hLoginHandle; |
| | | } |
| | | |
| | | /** |
| | |
| | | * 登出设备 |
| | | * \endif |
| | | */ |
| | | public static boolean logout() { |
| | | if (m_hLoginHandle.longValue() == 0) { |
| | | return false; |
| | | } |
| | | |
| | | boolean bRet = netsdk.CLIENT_Logout(m_hLoginHandle); |
| | | if (bRet) { |
| | | m_hLoginHandle.setValue(0); |
| | | } |
| | | |
| | | public static boolean logout(LLong loginId) { |
| | | boolean bRet = netsdk.CLIENT_Logout(loginId); |
| | | return bRet; |
| | | } |
| | | |
| | | public static String getOsdTime() { |
| | | public static OSDResult getOsd(String serialNumber,LLong loginId) { |
| | | OSDResult osdResult = new OSDResult(); |
| | | NetSDKLib.NET_TIME deviceTime = new NetSDKLib.NET_TIME(); |
| | | |
| | | if (!netsdk.CLIENT_QueryDeviceTime(m_hLoginHandle, deviceTime, 3000)) { |
| | | System.err.println("CLIENT_QueryDeviceTime Failed!" + ToolKits.getErrorCodePrint()); |
| | | if (!netsdk.CLIENT_QueryDeviceTime(loginId, deviceTime, 3000)) { |
| | | // log.error("CLIENT_QueryDeviceTime Failed!" + ToolKits.getErrorCodePrint()); |
| | | return null; |
| | | } |
| | | NetSDKLib.NET_OSD_CUSTOM_TITLE custom_title = new NetSDKLib.NET_OSD_CUSTOM_TITLE(); |
| | | Date checkTime = new Date(); |
| | | osdResult.setCheckTime(checkTime); |
| | | String date = deviceTime.toStringTime(); |
| | | date = date.replace("/", "-"); |
| | | log.info("成功获取检测osd时间" + date); |
| | | SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); |
| | | try { |
| | | Date time = simpleDateFormat.parse(date); |
| | | osdResult.setOsdTime(time); |
| | | } catch (ParseException e) { |
| | | // log.error("时间解析失败"); |
| | | } |
| | | NET_CFG_GBMODE_INFO reserve = new NET_CFG_GBMODE_INFO(); |
| | | |
| | | NET_CFG_GBMODE_INFO osdInfo = new NET_CFG_GBMODE_INFO(); |
| | | osdInfo.write(); |
| | | Pointer pointer = osdInfo.getPointer(); |
| | | boolean b = netsdk.CLIENT_GetConfig(m_hLoginHandle, NET_EM_CFG_CUSTOMTITLE, 0, custom_title.getPointer(), 1024, 3000, null); |
| | | // log.info("osd结果,自定义标题信息有效个数:{},是否叠加到预览显示{},是否叠加到主码流视频编码{}" ,osdInfo.nCustomTitleNum,osdInfo.bPreviewBlend,osdInfo.bEncodeBlend); |
| | | if(!b){ |
| | | log.info("调用失败"); |
| | | }else { |
| | | 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; |
| | | } else { |
| | | osdInfo.read(); |
| | | log.info("osd结果,自定义标题信息有效个数:{},是否叠加到预览显示{},是否叠加到主码流视频编码{}" ,osdInfo.nCustomTitleNum,osdInfo.bPreviewBlend,osdInfo.bEncodeBlend); |
| | | NET_GBMODE_CUSTOMTITLE_INFO[] stuCustomTitle = osdInfo.stuCustomTitle; |
| | | for (NET_GBMODE_CUSTOMTITLE_INFO title : stuCustomTitle) { |
| | | NET_TITLE_OSD_INFO[] stuOSD = title.stuOSD; |
| | | for (NET_TITLE_OSD_INFO osd : stuOSD) { |
| | | String osdStr = null; |
| | | log.info("----->"+ Arrays.toString(osd.szText)); |
| | | try { |
| | | osdStr = new String(osd.szText, "GBK"); |
| | | } catch (UnsupportedEncodingException e) { |
| | | 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).trim(); |
| | | // log.info("TEXT:"+osdStr); |
| | | if (!StringUtils.isEmpty(osdStr)) { |
| | | osdResult.setOSD4(osdStr); |
| | | } |
| | | } |
| | | log.info("osd二级文本" + osd+osdStr); |
| | | }else if("RightDown".equals(position)){ |
| | | NET_TITLE_OSD_INFO[] stuOSD = title.stuOSD; |
| | | int num = 0; |
| | | for (NET_TITLE_OSD_INFO osd : stuOSD) { |
| | | String osdStr = null; |
| | | osdStr = new String(osd.szText, StandardCharsets.UTF_8).trim(); |
| | | // log.info("TEXT:"+osdStr); |
| | | if (!StringUtils.isEmpty(osdStr)) { |
| | | if(num ==0){ |
| | | osdResult.setOSD1(osdStr); |
| | | }else if(num ==1){ |
| | | osdResult.setOSD2(osdStr); |
| | | }else if(num ==2){ |
| | | osdResult.setOSD3(osdStr); |
| | | }else if(num ==3){ |
| | | osdResult.setName(osdStr); |
| | | } |
| | | } |
| | | num++; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | return date; |
| | | osdResult.setDeviceBrand(DeviceType.DH.getType()); |
| | | return osdResult; |
| | | } |
| | | |
| | | } |