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
package com.ycl.api.YS.vca.face;
 
import com.sun.jna.Memory;
import com.ycl.api.YS.NetDemo;
import com.ycl.api.YS.lib.NetDEVSDKLib.NETDEV_LAPI_SUB_INFO_S;
import com.ycl.api.YS.lib.NetDEVSDKLib.NETDEV_SMART_INFO_S;
import com.ycl.api.YS.lib.NetDEVSDKLib.NETDEV_SUBSCRIBE_SMART_INFO_S;
import com.ycl.api.YS.lib.NetDEVSDKLib.NETDEV_SUBSCRIBE_SUCC_INFO_S;
 
import javax.swing.*;
 
/**
 * @description Data report includes registerPersonAlarm,cancelregisterPersonAlarm,registerPersonRecognize and cancelPersonRecognize
 * @introduction Support IPC/VMS.
 */
public class PersonAlarm {
    /**
     * @introduction To register person alarm.
     * @description Calling the interface of NETDEV_SetPersonAlarmCallBack,NETDEV_SubscibeLapiAlarm and NETDEV_SetAlarmCallBack_V30 to realize.
     */
    public static void registerPersonAlarm() {
        if(null == NetDemo.lpUserID)
        {
            JOptionPane.showMessageDialog(null, "Please Login device first. error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
        boolean bRet = NetDemo.netdevsdk.NETDEV_SetPersonAlarmCallBack(NetDemo.lpUserID, NetDemo.personAlarmMessCB, NetDemo.lpUserID);
        if(false == bRet)
        {
            JOptionPane.showMessageDialog(null, "SetPersonAlarmCallBack failed,error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            System.out.printf("NETDEV_SetPersonAlarmCallBack failed:%d", NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
        if(NetDemo.jComboBoxDeviceType.getSelectedIndex() == 0)
        {
            NETDEV_LAPI_SUB_INFO_S stSubInfo = new NETDEV_LAPI_SUB_INFO_S();
            stSubInfo.udwType = 16;
            stSubInfo.udwLibIDNum = 0xffff;
            NETDEV_SUBSCRIBE_SUCC_INFO_S stSubSuccInfo = new NETDEV_SUBSCRIBE_SUCC_INFO_S();
            bRet = NetDemo.netdevsdk.NETDEV_SubscibeLapiAlarm(NetDemo.lpUserID, stSubInfo, stSubSuccInfo);
            if(false == bRet){
                JOptionPane.showMessageDialog(null, "NETDEV_SubscibeLapiAlarm failed,error code"+ NetDemo.netdevsdk.NETDEV_GetLastError());
                System.out.printf("NETDEV_SubscibeLapiAlarm failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
                return;
            }else {
                JOptionPane.showMessageDialog(null, "Register success");
            }
            NetDemo.dwPersonRecognizeMointerID = stSubSuccInfo.udwID;
        }
        else
        {
            bRet = NetDemo.netdevsdk.NETDEV_SetAlarmCallBack_V30(NetDemo.lpUserID, NetDemo.cbAlarmMessCallBack, null);
            if(false == bRet)
            {
                JOptionPane.showMessageDialog(null, "NETDEV_SetAlarmCallBack_V30 failed,error code"+ NetDemo.netdevsdk.NETDEV_GetLastError());
                System.out.printf("NETDEV_SetAlarmCallBack_V30 failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
                return;
            }
            NETDEV_LAPI_SUB_INFO_S stSubInfo = new NETDEV_LAPI_SUB_INFO_S();
            stSubInfo.udwType = 16;
            stSubInfo.udwLibIDNum =  0xffff;
            NETDEV_SUBSCRIBE_SUCC_INFO_S stSubSuccInfo = new NETDEV_SUBSCRIBE_SUCC_INFO_S();
            bRet = NetDemo.netdevsdk.NETDEV_SubscibeLapiAlarm(NetDemo.lpUserID, stSubInfo, stSubSuccInfo);
            if(false == bRet)
            {
                JOptionPane.showMessageDialog(null, "NETDEV_SubscibeLapiAlarm failed,error code"+ NetDemo.netdevsdk.NETDEV_GetLastError());
                System.out.printf("NETDEV_SubscibeLapiAlarm failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
                return;
            }
            else 
            {
                JOptionPane.showMessageDialog(null, "Register success");
            }
            NetDemo.dwPersonRecognizeMointerID = stSubSuccInfo.udwID;
        }
    }
    /**
     * @introduction To cancel register person alarm.
     * @description Calling the interface of NETDEV_UnSubLapiAlarm and NETDEV_SetAlarmCallBack_V30 to realize.
     */
    public static void cancelRegisterPersonAlarm() {
        if(null == NetDemo.lpUserID)
        {
            JOptionPane.showMessageDialog(null, "Please Login device first. error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
        if(NetDemo.jComboBoxDeviceType.getSelectedIndex() == 0)
        {
            boolean bRet = NetDemo.netdevsdk.NETDEV_UnSubLapiAlarm(NetDemo.lpUserID, NetDemo.dwPersonRecognizeMointerID);
            if(false == bRet)
            {
                JOptionPane.showMessageDialog(null, "NETDEV_UnSubLapiAlarm failed,error code"+ NetDemo.netdevsdk.NETDEV_GetLastError());
                System.out.printf("NETDEV_UnSubLapiAlarm failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
                return;
            }
            else 
            {
                JOptionPane.showMessageDialog(null, "Cancel success");
            }
            NetDemo.dwPersonRecognizeMointerID = -1;
        }
        else
        { 
            boolean bRet3 = NetDemo.netdevsdk.NETDEV_SetAlarmCallBack_V30(NetDemo.lpUserID, null, null);
            if(false == bRet3)
            {
                JOptionPane.showMessageDialog(null, "NETDEV_SetAlarmCallBack_V30 failed,error code"+ NetDemo.netdevsdk.NETDEV_GetLastError());
                System.out.printf("NETDEV_SetAlarmCallBack_V30 failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
                return;
            }
            boolean bRet = NetDemo.netdevsdk.NETDEV_UnSubLapiAlarm(NetDemo.lpUserID, NetDemo.dwPersonRecognizeMointerID);
            if(false == bRet)
            {
                JOptionPane.showMessageDialog(null, "NETDEV_UnSubLapiAlarm failed,error code"+ NetDemo.netdevsdk.NETDEV_GetLastError());
                System.out.printf("NETDEV_UnSubLapiAlarm failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
                return;
            }
            else 
            {
                JOptionPane.showMessageDialog(null, "Cancel success");
            }
            NetDemo.dwPersonRecognizeMointerID = -1;
        }
    }
    
    /**
     * @introduction To register person recognize.
     * @description Calling the interface of NETDEV_SetStructAlarmCallBack,NETDEV_SubscibeLapiAlarm to realize.
     */
    public static void registerPersonRecognize() {
        if(null == NetDemo.lpUserID)
        {
            JOptionPane.showMessageDialog(null, "Please Login device first. error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
        if(0 == NetDemo.ChannelID)
        {
            JOptionPane.showMessageDialog(null, "Please select the device channel.");
            return;
        }
        boolean bRet = NetDemo.netdevsdk.NETDEV_SetStructAlarmCallBack(NetDemo.lpUserID, NetDemo.cbStructAlarmCallBack, NetDemo.lpUserID);
        if(false == bRet)
        {
            JOptionPane.showMessageDialog(null, "NETDEV_SetStructAlarmCallBack failed,error code"+ NetDemo.netdevsdk.NETDEV_GetLastError());
            System.out.printf("NETDEV_SetStructAlarmCallBack failed:%d", NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
        if(NetDemo.jComboBoxDeviceType.getSelectedIndex() == 0)
        {
            NETDEV_LAPI_SUB_INFO_S stSubInfo = new NETDEV_LAPI_SUB_INFO_S();
            stSubInfo.udwType = 32;
            stSubInfo.udwLibIDNum = 0xffff;
 
            NETDEV_SUBSCRIBE_SUCC_INFO_S stSubSuccInfo = new NETDEV_SUBSCRIBE_SUCC_INFO_S();
            bRet = NetDemo.netdevsdk.NETDEV_SubscibeLapiAlarm(NetDemo.lpUserID, stSubInfo, stSubSuccInfo);
            if(false == bRet){
                JOptionPane.showMessageDialog(null, "NETDEV_SubscibeLapiAlarm failed,error code"+ NetDemo.netdevsdk.NETDEV_GetLastError());
                System.out.printf("NETDEV_SubscibeLapiAlarm failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
                return;
            }else {
                JOptionPane.showMessageDialog(null, "Register success");
            }
 
            NetDemo.PersonStructMointerID = stSubSuccInfo.udwID;
            
        }
        else
        {
            bRet = NetDemo.netdevsdk.NETDEV_SetAlarmCallBack_V30(NetDemo.lpUserID, NetDemo.cbAlarmMessCallBack, null);
            if(false == bRet)
            {
                JOptionPane.showMessageDialog(null, "NETDEV_SetAlarmCallBack_V30 failed,error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
                System.out.printf("NETDEV_SetAlarmCallBack_V30 failed:%d", NetDemo.netdevsdk.NETDEV_GetLastError());
            }
            NETDEV_SUBSCRIBE_SMART_INFO_S stSubscribeInfo = new NETDEV_SUBSCRIBE_SMART_INFO_S();
            stSubscribeInfo.udwNum = 1;
            stSubscribeInfo.pudwSmartType = new Memory(4 * stSubscribeInfo.udwNum);
            stSubscribeInfo.pudwSmartType.setInt(0,0);
            NETDEV_SMART_INFO_S stSmartInfo = new NETDEV_SMART_INFO_S();
            stSmartInfo.dwChannelID = NetDemo.ChannelID;
            bRet = NetDemo.netdevsdk.NETDEV_SubscribeSmart(NetDemo.lpUserID, stSubscribeInfo, stSmartInfo);
            if(false == bRet)
            {
                JOptionPane.showMessageDialog(null, "NETDEV_SubscribeSmart failed,error code"+ NetDemo.netdevsdk.NETDEV_GetLastError());
                System.out.printf("NETDEV_SubscribeSmart failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
                return;
            }
            else 
            {
                JOptionPane.showMessageDialog(null, "Register success");
            }
            NetDemo.PersonStructMointerID = stSmartInfo.udwSubscribeID;
        }
    }
    /**
     * @introduction To cancel register person recognize.
     * @description Calling the interface of NETDEV_UnSubLapiAlarm and NETDEV_SetAlarmCallBack_V30 to realize.
     */
    public static void cancelPersonRecognize() {
        if(null == NetDemo.lpUserID)
        {
            JOptionPane.showMessageDialog(null, "Please Login device first. error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
            return;
        }
        if(0 ==  NetDemo.ChannelID || 0 ==  NetDemo.PersonStructMointerID)
        {
            JOptionPane.showMessageDialog(null, "Please select the device channel.");
            return;
        }
        
        if( NetDemo.jComboBoxDeviceType.getSelectedIndex() == 0)
        {
            boolean bRet = NetDemo.netdevsdk.NETDEV_UnSubLapiAlarm(NetDemo.lpUserID, NetDemo.PersonStructMointerID);
            if(false == bRet)
            {
                JOptionPane.showMessageDialog(null, "NETDEV_UnSubLapiAlarm failed,error code"+ NetDemo.netdevsdk.NETDEV_GetLastError());
                System.out.printf("NETDEV_UnSubLapiAlarm failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
                return;
            }
            else 
            {
                JOptionPane.showMessageDialog(null, "Cancel success");
            }
            NetDemo.PersonStructMointerID = -1;
        }
        else
        {
            boolean bRet3 = NetDemo.netdevsdk.NETDEV_SetAlarmCallBack_V30(NetDemo.lpUserID, null, null);
            if(false == bRet3)
            {
                JOptionPane.showMessageDialog(null, "NETDEV_SetAlarmCallBack_V30 failed,error code"+NetDemo.netdevsdk.NETDEV_GetLastError());
                System.out.printf("NETDEV_SetAlarmCallBack_V30 failed:%d", NetDemo.netdevsdk.NETDEV_GetLastError());
            }
            NETDEV_SMART_INFO_S stSmartInfo = new NETDEV_SMART_INFO_S();
            stSmartInfo.dwChannelID = NetDemo.ChannelID;
            stSmartInfo.udwSubscribeID = NetDemo.PersonStructMointerID;
            boolean bRet = NetDemo.netdevsdk.NETDEV_UnsubscribeSmart(NetDemo.lpUserID, stSmartInfo);
            if(false == bRet)
            {
                JOptionPane.showMessageDialog(null, "NETDEV_UnsubscribeSmart failed,error code"+ NetDemo.netdevsdk.NETDEV_GetLastError());
                System.out.printf("NETDEV_UnsubscribeSmart failed:%d\n", NetDemo.netdevsdk.NETDEV_GetLastError());
                return;
            }
            else 
            {
                JOptionPane.showMessageDialog(null, "Cancel success");
            }
            NetDemo.PersonStructMointerID=-1;
        }  
    }
}