passThrough(long userId, String url, byte[] inputBytes,
46 | int exceptOutByteSize);
47 |
48 | /**
49 | * 布防.
50 | *
51 | * 包括3个步骤: a.设置回调消息, b.建立上传通道, c.设置异常回调.
52 | */
53 | HikResult setupDeploy(long userId, HCNetSDK.FMSGCallBack messageCallback,
54 | FExceptionCallBack exceptionCallback);
55 |
56 | /**
57 | * 修改设备密码.
58 | */
59 | HikResult> modifyPassword(long userId, String username, String newPassword);
60 |
61 | /**
62 | * NVR重新绑定通道, 抓拍机修改密码后需要重新绑定.
63 | */
64 | HikResult> nvrRebindChannels(long userId, String dvrUsername, String dvrNewPassword);
65 |
66 | /**
67 | * 获取设备配置数据.
68 | */
69 | @SneakyThrows
70 | HikResult getDvrConfig(long userId, long channel, int command,
71 | Class clazz);
72 |
73 | /**
74 | * 获取设备配置数据.
75 | */
76 | HikResult> getDvrConfig(long userId, long channel, int command, Structure data);
77 |
78 | /**
79 | * 设置设备配置数据.
80 | */
81 | HikResult> setDvrConfig(long userId, long channel, int command, Structure data);
82 |
83 | /**
84 | * 设置视频实时预览
85 | */
86 | HikResult realPlay(long userId, FRealDataCallBack_V30 callback);
87 |
88 | /**
89 | * 设置实时预览
90 | */
91 | HikResult realPlay(long userId, NET_DVR_PREVIEWINFO previewInfo,
92 | FRealDataCallBack_V30 callback);
93 |
94 | /**
95 | * 停止实时预览
96 | */
97 | HikResult> stopRealPlay(long realHandle);
98 |
99 | /**
100 | * 本地sdk操作.
101 | */
102 | SdkOptions opsForSdk();
103 |
104 | /**
105 | * 设备维护.
106 | */
107 | MaintainOptions opsForMaintain(long userId);
108 |
109 | /**
110 | * 云台操作.
111 | */
112 | PtzOptions opsForPtz(long userId);
113 |
114 | }
115 |
--------------------------------------------------------------------------------
/src/main/java/com/github/lkqm/hcnet/HikDevice.java:
--------------------------------------------------------------------------------
1 | package com.github.lkqm.hcnet;
2 |
3 | import com.github.lkqm.hcnet.HCNetSDK.FExceptionCallBack;
4 | import com.github.lkqm.hcnet.HCNetSDK.FMSGCallBack;
5 | import com.github.lkqm.hcnet.model.PassThroughResponse;
6 | import com.github.lkqm.hcnet.options.MaintainOptions;
7 | import com.github.lkqm.hcnet.options.PtzOptions;
8 | import com.github.lkqm.hcnet.util.BiFunction;
9 | import com.sun.jna.NativeLong;
10 | import com.sun.jna.Structure;
11 | import lombok.Getter;
12 |
13 | /**
14 | * 设备.
15 | *
16 | * 线程安全的.
17 | */
18 | public class HikDevice implements DeviceOptions {
19 |
20 | @Getter
21 | private final String ip;
22 | @Getter
23 | private final int port;
24 |
25 | private final String user;
26 | private final String password;
27 | @Getter
28 | private final HikDeviceTemplate deviceTemplate;
29 |
30 | @Getter
31 | private volatile Token token;
32 | private volatile Long setupAlarmHandle;
33 |
34 | public HikDevice(HCNetSDK hcnetsdk, String ip, int port, String user, String password) {
35 | this.deviceTemplate = new HikDeviceTemplate(hcnetsdk);
36 | this.ip = ip;
37 | this.port = port;
38 | this.user = user;
39 | this.password = password;
40 | }
41 |
42 | @Override
43 | public HikResult> init() {
44 | if (token == null) {
45 | synchronized (this) {
46 | if (token == null) {
47 | HikResult loginResult = deviceTemplate.login(ip, port, user, password);
48 | if (loginResult.isSuccess()) {
49 | token = loginResult.getData();
50 | }
51 | return loginResult;
52 | }
53 | }
54 | }
55 | return HikResult.ok();
56 | }
57 |
58 | @Override
59 | public synchronized void destroy() {
60 | // 消息回调取消布防
61 | if (setupAlarmHandle != null) {
62 | deviceTemplate.getHcnetsdk().NET_DVR_CloseAlarmChan_V30(new NativeLong(setupAlarmHandle));
63 | setupAlarmHandle = null;
64 | }
65 |
66 | // 登录注销
67 | if (token != null && token.getUserId() != null) {
68 | deviceTemplate.logout(token.getUserId());
69 | }
70 | }
71 |
72 | @Override
73 | public HikResult> doAction(BiFunction> action) {
74 | checkInit();
75 | return action.apply(deviceTemplate.getHcnetsdk(), token);
76 | }
77 |
78 | @Override
79 | public HikResult setupDeploy(FMSGCallBack messageCallback, FExceptionCallBack exceptionCallback) {
80 | checkInit();
81 | if (setupAlarmHandle != null) {
82 | throw new RuntimeException("重复布防.");
83 | }
84 | HikResult deployResult = deviceTemplate
85 | .setupDeploy(token.getUserId(), messageCallback, exceptionCallback);
86 | if (deployResult.isSuccess() && deployResult.getData() != null) {
87 | setupAlarmHandle = deployResult.getData();
88 | }
89 | return deployResult;
90 | }
91 |
92 | @Override
93 | public HikResult passThrough(String url, String data) {
94 | checkInit();
95 | return deviceTemplate.passThrough(token.getUserId(), url, data);
96 | }
97 |
98 | @Override
99 | public HikResult passThrough(String url, String data, int exceptOutByteSize) {
100 | checkInit();
101 | return deviceTemplate.passThrough(token.getUserId(), url, data.getBytes(), exceptOutByteSize);
102 | }
103 |
104 | @Override
105 | public HikResult getDvrConfig(long channel, int command, Class clazz) {
106 | checkInit();
107 | return deviceTemplate.getDvrConfig(token.getUserId(), channel, command, clazz);
108 | }
109 |
110 | @Override
111 | public HikResult> setDvrConfig(long channel, int type, Structure settings) {
112 | checkInit();
113 | return deviceTemplate.setDvrConfig(token.getUserId(), channel, type, settings);
114 | }
115 |
116 | @Override
117 | public HikResult> modifyPassword(String targetUser, String newPassword) {
118 | checkInit();
119 | return deviceTemplate.modifyPassword(token.getUserId(), targetUser, newPassword);
120 | }
121 |
122 | @Override
123 | public MaintainOptions opsForMaintain() {
124 | checkInit();
125 | return deviceTemplate.opsForMaintain(token.getUserId());
126 | }
127 |
128 | @Override
129 | public PtzOptions opsForPtz() {
130 | checkInit();
131 | return deviceTemplate.opsForPtz(token.getUserId());
132 | }
133 |
134 | private void checkInit() {
135 | HikResult> result = init();
136 | if (!result.isSuccess()) {
137 | throw new RuntimeException(result.getError());
138 | }
139 | }
140 |
141 | }
142 |
--------------------------------------------------------------------------------
/src/main/java/com/github/lkqm/hcnet/HikDeviceTemplate.java:
--------------------------------------------------------------------------------
1 | package com.github.lkqm.hcnet;
2 |
3 | import com.github.lkqm.hcnet.HCNetSDK.FExceptionCallBack;
4 | import com.github.lkqm.hcnet.HCNetSDK.FRealDataCallBack_V30;
5 | import com.github.lkqm.hcnet.HCNetSDK.NET_DVR_DEVICEINFO_V40;
6 | import com.github.lkqm.hcnet.HCNetSDK.NET_DVR_PREVIEWINFO;
7 | import com.github.lkqm.hcnet.HCNetSDK.NET_DVR_USER_LOGIN_INFO;
8 | import com.github.lkqm.hcnet.model.PassThroughResponse;
9 | import com.github.lkqm.hcnet.model.ResponseStatus;
10 | import com.github.lkqm.hcnet.options.MaintainOptions;
11 | import com.github.lkqm.hcnet.options.MaintainOptionsImpl;
12 | import com.github.lkqm.hcnet.options.PtzOptions;
13 | import com.github.lkqm.hcnet.options.PtzOptionsImpl;
14 | import com.github.lkqm.hcnet.options.SdkOptions;
15 | import com.github.lkqm.hcnet.options.SdkOptionsImpl;
16 | import com.github.lkqm.hcnet.util.BiFunction;
17 | import com.sun.jna.NativeLong;
18 | import com.sun.jna.Pointer;
19 | import com.sun.jna.Structure;
20 | import com.sun.jna.ptr.IntByReference;
21 | import com.sun.jna.ptr.NativeLongByReference;
22 | import java.util.Objects;
23 | import lombok.Getter;
24 | import lombok.NonNull;
25 | import lombok.SneakyThrows;
26 |
27 | /**
28 | * 海康SDK工具类.
29 | */
30 | public class HikDeviceTemplate implements DeviceTemplateOptions {
31 |
32 | public static final int DEFAULT_PORT = 8000;
33 |
34 | @Getter
35 | @NonNull
36 | private final HCNetSDK hcnetsdk;
37 |
38 | public HikDeviceTemplate(@NonNull HCNetSDK hcnetsdk) {
39 | hcnetsdk.NET_DVR_Init();
40 | this.hcnetsdk = hcnetsdk;
41 | }
42 |
43 | @Override
44 | public HikResult login(String ip, int port, String user, String password) {
45 | HCNetSDK.NET_DVR_USER_LOGIN_INFO loginInfo = new NET_DVR_USER_LOGIN_INFO();
46 | System.arraycopy(ip.getBytes(), 0, loginInfo.sDeviceAddress, 0, ip.length());
47 | loginInfo.wPort = (short) port;
48 | System.arraycopy(user.getBytes(), 0, loginInfo.sUserName, 0, user.length());
49 | System.arraycopy(password.getBytes(), 0, loginInfo.sPassword, 0, password.length());
50 | loginInfo.bUseAsynLogin = 0;
51 | loginInfo.write();
52 |
53 | HCNetSDK.NET_DVR_DEVICEINFO_V40 deviceInfo = new NET_DVR_DEVICEINFO_V40();
54 | NativeLong userId = hcnetsdk.NET_DVR_Login_V40(loginInfo.getPointer(), deviceInfo.getPointer());
55 | deviceInfo.read();
56 | if (userId.longValue() == -1) {
57 | return lastError();
58 | }
59 |
60 | Token token = Token.builder()
61 | .userId(userId.longValue())
62 | .deviceSerialNumber(new String(deviceInfo.struDeviceV30.sSerialNumber).trim())
63 | .build();
64 | return HikResult.ok(token);
65 | }
66 |
67 | @Override
68 | public HikResult> logout(long userId) {
69 | if (userId > -1) {
70 | boolean result = hcnetsdk.NET_DVR_Logout(new NativeLong(userId));
71 | if (!result) {
72 | return lastError();
73 | }
74 | }
75 | return HikResult.ok();
76 | }
77 |
78 | @Override
79 | public HikResult> doAction(String ip, int port, String user, String password,
80 | BiFunction> action) {
81 | HikResult loginResult = login(ip, port, user, password);
82 | if (!loginResult.isSuccess()) {
83 | return loginResult;
84 | }
85 |
86 | Token token = loginResult.getData();
87 | try {
88 | HikResult> result = action.apply(hcnetsdk, token);
89 | if (result == null) {
90 | result = HikResult.ok();
91 | }
92 | return result;
93 | } finally {
94 | logout(token.getUserId());
95 | }
96 | }
97 |
98 | @Override
99 | public HikResult lastError() {
100 | int code = hcnetsdk.NET_DVR_GetLastError();
101 | if (code == 0) {
102 | return null;
103 | }
104 |
105 | String msg;
106 | if (code == 3) {
107 | msg = "sdk not init.";
108 | } else {
109 | msg = hcnetsdk.NET_DVR_GetErrorMsg(new NativeLongByReference(new NativeLong(code)));
110 | }
111 | return HikResult.fail(code, msg);
112 | }
113 |
114 | @Override
115 | public HikResult passThrough(long userId, String url, String input) {
116 | byte[] bytes = input == null ? null : input.getBytes();
117 | return passThrough(userId, url, bytes, 3 * 1024 * 1024);
118 | }
119 |
120 | @Override
121 | public HikResult passThrough(long userId, String url, byte[] inputBytes,
122 | int exceptOutByteSize) {
123 | byte[] urlBytes = url.getBytes();
124 | inputBytes = (inputBytes == null || inputBytes.length == 0) ? " ".getBytes() : inputBytes;
125 | // 输入参数
126 | HCNetSDK.NET_DVR_STRING_POINTER urlPointer = new HCNetSDK.NET_DVR_STRING_POINTER();
127 | urlPointer.byString = urlBytes;
128 | urlPointer.write();
129 |
130 | HCNetSDK.NET_DVR_STRING_POINTER inputPointer = new HCNetSDK.NET_DVR_STRING_POINTER();
131 | inputPointer.byString = inputBytes;
132 | inputPointer.write();
133 |
134 | HCNetSDK.NET_DVR_XML_CONFIG_INPUT inputParams = new HCNetSDK.NET_DVR_XML_CONFIG_INPUT();
135 | inputParams.dwSize = inputParams.size();
136 | inputParams.lpRequestUrl = urlPointer.getPointer();
137 | inputParams.dwRequestUrlLen = urlPointer.byString.length;
138 | inputParams.lpInBuffer = inputPointer.getPointer();
139 | inputParams.dwInBufferSize = inputPointer.byString.length;
140 | inputParams.write();
141 |
142 | // 输出参数
143 | HCNetSDK.NET_DVR_STRING_POINTER outputPointer = new HCNetSDK.NET_DVR_STRING_POINTER();
144 | outputPointer.byString = new byte[exceptOutByteSize];
145 | HCNetSDK.NET_DVR_STRING_POINTER outputStatusPointer = new HCNetSDK.NET_DVR_STRING_POINTER();
146 |
147 | HCNetSDK.NET_DVR_XML_CONFIG_OUTPUT outputParams = new HCNetSDK.NET_DVR_XML_CONFIG_OUTPUT();
148 | outputParams.dwSize = outputParams.size();
149 | outputParams.lpOutBuffer = outputPointer.getPointer();
150 | outputParams.dwOutBufferSize = outputPointer.size();
151 | outputParams.lpStatusBuffer = outputStatusPointer.getPointer();
152 | outputParams.dwStatusSize = outputStatusPointer.size();
153 | inputPointer.write();
154 |
155 | // 透传
156 | boolean result = hcnetsdk.NET_DVR_STDXMLConfig(new NativeLong(userId), inputParams, outputParams);
157 | outputPointer.read();
158 | outputStatusPointer.read();
159 | byte[] data = outputPointer.byString;
160 | byte[] statusData = outputStatusPointer.byString;
161 | String statusXml = new String(statusData).trim();
162 |
163 | HikResult hikResult = new HikResult<>();
164 | PassThroughResponse response = new PassThroughResponse();
165 | if (!result) {
166 | HikResult> error = lastError();
167 | hikResult.set(error);
168 | if (statusXml.trim().length() > 0) {
169 | response.setStatus(ResponseStatus.ofXml(statusXml));
170 | }
171 | } else {
172 | hikResult.setSuccess(true);
173 | response.setBytes(data);
174 | }
175 |
176 | hikResult.setData(response);
177 | return hikResult;
178 | }
179 |
180 |
181 | @Override
182 | public HikResult setupDeploy(long userId, HCNetSDK.FMSGCallBack messageCallback,
183 | FExceptionCallBack exceptionCallback) {
184 | // 消息回调
185 | if (messageCallback != null) {
186 | boolean result = hcnetsdk.NET_DVR_SetDVRMessageCallBack_V30(messageCallback, null);
187 | if (!result) {
188 | return lastError();
189 | }
190 | }
191 |
192 | // 建立通道
193 | NativeLong setupAlarmHandle = hcnetsdk.NET_DVR_SetupAlarmChan_V30(new NativeLong(userId));
194 | if (setupAlarmHandle.longValue() == -1) {
195 | return lastError();
196 | }
197 |
198 | // 异常回调
199 | if (exceptionCallback != null) {
200 | boolean setExceptionResult = hcnetsdk
201 | .NET_DVR_SetExceptionCallBack_V30(0, setupAlarmHandle.intValue(), exceptionCallback, null);
202 | if (!setExceptionResult) {
203 | hcnetsdk.NET_DVR_CloseAlarmChan_V30(setupAlarmHandle);
204 | return lastError();
205 | }
206 | }
207 | return HikResult.ok(setupAlarmHandle.longValue());
208 | }
209 |
210 | @Override
211 | public HikResult> modifyPassword(long userId, String username, String newPassword) {
212 | // 获取原始配置
213 | HCNetSDK.NET_DVR_USER_V30 dvrUser = new HCNetSDK.NET_DVR_USER_V30();
214 | boolean getResult = hcnetsdk.NET_DVR_GetDVRConfig(new NativeLong(userId), HCNetSDK.NET_DVR_GET_USERCFG_V30,
215 | new NativeLong(0), dvrUser.getPointer(), dvrUser.size(), new IntByReference(0));
216 | if (!getResult) {
217 | HikResult> errorResult = lastError();
218 | errorResult.setSuccess(false);
219 | return errorResult;
220 | }
221 |
222 | // 修改指定用户密码
223 | dvrUser.read();
224 | for (HCNetSDK.NET_DVR_USER_INFO_V30 userInfo : dvrUser.struUser) {
225 | String name = new String(userInfo.sUserName).trim();
226 | if (Objects.equals(username, name)) {
227 | userInfo.sPassword = newPassword.getBytes();
228 | }
229 | }
230 | dvrUser.write();
231 | boolean setResult = hcnetsdk.NET_DVR_SetDVRConfig(new NativeLong(userId), HCNetSDK.NET_DVR_SET_USERCFG_V30,
232 | new NativeLong(0), dvrUser.getPointer(), dvrUser.dwSize);
233 | if (!setResult) {
234 | HikResult> errorResult = lastError();
235 | errorResult.setSuccess(false);
236 | return errorResult;
237 | }
238 | return HikResult.ok();
239 | }
240 |
241 | @Override
242 | public HikResult> nvrRebindChannels(long userId, String dvrUsername, String dvrNewPassword) {
243 | // 获取已绑定通道配置
244 | IntByReference ibrBytesReturned = new IntByReference(0);
245 | HCNetSDK.NET_DVR_IPPARACFG mStrIpparaCfg = new HCNetSDK.NET_DVR_IPPARACFG();
246 | mStrIpparaCfg.write();
247 | Pointer lpIpParaConfig = mStrIpparaCfg.getPointer();
248 | boolean getResult = hcnetsdk
249 | .NET_DVR_GetDVRConfig(new NativeLong(userId), HCNetSDK.NET_DVR_GET_IPPARACFG, new NativeLong(33),
250 | lpIpParaConfig, mStrIpparaCfg.size(), ibrBytesReturned);
251 | if (!getResult) {
252 | HikResult> errorResult = lastError();
253 | errorResult.setSuccess(false);
254 | return errorResult;
255 | }
256 | mStrIpparaCfg.read();
257 |
258 | // 修改已绑定通道密码
259 | for (HCNetSDK.NET_DVR_IPDEVINFO deviceInfo : mStrIpparaCfg.struIPDevInfo) {
260 | String user = new String(deviceInfo.sUserName).trim();
261 | if (Objects.equals(dvrUsername, user)) {
262 | deviceInfo.sPassword = dvrNewPassword.getBytes();
263 | String ip = new String(deviceInfo.struIP.sIpV4).trim();
264 | }
265 | }
266 | mStrIpparaCfg.write();
267 | boolean setResult = hcnetsdk
268 | .NET_DVR_SetDVRConfig(new NativeLong(userId), HCNetSDK.NET_DVR_SET_IPPARACFG, new NativeLong(33),
269 | mStrIpparaCfg.getPointer(), mStrIpparaCfg.dwSize);
270 | if (!setResult) {
271 | HikResult> errorResult = lastError();
272 | errorResult.setSuccess(false);
273 | return errorResult;
274 | }
275 | return HikResult.ok();
276 | }
277 |
278 | @Override
279 | @SneakyThrows
280 | public HikResult getDvrConfig(long userId, long channel, int command,
281 | Class clazz) {
282 | T data = clazz.newInstance();
283 | data.write();
284 | boolean result = hcnetsdk.NET_DVR_GetDVRConfig(new NativeLong(userId), command, new NativeLong(channel),
285 | data.getPointer(), data.size(), new IntByReference(0));
286 | if (!result) {
287 | return lastError();
288 | }
289 | data.read();
290 | return HikResult.ok(data);
291 | }
292 |
293 | @Override
294 | public HikResult> getDvrConfig(long userId, long channel, int command, Structure data) {
295 | data.write();
296 | boolean result = hcnetsdk.NET_DVR_GetDVRConfig(new NativeLong(userId), command, new NativeLong(channel),
297 | data.getPointer(), data.size(), new IntByReference(0));
298 | if (!result) {
299 | return lastError();
300 | }
301 | data.read();
302 | return HikResult.ok();
303 | }
304 |
305 | @Override
306 | public HikResult> setDvrConfig(long userId, long channel, int command, Structure data) {
307 | data.write();
308 | boolean result = hcnetsdk.NET_DVR_SetDVRConfig(new NativeLong(userId), command, new NativeLong(channel),
309 | data.getPointer(), data.size());
310 | if (!result) {
311 | return lastError();
312 | }
313 | return HikResult.ok();
314 | }
315 |
316 | @Override
317 | public HikResult realPlay(long userId, FRealDataCallBack_V30 callback) {
318 | HCNetSDK.NET_DVR_PREVIEWINFO previewInfo = new HCNetSDK.NET_DVR_PREVIEWINFO();
319 | previewInfo.lChannel = new NativeLong(1);
320 | previewInfo.dwStreamType = 0;
321 | previewInfo.dwLinkMode = 1;
322 | previewInfo.hPlayWnd = null;
323 | previewInfo.bBlocked = false;
324 | previewInfo.bPassbackRecord = false;
325 | previewInfo.byPreviewMode = 0;
326 | return realPlay(userId, previewInfo, callback);
327 | }
328 |
329 | @Override
330 | public HikResult realPlay(long userId, NET_DVR_PREVIEWINFO previewInfo,
331 | FRealDataCallBack_V30 callback) {
332 | NativeLong realPlayHandle = hcnetsdk.NET_DVR_RealPlay_V40(new NativeLong(userId), previewInfo, callback, null);
333 | if (realPlayHandle.longValue() == -1) {
334 | return lastError();
335 | }
336 | return HikResult.ok(realPlayHandle.longValue());
337 | }
338 |
339 | @Override
340 | public HikResult> stopRealPlay(long realHandle) {
341 | boolean result = hcnetsdk.NET_DVR_StopRealPlay(new NativeLong(realHandle));
342 | return result ? HikResult.ok() : lastError();
343 | }
344 |
345 | @Override
346 | public SdkOptions opsForSdk() {
347 | return new SdkOptionsImpl(this);
348 | }
349 |
350 | @Override
351 | public MaintainOptions opsForMaintain(long userId) {
352 | return new MaintainOptionsImpl(this, userId);
353 | }
354 |
355 | @Override
356 | public PtzOptions opsForPtz(long userId) {
357 | return new PtzOptionsImpl(this, userId);
358 | }
359 |
360 | }
361 |
--------------------------------------------------------------------------------
/src/main/java/com/github/lkqm/hcnet/HikResult.java:
--------------------------------------------------------------------------------
1 | package com.github.lkqm.hcnet;
2 |
3 |
4 | import lombok.AllArgsConstructor;
5 | import lombok.Data;
6 | import lombok.NoArgsConstructor;
7 |
8 | /**
9 | * 执行海康动作的响应结果
10 | */
11 | @Data
12 | @AllArgsConstructor
13 | @NoArgsConstructor
14 | public class HikResult {
15 |
16 | protected boolean success;
17 | protected Integer errorCode;
18 | protected String errorMsg;
19 | protected T data;
20 |
21 | /**
22 | * 返回成功的实例.
23 | */
24 | public static HikResult ok() {
25 | return new HikResult<>(true, null, null, null);
26 | }
27 |
28 | /**
29 | * 创建成功的实例.
30 | */
31 | public static HikResult ok(T data) {
32 | return new HikResult<>(true, null, null, data);
33 | }
34 |
35 | /**
36 | * 创建失败的实例.
37 | */
38 | public static HikResult fail(int code, String msg) {
39 | return new HikResult<>(false, code, msg, null);
40 | }
41 |
42 | /**
43 | * 创建失败的实例.
44 | */
45 | public static HikResult fail(int code, String msg, T data) {
46 | return new HikResult<>(false, code, msg, data);
47 | }
48 |
49 | /**
50 | * 设置错误码,错误消息,成功状态.
51 | */
52 | public void set(HikResult data) {
53 | this.success = data.success;
54 | this.errorCode = data.errorCode;
55 | this.errorMsg = data.errorMsg;
56 | }
57 |
58 | /**
59 | * 获取错误信息,格式: $code,$msg
60 | */
61 | public String getError() {
62 | if (success) {
63 | return "";
64 | }
65 | return errorCode + "," + errorMsg;
66 | }
67 |
68 | /**
69 | * 是否是密码或用户名错误.
70 | */
71 | public boolean isPasswordError() {
72 | return errorCode != null && errorCode == 1;
73 | }
74 |
75 | /**
76 | * 是否是设备离线错误.
77 | */
78 | public boolean isDeviceOfflineError() {
79 | return errorCode != null && errorCode == 7;
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/src/main/java/com/github/lkqm/hcnet/JnaPathUtils.java:
--------------------------------------------------------------------------------
1 | package com.github.lkqm.hcnet;
2 |
3 | import java.io.File;
4 | import java.net.MalformedURLException;
5 | import java.net.URISyntaxException;
6 | import java.net.URL;
7 | import java.util.HashMap;
8 | import java.util.Map;
9 | import sun.awt.OSInfo;
10 |
11 | /**
12 | * Jna加载本地库相关工具类。
13 | */
14 | public class JnaPathUtils {
15 |
16 | public static final String JNA_PATH_PROPERTY_NAME = "jna.library.path";
17 |
18 |
19 | /**
20 | * 检查并设置本地库加载目录系统变量(jna.library.path), 仅开发环境下。
21 | */
22 | public static boolean initJnaLibraryPathDev() {
23 | return initJnaLibraryPath(null, false);
24 | }
25 |
26 | /**
27 | * 检查并设置本地库加载目录系统变量(jna.library.path),
28 | *
29 | * 设置的路径, 资源目录下: natives/{type}, 其中type在不同操作系统下对应值不一样(so, dll, dylib)
30 | */
31 | public static boolean initJnaLibraryPath(Class> target) {
32 | return initJnaLibraryPath(target, true);
33 | }
34 |
35 | /**
36 | * 检查并设置本地库加载目录系统变量(jna.library.path),
37 | *
38 | * 设置的路径, 资源目录下: natives/{type}, 其中type在不同操作系统下对应值不一样(so, dll, dylib)
39 | */
40 | public static boolean initJnaLibraryPath(Class> target, boolean effectiveJar) {
41 | boolean modifiedPath = false;
42 | String jnaLibPath = System.getProperty(JNA_PATH_PROPERTY_NAME);
43 | boolean isJnaLibEmpty = (jnaLibPath == null || jnaLibPath.trim().length() == 0);
44 | if (isJnaLibEmpty) {
45 | Map libDirMap = new HashMap<>();
46 | libDirMap.put(OSInfo.OSType.WINDOWS, "natives/dll");
47 | libDirMap.put(OSInfo.OSType.LINUX, "natives/so");
48 | libDirMap.put(OSInfo.OSType.MACOSX, "natives/dylib");
49 |
50 | String libDir = libDirMap.get(OSInfo.getOSType());
51 | if (libDir == null) {
52 | throw new RuntimeException("Unsupported operator system: " + OSInfo.getOSType().name());
53 | }
54 |
55 | if (!isRunJar()) {
56 | URL uri = JnaPathUtils.class.getClassLoader().getResource(libDir);
57 | if (uri == null) {
58 | throw new IllegalStateException("Not found relation library: " + libDir);
59 | }
60 | jnaLibPath = uri.getPath();
61 | System.setProperty(JNA_PATH_PROPERTY_NAME, jnaLibPath);
62 | modifiedPath = true;
63 | } else if (effectiveJar) {
64 | jnaLibPath = getJarDirectoryPath(target) + File.separator + libDir;
65 | System.setProperty(JNA_PATH_PROPERTY_NAME, jnaLibPath);
66 | modifiedPath = true;
67 | }
68 | }
69 | return modifiedPath;
70 | }
71 |
72 | /**
73 | * 是否以可执行jar方式启动
74 | */
75 | public static boolean isRunJar() {
76 | URL resource = JnaPathUtils.class.getResource("/");
77 | if (resource == null) {
78 | resource = JnaPathUtils.class.getResource("");
79 | }
80 | if (resource == null) {
81 | return false;
82 | }
83 |
84 | String protocol = resource.getProtocol();
85 | return "jar".equals(protocol);
86 | }
87 |
88 | /**
89 | * 获取执行jar所在目录
90 | */
91 | public static String getJarDirectoryPath(Class> target) {
92 | URL url = getLocation(target);
93 | File file = urlToFile(url);
94 | return file.getParent();
95 | }
96 |
97 |
98 | /**
99 | * Gets the base location of the given class.
100 | *
101 | * If the class is directly on the file system (e.g., "/path/to/my/package/MyClass.class") then it will return the
102 | * base directory (e.g., "file:/path/to").
103 | *
104 | *
105 | * If the class is within a JAR file (e.g., "/path/to/my-jar.jar!/my/package/MyClass.class") then it will return the
106 | * path to the JAR (e.g., "file:/path/to/my-jar.jar").
107 | *
108 | *
109 | * @param c The class whose location is desired.
110 | */
111 | private static URL getLocation(final Class> c) {
112 | if (c == null) {
113 | return null; // could not load the class
114 | }
115 |
116 | // try the easy way first
117 | try {
118 | final URL codeSourceLocation =
119 | c.getProtectionDomain().getCodeSource().getLocation();
120 | if (codeSourceLocation != null) {
121 | return codeSourceLocation;
122 | }
123 | } catch (final SecurityException e) {
124 | // NB: Cannot access protection domain.
125 | } catch (final NullPointerException e) {
126 | // NB: Protection domain or code source is null.
127 | }
128 |
129 | // NB: The easy way failed, so we try the hard way. We ask for the class
130 | // itself as a resource, then strip the class's path from the URL string,
131 | // leaving the base path.
132 |
133 | // get the class's raw resource path
134 | final URL classResource = c.getResource(c.getSimpleName() + ".class");
135 | if (classResource == null) {
136 | return null; // cannot find class resource
137 | }
138 |
139 | final String url = classResource.toString();
140 | final String suffix = c.getCanonicalName().replace('.', '/') + ".class";
141 | if (!url.endsWith(suffix)) {
142 | return null; // weird URL
143 | }
144 |
145 | // strip the class's path from the URL string
146 | final String base = url.substring(0, url.length() - suffix.length());
147 |
148 | String path = base;
149 |
150 | // remove the "jar:" prefix and "!/" suffix, if present
151 | if (path.startsWith("jar:")) {
152 | path = path.substring(4, path.length() - 2);
153 | }
154 |
155 | try {
156 | return new URL(path);
157 | } catch (final MalformedURLException e) {
158 | e.printStackTrace();
159 | return null;
160 | }
161 | }
162 |
163 | /**
164 | * Converts the given {@link URL} to its corresponding {@link File}.
165 | *
166 | * This method is similar to calling {@code new File(url.toURI())} except that it also handles "jar:file:" URLs,
167 | * returning the path to the JAR file.
168 | *
169 | *
170 | * @param url The URL to convert.
171 | * @throws IllegalArgumentException if the URL does not correspond to a file.
172 | */
173 | private static File urlToFile(final URL url) {
174 | return url == null ? null : urlToFile(url.toString());
175 | }
176 |
177 | /**
178 | * Converts the given URL string to its corresponding {@link File}.
179 | *
180 | * @param url The URL to convert.
181 | * @throws IllegalArgumentException if the URL does not correspond to a file.
182 | */
183 | private static File urlToFile(final String url) {
184 | String path = url;
185 | if (path.startsWith("jar:")) {
186 | // remove "jar:" prefix and "!/" suffix
187 | final int index = path.indexOf("!/");
188 | path = path.substring(4, index);
189 | }
190 | try {
191 | if (OSInfo.getOSType() == OSInfo.OSType.WINDOWS && path.matches("file:[A-Za-z]:.*")) {
192 | path = "file:/" + path.substring(5);
193 | }
194 | return new File(new URL(path).toURI());
195 | } catch (final MalformedURLException e) {
196 | // NB: URL is not completely well-formed.
197 | } catch (final URISyntaxException e) {
198 | // NB: URL is not completely well-formed.
199 | }
200 | if (path.startsWith("file:")) {
201 | // pass through the URL as-is, minus "file:" prefix
202 | path = path.substring(5);
203 | return new File(path);
204 | }
205 | throw new IllegalArgumentException("Invalid URL: " + url);
206 | }
207 |
208 | }
209 |
--------------------------------------------------------------------------------
/src/main/java/com/github/lkqm/hcnet/Token.java:
--------------------------------------------------------------------------------
1 | package com.github.lkqm.hcnet;
2 |
3 | import com.sun.jna.NativeLong;
4 | import java.io.Serializable;
5 | import lombok.Builder;
6 | import lombok.Data;
7 |
8 | /**
9 | * 海康设备登录响应结果
10 | */
11 | @Data
12 | @Builder
13 | public class Token implements Serializable {
14 |
15 | /**
16 | * 登录后的用户标识
17 | */
18 | private final Long userId;
19 |
20 | /**
21 | * 设备序列号
22 | */
23 | private final String deviceSerialNumber;
24 |
25 | public NativeLong getUserIdNativeLong() {
26 | return new NativeLong(userId);
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/src/main/java/com/github/lkqm/hcnet/handler/AbstractFaceSnapHandler.java:
--------------------------------------------------------------------------------
1 | package com.github.lkqm.hcnet.handler;
2 |
3 | import com.github.lkqm.hcnet.HCNetSDK;
4 | import com.github.lkqm.hcnet.HCNetSDK.NET_DVR_ALARMER;
5 | import com.github.lkqm.hcnet.HCNetSDK.NET_VCA_HUMAN_FEATURE;
6 | import com.github.lkqm.hcnet.HCNetSDK.NET_VCA_RECT;
7 | import com.github.lkqm.hcnet.HCNetSDK.RECV_ALARM;
8 | import com.github.lkqm.hcnet.model.FaceSnapEvent;
9 | import com.github.lkqm.hcnet.model.FaceSnapInfo;
10 | import com.github.lkqm.hcnet.model.FaceSnapInfo.FaceFuture;
11 | import com.github.lkqm.hcnet.model.FaceSnapInfo.FaceRect;
12 | import com.github.lkqm.hcnet.util.InnerUtils;
13 | import com.github.lkqm.hcnet.util.JnaUtils;
14 | import com.sun.jna.NativeLong;
15 | import com.sun.jna.Pointer;
16 |
17 | /**
18 | * 人脸抓拍事件处理.
19 | */
20 | public abstract class AbstractFaceSnapHandler extends AbstractHandler {
21 |
22 | public abstract void handle(FaceSnapEvent event);
23 |
24 | @Override
25 | public boolean accept(long command) {
26 | return command == HCNetSDK.COMM_UPLOAD_FACESNAP_RESULT;
27 | }
28 |
29 | @Override
30 | public void invoke(NativeLong lCommand, NET_DVR_ALARMER pAlarmer, RECV_ALARM pAlarmInfo, int dwBufLen,
31 | Pointer pUser) {
32 | if (accept(lCommand.longValue())) {
33 | FaceSnapEvent event = new FaceSnapEvent();
34 | event.setDeviceInfo(resolveDeviceInfo(pAlarmer));
35 | event.setFaceSnapInfo(resolveFaceSnapInfo(pAlarmInfo));
36 | this.handle(event);
37 | }
38 | }
39 |
40 | // 解析身份证信息
41 | private FaceSnapInfo resolveFaceSnapInfo(RECV_ALARM pAlarmInfo) {
42 | HCNetSDK.NET_VCA_FACESNAP_RESULT strFaceSnapInfo = new HCNetSDK.NET_VCA_FACESNAP_RESULT();
43 | JnaUtils.pointerToStructure(pAlarmInfo.getPointer(), strFaceSnapInfo);
44 | NET_VCA_RECT strRect = strFaceSnapInfo.struRect;
45 | NET_VCA_HUMAN_FEATURE strFaceFeature = strFaceSnapInfo.struFeature;
46 |
47 | FaceSnapInfo faceInfo = new FaceSnapInfo();
48 |
49 | // 抓拍信息
50 | faceInfo.setFaceScore(strFaceSnapInfo.dwFaceScore);
51 | if (strFaceSnapInfo.dwFacePicLen > 0) {
52 | byte[] faceBytes = JnaUtils.pointerToBytes(strFaceSnapInfo.pBuffer1, strFaceSnapInfo.dwFacePicLen);
53 | faceInfo.setFaceImageBytes(faceBytes);
54 | }
55 | if (strFaceSnapInfo.dwBackgroundPicLen > 0) {
56 | byte[] backgroundBytes = JnaUtils
57 | .pointerToBytes(strFaceSnapInfo.pBuffer2, strFaceSnapInfo.dwBackgroundPicLen);
58 | faceInfo.setBackgroundImageBytes(backgroundBytes);
59 | }
60 | int absTime = strFaceSnapInfo.dwAbsTime;
61 | faceInfo.setSnapTimestamp(InnerUtils.hikAbsTimeToTimestamp(absTime));
62 | faceInfo.setFacePicId(strFaceSnapInfo.dwFacePicID);
63 | faceInfo.setStayDurationMs((long) (strFaceSnapInfo.fStayDuration * 1000));
64 | faceInfo.setRepeatTimes(strFaceSnapInfo.byRepeatTimes);
65 |
66 | // 人脸位置.
67 | FaceRect faceRect = new FaceRect(strRect.fX, strRect.fY, strRect.fWidth, strRect.fHeight);
68 | faceInfo.setFaceRect(faceRect);
69 |
70 | // 人脸特征
71 | FaceFuture faceFuture = new FaceFuture();
72 | faceInfo.setFaceFuture(faceFuture);
73 | faceFuture.setAge(strFaceFeature.byAge);
74 | faceFuture.setEyeGlass(strFaceFeature.byEyeGlass);
75 | faceFuture.setAgeGroup(strFaceFeature.byAgeGroup);
76 | faceFuture.setAgeDeviation(strFaceFeature.byAgeDeviation);
77 | return faceInfo;
78 | }
79 |
80 |
81 |
82 | }
83 |
--------------------------------------------------------------------------------
/src/main/java/com/github/lkqm/hcnet/handler/AbstractFreshCardHandler.java:
--------------------------------------------------------------------------------
1 | package com.github.lkqm.hcnet.handler;
2 |
3 | import com.github.lkqm.hcnet.HCNetSDK;
4 | import com.github.lkqm.hcnet.HCNetSDK.NET_DVR_ALARMER;
5 | import com.github.lkqm.hcnet.HCNetSDK.NET_DVR_DATE;
6 | import com.github.lkqm.hcnet.HCNetSDK.NET_DVR_ID_CARD_INFO;
7 | import com.github.lkqm.hcnet.HCNetSDK.RECV_ALARM;
8 | import com.github.lkqm.hcnet.model.FreshCardEvent;
9 | import com.github.lkqm.hcnet.model.IDCardInfo;
10 | import com.sun.jna.NativeLong;
11 | import com.sun.jna.Pointer;
12 | import java.util.Calendar;
13 | import java.util.Date;
14 |
15 | /**
16 | * 刷证消息处理方法.
17 | */
18 | public abstract class AbstractFreshCardHandler extends AbstractHandler {
19 |
20 | /**
21 | * 处理刷证事件
22 | */
23 | public abstract void handle(FreshCardEvent event);
24 |
25 | @Override
26 | public boolean accept(long command) {
27 | return command == HCNetSDK.COMM_ID_INFO_ALARM;
28 | }
29 |
30 | @Override
31 | public void invoke(NativeLong lCommand, NET_DVR_ALARMER pAlarmer, RECV_ALARM pAlarmInfo, int dwBufLen,
32 | Pointer pUser) {
33 | if (accept(lCommand.longValue())) {
34 | FreshCardEvent event = new FreshCardEvent();
35 | event.setCardInfo(resolveIdCardInfo(pAlarmInfo));
36 | event.setDeviceInfo(resolveDeviceInfo(pAlarmer));
37 | this.handle(event);
38 | }
39 | }
40 |
41 | // 解析身份证信息
42 | private IDCardInfo resolveIdCardInfo(RECV_ALARM pAlarmInfo) {
43 | IDCardInfo cardInfo = new IDCardInfo();
44 |
45 | HCNetSDK.NET_DVR_ID_CARD_INFO_ALARM idCardInfoAlarm = new HCNetSDK.NET_DVR_ID_CARD_INFO_ALARM();
46 | idCardInfoAlarm.write();
47 | Pointer pCardInfo = idCardInfoAlarm.getPointer();
48 | pCardInfo.write(0, pAlarmInfo.getPointer().getByteArray(0, idCardInfoAlarm.size()), 0, idCardInfoAlarm.size());
49 | idCardInfoAlarm.read();
50 |
51 | NET_DVR_ID_CARD_INFO idCardCfg = idCardInfoAlarm.struIDCardCfg;
52 | cardInfo.setIdNumber(new String(idCardCfg.byIDNum).trim());
53 | cardInfo.setName(new String(idCardCfg.byName).trim());
54 | cardInfo.setAddress(new String(idCardCfg.byAddr).trim());
55 | cardInfo.setSex(idCardCfg.bySex);
56 | cardInfo.setNation(idCardCfg.byNation);
57 | cardInfo.setIssuingAuthority(new String(idCardCfg.byIssuingAuthority).trim());
58 | cardInfo.setTermValidity(idCardCfg.byTermOfValidity);
59 |
60 | cardInfo.setBirth(convertToDate(idCardCfg.struBirth));
61 | cardInfo.setValidityStartTime(convertToDate(idCardCfg.struStartDate));
62 | if (idCardCfg.byTermOfValidity == 0) {
63 | cardInfo.setValidityEndTime(convertToDate(idCardCfg.struEndDate));
64 | }
65 | return cardInfo;
66 | }
67 |
68 | private Date convertToDate(NET_DVR_DATE dvrDate) {
69 | Calendar calendar = Calendar.getInstance();
70 | calendar.set(dvrDate.wYear, dvrDate.byMonth - 1, dvrDate.byDay);
71 | return calendar.getTime();
72 | }
73 |
74 | }
75 |
--------------------------------------------------------------------------------
/src/main/java/com/github/lkqm/hcnet/handler/AbstractHandler.java:
--------------------------------------------------------------------------------
1 | package com.github.lkqm.hcnet.handler;
2 |
3 | import com.github.lkqm.hcnet.HCNetSDK.NET_DVR_ALARMER;
4 | import com.github.lkqm.hcnet.model.DeviceInfo;
5 |
6 | public abstract class AbstractHandler implements Handler {
7 |
8 | // 解析设备信息
9 | protected DeviceInfo resolveDeviceInfo(NET_DVR_ALARMER alarm) {
10 | DeviceInfo deviceInfo = new DeviceInfo();
11 | if (alarm.byUserIDValid == 1) {
12 | deviceInfo.setUserId(alarm.lUserID.longValue());
13 | }
14 | if (alarm.byDeviceIPValid == 1) {
15 | String deviceIp = new String(alarm.sDeviceIP).trim();
16 | deviceInfo.setDeviceIp(deviceIp);
17 | }
18 | if (alarm.byDeviceNameValid == 1) {
19 | String deviceName = new String(alarm.sDeviceName).trim();
20 | deviceInfo.setDeviceIp(deviceName);
21 | }
22 | if (alarm.bySerialValid == 1) {
23 | String serialNumber = new String(alarm.sSerialNumber).trim();
24 | deviceInfo.setSerialNumber(serialNumber);
25 | }
26 | if (alarm.byMacAddrValid == 1) {
27 | String macAddr = new String(alarm.byMacAddr).trim();
28 | deviceInfo.setDeviceMacAddr(macAddr);
29 | }
30 | return deviceInfo;
31 | }
32 |
33 | }
34 |
--------------------------------------------------------------------------------
/src/main/java/com/github/lkqm/hcnet/handler/DispatchMessageCallback.java:
--------------------------------------------------------------------------------
1 | package com.github.lkqm.hcnet.handler;
2 |
3 | import com.github.lkqm.hcnet.HCNetSDK;
4 | import com.github.lkqm.hcnet.HCNetSDK.NET_DVR_ALARMER;
5 | import com.github.lkqm.hcnet.HCNetSDK.RECV_ALARM;
6 | import com.sun.jna.NativeLong;
7 | import com.sun.jna.Pointer;
8 | import java.util.List;
9 | import java.util.concurrent.CopyOnWriteArrayList;
10 |
11 | /**
12 | * 基于分发的海康设备消息回调处理类.
13 | */
14 | public class DispatchMessageCallback implements HCNetSDK.FMSGCallBack {
15 |
16 | public static final DispatchMessageCallback INSTANCE = new DispatchMessageCallback();
17 |
18 | private final List handlers = new CopyOnWriteArrayList<>();
19 |
20 | public DispatchMessageCallback addHandler(Handler handler) {
21 | handlers.add(handler);
22 | return this;
23 | }
24 |
25 | @Override
26 | public void invoke(NativeLong lCommand, NET_DVR_ALARMER pAlarmer, RECV_ALARM pAlarmInfo, int dwBufLen,
27 | Pointer pUser) {
28 | int cmd = lCommand.intValue();
29 |
30 | for (Handler handler : handlers) {
31 | if (handler.accept(cmd)) {
32 | handler.invoke(lCommand, pAlarmer, pAlarmInfo, dwBufLen, pUser);
33 | return;
34 | }
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/main/java/com/github/lkqm/hcnet/handler/FaceSnapFileStoreHandler.java:
--------------------------------------------------------------------------------
1 | package com.github.lkqm.hcnet.handler;
2 |
3 | import com.github.lkqm.hcnet.model.DeviceInfo;
4 | import com.github.lkqm.hcnet.model.FaceSnapEvent;
5 | import com.github.lkqm.hcnet.model.FaceSnapInfo;
6 | import com.github.lkqm.hcnet.util.InnerUtils;
7 | import java.io.File;
8 | import java.text.SimpleDateFormat;
9 | import java.util.Date;
10 | import lombok.AllArgsConstructor;
11 | import lombok.Getter;
12 |
13 | /**
14 | * 人脸抓拍事件处理.
15 | */
16 | @AllArgsConstructor
17 | @Getter
18 | public class FaceSnapFileStoreHandler extends AbstractFaceSnapHandler {
19 |
20 | /**
21 | * 文件存储基本目录.
22 | */
23 | protected final String baseDir;
24 |
25 | // ___.jpg
26 | private static final String FILE_NAME_TPL = "%s_%s_%s_%s.jpg";
27 |
28 |
29 | @Override
30 | public void handle(FaceSnapEvent event) {
31 | DeviceInfo deviceInfo = event.getDeviceInfo();
32 | FaceSnapInfo snapInfo = event.getFaceSnapInfo();
33 |
34 | byte[] faceBytes = snapInfo.getFaceImageBytes();
35 | if (faceBytes != null) {
36 | String facePath = baseDir + File.separator + getFacePictureFileName(event);
37 | InnerUtils.writeFile(faceBytes, facePath);
38 | }
39 | byte[] backgroundBytes = snapInfo.getBackgroundImageBytes();
40 | if (backgroundBytes != null) {
41 | String backgroundPath = baseDir + File.separator + getBackgroundPictureFileName(event);
42 | InnerUtils.writeFile(backgroundBytes, backgroundPath);
43 | }
44 | }
45 |
46 | protected String getFacePictureFileName(FaceSnapEvent event) {
47 | return doPictureName(event, "face");
48 | }
49 |
50 | private String getBackgroundPictureFileName(FaceSnapEvent event) {
51 | return doPictureName(event, "bk");
52 | }
53 |
54 | private String doPictureName(FaceSnapEvent event, String type) {
55 | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
56 | SimpleDateFormat sdf2 = new SimpleDateFormat("yyyyMMdd");
57 | DeviceInfo deviceInfo = event.getDeviceInfo();
58 | FaceSnapInfo snapInfo = event.getFaceSnapInfo();
59 | Date snapDate = new Date(snapInfo.getSnapTimestamp());
60 | String snapTime = sdf.format(snapDate);
61 | String day = sdf2.format(snapDate);
62 | return day + File.separator + String
63 | .format(FILE_NAME_TPL, snapTime, deviceInfo.getDeviceIp(), deviceInfo.getSerialNumber(), type);
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/src/main/java/com/github/lkqm/hcnet/handler/Handler.java:
--------------------------------------------------------------------------------
1 | package com.github.lkqm.hcnet.handler;
2 |
3 | import com.github.lkqm.hcnet.HCNetSDK;
4 |
5 | /**
6 | * 消息回调处理器.
7 | */
8 | public interface Handler extends HCNetSDK.FMSGCallBack {
9 |
10 | /**
11 | * 是否接收命令.
12 | */
13 | boolean accept(long command);
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/com/github/lkqm/hcnet/handler/VideoFileStoreCallback.java:
--------------------------------------------------------------------------------
1 | package com.github.lkqm.hcnet.handler;
2 |
3 | import com.github.lkqm.hcnet.HCNetSDK;
4 | import com.github.lkqm.hcnet.HCNetSDK.FRealDataCallBack_V30;
5 | import com.github.lkqm.hcnet.util.InnerUtils;
6 | import com.sun.jna.NativeLong;
7 | import com.sun.jna.Pointer;
8 | import com.sun.jna.ptr.ByteByReference;
9 | import java.io.File;
10 | import java.util.Date;
11 |
12 | /**
13 | * 视频存储消息回调
14 | */
15 | public class VideoFileStoreCallback implements FRealDataCallBack_V30 {
16 |
17 | /**
18 | * 基本目录.
19 | */
20 | private final String baseDir;
21 |
22 | /**
23 | * 音频头数据.
24 | */
25 | private byte[] header;
26 |
27 | public VideoFileStoreCallback(String baseDir) {
28 | this.baseDir = baseDir;
29 | }
30 |
31 |
32 | @Override
33 | public void invoke(NativeLong lRealHandle, int dwDataType, ByteByReference pBuffer, int dwBufSize, Pointer pUser) {
34 | byte[] bytes = pBuffer.getPointer().getByteArray(0, dwBufSize);
35 | if (dwDataType == HCNetSDK.NET_DVR_SYSHEAD) {
36 | // 头数据
37 | header = bytes;
38 | } else if (dwDataType == HCNetSDK.NET_DVR_STREAMDATA && dwBufSize > 0) {
39 | // 视频流
40 | String videoPath = getVideoFilePath();
41 | File videoFile = new File(videoPath);
42 | if (!videoFile.exists()) {
43 | InnerUtils.writeFile(header, videoPath);
44 | }
45 | InnerUtils.writeFile(bytes, videoPath);
46 | }
47 | }
48 |
49 | /**
50 | * 获取视频路径.
51 | */
52 | protected String getVideoFilePath() {
53 | String filename = InnerUtils.formatDate(new Date(), "yyyyMMdd") + ".mp4";
54 | return baseDir + File.separator + filename;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/src/main/java/com/github/lkqm/hcnet/model/DeviceInfo.java:
--------------------------------------------------------------------------------
1 | package com.github.lkqm.hcnet.model;
2 |
3 | import java.io.Serializable;
4 | import lombok.Data;
5 |
6 | /**
7 | * 设备信息
8 | */
9 | @Data
10 | public class DeviceInfo implements Serializable {
11 |
12 | /**
13 | * 登录标识
14 | */
15 | private Long userId;
16 |
17 | /**
18 | * 设备ip地址
19 | */
20 | private String deviceIp;
21 |
22 | /**
23 | * 设备名称
24 | */
25 | private String deviceName;
26 |
27 | /**
28 | * 设备序列号
29 | */
30 | private String serialNumber;
31 |
32 | /**
33 | * 设备mac地址
34 | */
35 | private String deviceMacAddr;
36 | }
37 |
--------------------------------------------------------------------------------
/src/main/java/com/github/lkqm/hcnet/model/FaceSnapEvent.java:
--------------------------------------------------------------------------------
1 | package com.github.lkqm.hcnet.model;
2 |
3 | import lombok.Data;
4 |
5 | /**
6 | * 人脸抓拍事件.
7 | */
8 | @Data
9 | public class FaceSnapEvent {
10 |
11 | private FaceSnapInfo faceSnapInfo;
12 | private DeviceInfo deviceInfo;
13 |
14 | }
15 |
--------------------------------------------------------------------------------
/src/main/java/com/github/lkqm/hcnet/model/FaceSnapInfo.java:
--------------------------------------------------------------------------------
1 | package com.github.lkqm.hcnet.model;
2 |
3 | import java.io.Serializable;
4 | import lombok.Data;
5 |
6 | /**
7 | * 人脸抓拍数据.
8 | */
9 | @Data
10 | public class FaceSnapInfo implements Serializable {
11 |
12 | /**
13 | * 人脸图id
14 | */
15 | private int facePicId;
16 |
17 | /**
18 | * 人脸评分
19 | */
20 | private int faceScore;
21 |
22 | /**
23 | * 人脸图
24 | */
25 | private byte[] faceImageBytes;
26 |
27 | /**
28 | * 背景图
29 | */
30 | private byte[] backgroundImageBytes;
31 |
32 | /**
33 | * 抓拍时间轴(时间轴)
34 | */
35 | private long snapTimestamp;
36 |
37 | /**
38 | * 停留毫秒
39 | */
40 | private long stayDurationMs;
41 |
42 | /**
43 | * 重复告警次数
44 | */
45 | private int repeatTimes;
46 |
47 | /**
48 | * 人脸位置.
49 | */
50 | private FaceRect faceRect;
51 |
52 | /**
53 | * 人脸特性.
54 | */
55 | private FaceFuture faceFuture;
56 |
57 | /**
58 | * 人脸特征.
59 | */
60 | @Data
61 | public static class FaceFuture implements Serializable {
62 |
63 | /**
64 | * 年龄段分组
65 | */
66 | private int ageGroup;
67 |
68 | /**
69 | * 性别, 1- 男,2- 女
70 | */
71 | private int sex;
72 |
73 | /**
74 | * 是否戴眼镜:1- 不戴,2- 戴
75 | */
76 | private int eyeGlass;
77 |
78 | /**
79 | * 年龄
80 | */
81 | private int age;
82 |
83 | /**
84 | * 年龄误差
85 | */
86 | private int ageDeviation;
87 |
88 | /**
89 | * 是否戴口罩:0-表示“未知”(算法不支持);1- 不戴口罩;2-戴口罩;0xff-算法支持,但是没有识别出来
90 | */
91 | private int mask;
92 |
93 | /**
94 | * 是否微笑:0-表示“未知”(算法不支持);1- 不微笑;2- 微笑;0xff-算法支持,但是没有识别出来
95 | */
96 | private int smile;
97 |
98 | /**
99 | * 帽子:0- 不支持;1- 不戴帽子;2- 戴帽子;0xff- 未知,算法支持未检出
100 | */
101 | private int hat;
102 | }
103 |
104 | /**
105 | * 人脸图再背景的位置.
106 | */
107 | @Data
108 | public static class FaceRect implements Serializable {
109 |
110 | private float x;
111 | private float y;
112 | private float width;
113 | private float height;
114 |
115 | public FaceRect(float x, float y, float width, float height) {
116 | this.x = x;
117 | this.y = y;
118 | this.width = width;
119 | this.height = height;
120 | }
121 | }
122 | }
123 |
--------------------------------------------------------------------------------
/src/main/java/com/github/lkqm/hcnet/model/FreshCardEvent.java:
--------------------------------------------------------------------------------
1 | package com.github.lkqm.hcnet.model;
2 |
3 | import lombok.Data;
4 |
5 | /**
6 | * 人证机刷证事件数据.
7 | */
8 | @Data
9 | public class FreshCardEvent {
10 |
11 | private IDCardInfo cardInfo;
12 |
13 | private DeviceInfo deviceInfo;
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/main/java/com/github/lkqm/hcnet/model/IDCardInfo.java:
--------------------------------------------------------------------------------
1 | package com.github.lkqm.hcnet.model;
2 |
3 | import java.io.Serializable;
4 | import java.util.Date;
5 | import lombok.Data;
6 |
7 | /**
8 | * 身份证信息
9 | */
10 | @Data
11 | public class IDCardInfo implements Serializable {
12 |
13 | /**
14 | * 身份证号
15 | */
16 | private String idNumber;
17 |
18 | /**
19 | * 姓名
20 | */
21 | private String name;
22 | /**
23 | * 家庭住址
24 | */
25 | private String address;
26 |
27 | /**
28 | * 性别, 1- 男,2- 女
29 | */
30 | private int sex;
31 |
32 | /**
33 | * 民族
34 | */
35 | private int nation;
36 |
37 | /**
38 | * 出生日期
39 | */
40 | private Date birth;
41 |
42 | /**
43 | * 是否长期有效, 0- 否,1- 是(有效截止日期无效)
44 | */
45 | private int termValidity;
46 |
47 | /**
48 | * 有效开始时间
49 | */
50 | private Date validityStartTime;
51 |
52 | /**
53 | * 有效结束时间(长期有效时,该值为null)
54 | */
55 | private Date validityEndTime;
56 |
57 | /**
58 | * 签发机关
59 | */
60 | private String issuingAuthority;
61 |
62 | }
63 |
--------------------------------------------------------------------------------
/src/main/java/com/github/lkqm/hcnet/model/PassThroughResponse.java:
--------------------------------------------------------------------------------
1 | package com.github.lkqm.hcnet.model;
2 |
3 | import java.io.Serializable;
4 | import lombok.Data;
5 |
6 | /**
7 | * 设备透传响应数据.
8 | */
9 | @Data
10 | public class PassThroughResponse implements Serializable {
11 |
12 | /**
13 | * 执行透传成功返回数据.
14 | */
15 | private byte[] bytes;
16 |
17 | /**
18 | * 透传执行失败返回的详细错误信息.
19 | */
20 | private ResponseStatus status;
21 |
22 | /**
23 | * 返回字符串的数据.
24 | */
25 | public String getStringData() {
26 | if (bytes != null) {
27 | return new String(bytes).trim();
28 | }
29 | return null;
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/src/main/java/com/github/lkqm/hcnet/model/ResponseStatus.java:
--------------------------------------------------------------------------------
1 | package com.github.lkqm.hcnet.model;
2 |
3 | import com.github.lkqm.hcnet.util.InnerUtils;
4 | import java.io.Serializable;
5 | import java.util.Map;
6 | import lombok.Data;
7 |
8 | /**
9 | * 错误响应结果.
10 | */
11 | @Data
12 | public class ResponseStatus implements Serializable {
13 |
14 | /**
15 | * 请求的地址.
16 | */
17 | private String requestURL;
18 |
19 | /**
20 | * 状态码.
21 | */
22 | private Integer statusCode;
23 |
24 | /**
25 | * 子状态码.
26 | */
27 | private String subStatusCode;
28 |
29 | /**
30 | * 状态码文字描述.
31 | */
32 | private String statusString;
33 |
34 | public static ResponseStatus ofXml(String xml) {
35 | ResponseStatus instance = new ResponseStatus();
36 | Map map = InnerUtils.xmlToFlatMap(xml, "ResponseStatus");
37 | instance.setRequestURL(map.get("requestURL"));
38 | instance.setStatusCode(Integer.valueOf(map.get("statusCode")));
39 | instance.setSubStatusCode(map.get("subStatusCode"));
40 | instance.setStatusString(map.get("statusString"));
41 | return instance;
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/src/main/java/com/github/lkqm/hcnet/model/UpgradeAsyncResponse.java:
--------------------------------------------------------------------------------
1 | package com.github.lkqm.hcnet.model;
2 |
3 | import java.io.Serializable;
4 | import java.util.concurrent.Future;
5 | import lombok.Data;
6 |
7 | /**
8 | * 设备升级结果.
9 | */
10 | @Data
11 | public class UpgradeAsyncResponse implements Serializable {
12 |
13 | /**
14 | * 升级的句柄
15 | */
16 | private long handle;
17 |
18 | /**
19 | * 异步升级结果
20 | */
21 | private Future future;
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/com/github/lkqm/hcnet/model/UpgradeResponse.java:
--------------------------------------------------------------------------------
1 | package com.github.lkqm.hcnet.model;
2 |
3 | import com.github.lkqm.hcnet.HikResult;
4 | import java.io.Serializable;
5 | import lombok.Data;
6 |
7 | /**
8 | * 设备升级结果
9 | */
10 | @Data
11 | public class UpgradeResponse implements Serializable {
12 |
13 | /**
14 | * 升级的句柄
15 | */
16 | private long handle;
17 |
18 | /**
19 | * 升级状态
20 | */
21 | private int state;
22 |
23 | /**
24 | * 升级错误, 当state = -1时
25 | */
26 | private HikResult> error;
27 |
28 | /**
29 | * 是否升级成功.
30 | */
31 | public boolean isUpgradeSuccess() {
32 | return state == 1;
33 | }
34 |
35 | }
36 |
--------------------------------------------------------------------------------
/src/main/java/com/github/lkqm/hcnet/options/BaseOptions.java:
--------------------------------------------------------------------------------
1 | package com.github.lkqm.hcnet.options;
2 |
3 | import com.github.lkqm.hcnet.HCNetSDK;
4 | import com.github.lkqm.hcnet.HikDeviceTemplate;
5 | import com.github.lkqm.hcnet.HikResult;
6 |
7 | public abstract class BaseOptions {
8 |
9 | protected final HikDeviceTemplate deviceTemplate;
10 |
11 | public BaseOptions(HikDeviceTemplate deviceTemplate) {
12 | this.deviceTemplate = deviceTemplate;
13 | }
14 |
15 | protected HCNetSDK getHcnetsdk() {
16 | return deviceTemplate.getHcnetsdk();
17 | }
18 |
19 | protected HikResult lastError() {
20 | return deviceTemplate.lastError();
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/main/java/com/github/lkqm/hcnet/options/MaintainOptions.java:
--------------------------------------------------------------------------------
1 | package com.github.lkqm.hcnet.options;
2 |
3 | import com.github.lkqm.hcnet.HCNetSDK.NET_DVR_UPGRADE_PARAM;
4 | import com.github.lkqm.hcnet.HikResult;
5 | import com.github.lkqm.hcnet.model.UpgradeAsyncResponse;
6 | import com.github.lkqm.hcnet.model.UpgradeResponse;
7 | import com.sun.jna.Pointer;
8 | import java.util.Date;
9 | import lombok.SneakyThrows;
10 |
11 | /**
12 | * 设备维护.
13 | */
14 | public interface MaintainOptions {
15 |
16 | /**
17 | * 是否在线.
18 | */
19 | boolean isOnline();
20 |
21 | /**
22 | * 重启设备.
23 | */
24 | HikResult> reboot();
25 |
26 | /**
27 | * 设备校时.
28 | */
29 | HikResult getDeviceTime();
30 |
31 | /**
32 | * 设备校时.
33 | */
34 | HikResult> setDeviceTime(Date time);
35 |
36 | /**
37 | * 升级设备(同步)
38 | */
39 | @SneakyThrows
40 | HikResult upgradeSync(NET_DVR_UPGRADE_PARAM upgradeParam);
41 |
42 | /**
43 | * 升级设备(异步).
44 | */
45 | HikResult upgradeAsync(NET_DVR_UPGRADE_PARAM upgradeParam);
46 |
47 | /**
48 | * 升级普通设备(同步).
49 | */
50 | @SneakyThrows
51 | HikResult upgradeSyncForDVR(String sdkPath);
52 |
53 | /**
54 | * 升级普通设备(异步).
55 | */
56 | HikResult upgradeAsyncForDVR(String sdkPath);
57 |
58 | /**
59 | * 升级门禁/人证机设备(同步).
60 | */
61 | HikResult upgradeSyncForACS(String sdkPath, int deviceNo);
62 |
63 | /**
64 | * 升级门禁/人证机器设备(异步).
65 | */
66 | HikResult upgradeAsyncForACS(String sdkPath, int deviceNo);
67 |
68 | /**
69 | * 获取配置.
70 | */
71 | HikResult getConfig();
72 |
73 | /**
74 | * 导出设备配置.
75 | */
76 | HikResult> getConfigFile(String file);
77 |
78 | /**
79 | * 获取配置.
80 | */
81 | HikResult> setConfig(String configContent);
82 |
83 | /**
84 | * 设置配置.
85 | */
86 | HikResult> setConfigFile(String file);
87 |
88 | /**
89 | * 远程控制.
90 | */
91 | HikResult> remoteControl(int command, Pointer inBuffer, int inBufferSize);
92 | }
93 |
--------------------------------------------------------------------------------
/src/main/java/com/github/lkqm/hcnet/options/MaintainOptionsImpl.java:
--------------------------------------------------------------------------------
1 | package com.github.lkqm.hcnet.options;
2 |
3 | import com.github.lkqm.hcnet.HCNetSDK;
4 | import com.github.lkqm.hcnet.HCNetSDK.NET_DVR_STRING_POINTER;
5 | import com.github.lkqm.hcnet.HCNetSDK.NET_DVR_UPGRADE_PARAM;
6 | import com.github.lkqm.hcnet.HikDeviceTemplate;
7 | import com.github.lkqm.hcnet.HikResult;
8 | import com.github.lkqm.hcnet.model.UpgradeAsyncResponse;
9 | import com.github.lkqm.hcnet.model.UpgradeResponse;
10 | import com.sun.jna.NativeLong;
11 | import com.sun.jna.Pointer;
12 | import com.sun.jna.ptr.IntByReference;
13 | import java.util.Calendar;
14 | import java.util.Date;
15 | import java.util.concurrent.Callable;
16 | import java.util.concurrent.FutureTask;
17 | import java.util.concurrent.TimeUnit;
18 | import lombok.SneakyThrows;
19 |
20 | /**
21 | * 设备维护.
22 | */
23 | public class MaintainOptionsImpl extends BaseOptions implements MaintainOptions {
24 |
25 | private final NativeLong userId;
26 |
27 | public MaintainOptionsImpl(HikDeviceTemplate deviceTemplate, long userId) {
28 | super(deviceTemplate);
29 | this.userId = new NativeLong(userId);
30 | }
31 |
32 | @Override
33 | public boolean isOnline() {
34 | return getHcnetsdk().NET_DVR_RemoteControl(userId, 20005, null, 0);
35 | }
36 |
37 | @Override
38 | public HikResult> reboot() {
39 | boolean rebootResult = getHcnetsdk().NET_DVR_RebootDVR(userId);
40 | if (!rebootResult) {
41 | return lastError();
42 | }
43 | return HikResult.ok();
44 | }
45 |
46 | @Override
47 | public HikResult getDeviceTime() {
48 | HCNetSDK.NET_DVR_TIME netDvrTime = new HCNetSDK.NET_DVR_TIME();
49 | HikResult> result = deviceTemplate
50 | .getDvrConfig(userId.longValue(), 0, HCNetSDK.NET_DVR_GET_TIMECFG, netDvrTime);
51 | if (!result.isSuccess()) {
52 | return HikResult.fail(result.getErrorCode(), result.getErrorMsg());
53 | }
54 | netDvrTime.read();
55 |
56 | Calendar calendar = Calendar.getInstance();
57 | calendar.set(Calendar.YEAR, netDvrTime.dwYear);
58 | calendar.set(Calendar.MONTH, netDvrTime.dwMonth - 1);
59 | calendar.set(Calendar.DAY_OF_MONTH, netDvrTime.dwDay);
60 | calendar.set(Calendar.HOUR_OF_DAY, netDvrTime.dwHour);
61 | calendar.set(Calendar.MINUTE, netDvrTime.dwMinute);
62 | calendar.set(Calendar.SECOND, netDvrTime.dwSecond);
63 | return HikResult.ok(calendar.getTime());
64 | }
65 |
66 | @Override
67 | public HikResult> setDeviceTime(Date time) {
68 | Calendar calendar = Calendar.getInstance();
69 | calendar.setTime(time);
70 |
71 | HCNetSDK.NET_DVR_TIME netDvrTime = new HCNetSDK.NET_DVR_TIME();
72 | netDvrTime.dwYear = calendar.get(Calendar.YEAR);
73 | netDvrTime.dwMonth = calendar.get(Calendar.MONTH) + 1;
74 | netDvrTime.dwDay = calendar.get(Calendar.DAY_OF_MONTH);
75 | netDvrTime.dwHour = calendar.get(Calendar.HOUR_OF_DAY);
76 | netDvrTime.dwMinute = calendar.get(Calendar.MINUTE);
77 | netDvrTime.dwSecond = calendar.get(Calendar.SECOND);
78 | return deviceTemplate.setDvrConfig(userId.longValue(), 0, HCNetSDK.NET_DVR_SET_TIMECFG, netDvrTime);
79 | }
80 |
81 | @Override
82 | @SneakyThrows
83 | public HikResult upgradeSyncForDVR(String sdkPath) {
84 | HikResult upgradeResult = this.upgradeAsyncForDVR(sdkPath);
85 | if (!upgradeResult.isSuccess()) {
86 | return HikResult.fail(upgradeResult.getErrorCode(), upgradeResult.getErrorMsg());
87 | }
88 | UpgradeAsyncResponse asyncResponse = upgradeResult.getData();
89 | UpgradeResponse response = asyncResponse.getFuture().get();
90 | return HikResult.ok(response);
91 | }
92 |
93 | @Override
94 | public HikResult upgradeSyncForACS(String sdkPath, int deviceNo) {
95 | NET_DVR_UPGRADE_PARAM upgradeParam = new NET_DVR_UPGRADE_PARAM();
96 | upgradeParam.dwUpgradeType = 0;
97 | upgradeParam.sFilename = sdkPath;
98 | upgradeParam.pInbuffer = new IntByReference(deviceNo).getPointer();
99 | upgradeParam.dwBufferLen = 4;
100 | return upgradeSync(upgradeParam);
101 | }
102 |
103 | @Override
104 | @SneakyThrows
105 | public HikResult upgradeSync(NET_DVR_UPGRADE_PARAM upgradeParam) {
106 | HikResult upgradeResult = this.upgradeAsync(upgradeParam);
107 | if (!upgradeResult.isSuccess()) {
108 | return HikResult.fail(upgradeResult.getErrorCode(), upgradeResult.getErrorMsg());
109 | }
110 | UpgradeAsyncResponse asyncResponse = upgradeResult.getData();
111 | UpgradeResponse response = asyncResponse.getFuture().get();
112 | return HikResult.ok(response);
113 | }
114 |
115 | @Override
116 | public HikResult upgradeAsyncForDVR(String sdkPath) {
117 | NET_DVR_UPGRADE_PARAM upgradeParam = new NET_DVR_UPGRADE_PARAM();
118 | upgradeParam.dwUpgradeType = 0;
119 | upgradeParam.sFilename = sdkPath;
120 | return upgradeAsync(upgradeParam);
121 | }
122 |
123 | @Override
124 | public HikResult upgradeAsyncForACS(String sdkPath, int deviceNo) {
125 | NET_DVR_UPGRADE_PARAM upgradeParam = new NET_DVR_UPGRADE_PARAM();
126 | upgradeParam.dwUpgradeType = 0;
127 | upgradeParam.sFilename = sdkPath;
128 | upgradeParam.pInbuffer = new IntByReference(deviceNo).getPointer();
129 | upgradeParam.dwBufferLen = 4;
130 | return upgradeAsync(upgradeParam);
131 | }
132 |
133 | @Override
134 | public HikResult upgradeAsync(NET_DVR_UPGRADE_PARAM upgradeParam) {
135 | // 请求升级
136 | upgradeParam.write();
137 | final NativeLong upgradeHandle = getHcnetsdk().NET_DVR_Upgrade_V50(userId, upgradeParam);
138 | if (upgradeHandle.longValue() == -1) {
139 | return lastError();
140 | }
141 |
142 | // 获取结果, 并关闭资源
143 | FutureTask future = new FutureTask<>(new Callable() {
144 | @Override
145 | public UpgradeResponse call() throws Exception {
146 | int state;
147 | int errorTimes = 0;
148 | do {
149 | Thread.sleep(TimeUnit.SECONDS.toMillis(15));
150 | state = getHcnetsdk().NET_DVR_GetUpgradeState(upgradeHandle);
151 | if (state == -1) {
152 | errorTimes++;
153 | } else {
154 | errorTimes = 0;
155 | }
156 | } while (state == 2 || (state == -1 && errorTimes >= 3));
157 | UpgradeResponse response = new UpgradeResponse();
158 | response.setHandle(upgradeHandle.longValue());
159 | response.setState(state);
160 | if (state == -1) {
161 | response.setError(lastError());
162 | } else {
163 | // 关闭升级句柄
164 | getHcnetsdk().NET_DVR_CloseUpgradeHandle(upgradeHandle);
165 | }
166 | return response;
167 | }
168 | });
169 | new Thread(future).start();
170 |
171 | UpgradeAsyncResponse response = new UpgradeAsyncResponse();
172 | response.setHandle(upgradeHandle.longValue());
173 | response.setFuture(future);
174 | return HikResult.ok(response);
175 | }
176 |
177 |
178 | @Override
179 | public HikResult getConfig() {
180 | NET_DVR_STRING_POINTER out = new NET_DVR_STRING_POINTER();
181 | out.byString = new byte[10 * 1024 * 1024];
182 | out.write();
183 |
184 | IntByReference returnSize = new IntByReference();
185 | boolean result = getHcnetsdk()
186 | .NET_DVR_GetConfigFile_V30(userId, out.getPointer(), out.byString.length, returnSize);
187 | if (!result) {
188 | return lastError();
189 | }
190 | out.read();
191 | return HikResult.ok();
192 | }
193 |
194 | @Override
195 | public HikResult> getConfigFile(String file) {
196 | boolean result = getHcnetsdk().NET_DVR_GetConfigFile(userId, file);
197 | if (!result) {
198 | return lastError();
199 | }
200 | return HikResult.ok();
201 | }
202 |
203 | @Override
204 | public HikResult> setConfig(String configContent) {
205 | boolean result = getHcnetsdk()
206 | .NET_DVR_SetConfigFile_EX(userId, configContent, configContent.getBytes().length);
207 | if (!result) {
208 | lastError();
209 | }
210 | return HikResult.ok();
211 | }
212 |
213 | @Override
214 | public HikResult> setConfigFile(String file) {
215 | boolean result = getHcnetsdk().NET_DVR_SetConfigFile(userId, file);
216 | if (!result) {
217 | return lastError();
218 | }
219 | return HikResult.ok();
220 | }
221 |
222 | @Override
223 | public HikResult> remoteControl(int command, Pointer inBuffer, int inBufferSize) {
224 | boolean result = getHcnetsdk().NET_DVR_RemoteControl(userId, command, inBuffer, inBufferSize);
225 | if (!result) {
226 | return lastError();
227 | }
228 | return HikResult.ok();
229 | }
230 |
231 | }
232 |
--------------------------------------------------------------------------------
/src/main/java/com/github/lkqm/hcnet/options/PtzOptions.java:
--------------------------------------------------------------------------------
1 | package com.github.lkqm.hcnet.options;
2 |
3 | import com.github.lkqm.hcnet.HikResult;
4 |
5 | /**
6 | * 云台操作.
7 | */
8 | public interface PtzOptions {
9 |
10 | /**
11 | * 云台控制.
12 | */
13 | HikResult> control(int command, int stop, int speed);
14 |
15 | /**
16 | * 云台控制开始
17 | */
18 | HikResult> controlStart(int command, int speed);
19 |
20 | /**
21 | * 云台控制停止
22 | */
23 | HikResult> controlStop(int command, int speed);
24 |
25 | /**
26 | * 云台点位控制.
27 | */
28 | HikResult> preset(int presetCommand, int presetIndex);
29 |
30 | /**
31 | * 云台点位设置.
32 | */
33 | HikResult> presetSet(int presetIndex);
34 |
35 | /**
36 | * 云台点位清除.
37 | */
38 | HikResult> presetClean(int presetIndex);
39 |
40 | /**
41 | * 云台点位跳转.
42 | */
43 | HikResult> presetGoto(int presetIndex);
44 |
45 | /**
46 | * 云台巡航。
47 | */
48 | HikResult> cruise(int cruiseCommand, int cruiseRoute, int cruisePoint, int speed);
49 |
50 | /**
51 | * 云台巡航运行.
52 | */
53 | HikResult> cruiseRun(int cruiseRoute);
54 |
55 | /**
56 | * 云台巡航运行.
57 | */
58 | HikResult> cruiseStop(int cruiseRoute);
59 |
60 | /**
61 | * 云台巡航添加点位.
62 | */
63 | HikResult> cruiseFillPreset(int cruiseRoute, int cruisePoint, int speed);
64 |
65 | /**
66 | * 云台轨迹操作。
67 | */
68 | HikResult> track(int trackCommand);
69 |
70 | /**
71 | * 云台轨迹开始记录.
72 | */
73 | HikResult> trackStartRecord();
74 |
75 | /**
76 | * 云台轨迹停止记录.
77 | */
78 | HikResult> trackStopRecord();
79 |
80 | /**
81 | * 云台轨迹运行.
82 | */
83 | HikResult> trackRun();
84 |
85 | /**
86 | * 云台图像缩放.
87 | */
88 | HikResult> zoom(int xTop, int yTop, int xBottom, int yBottom);
89 |
90 | }
91 |
--------------------------------------------------------------------------------
/src/main/java/com/github/lkqm/hcnet/options/PtzOptionsImpl.java:
--------------------------------------------------------------------------------
1 | package com.github.lkqm.hcnet.options;
2 |
3 | import com.github.lkqm.hcnet.HCNetSDK.NET_DVR_POINT_FRAME;
4 | import com.github.lkqm.hcnet.HikDeviceTemplate;
5 | import com.github.lkqm.hcnet.HikResult;
6 | import com.sun.jna.NativeLong;
7 |
8 | /**
9 | * 云台操作.
10 | */
11 | public class PtzOptionsImpl extends BaseOptions implements PtzOptions {
12 |
13 | private final NativeLong userId;
14 |
15 | public PtzOptionsImpl(HikDeviceTemplate deviceTemplate, long userId) {
16 | super(deviceTemplate);
17 | this.userId = new NativeLong(userId);
18 | }
19 |
20 | @Override
21 | public HikResult> control(int command, int stop, int speed) {
22 | boolean result = getHcnetsdk().NET_DVR_PTZControlWithSpeed_Other(userId, new NativeLong(1),
23 | command, stop, speed);
24 | return result ? HikResult.ok() : lastError();
25 | }
26 |
27 | @Override
28 | public HikResult> controlStart(int command, int speed) {
29 | return control(command, 0, speed);
30 | }
31 |
32 | @Override
33 | public HikResult> controlStop(int command, int speed) {
34 | return control(command, 1, speed);
35 | }
36 |
37 |
38 | @Override
39 | public HikResult> presetSet(int presetIndex) {
40 | return preset(8, presetIndex);
41 | }
42 |
43 | @Override
44 | public HikResult> presetClean(int presetIndex) {
45 | return preset(9, presetIndex);
46 | }
47 |
48 | @Override
49 | public HikResult> presetGoto(int presetIndex) {
50 | return preset(39, presetIndex);
51 | }
52 |
53 | @Override
54 | public HikResult> preset(int presetCommand, int presetIndex) {
55 | boolean result = getHcnetsdk().NET_DVR_PTZPreset_Other(userId, new NativeLong(1),
56 | presetCommand, presetIndex);
57 | return result ? HikResult.ok() : lastError();
58 | }
59 |
60 | @Override
61 | public HikResult> cruise(int cruiseCommand, int cruiseRoute, int cruisePoint, int speed) {
62 | boolean result = getHcnetsdk().NET_DVR_PTZCruise_Other(userId, new NativeLong(1), cruiseCommand,
63 | (byte) cruiseRoute, (byte) cruisePoint, (byte) speed);
64 | return result ? HikResult.ok() : lastError();
65 | }
66 |
67 | @Override
68 | public HikResult> cruiseRun(int cruiseRoute) {
69 | return cruise(37, cruiseRoute, 0, 0);
70 | }
71 |
72 | @Override
73 | public HikResult> cruiseStop(int cruiseRoute) {
74 | return cruise(38, cruiseRoute, 0, 0);
75 | }
76 |
77 | @Override
78 | public HikResult> cruiseFillPreset(int cruiseRoute, int cruisePoint, int speed) {
79 | return cruise(30, cruiseRoute, cruisePoint, speed);
80 | }
81 |
82 | @Override
83 | public HikResult> track(int trackCommand) {
84 | boolean result = getHcnetsdk().NET_DVR_PTZTrack_Other(userId, new NativeLong(1), trackCommand);
85 | return result ? HikResult.ok() : lastError();
86 | }
87 |
88 | @Override
89 | public HikResult> trackStartRecord() {
90 | return track(34);
91 | }
92 |
93 | @Override
94 | public HikResult> trackStopRecord() {
95 | return track(35);
96 | }
97 |
98 | @Override
99 | public HikResult> trackRun() {
100 | return track(35);
101 | }
102 |
103 | @Override
104 | public HikResult> zoom(int xTop, int yTop, int xBottom, int yBottom) {
105 | NET_DVR_POINT_FRAME point = new NET_DVR_POINT_FRAME();
106 | point.xTop = xTop;
107 | point.yTop = yTop;
108 | point.xBottom = xBottom;
109 | point.yBottom = yBottom;
110 | point.write();
111 | boolean result = getHcnetsdk().NET_DVR_PTZSelZoomIn_EX(userId, new NativeLong(1), point);
112 | return result ? HikResult.ok() : lastError();
113 | }
114 | }
115 |
--------------------------------------------------------------------------------
/src/main/java/com/github/lkqm/hcnet/options/SdkOptions.java:
--------------------------------------------------------------------------------
1 | package com.github.lkqm.hcnet.options;
2 |
3 | import com.github.lkqm.hcnet.HCNetSDK.NET_DVR_SDKABL;
4 | import com.github.lkqm.hcnet.HCNetSDK.NET_DVR_SDKSTATE;
5 | import com.github.lkqm.hcnet.HikResult;
6 |
7 | /**
8 | * sdk本地功能.
9 | */
10 | public interface SdkOptions {
11 |
12 | /**
13 | * 获取sdk版本信息
14 | */
15 | String getVersion();
16 |
17 | /**
18 | * 获取sdk当前状态信息.
19 | */
20 | HikResult getState();
21 |
22 | /**
23 | * 获取sdk的能力
24 | */
25 | HikResult getAbility();
26 |
27 | /**
28 | * 设置sdk日志输出, 参考: NET_DVR_SetLogToFile
29 | */
30 | HikResult> setLogFile(int logLevel, String logDir, boolean autoDel);
31 |
32 | /**
33 | * 设置sdk超时配置.
34 | *
35 | * @param connectTimeoutMs 连接超时时间,默认3000毫秒, 取值范围[300,75000]
36 | * @param recvTimeoutMs 接收数据超时时间,默认5000毫秒
37 | * @param reconnectIntervalMs 重连时间间隔, 默认5000毫秒, 最小为 3000 毫秒
38 | */
39 | HikResult> setTimeout(int connectTimeoutMs, int recvTimeoutMs, int reconnectIntervalMs);
40 | }
41 |
--------------------------------------------------------------------------------
/src/main/java/com/github/lkqm/hcnet/options/SdkOptionsImpl.java:
--------------------------------------------------------------------------------
1 | package com.github.lkqm.hcnet.options;
2 |
3 | import com.github.lkqm.hcnet.HCNetSDK.NET_DVR_SDKABL;
4 | import com.github.lkqm.hcnet.HCNetSDK.NET_DVR_SDKSTATE;
5 | import com.github.lkqm.hcnet.HikDeviceTemplate;
6 | import com.github.lkqm.hcnet.HikResult;
7 |
8 | /**
9 | * sdk本地功能.
10 | */
11 | public class SdkOptionsImpl extends BaseOptions implements SdkOptions {
12 |
13 | public SdkOptionsImpl(HikDeviceTemplate deviceTemplate) {
14 | super(deviceTemplate);
15 | }
16 |
17 |
18 | @Override
19 | public String getVersion() {
20 | int buildVersion = getHcnetsdk().NET_DVR_GetSDKBuildVersion();
21 | return (buildVersion >> 24) + "." + (buildVersion << 8 >> 24) + "." + (buildVersion << 16 >> 16);
22 | }
23 |
24 | @Override
25 | public HikResult getState() {
26 | NET_DVR_SDKSTATE sdkState = new NET_DVR_SDKSTATE();
27 | boolean result = getHcnetsdk().NET_DVR_GetSDKState(sdkState);
28 | if (!result) {
29 | return lastError();
30 | }
31 | sdkState.read();
32 | return HikResult.ok(sdkState);
33 | }
34 |
35 | @Override
36 | public HikResult getAbility() {
37 | NET_DVR_SDKABL ability = new NET_DVR_SDKABL();
38 | boolean result = getHcnetsdk().NET_DVR_GetSDKAbility(ability);
39 | if (!result) {
40 | return lastError();
41 | }
42 | return HikResult.ok(ability);
43 | }
44 |
45 | @Override
46 | public HikResult> setLogFile(int logLevel, String logDir, boolean autoDel) {
47 | boolean result = getHcnetsdk().NET_DVR_SetLogToFile(logLevel, logDir, autoDel);
48 | if (!result) {
49 | return lastError();
50 | }
51 | return HikResult.ok();
52 | }
53 |
54 | @Override
55 | public HikResult> setTimeout(int connectTimeoutMs, int recvTimeoutMs, int reconnectIntervalMs) {
56 | boolean result = getHcnetsdk().NET_DVR_SetConnectTime(connectTimeoutMs, 3);
57 | if (!result) {
58 | return lastError();
59 | }
60 |
61 | result = getHcnetsdk().NET_DVR_SetRecvTimeOut(recvTimeoutMs);
62 | if (!result) {
63 | return lastError();
64 | }
65 |
66 | result = getHcnetsdk().NET_DVR_SetReconnect(reconnectIntervalMs, reconnectIntervalMs > 0);
67 | if (!result) {
68 | return lastError();
69 | }
70 | return HikResult.ok();
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/src/main/java/com/github/lkqm/hcnet/util/BiFunction.java:
--------------------------------------------------------------------------------
1 | package com.github.lkqm.hcnet.util;
2 |
3 | public interface BiFunction {
4 |
5 | R apply(T t, U u);
6 |
7 | }
8 |
--------------------------------------------------------------------------------
/src/main/java/com/github/lkqm/hcnet/util/InnerUtils.java:
--------------------------------------------------------------------------------
1 | package com.github.lkqm.hcnet.util;
2 |
3 | import java.io.File;
4 | import java.io.FileOutputStream;
5 | import java.io.IOException;
6 | import java.io.StringReader;
7 | import java.text.SimpleDateFormat;
8 | import java.util.Calendar;
9 | import java.util.Date;
10 | import java.util.HashMap;
11 | import java.util.Map;
12 | import java.util.TimeZone;
13 | import javax.xml.parsers.DocumentBuilder;
14 | import javax.xml.parsers.DocumentBuilderFactory;
15 | import javax.xml.parsers.ParserConfigurationException;
16 | import lombok.SneakyThrows;
17 | import org.w3c.dom.Document;
18 | import org.w3c.dom.Node;
19 | import org.w3c.dom.NodeList;
20 | import org.xml.sax.InputSource;
21 | import org.xml.sax.SAXException;
22 |
23 | public class InnerUtils {
24 |
25 |
26 | /**
27 | * 海康时间轴转化为时间轴
28 | */
29 | public static long hikAbsTimeToTimestamp(int absTime) {
30 | int year = (((absTime) >> 26) + 2000);
31 | int month = ((absTime >> 22) & 15) - 1;
32 | int day = (absTime >> 17) & 31;
33 | int hour = (absTime >> 12) & 31;
34 | int minute = (absTime >> 6) & 63;
35 | int second = (absTime) & 63;
36 | Calendar result = Calendar.getInstance(TimeZone.getDefault());
37 | result.set(Calendar.YEAR, year);
38 | result.set(Calendar.MONTH, month);
39 | result.set(Calendar.DAY_OF_MONTH, day);
40 | result.set(Calendar.HOUR_OF_DAY, hour);
41 | result.set(Calendar.MINUTE, minute);
42 | result.set(Calendar.SECOND, second);
43 | return result.getTimeInMillis();
44 | }
45 |
46 | /**
47 | * 创建文件所在目录.
48 | */
49 | public static boolean makeParentDirExists(File file) {
50 | File parentDir = file.getParentFile();
51 | if (!parentDir.exists()) {
52 | return parentDir.mkdirs();
53 | }
54 | return true;
55 | }
56 |
57 | /**
58 | * 写入文件.
59 | */
60 | public static void writeFile(byte[] bytes, String path) {
61 | File file = new File(path);
62 | InnerUtils.makeParentDirExists(file);
63 | try (FileOutputStream fos = new FileOutputStream(file, true)) {
64 | fos.write(bytes);
65 | fos.flush();
66 | } catch (IOException e) {
67 | throw new RuntimeException(e);
68 | }
69 | }
70 |
71 | /**
72 | * 时间格式化
73 | */
74 | public static String formatDate(Date date, String format) {
75 | SimpleDateFormat sdf = new SimpleDateFormat(format);
76 | return sdf.format(date);
77 | }
78 |
79 | /**
80 | * 转换xml为map
81 | */
82 | @SneakyThrows
83 | public static Map xmlToFlatMap(String xml, String rootElement) {
84 | Map map = new HashMap<>();
85 | Document doc = parseXmlString(xml);
86 |
87 | NodeList rootNode = doc.getElementsByTagName(rootElement);
88 | if (rootNode == null || rootNode.getLength() == 0) {
89 | return map;
90 | }
91 |
92 | Node root = rootNode.item(0);
93 | NodeList nodes = root.getChildNodes();
94 | if (nodes == null) {
95 | return map;
96 | }
97 | for (int i = 0; i < nodes.getLength(); i++) {
98 | Node node = nodes.item(i);
99 | map.put(node.getNodeName(), node.getTextContent());
100 | }
101 | return map;
102 | }
103 |
104 | private static Document parseXmlString(String xmlStr)
105 | throws ParserConfigurationException, IOException, SAXException {
106 | InputSource is = new InputSource(new StringReader(xmlStr));
107 | DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
108 | DocumentBuilder builder = factory.newDocumentBuilder();
109 | Document doc = builder.parse(is);
110 | return doc;
111 | }
112 |
113 | }
114 |
--------------------------------------------------------------------------------
/src/main/java/com/github/lkqm/hcnet/util/JnaUtils.java:
--------------------------------------------------------------------------------
1 | package com.github.lkqm.hcnet.util;
2 |
3 | import com.sun.jna.Pointer;
4 | import com.sun.jna.Structure;
5 | import java.nio.ByteBuffer;
6 | import lombok.experimental.UtilityClass;
7 |
8 | /**
9 | * Jna相关工具类.
10 | */
11 | @UtilityClass
12 | public class JnaUtils {
13 |
14 | public static byte[] pointerToBytes(Pointer pointer, int length) {
15 | byte[] faceBytes = new byte[length];
16 | ByteBuffer buffers = pointer.getByteBuffer(0, length);
17 | buffers.rewind();
18 | buffers.get(faceBytes);
19 | return faceBytes;
20 | }
21 |
22 | public static void pointerToStructure(Pointer pointer, Structure target) {
23 | target.write();
24 | target.getPointer().write(0, pointer.getByteArray(0, target.size()), 0, target.size());
25 | target.read();
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/src/test/java/com/github/lkqm/hcnet/HikDeviceTemplateTest.java:
--------------------------------------------------------------------------------
1 | package com.github.lkqm.hcnet;
2 |
3 |
4 | import static org.junit.jupiter.api.Assertions.assertNotEquals;
5 | import static org.junit.jupiter.api.Assertions.assertNotNull;
6 | import static org.junit.jupiter.api.Assertions.assertTrue;
7 |
8 | import com.github.lkqm.hcnet.HCNetSDK.NET_DVR_TIME;
9 | import com.github.lkqm.hcnet.callback.PrintDeviceExceptionCallback;
10 | import com.github.lkqm.hcnet.handler.DispatchMessageCallback;
11 | import com.github.lkqm.hcnet.handler.FaceSnapFileStoreHandler;
12 | import com.github.lkqm.hcnet.handler.VideoFileStoreCallback;
13 | import com.github.lkqm.hcnet.model.PassThroughResponse;
14 | import com.github.lkqm.hcnet.test.DeviceConstants;
15 | import com.github.lkqm.hcnet.test.DeviceConstants.DeviceInfo;
16 | import java.util.Date;
17 | import java.util.concurrent.CountDownLatch;
18 | import java.util.concurrent.TimeUnit;
19 | import lombok.SneakyThrows;
20 | import org.junit.jupiter.api.AfterAll;
21 | import org.junit.jupiter.api.Assertions;
22 | import org.junit.jupiter.api.BeforeAll;
23 | import org.junit.jupiter.api.Test;
24 |
25 | public class HikDeviceTemplateTest {
26 |
27 | static HikDeviceTemplate deviceTemplate;
28 | static Token token;
29 | static DeviceInfo device;
30 |
31 | @BeforeAll
32 | static void beforeAll() {
33 | JnaPathUtils.initJnaLibraryPathDev();
34 | deviceTemplate = new HikDeviceTemplate(HCNetSDK.INSTANCE);
35 |
36 | device = DeviceConstants.dvrDevice;
37 | HikResult loginResult = deviceTemplate.login(device.ip, device.port, device.user, device.password);
38 | Assertions.assertTrue(loginResult.isSuccess(), "登录失败: " + loginResult.getError());
39 |
40 | token = loginResult.getData();
41 | }
42 |
43 | @AfterAll
44 | static void afterAll() {
45 | if (token != null && token.getUserId() != null) {
46 | deviceTemplate.logout(token.getUserId());
47 | }
48 | }
49 |
50 | @Test
51 | void test() {
52 | HikResult deviceTimeResult = deviceTemplate.opsForMaintain(token.getUserId()).getDeviceTime();
53 | System.out.println(deviceTimeResult);
54 | }
55 |
56 | @Test
57 | void login() {
58 | HikResult tokenResult = deviceTemplate.login(device.ip, device.port, device.user, device.password);
59 | assertNotNull(tokenResult, "登录响应数据不能为空");
60 | if (tokenResult.isSuccess()) {
61 | Token token = tokenResult.getData();
62 | assertNotEquals(token.getUserId().longValue(), -1, "登录成功userId!=-1");
63 | assertTrue(token.getDeviceSerialNumber() != null && token.getDeviceSerialNumber().length() > 0,
64 | "登录返回设备序列号不能为空");
65 | } else {
66 | assertNotNull(tokenResult.getErrorCode(), "错误码不能为空");
67 | assertNotNull(tokenResult.getErrorMsg(), "错误消息不能为空");
68 | }
69 | assertTrue(tokenResult.isSuccess(), "登录应该成功: " + tokenResult.getErrorMsg());
70 | }
71 |
72 | @Test
73 | void modifyPassword() {
74 | HikResult actionResult = deviceTemplate.modifyPassword(token.getUserId(), device.user, "hik123456");
75 | assertTrue(actionResult.isSuccess(), "密码修改失败: " + actionResult.getError());
76 | // 还原
77 | actionResult = deviceTemplate.modifyPassword(token.getUserId(), device.user, device.password);
78 | assertTrue(actionResult.isSuccess(), "密码修改失败: " + actionResult.getError());
79 | }
80 |
81 | @SneakyThrows
82 | @Test
83 | void setupDeploy() {
84 | DispatchMessageCallback.INSTANCE.addHandler(new FaceSnapFileStoreHandler("/appfile/snap"));
85 |
86 | CountDownLatch sign = new CountDownLatch(1);
87 | HikResult callbackResult = deviceTemplate.setupDeploy(token.getUserId(), DispatchMessageCallback.INSTANCE,
88 | PrintDeviceExceptionCallback.INSTANCE);
89 | assertTrue(callbackResult.isSuccess(), "布防失败: " + callbackResult.getError());
90 |
91 | callbackResult = deviceTemplate.setupDeploy(token.getUserId(), DispatchMessageCallback.INSTANCE,
92 | PrintDeviceExceptionCallback.INSTANCE);
93 | assertTrue(callbackResult.isSuccess(), "布防失败: " + callbackResult.getError());
94 |
95 | sign.await(120, TimeUnit.SECONDS);
96 | }
97 |
98 | @Test
99 | void passThrough() {
100 | String xml =
101 | "\n"
102 | + "IP CAMERA \n"
103 | + "d9b04000-d0fb-11b2-80e4-988b0a0e517f \n"
104 | + "IPCamera \n"
105 | + "hangzhou \n"
106 | + "Hikvision.China \n"
107 | + "DS-2CD7A47FWD-XZS \n"
108 | + "DS-2CD7A47FWD-XZS20190228AACHC96234444 \n"
109 | + "98:8b:0a:0e:51:7f \n"
110 | + "V5.6.1 \n"
111 | + "build 190603 \n"
112 | + "V7.3 \n"
113 | + "build 190527 \n"
114 | + "V1.3.4 \n"
115 | + "100316 \n"
116 | + "0x0 \n"
117 | + "IPCamera \n"
118 | + "88 \n"
119 | + "false \n"
120 | + "false \n"
121 | + "B-R-H3-0 \n"
122 | + "";
123 | HikResult result = deviceTemplate
124 | .passThrough(token.getUserId(), "PUT /ISAPI/System/deviceInfo", xml);
125 | assertTrue(result.isSuccess(), "透传失败: " + result.getError());
126 | System.out.println(result.getData());
127 | }
128 |
129 | @Test
130 | void getDvrConfig() {
131 | HikResult result = deviceTemplate
132 | .getDvrConfig(token.getUserId(), 0, HCNetSDK.NET_DVR_GET_TIMECFG, NET_DVR_TIME.class);
133 | assertTrue(result.isSuccess(), "获取配置: " + result.getErrorMsg());
134 | result.getData().clear();
135 | }
136 |
137 | static VideoFileStoreCallback callback;
138 |
139 | @Test
140 | @SneakyThrows
141 | void realPlay() {
142 | callback = new VideoFileStoreCallback("/appfile/video");
143 | HikResult result = deviceTemplate.realPlay(token.getUserId(), callback);
144 | assertTrue(result.isSuccess(), "视频预览失败: " + result.getError());
145 | Thread.sleep(100000);
146 | }
147 |
148 | }
--------------------------------------------------------------------------------
/src/test/java/com/github/lkqm/hcnet/HikDeviceTest.java:
--------------------------------------------------------------------------------
1 | package com.github.lkqm.hcnet;
2 |
3 | import static org.junit.jupiter.api.Assertions.assertTrue;
4 |
5 | import com.github.lkqm.hcnet.callback.PrintDeviceExceptionCallback;
6 | import com.github.lkqm.hcnet.callback.PrintFaceSnapHandler;
7 | import com.github.lkqm.hcnet.handler.DispatchMessageCallback;
8 | import com.github.lkqm.hcnet.test.DeviceConstants;
9 | import com.github.lkqm.hcnet.test.DeviceConstants.DeviceInfo;
10 | import java.util.concurrent.TimeUnit;
11 | import org.junit.jupiter.api.AfterAll;
12 | import org.junit.jupiter.api.BeforeAll;
13 | import org.junit.jupiter.api.Test;
14 |
15 | class HikDeviceTest {
16 |
17 | private static HikDevice device;
18 | private static DeviceInfo dvrDeviceInfo;
19 |
20 | @BeforeAll
21 | static void beforeAll() {
22 | JnaPathUtils.initJnaLibraryPathDev();
23 | HCNetSDK hcnetsdk = HCNetSDK.INSTANCE;
24 |
25 | dvrDeviceInfo = DeviceConstants.dvrDevice;
26 | device = new HikDevice(hcnetsdk, dvrDeviceInfo.ip, dvrDeviceInfo.port, dvrDeviceInfo.user,
27 | dvrDeviceInfo.password);
28 |
29 | /*
30 | HikResult initResult = device.init();
31 | assertTrue(initResult.isSuccess(), "设备初始化失败: " + initResult.getError());
32 | */
33 | }
34 |
35 | @AfterAll
36 | static void after() {
37 | device.destroy();
38 | }
39 |
40 | @Test
41 | void setupDeploy() throws InterruptedException {
42 | DispatchMessageCallback.INSTANCE.addHandler(PrintFaceSnapHandler.INSTANCE);
43 | HikResult result = device
44 | .setupDeploy(DispatchMessageCallback.INSTANCE, PrintDeviceExceptionCallback.INSTANCE);
45 | assertTrue(result.isSuccess(), "布防失败: " + result.getError());
46 | Thread.sleep(TimeUnit.SECONDS.toMillis(120));
47 | }
48 |
49 | @Test
50 | void testModifyPassword() {
51 | HikResult actionResult = device.modifyPassword(dvrDeviceInfo.user, "hik123456");
52 | assertTrue(actionResult.isSuccess(), "密码修改失败: " + actionResult.getError());
53 |
54 | // 还原
55 | actionResult = device.modifyPassword(dvrDeviceInfo.user, dvrDeviceInfo.password);
56 | assertTrue(actionResult.isSuccess(), "密码修改失败: " + actionResult.getError());
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/src/test/java/com/github/lkqm/hcnet/JnaPathUtilsTest.java:
--------------------------------------------------------------------------------
1 | package com.github.lkqm.hcnet;
2 |
3 | import static org.junit.jupiter.api.Assertions.assertFalse;
4 | import static org.junit.jupiter.api.Assertions.assertNotEquals;
5 | import static org.junit.jupiter.api.Assertions.assertNotNull;
6 | import static org.junit.jupiter.api.Assertions.assertTrue;
7 |
8 | import com.sun.jna.Pointer;
9 | import org.junit.jupiter.api.Test;
10 |
11 | class JnaPathUtilsTest {
12 |
13 | @Test
14 | void initJnaLibraryPath() {
15 | String oldJnaPathProperty = System.getProperty(JnaPathUtils.JNA_PATH_PROPERTY_NAME);
16 | boolean modified = JnaPathUtils.initJnaLibraryPath(JnaPathUtilsTest.class, false);
17 | String newJnaPathProperty = System.getProperty(JnaPathUtils.JNA_PATH_PROPERTY_NAME);
18 | assertTrue(modified, "非jar执行应该修改了系统变量");
19 | assertNotEquals(oldJnaPathProperty, newJnaPathProperty, "系统变量应该被修改了");
20 | }
21 |
22 | @Test
23 | void isRunJar() {
24 | assertFalse(JnaPathUtils.isRunJar(), "运行再非Jar中");
25 | }
26 |
27 | @Test
28 | void getJarDirectoryPath() {
29 | String path = JnaPathUtils.getJarDirectoryPath(Pointer.class);
30 | assertNotNull(path, "返回该jar所在目录");
31 |
32 | path = JnaPathUtils.getJarDirectoryPath(String.class);
33 | assertNotNull(path, "返回该jar所在目录");
34 |
35 | path = JnaPathUtils.getJarDirectoryPath(JnaPathUtilsTest.class);
36 | assertNotNull(path, "返回该jar所在目录");
37 | }
38 | }
--------------------------------------------------------------------------------
/src/test/java/com/github/lkqm/hcnet/callback/PrintDeviceExceptionCallback.java:
--------------------------------------------------------------------------------
1 | package com.github.lkqm.hcnet.callback;
2 |
3 | import com.github.lkqm.hcnet.HCNetSDK.FExceptionCallBack;
4 | import com.sun.jna.NativeLong;
5 | import com.sun.jna.Pointer;
6 |
7 | public class PrintDeviceExceptionCallback implements FExceptionCallBack {
8 |
9 | public static final PrintDeviceExceptionCallback INSTANCE = new PrintDeviceExceptionCallback();
10 |
11 | @Override
12 | public void invoke(int dwType, NativeLong lUserID, NativeLong lHandle, Pointer pUser) throws InterruptedException {
13 | System.out.println(String.format("异常回调: type=%s, userId=%s, handle=%s", dwType, lUserID, lHandle));
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/test/java/com/github/lkqm/hcnet/callback/PrintFaceSnapHandler.java:
--------------------------------------------------------------------------------
1 | package com.github.lkqm.hcnet.callback;
2 |
3 | import com.github.lkqm.hcnet.handler.AbstractFaceSnapHandler;
4 | import com.github.lkqm.hcnet.model.FaceSnapEvent;
5 |
6 | public class PrintFaceSnapHandler extends AbstractFaceSnapHandler {
7 |
8 | public static PrintFaceSnapHandler INSTANCE = new PrintFaceSnapHandler();
9 |
10 | @Override
11 | public void handle(FaceSnapEvent event) {
12 | System.out.println("抓拍回调: " + event.getDeviceInfo() + "," + event.getFaceSnapInfo().getFaceScore());
13 | }
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/src/test/java/com/github/lkqm/hcnet/model/ResponseStatusTest.java:
--------------------------------------------------------------------------------
1 | package com.github.lkqm.hcnet.model;
2 |
3 | import static org.junit.jupiter.api.Assertions.assertEquals;
4 | import static org.junit.jupiter.api.Assertions.assertNotNull;
5 |
6 | import org.junit.jupiter.api.Test;
7 |
8 | class ResponseStatusTest {
9 |
10 | @Test
11 | void ofXml() {
12 | String xml = "\n"
13 | + "\n"
14 | + "/ISAPI/System/deviceInfo \n"
15 | + "5 \n"
16 | + "Invalid Format \n"
17 | + "badXmlFormat \n"
18 | + " ";
19 | ResponseStatus responseStatus = ResponseStatus.ofXml(xml);
20 | assertNotNull(responseStatus, "返回数据不应该为null");
21 | assertEquals("/ISAPI/System/deviceInfo", responseStatus.getRequestURL(), "requestURL解析不正确");
22 | assertEquals(5, responseStatus.getStatusCode(), "statusCode解析不正确");
23 | assertEquals("badXmlFormat", responseStatus.getSubStatusCode(), "subStatusCode解析不正确");
24 | assertEquals("Invalid Format", responseStatus.getStatusString(), "statusString解析不正确");
25 | }
26 | }
--------------------------------------------------------------------------------
/src/test/java/com/github/lkqm/hcnet/options/MaintainOptionsImplTest.java:
--------------------------------------------------------------------------------
1 | package com.github.lkqm.hcnet.options;
2 |
3 | import static org.junit.jupiter.api.Assertions.assertEquals;
4 | import static org.junit.jupiter.api.Assertions.assertNotNull;
5 | import static org.junit.jupiter.api.Assertions.assertTrue;
6 |
7 | import com.github.lkqm.hcnet.HCNetSDK;
8 | import com.github.lkqm.hcnet.HikDeviceTemplate;
9 | import com.github.lkqm.hcnet.HikResult;
10 | import com.github.lkqm.hcnet.JnaPathUtils;
11 | import com.github.lkqm.hcnet.Token;
12 | import com.github.lkqm.hcnet.model.UpgradeResponse;
13 | import com.github.lkqm.hcnet.test.DeviceConstants;
14 | import com.github.lkqm.hcnet.test.DeviceConstants.DeviceInfo;
15 | import java.util.Date;
16 | import org.junit.jupiter.api.AfterAll;
17 | import org.junit.jupiter.api.Assertions;
18 | import org.junit.jupiter.api.BeforeAll;
19 | import org.junit.jupiter.api.Test;
20 |
21 | class MaintainOptionsImplTest {
22 |
23 | static HikDeviceTemplate deviceTemplate;
24 | static Token dvrToken;
25 | static MaintainOptions dvrMaintainOptions;
26 |
27 | @BeforeAll
28 | static void beforeAll() {
29 | JnaPathUtils.initJnaLibraryPathDev();
30 | deviceTemplate = new HikDeviceTemplate(HCNetSDK.INSTANCE);
31 |
32 | DeviceInfo dvr = DeviceConstants.dvrDevice;
33 | HikResult loginResult = deviceTemplate.login(dvr.ip, dvr.port, dvr.user, dvr.password);
34 | Assertions.assertTrue(loginResult.isSuccess(), "登录失败: " + loginResult.getError());
35 |
36 | dvrToken = loginResult.getData();
37 | dvrMaintainOptions = new MaintainOptionsImpl(deviceTemplate, dvrToken.getUserId());
38 | }
39 |
40 | @AfterAll
41 | static void afterAll() {
42 | if (dvrToken != null && dvrToken.getUserId() != null) {
43 | deviceTemplate.logout(dvrToken.getUserId());
44 | }
45 | }
46 |
47 | @Test
48 | void isOnline() {
49 | boolean isOnline = dvrMaintainOptions.isOnline();
50 | assertTrue(isOnline, "设备离线");
51 | }
52 |
53 | @Test
54 | void reboot() {
55 | HikResult> result = dvrMaintainOptions.reboot();
56 | assertTrue(result.isSuccess(), result.getError());
57 | }
58 |
59 | @Test
60 | void getDeviceTime() {
61 | HikResult result = dvrMaintainOptions.getDeviceTime();
62 | assertTrue(result.isSuccess(), result.getError());
63 | assertNotNull(result.getData());
64 | }
65 |
66 | @Test
67 | void setDeviceTime() {
68 | HikResult> result = dvrMaintainOptions.setDeviceTime(new Date());
69 | assertTrue(result.isSuccess(), result.getError());
70 |
71 | HikResult deviceTimeResult = dvrMaintainOptions.getDeviceTime();
72 | assertTrue(deviceTimeResult.isSuccess(), deviceTimeResult.getError());
73 | assertNotNull(deviceTimeResult.getData());
74 |
75 | Date deviceTime = deviceTimeResult.getData();
76 | assertTrue(Math.abs(System.currentTimeMillis() - deviceTime.getTime()) < 5000, "设置时间成功后获取时差不超过5秒");
77 | }
78 |
79 | @Test
80 | void upgradeSync() {
81 | HikResult result = dvrMaintainOptions.upgradeSyncForDVR("C:\\appfile\\downloads\\zpj.dav");
82 | assertTrue(result.isSuccess(), "请求升级: " + result.getErrorMsg());
83 | UpgradeResponse upgradeResponse = result.getData();
84 | assertEquals(1, upgradeResponse.getState(), "升级结果: " + upgradeResponse.getState());
85 | }
86 |
87 | @Test
88 | void getConfig() {
89 | HikResult result = dvrMaintainOptions.getConfig();
90 | if (result.isSuccess()) {
91 | System.out.println(result.getData());
92 | }
93 | }
94 | }
--------------------------------------------------------------------------------
/src/test/java/com/github/lkqm/hcnet/options/PtzOptionsImplTest.java:
--------------------------------------------------------------------------------
1 | package com.github.lkqm.hcnet.options;
2 |
3 | import static org.junit.jupiter.api.Assertions.assertTrue;
4 |
5 | import com.github.lkqm.hcnet.HCNetSDK;
6 | import com.github.lkqm.hcnet.HikDeviceTemplate;
7 | import com.github.lkqm.hcnet.HikResult;
8 | import com.github.lkqm.hcnet.JnaPathUtils;
9 | import com.github.lkqm.hcnet.Token;
10 | import com.github.lkqm.hcnet.test.DeviceConstants;
11 | import com.github.lkqm.hcnet.test.DeviceConstants.DeviceInfo;
12 | import org.junit.jupiter.api.AfterAll;
13 | import org.junit.jupiter.api.Assertions;
14 | import org.junit.jupiter.api.BeforeAll;
15 | import org.junit.jupiter.api.Test;
16 |
17 | class PtzOptionsImplTest {
18 |
19 | static HikDeviceTemplate deviceTemplate;
20 | static Token dvrToken;
21 | static PtzOptions ptzOptions;
22 |
23 | @BeforeAll
24 | static void beforeAll() {
25 | JnaPathUtils.initJnaLibraryPathDev();
26 | deviceTemplate = new HikDeviceTemplate(HCNetSDK.INSTANCE);
27 |
28 | DeviceInfo dvr = DeviceConstants.dvrDevice;
29 | HikResult loginResult = deviceTemplate.login(dvr.ip, dvr.port, dvr.user, dvr.password);
30 | Assertions.assertTrue(loginResult.isSuccess(), "登录失败: " + loginResult.getError());
31 |
32 | dvrToken = loginResult.getData();
33 | ptzOptions = new PtzOptionsImpl(deviceTemplate, dvrToken.getUserId());
34 | }
35 |
36 | @AfterAll
37 | static void afterAll() {
38 | if (dvrToken != null && dvrToken.getUserId() != null) {
39 | deviceTemplate.logout(dvrToken.getUserId());
40 | }
41 | }
42 |
43 | @Test
44 | void ptzControl() {
45 | HikResult result = ptzOptions.controlStart(21, 7);
46 | assertTrue(result.isSuccess(), "云台控制开始失败: " + result.getError());
47 |
48 | result = ptzOptions.controlStop(21, 7);
49 | assertTrue(result.isSuccess(), "云台控制停止失败: " + result.getError());
50 | }
51 |
52 | @Test
53 | void ptzPreset() {
54 | int presetIndex = 1;
55 | HikResult result = ptzOptions.presetSet(presetIndex);
56 | assertTrue(result.isSuccess(), "云台点位设置失败: " + result.getError());
57 |
58 | result = ptzOptions.presetGoto(presetIndex);
59 | assertTrue(result.isSuccess(), "云台点位跳转失败: " + result.getError());
60 |
61 | result = ptzOptions.presetClean(presetIndex);
62 | assertTrue(result.isSuccess(), "云台点位跳转失败: " + result.getError());
63 | }
64 |
65 | @Test
66 | void ptzCruise() {
67 | int route = 1;
68 | HikResult result = ptzOptions.cruiseFillPreset(route, 1, 18);
69 | assertTrue(result.isSuccess(), "云台巡航添加点位失败: " + result.getError());
70 |
71 | result = ptzOptions.cruiseRun(route);
72 | assertTrue(result.isSuccess(), "云台巡航运行失败: " + result.getError());
73 |
74 | result = ptzOptions.cruiseStop(route);
75 | assertTrue(result.isSuccess(), "云台巡航停止失败: " + result.getError());
76 | }
77 |
78 | @Test
79 | void ptzTrack() {
80 | HikResult result = ptzOptions.trackStartRecord();
81 | assertTrue(result.isSuccess(), "云台轨迹开始记录失败: " + result.getError());
82 |
83 | result = ptzOptions.trackStopRecord();
84 | assertTrue(result.isSuccess(), "云台轨迹停止记录失败: " + result.getError());
85 |
86 | result = ptzOptions.trackRun();
87 | assertTrue(result.isSuccess(), "云台轨迹运行失败: " + result.getError());
88 |
89 | }
90 |
91 | @Test
92 | void pztZoom() {
93 | HikResult result = ptzOptions.zoom(0, 0, 1000, 1000);
94 | assertTrue(result.isSuccess(), "云台图像区域缩放失败: " + result.getError());
95 | }
96 |
97 | }
--------------------------------------------------------------------------------
/src/test/java/com/github/lkqm/hcnet/options/SdkOptionsImplTest.java:
--------------------------------------------------------------------------------
1 | package com.github.lkqm.hcnet.options;
2 |
3 | import static org.junit.jupiter.api.Assertions.assertEquals;
4 | import static org.junit.jupiter.api.Assertions.assertNotNull;
5 | import static org.junit.jupiter.api.Assertions.assertTrue;
6 |
7 | import com.github.lkqm.hcnet.HCNetSDK;
8 | import com.github.lkqm.hcnet.HCNetSDK.NET_DVR_SDKABL;
9 | import com.github.lkqm.hcnet.HCNetSDK.NET_DVR_SDKSTATE;
10 | import com.github.lkqm.hcnet.HikDeviceTemplate;
11 | import com.github.lkqm.hcnet.HikResult;
12 | import com.github.lkqm.hcnet.JnaPathUtils;
13 | import org.junit.jupiter.api.BeforeAll;
14 | import org.junit.jupiter.api.Test;
15 |
16 | class SdkOptionsImplTest {
17 |
18 | static SdkOptions sdkOptions;
19 |
20 | @BeforeAll
21 | static void beforeEach() {
22 | JnaPathUtils.initJnaLibraryPathDev();
23 | HikDeviceTemplate deviceTemplate = new HikDeviceTemplate(HCNetSDK.INSTANCE);
24 | sdkOptions = new SdkOptionsImpl(deviceTemplate);
25 | }
26 |
27 | @Test
28 | void getVersion() {
29 | String version = sdkOptions.getVersion();
30 | assertNotNull(version);
31 | String[] versionParts = version.split("\\.");
32 | assertEquals(3, versionParts.length);
33 | }
34 |
35 | @Test
36 | void getState() {
37 | HikResult result = sdkOptions.getState();
38 | assertTrue(result.isSuccess());
39 | assertNotNull(result.getData());
40 | System.out.println(result.getData());
41 | }
42 |
43 | @Test
44 | void getAbility() {
45 | HikResult result = sdkOptions.getAbility();
46 | assertTrue(result.isSuccess());
47 | assertNotNull(result.getData());
48 | System.out.println(result.getData());
49 | }
50 |
51 | @Test
52 | void setLogFile() {
53 | HikResult> result = sdkOptions.setLogFile(1, "/tmp/", true);
54 | assertTrue(result.isSuccess());
55 | }
56 |
57 | @Test
58 | void setTimeout() {
59 | HikResult> result = sdkOptions.setTimeout(3000, 5000, 5000);
60 | assertTrue(result.isSuccess());
61 | }
62 | }
--------------------------------------------------------------------------------
/src/test/java/com/github/lkqm/hcnet/test/DeviceConstants.java:
--------------------------------------------------------------------------------
1 | package com.github.lkqm.hcnet.test;
2 |
3 | import lombok.AllArgsConstructor;
4 |
5 | public interface DeviceConstants {
6 |
7 | DeviceInfo dvrDevice = new DeviceInfo("192.168.0.123", 8000, "admin", "wxb888888");
8 | DeviceInfo acsDevice = new DeviceInfo("192.168.0.155", 8000, "admin", "wxb888888");
9 |
10 |
11 | @AllArgsConstructor
12 | class DeviceInfo {
13 |
14 | public final String ip;
15 | public final int port;
16 | public final String user;
17 | public final String password;
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/src/test/resources/natives/dll/D3DCompiler_43.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/dll/D3DCompiler_43.dll
--------------------------------------------------------------------------------
/src/test/resources/natives/dll/D3DX9_43.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/dll/D3DX9_43.dll
--------------------------------------------------------------------------------
/src/test/resources/natives/dll/HCAlarm.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/dll/HCAlarm.dll
--------------------------------------------------------------------------------
/src/test/resources/natives/dll/HCCore.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/dll/HCCore.dll
--------------------------------------------------------------------------------
/src/test/resources/natives/dll/HCNetSDK.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/dll/HCNetSDK.dll
--------------------------------------------------------------------------------
/src/test/resources/natives/dll/HCNetSDKCom/AnalyzeData.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/dll/HCNetSDKCom/AnalyzeData.dll
--------------------------------------------------------------------------------
/src/test/resources/natives/dll/HCNetSDKCom/AudioIntercom.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/dll/HCNetSDKCom/AudioIntercom.dll
--------------------------------------------------------------------------------
/src/test/resources/natives/dll/HCNetSDKCom/HCAlarm.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/dll/HCNetSDKCom/HCAlarm.dll
--------------------------------------------------------------------------------
/src/test/resources/natives/dll/HCNetSDKCom/HCAlarm.lib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/dll/HCNetSDKCom/HCAlarm.lib
--------------------------------------------------------------------------------
/src/test/resources/natives/dll/HCNetSDKCom/HCCoreDevCfg.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/dll/HCNetSDKCom/HCCoreDevCfg.dll
--------------------------------------------------------------------------------
/src/test/resources/natives/dll/HCNetSDKCom/HCDisplay.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/dll/HCNetSDKCom/HCDisplay.dll
--------------------------------------------------------------------------------
/src/test/resources/natives/dll/HCNetSDKCom/HCGeneralCfgMgr.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/dll/HCNetSDKCom/HCGeneralCfgMgr.dll
--------------------------------------------------------------------------------
/src/test/resources/natives/dll/HCNetSDKCom/HCGeneralCfgMgr.lib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/dll/HCNetSDKCom/HCGeneralCfgMgr.lib
--------------------------------------------------------------------------------
/src/test/resources/natives/dll/HCNetSDKCom/HCIndustry.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/dll/HCNetSDKCom/HCIndustry.dll
--------------------------------------------------------------------------------
/src/test/resources/natives/dll/HCNetSDKCom/HCPlayBack.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/dll/HCNetSDKCom/HCPlayBack.dll
--------------------------------------------------------------------------------
/src/test/resources/natives/dll/HCNetSDKCom/HCPreview.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/dll/HCNetSDKCom/HCPreview.dll
--------------------------------------------------------------------------------
/src/test/resources/natives/dll/HCNetSDKCom/HCPreview.lib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/dll/HCNetSDKCom/HCPreview.lib
--------------------------------------------------------------------------------
/src/test/resources/natives/dll/HCNetSDKCom/HCVoiceTalk.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/dll/HCNetSDKCom/HCVoiceTalk.dll
--------------------------------------------------------------------------------
/src/test/resources/natives/dll/HCNetSDKCom/OpenAL32.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/dll/HCNetSDKCom/OpenAL32.dll
--------------------------------------------------------------------------------
/src/test/resources/natives/dll/HCNetSDKCom/StreamTransClient.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/dll/HCNetSDKCom/StreamTransClient.dll
--------------------------------------------------------------------------------
/src/test/resources/natives/dll/HCNetSDKCom/SystemTransform.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/dll/HCNetSDKCom/SystemTransform.dll
--------------------------------------------------------------------------------
/src/test/resources/natives/dll/HCNetSDKCom/libiconv2.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/dll/HCNetSDKCom/libiconv2.dll
--------------------------------------------------------------------------------
/src/test/resources/natives/dll/HCNetSDKCom/msvcr90.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/dll/HCNetSDKCom/msvcr90.dll
--------------------------------------------------------------------------------
/src/test/resources/natives/dll/PlayCtrl.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/dll/PlayCtrl.dll
--------------------------------------------------------------------------------
/src/test/resources/natives/dll/SuperRender.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/dll/SuperRender.dll
--------------------------------------------------------------------------------
/src/test/resources/natives/dll/gdiplus.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/dll/gdiplus.dll
--------------------------------------------------------------------------------
/src/test/resources/natives/dylib/changePath.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | install_name_tool -change /usr/local/lib/libSystemTranform.dylib @loader_path/libSystemTransform.dylib "libHCNetSDK.dylib"
3 | install_name_tool -change @loader_path/libPlayCtrl.dylib @loader_path/libPlayCtrl.dylib "libHCNetSDK.dylib"
4 | install_name_tool -change /usr/local/lib/libNPQos.dylib @loader_path/libNPQos.dylib "libHCNetSDK.dylib"
5 |
6 |
--------------------------------------------------------------------------------
/src/test/resources/natives/dylib/libHCNetSDK.dylib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/dylib/libHCNetSDK.dylib
--------------------------------------------------------------------------------
/src/test/resources/natives/dylib/libNPQos.dylib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/dylib/libNPQos.dylib
--------------------------------------------------------------------------------
/src/test/resources/natives/dylib/libPlayCtrl.dylib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/dylib/libPlayCtrl.dylib
--------------------------------------------------------------------------------
/src/test/resources/natives/dylib/libStreamTransClient.dylib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/dylib/libStreamTransClient.dylib
--------------------------------------------------------------------------------
/src/test/resources/natives/dylib/libSuperRender.dylib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/dylib/libSuperRender.dylib
--------------------------------------------------------------------------------
/src/test/resources/natives/dylib/libSystemTransform.dylib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/dylib/libSystemTransform.dylib
--------------------------------------------------------------------------------
/src/test/resources/natives/dylib/libhpr.dylib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/dylib/libhpr.dylib
--------------------------------------------------------------------------------
/src/test/resources/natives/so/HCNetSDKCom/libAudioIntercom.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/so/HCNetSDKCom/libAudioIntercom.so
--------------------------------------------------------------------------------
/src/test/resources/natives/so/HCNetSDKCom/libHCAlarm.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/so/HCNetSDKCom/libHCAlarm.so
--------------------------------------------------------------------------------
/src/test/resources/natives/so/HCNetSDKCom/libHCCoreDevCfg.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/so/HCNetSDKCom/libHCCoreDevCfg.so
--------------------------------------------------------------------------------
/src/test/resources/natives/so/HCNetSDKCom/libHCDisplay.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/so/HCNetSDKCom/libHCDisplay.so
--------------------------------------------------------------------------------
/src/test/resources/natives/so/HCNetSDKCom/libHCGeneralCfgMgr.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/so/HCNetSDKCom/libHCGeneralCfgMgr.so
--------------------------------------------------------------------------------
/src/test/resources/natives/so/HCNetSDKCom/libHCIndustry.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/so/HCNetSDKCom/libHCIndustry.so
--------------------------------------------------------------------------------
/src/test/resources/natives/so/HCNetSDKCom/libHCPlayBack.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/so/HCNetSDKCom/libHCPlayBack.so
--------------------------------------------------------------------------------
/src/test/resources/natives/so/HCNetSDKCom/libHCPreview.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/so/HCNetSDKCom/libHCPreview.so
--------------------------------------------------------------------------------
/src/test/resources/natives/so/HCNetSDKCom/libHCVoiceTalk.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/so/HCNetSDKCom/libHCVoiceTalk.so
--------------------------------------------------------------------------------
/src/test/resources/natives/so/HCNetSDKCom/libStreamTransClient.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/so/HCNetSDKCom/libStreamTransClient.so
--------------------------------------------------------------------------------
/src/test/resources/natives/so/HCNetSDKCom/libSystemTransform.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/so/HCNetSDKCom/libSystemTransform.so
--------------------------------------------------------------------------------
/src/test/resources/natives/so/HCNetSDKCom/libanalyzedata.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/so/HCNetSDKCom/libanalyzedata.so
--------------------------------------------------------------------------------
/src/test/resources/natives/so/HCNetSDKCom/libiconv2.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/so/HCNetSDKCom/libiconv2.so
--------------------------------------------------------------------------------
/src/test/resources/natives/so/HCNetSDK_Log_Switch.xml:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/so/HCNetSDK_Log_Switch.xml
--------------------------------------------------------------------------------
/src/test/resources/natives/so/libAudioRender.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/so/libAudioRender.so
--------------------------------------------------------------------------------
/src/test/resources/natives/so/libHCCore.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/so/libHCCore.so
--------------------------------------------------------------------------------
/src/test/resources/natives/so/libNPQos.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/so/libNPQos.so
--------------------------------------------------------------------------------
/src/test/resources/natives/so/libPlayCtrl.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/so/libPlayCtrl.so
--------------------------------------------------------------------------------
/src/test/resources/natives/so/libSuperRender.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/so/libSuperRender.so
--------------------------------------------------------------------------------
/src/test/resources/natives/so/libcrypto.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/so/libcrypto.so
--------------------------------------------------------------------------------
/src/test/resources/natives/so/libcrypto.so.1.0.0:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/so/libcrypto.so.1.0.0
--------------------------------------------------------------------------------
/src/test/resources/natives/so/libhcnetsdk.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/so/libhcnetsdk.so
--------------------------------------------------------------------------------
/src/test/resources/natives/so/libhpr.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/so/libhpr.so
--------------------------------------------------------------------------------
/src/test/resources/natives/so/libopenal.so.1:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/so/libopenal.so.1
--------------------------------------------------------------------------------
/src/test/resources/natives/so/libssl.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/so/libssl.so
--------------------------------------------------------------------------------
/src/test/resources/natives/so/libz.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/lkqm/hcnetsdk-java/c35697b7f62977f88f1c752d207164fad5e4fb00/src/test/resources/natives/so/libz.so
--------------------------------------------------------------------------------