zxl
1 天以前 3b0516a2959e25576e4f3fda697a3b025d06c8c9
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
package com.ycl.api.YS.config.network;
 
import com.ycl.api.YS.NetDemo;
import com.ycl.api.YS.util.Common;
import com.ycl.api.YS.lib.NetDEVSDKLib.NETDEV_DEV_ADDR_INFO_S;
 
import javax.swing.*;
 
/**
 *
 * @introduction Set IPV4 adress
 * @description Support IPC/NVR
 */
public class IPAdress {
 
    /**
     *
     * @introduction Set IPV4 adress
     * @description Calling the interface of NETDEV_ModifyDeviceAddr
     *
     */
    public static void setIpv4DeviceAddress() {
        if(null == NetDemo.lpUserID)
        {
            JOptionPane.showMessageDialog(null, "Please Login device first. error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
        if((NetDemo.DiscoveryTableModel.getRowCount()>0)&&(NetDemo.DiscoveryTable.getRowCount()>0)) {
            String MAC=null;
            try {
                MAC=(String) NetDemo.DiscoveryTableModel.getValueAt(NetDemo.DiscoveryTable.getSelectedRow(), 3);
            }catch(Exception m1) {
                JOptionPane.showMessageDialog(null, "MAC is null");
                return;
            }
            String Serial=null;
            try {
                Serial=(String) NetDemo.DiscoveryTableModel.getValueAt(NetDemo.DiscoveryTable.getSelectedRow(), 4);
            }catch(Exception m2) {
                JOptionPane.showMessageDialog(null, "Serial Num is null");
                return;
            }
 
            if(MAC==null||MAC.equals("")) {
                JOptionPane.showMessageDialog(null, "MAC is null");
                return;
            }
            if(Serial==null||Serial.equals("")) {
                JOptionPane.showMessageDialog(null, "Serial NUM is null");
                return;
            }
 
            String getUpdateUsername=NetDemo.jTextFieldUpdateUserName.getText();
            String getUpdatePassword=NetDemo.textFieldUpdatePassword.getText();
            String ipAddress=NetDemo.jTextFieldModifyDeviceIpv4Address.getText();
            String gateWay=NetDemo.jTextFieldUpdateChangeDeviceIpGateWay.getText();
            String Mask=NetDemo.jTextFieldUpdateChangeDeviceIpMask.getText();
            if(getUpdateUsername==null||getUpdateUsername.equals("")) {
                JOptionPane.showMessageDialog(null, "Username is null");
                return;
            }
            if(getUpdatePassword==null||getUpdatePassword.equals("")) {
                JOptionPane.showMessageDialog(null, "Password is null");
                return;
            }
            if(ipAddress==null||ipAddress.equals("")) {
                JOptionPane.showMessageDialog(null, "IP can not null");
                return;
            }
            if(gateWay==null||gateWay.equals("")) {
                JOptionPane.showMessageDialog(null, "GateWay can not null");
                return;
            }
            if(Mask==null||Mask.equals("")) {
                JOptionPane.showMessageDialog(null, "Mask can not null");
                return;
            }
 
            NETDEV_DEV_ADDR_INFO_S devAddr=new NETDEV_DEV_ADDR_INFO_S();
            Common.stringToByteArray(MAC, devAddr.szDevMac);
            Common.stringToByteArray(Serial, devAddr.szDevSerailNum);
            Common.stringToByteArray(getUpdateUsername, devAddr.szUserName);
            Common.stringToByteArray(getUpdatePassword, devAddr.szPassword);
            Common.stringToByteArray(gateWay, devAddr.szIPv4GateWay);
            Common.stringToByteArray(Mask, devAddr.szIPv4SubnetMask);
            if(Common.isIP(ipAddress)){
                Common.stringToByteArray(ipAddress, devAddr.szIPv4Address);
                devAddr.write();
                boolean bRet= NetDemo.netdevsdk.NETDEV_ModifyDeviceAddr(devAddr);
                if(bRet!=true) {
                    JOptionPane.showMessageDialog(null, "Modify Device Address failed,please check your username and password or other parameters,error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
                    System.out.printf("NETDEV_NETDEV_ModifyDeviceAddr failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
                    return;
                }else {
                    JOptionPane.showMessageDialog(null, "Set success");
                }
            }else {
                JOptionPane.showMessageDialog(null,"Please re-enter ,ip is error");
            }
        }else {
            JOptionPane.showMessageDialog(null, "Please choose device");
            return;
        }
    }
}