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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
package com.ycl.api.YS.config.privacymask;
 
import com.sun.jna.ptr.IntByReference;
import com.ycl.api.YS.NetDemo;
import com.ycl.api.YS.lib.NetDEVSDKLib;
import com.ycl.api.YS.lib.NetDEVSDKLib.NETDEV_CONFIG_COMMAND_E;
import com.ycl.api.YS.lib.NetDEVSDKLib.NETDEV_PRIVACY_MASK_AREA_INFO_S;
import com.ycl.api.YS.lib.NetDEVSDKLib.NETDEV_PRIVACY_MASK_CFG_S;
 
import javax.swing.*;
import java.util.Vector;
 
/**
 *
 * @introduction Privacy Mask
 * @description Support IPC/NVR
 */
public class PrivacyMask {
 
    /**
     *
     * @introduction Add privacy mask
     * @description Calling the interface of NETDEV_SetDevConfig
     *
     */
    public static void addPrivacyMask() {
 
        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;
        }
 
        Vector<String> PrivacyMaskVector = new Vector<String>();
        int dwInsertIndex = 0;
        for(int i = 0; i < NetDEVSDKLib.NETDEV_MAX_PRIVACY_MASK_AREA_NUM; i++) {
            dwInsertIndex = i + 1;
            if(i < NetDemo.ConfigPrivacyMaskTableModel.getRowCount()) {
                int dwCurrentIndex = Integer.valueOf((String) NetDemo.ConfigPrivacyMaskTableModel.getValueAt(i, 0));
                if (dwInsertIndex >= dwCurrentIndex) {
                    continue;
                }
            }
            PrivacyMaskVector.add(String.valueOf(dwInsertIndex));
            PrivacyMaskVector.add("0");
            PrivacyMaskVector.add("0");
            PrivacyMaskVector.add("1000");
            PrivacyMaskVector.add("1000");
            NetDemo.ConfigPrivacyMaskTableModel.insertRow(i, PrivacyMaskVector);
            break;
        }
 
        NETDEV_PRIVACY_MASK_CFG_S stPrivacyMaskInfo = new NETDEV_PRIVACY_MASK_CFG_S();
        for(int i =0; i < NetDEVSDKLib.NETDEV_MAX_PRIVACY_MASK_AREA_NUM; i++) {
            stPrivacyMaskInfo.astArea[i] = new NETDEV_PRIVACY_MASK_AREA_INFO_S();
        }
 
        for(int i =0; i< NetDemo.ConfigPrivacyMaskTableModel.getRowCount(); i++) {
            stPrivacyMaskInfo.astArea[i].dwIndex = Integer.valueOf((String) NetDemo.ConfigPrivacyMaskTableModel.getValueAt(i, 0));
            stPrivacyMaskInfo.astArea[i].dwTopLeftX = Integer.valueOf((String) NetDemo.ConfigPrivacyMaskTableModel.getValueAt(i, 1));
            stPrivacyMaskInfo.astArea[i].dwTopLeftY = Integer.valueOf((String) NetDemo.ConfigPrivacyMaskTableModel.getValueAt(i, 2));
            stPrivacyMaskInfo.astArea[i].dwBottomRightX = Integer.valueOf((String) NetDemo.ConfigPrivacyMaskTableModel.getValueAt(i, 3));
            stPrivacyMaskInfo.astArea[i].dwBottomRightY = Integer.valueOf((String) NetDemo.ConfigPrivacyMaskTableModel.getValueAt(i, 4));
            stPrivacyMaskInfo.astArea[i].bIsEanbled = 1;
        }
        stPrivacyMaskInfo.dwSize = NetDemo.ConfigPrivacyMaskTableModel.getRowCount();
        stPrivacyMaskInfo.write();
 
        boolean bRet = NetDemo.netdevsdk.NETDEV_SetDevConfig(NetDemo.lpUserID, NetDemo.ChannelID, NETDEV_CONFIG_COMMAND_E.NETDEV_SET_PRIVACYMASKCFG, stPrivacyMaskInfo.getPointer(), stPrivacyMaskInfo.size());
        if(bRet != true)
        {
            System.out.printf("NETDEV_SetDevConfig failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
        NetDemo.jButtonGetPrivacyMask.doClick();
    }
 
    /**
     *
     * @introduction Delete privacy mask
     * @description Calling the interface of NETDEV_GetDevConfig
     *
     */
    public static void deletePrivacyMask() {
        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(0 == NetDemo.tableConfigPrivacyMask.getRowCount()  || NetDemo.tableConfigPrivacyMask.getSelectedRow() < 0) {
            JOptionPane.showMessageDialog(null, "Please find privacy mask or seletc first.");
            return;
        }
 
        String strIndex = (String) NetDemo.tableConfigPrivacyMask.getValueAt(NetDemo.tableConfigPrivacyMask.getSelectedRow(), 0);
        IntByReference dwIndex = new IntByReference(Integer.valueOf(strIndex));
 
        boolean bRet = NetDemo.netdevsdk.NETDEV_SetDevConfig(NetDemo.lpUserID, NetDemo.ChannelID, NETDEV_CONFIG_COMMAND_E.NETDEV_DELETE_PRIVACYMASKCFG, dwIndex.getPointer(), 4);
        if(bRet != true)
        {
            System.out.printf("NETDEV_SetDevConfig failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
        NetDemo.jButtonGetPrivacyMask.doClick();
    }
 
    /**
     *
     * @introduction Get Privacy mask
     * @description Calling the interface of NETDEV_GetDevConfig
     *
     */
    public static void getPrivacyMask() {
        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.ConfigPrivacyMaskTableModel.setRowCount(0);
        NETDEV_PRIVACY_MASK_CFG_S stPrivacyMaskInfo = new NETDEV_PRIVACY_MASK_CFG_S();
        stPrivacyMaskInfo.write();
        IntByReference dwBytesReturned = new IntByReference();
        boolean bRet = NetDemo.netdevsdk.NETDEV_GetDevConfig(NetDemo.lpUserID, NetDemo.ChannelID, NETDEV_CONFIG_COMMAND_E.NETDEV_GET_PRIVACYMASKCFG, stPrivacyMaskInfo.getPointer(), stPrivacyMaskInfo.size(), dwBytesReturned );
        if(bRet != true) {
            System.out.printf("NETDEV_GetDevConfig failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
        stPrivacyMaskInfo.read();
        for(int i = 0; i < stPrivacyMaskInfo.dwSize; i++) {
            Vector<String> PrivacyMaskVector = new Vector<String>();
            PrivacyMaskVector.add(String.valueOf(stPrivacyMaskInfo.astArea[i].dwIndex));
            PrivacyMaskVector.add(String.valueOf(stPrivacyMaskInfo.astArea[i].dwTopLeftX));
            PrivacyMaskVector.add(String.valueOf(stPrivacyMaskInfo.astArea[i].dwTopLeftY));
            PrivacyMaskVector.add(String.valueOf(stPrivacyMaskInfo.astArea[i].dwBottomRightX));
            PrivacyMaskVector.add(String.valueOf(stPrivacyMaskInfo.astArea[i].dwBottomRightY));
            NetDemo.ConfigPrivacyMaskTableModel.addRow(PrivacyMaskVector);
        }
    }
 
    /**
     *
     * @introduction Set privacy mask
     * @description Calling the interface of NETDEV_SetDevConfig
     *
     */
    public static void setPrivacyMask() {
        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;
        }
 
        NETDEV_PRIVACY_MASK_CFG_S stPrivacyMaskInfo = new NETDEV_PRIVACY_MASK_CFG_S();
        for(int i =0; i < NetDEVSDKLib.NETDEV_MAX_PRIVACY_MASK_AREA_NUM; i++) {
            stPrivacyMaskInfo.astArea[i] = new NETDEV_PRIVACY_MASK_AREA_INFO_S();
        }
        for(int i =0; i< NetDemo.ConfigPrivacyMaskTableModel.getRowCount(); i++) {
            String index=(String) NetDemo.ConfigPrivacyMaskTableModel.getValueAt(i, 0);
            if(index==null||index.equals("")) {
                JOptionPane.showMessageDialog(null, "Index is null");
                return;
            }
            int getIndex=0;
            int getLeftX=0;
            int getLeftY=0;
            int getRightX=0;
            int getRightY=0;
 
            try {
                getIndex=Integer.parseInt(index);
            }catch(Exception t) {
                JOptionPane.showMessageDialog(null, "Index transformation Exception");
                return;
            }
            if(getIndex<0) {
                JOptionPane.showMessageDialog(null, "Index can not less than zero");
                return;
            }
 
            String LeftX=(String) NetDemo.ConfigPrivacyMaskTableModel.getValueAt(i, 1);
            try {
                getLeftX=Integer.parseInt(LeftX);
            }catch(Exception t) {
                JOptionPane.showMessageDialog(null, "LeftX transformation Exception");
                return;
            }
            if(getLeftX<0 || getLeftX>10000) {
                JOptionPane.showMessageDialog(null, "LeftX should between 0 and 10000");
                return;
            }
 
            String LeftY=(String) NetDemo.ConfigPrivacyMaskTableModel.getValueAt(i, 2);
            if(LeftY==null||LeftY.equals("")) {
                JOptionPane.showMessageDialog(null, "LeftY is null");
                return;
            }
            try {
                getLeftY=Integer.parseInt(LeftY);
            }catch(Exception t) {
                JOptionPane.showMessageDialog(null, "LeftY transformation Exception");
                return;
            }
            if(getLeftY<0 || getLeftY>10000) {
                JOptionPane.showMessageDialog(null, "LeftY should between 0 and 10000");
                return;
            }
 
            String RightX=(String) NetDemo.ConfigPrivacyMaskTableModel.getValueAt(i, 3);
            if(RightX==null||RightX.equals("")) {
                JOptionPane.showMessageDialog(null, "RightX is null");
                return;
            }
            try {
                getRightX=Integer.parseInt(RightX);
            }catch(Exception t) {
                JOptionPane.showMessageDialog(null, "RightX transformation Exception");
                return;
            }
            if(getRightX<0 || getRightX>10000) {
                JOptionPane.showMessageDialog(null, "RightX should between 0 and 10000");
                return;
            }
 
            String RightY=(String) NetDemo.ConfigPrivacyMaskTableModel.getValueAt(i, 4);
            if(RightY==null||RightY.equals("")) {
                JOptionPane.showMessageDialog(null, "RightY is null");
                return;
            }
            try {
                getRightY=Integer.parseInt(RightY);
            }catch(Exception t) {
                JOptionPane.showMessageDialog(null, "RightY transformation Exception");
                return;
            }
            if(getRightY<0 || getRightY>10000) {
                JOptionPane.showMessageDialog(null, "RightY should between 0 and 10000");
                return;
            }
 
            if(getRightX<getLeftX) {
                JOptionPane.showMessageDialog(null, "Right BottomX should more than Left TopX");
                return;
            }
            if(getRightY<getLeftY) {
                JOptionPane.showMessageDialog(null, "Right BottomY should more than Left TopY");
                return;
            }
 
            stPrivacyMaskInfo.astArea[i].dwIndex = getIndex;
            stPrivacyMaskInfo.astArea[i].dwTopLeftX = getLeftX;
            stPrivacyMaskInfo.astArea[i].dwTopLeftY = getLeftY;
            stPrivacyMaskInfo.astArea[i].dwBottomRightX =getRightX;
            stPrivacyMaskInfo.astArea[i].dwBottomRightY = getRightY;
            stPrivacyMaskInfo.astArea[i].bIsEanbled = 1;
        }
 
        stPrivacyMaskInfo.dwSize = NetDemo.ConfigPrivacyMaskTableModel.getRowCount();
        stPrivacyMaskInfo.write();
 
        boolean bRet = NetDemo.netdevsdk.NETDEV_SetDevConfig(NetDemo.lpUserID, NetDemo.ChannelID, NETDEV_CONFIG_COMMAND_E.NETDEV_SET_PRIVACYMASKCFG, stPrivacyMaskInfo.getPointer(), stPrivacyMaskInfo.size());
        if(bRet != true) {
            System.out.printf("NETDEV_SetDevConfig failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }else {
            JOptionPane.showMessageDialog(null, "Set success");
            }
        NetDemo.jButtonGetPrivacyMask.doClick();
        }
    }