您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

1501 行
91 KiB

  1. package com.hkversion;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.common.CommonUtil;
  4. import com.sun.jna.Pointer;
  5. import com.yzx.callback.AlarmCallback;
  6. import java.io.*;
  7. import java.nio.ByteBuffer;
  8. import java.text.SimpleDateFormat;
  9. import java.util.Date;
  10. /**
  11. * @author jiangxin
  12. * @create 2022-08-15-18:04
  13. */
  14. public class AlarmDataParse {
  15. public static void alarmDataHandle(int lCommand, HCNetSDK.NET_DVR_ALARMER pAlarmer, Pointer pAlarmInfo, int dwBufLen, Pointer pUser, AlarmCallback callback) {
  16. System.out.println("报警事件类型: lCommand:" + Integer.toHexString(lCommand));
  17. String sTime;
  18. String MonitoringSiteID;
  19. //lCommand是传的报警类型
  20. switch (lCommand) {
  21. case HCNetSDK.COMM_ITS_PLATE_RESULT://交通抓拍结果(新报警信息)
  22. HCNetSDK.NET_ITS_PLATE_RESULT strItsPlateResult = new HCNetSDK.NET_ITS_PLATE_RESULT();
  23. strItsPlateResult.write();
  24. Pointer pItsPlateInfo = strItsPlateResult.getPointer();
  25. pItsPlateInfo.write(0, pAlarmInfo.getByteArray(0, strItsPlateResult.size()), 0, strItsPlateResult.size());
  26. strItsPlateResult.read();
  27. try {
  28. String sLicense = new String(strItsPlateResult.struPlateInfo.sLicense, "GBK");
  29. byte VehicleType = strItsPlateResult.byVehicleType; //0-其他车辆,1-小型车,2-大型车,3- 行人触发,4- 二轮车触发,5- 三轮车触发,6- 机动车触发
  30. MonitoringSiteID = new String(strItsPlateResult.byMonitoringSiteID);
  31. System.out.println("车牌号:" + sLicense + ":车辆类型:" + VehicleType + ":监控点编号:" + MonitoringSiteID);
  32. } catch (UnsupportedEncodingException e1) {
  33. // TODO Auto-generated catch block
  34. e1.printStackTrace();
  35. } catch (IOException e) {
  36. // TODO Auto-generated catch block
  37. e.printStackTrace();
  38. }
  39. /**
  40. * 报警图片保存,车牌,车辆图片
  41. */
  42. for (int i = 0; i < strItsPlateResult.dwPicNum; i++) {
  43. if (strItsPlateResult.struPicInfo[i].dwDataLen > 0) {
  44. SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
  45. String newName = sf.format(new Date());
  46. FileOutputStream fout;
  47. try {
  48. String filename = "../pic/" + newName + "_type[" + strItsPlateResult.struPicInfo[i].byType + "]_ItsPlate.jpg";
  49. fout = new FileOutputStream(filename);
  50. //将字节写入文件
  51. long offset = 0;
  52. ByteBuffer buffers = strItsPlateResult.struPicInfo[i].pBuffer.getByteBuffer(offset, strItsPlateResult.struPicInfo[i].dwDataLen);
  53. byte[] bytes = new byte[strItsPlateResult.struPicInfo[i].dwDataLen];
  54. buffers.rewind();
  55. buffers.get(bytes);
  56. fout.write(bytes);
  57. fout.close();
  58. } catch (FileNotFoundException e) {
  59. // TODO Auto-generated catch block
  60. e.printStackTrace();
  61. } catch (IOException e) {
  62. // TODO Auto-generated catch block
  63. e.printStackTrace();
  64. }
  65. }
  66. }
  67. break;
  68. case HCNetSDK.COMM_ALARM_TFS: //道路违章取证报警
  69. HCNetSDK.NET_DVR_TFS_ALARM strTfsAlarm = new HCNetSDK.NET_DVR_TFS_ALARM();
  70. strTfsAlarm.write();
  71. Pointer pTfsAlarm = strTfsAlarm.getPointer();
  72. pTfsAlarm.write(0, pAlarmInfo.getByteArray(0, strTfsAlarm.size()), 0, strTfsAlarm.size());
  73. strTfsAlarm.read();
  74. sTime = CommonUtil.parseTime(strTfsAlarm.dwAbsTime); //报警绝对时间
  75. int IllegalType = strTfsAlarm.dwIllegalType; // 违章类型
  76. MonitoringSiteID = strTfsAlarm.byMonitoringSiteID.toString(); //监控点编号
  77. // 车牌信息
  78. try {
  79. String PlateInfo = "车牌号:" + new String(strTfsAlarm.struPlateInfo.sLicense, "GBK");
  80. System.out.println("【道路违章取证报警】时间:" + sTime + "违章类型:" + IllegalType + "车牌信息:" + PlateInfo);
  81. } catch (UnsupportedEncodingException e) {
  82. e.printStackTrace();
  83. }
  84. //报警图片信息
  85. for (int i = 0; i < strTfsAlarm.dwPicNum; i++) {
  86. if (strTfsAlarm.struPicInfo[i].dwDataLen > 0) {
  87. SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
  88. String newName = sf.format(new Date());
  89. FileOutputStream fout;
  90. try {
  91. String filename = "../pic/" + newName + "_type[" + strTfsAlarm.struPicInfo[i].byType + "]_TfsPlate.jpg";
  92. fout = new FileOutputStream(filename);
  93. //将字节写入文件
  94. long offset = 0;
  95. ByteBuffer buffers = strTfsAlarm.struPicInfo[i].pBuffer.getByteBuffer(offset, strTfsAlarm.struPicInfo[i].dwDataLen);
  96. byte[] bytes = new byte[strTfsAlarm.struPicInfo[i].dwDataLen];
  97. buffers.rewind();
  98. buffers.get(bytes);
  99. fout.write(bytes);
  100. fout.close();
  101. } catch (FileNotFoundException e) {
  102. // TODO Auto-generated catch block
  103. e.printStackTrace();
  104. } catch (IOException e) {
  105. // TODO Auto-generated catch block
  106. e.printStackTrace();
  107. }
  108. }
  109. }
  110. break;
  111. case HCNetSDK.COMM_ALARM_AID_V41: //道路事件检测
  112. HCNetSDK.NET_DVR_AID_ALARM_V41 strAIDAlarmV41 = new HCNetSDK.NET_DVR_AID_ALARM_V41();
  113. strAIDAlarmV41.write();
  114. Pointer pstrAIDAlarmV41 = strAIDAlarmV41.getPointer();
  115. pstrAIDAlarmV41.write(0, pAlarmInfo.getByteArray(0, strAIDAlarmV41.size()), 0, strAIDAlarmV41.size());
  116. strAIDAlarmV41.read();
  117. sTime = CommonUtil.parseTime(strAIDAlarmV41.dwAbsTime); //报警触发绝对时间
  118. MonitoringSiteID = strAIDAlarmV41.byMonitoringSiteID.toString(); //监控点编号
  119. int AIDType = strAIDAlarmV41.struAIDInfo.dwAIDType; // 交通事件类型
  120. int AIDTypeEx = strAIDAlarmV41.struAIDInfo.dwAIDTypeEx; //交通事件类型扩展
  121. System.out.println("【道路事件检测】" + "时间:" + sTime + "监控点:" + MonitoringSiteID + "交通事件类型:" + AIDType + "交通事件类型扩展:" + AIDTypeEx);
  122. //报警图片信息
  123. if (strAIDAlarmV41.dwPicDataLen > 0 && strAIDAlarmV41.pImage != null) {
  124. SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
  125. String newName = sf.format(new Date());
  126. FileOutputStream fout;
  127. try {
  128. String filename = "../pic/" + newName + "_AIDalarm.jpg";
  129. fout = new FileOutputStream(filename);
  130. //将字节写入文件
  131. long offset = 0;
  132. ByteBuffer buffers = strAIDAlarmV41.pImage.getByteBuffer(offset, strAIDAlarmV41.dwPicDataLen);
  133. byte[] bytes = new byte[strAIDAlarmV41.dwPicDataLen];
  134. buffers.rewind();
  135. buffers.get(bytes);
  136. fout.write(bytes);
  137. fout.close();
  138. } catch (FileNotFoundException e) {
  139. // TODO Auto-generated catch block
  140. e.printStackTrace();
  141. } catch (IOException e) {
  142. // TODO Auto-generated catch block
  143. e.printStackTrace();
  144. }
  145. }
  146. break;
  147. case HCNetSDK.COMM_ALARM_TPS_V41://交通数据统计的报警
  148. HCNetSDK.NET_DVR_TPS_ALARM_V41 strTPSalarmV41 = new HCNetSDK.NET_DVR_TPS_ALARM_V41();
  149. strTPSalarmV41.write();
  150. Pointer pstrTPSalarmV41 = strTPSalarmV41.getPointer();
  151. pstrTPSalarmV41.write(0, pAlarmInfo.getByteArray(0, strTPSalarmV41.size()), 0, strTPSalarmV41.size());
  152. strTPSalarmV41.read();
  153. sTime = CommonUtil.parseTime(strTPSalarmV41.dwAbsTime);
  154. MonitoringSiteID = strTPSalarmV41.byMonitoringSiteID.toString(); //监控点编号
  155. String StartTime = CommonUtil.parseTime(strTPSalarmV41.dwStartTime); //开始统计时间;
  156. String StopTime = CommonUtil.parseTime(strTPSalarmV41.dwStopTime); //结束统计时间;
  157. System.out.println("【交通数据统计】" + "时间:" + sTime + "监控点编号:" + MonitoringSiteID + "开始统计时间:" + StartTime + "结束统计时间:" + StopTime);
  158. //车道统计参数信息
  159. for (int i = 0; i <= HCNetSDK.MAX_TPS_RULE; i++) {
  160. byte LaneNo = strTPSalarmV41.struTPSInfo.struLaneParam[i].byLaneNo; //车道号
  161. byte TrafficState = strTPSalarmV41.struTPSInfo.struLaneParam[i].byTrafficState; //车道状态 0-无效,1-畅通,2-拥挤,3-堵塞
  162. int TpsType = strTPSalarmV41.struTPSInfo.struLaneParam[i].dwTpsType; //数据变化类型标志,表示当前上传的统计参数中,哪些数据有效,按位区分
  163. int LaneVolume = strTPSalarmV41.struTPSInfo.struLaneParam[i].dwLaneVolume; //车道流量
  164. int LaneVelocity = strTPSalarmV41.struTPSInfo.struLaneParam[i].dwLaneVelocity; //车道平均速度
  165. float SpaceOccupyRation = strTPSalarmV41.struTPSInfo.struLaneParam[i].fSpaceOccupyRation; //车道占有率,百分比计算(空间上,车辆长度与监控路段总长度的比值)
  166. System.out.println("车道号:" + LaneNo + "车道状态:" + TrafficState + "车道流量:" + LaneVolume + "车道占有率:" + SpaceOccupyRation + "\n");
  167. }
  168. break;
  169. case HCNetSDK.COMM_ALARM_TPS_REAL_TIME: //实时过车数据数据
  170. HCNetSDK.NET_DVR_TPS_REAL_TIME_INFO netDvrTpsParam = new HCNetSDK.NET_DVR_TPS_REAL_TIME_INFO();
  171. netDvrTpsParam.write();
  172. Pointer pItsParkVehicle = netDvrTpsParam.getPointer();
  173. pItsParkVehicle.write(0, pAlarmInfo.getByteArray(0, netDvrTpsParam.size()), 0, netDvrTpsParam.size());
  174. netDvrTpsParam.read();
  175. String struTime = "" + String.format("%04d", netDvrTpsParam.struTime.wYear) +
  176. String.format("%02d", netDvrTpsParam.struTime.byMonth) +
  177. String.format("%02d", netDvrTpsParam.struTime.byDay) +
  178. String.format("%02d", netDvrTpsParam.struTime.byDay) +
  179. String.format("%02d", netDvrTpsParam.struTime.byHour) +
  180. String.format("%02d", netDvrTpsParam.struTime.byMinute) +
  181. String.format("%02d", netDvrTpsParam.struTime.bySecond);
  182. Short wDeviceID = new Short(netDvrTpsParam.struTPSRealTimeInfo.wDeviceID);//设备ID
  183. int channel = netDvrTpsParam.dwChan; //触发报警通道号
  184. String byLane = new String(String.valueOf(netDvrTpsParam.struTPSRealTimeInfo.byLane)).trim();// 对应车道号
  185. String bySpeed = new String(String.valueOf(netDvrTpsParam.struTPSRealTimeInfo.bySpeed)).trim();// 对应车速(KM/H)
  186. int dwDownwardFlow = netDvrTpsParam.struTPSRealTimeInfo.dwDownwardFlow;//当前车道 从上到下车流量
  187. int dwUpwardFlow = netDvrTpsParam.struTPSRealTimeInfo.dwUpwardFlow; //当前车道 从下到上车流量
  188. System.out.println("通道号:" + channel + "; 时间:" + struTime + ";对应车道号:" + byLane + ";当前车道 从上到下车流量:" + dwDownwardFlow + ";dwUpwardFlow:" + dwUpwardFlow);
  189. break;
  190. case HCNetSDK.COMM_ALARM_TPS_STATISTICS: //统计过车数据
  191. HCNetSDK.NET_DVR_TPS_STATISTICS_INFO netDvrTpsStatisticsInfo = new HCNetSDK.NET_DVR_TPS_STATISTICS_INFO();
  192. netDvrTpsStatisticsInfo.write();
  193. Pointer pTpsVehicle = netDvrTpsStatisticsInfo.getPointer();
  194. pTpsVehicle.write(0, pAlarmInfo.getByteArray(0, netDvrTpsStatisticsInfo.size()), 0, netDvrTpsStatisticsInfo.size());
  195. netDvrTpsStatisticsInfo.read();
  196. int Tpschannel = netDvrTpsStatisticsInfo.dwChan; //触发报警通道号
  197. //统计开始时间
  198. String struStartTime = "" + String.format("%04d", netDvrTpsStatisticsInfo.struTPSStatisticsInfo.struStartTime.wYear) +
  199. String.format("%02d", netDvrTpsStatisticsInfo.struTPSStatisticsInfo.struStartTime.byMonth) +
  200. String.format("%02d", netDvrTpsStatisticsInfo.struTPSStatisticsInfo.struStartTime.byDay) +
  201. String.format("%02d", netDvrTpsStatisticsInfo.struTPSStatisticsInfo.struStartTime.byDay) +
  202. String.format("%02d", netDvrTpsStatisticsInfo.struTPSStatisticsInfo.struStartTime.byHour) +
  203. String.format("%02d", netDvrTpsStatisticsInfo.struTPSStatisticsInfo.struStartTime.byMinute) +
  204. String.format("%02d", netDvrTpsStatisticsInfo.struTPSStatisticsInfo.struStartTime.bySecond);
  205. byte TotalLaneNum = netDvrTpsStatisticsInfo.struTPSStatisticsInfo.byTotalLaneNum; //有效车道总数
  206. System.out.println("通道号:" + Tpschannel + "; 开始统计时间:" + struStartTime + "有效车道总数:" + TotalLaneNum);
  207. break;
  208. case HCNetSDK.COMM_ITS_PARK_VEHICLE: //停车场数据上传
  209. HCNetSDK.NET_ITS_PARK_VEHICLE strParkVehicle = new HCNetSDK.NET_ITS_PARK_VEHICLE();
  210. strParkVehicle.write();
  211. Pointer pstrParkVehicle = strParkVehicle.getPointer();
  212. pstrParkVehicle.write(0, pAlarmInfo.getByteArray(0, strParkVehicle.size()), 0, strParkVehicle.size());
  213. strParkVehicle.read();
  214. try {
  215. byte ParkError = strParkVehicle.byParkError; //停车异常:0- 正常,1- 异常
  216. String ParkingNo = new String(strParkVehicle.byParkingNo, "UTF-8"); //车位编号
  217. byte LocationStatus = strParkVehicle.byLocationStatus; //车位车辆状态 0- 无车,1- 有车
  218. MonitoringSiteID = strParkVehicle.byMonitoringSiteID.toString();
  219. String plateNo = new String(strParkVehicle.struPlateInfo.sLicense, "GBK"); //车牌号
  220. } catch (UnsupportedEncodingException e) {
  221. e.printStackTrace();
  222. }
  223. //报警图片信息
  224. for (int i = 0; i < strParkVehicle.dwPicNum; i++) {
  225. if (strParkVehicle.struPicInfo[i].dwDataLen > 0) {
  226. SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
  227. String newName = sf.format(new Date());
  228. FileOutputStream fout;
  229. try {
  230. String filename = "../pic/" + newName + "_ParkVehicle.jpg";
  231. fout = new FileOutputStream(filename);
  232. //将字节写入文件
  233. long offset = 0;
  234. ByteBuffer buffers = strParkVehicle.struPicInfo[i].pBuffer.getByteBuffer(offset, strParkVehicle.struPicInfo[i].dwDataLen);
  235. byte[] bytes = new byte[strParkVehicle.struPicInfo[i].dwDataLen];
  236. buffers.rewind();
  237. buffers.get(bytes);
  238. fout.write(bytes);
  239. fout.close();
  240. } catch (FileNotFoundException e) {
  241. // TODO Auto-generated catch block
  242. e.printStackTrace();
  243. } catch (IOException e) {
  244. // TODO Auto-generated catch block
  245. e.printStackTrace();
  246. }
  247. }
  248. }
  249. break;
  250. case HCNetSDK.COMM_ALARMHOST_CID_ALARM://报警主机CID报告报警上传
  251. HCNetSDK.NET_DVR_CID_ALARM strCIDalarm = new HCNetSDK.NET_DVR_CID_ALARM();
  252. strCIDalarm.write();
  253. Pointer pstrCIDalarm = strCIDalarm.getPointer();
  254. pstrCIDalarm.write(0, pAlarmInfo.getByteArray(0, strCIDalarm.size()), 0, strCIDalarm.size());
  255. strCIDalarm.read();
  256. try {
  257. String TriggerTime = "" + String.format("%04d", strCIDalarm.struTriggerTime.wYear) +
  258. String.format("%02d", strCIDalarm.struTriggerTime.byMonth) +
  259. String.format("%02d", strCIDalarm.struTriggerTime.byDay) +
  260. String.format("%02d", strCIDalarm.struTriggerTime.byDay) +
  261. String.format("%02d", strCIDalarm.struTriggerTime.byHour) +
  262. String.format("%02d", strCIDalarm.struTriggerTime.byMinute) +
  263. String.format("%02d", strCIDalarm.struTriggerTime.bySecond); //触发报警时间
  264. String sCIDCode = new String(strCIDalarm.sCIDCode, "GBK"); //CID事件号
  265. String sCIDDescribe = new String(strCIDalarm.sCIDDescribe, "GBK"); //CID事件名
  266. byte bySubSysNo = strCIDalarm.bySubSysNo; //子系统号
  267. if (strCIDalarm.wDefenceNo != 0xff)
  268. {
  269. System.out.println("防区号:"+Integer.sum(strCIDalarm.wDefenceNo,1));
  270. }
  271. System.out.println("【CID事件】" + "触发时间:" + TriggerTime + "CID事件号:" + sCIDCode + "CID事件名:" + sCIDDescribe + "子系统号:" +
  272. bySubSysNo);
  273. } catch (UnsupportedEncodingException e) {
  274. e.printStackTrace();
  275. }
  276. break;
  277. case HCNetSDK.COMM_IPC_AUXALARM_RESULT: //PIR报警、无线报警、呼救报警信息
  278. System.out.println("PIR报警、无线报警、呼救报警触发");
  279. break;
  280. case HCNetSDK.COMM_ISAPI_ALARM: //ISAPI协议报警信息
  281. HCNetSDK.NET_DVR_ALARM_ISAPI_INFO struEventISAPI = new HCNetSDK.NET_DVR_ALARM_ISAPI_INFO();
  282. struEventISAPI.write();
  283. Pointer pEventISAPI = struEventISAPI.getPointer();
  284. pEventISAPI.write(0, pAlarmInfo.getByteArray(0, struEventISAPI.size()), 0, struEventISAPI.size());
  285. struEventISAPI.read();
  286. String sAlarmInfo = new String(pAlarmer.sDeviceIP);
  287. //报警数据类型:0- invalid,1- xml,2- json
  288. sAlarmInfo = "报警设备IP:" + sAlarmInfo + ":ISAPI协议报警信息, 数据格式:" + struEventISAPI.byDataType +
  289. ", 图片个数:" + struEventISAPI.byPicturesNumber;
  290. System.out.println(sAlarmInfo);
  291. //报警数据保存
  292. SimpleDateFormat sf1 = new SimpleDateFormat("yyyyMMddHHmmss");
  293. String curTime1 = sf1.format(new Date());
  294. FileOutputStream foutdata;
  295. try {
  296. String jsonfilename = "../pic/" + new String(pAlarmer.sDeviceIP).trim() + curTime1 + "_ISAPI_Alarm_" + ".json";
  297. foutdata = new FileOutputStream(jsonfilename);
  298. //将字节写入文件
  299. ByteBuffer jsonbuffers = struEventISAPI.pAlarmData.getByteBuffer(0, struEventISAPI.dwAlarmDataLen);
  300. byte[] jsonbytes = new byte[struEventISAPI.dwAlarmDataLen];
  301. jsonbuffers.rewind();
  302. jsonbuffers.get(jsonbytes);
  303. foutdata.write(jsonbytes);
  304. foutdata.close();
  305. } catch (FileNotFoundException e) {
  306. // TODO Auto-generated catch block
  307. e.printStackTrace();
  308. } catch (IOException e) {
  309. // TODO Auto-generated catch block
  310. e.printStackTrace();
  311. }
  312. //图片数据保存
  313. for (int i = 0; i < struEventISAPI.byPicturesNumber; i++) {
  314. HCNetSDK.NET_DVR_ALARM_ISAPI_PICDATA struPicData = new HCNetSDK.NET_DVR_ALARM_ISAPI_PICDATA();
  315. struPicData.write();
  316. Pointer pPicData = struPicData.getPointer();
  317. pPicData.write(0, struEventISAPI.pPicPackData.getByteArray(i * struPicData.size(), struPicData.size()), 0, struPicData.size());
  318. struPicData.read();
  319. FileOutputStream fout;
  320. try {
  321. String filename = "../pic/" + new String(pAlarmer.sDeviceIP).trim() + curTime1 +
  322. "_ISAPIPic_" + i + "_" + new String(struPicData.szFilename).trim() + ".jpg";
  323. fout = new FileOutputStream(filename);
  324. //将字节写入文件
  325. long offset = 0;
  326. ByteBuffer buffers = struPicData.pPicData.getByteBuffer(offset, struPicData.dwPicLen);
  327. byte[] bytes = new byte[struPicData.dwPicLen];
  328. buffers.rewind();
  329. buffers.get(bytes);
  330. fout.write(bytes);
  331. fout.close();
  332. } catch (FileNotFoundException e) {
  333. // TODO Auto-generated catch block
  334. e.printStackTrace();
  335. } catch (IOException e) {
  336. // TODO Auto-generated catch block
  337. e.printStackTrace();
  338. }
  339. }
  340. break;
  341. case HCNetSDK.COMM_VCA_ALARM: // 智能检测通用报警(Json或者XML数据结构)
  342. sAlarmInfo = new String(pAlarmer.sDeviceIP);
  343. //报警数据类型:0- invalid,1- xml,2- json
  344. sAlarmInfo = "报警设备IP:" + sAlarmInfo;
  345. System.out.println(sAlarmInfo);
  346. SimpleDateFormat sf0 = new SimpleDateFormat("yyyyMMddHHmmss");
  347. String curTime0 = sf0.format(new Date());
  348. FileOutputStream Data;
  349. String jsonfile = "../pic" + new String(pAlarmer.sDeviceIP).trim() + curTime0 + "_VCA_ALARM_" + ".json";
  350. try {
  351. Data = new FileOutputStream(jsonfile);
  352. //将字节写入文件
  353. ByteBuffer dataBuffer = pAlarmInfo.getByteBuffer(0, dwBufLen);
  354. byte[] dataByte = new byte[dwBufLen];
  355. dataBuffer.rewind();
  356. dataBuffer.get(dataByte);
  357. Data.write(dataByte);
  358. Data.close();
  359. } catch (FileNotFoundException e) {
  360. e.printStackTrace();
  361. } catch (IOException e) {
  362. e.printStackTrace();
  363. }
  364. break;
  365. //行为分析信息
  366. case HCNetSDK.COMM_ALARM_RULE:
  367. HCNetSDK.NET_VCA_RULE_ALARM strVcaAlarm = new HCNetSDK.NET_VCA_RULE_ALARM();
  368. strVcaAlarm.write();
  369. Pointer pVCAInfo = strVcaAlarm.getPointer();
  370. pVCAInfo.write(0, pAlarmInfo.getByteArray(0, strVcaAlarm.size()), 0, strVcaAlarm.size());
  371. strVcaAlarm.read();
  372. switch (strVcaAlarm.struRuleInfo.wEventTypeEx) {
  373. case 1: //穿越警戒面 (越界侦测)
  374. System.out.println("越界侦测报警发生");
  375. strVcaAlarm.struRuleInfo.uEventParam.setType(HCNetSDK.NET_VCA_TRAVERSE_PLANE.class);
  376. System.out.println("检测目标:"+strVcaAlarm.struRuleInfo.uEventParam.struTraversePlane.byDetectionTarget); //检测目标,0表示所有目标(表示不锁定检测目标,所有目标都将进行检测),其他取值按位表示不同的检测目标:0x01-人,0x02-车
  377. //图片保存
  378. if ((strVcaAlarm.dwPicDataLen > 0) && (strVcaAlarm.byPicTransType == 0)) {
  379. SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
  380. String newName = sf.format(new Date());
  381. FileOutputStream fout;
  382. try {
  383. String filename = "../pic/" + newName + "VCA_TRAVERSE_PLANE" + ".jpg";
  384. fout = new FileOutputStream(filename);
  385. //将字节写入文件
  386. long offset = 0;
  387. ByteBuffer buffers = strVcaAlarm.pImage.getByteBuffer(offset, strVcaAlarm.dwPicDataLen);
  388. byte[] bytes = new byte[strVcaAlarm.dwPicDataLen];
  389. buffers.rewind();
  390. buffers.get(bytes);
  391. fout.write(bytes);
  392. fout.close();
  393. } catch (FileNotFoundException e) {
  394. // TODO Auto-generated catch block
  395. e.printStackTrace();
  396. } catch (IOException e) {
  397. // TODO Auto-generated catch block
  398. e.printStackTrace();
  399. }
  400. }
  401. break;
  402. case 2: //目标进入区域
  403. System.out.println("目标进入区域报警发生");
  404. strVcaAlarm.struRuleInfo.uEventParam.setType(HCNetSDK.NET_VCA_AREA.class);
  405. System.out.println("检测目标:"+strVcaAlarm.struRuleInfo.uEventParam.struArea.byDetectionTarget);
  406. //图片保存
  407. if ((strVcaAlarm.dwPicDataLen > 0) && (strVcaAlarm.byPicTransType == 0)) {
  408. SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
  409. String newName = sf.format(new Date());
  410. FileOutputStream fout;
  411. try {
  412. String filename = "../pic/" + newName + "_TargetEnter" + ".jpg";
  413. fout = new FileOutputStream(filename);
  414. //将字节写入文件
  415. long offset = 0;
  416. ByteBuffer buffers = strVcaAlarm.pImage.getByteBuffer(offset, strVcaAlarm.dwPicDataLen);
  417. byte[] bytes = new byte[strVcaAlarm.dwPicDataLen];
  418. buffers.rewind();
  419. buffers.get(bytes);
  420. fout.write(bytes);
  421. fout.close();
  422. } catch (FileNotFoundException e) {
  423. // TODO Auto-generated catch block
  424. e.printStackTrace();
  425. } catch (IOException e) {
  426. // TODO Auto-generated catch block
  427. e.printStackTrace();
  428. }
  429. }
  430. break;
  431. case 3: //目标离开区域
  432. System.out.println("目标离开区域报警触发");
  433. strVcaAlarm.struRuleInfo.uEventParam.setType(HCNetSDK.NET_VCA_AREA.class);
  434. System.out.println("检测目标:"+strVcaAlarm.struRuleInfo.uEventParam.struArea.byDetectionTarget);
  435. //图片保存
  436. if ((strVcaAlarm.dwPicDataLen > 0) && (strVcaAlarm.byPicTransType == 0)) {
  437. SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
  438. String newName = sf.format(new Date());
  439. FileOutputStream fout;
  440. try {
  441. String filename = "../pic/" + newName + "_TargetLeave" + ".jpg";
  442. fout = new FileOutputStream(filename);
  443. //将字节写入文件
  444. long offset = 0;
  445. ByteBuffer buffers = strVcaAlarm.pImage.getByteBuffer(offset, strVcaAlarm.dwPicDataLen);
  446. byte[] bytes = new byte[strVcaAlarm.dwPicDataLen];
  447. buffers.rewind();
  448. buffers.get(bytes);
  449. fout.write(bytes);
  450. fout.close();
  451. } catch (FileNotFoundException e) {
  452. // TODO Auto-generated catch block
  453. e.printStackTrace();
  454. } catch (IOException e) {
  455. // TODO Auto-generated catch block
  456. e.printStackTrace();
  457. }
  458. }
  459. break;
  460. case 4: //周界入侵
  461. System.out.println("周界入侵报警发生");
  462. strVcaAlarm.struRuleInfo.uEventParam.setType(HCNetSDK.NET_VCA_INTRUSION.class);
  463. System.out.println("检测目标:"+strVcaAlarm.struRuleInfo.uEventParam.struIntrusion.byDetectionTarget);
  464. //图片保存
  465. if ((strVcaAlarm.dwPicDataLen > 0) && (strVcaAlarm.byPicTransType == 0)) {
  466. SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
  467. String newName = sf.format(new Date());
  468. FileOutputStream fout;
  469. try {
  470. String filename = "../pic/" + newName + "VCA_INTRUSION" + ".jpg";
  471. fout = new FileOutputStream(filename);
  472. //将字节写入文件
  473. long offset = 0;
  474. ByteBuffer buffers = strVcaAlarm.pImage.getByteBuffer(offset, strVcaAlarm.dwPicDataLen);
  475. byte[] bytes = new byte[strVcaAlarm.dwPicDataLen];
  476. buffers.rewind();
  477. buffers.get(bytes);
  478. fout.write(bytes);
  479. fout.close();
  480. } catch (FileNotFoundException e) {
  481. // TODO Auto-generated catch block
  482. e.printStackTrace();
  483. } catch (IOException e) {
  484. // TODO Auto-generated catch block
  485. e.printStackTrace();
  486. }
  487. }
  488. break;
  489. case 5: //徘徊
  490. System.out.println("徘徊事件触发");
  491. break;
  492. case 8: //快速移动(奔跑),
  493. System.out.println("快速移动(奔跑)事件触发");
  494. break;
  495. case 15: //离岗
  496. System.out.println("离岗事件触发");
  497. strVcaAlarm.struRuleInfo.uEventParam.setType(HCNetSDK.NET_VCA_LEAVE_POSITION.class);
  498. System.out.println(strVcaAlarm.struRuleInfo.uEventParam.struLeavePos.byOnPosition);
  499. //图片保存
  500. if ((strVcaAlarm.dwPicDataLen > 0) && (strVcaAlarm.byPicTransType == 0)) {
  501. SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
  502. String newName = sf.format(new Date());
  503. FileOutputStream fout;
  504. try {
  505. String filename = "../pic/" + newName + "VCA_LEAVE_POSITION_" + ".jpg";
  506. fout = new FileOutputStream(filename);
  507. //将字节写入文件
  508. long offset = 0;
  509. ByteBuffer buffers = strVcaAlarm.pImage.getByteBuffer(offset, strVcaAlarm.dwPicDataLen);
  510. byte[] bytes = new byte[strVcaAlarm.dwPicDataLen];
  511. buffers.rewind();
  512. buffers.get(bytes);
  513. fout.write(bytes);
  514. fout.close();
  515. } catch (FileNotFoundException e) {
  516. // TODO Auto-generated catch block
  517. e.printStackTrace();
  518. } catch (IOException e) {
  519. // TODO Auto-generated catch block
  520. e.printStackTrace();
  521. }
  522. }
  523. case 20: //倒地检测
  524. System.out.println("倒地事件触发");
  525. break;
  526. case 44: //玩手机
  527. System.out.println("玩手机报警发生");
  528. //图片保存
  529. if ((strVcaAlarm.dwPicDataLen > 0) && (strVcaAlarm.byPicTransType == 0)) {
  530. SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
  531. String newName = sf.format(new Date());
  532. FileOutputStream fout;
  533. try {
  534. String filename = "../pic/" + newName + "PLAY_CELLPHONE_" + ".jpg";
  535. fout = new FileOutputStream(filename);
  536. //将字节写入文件
  537. long offset = 0;
  538. ByteBuffer buffers = strVcaAlarm.pImage.getByteBuffer(offset, strVcaAlarm.dwPicDataLen);
  539. byte[] bytes = new byte[strVcaAlarm.dwPicDataLen];
  540. buffers.rewind();
  541. buffers.get(bytes);
  542. fout.write(bytes);
  543. fout.close();
  544. } catch (FileNotFoundException e) {
  545. // TODO Auto-generated catch block
  546. e.printStackTrace();
  547. } catch (IOException e) {
  548. // TODO Auto-generated catch block
  549. e.printStackTrace();
  550. }
  551. }
  552. break;
  553. case 45: //持续检测
  554. System.out.println("持续检测事件触发");
  555. default:
  556. System.out.println("行为事件类型:" + strVcaAlarm.struRuleInfo.wEventTypeEx);
  557. break;
  558. }
  559. break;
  560. case HCNetSDK.COMM_ALARM_ACS: //门禁主机报警信息
  561. //组装数据
  562. JSONObject json = new JSONObject();
  563. HCNetSDK.NET_DVR_ACS_ALARM_INFO strACSInfo = new HCNetSDK.NET_DVR_ACS_ALARM_INFO();
  564. strACSInfo.write();
  565. Pointer pACSInfo = strACSInfo.getPointer();
  566. pACSInfo.write(0, pAlarmInfo.getByteArray(0, strACSInfo.size()), 0, strACSInfo.size());
  567. strACSInfo.read();
  568. /**门禁事件的详细信息解析,通过主次类型的可以判断当前的具体门禁类型,例如(主类型:0X5 次类型:0x4b 表示人脸认证通过,
  569. 主类型:0X5 次类型:0x4c 表示人脸认证失败)*/
  570. System.out.println("【门禁主机报警信息】卡号:" + new String(strACSInfo.struAcsEventInfo.byCardNo).trim() + ",卡类型:" +
  571. strACSInfo.struAcsEventInfo.byCardType + ",报警主类型:" + Integer.toHexString(strACSInfo.dwMajor) + ",报警次类型:" + Integer.toHexString(strACSInfo.dwMinor));
  572. System.out.println("工号1:" + strACSInfo.struAcsEventInfo.dwEmployeeNo);
  573. //温度信息(如果设备支持测温功能,人脸温度信息从NET_DVR_ACS_EVENT_INFO_EXTEND_V20结构体获取)
  574. if (strACSInfo.byAcsEventInfoExtendV20 == 1) {
  575. HCNetSDK.NET_DVR_ACS_EVENT_INFO_EXTEND_V20 strAcsInfoExV20 = new HCNetSDK.NET_DVR_ACS_EVENT_INFO_EXTEND_V20();
  576. strAcsInfoExV20.write();
  577. Pointer pAcsInfoExV20 = strAcsInfoExV20.getPointer();
  578. pAcsInfoExV20.write(0, strACSInfo.pAcsEventInfoExtendV20.getByteArray(0, strAcsInfoExV20.size()), 0, strAcsInfoExV20.size());
  579. strAcsInfoExV20.read();
  580. System.out.println("实时温度值:" + strAcsInfoExV20.fCurrTemperature);
  581. }
  582. //考勤状态
  583. if (strACSInfo.byAcsEventInfoExtend == 1) {
  584. HCNetSDK.NET_DVR_ACS_EVENT_INFO_EXTEND strAcsInfoEx = new HCNetSDK.NET_DVR_ACS_EVENT_INFO_EXTEND();
  585. strAcsInfoEx.write();
  586. Pointer pAcsInfoEx = strAcsInfoEx.getPointer();
  587. pAcsInfoEx.write(0, strACSInfo.pAcsEventInfoExtend.getByteArray(0, strAcsInfoEx.size()), 0, strAcsInfoEx.size());
  588. strAcsInfoEx.read();
  589. System.out.println("考勤状态:" + strAcsInfoEx.byAttendanceStatus);
  590. System.out.println("工号2:" + new String(strAcsInfoEx.byEmployeeNo).trim());
  591. }
  592. /**
  593. * 报警时间
  594. */
  595. String year = Integer.toString(strACSInfo.struTime.dwYear);
  596. String SwipeTime = year + strACSInfo.struTime.dwMonth + strACSInfo.struTime.dwDay + strACSInfo.struTime.dwHour + strACSInfo.struTime.dwMinute +
  597. strACSInfo.struTime.dwSecond;
  598. if (strACSInfo.dwPicDataLen > 0) {
  599. // SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
  600. // String newName = sf.format(new Date());
  601. FileOutputStream fout;
  602. try {
  603. /**
  604. * 人脸保存路径
  605. */
  606. String filename = "../pic/" + SwipeTime + "_ACS_Event_" + new String(strACSInfo.struAcsEventInfo.byCardNo).trim() + ".jpg";
  607. File file = new File(filename);
  608. File parentFile = file.getParentFile();
  609. if(!parentFile.exists()){
  610. parentFile.mkdirs();
  611. }
  612. fout = new FileOutputStream(filename);
  613. //将字节写入文件
  614. long offset = 0;
  615. ByteBuffer buffers = strACSInfo.pPicData.getByteBuffer(offset, strACSInfo.dwPicDataLen);
  616. byte[] bytes = new byte[strACSInfo.dwPicDataLen];
  617. buffers.rewind();
  618. buffers.get(bytes);
  619. fout.write(bytes);
  620. fout.close();
  621. } catch (FileNotFoundException e) {
  622. // TODO Auto-generated catch block
  623. e.printStackTrace();
  624. } catch (IOException e) {
  625. // TODO Auto-generated catch block
  626. e.printStackTrace();
  627. }
  628. }
  629. break;
  630. case HCNetSDK.COMM_ID_INFO_ALARM: //身份证信息
  631. HCNetSDK.NET_DVR_ID_CARD_INFO_ALARM strIDCardInfo = new HCNetSDK.NET_DVR_ID_CARD_INFO_ALARM();
  632. strIDCardInfo.write();
  633. Pointer pIDCardInfo = strIDCardInfo.getPointer();
  634. pIDCardInfo.write(0, pAlarmInfo.getByteArray(0, strIDCardInfo.size()), 0, strIDCardInfo.size());
  635. strIDCardInfo.read();
  636. System.out.println("报警主类型:" + Integer.toHexString(strIDCardInfo.dwMajor) + ",报警次类型:" + Integer.toHexString(strIDCardInfo.dwMinor));
  637. /**
  638. * 身份证信息
  639. */
  640. String IDnum = new String(strIDCardInfo.struIDCardCfg.byIDNum).trim();
  641. System.out.println("【身份证信息】:身份证号码:" + IDnum + ",姓名:" +
  642. new String(strIDCardInfo.struIDCardCfg.byName).trim() + ",住址:" + new String(strIDCardInfo.struIDCardCfg.byAddr));
  643. /**
  644. * 报警时间
  645. */
  646. String year1 = Integer.toString(strIDCardInfo.struSwipeTime.wYear);
  647. String SwipeTime1 = year1 + strIDCardInfo.struSwipeTime.byMonth + strIDCardInfo.struSwipeTime.byDay + strIDCardInfo.struSwipeTime.byHour + strIDCardInfo.struSwipeTime.byMinute +
  648. strIDCardInfo.struSwipeTime.bySecond;
  649. /**
  650. * 保存图片
  651. */
  652. //身份证图片
  653. if (strIDCardInfo.dwPicDataLen > 0 || strIDCardInfo.pPicData != null) {
  654. // SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
  655. // String nowtime = sf.format(new Date());
  656. FileOutputStream fout;
  657. try {
  658. String filename = "../pic/" + SwipeTime1 + "_" + IDnum + ".jpg";
  659. fout = new FileOutputStream(filename);
  660. //将字节写入文件
  661. long offset = 0;
  662. ByteBuffer buffers = strIDCardInfo.pPicData.getByteBuffer(offset, strIDCardInfo.dwPicDataLen);
  663. byte[] bytes = new byte[strIDCardInfo.dwPicDataLen];
  664. buffers.rewind();
  665. buffers.get(bytes);
  666. fout.write(bytes);
  667. fout.close();
  668. } catch (FileNotFoundException e) {
  669. // TODO Auto-generated catch block
  670. e.printStackTrace();
  671. } catch (IOException e) {
  672. // TODO Auto-generated catch block
  673. e.printStackTrace();
  674. }
  675. }
  676. if (strIDCardInfo.dwCapturePicDataLen > 0 || strIDCardInfo.pCapturePicData != null) {
  677. // SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
  678. // String nowtime = sf.format(new Date());
  679. FileOutputStream fout;
  680. try {
  681. /**
  682. * 人脸图片保存路径
  683. */
  684. String filename = "../pic/" + SwipeTime1 + "_CapturePic_" + ".jpg";
  685. fout = new FileOutputStream(filename);
  686. //将字节写入文件
  687. long offset = 0;
  688. ByteBuffer buffers = strIDCardInfo.pCapturePicData.getByteBuffer(offset, strIDCardInfo.dwCapturePicDataLen);
  689. byte[] bytes = new byte[strIDCardInfo.dwCapturePicDataLen];
  690. buffers.rewind();
  691. buffers.get(bytes);
  692. fout.write(bytes);
  693. fout.close();
  694. } catch (FileNotFoundException e) {
  695. // TODO Auto-generated catch block
  696. e.printStackTrace();
  697. } catch (IOException e) {
  698. // TODO Auto-generated catch block
  699. e.printStackTrace();
  700. }
  701. }
  702. break;
  703. case HCNetSDK.COMM_ALARM_VIDEO_INTERCOM: //可视对讲报警信息
  704. System.out.println("可视对讲报警触发");
  705. HCNetSDK.NET_DVR_VIDEO_INTERCOM_ALARM strVideoIntercomAlarm = new HCNetSDK.NET_DVR_VIDEO_INTERCOM_ALARM();
  706. strVideoIntercomAlarm.write();
  707. Pointer pVideoIntercomAlarm = strVideoIntercomAlarm.getPointer();
  708. pVideoIntercomAlarm.write(0, pAlarmInfo.getByteArray(0, strVideoIntercomAlarm.size()), 0, strVideoIntercomAlarm.size());
  709. strVideoIntercomAlarm.read();
  710. System.out.println("byAlarmType:" + strVideoIntercomAlarm.byAlarmType);
  711. if (strVideoIntercomAlarm.byAlarmType == 1) {
  712. strVideoIntercomAlarm.uAlarmInfo.setType(HCNetSDK.NET_DVR_VIDEO_INTERCOM_ALARM_INFO_UNION.class);
  713. strVideoIntercomAlarm.uAlarmInfo.read();
  714. System.out.println("byZoneType :" + strVideoIntercomAlarm.uAlarmInfo.struZoneAlarm.byZoneType);
  715. }
  716. break;
  717. case HCNetSDK.COMM_UPLOAD_VIDEO_INTERCOM_EVENT: //可视对讲事件记录信息
  718. System.out.println("可视对讲事件记录报警触发");
  719. HCNetSDK.NET_DVR_VIDEO_INTERCOM_EVENT strVideoIntercomEvent = new HCNetSDK.NET_DVR_VIDEO_INTERCOM_EVENT();
  720. strVideoIntercomEvent.write();
  721. Pointer pVideoIntercomEvent = strVideoIntercomEvent.getPointer();
  722. pVideoIntercomEvent.write(0, pAlarmInfo.getByteArray(0, strVideoIntercomEvent.size()), 0, strVideoIntercomEvent.size());
  723. strVideoIntercomEvent.read();
  724. System.out.println("byEventType:" + strVideoIntercomEvent.byEventType);
  725. if (strVideoIntercomEvent.byEventType == 1) {
  726. strVideoIntercomEvent.uEventInfo.setType(HCNetSDK.NET_DVR_UNLOCK_RECORD_INFO.class);
  727. strVideoIntercomEvent.uEventInfo.read();
  728. System.out.println("byUnlockType:" + strVideoIntercomEvent.uEventInfo.struUnlockRecord.byUnlockType
  729. + ",byControlSrc:" + new String(strVideoIntercomEvent.uEventInfo.struUnlockRecord.byControlSrc).trim());
  730. }
  731. break;
  732. case HCNetSDK.COMM_UPLOAD_FACESNAP_RESULT: //实时人脸抓拍上传
  733. System.out.println("UPLOAD_FACESNAP_Alarm");
  734. HCNetSDK.NET_VCA_FACESNAP_RESULT strFaceSnapInfo = new HCNetSDK.NET_VCA_FACESNAP_RESULT();
  735. strFaceSnapInfo.write();
  736. Pointer pFaceSnapInfo = strFaceSnapInfo.getPointer();
  737. pFaceSnapInfo.write(0, pAlarmInfo.getByteArray(0, strFaceSnapInfo.size()), 0, strFaceSnapInfo.size());
  738. strFaceSnapInfo.read();
  739. //事件时间
  740. int dwYear = (strFaceSnapInfo.dwAbsTime >> 26) + 2000;
  741. int dwMonth = (strFaceSnapInfo.dwAbsTime >> 22) & 15;
  742. int dwDay = (strFaceSnapInfo.dwAbsTime >> 17) & 31;
  743. int dwHour = (strFaceSnapInfo.dwAbsTime >> 12) & 31;
  744. int dwMinute = (strFaceSnapInfo.dwAbsTime >> 6) & 63;
  745. int dwSecond = (strFaceSnapInfo.dwAbsTime >> 0) & 63;
  746. String strAbsTime = "" + String.format("%04d", dwYear) +
  747. String.format("%02d", dwMonth) +
  748. String.format("%02d", dwDay) +
  749. String.format("%02d", dwHour) +
  750. String.format("%02d", dwMinute) +
  751. String.format("%02d", dwSecond);
  752. //人脸属性信息
  753. String sFaceAlarmInfo = "Abs时间:" + strAbsTime + ",年龄:" + strFaceSnapInfo.struFeature.byAge +
  754. ",性别:" + strFaceSnapInfo.struFeature.bySex + ",是否戴口罩:" +
  755. strFaceSnapInfo.struFeature.byMask + ",是否微笑:" + strFaceSnapInfo.struFeature.bySmile;
  756. System.out.println("人脸信息:" + sFaceAlarmInfo);
  757. //人脸测温信息
  758. if (strFaceSnapInfo.byAddInfo == 1) {
  759. HCNetSDK.NET_VCA_FACESNAP_ADDINFO strAddInfo = new HCNetSDK.NET_VCA_FACESNAP_ADDINFO();
  760. strAddInfo.write();
  761. Pointer pAddInfo = strAddInfo.getPointer();
  762. pAddInfo.write(0, strFaceSnapInfo.pAddInfoBuffer.getByteArray(0, strAddInfo.size()), 0, strAddInfo.size());
  763. strAddInfo.read();
  764. String sTemperatureInfo = "测温是否开启:" + strAddInfo.byFaceSnapThermometryEnabled + "人脸温度:" + strAddInfo.fFaceTemperature + "温度是否异常"
  765. + strAddInfo.byIsAbnomalTemperature + "报警温度阈值:" + strAddInfo.fAlarmTemperature;
  766. System.out.println("人脸温度信息:" + sTemperatureInfo);
  767. }
  768. try {
  769. SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");//设置日期格式
  770. String time = df.format(new Date());// new Date()为获取当前系统时间
  771. //人脸图片写文件
  772. FileOutputStream small = new FileOutputStream("../pic/" + time + "small.jpg");
  773. FileOutputStream big = new FileOutputStream("../pic/" + time + "big.jpg");
  774. try {
  775. small.write(strFaceSnapInfo.pBuffer1.getByteArray(0, strFaceSnapInfo.dwFacePicLen), 0, strFaceSnapInfo.dwFacePicLen);
  776. small.close();
  777. } catch (IOException ex) {
  778. ex.printStackTrace();
  779. }
  780. try {
  781. big.write(strFaceSnapInfo.pBuffer2.getByteArray(0, strFaceSnapInfo.dwBackgroundPicLen), 0, strFaceSnapInfo.dwBackgroundPicLen);
  782. big.close();
  783. } catch (IOException ex) {
  784. ex.printStackTrace();
  785. }
  786. } catch (FileNotFoundException ex) {
  787. ex.printStackTrace();
  788. }
  789. break;
  790. case HCNetSDK.COMM_SNAP_MATCH_ALARM: //人脸黑名单比对报警
  791. HCNetSDK.NET_VCA_FACESNAP_MATCH_ALARM strFaceSnapMatch = new HCNetSDK.NET_VCA_FACESNAP_MATCH_ALARM();
  792. strFaceSnapMatch.write();
  793. Pointer pFaceSnapMatch = strFaceSnapMatch.getPointer();
  794. pFaceSnapMatch.write(0, pAlarmInfo.getByteArray(0, strFaceSnapMatch.size()), 0, strFaceSnapMatch.size());
  795. strFaceSnapMatch.read();
  796. //比对结果,0-保留,1-比对成功,2-比对失败
  797. String sFaceSnapMatchInfo = "比对结果:" + strFaceSnapMatch.byContrastStatus + ",相似度:" + strFaceSnapMatch.fSimilarity;
  798. System.out.println(sFaceSnapMatchInfo);
  799. if (strFaceSnapMatch.struBlockListInfo.dwFDIDLen > 0) {
  800. long offset1 = 0;
  801. ByteBuffer buffers1 = strFaceSnapMatch.struBlockListInfo.pFDID.getByteBuffer(offset1, strFaceSnapMatch.struBlockListInfo.dwFDIDLen);
  802. byte[] bytes1 = new byte[strFaceSnapMatch.struBlockListInfo.dwFDIDLen];
  803. buffers1.get(bytes1);
  804. System.out.println("人脸库ID:" + new String(bytes1));
  805. }
  806. if (strFaceSnapMatch.struBlockListInfo.dwPIDLen > 0) {
  807. long offset2 = 0;
  808. ByteBuffer buffers2 = strFaceSnapMatch.struBlockListInfo.pPID.getByteBuffer(offset2, strFaceSnapMatch.struBlockListInfo.dwPIDLen);
  809. byte[] bytes2 = new byte[strFaceSnapMatch.struBlockListInfo.dwPIDLen];
  810. buffers2.get(bytes2);
  811. System.out.println("图片ID:" + new String(bytes2));
  812. }
  813. if (strFaceSnapMatch.struBlockListInfo.struBlockListInfo.dwFCAdditionInfoLen > 0) {
  814. //抓拍库附加信息解析(解析人脸测温温度,人脸温度存放在附件信息的XML报文中,节点: <currTemperature> )
  815. SimpleDateFormat sf2 = new SimpleDateFormat("yyyyMMddHHmmss");
  816. String curTime2 = sf2.format(new Date());
  817. FileOutputStream AddtionData;
  818. String AddtionFile = "../pic" + new String(pAlarmer.sDeviceIP).trim() + curTime2 + "_FCAdditionInfo_" + ".xml";
  819. try {
  820. Data = new FileOutputStream(AddtionFile);
  821. //将字节写入文件
  822. ByteBuffer dataBuffer = strFaceSnapMatch.struBlockListInfo.struBlockListInfo.pFCAdditionInfoBuffer.getByteBuffer(0, strFaceSnapMatch.struBlockListInfo.struBlockListInfo.dwFCAdditionInfoLen);
  823. byte[] dataByte = new byte[dwBufLen];
  824. dataBuffer.rewind();
  825. dataBuffer.get(dataByte);
  826. Data.write(dataByte);
  827. Data.close();
  828. } catch (FileNotFoundException e) {
  829. e.printStackTrace();
  830. } catch (IOException e) {
  831. e.printStackTrace();
  832. }
  833. }
  834. //人脸比对报警图片保存,图片格式二进制
  835. if ((strFaceSnapMatch.dwSnapPicLen > 0) && (strFaceSnapMatch.byPicTransType == 0)) {
  836. SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
  837. String newName = sf.format(new Date());
  838. FileOutputStream fout;
  839. try {
  840. String filename = "../pic/" + newName + "_pSnapPicBuffer" + ".jpg";
  841. fout = new FileOutputStream(filename);
  842. //将字节写入文件
  843. long offset = 0;
  844. ByteBuffer buffers = strFaceSnapMatch.pSnapPicBuffer.getByteBuffer(offset, strFaceSnapMatch.dwSnapPicLen);
  845. byte[] bytes = new byte[strFaceSnapMatch.dwSnapPicLen];
  846. buffers.rewind();
  847. buffers.get(bytes);
  848. fout.write(bytes);
  849. fout.close();
  850. } catch (FileNotFoundException e) {
  851. // TODO Auto-generated catch block
  852. e.printStackTrace();
  853. } catch (IOException e) {
  854. // TODO Auto-generated catch block
  855. e.printStackTrace();
  856. }
  857. }
  858. if ((strFaceSnapMatch.struSnapInfo.dwSnapFacePicLen > 0) && (strFaceSnapMatch.byPicTransType == 0)) {
  859. SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
  860. String newName = sf.format(new Date());
  861. FileOutputStream fout;
  862. try {
  863. String filename = "../pic/" + newName + "_struSnapInfo_pBuffer1" + ".jpg";
  864. fout = new FileOutputStream(filename);
  865. //将字节写入文件
  866. long offset = 0;
  867. ByteBuffer buffers = strFaceSnapMatch.struSnapInfo.pBuffer1.getByteBuffer(offset, strFaceSnapMatch.struSnapInfo.dwSnapFacePicLen);
  868. byte[] bytes = new byte[strFaceSnapMatch.struSnapInfo.dwSnapFacePicLen];
  869. buffers.rewind();
  870. buffers.get(bytes);
  871. fout.write(bytes);
  872. fout.close();
  873. } catch (FileNotFoundException e) {
  874. // TODO Auto-generated catch block
  875. e.printStackTrace();
  876. } catch (IOException e) {
  877. // TODO Auto-generated catch block
  878. e.printStackTrace();
  879. }
  880. }
  881. if ((strFaceSnapMatch.struBlockListInfo.dwBlockListPicLen > 0) && (strFaceSnapMatch.byPicTransType == 0)) {
  882. SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
  883. String newName = sf.format(new Date());
  884. FileOutputStream fout;
  885. try {
  886. String filename = "../pic/" + newName + "_fSimilarity_" + strFaceSnapMatch.fSimilarity + "_struBlackListInfo_pBuffer1" + ".jpg";
  887. fout = new FileOutputStream(filename);
  888. //将字节写入文件
  889. long offset = 0;
  890. ByteBuffer buffers = strFaceSnapMatch.struBlockListInfo.pBuffer1.getByteBuffer(offset, strFaceSnapMatch.struBlockListInfo.dwBlockListPicLen);
  891. byte[] bytes = new byte[strFaceSnapMatch.struBlockListInfo.dwBlockListPicLen];
  892. buffers.rewind();
  893. buffers.get(bytes);
  894. fout.write(bytes);
  895. fout.close();
  896. } catch (FileNotFoundException e) {
  897. // TODO Auto-generated catch block
  898. e.printStackTrace();
  899. } catch (IOException e) {
  900. // TODO Auto-generated catch block
  901. e.printStackTrace();
  902. }
  903. }
  904. //人脸比对报警图片保存,图片格式URL格式
  905. if ((strFaceSnapMatch.dwSnapPicLen > 0) && (strFaceSnapMatch.byPicTransType == 1)) {
  906. long offset = 0;
  907. ByteBuffer buffers = strFaceSnapMatch.pSnapPicBuffer.getByteBuffer(offset, strFaceSnapMatch.dwSnapPicLen);
  908. byte[] bytes = new byte[strFaceSnapMatch.dwSnapPicLen];
  909. buffers.rewind();
  910. buffers.get(bytes);
  911. String SnapPicUrl = new String(bytes);
  912. System.out.println("抓拍图URL:" + SnapPicUrl);
  913. }
  914. if ((strFaceSnapMatch.struSnapInfo.dwSnapFacePicLen > 0) && (strFaceSnapMatch.byPicTransType == 1)) {
  915. long offset = 0;
  916. ByteBuffer buffers = strFaceSnapMatch.struSnapInfo.pBuffer1.getByteBuffer(offset, strFaceSnapMatch.struSnapInfo.dwSnapFacePicLen);
  917. byte[] bytes = new byte[strFaceSnapMatch.struSnapInfo.dwSnapFacePicLen];
  918. buffers.rewind();
  919. buffers.get(bytes);
  920. String SnapPicUrl = new String(bytes);
  921. System.out.println("抓拍人脸子图URL:" + SnapPicUrl);
  922. }
  923. if ((strFaceSnapMatch.struBlockListInfo.dwBlockListPicLen > 0) && (strFaceSnapMatch.byPicTransType == 1)) {
  924. long offset = 0;
  925. ByteBuffer buffers = strFaceSnapMatch.struBlockListInfo.pBuffer1.getByteBuffer(offset, strFaceSnapMatch.struBlockListInfo.dwBlockListPicLen);
  926. byte[] bytes = new byte[strFaceSnapMatch.struBlockListInfo.dwBlockListPicLen];
  927. buffers.rewind();
  928. buffers.get(bytes);
  929. String SnapPicUrl = new String(bytes);
  930. System.out.println("人脸库人脸图的URL:" + SnapPicUrl);
  931. }
  932. break;
  933. // 客流量报警信息
  934. case HCNetSDK.COMM_ALARM_PDC:
  935. HCNetSDK.NET_DVR_PDC_ALRAM_INFO strPDCResult = new HCNetSDK.NET_DVR_PDC_ALRAM_INFO();
  936. strPDCResult.write();
  937. Pointer pPDCInfo = strPDCResult.getPointer();
  938. pPDCInfo.write(0, pAlarmInfo.getByteArray(0, strPDCResult.size()), 0, strPDCResult.size());
  939. strPDCResult.read();
  940. // byMode=0-实时统计结果(联合体中struStatFrame有效),
  941. if (strPDCResult.byMode == 0) {
  942. strPDCResult.uStatModeParam.setType(HCNetSDK.NET_DVR_STATFRAME.class);
  943. String sAlarmPDC0Info = "实时客流量统计,进入人数:" + strPDCResult.dwEnterNum + ",离开人数:" + strPDCResult.dwLeaveNum +
  944. ", byMode:" + strPDCResult.byMode + ", dwRelativeTime:" + strPDCResult.uStatModeParam.struStatFrame.dwRelativeTime +
  945. ", dwAbsTime:" + strPDCResult.uStatModeParam.struStatFrame.dwAbsTime;
  946. }
  947. // byMode=1-周期统计结果(联合体中struStatTime有效),
  948. if (strPDCResult.byMode == 1) {
  949. strPDCResult.uStatModeParam.setType(HCNetSDK.NET_DVR_STATTIME.class);
  950. String strtmStart = "" + String.format("%04d", strPDCResult.uStatModeParam.struStatTime.tmStart.dwYear) +
  951. String.format("%02d", strPDCResult.uStatModeParam.struStatTime.tmStart.dwMonth) +
  952. String.format("%02d", strPDCResult.uStatModeParam.struStatTime.tmStart.dwDay) +
  953. String.format("%02d", strPDCResult.uStatModeParam.struStatTime.tmStart.dwHour) +
  954. String.format("%02d", strPDCResult.uStatModeParam.struStatTime.tmStart.dwMinute) +
  955. String.format("%02d", strPDCResult.uStatModeParam.struStatTime.tmStart.dwSecond);
  956. String strtmEnd = "" + String.format("%04d", strPDCResult.uStatModeParam.struStatTime.tmEnd.dwYear) +
  957. String.format("%02d", strPDCResult.uStatModeParam.struStatTime.tmEnd.dwMonth) +
  958. String.format("%02d", strPDCResult.uStatModeParam.struStatTime.tmEnd.dwDay) +
  959. String.format("%02d", strPDCResult.uStatModeParam.struStatTime.tmEnd.dwHour) +
  960. String.format("%02d", strPDCResult.uStatModeParam.struStatTime.tmEnd.dwMinute) +
  961. String.format("%02d", strPDCResult.uStatModeParam.struStatTime.tmEnd.dwSecond);
  962. String sAlarmPDC1Info = "周期性客流量统计,进入人数:" + strPDCResult.dwEnterNum + ",离开人数:" + strPDCResult.dwLeaveNum +
  963. ", byMode:" + strPDCResult.byMode + ", tmStart:" + strtmStart + ",tmEnd :" + strtmEnd;
  964. }
  965. break;
  966. case HCNetSDK.COMM_ALARM_V30: //移动侦测、视频丢失、遮挡、IO信号量等报警信息(V3.0以上版本支持的设备)
  967. HCNetSDK.NET_DVR_ALARMINFO_V30 struAlarmInfo = new HCNetSDK.NET_DVR_ALARMINFO_V30();
  968. struAlarmInfo.write();
  969. Pointer pAlarmInfo_V30 = struAlarmInfo.getPointer();
  970. pAlarmInfo_V30.write(0, pAlarmInfo.getByteArray(0, struAlarmInfo.size()), 0, struAlarmInfo.size());
  971. struAlarmInfo.read();
  972. System.out.println("报警类型:" + struAlarmInfo.dwAlarmType); // 3-移动侦测
  973. break;
  974. case HCNetSDK.COMM_ALARM_V40: //移动侦测、视频丢失、遮挡、IO信号量等报警信息,报警数据为可变长
  975. HCNetSDK.NET_DVR_ALARMINFO_V40 struAlarmInfoV40 = new HCNetSDK.NET_DVR_ALARMINFO_V40();
  976. struAlarmInfoV40.write();
  977. Pointer pAlarmInfoV40 = struAlarmInfoV40.getPointer();
  978. pAlarmInfoV40.write(0, pAlarmInfo.getByteArray(0, struAlarmInfoV40.size()), 0, struAlarmInfoV40.size());
  979. struAlarmInfoV40.read();
  980. System.out.println("报警类型:" + struAlarmInfoV40.struAlarmFixedHeader.dwAlarmType); //3-移动侦测
  981. break;
  982. case HCNetSDK.COMM_THERMOMETRY_ALARM: //温度报警信息
  983. HCNetSDK.NET_DVR_THERMOMETRY_ALARM struTemInfo = new HCNetSDK.NET_DVR_THERMOMETRY_ALARM();
  984. struTemInfo.write();
  985. Pointer pTemInfo = struTemInfo.getPointer();
  986. pTemInfo.write(0, pAlarmInfo.getByteArray(0, struTemInfo.size()), 0, struTemInfo.size());
  987. struTemInfo.read();
  988. String sThermAlarmInfo = "规则ID:" + struTemInfo.byRuleID + "预置点号:" + struTemInfo.wPresetNo + "报警等级:" + struTemInfo.byAlarmLevel + "报警类型:" +
  989. struTemInfo.byAlarmType + "当前温度:" + struTemInfo.fCurrTemperature;
  990. System.out.println(sThermAlarmInfo);
  991. //可见光图片保存
  992. if ((struTemInfo.dwPicLen > 0) && (struTemInfo.byPicTransType == 0)) {
  993. SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
  994. String newName = sf.format(new Date());
  995. FileOutputStream fout;
  996. try {
  997. String filename = "../pic/" + newName + "_" + struTemInfo.fCurrTemperature + ".jpg";
  998. fout = new FileOutputStream(filename);
  999. //将字节写入文件
  1000. long offset = 0;
  1001. ByteBuffer buffers = struTemInfo.pPicBuff.getByteBuffer(offset, struTemInfo.dwPicLen);
  1002. byte[] bytes = new byte[struTemInfo.dwPicLen];
  1003. buffers.rewind();
  1004. buffers.get(bytes);
  1005. fout.write(bytes);
  1006. fout.close();
  1007. } catch (FileNotFoundException e) {
  1008. // TODO Auto-generated catch block
  1009. e.printStackTrace();
  1010. } catch (IOException e) {
  1011. // TODO Auto-generated catch block
  1012. e.printStackTrace();
  1013. }
  1014. }
  1015. if ((struTemInfo.dwThermalPicLen > 0) && (struTemInfo.byPicTransType == 0)) {
  1016. SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
  1017. String newName = sf.format(new Date());
  1018. FileOutputStream fout;
  1019. try {
  1020. String filename = "../pic/" + newName + "_" + "_ThermalPiC" + ".jpg";
  1021. fout = new FileOutputStream(filename);
  1022. //将字节写入文件
  1023. long offset = 0;
  1024. ByteBuffer buffers = struTemInfo.pThermalPicBuff.getByteBuffer(offset, struTemInfo.dwThermalPicLen);
  1025. byte[] bytes = new byte[struTemInfo.dwThermalPicLen];
  1026. buffers.rewind();
  1027. buffers.get(bytes);
  1028. fout.write(bytes);
  1029. fout.close();
  1030. } catch (FileNotFoundException e) {
  1031. // TODO Auto-generated catch block
  1032. e.printStackTrace();
  1033. } catch (IOException e) {
  1034. // TODO Auto-generated catch block
  1035. e.printStackTrace();
  1036. }
  1037. }
  1038. break;
  1039. case HCNetSDK.COMM_THERMOMETRY_DIFF_ALARM: //温差检测报警
  1040. HCNetSDK.NET_DVR_THERMOMETRY_DIFF_ALARM strThermDiffAlarm = new HCNetSDK.NET_DVR_THERMOMETRY_DIFF_ALARM();
  1041. strThermDiffAlarm.write();
  1042. Pointer pTemDiffInfo = strThermDiffAlarm.getPointer();
  1043. pTemDiffInfo.write(0, pAlarmInfo.getByteArray(0, strThermDiffAlarm.size()), 0, strThermDiffAlarm.size());
  1044. strThermDiffAlarm.read();
  1045. String sThremDiffInfo = "通道号:" + strThermDiffAlarm.dwChannel + ",报警规则:" + strThermDiffAlarm.byAlarmRule + ",当前温差:" + strThermDiffAlarm.fCurTemperatureDiff;
  1046. System.out.println(sThremDiffInfo);
  1047. //可见光图片保存
  1048. if ((strThermDiffAlarm.dwPicLen > 0) && (strThermDiffAlarm.byPicTransType == 0)) {
  1049. SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
  1050. String newName = sf.format(new Date());
  1051. FileOutputStream fout;
  1052. try {
  1053. String filename = "../pic/" + newName + "_" + strThermDiffAlarm.fCurTemperatureDiff + ".jpg";
  1054. fout = new FileOutputStream(filename);
  1055. //将字节写入文件
  1056. long offset = 0;
  1057. ByteBuffer buffers = strThermDiffAlarm.pPicBuff.getByteBuffer(offset, strThermDiffAlarm.dwPicLen);
  1058. byte[] bytes = new byte[strThermDiffAlarm.dwPicLen];
  1059. buffers.rewind();
  1060. buffers.get(bytes);
  1061. fout.write(bytes);
  1062. fout.close();
  1063. } catch (FileNotFoundException e) {
  1064. // TODO Auto-generated catch block
  1065. e.printStackTrace();
  1066. } catch (IOException e) {
  1067. // TODO Auto-generated catch block
  1068. e.printStackTrace();
  1069. }
  1070. }
  1071. //热成像图片保存
  1072. if ((strThermDiffAlarm.dwThermalPicLen > 0) && (strThermDiffAlarm.byPicTransType == 0)) {
  1073. SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
  1074. String newName = sf.format(new Date());
  1075. FileOutputStream fout;
  1076. try {
  1077. String filename = "../pic/" + newName + "_" + "_ThermalDiffPiC" + ".jpg";
  1078. fout = new FileOutputStream(filename);
  1079. //将字节写入文件
  1080. long offset = 0;
  1081. ByteBuffer buffers = strThermDiffAlarm.pThermalPicBuff.getByteBuffer(offset, strThermDiffAlarm.dwThermalPicLen);
  1082. byte[] bytes = new byte[strThermDiffAlarm.dwThermalPicLen];
  1083. buffers.rewind();
  1084. buffers.get(bytes);
  1085. fout.write(bytes);
  1086. fout.close();
  1087. } catch (FileNotFoundException e) {
  1088. // TODO Auto-generated catch block
  1089. e.printStackTrace();
  1090. } catch (IOException e) {
  1091. // TODO Auto-generated catch block
  1092. e.printStackTrace();
  1093. }
  1094. }
  1095. break;
  1096. case HCNetSDK.COMM_ALARM_SHIPSDETECTION: //船只检测报警
  1097. HCNetSDK.NET_DVR_SHIPSDETECTION_ALARM struShipAlarm = new HCNetSDK.NET_DVR_SHIPSDETECTION_ALARM();
  1098. struShipAlarm.write();
  1099. Pointer pShipAlarm = struShipAlarm.getPointer();
  1100. pShipAlarm.write(0, pAlarmInfo.getByteArray(0, struShipAlarm.size()), 0, struShipAlarm.size());
  1101. struShipAlarm.read();
  1102. String sShipAlarm = "绝对时间:" + struShipAlarm.dwAbsTime + ",正跨越检测线的船只数:" + struShipAlarm.byShipsNum + ",船头检测的船只数 :" + struShipAlarm.byShipsNumHead
  1103. + ", 船尾检测的船只数 :" + struShipAlarm.byShipsNumEnd;
  1104. System.out.println(sShipAlarm);
  1105. //可见光图片保存
  1106. if ((struShipAlarm.dwPicLen > 0) && (struShipAlarm.byPicTransType == 0)) {
  1107. SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
  1108. String newName = sf.format(new Date());
  1109. FileOutputStream fout;
  1110. try {
  1111. String filename = "../pic/" + newName + "_ShipAlarm" + ".jpg";
  1112. fout = new FileOutputStream(filename);
  1113. //将字节写入文件
  1114. long offset = 0;
  1115. ByteBuffer buffers = struShipAlarm.pPicBuffer.getByteBuffer(offset, struShipAlarm.dwPicLen);
  1116. byte[] bytes = new byte[struShipAlarm.dwPicLen];
  1117. buffers.rewind();
  1118. buffers.get(bytes);
  1119. fout.write(bytes);
  1120. fout.close();
  1121. } catch (FileNotFoundException e) {
  1122. // TODO Auto-generated catch block
  1123. e.printStackTrace();
  1124. } catch (IOException e) {
  1125. // TODO Auto-generated catch block
  1126. e.printStackTrace();
  1127. }
  1128. }
  1129. //热成像图片保存
  1130. if ((struShipAlarm.dwThermalPicLen > 0) && (struShipAlarm.byPicTransType == 0)) {
  1131. SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
  1132. String newName = sf.format(new Date());
  1133. FileOutputStream fout;
  1134. try {
  1135. String filename = "../pic/" + newName + "_" + "_ThermalShipAlarm" + ".jpg";
  1136. fout = new FileOutputStream(filename);
  1137. //将字节写入文件
  1138. long offset = 0;
  1139. ByteBuffer buffers = struShipAlarm.pThermalPicBuffer.getByteBuffer(offset, struShipAlarm.dwThermalPicLen);
  1140. byte[] bytes = new byte[struShipAlarm.dwThermalPicLen];
  1141. buffers.rewind();
  1142. buffers.get(bytes);
  1143. fout.write(bytes);
  1144. fout.close();
  1145. } catch (FileNotFoundException e) {
  1146. // TODO Auto-generated catch block
  1147. e.printStackTrace();
  1148. } catch (IOException e) {
  1149. // TODO Auto-generated catch block
  1150. e.printStackTrace();
  1151. }
  1152. }
  1153. break;
  1154. case HCNetSDK.COMM_FIREDETECTION_ALARM://烟火检测
  1155. HCNetSDK.NET_DVR_FIREDETECTION_ALARM struFireDecAlarm = new HCNetSDK.NET_DVR_FIREDETECTION_ALARM();
  1156. struFireDecAlarm.write();
  1157. Pointer pFireDecAlarm = struFireDecAlarm.getPointer();
  1158. pFireDecAlarm.write(0, pAlarmInfo.getByteArray(0, struFireDecAlarm.size()), 0, struFireDecAlarm.size());
  1159. struFireDecAlarm.read();
  1160. String sFireDecAlarmInfo = "绝对时间:" + struFireDecAlarm.dwAbsTime + ",报警子类型:" + struFireDecAlarm.byAlarmSubType + ",火点最高温度 :" +
  1161. struFireDecAlarm.wFireMaxTemperature + ",火点目标距离:" + struFireDecAlarm.wTargetDistance;
  1162. System.out.println(sFireDecAlarmInfo);
  1163. //可见光图片保存
  1164. if ((struFireDecAlarm.dwVisiblePicLen > 0) && (struFireDecAlarm.byPicTransType == 0)) {
  1165. SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
  1166. String newName = sf.format(new Date());
  1167. FileOutputStream fout;
  1168. try {
  1169. String filename = "../pic/" + newName + "_FireDecAlarm" + ".jpg";
  1170. fout = new FileOutputStream(filename);
  1171. //将字节写入文件
  1172. long offset = 0;
  1173. ByteBuffer buffers = struFireDecAlarm.pVisiblePicBuf.getByteBuffer(offset, struFireDecAlarm.dwVisiblePicLen);
  1174. byte[] bytes = new byte[struFireDecAlarm.dwVisiblePicLen];
  1175. buffers.rewind();
  1176. buffers.get(bytes);
  1177. fout.write(bytes);
  1178. fout.close();
  1179. } catch (FileNotFoundException e) {
  1180. // TODO Auto-generated catch block
  1181. e.printStackTrace();
  1182. } catch (IOException e) {
  1183. // TODO Auto-generated catch block
  1184. e.printStackTrace();
  1185. }
  1186. }
  1187. //热成像图片保存
  1188. if ((struFireDecAlarm.dwPicDataLen > 0) && (struFireDecAlarm.byPicTransType == 0)) {
  1189. SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss");
  1190. String newName = sf.format(new Date());
  1191. FileOutputStream fout;
  1192. try {
  1193. String filename = "../pic/" + newName + "_" + "_ThermalFireAlarm" + ".jpg";
  1194. fout = new FileOutputStream(filename);
  1195. //将字节写入文件
  1196. long offset = 0;
  1197. ByteBuffer buffers = struFireDecAlarm.pBuffer.getByteBuffer(offset, struFireDecAlarm.dwPicDataLen);
  1198. byte[] bytes = new byte[struFireDecAlarm.dwPicDataLen];
  1199. buffers.rewind();
  1200. buffers.get(bytes);
  1201. fout.write(bytes);
  1202. fout.close();
  1203. } catch (FileNotFoundException e) {
  1204. // TODO Auto-generated catch block
  1205. e.printStackTrace();
  1206. } catch (IOException e) {
  1207. // TODO Auto-generated catch block
  1208. e.printStackTrace();
  1209. }
  1210. }
  1211. break;
  1212. case HCNetSDK.COMM_UPLOAD_AIOP_VIDEO: //AI开放平台接入视频检测报警信息
  1213. System.out.println("AI开放平台接入视频检测报警上传");
  1214. HCNetSDK.NET_AIOP_VIDEO_HEAD struAIOPVideo = new HCNetSDK.NET_AIOP_VIDEO_HEAD();
  1215. struAIOPVideo.write();
  1216. Pointer pAIOPVideo = struAIOPVideo.getPointer();
  1217. pAIOPVideo.write(0, pAlarmInfo.getByteArray(0, struAIOPVideo.size()), 0, struAIOPVideo.size());
  1218. struAIOPVideo.read();
  1219. System.out.println("视频任务ID" + new String(struAIOPVideo.szTaskID));
  1220. System.out.println("通道号:" + struAIOPVideo.dwChannel);
  1221. System.out.println("检测模型包ID" + new String(struAIOPVideo.szMPID));
  1222. String strTime = String.format("%04d", struAIOPVideo.struTime.wYear) +
  1223. String.format("%02d", struAIOPVideo.struTime.wMonth) +
  1224. String.format("%02d", struAIOPVideo.struTime.wDay) +
  1225. String.format("%02d", struAIOPVideo.struTime.wHour) +
  1226. String.format("%02d", struAIOPVideo.struTime.wMinute) +
  1227. String.format("%02d", struAIOPVideo.struTime.wSecond) +
  1228. String.format("%03d", struAIOPVideo.struTime.wMilliSec);
  1229. //AIOPData数据
  1230. if (struAIOPVideo.dwAIOPDataSize > 0) {
  1231. FileOutputStream fout;
  1232. try {
  1233. String filename = "../pic/" + new String(pAlarmer.sDeviceIP).trim() +
  1234. "_" + strTime + "_VideoData.json";
  1235. fout = new FileOutputStream(filename);
  1236. //将字节写入文件
  1237. long offset = 0;
  1238. ByteBuffer buffers = struAIOPVideo.pBufferAIOPData.getByteBuffer(offset, struAIOPVideo.dwAIOPDataSize);
  1239. byte[] bytes = new byte[struAIOPVideo.dwAIOPDataSize];
  1240. buffers.rewind();
  1241. buffers.get(bytes);
  1242. fout.write(bytes);
  1243. fout.close();
  1244. } catch (FileNotFoundException e) {
  1245. // TODO Auto-generated catch block
  1246. e.printStackTrace();
  1247. } catch (IOException e) {
  1248. // TODO Auto-generated catch block
  1249. e.printStackTrace();
  1250. }
  1251. }
  1252. //图片数据保存
  1253. if (struAIOPVideo.dwPictureSize > 0) {
  1254. FileOutputStream fout;
  1255. try {
  1256. String filename = "../pic/" + new String(pAlarmer.sDeviceIP).trim() +
  1257. "_" + strTime + "_VideoPic.jpg";
  1258. fout = new FileOutputStream(filename);
  1259. //将字节写入文件
  1260. long offset = 0;
  1261. ByteBuffer buffers = struAIOPVideo.pBufferPicture.getByteBuffer(offset, struAIOPVideo.dwPictureSize);
  1262. byte[] bytes = new byte[struAIOPVideo.dwPictureSize];
  1263. buffers.rewind();
  1264. buffers.get(bytes);
  1265. fout.write(bytes);
  1266. fout.close();
  1267. } catch (FileNotFoundException e) {
  1268. // TODO Auto-generated catch block
  1269. e.printStackTrace();
  1270. } catch (IOException e) {
  1271. // TODO Auto-generated catch block
  1272. e.printStackTrace();
  1273. }
  1274. }
  1275. break;
  1276. case HCNetSDK.COMM_UPLOAD_AIOP_PICTURE: //AI开放平台接入图片检测报警信息
  1277. System.out.println("AI开放平台接入图片检测报警上传");
  1278. HCNetSDK.NET_AIOP_PICTURE_HEAD struAIOPPic = new HCNetSDK.NET_AIOP_PICTURE_HEAD();
  1279. struAIOPPic.write();
  1280. Pointer pAIOPPic = struAIOPPic.getPointer();
  1281. pAIOPPic.write(0, pAlarmInfo.getByteArray(0, struAIOPPic.size()), 0, struAIOPPic.size());
  1282. struAIOPPic.read();
  1283. System.out.println("图片ID:" + new String(struAIOPPic.szPID));
  1284. System.out.println("检测模型包ID:" + new String(struAIOPPic.szMPID));
  1285. String strPicTime = "" + String.format("%04d", struAIOPPic.struTime.wYear) +
  1286. String.format("%02d", struAIOPPic.struTime.wMonth) +
  1287. String.format("%02d", struAIOPPic.struTime.wDay) +
  1288. String.format("%02d", struAIOPPic.struTime.wHour) +
  1289. String.format("%02d", struAIOPPic.struTime.wMinute) +
  1290. String.format("%02d", struAIOPPic.struTime.wSecond) +
  1291. String.format("%03d", struAIOPPic.struTime.wMilliSec);
  1292. //AIOPData数据
  1293. if (struAIOPPic.dwAIOPDataSize > 0) {
  1294. FileOutputStream fout;
  1295. try {
  1296. String filename = "../pic/" + new String(pAlarmer.sDeviceIP).trim() +
  1297. "_" + strPicTime + "_AIO_PicData.json";
  1298. fout = new FileOutputStream(filename);
  1299. //将字节写入文件
  1300. long offset = 0;
  1301. ByteBuffer buffers = struAIOPPic.pBufferAIOPData.getByteBuffer(offset, struAIOPPic.dwAIOPDataSize);
  1302. byte[] bytes = new byte[struAIOPPic.dwAIOPDataSize];
  1303. buffers.rewind();
  1304. buffers.get(bytes);
  1305. fout.write(bytes);
  1306. fout.close();
  1307. } catch (FileNotFoundException e) {
  1308. // TODO Auto-generated catch block
  1309. e.printStackTrace();
  1310. } catch (IOException e) {
  1311. // TODO Auto-generated catch block
  1312. e.printStackTrace();
  1313. }
  1314. }
  1315. break;
  1316. //AI开放平台接入轮询抓图检测报警信息
  1317. case HCNetSDK.COMM_UPLOAD_AIOP_POLLING_SNAP:
  1318. System.out.println("AI开放平台接入轮询抓图检测报警事件上传");
  1319. HCNetSDK.NET_AIOP_POLLING_SNAP_HEAD strAiopPollingPic = new HCNetSDK.NET_AIOP_POLLING_SNAP_HEAD();
  1320. strAiopPollingPic.write();
  1321. Pointer pAiopPollingPic = strAiopPollingPic.getPointer();
  1322. pAiopPollingPic.write(0, pAlarmInfo.getByteArray(0, strAiopPollingPic.size()), 0, strAiopPollingPic.size());
  1323. strAiopPollingPic.read();
  1324. System.out.println("通道号:" + strAiopPollingPic.dwChannel);
  1325. System.out.println("轮询抓图任务ID:" + new String(strAiopPollingPic.szTaskID));
  1326. String strPollingPicTime = "" + String.format("%04d", strAiopPollingPic.struTime.wYear) +
  1327. String.format("%02d", strAiopPollingPic.struTime.wMonth) +
  1328. String.format("%02d", strAiopPollingPic.struTime.wDay) +
  1329. String.format("%02d", strAiopPollingPic.struTime.wHour) +
  1330. String.format("%02d", strAiopPollingPic.struTime.wMinute) +
  1331. String.format("%02d", strAiopPollingPic.struTime.wSecond) +
  1332. String.format("%03d", strAiopPollingPic.struTime.wMilliSec);
  1333. //AIOPData数据保存
  1334. if (strAiopPollingPic.dwAIOPDataSize > 0) {
  1335. FileOutputStream fout;
  1336. try {
  1337. String filename = "../pic/" + new String(pAlarmer.sDeviceIP).trim() +
  1338. "_" + strPollingPicTime + "_PollingPicData.json";
  1339. fout = new FileOutputStream(filename);
  1340. //将字节写入文件
  1341. long offset = 0;
  1342. ByteBuffer buffers = strAiopPollingPic.pBufferAIOPData.getByteBuffer(offset, strAiopPollingPic.dwAIOPDataSize);
  1343. byte[] bytes = new byte[strAiopPollingPic.dwAIOPDataSize];
  1344. buffers.rewind();
  1345. buffers.get(bytes);
  1346. fout.write(bytes);
  1347. fout.close();
  1348. } catch (FileNotFoundException e) {
  1349. // TODO Auto-generated catch block
  1350. e.printStackTrace();
  1351. } catch (IOException e) {
  1352. // TODO Auto-generated catch block
  1353. e.printStackTrace();
  1354. }
  1355. }
  1356. //轮询抓图图片保存
  1357. if (strAiopPollingPic.dwPictureSize > 0) {
  1358. FileOutputStream fout;
  1359. try {
  1360. String filename = "../pic/" + new String(pAlarmer.sDeviceIP).trim() +
  1361. "_" + strPollingPicTime + "_PollingPic.jpg";
  1362. fout = new FileOutputStream(filename);
  1363. //将字节写入文件
  1364. long offset = 0;
  1365. ByteBuffer buffers = strAiopPollingPic.pBufferPicture.getByteBuffer(offset, strAiopPollingPic.dwPictureSize);
  1366. byte[] bytes = new byte[strAiopPollingPic.dwPictureSize];
  1367. buffers.rewind();
  1368. buffers.get(bytes);
  1369. fout.write(bytes);
  1370. fout.close();
  1371. } catch (FileNotFoundException e) {
  1372. // TODO Auto-generated catch block
  1373. e.printStackTrace();
  1374. } catch (IOException e) {
  1375. // TODO Auto-generated catch block
  1376. e.printStackTrace();
  1377. }
  1378. }
  1379. break;
  1380. //AI开放平台接入轮询视频检测报警信息
  1381. case HCNetSDK.COMM_UPLOAD_AIOP_POLLING_VIDEO:
  1382. System.out.println("AI开放平台接入轮询视频检测报警事件上传");
  1383. HCNetSDK.NET_AIOP_POLLING_VIDEO_HEAD strAiopPollingVideo = new HCNetSDK.NET_AIOP_POLLING_VIDEO_HEAD();
  1384. strAiopPollingVideo.write();
  1385. Pointer pAiopPollingVideo = strAiopPollingVideo.getPointer();
  1386. pAiopPollingVideo.write(0, pAlarmInfo.getByteArray(0, strAiopPollingVideo.size()), 0, strAiopPollingVideo.size());
  1387. strAiopPollingVideo.read();
  1388. System.out.println("通道号:" + strAiopPollingVideo.dwChannel);
  1389. System.out.println("轮询视频任务ID:" + new String(strAiopPollingVideo.szTaskID));
  1390. String AiopPollingVideoTime = "" + String.format("%04d", strAiopPollingVideo.struTime.wYear) +
  1391. String.format("%02d", strAiopPollingVideo.struTime.wMonth) +
  1392. String.format("%02d", strAiopPollingVideo.struTime.wDay) +
  1393. String.format("%02d", strAiopPollingVideo.struTime.wHour) +
  1394. String.format("%02d", strAiopPollingVideo.struTime.wMinute) +
  1395. String.format("%02d", strAiopPollingVideo.struTime.wSecond) +
  1396. String.format("%03d", strAiopPollingVideo.struTime.wMilliSec);
  1397. //AIOPData数据保存
  1398. if (strAiopPollingVideo.dwAIOPDataSize > 0) {
  1399. FileOutputStream fout;
  1400. try {
  1401. String filename = "../pic/" + new String(pAlarmer.sDeviceIP).trim() +
  1402. "_" + AiopPollingVideoTime + "_PollingVideoData.json";
  1403. fout = new FileOutputStream(filename);
  1404. //将字节写入文件
  1405. long offset = 0;
  1406. ByteBuffer buffers = strAiopPollingVideo.pBufferAIOPData.getByteBuffer(offset, strAiopPollingVideo.dwAIOPDataSize);
  1407. byte[] bytes = new byte[strAiopPollingVideo.dwAIOPDataSize];
  1408. buffers.rewind();
  1409. buffers.get(bytes);
  1410. fout.write(bytes);
  1411. fout.close();
  1412. } catch (FileNotFoundException e) {
  1413. // TODO Auto-generated catch block
  1414. e.printStackTrace();
  1415. } catch (IOException e) {
  1416. // TODO Auto-generated catch block
  1417. e.printStackTrace();
  1418. }
  1419. }
  1420. //对应分析图片数据
  1421. if (strAiopPollingVideo.dwPictureSize > 0) {
  1422. FileOutputStream fout;
  1423. try {
  1424. String filename = "../pic/" + new String(pAlarmer.sDeviceIP).trim() +
  1425. "_" + AiopPollingVideoTime + "_PollingVideo.jpg";
  1426. fout = new FileOutputStream(filename);
  1427. //将字节写入文件
  1428. long offset = 0;
  1429. ByteBuffer buffers = strAiopPollingVideo.pBufferPicture.getByteBuffer(offset, strAiopPollingVideo.dwPictureSize);
  1430. byte[] bytes = new byte[strAiopPollingVideo.dwPictureSize];
  1431. buffers.rewind();
  1432. buffers.get(bytes);
  1433. fout.write(bytes);
  1434. fout.close();
  1435. } catch (FileNotFoundException e) {
  1436. // TODO Auto-generated catch block
  1437. e.printStackTrace();
  1438. } catch (IOException e) {
  1439. // TODO Auto-generated catch block
  1440. e.printStackTrace();
  1441. }
  1442. }
  1443. break;
  1444. default:
  1445. System.out.println("报警类型" + Integer.toHexString(lCommand));
  1446. break;
  1447. }
  1448. }
  1449. }