hanqingsong преди 1 година
родител
ревизия
40248f36fa

+ 388 - 0
src/main/java/com/unis/alarm/Alarm.java

@@ -0,0 +1,388 @@
1
+package com.unis.alarm;
2
+
3
+import com.sun.jna.Native;
4
+import com.sun.jna.Pointer;
5
+import com.unis.common.osSelect;
6
+import com.unis.config.AddressModel;
7
+import lombok.extern.slf4j.Slf4j;
8
+import org.springframework.boot.ApplicationArguments;
9
+import org.springframework.boot.ApplicationRunner;
10
+import org.springframework.stereotype.Component;
11
+
12
+import javax.annotation.Resource;
13
+import java.util.Scanner;
14
+
15
+/**
16
+ * @author qingsong.han
17
+ * @description:
18
+ * @create 2024-08-01 14:24
19
+ */
20
+@Slf4j
21
+@Component
22
+@SuppressWarnings("all")
23
+public class Alarm implements ApplicationRunner {
24
+
25
+    static HCNetSDK hCNetSDK = null;
26
+    static int[] lUserID = new int[]{0, 0, 0, 0, 0};//用户句柄 实现对设备登录
27
+    static int[] lAlarmHandle = new int[]{-1, -1, -1, -1, -1};//报警布防句柄
28
+    static int[] lAlarmHandle_V50 = new int[]{-1, -1, -1, -1, -1}; //v50报警布防句柄
29
+    static int lListenHandle = -1;//报警监听句柄
30
+    static FMSGCallBack_V31 fMSFCallBack_V31 = null;
31
+    static FMSGCallBack fMSFCallBack = null;
32
+    // 设备连接信息
33
+    @Resource
34
+    private AddressModel addressModel;
35
+
36
+    private void mainMethod() {
37
+        if (hCNetSDK == null) {
38
+            if (!CreateSDKInstance()) {
39
+                log.info("Load SDK fail");
40
+                return;
41
+            }
42
+        }
43
+        //linux系统建议调用以下接口加载组件库
44
+        if (osSelect.isLinux()) {
45
+            HCNetSDK.BYTE_ARRAY ptrByteArray1 = new HCNetSDK.BYTE_ARRAY(256);
46
+            HCNetSDK.BYTE_ARRAY ptrByteArray2 = new HCNetSDK.BYTE_ARRAY(256);
47
+            //这里是库的绝对路径,请根据实际情况修改,注意改路径必须有访问权限
48
+            String strPath1 = System.getProperty("user.dir") + "/lib/libcrypto.so.1.1";
49
+            String strPath2 = System.getProperty("user.dir") + "/lib/libssl.so.1.1";
50
+
51
+            System.arraycopy(strPath1.getBytes(), 0, ptrByteArray1.byValue, 0, strPath1.length());
52
+            ptrByteArray1.write();
53
+            hCNetSDK.NET_DVR_SetSDKInitCfg(3, ptrByteArray1.getPointer());
54
+
55
+            System.arraycopy(strPath2.getBytes(), 0, ptrByteArray2.byValue, 0, strPath2.length());
56
+            ptrByteArray2.write();
57
+            hCNetSDK.NET_DVR_SetSDKInitCfg(4, ptrByteArray2.getPointer());
58
+
59
+            String strPathCom = System.getProperty("user.dir") + "/lib";
60
+            HCNetSDK.NET_DVR_LOCAL_SDK_PATH struComPath = new HCNetSDK.NET_DVR_LOCAL_SDK_PATH();
61
+            System.arraycopy(strPathCom.getBytes(), 0, struComPath.sPath, 0, strPathCom.length());
62
+            struComPath.write();
63
+            hCNetSDK.NET_DVR_SetSDKInitCfg(2, struComPath.getPointer());
64
+        }
65
+
66
+        /**初始化*/
67
+        hCNetSDK.NET_DVR_Init();
68
+        /**加载日志*/
69
+        hCNetSDK.NET_DVR_SetLogToFile(3, "../sdklog", false);
70
+        //设置报警回调函数
71
+        if (fMSFCallBack_V31 == null) {
72
+            fMSFCallBack_V31 = new FMSGCallBack_V31();
73
+            Pointer pUser = null;
74
+            if (!hCNetSDK.NET_DVR_SetDVRMessageCallBack_V31(fMSFCallBack_V31, pUser)) {
75
+                log.error("设置回调函数失败!");
76
+                return;
77
+            } else {
78
+                log.info("设置回调函数成功!");
79
+            }
80
+        }
81
+        /** 设备上传的报警信息是COMM_VCA_ALARM(0x4993)类型,
82
+         在SDK初始化之后增加调用NET_DVR_SetSDKLocalCfg(enumType为NET_DVR_LOCAL_CFG_TYPE_GENERAL)设置通用参数NET_DVR_LOCAL_GENERAL_CFG的byAlarmJsonPictureSeparate为1,
83
+         将Json数据和图片数据分离上传,这样设置之后,报警布防回调函数里面接收到的报警信息类型为COMM_ISAPI_ALARM(0x6009),
84
+         报警信息结构体为NET_DVR_ALARM_ISAPI_INFO(与设备无关,SDK封装的数据结构),更便于解析。*/
85
+        HCNetSDK.NET_DVR_LOCAL_GENERAL_CFG struNET_DVR_LOCAL_GENERAL_CFG = new HCNetSDK.NET_DVR_LOCAL_GENERAL_CFG();
86
+        struNET_DVR_LOCAL_GENERAL_CFG.byAlarmJsonPictureSeparate = 1;   //设置JSON透传报警数据和图片分离
87
+        struNET_DVR_LOCAL_GENERAL_CFG.write();
88
+        Pointer pStrNET_DVR_LOCAL_GENERAL_CFG = struNET_DVR_LOCAL_GENERAL_CFG.getPointer();
89
+        hCNetSDK.NET_DVR_SetSDKLocalCfg(17, pStrNET_DVR_LOCAL_GENERAL_CFG);
90
+
91
+        String m_sDeviceIP = addressModel.getDeviceIP();//设备ip地址
92
+        short m_wPort = addressModel.getPort();//设备ip地址
93
+        String m_sUsername = addressModel.getUserName();//设备用户名
94
+        String m_sPassword = addressModel.getPassword();//设备密码
95
+        Alarm.Login_V40(0, m_sDeviceIP, (short) m_wPort, m_sUsername, m_sPassword);  //登录设备
96
+
97
+        Alarm.SetAlarm(0);//报警布防,和报警监听二选一即可
98
+
99
+        //  Alarm.StartListen("10.17.34.18",(short)8000);//报警监听,不需要登陆设备
100
+        while (true) {
101
+            //这里加入控制台输入控制,是为了保持连接状态,当输入Y表示布防结束
102
+            log.info("请选择是否撤出布防(Y/N): ");
103
+            Scanner input = new Scanner(System.in);
104
+            String str = input.next();
105
+            if (str.equals("Y")) {
106
+                break;
107
+            }
108
+        }
109
+        Alarm.Logout(0);
110
+        //释放SDK
111
+        hCNetSDK.NET_DVR_Cleanup();
112
+        return;
113
+    }
114
+
115
+    /**
116
+     * 设备登录V40 与V30功能一致
117
+     *
118
+     * @param i    登录设备编号
119
+     * @param ip   设备IP
120
+     * @param port SDK端口,默认设备的8000端口
121
+     * @param user 设备用户名
122
+     * @param psw  设备密码
123
+     */
124
+    public static void Login_V40(int i, String ip, short port, String user, String psw) {
125
+        //注册
126
+        HCNetSDK.NET_DVR_USER_LOGIN_INFO m_strLoginInfo = new HCNetSDK.NET_DVR_USER_LOGIN_INFO();//设备登录信息
127
+        HCNetSDK.NET_DVR_DEVICEINFO_V40 m_strDeviceInfo = new HCNetSDK.NET_DVR_DEVICEINFO_V40();//设备信息
128
+
129
+        String m_sDeviceIP = ip;//设备ip地址
130
+        m_strLoginInfo.sDeviceAddress = new byte[HCNetSDK.NET_DVR_DEV_ADDRESS_MAX_LEN];
131
+        System.arraycopy(m_sDeviceIP.getBytes(), 0, m_strLoginInfo.sDeviceAddress, 0, m_sDeviceIP.length());
132
+
133
+        String m_sUsername = user;//设备用户名
134
+        m_strLoginInfo.sUserName = new byte[HCNetSDK.NET_DVR_LOGIN_USERNAME_MAX_LEN];
135
+        System.arraycopy(m_sUsername.getBytes(), 0, m_strLoginInfo.sUserName, 0, m_sUsername.length());
136
+
137
+        String m_sPassword = psw;//设备密码
138
+        m_strLoginInfo.sPassword = new byte[HCNetSDK.NET_DVR_LOGIN_PASSWD_MAX_LEN];
139
+        System.arraycopy(m_sPassword.getBytes(), 0, m_strLoginInfo.sPassword, 0, m_sPassword.length());
140
+
141
+        m_strLoginInfo.wPort = port;
142
+        m_strLoginInfo.bUseAsynLogin = false; //是否异步登录:0- 否,1- 是
143
+//        m_strLoginInfo.byLoginMode=1;  //ISAPI登录
144
+        m_strLoginInfo.write();
145
+
146
+        lUserID[i] = hCNetSDK.NET_DVR_Login_V40(m_strLoginInfo, m_strDeviceInfo);
147
+        if (lUserID[i] == -1) {
148
+            log.error("登录失败,错误码为: {}", hCNetSDK.NET_DVR_GetLastError());
149
+            return;
150
+        } else {
151
+            log.info("设备登录成功IP: {}", ip);
152
+            return;
153
+        }
154
+    }
155
+
156
+    /**
157
+     * 设备登录V30
158
+     *
159
+     * @param i    登录设备编号
160
+     * @param ip   设备IP
161
+     * @param port SDK端口,默认设备的8000端口
162
+     * @param user 设备用户名
163
+     * @param psw  设备密码
164
+     */
165
+    public static void Login_V30(int i, String ip, short port, String user, String psw) {
166
+        HCNetSDK.NET_DVR_DEVICEINFO_V30 m_strDeviceInfo = new HCNetSDK.NET_DVR_DEVICEINFO_V30();
167
+        lUserID[i] = hCNetSDK.NET_DVR_Login_V30(ip, port, user, psw, m_strDeviceInfo);
168
+        log.info("UsID: {}", lUserID[i]);
169
+        if ((lUserID[i] == -1) || (lUserID[i] == 0xFFFFFFFF)) {
170
+            log.error("登录失败,错误码为: {}", hCNetSDK.NET_DVR_GetLastError());
171
+            return;
172
+        } else {
173
+            log.info("设备登录成功IP: {}", ip);
174
+            return;
175
+        }
176
+    }
177
+
178
+    /**
179
+     * 报警布防接口
180
+     *
181
+     * @param i
182
+     */
183
+    public static void SetAlarm(int i) {
184
+        if (lAlarmHandle[i] < 0) { //尚未布防,需要布防
185
+            //报警布防参数设置
186
+            HCNetSDK.NET_DVR_SETUPALARM_PARAM m_strAlarmInfo = new HCNetSDK.NET_DVR_SETUPALARM_PARAM();
187
+            m_strAlarmInfo.dwSize = m_strAlarmInfo.size();
188
+            m_strAlarmInfo.byLevel = 0;  //布防等级
189
+            m_strAlarmInfo.byAlarmInfoType = 1;   // 智能交通报警信息上传类型:0- 老报警信息(NET_DVR_PLATE_RESULT),1- 新报警信息(NET_ITS_PLATE_RESULT)
190
+            m_strAlarmInfo.byDeployType = 0;   //布防类型:0-客户端布防,1-实时布防
191
+            m_strAlarmInfo.write();
192
+            lAlarmHandle[i] = hCNetSDK.NET_DVR_SetupAlarmChan_V41(lUserID[i], m_strAlarmInfo);
193
+            System.out.println("lAlarmHandle: " + lAlarmHandle[i]);
194
+            if (lAlarmHandle[i] == -1) {
195
+                log.error("布防失败,错误码为: {}", hCNetSDK.NET_DVR_GetLastError());
196
+                return;
197
+            } else {
198
+                log.info("布防成功");
199
+            }
200
+        } else {
201
+            log.info("设备已经布防,请先撤防!");
202
+        }
203
+        return;
204
+    }
205
+
206
+    /**
207
+     * 报警布防V50接口,功能和V41一致
208
+     *
209
+     * @param i
210
+     */
211
+    public static void setAlarm_V50(int i) {
212
+        if (lAlarmHandle_V50[i] < 0) {//尚未布防,需要布防
213
+            //报警布防参数设置
214
+            HCNetSDK.NET_DVR_SETUPALARM_PARAM_V50 m_strAlarmInfo = new HCNetSDK.NET_DVR_SETUPALARM_PARAM_V50();
215
+            m_strAlarmInfo.dwSize = m_strAlarmInfo.size();
216
+            m_strAlarmInfo.byLevel = 1;  //布防等级
217
+            m_strAlarmInfo.byAlarmInfoType = 1;   // 智能交通报警信息上传类型:0- 老报警信息(NET_DVR_PLATE_RESULT),1- 新报警信息(NET_ITS_PLATE_RESULT)
218
+            m_strAlarmInfo.byDeployType = 1;   //布防类型 0:客户端布防 1:实时布防
219
+            m_strAlarmInfo.write();
220
+            lAlarmHandle[i] = hCNetSDK.NET_DVR_SetupAlarmChan_V50(lUserID[i], m_strAlarmInfo, Pointer.NULL, 0);
221
+            log.info("lAlarmHandle: {}", lAlarmHandle[i]);
222
+            if (lAlarmHandle[i] == -1) {
223
+                log.error("布防失败,错误码为: {}", hCNetSDK.NET_DVR_GetLastError());
224
+                return;
225
+            } else {
226
+                log.info("布防成功");
227
+            }
228
+        } else {
229
+            log.info("设备已经布防,请先撤防!");
230
+        }
231
+        return;
232
+
233
+    }
234
+
235
+    /**
236
+     * 开启监听
237
+     *
238
+     * @param ip   监听IP
239
+     * @param port 监听端口
240
+     */
241
+    public static void StartListen(String ip, short port) {
242
+        if (fMSFCallBack == null) {
243
+            fMSFCallBack = new FMSGCallBack();
244
+        }
245
+        lListenHandle = hCNetSDK.NET_DVR_StartListen_V30(ip, port, fMSFCallBack_V31, null);
246
+        if (lListenHandle == -1) {
247
+            log.error("监听失败: {}", hCNetSDK.NET_DVR_GetLastError());
248
+            return;
249
+        } else {
250
+            log.info("监听成功");
251
+        }
252
+    }
253
+
254
+    /**
255
+     * 设备注销
256
+     *
257
+     * @param i
258
+     */
259
+    public static void Logout(int i) {
260
+        if (lAlarmHandle[i] > -1) {
261
+            if (!hCNetSDK.NET_DVR_CloseAlarmChan(lAlarmHandle[i])) {
262
+                log.info("撤防成功");
263
+            }
264
+        }
265
+        if (lListenHandle > -1) {
266
+            if (!hCNetSDK.NET_DVR_StopListen_V30(lListenHandle)) {
267
+                log.info("停止监听成功");
268
+            }
269
+        }
270
+        if (hCNetSDK.NET_DVR_Logout(lUserID[i])) {
271
+            log.info("注销成功");
272
+        }
273
+        return;
274
+    }
275
+
276
+    /**
277
+     * 动态库加载
278
+     *
279
+     * @return
280
+     */
281
+    private static boolean CreateSDKInstance() {
282
+        if (hCNetSDK == null) {
283
+            synchronized (HCNetSDK.class) {
284
+                String strDllPath = "";
285
+                try {
286
+                    if (osSelect.isWindows())
287
+                        //win系统加载库路径
288
+                        strDllPath = System.getProperty("user.dir") + "\\lib\\HCNetSDK.dll";
289
+                    else if (osSelect.isLinux())
290
+                        //Linux系统加载库路径
291
+                        strDllPath = System.getProperty("user.dir") + "/lib/libhcnetsdk.so";
292
+                    hCNetSDK = (HCNetSDK) Native.loadLibrary(strDllPath, HCNetSDK.class);
293
+                } catch (Exception ex) {
294
+                    log.error("loadLibrary: {}", strDllPath);
295
+                    log.error("Error: {}", ex.getMessage());
296
+                    return false;
297
+                }
298
+            }
299
+        }
300
+        return true;
301
+    }
302
+
303
+    @Override
304
+    public void run(ApplicationArguments args) throws Exception {
305
+        // after behind for application run,because implements ApplicationRunner
306
+        this.mainMethod();
307
+    }
308
+
309
+    // ------------------------------------------------------
310
+
311
+    /**
312
+     * @param args
313
+     */
314
+    /*public static void main(String[] args) throws InterruptedException {
315
+
316
+        if (hCNetSDK == null) {
317
+            if (!CreateSDKInstance()) {
318
+                System.out.println("Load SDK fail");
319
+                return;
320
+            }
321
+        }
322
+        //linux系统建议调用以下接口加载组件库
323
+        if (osSelect.isLinux()) {
324
+            HCNetSDK.BYTE_ARRAY ptrByteArray1 = new HCNetSDK.BYTE_ARRAY(256);
325
+            HCNetSDK.BYTE_ARRAY ptrByteArray2 = new HCNetSDK.BYTE_ARRAY(256);
326
+            //这里是库的绝对路径,请根据实际情况修改,注意改路径必须有访问权限
327
+            String strPath1 = System.getProperty("user.dir") + "/lib/libcrypto.so.1.1";
328
+            String strPath2 = System.getProperty("user.dir") + "/lib/libssl.so.1.1";
329
+
330
+            System.arraycopy(strPath1.getBytes(), 0, ptrByteArray1.byValue, 0, strPath1.length());
331
+            ptrByteArray1.write();
332
+            hCNetSDK.NET_DVR_SetSDKInitCfg(3, ptrByteArray1.getPointer());
333
+
334
+            System.arraycopy(strPath2.getBytes(), 0, ptrByteArray2.byValue, 0, strPath2.length());
335
+            ptrByteArray2.write();
336
+            hCNetSDK.NET_DVR_SetSDKInitCfg(4, ptrByteArray2.getPointer());
337
+
338
+            String strPathCom = System.getProperty("user.dir") + "/lib";
339
+            HCNetSDK.NET_DVR_LOCAL_SDK_PATH struComPath = new HCNetSDK.NET_DVR_LOCAL_SDK_PATH();
340
+            System.arraycopy(strPathCom.getBytes(), 0, struComPath.sPath, 0, strPathCom.length());
341
+            struComPath.write();
342
+            hCNetSDK.NET_DVR_SetSDKInitCfg(2, struComPath.getPointer());
343
+        }
344
+
345
+        *//**初始化*//*
346
+        hCNetSDK.NET_DVR_Init();
347
+        *//**加载日志*//*
348
+        hCNetSDK.NET_DVR_SetLogToFile(3, "../sdklog", false);
349
+        //设置报警回调函数
350
+        if (fMSFCallBack_V31 == null) {
351
+            fMSFCallBack_V31 = new FMSGCallBack_V31();
352
+            Pointer pUser = null;
353
+            if (!hCNetSDK.NET_DVR_SetDVRMessageCallBack_V31(fMSFCallBack_V31, pUser)) {
354
+                System.out.println("设置回调函数失败!");
355
+                return;
356
+            } else {
357
+                System.out.println("设置回调函数成功!");
358
+            }
359
+        }
360
+        *//** 设备上传的报警信息是COMM_VCA_ALARM(0x4993)类型,
361
+     在SDK初始化之后增加调用NET_DVR_SetSDKLocalCfg(enumType为NET_DVR_LOCAL_CFG_TYPE_GENERAL)设置通用参数NET_DVR_LOCAL_GENERAL_CFG的byAlarmJsonPictureSeparate为1,
362
+     将Json数据和图片数据分离上传,这样设置之后,报警布防回调函数里面接收到的报警信息类型为COMM_ISAPI_ALARM(0x6009),
363
+     报警信息结构体为NET_DVR_ALARM_ISAPI_INFO(与设备无关,SDK封装的数据结构),更便于解析。*//*
364
+        HCNetSDK.NET_DVR_LOCAL_GENERAL_CFG struNET_DVR_LOCAL_GENERAL_CFG = new HCNetSDK.NET_DVR_LOCAL_GENERAL_CFG();
365
+        struNET_DVR_LOCAL_GENERAL_CFG.byAlarmJsonPictureSeparate = 1;   //设置JSON透传报警数据和图片分离
366
+        struNET_DVR_LOCAL_GENERAL_CFG.write();
367
+        Pointer pStrNET_DVR_LOCAL_GENERAL_CFG = struNET_DVR_LOCAL_GENERAL_CFG.getPointer();
368
+        hCNetSDK.NET_DVR_SetSDKLocalCfg(17, pStrNET_DVR_LOCAL_GENERAL_CFG);
369
+        Alarm.Login_V40(0, "10.7.11.161", (short) 8000, "admin", "Aa870618");  //登录设备
370
+
371
+        Alarm.SetAlarm(0);//报警布防,和报警监听二选一即可
372
+
373
+        //  Alarm.StartListen("10.17.34.18",(short)8000);//报警监听,不需要登陆设备
374
+        while (true) {
375
+            //这里加入控制台输入控制,是为了保持连接状态,当输入Y表示布防结束
376
+            System.out.print("请选择是否撤出布防(Y/N):");
377
+            Scanner input = new Scanner(System.in);
378
+            String str = input.next();
379
+            if (str.equals("Y")) {
380
+                break;
381
+            }
382
+        }
383
+        Alarm.Logout(0);
384
+        //释放SDK
385
+        hCNetSDK.NET_DVR_Cleanup();
386
+        return;
387
+    }*/
388
+}

+ 498 - 0
src/main/java/com/unis/alarm/AlarmDataParse.java

@@ -0,0 +1,498 @@
1
+package com.unis.alarm;
2
+
3
+import com.sun.jna.Pointer;
4
+import lombok.extern.slf4j.Slf4j;
5
+
6
+import java.io.FileNotFoundException;
7
+import java.io.FileOutputStream;
8
+import java.io.IOException;
9
+import java.io.UnsupportedEncodingException;
10
+import java.nio.ByteBuffer;
11
+import java.text.SimpleDateFormat;
12
+import java.util.Date;
13
+
14
+/**
15
+ * @author qingsong.han
16
+ * @create 2024-08-01 9:24
17
+ */
18
+@Slf4j
19
+@SuppressWarnings("all")
20
+public class AlarmDataParse {
21
+
22
+    public static void alarmDataHandle(int lCommand, HCNetSDK.NET_DVR_ALARMER pAlarmer, Pointer pAlarmInfo, int dwBufLen, Pointer pUser) {
23
+        log.info("报警事件类型lCommand int: {}", lCommand);
24
+        log.info("报警事件类型lCommand int: {}", "0x" + lCommand);
25
+
26
+        /*String hexString = Integer.toHexString(lCommand);
27
+        log.info("报警事件类型lCommand Hex: {}", hexString);*/
28
+
29
+        String sTime;
30
+        String MonitoringSiteID;
31
+        String pic = System.getProperty("user.dir") + "/pic/";
32
+        log.info("pic: {}", pic);
33
+        //lCommand是传的报警类型
34
+        switch (lCommand) {
35
+            //行为分析信息
36
+            case HCNetSDK.COMM_ALARM_RULE:
37
+                HCNetSDK.NET_VCA_RULE_ALARM strVcaAlarm = new HCNetSDK.NET_VCA_RULE_ALARM();
38
+                strVcaAlarm.write();
39
+                Pointer pVCAInfo = strVcaAlarm.getPointer();
40
+                pVCAInfo.write(0, pAlarmInfo.getByteArray(0, strVcaAlarm.size()), 0, strVcaAlarm.size());
41
+                strVcaAlarm.read();
42
+
43
+                switch (strVcaAlarm.struRuleInfo.wEventTypeEx) {
44
+                    case 1: //穿越警戒面 (越界侦测)
45
+                        System.out.println("越界侦测报警发生");
46
+                        strVcaAlarm.struRuleInfo.uEventParam.setType(HCNetSDK.NET_VCA_TRAVERSE_PLANE.class);
47
+                        System.out.println("检测目标:" + strVcaAlarm.struRuleInfo.uEventParam.struTraversePlane.byDetectionTarget); //检测目标,0表示所有目标(表示不锁定检测目标,所有目标都将进行检测),其他取值按位表示不同的检测目标:0x01-人,0x02-车
48
+                        //图片保存
49
+                        if ((strVcaAlarm.dwPicDataLen > 0) && (strVcaAlarm.byPicTransType == 0)) {
50
+                            SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
51
+                            String newName = sf.format(new Date());
52
+                            FileOutputStream fout;
53
+                            try {
54
+                                String filename = pic + newName + "VCA_TRAVERSE_PLANE" + ".jpg";
55
+                                fout = new FileOutputStream(filename);
56
+                                //将字节写入文件
57
+                                long offset = 0;
58
+                                ByteBuffer buffers = strVcaAlarm.pImage.getByteBuffer(offset, strVcaAlarm.dwPicDataLen);
59
+                                byte[] bytes = new byte[strVcaAlarm.dwPicDataLen];
60
+                                buffers.rewind();
61
+                                buffers.get(bytes);
62
+                                fout.write(bytes);
63
+                                fout.close();
64
+                            } catch (FileNotFoundException e) {
65
+                                // TODO Auto-generated catch block
66
+                                e.printStackTrace();
67
+                            } catch (IOException e) {
68
+                                // TODO Auto-generated catch block
69
+                                e.printStackTrace();
70
+                            }
71
+                        }
72
+                        break;
73
+                    case 2: //目标进入区域
74
+                        System.out.println("目标进入区域报警发生");
75
+                        strVcaAlarm.struRuleInfo.uEventParam.setType(HCNetSDK.NET_VCA_AREA.class);
76
+                        System.out.println("检测目标:" + strVcaAlarm.struRuleInfo.uEventParam.struArea.byDetectionTarget);
77
+                        //图片保存
78
+                        if ((strVcaAlarm.dwPicDataLen > 0) && (strVcaAlarm.byPicTransType == 0)) {
79
+                            SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
80
+                            String newName = sf.format(new Date());
81
+                            FileOutputStream fout;
82
+                            try {
83
+                                String filename = "../pic/" + newName + "_TargetEnter" + ".jpg";
84
+                                fout = new FileOutputStream(filename);
85
+                                //将字节写入文件
86
+                                long offset = 0;
87
+                                ByteBuffer buffers = strVcaAlarm.pImage.getByteBuffer(offset, strVcaAlarm.dwPicDataLen);
88
+                                byte[] bytes = new byte[strVcaAlarm.dwPicDataLen];
89
+                                buffers.rewind();
90
+                                buffers.get(bytes);
91
+                                fout.write(bytes);
92
+                                fout.close();
93
+                            } catch (FileNotFoundException e) {
94
+                                // TODO Auto-generated catch block
95
+                                e.printStackTrace();
96
+                            } catch (IOException e) {
97
+                                // TODO Auto-generated catch block
98
+                                e.printStackTrace();
99
+                            }
100
+                        }
101
+                        break;
102
+                    case 3: //目标离开区域
103
+                        System.out.println("目标离开区域报警触发");
104
+                        strVcaAlarm.struRuleInfo.uEventParam.setType(HCNetSDK.NET_VCA_AREA.class);
105
+                        System.out.println("检测目标:" + strVcaAlarm.struRuleInfo.uEventParam.struArea.byDetectionTarget);
106
+                        //图片保存
107
+                        if ((strVcaAlarm.dwPicDataLen > 0) && (strVcaAlarm.byPicTransType == 0)) {
108
+                            SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
109
+                            String newName = sf.format(new Date());
110
+                            FileOutputStream fout;
111
+                            try {
112
+                                String filename = "../pic/" + newName + "_TargetLeave" + ".jpg";
113
+                                fout = new FileOutputStream(filename);
114
+                                //将字节写入文件
115
+                                long offset = 0;
116
+                                ByteBuffer buffers = strVcaAlarm.pImage.getByteBuffer(offset, strVcaAlarm.dwPicDataLen);
117
+                                byte[] bytes = new byte[strVcaAlarm.dwPicDataLen];
118
+                                buffers.rewind();
119
+                                buffers.get(bytes);
120
+                                fout.write(bytes);
121
+                                fout.close();
122
+                            } catch (FileNotFoundException e) {
123
+                                // TODO Auto-generated catch block
124
+                                e.printStackTrace();
125
+                            } catch (IOException e) {
126
+                                // TODO Auto-generated catch block
127
+                                e.printStackTrace();
128
+                            }
129
+                        }
130
+                        break;
131
+                    case 4: //周界入侵
132
+                        System.out.println("周界入侵报警发生");
133
+                        strVcaAlarm.struRuleInfo.uEventParam.setType(HCNetSDK.NET_VCA_INTRUSION.class);
134
+                        System.out.println("检测目标:" + strVcaAlarm.struRuleInfo.uEventParam.struIntrusion.byDetectionTarget);
135
+                        //图片保存
136
+                        if ((strVcaAlarm.dwPicDataLen > 0) && (strVcaAlarm.byPicTransType == 0)) {
137
+                            SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
138
+                            String newName = sf.format(new Date());
139
+                            FileOutputStream fout;
140
+                            try {
141
+                                String filename = pic + newName + "VCA_INTRUSION" + ".jpg";
142
+                                log.info("filename: {}", filename);
143
+                                fout = new FileOutputStream(filename);
144
+                                //将字节写入文件
145
+                                long offset = 0;
146
+                                ByteBuffer buffers = strVcaAlarm.pImage.getByteBuffer(offset, strVcaAlarm.dwPicDataLen);
147
+                                byte[] bytes = new byte[strVcaAlarm.dwPicDataLen];
148
+                                buffers.rewind();
149
+                                buffers.get(bytes);
150
+                                fout.write(bytes);
151
+                                fout.close();
152
+                            } catch (FileNotFoundException e) {
153
+                                // TODO Auto-generated catch block
154
+                                e.printStackTrace();
155
+                            } catch (IOException e) {
156
+                                // TODO Auto-generated catch block
157
+                                e.printStackTrace();
158
+                            }
159
+                        }
160
+                        break;
161
+                    case 15: //离岗
162
+                        System.out.println("离岗事件触发");
163
+                        strVcaAlarm.struRuleInfo.uEventParam.setType(HCNetSDK.NET_VCA_LEAVE_POSITION.class);
164
+                        System.out.println(strVcaAlarm.struRuleInfo.uEventParam.struLeavePos.byOnPosition);
165
+                        //图片保存
166
+                        if ((strVcaAlarm.dwPicDataLen > 0) && (strVcaAlarm.byPicTransType == 0)) {
167
+                            SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
168
+                            String newName = sf.format(new Date());
169
+                            FileOutputStream fout;
170
+                            try {
171
+                                String filename = "../pic/" + newName + "VCA_LEAVE_POSITION_" + ".jpg";
172
+                                fout = new FileOutputStream(filename);
173
+                                //将字节写入文件
174
+                                long offset = 0;
175
+                                ByteBuffer buffers = strVcaAlarm.pImage.getByteBuffer(offset, strVcaAlarm.dwPicDataLen);
176
+                                byte[] bytes = new byte[strVcaAlarm.dwPicDataLen];
177
+                                buffers.rewind();
178
+                                buffers.get(bytes);
179
+                                fout.write(bytes);
180
+                                fout.close();
181
+                            } catch (FileNotFoundException e) {
182
+                                // TODO Auto-generated catch block
183
+                                e.printStackTrace();
184
+                            } catch (IOException e) {
185
+                                // TODO Auto-generated catch block
186
+                                e.printStackTrace();
187
+                            }
188
+                        }
189
+                    case 20: //倒地检测
190
+                        System.out.println("倒地事件触发");
191
+                        break;
192
+                    case 44: //玩手机
193
+
194
+                        System.out.println("玩手机报警发生");
195
+                        //图片保存
196
+                        if ((strVcaAlarm.dwPicDataLen > 0) && (strVcaAlarm.byPicTransType == 0)) {
197
+                            SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
198
+                            String newName = sf.format(new Date());
199
+                            FileOutputStream fout;
200
+                            try {
201
+                                String filename = "../pic/" + newName + "PLAY_CELLPHONE_" + ".jpg";
202
+                                fout = new FileOutputStream(filename);
203
+                                //将字节写入文件
204
+                                long offset = 0;
205
+                                ByteBuffer buffers = strVcaAlarm.pImage.getByteBuffer(offset, strVcaAlarm.dwPicDataLen);
206
+                                byte[] bytes = new byte[strVcaAlarm.dwPicDataLen];
207
+                                buffers.rewind();
208
+                                buffers.get(bytes);
209
+                                fout.write(bytes);
210
+                                fout.close();
211
+                            } catch (FileNotFoundException e) {
212
+                                // TODO Auto-generated catch block
213
+                                e.printStackTrace();
214
+                            } catch (IOException e) {
215
+                                // TODO Auto-generated catch block
216
+                                e.printStackTrace();
217
+                            }
218
+                        }
219
+                        break;
220
+                    case 45: //持续检测
221
+                        System.out.println("持续检测事件触发");
222
+                    default:
223
+                        System.out.println("行为事件类型:" + strVcaAlarm.struRuleInfo.wEventTypeEx);
224
+                        break;
225
+                }
226
+                break;
227
+            case HCNetSDK.COMM_UPLOAD_FACESNAP_RESULT: //实时人脸抓拍上传
228
+                System.out.println("UPLOAD_FACESNAP_Alarm");
229
+                HCNetSDK.NET_VCA_FACESNAP_RESULT strFaceSnapInfo = new HCNetSDK.NET_VCA_FACESNAP_RESULT();
230
+                strFaceSnapInfo.write();
231
+                Pointer pFaceSnapInfo = strFaceSnapInfo.getPointer();
232
+                pFaceSnapInfo.write(0, pAlarmInfo.getByteArray(0, strFaceSnapInfo.size()), 0, strFaceSnapInfo.size());
233
+                strFaceSnapInfo.read();
234
+
235
+                //事件时间
236
+                int dwYear = (strFaceSnapInfo.dwAbsTime >> 26) + 2000;
237
+                int dwMonth = (strFaceSnapInfo.dwAbsTime >> 22) & 15;
238
+                int dwDay = (strFaceSnapInfo.dwAbsTime >> 17) & 31;
239
+                int dwHour = (strFaceSnapInfo.dwAbsTime >> 12) & 31;
240
+                int dwMinute = (strFaceSnapInfo.dwAbsTime >> 6) & 63;
241
+                int dwSecond = (strFaceSnapInfo.dwAbsTime >> 0) & 63;
242
+
243
+                String strAbsTime = "" + String.format("%04d", dwYear) +
244
+                        String.format("%02d", dwMonth) +
245
+                        String.format("%02d", dwDay) +
246
+                        String.format("%02d", dwHour) +
247
+                        String.format("%02d", dwMinute) +
248
+                        String.format("%02d", dwSecond);
249
+
250
+                //人脸属性信息
251
+                String sFaceAlarmInfo = "Abs时间:" + strAbsTime + ",年龄:" + strFaceSnapInfo.struFeature.byAge +
252
+                        ",性别:" + strFaceSnapInfo.struFeature.bySex + ",是否戴口罩:" +
253
+                        strFaceSnapInfo.struFeature.byMask + ",是否微笑:" + strFaceSnapInfo.struFeature.bySmile;
254
+                System.out.println("人脸信息:" + sFaceAlarmInfo);
255
+
256
+                //人脸测温信息
257
+                if (strFaceSnapInfo.byAddInfo == 1) {
258
+                    HCNetSDK.NET_VCA_FACESNAP_ADDINFO strAddInfo = new HCNetSDK.NET_VCA_FACESNAP_ADDINFO();
259
+                    strAddInfo.write();
260
+                    Pointer pAddInfo = strAddInfo.getPointer();
261
+                    pAddInfo.write(0, strFaceSnapInfo.pAddInfoBuffer.getByteArray(0, strAddInfo.size()), 0, strAddInfo.size());
262
+                    strAddInfo.read();
263
+
264
+                    String sTemperatureInfo = "测温是否开启:" + strAddInfo.byFaceSnapThermometryEnabled + "人脸温度:" + strAddInfo.fFaceTemperature + "温度是否异常"
265
+                            + strAddInfo.byIsAbnomalTemperature + "报警温度阈值:" + strAddInfo.fAlarmTemperature;
266
+                    System.out.println("人脸温度信息:" + sTemperatureInfo);
267
+
268
+                }
269
+
270
+                try {
271
+                    SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");//设置日期格式
272
+                    String time = df.format(new Date());// new Date()为获取当前系统时间
273
+
274
+                    //人脸图片写文件
275
+                    FileOutputStream small = new FileOutputStream("../pic/" + time + "small.jpg");
276
+                    FileOutputStream big = new FileOutputStream("../pic/" + time + "big.jpg");
277
+                    try {
278
+                        small.write(strFaceSnapInfo.pBuffer1.getByteArray(0, strFaceSnapInfo.dwFacePicLen), 0, strFaceSnapInfo.dwFacePicLen);
279
+                        small.close();
280
+                    } catch (IOException ex) {
281
+                        ex.printStackTrace();
282
+                    }
283
+                    try {
284
+                        big.write(strFaceSnapInfo.pBuffer2.getByteArray(0, strFaceSnapInfo.dwBackgroundPicLen), 0, strFaceSnapInfo.dwBackgroundPicLen);
285
+                        big.close();
286
+                    } catch (IOException ex) {
287
+                        ex.printStackTrace();
288
+                    }
289
+
290
+                } catch (FileNotFoundException ex) {
291
+                    ex.printStackTrace();
292
+                }
293
+                break;
294
+            case HCNetSDK.COMM_ALARM_V30:  //移动侦测、视频丢失、遮挡、IO信号量等报警信息(V3.0以上版本支持的设备)
295
+                HCNetSDK.NET_DVR_ALARMINFO_V30 struAlarmInfo = new HCNetSDK.NET_DVR_ALARMINFO_V30();
296
+                struAlarmInfo.write();
297
+                Pointer pAlarmInfo_V30 = struAlarmInfo.getPointer();
298
+                pAlarmInfo_V30.write(0, pAlarmInfo.getByteArray(0, struAlarmInfo.size()), 0, struAlarmInfo.size());
299
+                struAlarmInfo.read();
300
+                System.out.println("报警类型:" + struAlarmInfo.dwAlarmType);  // 3-移动侦测
301
+                break;
302
+            case HCNetSDK.COMM_ALARM_V40: //移动侦测、视频丢失、遮挡、IO信号量等报警信息,报警数据为可变长
303
+                HCNetSDK.NET_DVR_ALARMINFO_V40 struAlarmInfoV40 = new HCNetSDK.NET_DVR_ALARMINFO_V40();
304
+                struAlarmInfoV40.write();
305
+                Pointer pAlarmInfoV40 = struAlarmInfoV40.getPointer();
306
+                pAlarmInfoV40.write(0, pAlarmInfo.getByteArray(0, struAlarmInfoV40.size()), 0, struAlarmInfoV40.size());
307
+                struAlarmInfoV40.read();
308
+                System.out.println("报警类型:" + struAlarmInfoV40.struAlarmFixedHeader.dwAlarmType); //3-移动侦测
309
+                break;
310
+            case HCNetSDK.COMM_THERMOMETRY_ALARM:  //温度报警信息
311
+                HCNetSDK.NET_DVR_THERMOMETRY_ALARM struTemInfo = new HCNetSDK.NET_DVR_THERMOMETRY_ALARM();
312
+                struTemInfo.write();
313
+                Pointer pTemInfo = struTemInfo.getPointer();
314
+                pTemInfo.write(0, pAlarmInfo.getByteArray(0, struTemInfo.size()), 0, struTemInfo.size());
315
+                struTemInfo.read();
316
+                String sThermAlarmInfo = "规则ID:" + struTemInfo.byRuleID + "预置点号:" + struTemInfo.wPresetNo + "报警等级:" + struTemInfo.byAlarmLevel + "报警类型:" +
317
+                        struTemInfo.byAlarmType + "当前温度:" + struTemInfo.fCurrTemperature;
318
+                System.out.println(sThermAlarmInfo);
319
+                //可见光图片保存
320
+                if ((struTemInfo.dwPicLen > 0) && (struTemInfo.byPicTransType == 0)) {
321
+                    SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
322
+                    String newName = sf.format(new Date());
323
+                    FileOutputStream fout;
324
+
325
+                    try {
326
+                        String filename = "../pic/" + newName + "_" + struTemInfo.fCurrTemperature + ".jpg";
327
+                        fout = new FileOutputStream(filename);
328
+                        //将字节写入文件
329
+                        long offset = 0;
330
+                        ByteBuffer buffers = struTemInfo.pPicBuff.getByteBuffer(offset, struTemInfo.dwPicLen);
331
+                        byte[] bytes = new byte[struTemInfo.dwPicLen];
332
+                        buffers.rewind();
333
+                        buffers.get(bytes);
334
+                        fout.write(bytes);
335
+                        fout.close();
336
+                    } catch (FileNotFoundException e) {
337
+                        // TODO Auto-generated catch block
338
+                        e.printStackTrace();
339
+                    } catch (IOException e) {
340
+                        // TODO Auto-generated catch block
341
+                        e.printStackTrace();
342
+                    }
343
+                }
344
+
345
+                if ((struTemInfo.dwThermalPicLen > 0) && (struTemInfo.byPicTransType == 0)) {
346
+                    SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
347
+                    String newName = sf.format(new Date());
348
+                    FileOutputStream fout;
349
+
350
+                    try {
351
+                        String filename = "../pic/" + newName + "_" + "_ThermalPiC" + ".jpg";
352
+                        fout = new FileOutputStream(filename);
353
+                        //将字节写入文件
354
+                        long offset = 0;
355
+                        ByteBuffer buffers = struTemInfo.pThermalPicBuff.getByteBuffer(offset, struTemInfo.dwThermalPicLen);
356
+                        byte[] bytes = new byte[struTemInfo.dwThermalPicLen];
357
+                        buffers.rewind();
358
+                        buffers.get(bytes);
359
+                        fout.write(bytes);
360
+                        fout.close();
361
+                    } catch (FileNotFoundException e) {
362
+                        // TODO Auto-generated catch block
363
+                        e.printStackTrace();
364
+                    } catch (IOException e) {
365
+                        // TODO Auto-generated catch block
366
+                        e.printStackTrace();
367
+                    }
368
+
369
+                }
370
+                break;
371
+            case HCNetSDK.COMM_THERMOMETRY_DIFF_ALARM: //温差检测报警
372
+                HCNetSDK.NET_DVR_THERMOMETRY_DIFF_ALARM strThermDiffAlarm = new HCNetSDK.NET_DVR_THERMOMETRY_DIFF_ALARM();
373
+                strThermDiffAlarm.write();
374
+                Pointer pTemDiffInfo = strThermDiffAlarm.getPointer();
375
+                pTemDiffInfo.write(0, pAlarmInfo.getByteArray(0, strThermDiffAlarm.size()), 0, strThermDiffAlarm.size());
376
+                strThermDiffAlarm.read();
377
+                String sThremDiffInfo = "通道号:" + strThermDiffAlarm.dwChannel + ",报警规则:" + strThermDiffAlarm.byAlarmRule + ",当前温差:" + strThermDiffAlarm.fCurTemperatureDiff;
378
+                System.out.println(sThremDiffInfo);
379
+                //可见光图片保存
380
+                if ((strThermDiffAlarm.dwPicLen > 0) && (strThermDiffAlarm.byPicTransType == 0)) {
381
+                    SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
382
+                    String newName = sf.format(new Date());
383
+                    FileOutputStream fout;
384
+
385
+                    try {
386
+                        String filename = "../pic/" + newName + "_" + strThermDiffAlarm.fCurTemperatureDiff + ".jpg";
387
+                        fout = new FileOutputStream(filename);
388
+                        //将字节写入文件
389
+                        long offset = 0;
390
+                        ByteBuffer buffers = strThermDiffAlarm.pPicBuff.getByteBuffer(offset, strThermDiffAlarm.dwPicLen);
391
+                        byte[] bytes = new byte[strThermDiffAlarm.dwPicLen];
392
+                        buffers.rewind();
393
+                        buffers.get(bytes);
394
+                        fout.write(bytes);
395
+                        fout.close();
396
+                    } catch (FileNotFoundException e) {
397
+                        // TODO Auto-generated catch block
398
+                        e.printStackTrace();
399
+                    } catch (IOException e) {
400
+                        // TODO Auto-generated catch block
401
+                        e.printStackTrace();
402
+                    }
403
+                }
404
+                //热成像图片保存
405
+                if ((strThermDiffAlarm.dwThermalPicLen > 0) && (strThermDiffAlarm.byPicTransType == 0)) {
406
+                    SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
407
+                    String newName = sf.format(new Date());
408
+                    FileOutputStream fout;
409
+
410
+                    try {
411
+                        String filename = "../pic/" + newName + "_" + "_ThermalDiffPiC" + ".jpg";
412
+                        fout = new FileOutputStream(filename);
413
+                        //将字节写入文件
414
+                        long offset = 0;
415
+                        ByteBuffer buffers = strThermDiffAlarm.pThermalPicBuff.getByteBuffer(offset, strThermDiffAlarm.dwThermalPicLen);
416
+                        byte[] bytes = new byte[strThermDiffAlarm.dwThermalPicLen];
417
+                        buffers.rewind();
418
+                        buffers.get(bytes);
419
+                        fout.write(bytes);
420
+                        fout.close();
421
+                    } catch (FileNotFoundException e) {
422
+                        // TODO Auto-generated catch block
423
+                        e.printStackTrace();
424
+                    } catch (IOException e) {
425
+                        // TODO Auto-generated catch block
426
+                        e.printStackTrace();
427
+                    }
428
+
429
+                }
430
+                break;
431
+
432
+            case HCNetSDK.COMM_FIREDETECTION_ALARM://烟火检测
433
+                HCNetSDK.NET_DVR_FIREDETECTION_ALARM struFireDecAlarm = new HCNetSDK.NET_DVR_FIREDETECTION_ALARM();
434
+                struFireDecAlarm.write();
435
+                Pointer pFireDecAlarm = struFireDecAlarm.getPointer();
436
+                pFireDecAlarm.write(0, pAlarmInfo.getByteArray(0, struFireDecAlarm.size()), 0, struFireDecAlarm.size());
437
+                struFireDecAlarm.read();
438
+                String sFireDecAlarmInfo = "绝对时间:" + struFireDecAlarm.dwAbsTime + ",报警子类型:" + struFireDecAlarm.byAlarmSubType + ",火点最高温度 :" +
439
+                        struFireDecAlarm.wFireMaxTemperature + ",火点目标距离:" + struFireDecAlarm.wTargetDistance;
440
+                System.out.println(sFireDecAlarmInfo);
441
+                //可见光图片保存
442
+                if ((struFireDecAlarm.dwVisiblePicLen > 0) && (struFireDecAlarm.byPicTransType == 0)) {
443
+                    SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
444
+                    String newName = sf.format(new Date());
445
+                    FileOutputStream fout;
446
+
447
+                    try {
448
+                        String filename = "../pic/" + newName + "_FireDecAlarm" + ".jpg";
449
+                        fout = new FileOutputStream(filename);
450
+                        //将字节写入文件
451
+                        long offset = 0;
452
+                        ByteBuffer buffers = struFireDecAlarm.pVisiblePicBuf.getByteBuffer(offset, struFireDecAlarm.dwVisiblePicLen);
453
+                        byte[] bytes = new byte[struFireDecAlarm.dwVisiblePicLen];
454
+                        buffers.rewind();
455
+                        buffers.get(bytes);
456
+                        fout.write(bytes);
457
+                        fout.close();
458
+                    } catch (FileNotFoundException e) {
459
+                        // TODO Auto-generated catch block
460
+                        e.printStackTrace();
461
+                    } catch (IOException e) {
462
+                        // TODO Auto-generated catch block
463
+                        e.printStackTrace();
464
+                    }
465
+                }
466
+                //热成像图片保存
467
+                if ((struFireDecAlarm.dwPicDataLen > 0) && (struFireDecAlarm.byPicTransType == 0)) {
468
+                    SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
469
+                    String newName = sf.format(new Date());
470
+                    FileOutputStream fout;
471
+
472
+                    try {
473
+                        String filename = "../pic/" + newName + "_" + "_ThermalFireAlarm" + ".jpg";
474
+                        fout = new FileOutputStream(filename);
475
+                        //将字节写入文件
476
+                        long offset = 0;
477
+                        ByteBuffer buffers = struFireDecAlarm.pBuffer.getByteBuffer(offset, struFireDecAlarm.dwPicDataLen);
478
+                        byte[] bytes = new byte[struFireDecAlarm.dwPicDataLen];
479
+                        buffers.rewind();
480
+                        buffers.get(bytes);
481
+                        fout.write(bytes);
482
+                        fout.close();
483
+                    } catch (FileNotFoundException e) {
484
+                        // TODO Auto-generated catch block
485
+                        e.printStackTrace();
486
+                    } catch (IOException e) {
487
+                        // TODO Auto-generated catch block
488
+                        e.printStackTrace();
489
+                    }
490
+
491
+                }
492
+                break;
493
+            default:
494
+                log.info("default报警类型: {}", Integer.toHexString(lCommand));
495
+                break;
496
+        }
497
+    }
498
+}

+ 24 - 0
src/main/java/com/unis/alarm/CommonUtil.java

@@ -0,0 +1,24 @@
1
+
2
+
3
+package com.unis.alarm;
4
+
5
+/**
6
+ * @author
7
+ * @create 2022-03-22-11:13
8
+ */
9
+public class CommonUtil {
10
+
11
+    //SDK时间解析
12
+    public static String parseTime(int time)
13
+    {
14
+        int year=(time>>26)+2000;
15
+        int month=(time>>22)&15;
16
+        int day=(time>>17)&31;
17
+        int hour=(time>>12)&31;
18
+        int min=(time>>6)&63;
19
+        int second=(time>>0)&63;
20
+        String sTime=year+"-"+month+"-"+day+"-"+hour+":"+min+":"+second;
21
+//        System.out.println(sTime);
22
+        return sTime;
23
+    }
24
+}

+ 16 - 0
src/main/java/com/unis/alarm/FMSGCallBack.java

@@ -0,0 +1,16 @@
1
+package com.unis.alarm;
2
+
3
+import com.sun.jna.Pointer;
4
+
5
+
6
+/**
7
+ * @author jiangxin
8
+ * @create 2022-08-15-17:26
9
+ */
10
+public class FMSGCallBack implements HCNetSDK.FMSGCallBack {
11
+    //报警信息回调函数
12
+    public void invoke(int lCommand, HCNetSDK.NET_DVR_ALARMER pAlarmer, Pointer pAlarmInfo, int dwBufLen, Pointer pUser) {
13
+        AlarmDataParse.alarmDataHandle(lCommand, pAlarmer, pAlarmInfo, dwBufLen, pUser);
14
+        return;
15
+    }
16
+}

+ 20 - 0
src/main/java/com/unis/alarm/FMSGCallBack_V31.java

@@ -0,0 +1,20 @@
1
+
2
+package com.unis.alarm;
3
+
4
+import com.sun.jna.Pointer;
5
+
6
+
7
+public class FMSGCallBack_V31 implements HCNetSDK.FMSGCallBack_V31 {
8
+    //报警信息回调函数
9
+    public boolean invoke(int lCommand, HCNetSDK.NET_DVR_ALARMER pAlarmer, Pointer pAlarmInfo, int dwBufLen, Pointer pUser) {
10
+        AlarmDataParse.alarmDataHandle(lCommand, pAlarmer, pAlarmInfo, dwBufLen, pUser);
11
+        return true;
12
+    }
13
+}
14
+
15
+
16
+
17
+
18
+
19
+
20
+

Файловите разлики са ограничени, защото са твърде много
+ 10677 - 0
src/main/java/com/unis/alarm/HCNetSDK.java


Файловите разлики са ограничени, защото са твърде много
+ 769 - 731
src/main/java/com/unis/common/HCNetSDK.java


+ 1 - 1
src/main/java/com/unis/common/NetDVRAlarmerConvert.java

@@ -24,7 +24,7 @@ public class NetDVRAlarmerConvert {
24 24
     private Byte byUserIDValid;
25 25
     private Byte byVersionValid;
26 26
     private Byte dwDeviceVersion;
27
-    private String lUserID;
27
+    private Integer lUserID;
28 28
     private Object pointer;
29 29
     private String sDeviceIP;
30 30
     private String sDeviceName;

+ 4 - 0
src/main/java/com/unis/config/AddressModel.java

@@ -29,4 +29,8 @@ public class AddressModel {
29 29
     @Value("${exceptionAlarm.password}")
30 30
     private String password;
31 31
 
32
+    // 设备登录密码
33
+    @Value("${exceptionAlarm.port}")
34
+    private short port;
35
+
32 36
 }

+ 9 - 3
src/main/java/com/unis/face/FMSGCallBack_V31.java

@@ -7,6 +7,7 @@ import com.unis.common.HCNetSDK;
7 7
 import com.unissoft.pushMsg.AlarmDSServiceImpl;*/
8 8
 import com.unis.common.NetDVRAlarmerConvert;
9 9
 import com.unis.utils.BinaryConversionUtil;
10
+import com.unis.video.VideoMok;
10 11
 import lombok.extern.slf4j.Slf4j;
11 12
 import org.springframework.beans.BeanUtils;
12 13
 
@@ -23,6 +24,8 @@ import java.util.Date;
23 24
 public class FMSGCallBack_V31 implements HCNetSDK.FMSGCallBack_V31 {
24 25
     // this class call jna native callback,so is not spring manage class
25 26
     /*private AlarmDSService alarmDSService = new AlarmDSServiceImpl();*/
27
+    //相机一般只有一个通道号,热成像相机有2个通道号,通道号为1或1,2
28
+    static int iChannelNo = 1;
26 29
 
27 30
     //报警信息回调函数
28 31
     public boolean invoke(int lCommand, HCNetSDK.NET_DVR_ALARMER pAlarmer, Pointer pAlarmInfo, int dwBufLen, Pointer pUser) {
@@ -59,6 +62,9 @@ public class FMSGCallBack_V31 implements HCNetSDK.FMSGCallBack_V31 {
59 62
         convert.setSSocketIP(new String(pAlarmer.getSSocketIP()));
60 63
         log.info("convert: {}", convert);
61 64
 
65
+        // 抓图
66
+        VideoMok.RealPlay(convert.getLUserID(), iChannelNo);
67
+        VideoMok.getPicbyPlayCtrl();
62 68
 
63 69
         /*String hexString = Integer.toHexString(lCommand);
64 70
         log.info("报警类型 hexString {}", hexString);*/
@@ -69,7 +75,7 @@ public class FMSGCallBack_V31 implements HCNetSDK.FMSGCallBack_V31 {
69 75
                 Pointer ruleAlarmPointer = ruleAlarm.getPointer();
70 76
                 ruleAlarmPointer.write(0, pAlarmInfo.getByteArray(0, ruleAlarm.size()), 0, ruleAlarm.size());
71 77
                 ruleAlarm.read();
72
-                log.info("alarm type in the NET_VCA_RULE_ALARM ---------->: {}", JSON.toJSONString(ruleAlarm));
78
+                log.info("Alarm type in the NET_VCA_RULE_ALARM ---------->: {}", JSON.toJSONString(ruleAlarm));
73 79
 //                alarmDSService.pushLCommand(lCommand);
74 80
                 break;
75 81
             case HCNetSDK.COMM_SNAP_MATCH_ALARM:
@@ -199,8 +205,8 @@ public class FMSGCallBack_V31 implements HCNetSDK.FMSGCallBack_V31 {
199 205
                 break;
200 206
             default:
201 207
                 // TODO 单报警设备 目前不需要 sAlarmType alarmNow
202
-                log.info("alarm type in the FMSGCallBack_V31 ->int: {}", lCommand);
203
-                log.info("alarm type in the FMSGCallBack_V31 ->HEX: {}", BinaryConversionUtil.toHex(lCommand));
208
+                log.info("Alarm type in the FMSGCallBack_V31 ->int: {}", lCommand);
209
+                log.info("Alarm type in the FMSGCallBack_V31 ->HEX: {}", BinaryConversionUtil.toHex(lCommand));
204 210
 //                alarmDSService.pushLCommand(lCommand);
205 211
                 break;
206 212
         }

+ 2 - 1
src/main/java/com/unis/face/FaceMain.java

@@ -21,7 +21,8 @@ import java.io.InputStreamReader;
21 21
  * @create 2024-07-31 9:29
22 22
  */
23 23
 @Slf4j
24
-@Component
24
+// 启动加载注解
25
+//@Component
25 26
 @Order(1)
26 27
 public class FaceMain implements ApplicationRunner {
27 28
 

+ 213 - 0
src/main/java/com/unis/video/Clinet.java

@@ -0,0 +1,213 @@
1
+package com.unis.video;
2
+
3
+import com.sun.jna.Native;
4
+import com.sun.jna.Pointer;
5
+import com.unis.common.HCNetSDK;
6
+import com.unis.common.osSelect;
7
+
8
+import java.util.Timer;
9
+
10
+/**
11
+ * @author qingsong.han
12
+ * @description:
13
+ * @create 2024-08-01 10:35
14
+ */
15
+public class Clinet {
16
+    int iErr = 0;
17
+    static HCNetSDK hCNetSDK = null;
18
+    static PlayCtrl playControl = null;
19
+    static int lUserID = 0;//用户句柄
20
+    static int lAlarmHandle = -1;//报警布防句柄
21
+    static int lListenHandle = -1;//报警监听句柄
22
+
23
+    static boolean bSaveHandle = false;
24
+    Timer Playbacktimer;//回放用定时器
25
+
26
+    static FExceptionCallBack_Imp fExceptionCallBack;
27
+    static int FlowHandle;
28
+
29
+    static class FExceptionCallBack_Imp implements HCNetSDK.FExceptionCallBack {
30
+        public void invoke(int dwType, int lUserID, int lHandle, Pointer pUser) {
31
+            System.out.println("异常事件类型:" + dwType);
32
+            return;
33
+        }
34
+    }
35
+
36
+    public static void main(String[] args) throws InterruptedException {
37
+
38
+        if (hCNetSDK == null && playControl == null) {
39
+            if (!CreateSDKInstance()) {
40
+                System.out.println("Load SDK fail");
41
+                return;
42
+            }
43
+            if (!CreatePlayInstance()) {
44
+                System.out.println("Load PlayCtrl fail");
45
+                return;
46
+            }
47
+        }
48
+        //linux系统建议调用以下接口加载组件库
49
+        if (osSelect.isLinux()) {
50
+            HCNetSDK.BYTE_ARRAY ptrByteArray1 = new HCNetSDK.BYTE_ARRAY(256);
51
+            HCNetSDK.BYTE_ARRAY ptrByteArray2 = new HCNetSDK.BYTE_ARRAY(256);
52
+            //这里是库的绝对路径,请根据实际情况修改,注意改路径必须有访问权限
53
+            /*String strPath1 = "/home/hik/LinuxSDK/libcrypto.so.1.1";
54
+            String strPath2 = "/home/hik/LinuxSDK/libssl.so.1.1";*/
55
+            String strPath1 = System.getProperty("user.dir") + "\\lib\\libcrypto.so.1.1";
56
+            String strPath2 = System.getProperty("user.dir") + "\\lib\\libssl.so.1.1";
57
+
58
+            System.arraycopy(strPath1.getBytes(), 0, ptrByteArray1.byValue, 0, strPath1.length());
59
+            ptrByteArray1.write();
60
+            hCNetSDK.NET_DVR_SetSDKInitCfg(3, ptrByteArray1.getPointer());
61
+
62
+            System.arraycopy(strPath2.getBytes(), 0, ptrByteArray2.byValue, 0, strPath2.length());
63
+            ptrByteArray2.write();
64
+            hCNetSDK.NET_DVR_SetSDKInitCfg(4, ptrByteArray2.getPointer());
65
+
66
+            String strPathCom = System.getProperty("user.dir") + "\\lib\\";
67
+            HCNetSDK.NET_DVR_LOCAL_SDK_PATH struComPath = new HCNetSDK.NET_DVR_LOCAL_SDK_PATH();
68
+            System.arraycopy(strPathCom.getBytes(), 0, struComPath.sPath, 0, strPathCom.length());
69
+            struComPath.write();
70
+            hCNetSDK.NET_DVR_SetSDKInitCfg(2, struComPath.getPointer());
71
+        }
72
+
73
+        //SDK初始化,一个程序只需要调用一次
74
+        boolean initSuc = hCNetSDK.NET_DVR_Init();
75
+
76
+        if (initSuc != true) {
77
+            System.out.println("初始化失败");
78
+        }
79
+
80
+        //异常消息回调
81
+        if (fExceptionCallBack == null) {
82
+            fExceptionCallBack = new FExceptionCallBack_Imp();
83
+        }
84
+
85
+        Pointer pUser = null;
86
+        if (!hCNetSDK.NET_DVR_SetExceptionCallBack_V30(0, 0, fExceptionCallBack, pUser)) {
87
+            return;
88
+        }
89
+        System.out.println("设置异常消息回调成功");
90
+
91
+        //启动SDK写日志
92
+        hCNetSDK.NET_DVR_SetLogToFile(3, "..\\sdkLog\\", false);
93
+
94
+        //登录设备,每一台设备分别登录; 登录句柄是唯一的,可以区分设备
95
+        HCNetSDK.NET_DVR_USER_LOGIN_INFO m_strLoginInfo = new HCNetSDK.NET_DVR_USER_LOGIN_INFO();//设备登录信息
96
+        HCNetSDK.NET_DVR_DEVICEINFO_V40 m_strDeviceInfo = new HCNetSDK.NET_DVR_DEVICEINFO_V40();//设备信息
97
+
98
+        String m_sDeviceIP = "10.7.11.161";//设备ip地址
99
+        m_strLoginInfo.sDeviceAddress = new byte[HCNetSDK.NET_DVR_DEV_ADDRESS_MAX_LEN];
100
+        System.arraycopy(m_sDeviceIP.getBytes(), 0, m_strLoginInfo.sDeviceAddress, 0, m_sDeviceIP.length());
101
+
102
+        String m_sUsername = "admin";//设备用户名
103
+        m_strLoginInfo.sUserName = new byte[HCNetSDK.NET_DVR_LOGIN_USERNAME_MAX_LEN];
104
+        System.arraycopy(m_sUsername.getBytes(), 0, m_strLoginInfo.sUserName, 0, m_sUsername.length());
105
+
106
+        String m_sPassword = "Aa870618";//设备密码
107
+        m_strLoginInfo.sPassword = new byte[HCNetSDK.NET_DVR_LOGIN_PASSWD_MAX_LEN];
108
+        System.arraycopy(m_sPassword.getBytes(), 0, m_strLoginInfo.sPassword, 0, m_sPassword.length());
109
+
110
+        m_strLoginInfo.wPort = 8000; //SDK端口
111
+        m_strLoginInfo.bUseAsynLogin = false; //是否异步登录:0- 否,1- 是
112
+        m_strLoginInfo.write();
113
+
114
+        lUserID = hCNetSDK.NET_DVR_Login_V40(m_strLoginInfo, m_strDeviceInfo);
115
+        if (lUserID == -1) {
116
+            System.out.println("登录失败,错误码为" + hCNetSDK.NET_DVR_GetLastError());
117
+        } else {
118
+            System.out.println(m_sDeviceIP + ":设备登录成功! " + "设备序列号:" + new String(m_strDeviceInfo.struDeviceV30.sSerialNumber).trim());
119
+            m_strDeviceInfo.read();
120
+        }
121
+        //相机一般只有一个通道号,热成像相机有2个通道号,通道号为1或1,2
122
+        int lDChannel = 1;
123
+        //byStartDChan为IP通道起始通道号, 预览回放NVR的IP通道时需要根据起始通道号进行取值
124
+        if ((int) m_strDeviceInfo.struDeviceV30.byStartDChan == 1 && (int) m_strDeviceInfo.struDeviceV30.byStartDChan == 33) {
125
+            //byStartDChan为IP通道起始通道号, 预览回放NVR的IP通道时需要根据起始通道号进行取值,NVR起始通道号一般是33或者1开始
126
+            lDChannel = (int) m_strDeviceInfo.struDeviceV30.byStartDChan;
127
+        }
128
+        System.out.println("预览通道号: " + lDChannel);
129
+
130
+        //注释掉的代码也可以参考,去掉注释可以运行
131
+        //VideoDemo.getIPChannelInfo(lUserID); //获取IP通道
132
+
133
+//        VideoDemo.RealPlay(lUserID,lDChannel);
134
+
135
+        //按时间回放和下载
136
+        new VideoMok().PlayBackBytime(lUserID);
137
+//        new VideoDemo().DowmloadRecordByTime(lUserID); //按时间下载录像
138
+        //按时间回放和下载录像,需要等待回放和下载完成后调用注销和释放接口
139
+/*        while (true)
140
+        {
141
+
142
+        }*/
143
+
144
+        //按录像文件回放和下载
145
+//        VideoDemo.DownloadRecordByFile(lUserID, 1);//录像文件查找下载
146
+//        VideoDemo.playBackByfile(lUserID);
147
+        Thread.sleep(3000);
148
+
149
+        //退出程序时调用,每一台设备分别注销
150
+        if (hCNetSDK.NET_DVR_Logout(lUserID)) {
151
+            System.out.println("注销成功");
152
+        }
153
+
154
+        //SDK反初始化,释放资源,只需要退出时调用一次
155
+        hCNetSDK.NET_DVR_Cleanup();
156
+        return;
157
+
158
+    }
159
+
160
+    /**
161
+     * 动态库加载
162
+     *
163
+     * @return
164
+     */
165
+    private static boolean CreateSDKInstance() {
166
+        if (hCNetSDK == null) {
167
+            synchronized (HCNetSDK.class) {
168
+                String strDllPath = "";
169
+                try {
170
+                    if (osSelect.isWindows())
171
+                        //win系统加载库路径
172
+                        strDllPath = System.getProperty("user.dir") + "\\lib\\HCNetSDK.dll";
173
+
174
+                    else if (osSelect.isLinux())
175
+                        //Linux系统加载库路径
176
+                        strDllPath = "/home/hik/LinuxSDK/libhcnetsdk.so";
177
+                    hCNetSDK = (HCNetSDK) Native.loadLibrary(strDllPath, HCNetSDK.class);
178
+                } catch (Exception ex) {
179
+                    System.out.println("loadLibrary: " + strDllPath + " Error: " + ex.getMessage());
180
+                    return false;
181
+                }
182
+            }
183
+        }
184
+        return true;
185
+    }
186
+
187
+    /**
188
+     * 播放库加载
189
+     *
190
+     * @return
191
+     */
192
+    private static boolean CreatePlayInstance() {
193
+        if (playControl == null) {
194
+            synchronized (PlayCtrl.class) {
195
+                String strPlayPath = "";
196
+                try {
197
+                    if (osSelect.isWindows())
198
+                        //win系统加载库路径
199
+                        strPlayPath = System.getProperty("user.dir") + "\\lib\\PlayCtrl.dll";
200
+                    else if (osSelect.isLinux())
201
+                        //Linux系统加载库路径
202
+                        strPlayPath = "/home/hik/LinuxSDK/libPlayCtrl.so";
203
+                    playControl = (PlayCtrl) Native.loadLibrary(strPlayPath, PlayCtrl.class);
204
+
205
+                } catch (Exception ex) {
206
+                    System.out.println("loadLibrary: " + strPlayPath + " Error: " + ex.getMessage());
207
+                    return false;
208
+                }
209
+            }
210
+        }
211
+        return true;
212
+    }
213
+}

+ 59 - 0
src/main/java/com/unis/video/PlayCtrl.java

@@ -0,0 +1,59 @@
1
+package com.unis.video;
2
+
3
+import com.sun.jna.Callback;
4
+import com.sun.jna.Library;
5
+import com.sun.jna.Pointer;
6
+import com.sun.jna.Structure;
7
+import com.sun.jna.examples.win32.W32API;
8
+import com.sun.jna.ptr.ByteByReference;
9
+import com.sun.jna.ptr.IntByReference;
10
+
11
+/**
12
+ * @author qingsong.han
13
+ * @description:
14
+ * @create 2024-08-01 10:44
15
+ */
16
+//播放库函数声明,PlayCtrl.dll
17
+public interface PlayCtrl extends Library {
18
+
19
+    public static final int STREAME_REALTIME = 0;
20
+    public static final int STREAME_FILE = 1;
21
+
22
+    boolean PlayM4_GetPort(IntByReference nPort);
23
+
24
+    boolean PlayM4_OpenStream(int nPort, ByteByReference pFileHeadBuf, int nSize, int nBufPoolSize);
25
+
26
+    boolean PlayM4_InputData(int nPort, ByteByReference pBuf, int nSize);
27
+
28
+    boolean PlayM4_CloseStream(int nPort);
29
+
30
+    boolean PlayM4_SetStreamOpenMode(int nPort, int nMode);
31
+
32
+    boolean PlayM4_Play(int nPort, W32API.HWND hWnd);
33
+
34
+    boolean PlayM4_Stop(int nPort);
35
+
36
+    boolean PlayM4_SetSecretKey(int nPort, int lKeyType, String pSecretKey, int lKeyLen);
37
+
38
+    boolean PlayM4_GetPictureSize(int nPort, IntByReference pWidth, IntByReference pHeight);
39
+
40
+    boolean PlayM4_GetJPEG(int nPort, Pointer pBitmap, int nBufSize, IntByReference pBmpSize);
41
+
42
+    int PlayM4_GetLastError(int nPort);
43
+
44
+    boolean PlayM4_SetDecCallBackExMend(int nPort, DecCallBack decCBFun, Pointer pDest, int nDestSize, int nUser);
45
+
46
+    public static interface DecCallBack extends Callback {
47
+        void invoke(int nPort, Pointer pBuf, int nSize, FRAME_INFO pFrameInfo, int nReserved1, int nReserved2);
48
+    }
49
+
50
+    public class FRAME_INFO extends Structure {
51
+        public int nWidth;                   /* 画面宽,单位像素。如果是音频数据,则为音频声道数 */
52
+        public int nHeight;                     /* 画面高,单位像素。如果是音频数据,则为样位率 */
53
+        public int nStamp;                           /* 时标信息,单位毫秒 */
54
+        public int nType;                            /* 数据类型,T_AUDIO16, T_RGB32, T_YV12 */
55
+        public int nFrameRate;                /* 编码时产生的图像帧率,如果是音频数据则为采样率 */
56
+        public int dwFrameNum;                      /* 帧号 */
57
+    }
58
+
59
+}

+ 716 - 0
src/main/java/com/unis/video/VideoMok.java

@@ -0,0 +1,716 @@
1
+package com.unis.video;
2
+
3
+import com.sun.jna.Pointer;
4
+import com.sun.jna.ptr.ByteByReference;
5
+import com.sun.jna.ptr.IntByReference;
6
+import com.unis.common.HCNetSDK;
7
+
8
+import java.io.*;
9
+import java.nio.ByteBuffer;
10
+import java.text.SimpleDateFormat;
11
+import java.util.Date;
12
+import java.util.Timer;
13
+
14
+import static com.unis.video.Clinet.hCNetSDK;
15
+import static com.unis.video.Clinet.playControl;
16
+
17
+/**
18
+ * @author qingsong.han
19
+ * @description: 视频取流预览,下载,抓图mok
20
+ * @create 2024-08-01 10:30
21
+ */
22
+public class VideoMok {
23
+    Timer Downloadtimer;//下载用定时器
24
+    Timer Playbacktimer;//回放用定时器
25
+    static FRealDataCallBack fRealDataCallBack;//预览回调函数实现
26
+    static fPlayEScallback fPlayescallback; //裸码流回调函数
27
+    static playDataCallBack playBackCallBack; //回放码流回调
28
+    static int lPlay = -1;  //预览句柄
29
+    int m_lLoadHandle;
30
+    int iPlayBack; //回放句柄
31
+    static File file;
32
+    static FileOutputStream outputStream;
33
+    static IntByReference m_lPort = new IntByReference(-1);
34
+    static String resultFileName = "..\\Download" + new String("returnFile" + ".h264");
35
+    static FileOutputStream fileOutputStream = null;
36
+    static int fileLenth = 0;
37
+
38
+    public static void RealPlay(int userID, int iChannelNo) {
39
+        if (userID == -1) {
40
+            System.out.println("请先注册");
41
+            return;
42
+        }
43
+        HCNetSDK.NET_DVR_PREVIEWINFO strClientInfo = new HCNetSDK.NET_DVR_PREVIEWINFO();
44
+        strClientInfo.read();
45
+        strClientInfo.hPlayWnd = 0;  //窗口句柄,从回调取流不显示一般设置为空
46
+        strClientInfo.lChannel = iChannelNo;  //通道号
47
+        strClientInfo.dwStreamType = 0; //0-主码流,1-子码流,2-三码流,3-虚拟码流,以此类推
48
+        strClientInfo.dwLinkMode = 0; //连接方式:0- TCP方式,1- UDP方式,2- 多播方式,3- RTP方式,4- RTP/RTSP,5- RTP/HTTP,6- HRUDP(可靠传输) ,7- RTSP/HTTPS,8- NPQ
49
+        strClientInfo.bBlocked = 1;
50
+        strClientInfo.write();
51
+
52
+        //回调函数定义必须是全局的
53
+        if (fRealDataCallBack == null) {
54
+            fRealDataCallBack = new FRealDataCallBack();
55
+        }
56
+
57
+        //开启预览
58
+        lPlay = hCNetSDK.NET_DVR_RealPlay_V40(userID, strClientInfo, fRealDataCallBack, null);
59
+        if (lPlay == -1) {
60
+            int iErr = hCNetSDK.NET_DVR_GetLastError();
61
+            System.out.println("取流失败" + iErr);
62
+            return;
63
+        }
64
+        System.out.println("取流成功");
65
+
66
+        //设置裸码流回调函数
67
+//        if (fPlayescallback==null)
68
+//        {
69
+//            fPlayescallback=new fPlayEScallback();
70
+//        }
71
+//        boolean setcallback=hCNetSDK.NET_DVR_SetESRealPlayCallBack(lPlay,fPlayescallback,null);
72
+//        if (setcallback==false)
73
+//        {
74
+//            System.out.println("设置裸码流回调失败,错误码:"+hCNetSDK.NET_DVR_GetLastError());
75
+//        }
76
+
77
+//        try {
78
+//            Thread.sleep(3000);
79
+//        } catch (InterruptedException e) {
80
+//            e.printStackTrace();
81
+//        }
82
+
83
+        //取流解码过程中播放库从解码码流中抓图
84
+//        getPicbyPlayCtrl();
85
+
86
+        /**
87
+         * 预览一段时间;如果要一直取流预览,需要保证程序一直运行
88
+         */
89
+        try {
90
+            Thread.sleep(30000);
91
+        } catch (InterruptedException e) {
92
+            // TODO Auto-generated catch block
93
+            e.printStackTrace();
94
+        }
95
+
96
+        if (lPlay >= 0) {
97
+            if (hCNetSDK.NET_DVR_StopRealPlay(lPlay)) {
98
+                System.out.println("停止预览成功");
99
+                return;
100
+            }
101
+        }
102
+    }
103
+
104
+    //播放库抓图
105
+    public static void getPicbyPlayCtrl() {
106
+
107
+        IntByReference pWidth = new IntByReference(0);
108
+        IntByReference pHieght = new IntByReference(0);
109
+        boolean bFlag = playControl.PlayM4_GetPictureSize(m_lPort.getValue(), pWidth, pHieght);
110
+        if (!bFlag) {
111
+            System.out.println("获取失败:" + playControl.PlayM4_GetLastError(m_lPort.getValue()));
112
+        }
113
+        System.out.println(pWidth.getValue());
114
+        System.out.println(pHieght.getValue());
115
+        IntByReference RealPicSize = new IntByReference(0);
116
+        int picsize = pWidth.getValue() * pHieght.getValue() * 5;
117
+        HCNetSDK.BYTE_ARRAY picByte = new HCNetSDK.BYTE_ARRAY(picsize);
118
+        picByte.write();
119
+        Pointer pByte = picByte.getPointer();
120
+        boolean b_GetPic = playControl.PlayM4_GetJPEG(m_lPort.getValue(), pByte, picsize, RealPicSize);
121
+        if (!b_GetPic) {
122
+            System.out.println("抓图失败:" + playControl.PlayM4_GetLastError(m_lPort.getValue()));
123
+        }
124
+        picByte.read();
125
+        SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
126
+        String newName = sf.format(new Date());
127
+        FileOutputStream fout = null;
128
+        try {
129
+
130
+            fout = new FileOutputStream(System.getProperty("user.dir") + "//pic//" + newName + ".jpg");
131
+            //将字节写入文件
132
+            long offset = 0;
133
+            ByteBuffer buffers = pByte.getByteBuffer(offset, RealPicSize.getValue());
134
+            byte[] bytes = new byte[RealPicSize.getValue()];
135
+            buffers.rewind();
136
+            buffers.get(bytes);
137
+            fout.write(bytes);
138
+            fout.close();
139
+        } catch (FileNotFoundException e) {
140
+            // TODO Auto-generated catch block
141
+            e.printStackTrace();
142
+        } catch (IOException e) {
143
+            // TODO Auto-generated catch block
144
+            e.printStackTrace();
145
+        }
146
+        System.out.println("抓图成功!");
147
+
148
+    }
149
+
150
+
151
+    /**
152
+     * 按时间回放获取码流数据
153
+     *
154
+     * @param userID
155
+     */
156
+
157
+    public void PlayBackBytime(int userID) {
158
+        file = new File(System.getProperty("user.dir") + "\\Download\\Videodatabytime.mp4");  //保存回调函数的音频数据
159
+
160
+        if (!file.exists()) {
161
+            try {
162
+                file.createNewFile();
163
+            } catch (Exception e) {
164
+                e.printStackTrace();
165
+            }
166
+        }
167
+        try {
168
+            outputStream = new FileOutputStream(file);
169
+        } catch (FileNotFoundException e) {
170
+            // TODO Auto-generated catch block
171
+            e.printStackTrace();
172
+        }
173
+        HCNetSDK.NET_DVR_VOD_PARA net_dvr_vod_para = new HCNetSDK.NET_DVR_VOD_PARA();
174
+        net_dvr_vod_para.dwSize = net_dvr_vod_para.size();
175
+        net_dvr_vod_para.struIDInfo.dwChannel = 1; //通道号
176
+        net_dvr_vod_para.struBeginTime.dwYear = 2024;
177
+        net_dvr_vod_para.struBeginTime.dwMonth = 8;
178
+        net_dvr_vod_para.struBeginTime.dwDay = 1;
179
+        net_dvr_vod_para.struBeginTime.dwHour = 14;
180
+        net_dvr_vod_para.struBeginTime.dwMinute = 00;
181
+        net_dvr_vod_para.struBeginTime.dwSecond = 00;
182
+        //停止时间
183
+        net_dvr_vod_para.struEndTime.dwYear = 2024;
184
+        net_dvr_vod_para.struEndTime.dwMonth = 8;
185
+        net_dvr_vod_para.struEndTime.dwDay = 1;
186
+        net_dvr_vod_para.struEndTime.dwHour = 14;
187
+        net_dvr_vod_para.struEndTime.dwMinute = 05;
188
+        net_dvr_vod_para.struEndTime.dwSecond = 00;
189
+        net_dvr_vod_para.hWnd = null; // 回放的窗口句柄,若置为空,SDK仍能收到码流数据,但不解码显示
190
+        net_dvr_vod_para.write();
191
+
192
+        int iPlayBack = hCNetSDK.NET_DVR_PlayBackByTime_V40(userID, net_dvr_vod_para);
193
+        if (iPlayBack <= -1) {
194
+            System.out.println("按时间回放失败,错误码为" + hCNetSDK.NET_DVR_GetLastError());
195
+            return;
196
+        }
197
+
198
+        //开启取流
199
+        boolean bCrtl = hCNetSDK.NET_DVR_PlayBackControl(iPlayBack, HCNetSDK.NET_DVR_PLAYSTART, 0, null);
200
+        if (playBackCallBack == null) {
201
+            playBackCallBack = new playDataCallBack();
202
+        }
203
+        boolean bRet = hCNetSDK.NET_DVR_SetPlayDataCallBack_V40(iPlayBack, playBackCallBack, Pointer.NULL);
204
+        //开始计时器
205
+        Playbacktimer = new Timer();//新建定时器
206
+        Playbacktimer.schedule(new PlaybackTask(), 0, 5000);//0秒后开始响应函数
207
+        return;
208
+    }
209
+
210
+
211
+    public static void playBackByfile(int userID) {
212
+        file = new File(System.getProperty("user.dir") + "\\Download\\Videodatabyfile.mp4");  //保存回调函数的音频数据
213
+
214
+        if (!file.exists()) {
215
+            try {
216
+                file.createNewFile();
217
+            } catch (Exception e) {
218
+                e.printStackTrace();
219
+            }
220
+        }
221
+        try {
222
+            outputStream = new FileOutputStream(file);
223
+        } catch (FileNotFoundException e) {
224
+            // TODO Auto-generated catch block
225
+            e.printStackTrace();
226
+        }
227
+        String strFileName = "";
228
+        HCNetSDK.NET_DVR_FILECOND_V40 struFileCond = new HCNetSDK.NET_DVR_FILECOND_V40();
229
+        struFileCond.read();
230
+        struFileCond.lChannel = 1; //通道号 NVR设备路数小于32路的起始通道号从33开始,依次增加
231
+        struFileCond.byFindType = 0;  //录象文件类型 0=定时录像
232
+        //起始时间
233
+        struFileCond.struStartTime.dwYear = 2022;
234
+        struFileCond.struStartTime.dwMonth = 4;
235
+        struFileCond.struStartTime.dwDay = 17;
236
+        struFileCond.struStartTime.dwHour = 10;
237
+        struFileCond.struStartTime.dwMinute = 00;
238
+        struFileCond.struStartTime.dwSecond = 00;
239
+        //停止时间
240
+        struFileCond.struStopTime.dwYear = 2022;
241
+        struFileCond.struStopTime.dwMonth = 4;
242
+        struFileCond.struStopTime.dwDay = 17;
243
+        struFileCond.struStopTime.dwHour = 10;
244
+        struFileCond.struStopTime.dwMinute = 10;
245
+        struFileCond.struStopTime.dwSecond = 0;
246
+        struFileCond.write();
247
+        int FindFileHandle = hCNetSDK.NET_DVR_FindFile_V40(userID, struFileCond);
248
+        if (FindFileHandle <= -1) {
249
+            System.out.println("查找建立失败,错误码为" + hCNetSDK.NET_DVR_GetLastError());
250
+        }
251
+
252
+        while (true) {
253
+            HCNetSDK.NET_DVR_FINDDATA_V40 struFindData = new HCNetSDK.NET_DVR_FINDDATA_V40();
254
+
255
+            long State = hCNetSDK.NET_DVR_FindNextFile_V40(FindFileHandle, struFindData);
256
+            if (State <= -1) {
257
+
258
+                System.out.println("查找失败,错误码为" + hCNetSDK.NET_DVR_GetLastError());
259
+                return;
260
+
261
+            } else if (State == 1000)  //获取文件信息成功
262
+            {
263
+                struFindData.read();
264
+                try {
265
+                    strFileName = new String(struFindData.sFileName, "UTF-8").trim();
266
+                    System.out.println("文件名称:" + strFileName);
267
+                    System.out.println("文件大小:" + struFindData.dwFileSize);
268
+                } catch (UnsupportedEncodingException e) {
269
+                    e.printStackTrace();
270
+                }
271
+                System.out.println("获取文件成功");
272
+                break;
273
+
274
+            } else if (State == 1001) //未查找到文件
275
+            {
276
+                System.out.println("未查找到文件");
277
+                break;
278
+
279
+            } else if (State == 1002) //正在查找请等待
280
+            {
281
+                System.out.println("正在查找,请等待");
282
+                continue;
283
+
284
+            } else if (State == 1003) //没有更多的文件,查找结束
285
+            {
286
+                System.out.println("没有更多的文件,查找结束");
287
+                break;
288
+
289
+            } else if (State == 1004) //查找文件时异常
290
+            {
291
+
292
+                System.out.println("没有更多的文件,查找结束");
293
+                break;
294
+
295
+            } else if (State == 1005) //查找文件超时
296
+            {
297
+
298
+                System.out.println("没有更多的文件,查找结束");
299
+                break;
300
+
301
+            }
302
+
303
+        }
304
+        boolean b_CloseHandle = hCNetSDK.NET_DVR_FindClose_V30(FindFileHandle);
305
+        if (!b_CloseHandle) {
306
+            System.out.println("关闭失败,错误码为" + hCNetSDK.NET_DVR_GetLastError());
307
+            return;
308
+        }
309
+
310
+        int lPlayByFileHandle = hCNetSDK.NET_DVR_PlayBackByName(userID, strFileName, null);
311
+        if (lPlayByFileHandle <= -1) {
312
+            System.out.println("按文件回放失败,错误码为" + hCNetSDK.NET_DVR_GetLastError());
313
+            return;
314
+        }
315
+        IntByReference intP1 = new IntByReference(0);
316
+        IntByReference intInlen = new IntByReference(0);
317
+        boolean b_PlayBackStart = hCNetSDK.NET_DVR_PlayBackControl_V40(lPlayByFileHandle, HCNetSDK.NET_DVR_PLAYSTART, intP1.getPointer(), 4, Pointer.NULL, intInlen);
318
+        if (!b_PlayBackStart) {
319
+            System.out.println("开始播放失败,错误码为" + hCNetSDK.NET_DVR_GetLastError());
320
+            return;
321
+        }
322
+        if (playBackCallBack == null) {
323
+            playBackCallBack = new playDataCallBack();
324
+        }
325
+        boolean bRet = hCNetSDK.NET_DVR_SetPlayDataCallBack_V40(lPlayByFileHandle, playBackCallBack, Pointer.NULL);
326
+        while (true) {
327
+            int Pos = hCNetSDK.NET_DVR_GetDownloadPos(lPlayByFileHandle);
328
+            if (Pos != 100) {
329
+                System.out.println("回放进度:" + Pos);
330
+
331
+                try {
332
+                    Thread.sleep(1000);
333
+                } catch (InterruptedException e) {
334
+                    // TODO Auto-generated catch block
335
+                    e.printStackTrace();
336
+                }
337
+                continue;
338
+            } else {
339
+                break;
340
+            }
341
+        }
342
+        boolean b_Stop = hCNetSDK.NET_DVR_StopPlayBack(lPlayByFileHandle);
343
+        if (!b_Stop) {
344
+            System.out.println("停止回放失败,错误码为" + hCNetSDK.NET_DVR_GetLastError());
345
+            return;
346
+        }
347
+        System.out.println("回放成功");
348
+        return;
349
+
350
+
351
+    }
352
+
353
+
354
+    //按文件下载录像(设置转成3GP格式)
355
+    public static void DownloadRecordByFile(int userID, int iChannelNo) {
356
+        String strFileName = "";
357
+        HCNetSDK.NET_DVR_FILECOND_V40 struFileCond = new HCNetSDK.NET_DVR_FILECOND_V40();
358
+        struFileCond.read();
359
+        struFileCond.lChannel = 1; //通道号 NVR设备路数小于32路的起始通道号从33开始,依次增加
360
+        struFileCond.dwFileType = 0Xff;
361
+        struFileCond.byFindType = 0;
362
+        //起始时间
363
+        struFileCond.struStartTime.dwYear = 2022;
364
+        struFileCond.struStartTime.dwMonth = 7;
365
+        struFileCond.struStartTime.dwDay = 5;
366
+        struFileCond.struStartTime.dwHour = 12;
367
+        struFileCond.struStartTime.dwMinute = 00;
368
+        struFileCond.struStartTime.dwSecond = 00;
369
+        //停止时间
370
+        struFileCond.struStopTime.dwYear = 2022;
371
+        struFileCond.struStopTime.dwMonth = 7;
372
+        struFileCond.struStopTime.dwDay = 5;
373
+        struFileCond.struStopTime.dwHour = 12;
374
+        struFileCond.struStopTime.dwMinute = 10;
375
+        struFileCond.struStopTime.dwSecond = 00;
376
+        struFileCond.write();
377
+        int FindFileHandle = hCNetSDK.NET_DVR_FindFile_V40(userID, struFileCond);
378
+        if (FindFileHandle <= -1) {
379
+            System.out.println("查找建立失败,错误码为" + hCNetSDK.NET_DVR_GetLastError());
380
+        }
381
+
382
+        while (true) {
383
+            HCNetSDK.NET_DVR_FINDDATA_V40 struFindData = new HCNetSDK.NET_DVR_FINDDATA_V40();
384
+
385
+            long State = hCNetSDK.NET_DVR_FindNextFile_V40(FindFileHandle, struFindData);
386
+            if (State <= -1) {
387
+
388
+                System.out.println("查找失败,错误码为" + hCNetSDK.NET_DVR_GetLastError());
389
+                return;
390
+
391
+            } else if (State == 1000)  //获取文件信息成功
392
+            {
393
+                struFindData.read();
394
+                try {
395
+                    strFileName = new String(struFindData.sFileName, "UTF-8").trim();
396
+                    System.out.println("文件名称:" + strFileName);
397
+                    System.out.println("文件大小:" + struFindData.dwFileSize);
398
+                } catch (UnsupportedEncodingException e) {
399
+                    e.printStackTrace();
400
+                }
401
+                System.out.println("获取文件成功");
402
+                break;
403
+
404
+            } else if (State == 1001) //未查找到文件
405
+            {
406
+                System.out.println("未查找到文件");
407
+                break;
408
+
409
+            } else if (State == 1002) //正在查找请等待
410
+            {
411
+                System.out.println("正在查找,请等待");
412
+                continue;
413
+
414
+            } else if (State == 1003) //没有更多的文件,查找结束
415
+            {
416
+                System.out.println("没有更多的文件,查找结束");
417
+                break;
418
+
419
+            } else if (State == 1004) //查找文件时异常
420
+            {
421
+
422
+                System.out.println("没有更多的文件,查找结束");
423
+                break;
424
+
425
+            } else if (State == 1005) //查找文件超时
426
+            {
427
+
428
+                System.out.println("没有更多的文件,查找结束");
429
+                break;
430
+
431
+            }
432
+
433
+        }
434
+        boolean b_CloseHandle = hCNetSDK.NET_DVR_FindClose_V30(FindFileHandle);
435
+        if (!b_CloseHandle) {
436
+            System.out.println("关闭失败,错误码为" + hCNetSDK.NET_DVR_GetLastError());
437
+            return;
438
+        }
439
+
440
+        //按文件下载录像
441
+        String SaveDir = ".\\Download\\test.mp4";
442
+
443
+        int FileName = hCNetSDK.NET_DVR_GetFileByName(userID, strFileName, SaveDir.getBytes());
444
+        if (FileName <= -1) {
445
+            System.out.println("下载录像失败,错误码为" + hCNetSDK.NET_DVR_GetLastError());
446
+            return;
447
+        }
448
+        //转码3GP命令
449
+        IntByReference intP = new IntByReference(5);
450
+        IntByReference intInlen1 = new IntByReference(0);
451
+        boolean b_PlayBack = hCNetSDK.NET_DVR_PlayBackControl_V40(FileName, 32, intP.getPointer(), 4, Pointer.NULL, intInlen1);
452
+        if (!b_PlayBack) {
453
+            System.out.println("转封装失败,错误码为" + hCNetSDK.NET_DVR_GetLastError());
454
+            return;
455
+        }
456
+
457
+        IntByReference intP1 = new IntByReference(0);
458
+        IntByReference intInlen = new IntByReference(0);
459
+        boolean b_PlayBackStart = hCNetSDK.NET_DVR_PlayBackControl_V40(FileName, HCNetSDK.NET_DVR_PLAYSTART, intP1.getPointer(), 4, Pointer.NULL, intInlen);
460
+        if (!b_PlayBackStart) {
461
+            System.out.println("开始播放失败,错误码为" + hCNetSDK.NET_DVR_GetLastError());
462
+            return;
463
+        }
464
+
465
+/*        IntByReference intP=new IntByReference(30*1024);
466
+        IntByReference intInlen1=new IntByReference(0);
467
+        boolean b_PlayBack=hCNetSDK.NET_DVR_PlayBackControl_V40(FileName,24,intP.getPointer(),4, Pointer.NULL,intInlen1);
468
+        if (!b_PlayBack) {
469
+            System.out.println("设置下载速度失败,错误码为" + hCNetSDK.NET_DVR_GetLastError());
470
+            return;
471
+        }*/
472
+        while (true) {
473
+            int Pos = hCNetSDK.NET_DVR_GetDownloadPos(FileName);
474
+            if (Pos != 100) {
475
+                System.out.println("下载进度:" + Pos);
476
+
477
+                try {
478
+                    Thread.sleep(1000);
479
+                } catch (InterruptedException e) {
480
+                    // TODO Auto-generated catch block
481
+                    e.printStackTrace();
482
+                }
483
+                continue;
484
+            } else {
485
+                break;
486
+            }
487
+        }
488
+        boolean b_Stop = hCNetSDK.NET_DVR_StopGetFile(FileName);
489
+        if (!b_Stop) {
490
+            System.out.println("停止下载失败,错误码为" + hCNetSDK.NET_DVR_GetLastError());
491
+            return;
492
+        }
493
+        System.out.println("下载成功");
494
+        return;
495
+    }
496
+
497
+    //按时间下载录像(不支持转码3GP格式)
498
+    public void DowmloadRecordByTime(int userID) {
499
+        HCNetSDK.NET_DVR_PLAYCOND net_dvr_playcond = new HCNetSDK.NET_DVR_PLAYCOND();
500
+        net_dvr_playcond.read();
501
+        net_dvr_playcond.dwChannel = 1; //通道号 NVR设备路数小于32路的起始通道号从33开始,依次增加
502
+        //开始时间
503
+        net_dvr_playcond.struStartTime.dwYear = 2022;
504
+        net_dvr_playcond.struStartTime.dwMonth = 4;
505
+        net_dvr_playcond.struStartTime.dwDay = 17;
506
+        net_dvr_playcond.struStartTime.dwHour = 10;
507
+        net_dvr_playcond.struStartTime.dwMinute = 00;
508
+        net_dvr_playcond.struStartTime.dwSecond = 00;
509
+        //停止时间
510
+        net_dvr_playcond.struStopTime.dwYear = 2022;
511
+        net_dvr_playcond.struStopTime.dwMonth = 4;
512
+        net_dvr_playcond.struStopTime.dwDay = 17;
513
+        net_dvr_playcond.struStopTime.dwHour = 10;
514
+        net_dvr_playcond.struStopTime.dwMinute = 10;
515
+        net_dvr_playcond.struStopTime.dwSecond = 00;
516
+        net_dvr_playcond.write();
517
+        String sFileName = ".\\Download\\" + System.currentTimeMillis() + ".mp4";
518
+        System.out.println(sFileName);
519
+        m_lLoadHandle = hCNetSDK.NET_DVR_GetFileByTime_V40(userID, sFileName, net_dvr_playcond);
520
+        if (m_lLoadHandle >= 0) {
521
+            hCNetSDK.NET_DVR_PlayBackControl(m_lLoadHandle, HCNetSDK.NET_DVR_PLAYSTART, 0, null);
522
+/*            IntByReference intP=new IntByReference(5*8*1024);
523
+            IntByReference intInlen=new IntByReference(0);
524
+            boolean b_PlayBack=ClientDemo.hCNetSDK.NET_DVR_PlayBackControl_V40(m_lLoadHandle,24,intP.getPointer(),4,Pointer.NULL,intInlen);
525
+            if (!b_PlayBack) {
526
+                System.out.println("设置下载速度失败,错误码为" + ClientDemo.hCNetSDK.NET_DVR_GetLastError());
527
+                return;
528
+            }*/
529
+            Date nowTime = new Date(System.currentTimeMillis());
530
+            SimpleDateFormat sdFormatter = new SimpleDateFormat("yyyy-MM-dd-hh-mm-ss");
531
+            System.out.println("开始下载时间:" + sdFormatter.format(nowTime));
532
+            Downloadtimer = new Timer();//新建定时器
533
+            Downloadtimer.schedule(new DownloadTask(), 0, 5000);//0秒后开始响应函数
534
+        } else {
535
+            System.out.println("按时间下载失败");
536
+            System.out.println("laste error " + hCNetSDK.NET_DVR_GetLastError());
537
+            return;
538
+        }
539
+    }
540
+
541
+    /*************************************************
542
+     类:      DownloadTask
543
+     类描述:  下载定时器响应函数
544
+     *************************************************/
545
+    class DownloadTask extends java.util.TimerTask {
546
+        //定时器函数
547
+        @Override
548
+        public void run() {
549
+            IntByReference nPos = new IntByReference(0);
550
+            hCNetSDK.NET_DVR_PlayBackControl(m_lLoadHandle, HCNetSDK.NET_DVR_PLAYGETPOS, 0, nPos);
551
+            if (nPos.getValue() > 100) {
552
+                m_lLoadHandle = -1;
553
+                Downloadtimer.cancel();
554
+                System.out.println("由于网络原因或DVR忙,下载异常终止!");
555
+            }
556
+            if (nPos.getValue() == 100) {
557
+                Date nowTime = new Date(System.currentTimeMillis());
558
+                SimpleDateFormat sdFormatter = new SimpleDateFormat("yyyy-MM-dd-hh-mm-ss");
559
+                System.out.println("结束下载时间:" + sdFormatter.format(nowTime));
560
+                m_lLoadHandle = -1;
561
+                Downloadtimer.cancel();
562
+                System.out.println("按时间下载结束!");
563
+            }
564
+        }
565
+    }
566
+
567
+
568
+    class PlaybackTask extends java.util.TimerTask {
569
+        //定时器函数
570
+        @Override
571
+        public void run() {
572
+            System.out.println("定时器触发");
573
+            IntByReference nPos = new IntByReference(0);
574
+            System.out.println("ceshi");
575
+
576
+            System.out.println("iPlayBack" + iPlayBack);
577
+            boolean bret = hCNetSDK.NET_DVR_PlayBackControl(iPlayBack, HCNetSDK.NET_DVR_PLAYGETPOS, 0, nPos);
578
+            if (bret) {
579
+                System.out.println("回放进度" + nPos.getValue());
580
+            } else {
581
+                System.out.println("获取回放进度失败");
582
+            }
583
+
584
+            if (nPos.getValue() > 100) {
585
+
586
+                hCNetSDK.NET_DVR_StopPlayBack(iPlayBack);
587
+                if (outputStream != null) {
588
+                    try {
589
+                        outputStream.close();
590
+                    } catch (IOException e) {
591
+                        // TODO Auto-generated catch block
592
+                        e.printStackTrace();
593
+                    }
594
+                }
595
+                System.out.println("由于网络原因或DVR忙,回放异常终止!");
596
+            }
597
+            if (nPos.getValue() == 100) {
598
+                hCNetSDK.NET_DVR_StopPlayBack(iPlayBack);
599
+                if (outputStream != null) {
600
+                    try {
601
+                        outputStream.close();
602
+                    } catch (IOException e) {
603
+                        // TODO Auto-generated catch block
604
+                        e.printStackTrace();
605
+                    }
606
+                }
607
+                System.out.println("按时间回放结束");
608
+            }
609
+        }
610
+
611
+
612
+    }
613
+
614
+
615
+    //获取IP通道
616
+    public static void getIPChannelInfo(int userID) {
617
+        IntByReference ibrBytesReturned = new IntByReference(0);//获取IP接入配置参数
618
+        HCNetSDK.NET_DVR_IPPARACFG_V40 m_strIpparaCfg = new HCNetSDK.NET_DVR_IPPARACFG_V40();
619
+        m_strIpparaCfg.write();
620
+        //lpIpParaConfig 接收数据的缓冲指针
621
+        Pointer lpIpParaConfig = m_strIpparaCfg.getPointer();
622
+        boolean bRet = hCNetSDK.NET_DVR_GetDVRConfig(userID, HCNetSDK.NET_DVR_GET_IPPARACFG_V40, 0, lpIpParaConfig, m_strIpparaCfg.size(), ibrBytesReturned);
623
+        m_strIpparaCfg.read();
624
+        System.out.println("起始数字通道号:" + m_strIpparaCfg.dwStartDChan);
625
+
626
+        for (int iChannum = 0; iChannum < m_strIpparaCfg.dwDChanNum; iChannum++) {
627
+            int channum = iChannum + m_strIpparaCfg.dwStartDChan;
628
+            m_strIpparaCfg.struStreamMode[iChannum].read();
629
+            if (m_strIpparaCfg.struStreamMode[iChannum].byGetStreamType == 0) {
630
+                m_strIpparaCfg.struStreamMode[iChannum].uGetStream.setType(HCNetSDK.NET_DVR_IPCHANINFO.class);
631
+                m_strIpparaCfg.struStreamMode[iChannum].uGetStream.struChanInfo.read();
632
+                if (m_strIpparaCfg.struStreamMode[iChannum].uGetStream.struChanInfo.byEnable == 1) {
633
+                    System.out.println("IP通道" + channum + "在线");
634
+                } else {
635
+                    System.out.println("IP通道" + channum + "不在线");
636
+                }
637
+            }
638
+        }
639
+    }
640
+
641
+    static class fPlayEScallback implements HCNetSDK.FPlayESCallBack {
642
+        public void invoke(int lPreviewHandle, HCNetSDK.NET_DVR_PACKET_INFO_EX pstruPackInfo, Pointer pUser) {
643
+            System.out.println("进入码流回调");
644
+            System.out.println(pstruPackInfo.dwPacketSize);
645
+//            try {
646
+//                fileLenth += pstruPackInfo.dwPacketSize;
647
+//                fileOutputStream = new FileOutputStream(resultFileName,true);
648
+//                //将字节写入文件
649
+//                ByteBuffer buffers = pstruPackInfo.pPacketBuffer.getByteBuffer(0, pstruPackInfo.dwPacketSize);
650
+//                byte[] bytes = new byte[pstruPackInfo.dwPacketSize];
651
+//                buffers.rewind();
652
+//                buffers.get(bytes);
653
+//                fileOutputStream.write(bytes);
654
+//            } catch (FileNotFoundException e) {
655
+//                e.printStackTrace();
656
+//            } catch (IOException e) {
657
+//                e.printStackTrace();
658
+//            }
659
+        }
660
+    }
661
+
662
+    static class playDataCallBack implements HCNetSDK.FPlayDataCallBack {
663
+        public void invoke(int lPlayHandle, int dwDataType, Pointer pBuffer, int dwBufSize, int dwUser) {
664
+            System.out.println("回放码流回调...");
665
+            //将设备发送过来的回放码流数据写入文件
666
+            long offset = 0;
667
+            ByteBuffer buffers = pBuffer.getByteBuffer(offset, dwBufSize);
668
+            byte[] bytes = new byte[dwBufSize];
669
+            buffers.rewind();
670
+            buffers.get(bytes);
671
+            try {
672
+                outputStream.write(bytes);
673
+            } catch (IOException e) {
674
+                e.printStackTrace();
675
+            }
676
+        }
677
+    }
678
+
679
+    static class FRealDataCallBack implements HCNetSDK.FRealDataCallBack_V30 {
680
+        //预览回调
681
+        public void invoke(int lRealHandle, int dwDataType, ByteByReference pBuffer, int dwBufSize, Pointer pUser) {
682
+            System.out.println("码流数据回调...dwBufSize=" + dwBufSize);
683
+            //播放库解码
684
+            switch (dwDataType) {
685
+                case HCNetSDK.NET_DVR_SYSHEAD: //系统头
686
+                    if (!playControl.PlayM4_GetPort(m_lPort)) //获取播放库未使用的通道号
687
+                    {
688
+                        break;
689
+                    }
690
+                    if (dwBufSize > 0) {
691
+                        if (!playControl.PlayM4_SetStreamOpenMode(m_lPort.getValue(), PlayCtrl.STREAME_REALTIME))  //设置实时流播放模式
692
+                        {
693
+                            break;
694
+                        }
695
+                        if (!playControl.PlayM4_OpenStream(m_lPort.getValue(), pBuffer, dwBufSize, 1024 * 1024)) //打开流接口
696
+                        {
697
+                            break;
698
+                        }
699
+                        if (!playControl.PlayM4_Play(m_lPort.getValue(), null)) //播放开始
700
+                        {
701
+                            break;
702
+                        }
703
+
704
+                    }
705
+                case HCNetSDK.NET_DVR_STREAMDATA:   //码流数据
706
+                    if ((dwBufSize > 0) && (m_lPort.getValue() != -1)) {
707
+                        if (!playControl.PlayM4_InputData(m_lPort.getValue(), pBuffer, dwBufSize))  //输入流数据
708
+                        {
709
+                            break;
710
+                        }
711
+                    }
712
+            }
713
+        }
714
+    }
715
+
716
+}

+ 2 - 0
src/main/resources/application-dev.yml

@@ -3,6 +3,8 @@
3 3
 exceptionAlarm:
4 4
   # 设备ip地址 枪机: DS-2CD7T27DWD-IZS(16384)/球机: DS-7716NX-I4(4354)
5 5
   deviceIP: 10.7.11.161
6
+  # 端口
7
+  port: 8000
6 8
   # 设备用户名
7 9
   userName: admin
8 10
   # 设备密码

+ 6 - 4
src/main/resources/application-prod.yml

@@ -2,13 +2,15 @@
2 2
 # 设备登录
3 3
 exceptionAlarm:
4 4
   # 设备ip地址 DS-2CD7T27DWD-IZS(16384)/DS-7716NX-I4(4354)-->4432
5
-  deviceIP: 192.168.143.10
6
-  # orgCode
7
-  org-code: SPB
5
+  deviceIP: 10.7.11.161
8 6
   # 设备用户名
9 7
   userName: admin
10 8
   # 设备密码
11
-  password: JLspb20220928
9
+  password: Aa870618
10
+  # 端口
11
+  port: 8000
12
+  # orgCode
13
+  org-code: SPB
12 14
 # 只支持post
13 15
 address:
14 16
   # 推送异常闯入/入侵信息地址