xiangpei
2024-08-30 10f65333417f064377b01a89064d2ce716603a07
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
package com.ycl.api.YS;
 
 
import com.sun.jna.Pointer;
import com.sun.jna.ptr.IntByReference;
import com.ycl.api.DH.utils.DHApi;
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 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){
        log.info("ip:{},用户:{},密码:{}",ip,userName,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.szUserName = userName.getBytes();
        stDevLoginInfo.szPassword = password.getBytes();
        stDevLoginInfo.szIPAddr = ip.getBytes();
        stDevLoginInfo.dwPort = 80;
        //登录协议
        stDevLoginInfo.dwLoginProto = NETDEV_LOGIN_PROTO_ONVIF;
        log.info("SDK传参ip:{},用户:{},密码:{}",stDevLoginInfo.szIPAddr,stDevLoginInfo.szUserName,stDevLoginInfo.szPassword);
        Pointer lpUserID  = YSInit.netdevsdk.NETDEV_Login_V30(stDevLoginInfo, stSELogInfo);
 
        log.info("登录返回id:{}",lpUserID);
        if(lpUserID !=null) {
            log.info("登录成功");
            //获取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, 0, 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();
            for (NetDEVSDKLib.NETDEV_OSD_TEXT_OVERLAY_S osd : stOSDInfo.astTextOverlay) {
                String text = new String(osd.szOSDText, StandardCharsets.UTF_8);
                log.info("text:" + text);
            }
            //登出
            YSInit.netdevsdk.NETDEV_Logout(lpUserID);
        }else {
            log.error("error code"+YSInit.netdevsdk.NETDEV_GetLastError());
        }
        return null;
    }
    public static void demo(){
        Login.loginIn();
    }
}