|
@@ -1,10 +1,12 @@
|
1
|
1
|
package com.unissoft.face;
|
2
|
2
|
|
3
|
3
|
import com.sun.jna.Native;
|
|
4
|
+import com.sun.jna.Pointer;
|
4
|
5
|
import com.unissoft.common.osSelect;
|
5
|
6
|
import com.unissoft.netSDKDemo.HCNetSDK;
|
6
|
7
|
import com.unissoft.pushMsg.AddressModel;
|
7
|
8
|
import lombok.extern.slf4j.Slf4j;
|
|
9
|
+import org.dom4j.util.StringUtils;
|
8
|
10
|
import org.springframework.boot.ApplicationArguments;
|
9
|
11
|
import org.springframework.boot.ApplicationRunner;
|
10
|
12
|
import org.springframework.core.annotation.Order;
|
|
@@ -14,6 +16,9 @@ import javax.annotation.Resource;
|
14
|
16
|
import java.io.BufferedReader;
|
15
|
17
|
import java.io.IOException;
|
16
|
18
|
import java.io.InputStreamReader;
|
|
19
|
+import java.time.LocalDate;
|
|
20
|
+import java.util.Calendar;
|
|
21
|
+import java.util.Date;
|
17
|
22
|
import java.util.Scanner;
|
18
|
23
|
|
19
|
24
|
@Slf4j
|
|
@@ -35,6 +40,7 @@ public class FaceMain implements ApplicationRunner {
|
35
|
40
|
*/
|
36
|
41
|
private void mainMethod() {
|
37
|
42
|
log.info("FaceMain mainMethod===========================================================init thread");
|
|
43
|
+
|
38
|
44
|
try {
|
39
|
45
|
if (hCNetSDK == null) {
|
40
|
46
|
if (!CreateSDKInstance()) {
|
|
@@ -42,13 +48,16 @@ public class FaceMain implements ApplicationRunner {
|
42
|
48
|
return;
|
43
|
49
|
}
|
44
|
50
|
}
|
|
51
|
+
|
45
|
52
|
//linux系统建议调用以下接口加载组件库
|
46
|
53
|
if (osSelect.isLinux()) {
|
|
54
|
+ System.out.println("linux system come in here");
|
47
|
55
|
HCNetSDK.BYTE_ARRAY ptrByteArray1 = new HCNetSDK.BYTE_ARRAY(256);
|
48
|
56
|
HCNetSDK.BYTE_ARRAY ptrByteArray2 = new HCNetSDK.BYTE_ARRAY(256);
|
49
|
57
|
//这里是库的绝对路径,请根据实际情况修改,注意改路径必须有访问权限
|
50
|
58
|
String strPath1 = System.getProperty("user.dir") + "/lib/libcrypto.so.1.1";
|
51
|
59
|
String strPath2 = System.getProperty("user.dir") + "/lib/libssl.so.1.1";
|
|
60
|
+ System.out.println("strPath1:" + strPath1);
|
52
|
61
|
|
53
|
62
|
System.arraycopy(strPath1.getBytes(), 0, ptrByteArray1.byValue, 0, strPath1.length());
|
54
|
63
|
ptrByteArray1.write();
|
|
@@ -64,7 +73,6 @@ public class FaceMain implements ApplicationRunner {
|
64
|
73
|
struComPath.write();
|
65
|
74
|
hCNetSDK.NET_DVR_SetSDKInitCfg(2, struComPath.getPointer());
|
66
|
75
|
}
|
67
|
|
-
|
68
|
76
|
//初始化
|
69
|
77
|
hCNetSDK.NET_DVR_Init();
|
70
|
78
|
|
|
@@ -74,7 +82,7 @@ public class FaceMain implements ApplicationRunner {
|
74
|
82
|
//登录设备,每一台设备分别登录; 登录句柄是唯一的,可以区分设备
|
75
|
83
|
HCNetSDK.NET_DVR_USER_LOGIN_INFO m_strLoginInfo = new HCNetSDK.NET_DVR_USER_LOGIN_INFO();//设备登录信息
|
76
|
84
|
HCNetSDK.NET_DVR_DEVICEINFO_V40 m_strDeviceInfo = new HCNetSDK.NET_DVR_DEVICEINFO_V40();//设备信息
|
77
|
|
-
|
|
85
|
+ //m_strDeviceInfo.struDeviceV30.
|
78
|
86
|
String m_sDeviceIP = addressModel.getDeviceIP();//设备ip地址
|
79
|
87
|
m_strLoginInfo.sDeviceAddress = new byte[HCNetSDK.NET_DVR_DEV_ADDRESS_MAX_LEN];
|
80
|
88
|
System.arraycopy(m_sDeviceIP.getBytes(), 0, m_strLoginInfo.sDeviceAddress, 0, m_sDeviceIP.length());
|
|
@@ -92,6 +100,7 @@ public class FaceMain implements ApplicationRunner {
|
92
|
100
|
m_strLoginInfo.byLoginMode = 0; //登录模式:0- SDK私有协议,1- ISAPI协议
|
93
|
101
|
m_strLoginInfo.write();
|
94
|
102
|
|
|
103
|
+
|
95
|
104
|
lUserID = hCNetSDK.NET_DVR_Login_V40(m_strLoginInfo, m_strDeviceInfo);
|
96
|
105
|
if (lUserID == -1) {
|
97
|
106
|
log.error("登录失败,错误码为: {}", hCNetSDK.NET_DVR_GetLastError());
|
|
@@ -100,49 +109,74 @@ public class FaceMain implements ApplicationRunner {
|
100
|
109
|
m_strDeviceInfo.read();
|
101
|
110
|
}
|
102
|
111
|
|
|
112
|
+ try {
|
|
113
|
+ log.info("進行撤防");
|
|
114
|
+ hCNetSDK.NET_DVR_CloseAlarmChan_V30(lAlarmHandle);
|
|
115
|
+ } catch (Exception e) {
|
|
116
|
+ log.info("不需要撤防");
|
|
117
|
+ }
|
|
118
|
+ try {
|
|
119
|
+ log.info("停止监听");
|
|
120
|
+ hCNetSDK.NET_DVR_StopListen_V30(lListenHandle);
|
|
121
|
+ } catch (Exception e) {
|
|
122
|
+ log.info("不需要停止监听");
|
|
123
|
+ }
|
|
124
|
+
|
103
|
125
|
//报警布防实时接收人脸比对的结果信息,也可以单独参考“2-报警布防监听”这个Demo示例
|
104
|
126
|
Alarm.SetAlarm(lUserID);
|
105
|
127
|
|
106
|
128
|
// TODO 暂停状态 需要测试改造
|
|
129
|
+ Date satart = new Date();
|
|
130
|
+ Calendar c1 = Calendar.getInstance();
|
|
131
|
+ c1.setTime(satart);
|
107
|
132
|
while (true) {
|
108
|
133
|
//这里加入控制台输入控制,是为了保持连接状态,当输入Y表示布防结束
|
109
|
|
- log.info("请选择是否撤出布防(Y/N):");
|
|
134
|
+ log.info("监听进行中,输入字母Q可退出监听");
|
110
|
135
|
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
|
111
|
136
|
String str = bufferedReader.readLine();
|
112
|
|
- if (str.toUpperCase().equals("Y")) {
|
|
137
|
+ if (str.toUpperCase().equals("Q")) {
|
|
138
|
+ break;
|
|
139
|
+ /*
|
|
140
|
+ Thread.sleep(60000);
|
|
141
|
+ Date end = new Date();
|
|
142
|
+ Calendar c2 = Calendar.getInstance();
|
|
143
|
+ c2.setTime(end);
|
|
144
|
+ long millis = c2.getTimeInMillis() - c1.getTimeInMillis();
|
|
145
|
+ long hours = millis/(1000*60*60);
|
|
146
|
+ if(hours > 10) {
|
|
147
|
+ log.info("时间过去10小时,退出程序");
|
113
|
148
|
break;
|
114
|
149
|
}
|
115
|
|
- }
|
116
|
|
- Thread.sleep(3000);
|
117
|
|
-
|
118
|
|
- //退出之前判断布防监听状态,并做撤防和停止监听操作
|
119
|
|
- if (lAlarmHandle >= 0) {
|
120
|
|
- if (!hCNetSDK.NET_DVR_CloseAlarmChan_V30(lAlarmHandle)) {
|
121
|
|
- log.error("撤防失败,错误码: {}", hCNetSDK.NET_DVR_GetLastError());
|
122
|
|
- } else {
|
123
|
|
- log.info("撤防成功!!!");
|
|
150
|
+ }*/
|
124
|
151
|
}
|
125
|
|
- }
|
126
|
|
- if (lListenHandle >= 0) {
|
127
|
|
- if (!hCNetSDK.NET_DVR_StopListen_V30(lListenHandle)) {
|
128
|
|
- log.error("取消监听失败,错误码:{}", hCNetSDK.NET_DVR_GetLastError());
|
129
|
|
- } else {
|
130
|
|
- log.info("停止监听成功!!!");
|
|
152
|
+
|
|
153
|
+ //退出之前判断布防监听状态,并做撤防和停止监听操作
|
|
154
|
+ if (lAlarmHandle >= 0) {
|
|
155
|
+ if (!hCNetSDK.NET_DVR_CloseAlarmChan_V30(lAlarmHandle)) {
|
|
156
|
+ log.error("撤防失败,错误码: {}", hCNetSDK.NET_DVR_GetLastError());
|
|
157
|
+ } else {
|
|
158
|
+ log.info("撤防成功!!!");
|
|
159
|
+ }
|
|
160
|
+ }
|
|
161
|
+ if (lListenHandle >= 0) {
|
|
162
|
+ if (!hCNetSDK.NET_DVR_StopListen_V30(lListenHandle)) {
|
|
163
|
+ log.error("取消监听失败,错误码:{}", hCNetSDK.NET_DVR_GetLastError());
|
|
164
|
+ } else {
|
|
165
|
+ log.info("停止监听成功!!!");
|
|
166
|
+ }
|
131
|
167
|
}
|
132
|
|
- }
|
133
|
168
|
|
134
|
|
- //注销登录,程序退出时调用;程序同时对接多台设备时,每一台设备分别调用一次接口,传入不同的登录句柄
|
135
|
|
- if (lUserID >= 0) {
|
136
|
|
- hCNetSDK.NET_DVR_Logout(lUserID);
|
137
|
|
- }
|
|
169
|
+ //注销登录,程序退出时调用;程序同时对接多台设备时,每一台设备分别调用一次接口,传入不同的登录句柄
|
|
170
|
+ if (lUserID >= 0) {
|
|
171
|
+ hCNetSDK.NET_DVR_Logout(lUserID);
|
|
172
|
+ }
|
138
|
173
|
|
139
|
|
- //SDK反初始化,释放资源,程序退出时调用
|
140
|
|
- boolean b = hCNetSDK.NET_DVR_Cleanup();
|
141
|
|
- if (b)
|
142
|
|
- log.info("释放资源,程序退出!");
|
143
|
|
- } catch (InterruptedException e) {
|
144
|
|
- e.printStackTrace();
|
145
|
|
- } catch (IOException e) {
|
|
174
|
+ //SDK反初始化,释放资源,程序退出时调用
|
|
175
|
+ boolean b = hCNetSDK.NET_DVR_Cleanup();
|
|
176
|
+ if (b)
|
|
177
|
+ log.info("释放资源,程序退出!");
|
|
178
|
+ }
|
|
179
|
+ } catch (Exception e) {
|
146
|
180
|
e.printStackTrace();
|
147
|
181
|
}
|
148
|
182
|
}
|
|
@@ -174,9 +208,72 @@ public class FaceMain implements ApplicationRunner {
|
174
|
208
|
return true;
|
175
|
209
|
}
|
176
|
210
|
|
|
211
|
+ private void alarmListenMethod() {
|
|
212
|
+
|
|
213
|
+ if (hCNetSDK == null) {
|
|
214
|
+ if (!CreateSDKInstance()) {
|
|
215
|
+ log.error("Load SDK fail");
|
|
216
|
+ return;
|
|
217
|
+ }
|
|
218
|
+ }
|
|
219
|
+
|
|
220
|
+ //linux系统建议调用以下接口加载组件库
|
|
221
|
+ if (osSelect.isLinux()) {
|
|
222
|
+ System.out.println("linux system come in here");
|
|
223
|
+ HCNetSDK.BYTE_ARRAY ptrByteArray1 = new HCNetSDK.BYTE_ARRAY(256);
|
|
224
|
+ HCNetSDK.BYTE_ARRAY ptrByteArray2 = new HCNetSDK.BYTE_ARRAY(256);
|
|
225
|
+ //这里是库的绝对路径,请根据实际情况修改,注意改路径必须有访问权限
|
|
226
|
+ String strPath1 = System.getProperty("user.dir") + "/lib/libcrypto.so.1.1";
|
|
227
|
+ String strPath2 = System.getProperty("user.dir") + "/lib/libssl.so.1.1";
|
|
228
|
+ System.out.println("strPath1:" + strPath1);
|
|
229
|
+
|
|
230
|
+ System.arraycopy(strPath1.getBytes(), 0, ptrByteArray1.byValue, 0, strPath1.length());
|
|
231
|
+ ptrByteArray1.write();
|
|
232
|
+ hCNetSDK.NET_DVR_SetSDKInitCfg(3, ptrByteArray1.getPointer());
|
|
233
|
+
|
|
234
|
+ System.arraycopy(strPath2.getBytes(), 0, ptrByteArray2.byValue, 0, strPath2.length());
|
|
235
|
+ ptrByteArray2.write();
|
|
236
|
+ hCNetSDK.NET_DVR_SetSDKInitCfg(4, ptrByteArray2.getPointer());
|
|
237
|
+
|
|
238
|
+ String strPathCom = System.getProperty("user.dir") + "/lib";
|
|
239
|
+ HCNetSDK.NET_DVR_LOCAL_SDK_PATH struComPath = new HCNetSDK.NET_DVR_LOCAL_SDK_PATH();
|
|
240
|
+ System.arraycopy(strPathCom.getBytes(), 0, struComPath.sPath, 0, strPathCom.length());
|
|
241
|
+ struComPath.write();
|
|
242
|
+ hCNetSDK.NET_DVR_SetSDKInitCfg(2, struComPath.getPointer());
|
|
243
|
+ }
|
|
244
|
+ //初始化
|
|
245
|
+ hCNetSDK.NET_DVR_Init();
|
|
246
|
+ Alarm.StartListen();
|
|
247
|
+ try {
|
|
248
|
+ while (true) {
|
|
249
|
+ Thread.sleep(60000);
|
|
250
|
+ log.info("监听进行中,如需退出监听请输入字母Q");
|
|
251
|
+ BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
|
|
252
|
+ String str = bufferedReader.readLine();
|
|
253
|
+ if (str.toUpperCase().equals("Q")) {
|
|
254
|
+ break;
|
|
255
|
+ }
|
|
256
|
+ }
|
|
257
|
+ } catch (InterruptedException e) {
|
|
258
|
+ e.printStackTrace();
|
|
259
|
+ } catch (IOException ioe) {
|
|
260
|
+ ioe.printStackTrace();
|
|
261
|
+ }
|
|
262
|
+
|
|
263
|
+ //停止监听
|
|
264
|
+ if (lListenHandle >= 0) {
|
|
265
|
+ if (!hCNetSDK.NET_DVR_StopListen_V30(lListenHandle)) {
|
|
266
|
+ log.error("取消监听失败,错误码:{}", hCNetSDK.NET_DVR_GetLastError());
|
|
267
|
+ } else {
|
|
268
|
+ log.info("停止监听成功!!!");
|
|
269
|
+ }
|
|
270
|
+ }
|
|
271
|
+ hCNetSDK.NET_DVR_Cleanup();
|
|
272
|
+ }
|
177
|
273
|
@Override
|
178
|
274
|
public void run(ApplicationArguments args) throws Exception {
|
179
|
|
- // after behind for application run,because implements ApplicationRunner
|
|
275
|
+ //after behind for application run,because implements ApplicationRunner
|
180
|
276
|
this.mainMethod();
|
|
277
|
+ //this.alarmListenMethod();
|
181
|
278
|
}
|
182
|
279
|
}
|