fuliqi
2024-08-29 4163c93761115c7524ef74a557a1f5e01eafb429
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
package com.ycl.api.YS.config.basic;
 
import com.sun.jna.ptr.IntByReference;
import com.ycl.api.YS.NetDemo;
import com.ycl.api.YS.util.Common;
import com.ycl.api.YS.lib.NetDEVSDKLib.NETDEV_CONFIG_COMMAND_E;
import com.ycl.api.YS.lib.NetDEVSDKLib.NETDEV_DEVICE_BASICINFO_S;
import com.ycl.api.YS.lib.NetDEVSDKLib.NETDEV_DEVICE_TYPE_E;
 
import javax.swing.*;
 
/**
 *
 * @introduction Device name
 * @description Support IPC/NVR/VMS
 */
public class DeviceName {
 
    /**
     *
     * @introduction Get device name
     * @description Calling the interface of NETDEV_GetDevConfig
     *
     */
    public static void getDeviceName() {
        if(null == NetDemo.lpUserID){
            JOptionPane.showMessageDialog(null, "Please Login device first.error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
        NETDEV_DEVICE_BASICINFO_S stDeviceInfo = new NETDEV_DEVICE_BASICINFO_S();
        IntByReference dwBytesReturned = new IntByReference();
        boolean bRet = NetDemo.netdevsdk.NETDEV_GetDevConfig(NetDemo.lpUserID, NetDemo.ChannelID, NETDEV_CONFIG_COMMAND_E.NETDEV_GET_DEVICECFG, stDeviceInfo.getPointer(), stDeviceInfo.size(), dwBytesReturned );
        if(bRet != true)
        {
            JOptionPane.showMessageDialog(null, "Get data failed.error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            System.out.printf("NETDEV_GetDevConfig failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
        stDeviceInfo.read();
        NetDemo.textFieldConfigDeviceName.setText(Common.byteArrayToString(stDeviceInfo.szDeviceName));
    }
 
    /**
     *
     * @introduction Set device name
     * @description
     *
     */
    public static void setDeviceName() {
        if(null == NetDemo.lpUserID) {
            JOptionPane.showMessageDialog(null, "Please Login device first. error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
        if(NetDemo.pstDeviceInfo.dwDeviceType == NETDEV_DEVICE_TYPE_E.NETDEV_DTYPE_VMS) {
             JOptionPane.showMessageDialog(null, "VMS cannot modify device name");
                return;
         }
 
        String strDeviceNameString = NetDemo.textFieldConfigDeviceName.getText();
        try {
            strDeviceNameString=new String(strDeviceNameString.getBytes(),"UTF-8");
        } catch (Exception e) {
            e.printStackTrace();
        }
 
        if((strDeviceNameString==null||strDeviceNameString.equals(""))||strDeviceNameString.length()>20) {
            JOptionPane.showMessageDialog(null, "Length of device name should between 1 and 20!");
            NetDemo.textFieldConfigDeviceName.setText(strDeviceNameString.substring(0, 20));
            return;
        }
 
 
        boolean bRet = NetDemo.netdevsdk.NETDEV_ModifyDeviceName(NetDemo.lpUserID, strDeviceNameString);
        if(bRet != true)
        {
            System.out.printf("NETDEV_ModifyDeviceName failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }else {
            JOptionPane.showMessageDialog(null, "Set success");
            NetDemo.jButtonConfigGetDeviceName.doClick();
        }
 
    }
}