‘liusuyi’
2023-10-24 4a293865ac437a812eea8800cc0b04314efbd210
ard-work/src/main/java/com/ruoyi/device/dhsdk/module/ConfigModule.java
@@ -4,6 +4,7 @@
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;
@@ -13,6 +14,7 @@
 * @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;
@@ -25,6 +27,21 @@
        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();
@@ -52,11 +69,11 @@
                cmdObject.read();
                result = true;
            } else {
                System.err.println("Parse " + strCmd + " Config Failed!" + ToolKits.getErrorCodePrint());
                log.error("Parse [" + strCmd + "] Config Failed!" + ToolKits.getErrorCodePrint());
                result = false;
            }
        } else {
            System.err.printf("Get %s Config Failed!Last Error = %s\n", strCmd, getErrorCodePrint());
            log.error("Get [" + strCmd + "] Config Failed!Last Error = " + getErrorCodePrint());
            result = false;
        }
@@ -69,11 +86,26 @@
        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);
        boolean bRet = netsdk.CLIENT_QueryNewSystemInfo(hLoginHandle, strCmd, nChn, strBuffer, cmdObject.size(), error, 3000);
        if (bRet) {
            cmdObject.read();
        } else {
            System.err.printf("Get %s Config Failed!Last Error = %s\n", strCmd, getErrorCodePrint());
            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;
@@ -101,15 +133,17 @@
            if (netsdk.CLIENT_SetNewDevConfig(hLoginHandle, strCmd, nChn, szBuffer, nBufferLen, error, restart, 3000)) {
                result = true;
            } else {
                System.err.printf("Set %s Config Failed! Last Error = %s\n", strCmd, getErrorCodePrint());
                log.error("Set [" + strCmd + "] Config Failed! Last Error = " + getErrorCodePrint());
                result = false;
            }
        } else {
            System.err.println("Packet " + strCmd + " Config Failed!" + getErrorCodePrint());
            log.error("Parse [" + strCmd + "] Config Failed!" + ToolKits.getErrorCodePrint());
            result = false;
        }
        return result;
    }
}