fuliqi
2024-09-11 b14531e3b850fe6d2fa916ba7b88b3e2bd2ff30a
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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
package com.ycl.api.YS.vca.face;
 
import com.sun.jna.Memory;
import com.sun.jna.Pointer;
import com.ycl.api.YS.NetDemo;
import com.ycl.api.YS.util.Common;
import com.ycl.api.YS.vca.face.PersonMonitor.PERSON_MONITOR_OPERATE_WINDOW_EFFECT;
import com.ycl.api.YS.lib.NetDEVSDKLib;
import com.ycl.api.YS.lib.NetDEVSDKLib.*;
 
import javax.swing.*;
import java.util.Vector;
 
/**
 * @description This section can add delete modify and find monitor information.
 * @introduction Support IPC/VMS.
 */
public class PersonMonitorFunction {
    /**
     * @description To add person monitor.
     * @introduction It is mainly realized by the constructor of PersonMonitor.
     */
    public static void addPersonMonitor() {
        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.");
            return;
        }
        PersonMonitor p=new PersonMonitor(PERSON_MONITOR_OPERATE_WINDOW_EFFECT.PERSON_MONITOR_OPERATE_WINDOW_ADDPERSONMONITOR,NetDemo.jButtonFindPersonLib,NetDemo.jButtonFindPersonMonitor,null);
        p.setVisible(true);
     }
    /**
     * @description To delete the person monitor.
     * @introduction Calling  the interface of NETDEV_DeletePersonMonitorInfo to realize. 
     */
    public static void deletePersonMonitor() {
        if(null == NetDemo.lpUserID)
        {
            JOptionPane.showMessageDialog(null, "Please Login device first. error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
        if(0 == NetDemo.PersonMonitorTable.getRowCount() || NetDemo.PersonMonitorTable.getSelectedRow() < 0)
        {
            JOptionPane.showMessageDialog(null, "Please find monitor first");
            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
            ) {
            String strPersonMonitorName = (String) NetDemo.PersonMonitorTable.getValueAt(NetDemo.PersonMonitorTable.getSelectedRow(), 0);
            NETDEV_MONITION_INFO_S stPersonMonitorInfo = NetDemo.mapPersonMonitorMap.get(strPersonMonitorName);
            stPersonMonitorInfo.read();
            int udwId=stPersonMonitorInfo.udwID;
            boolean bRet = NetDemo.netdevsdk.NETDEV_DeletePersonMonitorInfo(NetDemo.lpUserID, udwId);
            if(!bRet)
            {
                System.out.printf("NETDEV_DeletePersonMonitorInfo failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
                return;
            }else {
                JOptionPane.showMessageDialog(null, " Delete success");
                NetDemo.jButtonFindPersonMonitor.doClick();
            }
        }else {
            String strPersonMonitorName = (String) NetDemo.PersonMonitorTable.getValueAt(NetDemo.PersonMonitorTable.getSelectedRow(), 0);
            NETDEV_MONITION_INFO_S stPersonMonitorInfo = NetDemo.mapPersonMonitorMap.get(strPersonMonitorName);
 
            NETDEV_BATCH_OPERATOR_LIST_S stResultList = new NETDEV_BATCH_OPERATOR_LIST_S();
            stResultList.udwNum = 1;
            NETDEV_BATCH_OPERATOR_INFO_S stBatchList = new NETDEV_BATCH_OPERATOR_INFO_S();
            stBatchList.udwID = stPersonMonitorInfo.udwID;
            stBatchList.write();
            stResultList.pstBatchList = stBatchList.getPointer();
 
            boolean bRet = NetDemo.netdevsdk.NETDEV_BatchDeletePersonMonitorInfo(NetDemo.lpUserID, stResultList);
            if(false == bRet)
            {
                JOptionPane.showMessageDialog(null, "NETDEV_BatchDeletePersonMonitorInfo failed,error code"+  NetDemo.netdevsdk.NETDEV_GetLastError());
                System.out.printf("NETDEV_BatchDeletePersonMonitorInfo failed:%d\n",  NetDemo.netdevsdk.NETDEV_GetLastError());
                return;
            }else {
                JOptionPane.showMessageDialog(null, " Delete success");
                NetDemo.jButtonFindPersonMonitor.doClick();
            }
        }
    }
    /**
     * @description To find person monitor.
     * @introduction Calling the interface of NETDEV_FindPersonMonitorList to realize.
     */
    public static void findPersonMonitor() {
        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.mapPersonMonitorMap.clear();
        NetDemo.PersonMonitorTableModel.setRowCount(0);
 
        boolean bRet = false;
        NETDEV_MONITOR_QUERY_INFO_S stQueryInfo = new NETDEV_MONITOR_QUERY_INFO_S();
        stQueryInfo.udwLimit = 20;
        Pointer lpPersonMonitorHandle = NetDemo.netdevsdk.NETDEV_FindPersonMonitorList(NetDemo.lpUserID, NetDemo.ChannelID, stQueryInfo);
        if(lpPersonMonitorHandle == null)
        {
            System.out.printf("NETDEV_FindPersonMonitorList failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
        else
        {
            while(true)
            {
                NETDEV_MONITION_INFO_S stMonitorInfo = new NETDEV_MONITION_INFO_S();
                stMonitorInfo.stMonitorRuleInfo = new NETDEV_MONITION_RULE_INFO_S();
 
                stMonitorInfo.stMonitorRuleInfo.udwChannelNum = 1;
                stMonitorInfo.stMonitorRuleInfo.pudwMonitorChlIDList = new Memory(4 * stMonitorInfo.stMonitorRuleInfo.udwChannelNum);
                stMonitorInfo.stMonitorRuleInfo.pudwMonitorChlIDList.setInt(0, 0);
 
                stMonitorInfo.udwLinkStrategyNum = 10;
                NETDEV_LINKAGE_STRATEGY_S stLinkStrategyList = new NETDEV_LINKAGE_STRATEGY_S();
 
                stMonitorInfo.pstLinkStrategyList = new Memory(stLinkStrategyList.size() * 10);
 
 
 
                stMonitorInfo.stWeekPlan = new NETDEV_VIDEO_WEEK_PLAN_S();
                for(int i =0; i < NetDEVSDKLib.NETDEV_MAX_DAY_NUM; i++)
                {
                    stMonitorInfo.stWeekPlan.astDayPlan[i] = new NETDEV_VIDEO_DAY_PLAN_S();
                }
                stMonitorInfo.write();
 
                bRet = NetDemo.netdevsdk.NETDEV_FindNextPersonMonitorInfo(lpPersonMonitorHandle, stMonitorInfo);
                if(bRet != true)
                {
                    System.out.printf("NETDEV_FindNextPersonMonitorInfo failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
                    break;
                }
                else
                {
                    //显示查询数据
                    Vector<String> PersonMonitorVector = new Vector<String>();
                    PersonMonitorVector.add(Common.byteArrayToString(stMonitorInfo.stMonitorRuleInfo.szName));
                    PersonMonitorVector.add(Common.byteArrayToString(stMonitorInfo.stMonitorRuleInfo.szReason));
                    if(stMonitorInfo.stMonitorRuleInfo.bEnabled == 1)
                    {
                        PersonMonitorVector.add("enable");
                    }
                    else
                    {
                        PersonMonitorVector.add("disable");
                    }
                    NetDemo.PersonMonitorTableModel.addRow(PersonMonitorVector);
                    NetDemo.mapPersonMonitorMap.put(Common.byteArrayToString(stMonitorInfo.stMonitorRuleInfo.szName), stMonitorInfo);
                }
            }
            bRet = NetDemo.netdevsdk.NETDEV_FindClosePersonMonitorList(lpPersonMonitorHandle);
            if(bRet != true)
            {
                System.out.printf("NETDEV_FindClosePersonMonitorList failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
                return;
            }
        }
    }
    /**
     * @description To open the person monitor.
     * @introduction Calling the interface of NETDEV_GetPersonMonitorRuleInfo to realize.
     */
    public static void enablePersonMonitor() {
        if(null == NetDemo.lpUserID)
        {
            JOptionPane.showMessageDialog(null, "Please Login device first. error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
        
        if(0 == NetDemo.PersonMonitorTable.getRowCount() || NetDemo.PersonMonitorTable.getSelectedRow() < 0)
        {
            JOptionPane.showMessageDialog(null, "Please find monitor first");
            return;
        }
 
        String strPersonMonitorName = (String) NetDemo.PersonMonitorTable.getValueAt(NetDemo.PersonMonitorTable.getSelectedRow(), 0);
        NETDEV_MONITION_INFO_S stPersonMonitorInfo = NetDemo.mapPersonMonitorMap.get(strPersonMonitorName);//布控任务信息 结构体
        boolean bRet = NetDemo.netdevsdk.NETDEV_GetPersonMonitorRuleInfo(NetDemo.lpUserID, stPersonMonitorInfo);//查询单个人脸布控任务配置信息
        if(false == bRet)
        {
                if(NetDemo.netdevsdk.NETDEV_GetLastError()!=130) {//
                    System.out.printf("NETDEV_GetPersonMonitorRuleInfo failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
                    return;
                }else {
                    stPersonMonitorInfo.read();
                    stPersonMonitorInfo.write();
                    bRet = NetDemo.netdevsdk.NETDEV_GetPersonMonitorRuleInfo(NetDemo.lpUserID, stPersonMonitorInfo);
                    if(bRet) {
                        stPersonMonitorInfo.read();
                        stPersonMonitorInfo.stMonitorRuleInfo.bEnabled = 1;
                        
                        if(NetDemo.pstDeviceInfo.dwDeviceType == NETDEV_DEVICE_TYPE_E.NETDEV_DTYPE_NVR||
                                NetDemo.pstDeviceInfo.dwDeviceType == NETDEV_DEVICE_TYPE_E.NETDEV_DTYPE_HNVR||
                                NetDemo.pstDeviceInfo.dwDeviceType == NETDEV_DEVICE_TYPE_E.NETDEV_DTYPE_NVR_BACKUP
                            ) {
                            stPersonMonitorInfo.udwLinkStrategyNum=0;
                            stPersonMonitorInfo.write();
                        }else {
                            stPersonMonitorInfo.write();
                        }
                        bRet = NetDemo.netdevsdk.NETDEV_SetPersonMonitorRuleInfo(NetDemo.lpUserID, stPersonMonitorInfo);
                        if(false == bRet)
                        {
                            JOptionPane.showMessageDialog(null, "NETDEV_SetPersonMonitorRuleInfo failed,error code"+ NetDemo.netdevsdk.NETDEV_GetLastError());
                            System.out.printf("NETDEV_SetPersonMonitorRuleInfo failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
                        
                            return;
                        }else {
                            JOptionPane.showMessageDialog(null, "set success");
                            NetDemo.jButtonFindPersonMonitor.doClick(); 
                        }
                    }
                }
                
        }else {
            stPersonMonitorInfo.read();
            stPersonMonitorInfo.stMonitorRuleInfo.bEnabled = 1;
            
            if(NetDemo.pstDeviceInfo.dwDeviceType == NETDEV_DEVICE_TYPE_E.NETDEV_DTYPE_NVR||
                    NetDemo.pstDeviceInfo.dwDeviceType == NETDEV_DEVICE_TYPE_E.NETDEV_DTYPE_HNVR||
                    NetDemo.pstDeviceInfo.dwDeviceType == NETDEV_DEVICE_TYPE_E.NETDEV_DTYPE_NVR_BACKUP
                ) {//NVR
                stPersonMonitorInfo.udwLinkStrategyNum=0;
                stPersonMonitorInfo.write();
            }else {
                stPersonMonitorInfo.write();
            }
            bRet = NetDemo.netdevsdk.NETDEV_SetPersonMonitorRuleInfo(NetDemo.lpUserID, stPersonMonitorInfo);////设置单个人脸布控任务配置信息
            if(false == bRet)
            {
                JOptionPane.showMessageDialog(null, "NETDEV_SetPersonMonitorRuleInfo failed,error code"+ NetDemo.netdevsdk.NETDEV_GetLastError());
                System.out.printf("NETDEV_SetPersonMonitorRuleInfo failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
            
                return;
            }else {
                JOptionPane.showMessageDialog(null, "Set success");
                NetDemo.jButtonFindPersonMonitor.doClick(); 
            }
        }
    }
    
    /**
     * @description To shut down the person monitor.
     * @introduction Calling the interface of NETDEV_GetPersonMonitorRuleInfo and NETDEV_SetPersonMonitorRuleInfo to realize.
     */
    public static void disablePersonMonitor() {
        if(null == NetDemo.lpUserID)
        {
            JOptionPane.showMessageDialog(null, "Please Login device first. error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
        
        if(0 == NetDemo.PersonMonitorTable.getRowCount() || NetDemo.PersonMonitorTable.getSelectedRow() < 0)
        {
            JOptionPane.showMessageDialog(null, "Please find monitor first");
            return;
        }
 
        String strPersonMonitorName = (String) NetDemo.PersonMonitorTable.getValueAt(NetDemo.PersonMonitorTable.getSelectedRow(), 0);
        NETDEV_MONITION_INFO_S stPersonMonitorInfo = NetDemo.mapPersonMonitorMap.get(strPersonMonitorName);
        boolean bRet = NetDemo.netdevsdk.NETDEV_GetPersonMonitorRuleInfo(NetDemo.lpUserID, stPersonMonitorInfo);
        if(false == bRet)
        {
            if(NetDemo.netdevsdk.NETDEV_GetLastError()!=130) {
                System.out.printf("NETDEV_GetPersonMonitorRuleInfo failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
                return;
            }else {
                stPersonMonitorInfo.read();
                stPersonMonitorInfo.write();
                bRet = NetDemo.netdevsdk.NETDEV_GetPersonMonitorRuleInfo(NetDemo.lpUserID, stPersonMonitorInfo);
                if(bRet) {
                    stPersonMonitorInfo.read();
                    stPersonMonitorInfo.stMonitorRuleInfo.bEnabled = 0;
                    if(NetDemo.pstDeviceInfo.dwDeviceType == NETDEV_DEVICE_TYPE_E.NETDEV_DTYPE_NVR||
                            NetDemo.pstDeviceInfo.dwDeviceType == NETDEV_DEVICE_TYPE_E.NETDEV_DTYPE_HNVR||
                            NetDemo.pstDeviceInfo.dwDeviceType == NETDEV_DEVICE_TYPE_E.NETDEV_DTYPE_NVR_BACKUP
                        ) {
                        stPersonMonitorInfo.udwLinkStrategyNum=0;
                        stPersonMonitorInfo.write();
                    }else {
                        stPersonMonitorInfo.write();
                    }
                    stPersonMonitorInfo.write();
                    bRet = NetDemo.netdevsdk.NETDEV_SetPersonMonitorRuleInfo(NetDemo.lpUserID, stPersonMonitorInfo);
                    if(false == bRet)
                    {
                        JOptionPane.showMessageDialog(null, "NETDEV_SetPersonMonitorRuleInfo failed,error code"+ NetDemo.netdevsdk.NETDEV_GetLastError());
                        System.out.printf("NETDEV_SetPersonMonitorRuleInfo failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
                        return;
                    }else {
                        JOptionPane.showMessageDialog(null, "Set success");
                        NetDemo.jButtonFindPersonMonitor.doClick();
                    }
                }
            }
            
        }else {
            stPersonMonitorInfo.read();
            stPersonMonitorInfo.stMonitorRuleInfo.bEnabled = 0;
            if(NetDemo.pstDeviceInfo.dwDeviceType == NETDEV_DEVICE_TYPE_E.NETDEV_DTYPE_NVR||
                    NetDemo.pstDeviceInfo.dwDeviceType == NETDEV_DEVICE_TYPE_E.NETDEV_DTYPE_HNVR||
                    NetDemo.pstDeviceInfo.dwDeviceType == NETDEV_DEVICE_TYPE_E.NETDEV_DTYPE_NVR_BACKUP
                ) {
                stPersonMonitorInfo.udwLinkStrategyNum=0;
                stPersonMonitorInfo.write();
            }else {
                stPersonMonitorInfo.write();
            }
            stPersonMonitorInfo.write();
            bRet = NetDemo.netdevsdk.NETDEV_SetPersonMonitorRuleInfo(NetDemo.lpUserID, stPersonMonitorInfo);
            if(false == bRet)
            {
                JOptionPane.showMessageDialog(null, "NETDEV_SetPersonMonitorRuleInfo failed,error code"+ NetDemo.netdevsdk.NETDEV_GetLastError());
                System.out.printf("NETDEV_SetPersonMonitorRuleInfo failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
                return;
            }else {
                JOptionPane.showMessageDialog(null, "Set success");
                NetDemo.jButtonFindPersonMonitor.doClick();
            }
        }
    }
   /**
    * @introduction To modify person monitor.
    * @description  It is mainly realized by the constructor of PersonMonitor.
    */
    public static void modifyPersonMonitor() {
        if(null == NetDemo.lpUserID)
        {
            JOptionPane.showMessageDialog(null, "Please Login device first. error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
        
        if(0 == NetDemo.PersonMonitorTable.getRowCount() || NetDemo.PersonMonitorTable.getSelectedRow() < 0)
        {
            JOptionPane.showMessageDialog(null, "Please find monitor first");
            return;
        }
        String strPersonMonitorName = (String) NetDemo.PersonMonitorTable.getValueAt(NetDemo.PersonMonitorTable.getSelectedRow(), 0);
        PersonMonitor PP=new PersonMonitor(PERSON_MONITOR_OPERATE_WINDOW_EFFECT.PERSON_MONITOR_OPERATE_WINDOW_MODIFYPERSONMONITOR,NetDemo.jButtonFindPersonLib,NetDemo.jButtonFindPersonMonitor,strPersonMonitorName);
        PP.setVisible(true);
    }
}