From 97b1e0d4820606bef726f60e459b66afb1e8eab1 Mon Sep 17 00:00:00 2001
From: zxl <763096477@qq.com>
Date: 星期五, 21 十一月 2025 11:50:51 +0800
Subject: [PATCH] 优化与日志
---
ycl-server/src/main/java/com/ycl/api/DH/module/LoginModule.java | 222 ++++++++++++++++++++++++++++++++++++++++++++-----------
1 files changed, 178 insertions(+), 44 deletions(-)
diff --git a/ycl-server/src/main/java/com/ycl/api/DH/module/LoginModule.java b/ycl-server/src/main/java/com/ycl/api/DH/module/LoginModule.java
index 6064fcb..c169561 100644
--- a/ycl-server/src/main/java/com/ycl/api/DH/module/LoginModule.java
+++ b/ycl-server/src/main/java/com/ycl/api/DH/module/LoginModule.java
@@ -2,6 +2,7 @@
import com.sun.jna.Native;
import com.sun.jna.Pointer;
+import com.sun.jna.Structure;
import com.sun.jna.ptr.IntByReference;
import com.ycl.api.DH.lib.NetSDKLib;
import com.ycl.api.DH.lib.NetSDKLib.LLong;
@@ -11,16 +12,23 @@
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.Charset;
import java.nio.charset.StandardCharsets;
import java.text.ParseException;
import java.text.SimpleDateFormat;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
+import java.util.List;
+import static com.ycl.api.DH.lib.NetSDKLib.CFG_CMD_VIDEOWIDGET;
+import static com.ycl.api.DH.lib.NetSDKLib.NET_DEV_VIDEO_OSD_CFG;
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;
import static com.ycl.api.DH.lib.enumeration.NET_EM_CFG_OPERATE_TYPE.NET_EM_CFG_GBMODE;
@@ -34,12 +42,6 @@
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;
@@ -80,7 +82,7 @@
netsdk.CLIENT_SetAutoReconnect(haveReConnect, null);
//璁剧疆鐧诲綍瓒呮椂鏃堕棿鍜屽皾璇曟鏁帮紝鍙��
- int waitTime = 5000; //鐧诲綍璇锋眰鍝嶅簲瓒呮椂鏃堕棿璁剧疆涓�5S
+ int waitTime = 3000; //鐧诲綍璇锋眰鍝嶅簲瓒呮椂鏃堕棿璁剧疆涓�5S
int tryTimes = 1; //鐧诲綍鏃跺皾璇曞缓绔嬮摼鎺�1娆�
netsdk.CLIENT_SetConnectTime(waitTime, tryTimes);
@@ -88,7 +90,7 @@
// 璁剧疆鏇村缃戠粶鍙傛暟锛孨ET_PARAM鐨刵Waittime锛宯ConnectTryNum鎴愬憳涓嶤LIENT_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);
@@ -120,7 +122,7 @@
* 鐧诲綍璁惧
* \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();
@@ -129,18 +131,20 @@
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;
}
/**
@@ -150,24 +154,16 @@
* 鐧诲嚭璁惧
* \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 OSDResult getOsd() {
+ 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)) {
- log.error("CLIENT_QueryDeviceTime Failed!" + ToolKits.getErrorCodePrint());
+ if (!netsdk.CLIENT_QueryDeviceTime(loginId, deviceTime, 3000)) {
+// log.error("CLIENT_QueryDeviceTime Failed!" + ToolKits.getErrorCodePrint());
return null;
}
Date checkTime = new Date();
@@ -179,45 +175,66 @@
Date time = simpleDateFormat.parse(date);
osdResult.setOsdTime(time);
} catch (ParseException e) {
- log.error("鏃堕棿瑙f瀽澶辫触");
+// log.error("鏃堕棿瑙f瀽澶辫触");
}
NET_CFG_GBMODE_INFO reserve = new NET_CFG_GBMODE_INFO();
-
NET_CFG_GBMODE_INFO osdInfo = new NET_CFG_GBMODE_INFO();
osdInfo.write();
- boolean b = netsdk.CLIENT_GetConfig(m_hLoginHandle, 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());
+// log.error("CLIENT_GetConfig Failed!" + ToolKits.getErrorCodePrint());
return null;
} else {
osdInfo.read();
NET_GBMODE_CUSTOMTITLE_INFO[] stuCustomTitle = osdInfo.stuCustomTitle;
for (NET_GBMODE_CUSTOMTITLE_INFO title : stuCustomTitle) {
String position = new String(title.szPositon, StandardCharsets.UTF_8).trim();
- if("LeftDown".equals(position)) {
+ 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.error("DHTEXTLeftDown锛�"+osdStr);
if (!StringUtils.isEmpty(osdStr)) {
osdResult.setOSD4(osdStr);
}
}
- }else if("RightDown".equals(position)){
+ } 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);
+ osdStr = new String(osd.szText, StandardCharsets.UTF_8).trim();
+ log.error("DHTEXTRightDown锛�"+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);
+ if (osdStr.contains("|")) {
+ String[] osdNames = osdStr.split("\\|");
+ osdResult.setOSD1(osdNames[0]);
+ osdResult.setOSD2(osdNames[1]);
+ osdResult.setOSD3(osdNames[2]);
+ osdResult.setName(osdNames[3]);
+ } else {
+ 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++;
@@ -225,7 +242,124 @@
}
}
}
+ osdResult.setDeviceBrand(DeviceType.DH.getType());
return osdResult;
}
+ /**
+ * 閽堝鍒╂棫璁惧鑾峰彇OSD鐨勬柟娉�
+ *
+ * @param serialNumber
+ * @param loginId
+ * @return
+ */
+ public static OSDResult getOsdOld(String moName,String serialNumber, LLong loginId) {
+ OSDResult result = new OSDResult();
+ NetSDKLib.NET_OSD_CUSTOM_TITLE osdInfo4 = new NetSDKLib.NET_OSD_CUSTOM_TITLE();
+ osdInfo4.emOsdBlendType = NetSDKLib.NET_EM_OSD_BLEND_TYPE.NET_EM_OSD_BLEND_TYPE_MAIN;
+ NetSDKLib.NET_OSD_CUSTOM_TITLE reserve4 = new NetSDKLib.NET_OSD_CUSTOM_TITLE();
+ osdInfo4.write();
+ boolean e = false;
+ if (moName.startsWith("DX_R2")){ //鍒ゆ柇璁惧鏄惁鏄疍X_R2寮�澶�
+ if (serialNumber.charAt(ApiConstants.SerialNumber_Channel) == ApiConstants.SerialNumber_All) {
+ e = netsdk.CLIENT_GetConfig(loginId, NET_EM_CFG_CUSTOMTITLE, 0, osdInfo4.getPointer(), osdInfo4.size(), 3000, reserve4.getPointer());
+ }
+ else if (serialNumber.charAt(ApiConstants.SerialNumber_Channel) == ApiConstants.SerialNumber_Detail) {
+ e = netsdk.CLIENT_GetConfig(loginId, NET_EM_CFG_CUSTOMTITLE, 1, osdInfo4.getPointer(), osdInfo4.size(), 3000, reserve4.getPointer());
+ }
+ if (!e) {
+ log.error("e涓虹┖");
+ }
+ }else if(moName.startsWith("DX_RD")){ //鍒ゆ柇璁惧鏄惁鏄疍X_RD寮�澶�
+ if (serialNumber.charAt(ApiConstants.SerialNumber_Channel) == ApiConstants.SerialNumber_All) {
+ e = netsdk.CLIENT_GetConfig(loginId, NET_EM_CFG_CUSTOMTITLE, 0, osdInfo4.getPointer(), osdInfo4.size(), 3000, reserve4.getPointer());
+ }
+ else if (serialNumber.charAt(ApiConstants.SerialNumber_Channel) == ApiConstants.SerialNumber_Detail) {
+ e = netsdk.CLIENT_GetConfig(loginId, NET_EM_CFG_CUSTOMTITLE, 1, osdInfo4.getPointer(), osdInfo4.size(), 3000, reserve4.getPointer());
+ }
+ if (!e) {
+ log.error("e涓虹┖");
+ }
+ }else {
+ e = netsdk.CLIENT_GetConfig(loginId, NET_EM_CFG_CUSTOMTITLE, 0, osdInfo4.getPointer(), osdInfo4.size(), 3000, reserve4.getPointer());
+ if (!e) {
+ log.error("e涓虹┖,灏濊瘯鍙︿竴涓�氶亾");
+ e = netsdk.CLIENT_GetConfig(loginId, NET_EM_CFG_CUSTOMTITLE, 1, osdInfo4.getPointer(), osdInfo4.size(), 3000, reserve4.getPointer());
+ }
+ }
+ if (e) {
+ osdInfo4.read();
+ NetSDKLib.NET_CUSTOM_TITLE_INFO[] stuCustomTitle = osdInfo4.stuCustomTitle;
+ for (NetSDKLib.NET_CUSTOM_TITLE_INFO net_custom_title_info : stuCustomTitle) {
+ String name = new String(net_custom_title_info.szText, StandardCharsets.UTF_8).trim();
+ log.error("DHname:{}", name);
+ if (StringUtils.isNotEmpty(name) && name.contains("|")) {
+ String[] osdNames = name.split("\\|");
+ //鍓旈櫎鎺夌┖涓�
+// List<String> nonEmptyList = new ArrayList<>();
+// for (String osd : osdNames) {
+// if (StringUtils.isNotEmpty(osd)) {
+// nonEmptyList.add(osd);
+// }
+// }
+ for (int i = 0; i < osdNames.length; i++) {
+ if (i == 0) {
+ result.setOSD1(osdNames[i]);
+ }
+ if (i == 1) {
+ result.setOSD2(osdNames[i]);
+ }
+ if (i == 2) {
+ result.setOSD3(osdNames[i]);
+ }
+ if (i == 3) {
+ result.setName(osdNames[i]);
+ }
+ }
+
+
+ }
+ }
+
+
+ } else {
+ log.error(serialNumber, "鍒╂棫osd涓虹┖");
+ }
+
+ return result;
+ }
+
+ /**
+ * 鑾峰彇鍗曚釜閰嶇疆
+ *
+ * @param hLoginHandle 鐧婚檰鍙ユ焺
+ * @param nChn 閫氶亾鍙凤紝-1 琛ㄧず鍏ㄩ�氶亾
+ * @param strCmd 閰嶇疆鍚嶇О
+ * @param cmdObject 閰嶇疆瀵瑰簲鐨勭粨鏋勪綋瀵硅薄
+ * @return 鎴愬姛杩斿洖 true
+ */
+ public static boolean GetDevConfig(LLong hLoginHandle, int nChn, String strCmd, Structure cmdObject) {
+ boolean result = false;
+ IntByReference error = new IntByReference(0);
+ int nBufferLen = 2 * 1024 * 1024;
+ byte[] strBuffer = new byte[nBufferLen];
+
+ if (netsdk.CLIENT_GetNewDevConfig(hLoginHandle, strCmd, nChn, strBuffer, nBufferLen, error, 3000, null)) {
+ cmdObject.write();
+ if (netsdk.CLIENT_ParseData(strCmd, strBuffer, cmdObject.getPointer(),
+ cmdObject.size(), null)) {
+ cmdObject.read();
+ result = true;
+ } else {
+ System.err.println("Parse " + strCmd + " Config Failed!" + ToolKits.getErrorCodePrint());
+ result = false;
+ }
+ } else {
+ System.err.println("璋冪敤澶辫触");
+ result = false;
+ }
+
+ return result;
+ }
+
}
--
Gitblit v1.8.0