admin
2024-05-27 816ba1e56476f0e23f51711aae4b34507a04a59c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
package com.ruoyi.HIKVISION.NetSDK;
 
 
//import com.ruoyi.aibox.domain.AiAlarmInfo;
import com.sun.jna.Pointer;
 
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.text.SimpleDateFormat;
import java.util.Date;
 
//布防回调函数
public class FMSGCallBack_V31 implements HCNetSDK.FMSGCallBack_V31 {
    //报警信息回调函数
    public boolean invoke(int lCommand, HCNetSDK.NET_DVR_ALARMER pAlarmer, Pointer pAlarmInfo, int dwBufLen, Pointer pUser) {
        AlarmDataHandle(lCommand, pAlarmer, pAlarmInfo, dwBufLen, pUser);
        return true;
    }
    public void AlarmDataHandle(int lCommand, HCNetSDK.NET_DVR_ALARMER pAlarmer, Pointer pAlarmInfo, int dwBufLen, Pointer pUser) {
//        System.out.println("报警事件发生,进入回调");
//        String hexString = Integer.toHexString(lCommand);
//        System.out.println("报警类型 = " + hexString);
//        String[] sIP = new String(pAlarmer.sDeviceIP).split("\0", 2);
//        String[] sDeviceName = new String(pAlarmer.sDeviceName).split("\0", 2);
//        System.out.println("收到报警信息pAlarmInfo:"+pAlarmInfo.toString());
//        System.out.println("报警设备IP地址:"+sIP.toString());
//        System.out.println("报警设备名称:"+sDeviceName.toString());
//        System.out.println("报警类型 lCommand:" + Integer.toHexString(lCommand));
//        switch (lCommand) {
//            case HCNetSDK.COMM_SNAP_MATCH_ALARM://人脸黑名单比对报警
//                System.out.println("SNAP_MATCH_ALARM");
//                HCNetSDK.NET_VCA_FACESNAP_MATCH_ALARM strFaceSnapMatch = new HCNetSDK.NET_VCA_FACESNAP_MATCH_ALARM();
//                strFaceSnapMatch.write();
//                Pointer pFaceSnapMatch = strFaceSnapMatch.getPointer();
//                pFaceSnapMatch.write(0, pAlarmInfo.getByteArray(0, strFaceSnapMatch.size()), 0, strFaceSnapMatch.size());
//                strFaceSnapMatch.read();
//                //比对结果
//                System.out.println("比对结果:" + (strFaceSnapMatch.byContrastStatus == 1 ? "比对成功" : "比对失败"));
//                //人脸库ID
//                if (strFaceSnapMatch.struBlockListInfo.dwFDIDLen > 0) {
//                    long offset1 = 0;
//                    ByteBuffer buffers1 = strFaceSnapMatch.struBlockListInfo.pFDID.getByteBuffer(offset1, strFaceSnapMatch.struBlockListInfo.dwFDIDLen);
//                    byte[] bytes1 = new byte[strFaceSnapMatch.struBlockListInfo.dwFDIDLen];
//                    buffers1.get(bytes1);
//                    System.out.println("人脸库ID:" + new String(bytes1));
//                }
//                //人脸库图片ID
//                if (strFaceSnapMatch.struBlockListInfo.dwPIDLen > 0) {
//                    long offset2 = 0;
//                    ByteBuffer buffers2 = strFaceSnapMatch.struBlockListInfo.pPID.getByteBuffer(offset2, strFaceSnapMatch.struBlockListInfo.dwPIDLen);
//                    byte[] bytes2 = new byte[strFaceSnapMatch.struBlockListInfo.dwPIDLen];
//                    buffers2.get(bytes2);
//                    System.out.println("图片ID:" + new String(bytes2));
//                }
//                //保存抓拍人脸图,图片数据传输方式: 0- 二进制
//                if ((strFaceSnapMatch.dwSnapPicLen > 0) && (strFaceSnapMatch.byPicTransType == 0)) {
//                    SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
//                    String newName = sf.format(new Date());
//                    FileOutputStream fout;
//                    try {
//                        String filename = ".//pic//" + newName + "_pSnapPicBuffer" + ".jpg";
//                        fout = new FileOutputStream(filename);
//                        //将字节写入文件
//                        long offset = 0;
//                        ByteBuffer buffers = strFaceSnapMatch.pSnapPicBuffer.getByteBuffer(offset, strFaceSnapMatch.dwSnapPicLen);
//                        byte[] bytes = new byte[strFaceSnapMatch.dwSnapPicLen];
//                        buffers.rewind();
//                        buffers.get(bytes);
//                        fout.write(bytes);
//                        fout.close();
//                    } catch (FileNotFoundException e) {
//                        // TODO Auto-generated catch block
//                        e.printStackTrace();
//                    } catch (IOException e) {
//                        // TODO Auto-generated catch block
//                        e.printStackTrace();
//                    }
//                }
//                //保存抓拍人脸图URL,图片数据传输方式: 1- URL 注:超脑设备人脸比对报警图片一般按照URL上传,根据URL去下载设备中存储的图片,认证方式选择:摘要认证
//                if ((strFaceSnapMatch.dwSnapPicLen > 0) && (strFaceSnapMatch.byPicTransType == 1)) {
//                    long offset = 0;
//                    ByteBuffer buffers = strFaceSnapMatch.pSnapPicBuffer.getByteBuffer(offset, strFaceSnapMatch.dwSnapPicLen);
//                    byte[] bytes = new byte[strFaceSnapMatch.dwSnapPicLen];
//                    buffers.rewind();
//                    buffers.get(bytes);
//                    System.out.println("人脸抓拍图片 URL:" + new String(bytes));
//                }
//                if ((strFaceSnapMatch.struSnapInfo.dwSnapFacePicLen > 0) && (strFaceSnapMatch.byPicTransType == 0)) {
//                    SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
//                    String newName = sf.format(new Date());
//                    FileOutputStream fout;
//                    try {
//                        String filename = ".//pic//" + newName + "_struSnapInfo_pBuffer1" + ".jpg";
//                        fout = new FileOutputStream(filename);
//                        //将字节写入文件
//                        long offset = 0;
//                        ByteBuffer buffers = strFaceSnapMatch.struSnapInfo.pBuffer1.getByteBuffer(offset, strFaceSnapMatch.struSnapInfo.dwSnapFacePicLen);
//                        byte[] bytes = new byte[strFaceSnapMatch.struSnapInfo.dwSnapFacePicLen];
//                        buffers.rewind();
//                        buffers.get(bytes);
//                        fout.write(bytes);
//                        fout.close();
//                    } catch (FileNotFoundException e) {
//                        // TODO Auto-generated catch block
//                        e.printStackTrace();
//                    } catch (IOException e) {
//                        // TODO Auto-generated catch block
//                        e.printStackTrace();
//                    }
//                }
//                if ((strFaceSnapMatch.struSnapInfo.dwSnapFacePicLen > 0) && (strFaceSnapMatch.byPicTransType == 1)) {
//                    long offset = 0;
//                    ByteBuffer buffers = strFaceSnapMatch.struSnapInfo.pBuffer1.getByteBuffer(offset, strFaceSnapMatch.struSnapInfo.dwSnapFacePicLen);
//                    byte[] bytes = new byte[strFaceSnapMatch.struSnapInfo.dwSnapFacePicLen];
//                    buffers.rewind();
//                    buffers.get(bytes);
//                    System.out.println("人脸抓拍图片1 URL:" + new String(bytes));
//                }
//                //保存人脸库图片,图片数据传输方式: 0- 二进制
//                if ((strFaceSnapMatch.struBlockListInfo.dwBlockListPicLen > 0) && (strFaceSnapMatch.byPicTransType == 0)) {
//                    SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
//                    String newName = sf.format(new Date());
//                    FileOutputStream fout;
//                    try {
//                        String filename = ".//pic//" + newName + "_fSimilarity_" + strFaceSnapMatch.fSimilarity + "_struBlackListInfo_pBuffer1" + ".jpg";
//                        fout = new FileOutputStream(filename);
//                        //将字节写入文件
//                        long offset = 0;
//                        ByteBuffer buffers = strFaceSnapMatch.struBlockListInfo.pBuffer1.getByteBuffer(offset, strFaceSnapMatch.struBlockListInfo.dwBlockListPicLen);
//                        byte[] bytes = new byte[strFaceSnapMatch.struBlockListInfo.dwBlockListPicLen];
//                        buffers.rewind();
//                        buffers.get(bytes);
//                        fout.write(bytes);
//                        fout.close();
//                    } catch (FileNotFoundException e) {
//                        // TODO Auto-generated catch block
//                        e.printStackTrace();
//                    } catch (IOException e) {
//                        // TODO Auto-generated catch block
//                        e.printStackTrace();
//                    }
//                }
//                //保存人脸库图片,图片数据传输方式: 1-URL
//                if ((strFaceSnapMatch.struBlockListInfo.dwBlockListPicLen > 0) && (strFaceSnapMatch.byPicTransType == 1)) {
//                    long offset = 0;
//                    ByteBuffer buffers = strFaceSnapMatch.struBlockListInfo.pBuffer1.getByteBuffer(offset, strFaceSnapMatch.struBlockListInfo.dwBlockListPicLen);
//                    byte[] bytes = new byte[strFaceSnapMatch.struBlockListInfo.dwBlockListPicLen];
//                    buffers.rewind();
//                    buffers.get(bytes);
//                    System.out.println("人脸库图片 URL:" + new String(bytes));
//                }
//                //抓拍库附加信息数据指针,附加信息的XML文本中包含人脸温度数据
//                if (strFaceSnapMatch.struBlockListInfo.struBlockListInfo.dwFCAdditionInfoLen > 0) {
//                    long offset = 0;
//                    ByteBuffer buffers = strFaceSnapMatch.struBlockListInfo.struBlockListInfo.pFCAdditionInfoBuffer.getByteBuffer(offset, strFaceSnapMatch.struBlockListInfo.struBlockListInfo.dwFCAdditionInfoLen);
//                    byte[] bytes = new byte[strFaceSnapMatch.struBlockListInfo.struBlockListInfo.dwFCAdditionInfoLen];
//                    buffers.rewind();
//                    buffers.get(bytes);
//                    System.out.println("抓拍库附加信息:" + new String(bytes));
//                }
//                AiAlarmInfo alarmInfo = new AiAlarmInfo();
//                alarmInfo.setCategory("1");//报警类型(1三违,2隐患)
//                alarmInfo.setSmallClass("25");//报警事件(字典aibox_rule_type)
//                break;
//            case HCNetSDK.COMM_FIREDETECTION_ALARM://烟火检测
//                HCNetSDK.NET_DVR_FIREDETECTION_ALARM struFireDecAlarm = new HCNetSDK.NET_DVR_FIREDETECTION_ALARM();
//                struFireDecAlarm.write();
//                Pointer pFireDecAlarm = struFireDecAlarm.getPointer();
//                pFireDecAlarm.write(0, pAlarmInfo.getByteArray(0, struFireDecAlarm.size()), 0, struFireDecAlarm.size());
//                struFireDecAlarm.read();
//                String sFireDecAlarmInfo = "绝对时间:" + struFireDecAlarm.dwAbsTime + ",报警子类型:" + struFireDecAlarm.byAlarmSubType + ",火点最高温度 :" +
//                        struFireDecAlarm.wFireMaxTemperature + ",火点目标距离:" + struFireDecAlarm.wTargetDistance;
//                System.out.println(sFireDecAlarmInfo);
//                //可见光图片保存
//                if ((struFireDecAlarm.dwVisiblePicLen > 0) && (struFireDecAlarm.byPicTransType == 0)) {
//                    SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
//                    String newName = sf.format(new Date());
//                    FileOutputStream fout;
//
//                    try {
//                        String filename = "../pic/" + newName + "_FireDecAlarm" + ".jpg";
//                        fout = new FileOutputStream(filename);
//                        //将字节写入文件
//                        long offset = 0;
//                        ByteBuffer buffers = struFireDecAlarm.pVisiblePicBuf.getByteBuffer(offset, struFireDecAlarm.dwVisiblePicLen);
//                        byte[] bytes = new byte[struFireDecAlarm.dwVisiblePicLen];
//                        buffers.rewind();
//                        buffers.get(bytes);
//                        fout.write(bytes);
//                        fout.close();
//                    } catch (FileNotFoundException e) {
//                        // TODO Auto-generated catch block
//                        e.printStackTrace();
//                    } catch (IOException e) {
//                        // TODO Auto-generated catch block
//                        e.printStackTrace();
//                    }
//                }
//                //热成像图片保存
//                if ((struFireDecAlarm.dwPicDataLen > 0) && (struFireDecAlarm.byPicTransType == 0)) {
//                    SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
//                    String newName = sf.format(new Date());
//                    FileOutputStream fout;
//
//                    try {
//                        String filename = "../pic/" + newName + "_" + "_ThermalFireAlarm" + ".jpg";
//                        fout = new FileOutputStream(filename);
//                        //将字节写入文件
//                        long offset = 0;
//                        ByteBuffer buffers = struFireDecAlarm.pBuffer.getByteBuffer(offset, struFireDecAlarm.dwPicDataLen);
//                        byte[] bytes = new byte[struFireDecAlarm.dwPicDataLen];
//                        buffers.rewind();
//                        buffers.get(bytes);
//                        fout.write(bytes);
//                        fout.close();
//                    } catch (FileNotFoundException e) {
//                        // TODO Auto-generated catch block
//                        e.printStackTrace();
//                    } catch (IOException e) {
//                        // TODO Auto-generated catch block
//                        e.printStackTrace();
//                    }
//
//                }
//                break;
//            case HCNetSDK.COMM_VCA_ALARM:  // 智能检测通用报警(Json或者XML数据结构) PS:这里用来接受安全帽报警
//                String sAlarmInfo = new String(pAlarmer.sDeviceIP);
//                //报警数据类型:0- invalid,1- xml,2- json
//                sAlarmInfo = "报警设备IP:" + sAlarmInfo;
//                System.out.println(sAlarmInfo);
//
//                SimpleDateFormat sf0 = new SimpleDateFormat("yyyyMMddHHmmss");
//                String curTime0 = sf0.format(new Date());
//                FileOutputStream Data;
//                String jsonfile = "../pic" + new String(pAlarmer.sDeviceIP).trim() + curTime0 + "_VCA_ALARM_" + ".json";
//                try {
//                    Data = new FileOutputStream(jsonfile);
//                    //将字节写入文件
//                    ByteBuffer dataBuffer = pAlarmInfo.getByteBuffer(0, dwBufLen);
//                    byte[] dataByte = new byte[dwBufLen];
//                    dataBuffer.rewind();
//                    dataBuffer.get(dataByte);
//                    Data.write(dataByte);
//                    Data.close();
//                } catch (FileNotFoundException e) {
//                    e.printStackTrace();
//                } catch (IOException e) {
//                    e.printStackTrace();
//                }
//                break;
//            case HCNetSDK.COMM_ALARM_RULE: //行为分析信息 PS:用来实现区域闯入报警
//                HCNetSDK.NET_VCA_RULE_ALARM strVcaAlarm = new HCNetSDK.NET_VCA_RULE_ALARM();
//                strVcaAlarm.write();
//                Pointer pVCAInfo = strVcaAlarm.getPointer();
//                pVCAInfo.write(0, pAlarmInfo.getByteArray(0, strVcaAlarm.size()), 0, strVcaAlarm.size());
//                strVcaAlarm.read();
//                switch (strVcaAlarm.struRuleInfo.wEventTypeEx) {
//                    case 1: //穿越警戒面 (越界侦测)
//                        System.out.println("穿越警戒面报警发生");
//                        break;
//                    case 2: //目标进入区域
//
//                        System.out.println("目标进入区域报警发生");
//
//                        break;
//                    case 3: //目标离开区域
//                        System.out.println("目标离开区域报警触发");
//                    case 4: //周界入侵
//
//                        System.out.println("周界入侵报警发生");
//
//                        break;
//                    case 5: //徘徊
//                        System.out.println("徘徊事件触发");
//
//                        break;
//                    case 8: //快速移动(奔跑),
//                        System.out.println("快速移动(奔跑)事件触发");
//                        break;
//                    case 15: //离岗
//                        System.out.println("离岗事件触发");
//                    case 20: //倒地检测
//                        System.out.println("倒地事件触发");
//                        break;
//                    case 44: //玩手机
//                        System.out.println("玩手机报警发生");
//                        if ((strVcaAlarm.dwPicDataLen > 0) && (strVcaAlarm.byPicTransType == 0)) {
//                            SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
//                            String newName = sf.format(new Date());
//                            FileOutputStream fout;
//                            try {
//                                String filename = "../pic/" + newName + "PLAY_CELLPHONE_" + ".jpg";
//                                fout = new FileOutputStream(filename);
//                                //将字节写入文件
//                                long offset = 0;
//                                ByteBuffer buffers = strVcaAlarm.pImage.getByteBuffer(offset, strVcaAlarm.dwPicDataLen);
//                                byte[] bytes = new byte[strVcaAlarm.dwPicDataLen];
//                                buffers.rewind();
//                                buffers.get(bytes);
//                                fout.write(bytes);
//                                fout.close();
//                            } catch (FileNotFoundException e) {
//                                // TODO Auto-generated catch block
//                                e.printStackTrace();
//                            } catch (IOException e) {
//                                // TODO Auto-generated catch block
//                                e.printStackTrace();
//                            }
//                        }
//                        break;
//                    case 45: //持续检测
//                        System.out.println("持续检测事件触发");
//                    default:
//                        System.out.println("行为事件类型:"+strVcaAlarm.struRuleInfo.wEventTypeEx);
//                        break;
//                }
//                break;
//            case HCNetSDK.COMM_ISAPI_ALARM: //ISAPI协议报警信息 PS:用来实现人员密集度报警
//                HCNetSDK.NET_DVR_ALARM_ISAPI_INFO struEventISAPI = new HCNetSDK.NET_DVR_ALARM_ISAPI_INFO();
//                struEventISAPI.write();
//                Pointer pEventISAPI = struEventISAPI.getPointer();
//                pEventISAPI.write(0, pAlarmInfo.getByteArray(0, struEventISAPI.size()), 0, struEventISAPI.size());
//                struEventISAPI.read();
//                sAlarmInfo = new String(pAlarmer.sDeviceIP);
//                //报警数据类型:0- invalid,1- xml,2- json
//                sAlarmInfo = "报警设备IP:" + sAlarmInfo + ":ISAPI协议报警信息, 数据格式:" + struEventISAPI.byDataType +
//                        ", 图片个数:" + struEventISAPI.byPicturesNumber;
//                System.out.println(sAlarmInfo);
//
//                //报警数据保存
//                SimpleDateFormat sf1 = new SimpleDateFormat("yyyyMMddHHmmss");
//                String curTime1 = sf1.format(new Date());
//                FileOutputStream foutdata;
//                try {
//                    String jsonfilename = "../pic/" + new String(pAlarmer.sDeviceIP).trim() + curTime1 + "_ISAPI_Alarm_" + ".json";
//                    foutdata = new FileOutputStream(jsonfilename);
//                    //将字节写入文件
//                    ByteBuffer jsonbuffers = struEventISAPI.pAlarmData.getByteBuffer(0, struEventISAPI.dwAlarmDataLen);
//                    byte[] jsonbytes = new byte[struEventISAPI.dwAlarmDataLen];
//                    jsonbuffers.rewind();
//                    jsonbuffers.get(jsonbytes);
//                    foutdata.write(jsonbytes);
//                    foutdata.close();
//                } catch (FileNotFoundException e) {
//                    // TODO Auto-generated catch block
//                    e.printStackTrace();
//                } catch (IOException e) {
//                    // TODO Auto-generated catch block
//                    e.printStackTrace();
//                }
//                //图片数据保存
//                for (int i = 0; i < struEventISAPI.byPicturesNumber; i++) {
//                    HCNetSDK.NET_DVR_ALARM_ISAPI_PICDATA struPicData = new HCNetSDK.NET_DVR_ALARM_ISAPI_PICDATA();
//                    struPicData.write();
//                    Pointer pPicData = struPicData.getPointer();
//                    pPicData.write(0, struEventISAPI.pPicPackData.getByteArray(i * struPicData.size(), struPicData.size()), 0, struPicData.size());
//                    struPicData.read();
//
//                    FileOutputStream fout;
//                    try {
//                        String filename = "../pic/" + new String(pAlarmer.sDeviceIP).trim() + curTime1 +
//                                "_ISAPIPic_" + i + "_" + new String(struPicData.szFilename).trim() + ".jpg";
//                        fout = new FileOutputStream(filename);
//                        //将字节写入文件
//                        long offset = 0;
//                        ByteBuffer buffers = struPicData.pPicData.getByteBuffer(offset, struPicData.dwPicLen);
//                        byte[] bytes = new byte[struPicData.dwPicLen];
//                        buffers.rewind();
//                        buffers.get(bytes);
//                        fout.write(bytes);
//                        fout.close();
//                    } catch (FileNotFoundException e) {
//                        // TODO Auto-generated catch block
//                        e.printStackTrace();
//                    } catch (IOException e) {
//                        // TODO Auto-generated catch block
//                        e.printStackTrace();
//                    }
//                }
//                break;
//        }
    }
}