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
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package com.ycl.api.YS.config.server;
 
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.*;
 
import javax.swing.*;
import java.util.Vector;
 
public class SmartServer {
 
    /**
     *
     * @introduction Get the smart server information
     * @description Calling the interface of NETDEV_GetDevConfig
     *
     */
    public static void getSmartServer() {
        if(null == NetDemo.lpUserID){
            JOptionPane.showMessageDialog(null, "Please Login device first. error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
        if(NetDemo.ChannelID == 0){
            JOptionPane.showMessageDialog(null, "Please select an online channel after login.");
            return;
        }
 
        NetDemo.SmartServertableModel.setRowCount(0);
         if(NetDemo.pstDeviceInfo.dwDeviceType == NETDEV_DEVICE_TYPE_E.NETDEV_DTYPE_IPC ||
                 NetDemo.pstDeviceInfo.dwDeviceType == NETDEV_DEVICE_TYPE_E.NETDEV_DTYPE_IPC_FISHEYE ||
                 NetDemo.pstDeviceInfo.dwDeviceType == NETDEV_DEVICE_TYPE_E.NETDEV_DTYPE_IPC_ECONOMIC_FISHEYE ||
                 NetDemo.pstDeviceInfo.dwDeviceType == NETDEV_DEVICE_TYPE_E.NETDEV_DTYPE_IPC_ACS) {
 
            IntByReference dwBytesReturned = new IntByReference();
            NetDemo.serverList = new NETDEV_DATA_SERVER_LIST();
            boolean bRet = NetDemo.netdevsdk.NETDEV_GetDevConfig(NetDemo.lpUserID, NetDemo.ChannelID, NETDEV_CONFIG_COMMAND_E.NETDEV_GET_INTELLIGENT_SERVER_INFO, NetDemo.serverList.getPointer(),5476,dwBytesReturned);
            if(bRet != true) {
                System.out.printf("NETDEV_GetDevConfig failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
                return;
            }else {
                NetDemo.serverList.read();
                //清空tableModel内容
                NetDemo.SmartServertableModel.setRowCount(0);
                for(int i = 0; i <  NetDemo.serverList.udwNum; i++){
                    Vector<Object> vtData = new Vector<>();
                    vtData.add(NetDemo.serverList.astDataServerList[i].udwIndex);
                    if(NetDemo.serverList.astDataServerList[i].bEnable == 1){
                        vtData.add(true);
                    }else{
                        vtData.add(false);
                    }
 
                    vtData.add(NetDemo.serverList.astDataServerList[i].udwProtocol);
                    vtData.add(Common.byteArrayToString(NetDemo.serverList.astDataServerList[i].szCameraID));
                    vtData.add(Common.byteArrayToString(NetDemo.serverList.astDataServerList[i].szTollgateID));
                    vtData.add(Common.byteArrayToString(NetDemo.serverList.astDataServerList[i].szServerAddr));
                    vtData.add(NetDemo.serverList.astDataServerList[i].udwServerPort);
                    vtData.add(Common.byteArrayToString(NetDemo.serverList.astDataServerList[i].szDrivewayID));
                    vtData.add(Common.byteArrayToString(NetDemo.serverList.astDataServerList[i].szDirectionID));
                    vtData.add(Common.byteArrayToString(NetDemo.serverList.astDataServerList[i].szDeviceID));
                    vtData.add(Common.byteArrayToString(NetDemo.serverList.astDataServerList[i].szAreaId));
                    NetDemo.SmartServertableModel.insertRow(i, vtData);
                    }
                NetDemo.SmartServerTable.setModel(NetDemo.SmartServertableModel);
                }
            }else{
             JOptionPane.showMessageDialog(null, "Only Support IPC.");
             return;
                }
         }
 
    /**
     *
     * @introduction Set the smart server information
     * @description Calling the interface of NETDEV_SetDevConfig
     *
     */
    public static void setSmartServer() {
        if(null == NetDemo.lpUserID){
            JOptionPane.showMessageDialog(null, "Please Login device first. error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
        if(NetDemo.ChannelID == 0){
            JOptionPane.showMessageDialog(null, "Please select an online channel after login.");
            return;
        }
        if(NetDemo.pstDeviceInfo.dwDeviceType == NETDEV_DEVICE_TYPE_E.NETDEV_DTYPE_IPC ||
                NetDemo.pstDeviceInfo.dwDeviceType == NETDEV_DEVICE_TYPE_E.NETDEV_DTYPE_IPC_FISHEYE ||
                NetDemo.pstDeviceInfo.dwDeviceType == NETDEV_DEVICE_TYPE_E.NETDEV_DTYPE_IPC_ECONOMIC_FISHEYE ||
                NetDemo.pstDeviceInfo.dwDeviceType == NETDEV_DEVICE_TYPE_E.NETDEV_DTYPE_IPC_ACS) {
            NETDEV_DATA_SERVER_LIST serverListData = new NETDEV_DATA_SERVER_LIST();
            for(int i =0; i< NetDemo.SmartServertableModel.getRowCount(); i++) {
                serverListData.astDataServerList[i] = new NETDEV_DATA_SERVER_INFO();
                String getValue=NetDemo.SmartServertableModel.getValueAt(i, 0).toString();
                if(getValue==null||getValue.equals("")) {
                    JOptionPane.showMessageDialog(null, "Index is null");
                    return;
                    }
 
                int index=0;
                try {
                    index=Integer.valueOf(NetDemo.SmartServertableModel.getValueAt(i, 0).toString());
                    }catch(Exception m) {
                        return;
                        }
                serverListData.astDataServerList[i].udwIndex = index;
 
                if(new Boolean(NetDemo.SmartServertableModel.getValueAt(i, 1).toString()) == true){
                    serverListData.astDataServerList[i].bEnable = 1;
                }else{
                    serverListData.astDataServerList[i].bEnable = 0;
                }
 
                String getProtol=NetDemo.SmartServertableModel.getValueAt(i, 2).toString();
                if(getProtol==null||getProtol.equals("")) {
                    JOptionPane.showMessageDialog(null, "Protol is null");
                    return;
                }
                int protrol=1;
                try {
                    protrol=Integer.valueOf(NetDemo.SmartServertableModel.getValueAt(i, 2).toString());
                }catch(Exception m) {
                    return;
                }
 
                serverListData.astDataServerList[i].udwProtocol = protrol;
                Common.stringToByteArray(NetDemo.SmartServertableModel.getValueAt(i, 3).toString(),serverListData.astDataServerList[i].szCameraID);
                Common.stringToByteArray(NetDemo.SmartServertableModel.getValueAt(i, 4).toString(),serverListData.astDataServerList[i].szTollgateID);
                Common.stringToByteArray(NetDemo.SmartServertableModel.getValueAt(i, 5).toString(),serverListData.astDataServerList[i].szServerAddr);
 
                String getPort=NetDemo.SmartServertableModel.getValueAt(i, 6).toString();
                if(getPort==null||getPort.equals("")) {
                    JOptionPane.showMessageDialog(null, "Port is null");
                    return;
                }
 
                int port=0;
                try {
                    port=Integer.valueOf(NetDemo.SmartServertableModel.getValueAt(i, 6).toString());
                }catch(Exception m2) {
                    return;
                }
                serverListData.astDataServerList[i].udwServerPort = port;
 
                Common.stringToByteArray(NetDemo.SmartServertableModel.getValueAt(i, 7).toString(),serverListData.astDataServerList[i].szDrivewayID);
                Common.stringToByteArray(NetDemo.SmartServertableModel.getValueAt(i, 8).toString(),serverListData.astDataServerList[i].szDirectionID);
                Common.stringToByteArray(NetDemo.SmartServertableModel.getValueAt(i, 9).toString(),serverListData.astDataServerList[i].szDeviceID);
                Common.stringToByteArray(NetDemo.SmartServertableModel.getValueAt(i, 10).toString(),serverListData.astDataServerList[i].szAreaId);
                try {
                    if(null != NetDemo.serverList.astDataServerList[i]){
                        serverListData.astDataServerList[i].stServerUserInfo = NetDemo.serverList.astDataServerList[i].stServerUserInfo;
                    }else{
                        serverListData.astDataServerList[i].stServerUserInfo = new NETDEV_SERVER_USER_INFO_S();
                    }
                }catch(Exception m3) {
 
                }
                serverListData.astDataServerList[i].write();
                }
            serverListData.udwNum = NetDemo.SmartServertableModel.getRowCount();
            serverListData.write();
            boolean bRet = NetDemo.netdevsdk.NETDEV_SetDevConfig(NetDemo.lpUserID, NetDemo.ChannelID, NETDEV_CONFIG_COMMAND_E.NETDEV_SET_INTELLIGENT_SERVER_INFO, serverListData.getPointer(), 5476);
            if(bRet != true) {
                System.out.printf("NETDEV_SetDevConfig failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
                return;
                }else{
                    JOptionPane.showMessageDialog(null, "Set success!");
                    NetDemo.jButtonGetSmartServer.doClick();
                    }
            }else{
                JOptionPane.showMessageDialog(null, "Only Support IPC.");
                return;
                }
        }
    }