fuliqi
2024-09-03 ae0c129c499e7e166399f2e3e2ccca93a076a669
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package com.ycl.api.YS;
 
 
import com.sun.jna.Pointer;
import com.sun.jna.ptr.IntByReference;
import com.ycl.api.YS.lib.NetDEVSDKLib;
import com.ycl.api.YS.login.Login;
import com.ycl.platform.domain.result.OSDResult;
import lombok.extern.slf4j.Slf4j;
 
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.Date;
 
import static com.ycl.api.YS.lib.NetDEVSDKLib.NETDEV_LOGIN_PROTO_E.NETDEV_LOGIN_PROTO_ONVIF;
 
@Slf4j
public class YSApi {
 
    public static OSDResult getOsd(String ip, String userName, String password) {
        //登录
        NetDEVSDKLib.NETDEV_DEVICE_LOGIN_INFO_S stDevLoginInfo = new NetDEVSDKLib.NETDEV_DEVICE_LOGIN_INFO_S();
        NetDEVSDKLib.NETDEV_SELOG_INFO_S stSELogInfo = new NetDEVSDKLib.NETDEV_SELOG_INFO_S();
        System.arraycopy(userName.getBytes(), 0, stDevLoginInfo.szUserName, 0, userName.getBytes().length);
        System.arraycopy(password.getBytes(), 0, stDevLoginInfo.szPassword, 0, password.getBytes().length);
        System.arraycopy(ip.getBytes(), 0, stDevLoginInfo.szIPAddr, 0, ip.getBytes().length);
        stDevLoginInfo.dwPort = 80;
        //登录协议
        stDevLoginInfo.dwLoginProto = NETDEV_LOGIN_PROTO_ONVIF;
        Pointer lpUserID = YSInit.netdevsdk.NETDEV_Login_V30(stDevLoginInfo, stSELogInfo);
        if (lpUserID != null) {
            OSDResult osdResult = new OSDResult();
            //获取通道
            int nMaxChlCount = 256;
            IntByReference dwChlCount = new IntByReference(nMaxChlCount);
            NetDEVSDKLib.NETDEV_VIDEO_CHL_DETAIL_INFO_EX_S[] stVideoChlList = (NetDEVSDKLib.NETDEV_VIDEO_CHL_DETAIL_INFO_EX_S[]) new NetDEVSDKLib.NETDEV_VIDEO_CHL_DETAIL_INFO_EX_S().toArray(nMaxChlCount);
            boolean bRe = YSInit.netdevsdk.NETDEV_QueryVideoChlDetailListEx(lpUserID, dwChlCount, stVideoChlList);
            if (!bRe) {
//                log.error("error code" + YSInit.netdevsdk.NETDEV_GetLastError());
                return null;
            }
            //获取时间
            NetDEVSDKLib.NETDEV_TIME_CFG_S stTimeCfg = new NetDEVSDKLib.NETDEV_TIME_CFG_S();
            stTimeCfg.write();
            boolean bRetime = NetDemo.netdevsdk.NETDEV_GetSystemTimeCfg(lpUserID, stTimeCfg);
            Date checkTime = new Date();
            osdResult.setCheckTime(checkTime);
            if (!bRetime) {
//                log.error("error code" + YSInit.netdevsdk.NETDEV_GetLastError());
                return null;
            } else {
                stTimeCfg.read();
                String strTime = "" + stTimeCfg.stTime.dwYear + "-";
                if (stTimeCfg.stTime.dwMonth < 10) {
                    strTime += "0";
                }
                strTime = strTime + stTimeCfg.stTime.dwMonth + "-";
                if (stTimeCfg.stTime.dwDay < 10) {
                    strTime += "0";
                }
                strTime = strTime + stTimeCfg.stTime.dwDay + " ";
                if (stTimeCfg.stTime.dwHour < 10) {
                    strTime += "0";
                }
                strTime = strTime + stTimeCfg.stTime.dwHour + ":";
                if (stTimeCfg.stTime.dwMinute < 10) {
                    strTime += "0";
                }
                strTime = strTime + stTimeCfg.stTime.dwMinute + ":";
 
                if (stTimeCfg.stTime.dwSecond < 10) {
                    strTime += "0";
                }
                strTime = strTime + stTimeCfg.stTime.dwSecond;
                SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                try {
                    osdResult.setOsdTime(format.parse(strTime));
                } catch (Exception e) {
//                    log.error(ip + "时间解析有误");
                }
            }
            //获取osd
            NetDEVSDKLib.NETDEV_VIDEO_OSD_CFG_S stOSDInfo = new NetDEVSDKLib.NETDEV_VIDEO_OSD_CFG_S();
            stOSDInfo.write();
            IntByReference dwBytesReturned = new IntByReference();
 
            boolean bRet = YSInit.netdevsdk.NETDEV_GetDevConfig(lpUserID, stVideoChlList[0].dwChannelID, NetDEVSDKLib.NETDEV_CONFIG_COMMAND_E.NETDEV_GET_OSDCFG, stOSDInfo.getPointer(), 616, dwBytesReturned);
            if (!bRet) {
//                log.error("error code" + YSInit.netdevsdk.NETDEV_GetLastError());
                return null;
            }
            stOSDInfo.read();
            //省份
            String name = new String(stOSDInfo.stNameOSD.szOSDText, StandardCharsets.UTF_8);
            osdResult.setOSD1(name);
            int num = 0;
            for (NetDEVSDKLib.NETDEV_OSD_TEXT_OVERLAY_S osd : stOSDInfo.astTextOverlay) {
                String text = new String(osd.szOSDText, StandardCharsets.UTF_8).trim();
                if (num == 0) {
                    osdResult.setOSD2(text);
                } else if (num == 1) {
                    osdResult.setOSD3(text);
                } else if (num == 2) {
                    osdResult.setName(text);
                } else if (num == 3) {
                    osdResult.setOSD4(text);
                }
                num++;
            }
            //登出
            YSInit.netdevsdk.NETDEV_Logout(lpUserID);
            return osdResult;
        } else {
//            log.error("ip:"+ip+",error code" + YSInit.netdevsdk.NETDEV_GetLastError());
            return null;
        }
    }
 
    public static void demo() {
        Login.loginIn();
    }
}