From 4a293865ac437a812eea8800cc0b04314efbd210 Mon Sep 17 00:00:00 2001
From: ‘liusuyi’ <1951119284@qq.com>
Date: Tue, 24 Oct 2023 10:06:24 +0800
Subject: [PATCH] 异步登录增加延迟时间避免接口频繁 修改大华通道数量获取

---
 ard-work/src/main/java/com/ruoyi/device/dhsdk/module/ConfigModule.java |  117 +++++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 102 insertions(+), 15 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 bb99075..587adef 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,8 +1,11 @@
 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;
 
 /**
@@ -11,9 +14,11 @@
  * @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;
+
     /**
      * 查询设备状态
      */
@@ -27,36 +32,118 @@
         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 配置对应的结构体对象
+     * @param nChn         通道号,-1 表示全通道
+     * @param strCmd       配置名称
+     * @param cmdObject    配置对应的结构体对象
      * @return 成功返回 true
      */
-    public static boolean SetDevConfig(NetSDKLib.LLong hLoginHandle, int nChn, String strCmd, Structure cmdObject) {
+    public static boolean GetNewDevConfig(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( configsdk.CLIENT_SetNewDevConfig(hLoginHandle, strCmd , nChn , szBuffer, nBufferLen, error, restart, 3000)) {
+        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 {
-                System.err.printf("Set %s Config Failed! Last Error = %s\n" , strCmd , getErrorCodePrint());
+                log.error("Parse [" + strCmd + "] Config Failed!" + ToolKits.getErrorCodePrint());
                 result = false;
             }
         } else {
-            System.err.println("Packet " + strCmd + " Config Failed!" + getErrorCodePrint());
+            log.error("Get [" + strCmd + "] Config Failed!Last Error = " + 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 ["+strCmd+"] Config Failed!Last Error = " + 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 [" + strCmd + "] Config Failed! Last Error = " + getErrorCodePrint());
+
+                result = false;
+            }
+        } else {
+            log.error("Parse [" + strCmd + "] Config Failed!" + ToolKits.getErrorCodePrint());
+            result = false;
+        }
+
+        return result;
+    }
+
+
 }

--
Gitblit v1.9.3