From 3591fc47eaa3e301252dc06d257d46bd3a45e120 Mon Sep 17 00:00:00 2001 From: liusuyi <13324259@qq.com> Date: 星期一, 23 十月 2023 22:10:19 +0800 Subject: [PATCH] 相机sdk异步登录 --- ard-work/src/main/java/com/ruoyi/device/dhsdk/module/ConfigModule.java | 182 ++++++++++++++++++++++++++++++++++++--------- 1 files changed, 146 insertions(+), 36 deletions(-) diff --git a/ard-work/src/main/java/com/ruoyi/device/dhsdk/module/ConfigModule.java b/ard-work/src/main/java/com/ruoyi/device/dhsdk/module/ConfigModule.java index 7678235..9d9d17a 100644 --- a/ard-work/src/main/java/com/ruoyi/device/dhsdk/module/ConfigModule.java +++ b/ard-work/src/main/java/com/ruoyi/device/dhsdk/module/ConfigModule.java @@ -1,36 +1,146 @@ -package com.ruoyi.device.dhsdk.module; - -import com.ruoyi.device.dhsdk.lib.NetSDKLib; -import com.sun.jna.Structure; -import com.sun.jna.ptr.IntByReference; - -/** - * @Description: - * @ClassName: ConfigModule - * @Author: 鍒樿嫃涔� - * @Date: 2023骞�10鏈�14鏃�14:57:01 - **/ -public class ConfigModule { - public static NetSDKLib netsdk = NetSDKLib.NETSDK_INSTANCE; - - public static boolean GetDevConfig(NetSDKLib.LLong hLoginHandle, int nType, Structure cmdObject) { - boolean result = false; - IntByReference error = new IntByReference(0); - int nBufferLen = 2 * 1024 * 1024; - netsdk.CLIENT_QueryDevState(hLoginHandle, nType, cmdObject.getPointer(), nBufferLen, error, 3000); - return result; - } - /** - * 鏌ヨ璁惧鐘舵�� - */ - public static boolean queryDevState(NetSDKLib.LLong hLoginHandle, int nType, NetSDKLib.SdkStructure stuInfo) { - - IntByReference intRetLen = new IntByReference(); - stuInfo.write(); - if (!LoginModule.netsdk.CLIENT_QueryDevState(hLoginHandle, nType, stuInfo.getPointer(), stuInfo.size(), intRetLen, 3000)) { - return false; - } - stuInfo.read(); - return true; - } -} +package com.ruoyi.device.dhsdk.module; + +import com.ruoyi.device.dhsdk.lib.NetSDKLib; +import com.ruoyi.device.dhsdk.lib.ToolKits; +import com.sun.jna.Structure; +import com.sun.jna.ptr.IntByReference; +import lombok.extern.slf4j.Slf4j; + +import static com.ruoyi.device.dhsdk.lib.ToolKits.getErrorCodePrint; + +/** + * @Description: + * @ClassName: ConfigModule + * @Author: 鍒樿嫃涔� + * @Date: 2023骞�10鏈�14鏃�14:57:01 + **/ +@Slf4j(topic = "dhSdk") +public class ConfigModule { + public static NetSDKLib netsdk = NetSDKLib.NETSDK_INSTANCE; + public static NetSDKLib configsdk = NetSDKLib.CONFIG_INSTANCE; + + /** + * 鏌ヨ璁惧鐘舵�� + */ + public static boolean queryDevState(NetSDKLib.LLong hLoginHandle, int nType, NetSDKLib.SdkStructure stuInfo) { + + IntByReference intRetLen = new IntByReference(); + stuInfo.write(); + if (!netsdk.CLIENT_QueryDevState(hLoginHandle, nType, stuInfo.getPointer(), stuInfo.size(), intRetLen, 3000)) { + return false; + } + stuInfo.read(); + return true; + } + + /** + * 鏌ヨ杩滅▼璁惧鐘舵�� + */ + public static boolean queryRemotDevState(NetSDKLib.LLong hLoginHandle, int nChn, int nType, NetSDKLib.SdkStructure stuInfo) { + + IntByReference intRetLen = new IntByReference(); + stuInfo.write(); + if (!netsdk.CLIENT_QueryRemotDevState(hLoginHandle, nType, nChn, stuInfo.getPointer(), stuInfo.size(), intRetLen, 3000)) { + log.error("Config Failed!" + ToolKits.getErrorCodePrint()); + return false; + } + stuInfo.read(); + return true; + } + + /** + * 鑾峰彇鍗曚釜閰嶇疆 + * + * @param hLoginHandle 鐧婚檰鍙ユ焺 + * @param nChn 閫氶亾鍙凤紝-1 琛ㄧず鍏ㄩ�氶亾 + * @param strCmd 閰嶇疆鍚嶇О + * @param cmdObject 閰嶇疆瀵瑰簲鐨勭粨鏋勪綋瀵硅薄 + * @return 鎴愬姛杩斿洖 true + */ + public static boolean GetNewDevConfig(NetSDKLib.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)) { + cmdObject.write(); + if (configsdk.CLIENT_ParseData(strCmd, strBuffer, cmdObject.getPointer(), cmdObject.size(), null)) { + cmdObject.read(); + result = true; + } else { + log.error("Parse " + strCmd + " Config Failed!" + ToolKits.getErrorCodePrint()); + result = false; + } + } else { + log.error("Get %s Config Failed!Last Error = %s\n", strCmd, getErrorCodePrint()); + result = false; + } + + return result; + } + + public static boolean GetDevConfig(NetSDKLib.LLong hLoginHandle, int nChn, String strCmd, Structure cmdObject) { + boolean result = true; + IntByReference error = new IntByReference(0); + int nBufferLen = 2 * 1024 * 1024; + byte[] strBuffer = new byte[nBufferLen]; + cmdObject.write(); + boolean bRet = netsdk.CLIENT_QueryNewSystemInfo(hLoginHandle, strCmd, nChn, strBuffer, cmdObject.size(), error, 3000); + if (bRet) { + cmdObject.read(); + } else { + log.error("Get %s Config Failed!Last Error = %s\n", strCmd, getErrorCodePrint()); + result = false; + } + return result; + } + // 鑾峰彇閰嶇疆 + public static boolean GetConfig(NetSDKLib.LLong hLoginHandle, int nChn,int type,Structure cmdObject) { + boolean result = false; + // 鑾峰彇 + cmdObject.write(); + if (netsdk.CLIENT_GetConfig(hLoginHandle, type, nChn, cmdObject.getPointer(), cmdObject.size(), 4000, null)) { + cmdObject.read(); + result=true; + } else { + log.error("GetConfig Failed!" + getErrorCodePrint()); + result=false; + } + return result; + } + /** + * 璁剧疆鍗曚釜閰嶇疆 + * + * @param hLoginHandle 鐧婚檰鍙ユ焺 + * @param nChn 閫氶亾鍙凤紝-1 琛ㄧず鍏ㄩ�氶亾 + * @param strCmd 閰嶇疆鍚嶇О + * @param cmdObject 閰嶇疆瀵瑰簲鐨勭粨鏋勪綋瀵硅薄 + * @return 鎴愬姛杩斿洖 true + */ + public static boolean SetDevConfig(NetSDKLib.LLong hLoginHandle, int nChn, String strCmd, Structure cmdObject) { + boolean result = false; + int nBufferLen = 2 * 1024 * 1024; + byte szBuffer[] = new byte[nBufferLen]; + for (int i = 0; i < nBufferLen; i++) szBuffer[i] = 0; + IntByReference error = new IntByReference(0); + IntByReference restart = new IntByReference(0); + cmdObject.write(); + if (configsdk.CLIENT_PacketData(strCmd, cmdObject.getPointer(), cmdObject.size(), szBuffer, nBufferLen)) { + cmdObject.read(); + if (netsdk.CLIENT_SetNewDevConfig(hLoginHandle, strCmd, nChn, szBuffer, nBufferLen, error, restart, 3000)) { + result = true; + } else { + log.error("Set %s Config Failed! Last Error = %s\n", strCmd, getErrorCodePrint()); + result = false; + } + } else { + log.error("Packet " + strCmd + " Config Failed!" + getErrorCodePrint()); + result = false; + } + + return result; + } + + +} -- Gitblit v1.9.3