fuliqi
2024-10-10 d268f82d25c25ebdc7a1ea30614f6cda6d3a9ae3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package com.ycl.api.YS;
 
import com.sun.jna.Pointer;
import com.sun.jna.Structure;
import com.ycl.api.YS.lib.NetDEVSDKLib;
import com.ycl.api.YS.util.Common;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
 
import javax.swing.*;
import java.io.File;
 
@Component
@Slf4j
public class YSInit {
    @Value("${spring.profiles.active}")
    private String activeEnv;
 
    public static NetDEVSDKLib netdevsdk;
    public static String strPicturePath = "."+File.separator+"Picture"+File.separator;
    @PostConstruct
    void init() {
        if("prod".equals(activeEnv)) {
            netdevsdk = NetDEVSDKLib.NETDEVSDK_INSTANCE;
            String strLogPath = "./sdklog/";
            boolean bRet = netdevsdk.NETDEV_SetLogPath(strLogPath);
            if(false == bRet){
                System.out.printf("NETDEV_SetLogPath failed:%d", netdevsdk.NETDEV_GetLastError());
            }
 
            bRet = netdevsdk.NETDEV_Init();
            if(false == bRet){
                System.out.printf("Initialize failed:%d", netdevsdk.NETDEV_GetLastError());
                return;
            }
//            try {
//                Common.updateStructureByReferenceMethod = Structure.class.getDeclaredMethod("updateStructureByReference", Class.class, Structure.class, Pointer.class);
//                Common.updateStructureByReferenceMethod.setAccessible(true);
//            } catch (Exception e) {
//                throw new RuntimeException(e);
//            }
 
//            File file=new File(strPicturePath);
//            if(!file.exists()){
//                file.mkdir();
//            }
 
            NetDEVSDKLib.NETDEV_REV_TIMEOUT_S pstRevTimeout=new NetDEVSDKLib.NETDEV_REV_TIMEOUT_S();
            pstRevTimeout.dwRevTimeOut=3;
            pstRevTimeout.dwFileReportTimeOut=30;
            pstRevTimeout.write();
            boolean rbet1=netdevsdk.NETDEV_SetRevTimeOut(pstRevTimeout);
            boolean rbet2=netdevsdk.NETDEV_SetConnectTime(3, 1);
 
 
        }
    }
    @PreDestroy
    void clean(){
        if("prod".equals(activeEnv)) {
            netdevsdk.NETDEV_Cleanup();
        }
    }
}