diff --git a/src/main/java/com/hkversion/AlarmDataParse.java b/src/main/java/com/hkversion/AlarmDataParse.java index 822fe2a..fdcb08a 100644 --- a/src/main/java/com/hkversion/AlarmDataParse.java +++ b/src/main/java/com/hkversion/AlarmDataParse.java @@ -4,12 +4,13 @@ import com.alibaba.fastjson.JSONObject; import com.common.CommonUtil; import com.sun.jna.Pointer; import com.yzx.callback.AlarmCallback; -import sun.misc.BASE64Encoder; -import java.io.*; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; import java.text.SimpleDateFormat; -import java.util.Base64; import java.util.Date; /** @@ -19,7 +20,7 @@ import java.util.Date; public class AlarmDataParse { public static void alarmDataHandle(int lCommand, HCNetSDK.NET_DVR_ALARMER pAlarmer, Pointer pAlarmInfo, int dwBufLen, Pointer pUser, AlarmCallback callback) { - System.out.println("报警事件类型: lCommand:" + Integer.toHexString(lCommand)); + //System.out.println("报警事件类型: lCommand:" + Integer.toHexString(lCommand)); String sTime; String MonitoringSiteID; //lCommand是传的报警类型 @@ -34,7 +35,7 @@ public class AlarmDataParse { String sLicense = new String(strItsPlateResult.struPlateInfo.sLicense, "GBK"); byte VehicleType = strItsPlateResult.byVehicleType; //0-其他车辆,1-小型车,2-大型车,3- 行人触发,4- 二轮车触发,5- 三轮车触发,6- 机动车触发 MonitoringSiteID = new String(strItsPlateResult.byMonitoringSiteID); - System.out.println("车牌号:" + sLicense + ":车辆类型:" + VehicleType + ":监控点编号:" + MonitoringSiteID); + //System.out.println("车牌号:" + sLicense + ":车辆类型:" + VehicleType + ":监控点编号:" + MonitoringSiteID); } catch (UnsupportedEncodingException e1) { // TODO Auto-generated catch block e1.printStackTrace(); @@ -47,27 +48,12 @@ public class AlarmDataParse { */ for (int i = 0; i < strItsPlateResult.dwPicNum; i++) { if (strItsPlateResult.struPicInfo[i].dwDataLen > 0) { - SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss"); - String newName = sf.format(new Date()); - FileOutputStream fout; - try { - String filename = "../pic/" + newName + "_type[" + strItsPlateResult.struPicInfo[i].byType + "]_ItsPlate.jpg"; - fout = new FileOutputStream(filename); - //将字节写入文件 - long offset = 0; - ByteBuffer buffers = strItsPlateResult.struPicInfo[i].pBuffer.getByteBuffer(offset, strItsPlateResult.struPicInfo[i].dwDataLen); - byte[] bytes = new byte[strItsPlateResult.struPicInfo[i].dwDataLen]; - 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(); - } + //将字节写入文件 + long offset = 0; + ByteBuffer buffers = strItsPlateResult.struPicInfo[i].pBuffer.getByteBuffer(offset, strItsPlateResult.struPicInfo[i].dwDataLen); + byte[] bytes = new byte[strItsPlateResult.struPicInfo[i].dwDataLen]; + buffers.rewind(); + buffers.get(bytes); } } break; @@ -83,34 +69,19 @@ public class AlarmDataParse { // 车牌信息 try { String PlateInfo = "车牌号:" + new String(strTfsAlarm.struPlateInfo.sLicense, "GBK"); - System.out.println("【道路违章取证报警】时间:" + sTime + "违章类型:" + IllegalType + "车牌信息:" + PlateInfo); + //System.out.println("【道路违章取证报警】时间:" + sTime + "违章类型:" + IllegalType + "车牌信息:" + PlateInfo); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } //报警图片信息 for (int i = 0; i < strTfsAlarm.dwPicNum; i++) { if (strTfsAlarm.struPicInfo[i].dwDataLen > 0) { - SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss"); - String newName = sf.format(new Date()); - FileOutputStream fout; - try { - String filename = "../pic/" + newName + "_type[" + strTfsAlarm.struPicInfo[i].byType + "]_TfsPlate.jpg"; - fout = new FileOutputStream(filename); - //将字节写入文件 - long offset = 0; - ByteBuffer buffers = strTfsAlarm.struPicInfo[i].pBuffer.getByteBuffer(offset, strTfsAlarm.struPicInfo[i].dwDataLen); - byte[] bytes = new byte[strTfsAlarm.struPicInfo[i].dwDataLen]; - 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(); - } + //将字节写入文件 + long offset = 0; + ByteBuffer buffers = strTfsAlarm.struPicInfo[i].pBuffer.getByteBuffer(offset, strTfsAlarm.struPicInfo[i].dwDataLen); + byte[] bytes = new byte[strTfsAlarm.struPicInfo[i].dwDataLen]; + buffers.rewind(); + buffers.get(bytes); } } break; @@ -124,30 +95,15 @@ public class AlarmDataParse { MonitoringSiteID = strAIDAlarmV41.byMonitoringSiteID.toString(); //监控点编号 int AIDType = strAIDAlarmV41.struAIDInfo.dwAIDType; // 交通事件类型 int AIDTypeEx = strAIDAlarmV41.struAIDInfo.dwAIDTypeEx; //交通事件类型扩展 - System.out.println("【道路事件检测】" + "时间:" + sTime + "监控点:" + MonitoringSiteID + "交通事件类型:" + AIDType + "交通事件类型扩展:" + AIDTypeEx); + //System.out.println("【道路事件检测】" + "时间:" + sTime + "监控点:" + MonitoringSiteID + "交通事件类型:" + AIDType + "交通事件类型扩展:" + AIDTypeEx); //报警图片信息 if (strAIDAlarmV41.dwPicDataLen > 0 && strAIDAlarmV41.pImage != null) { - SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss"); - String newName = sf.format(new Date()); - FileOutputStream fout; - try { - String filename = "../pic/" + newName + "_AIDalarm.jpg"; - fout = new FileOutputStream(filename); - //将字节写入文件 - long offset = 0; - ByteBuffer buffers = strAIDAlarmV41.pImage.getByteBuffer(offset, strAIDAlarmV41.dwPicDataLen); - byte[] bytes = new byte[strAIDAlarmV41.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(); - } + //将字节写入文件 + long offset = 0; + ByteBuffer buffers = strAIDAlarmV41.pImage.getByteBuffer(offset, strAIDAlarmV41.dwPicDataLen); + byte[] bytes = new byte[strAIDAlarmV41.dwPicDataLen]; + buffers.rewind(); + buffers.get(bytes); } break; case HCNetSDK.COMM_ALARM_TPS_V41://交通数据统计的报警 @@ -160,7 +116,7 @@ public class AlarmDataParse { MonitoringSiteID = strTPSalarmV41.byMonitoringSiteID.toString(); //监控点编号 String StartTime = CommonUtil.parseTime(strTPSalarmV41.dwStartTime); //开始统计时间; String StopTime = CommonUtil.parseTime(strTPSalarmV41.dwStopTime); //结束统计时间; - System.out.println("【交通数据统计】" + "时间:" + sTime + "监控点编号:" + MonitoringSiteID + "开始统计时间:" + StartTime + "结束统计时间:" + StopTime); + //System.out.println("【交通数据统计】" + "时间:" + sTime + "监控点编号:" + MonitoringSiteID + "开始统计时间:" + StartTime + "结束统计时间:" + StopTime); //车道统计参数信息 for (int i = 0; i <= HCNetSDK.MAX_TPS_RULE; i++) { byte LaneNo = strTPSalarmV41.struTPSInfo.struLaneParam[i].byLaneNo; //车道号 @@ -169,7 +125,7 @@ public class AlarmDataParse { int LaneVolume = strTPSalarmV41.struTPSInfo.struLaneParam[i].dwLaneVolume; //车道流量 int LaneVelocity = strTPSalarmV41.struTPSInfo.struLaneParam[i].dwLaneVelocity; //车道平均速度 float SpaceOccupyRation = strTPSalarmV41.struTPSInfo.struLaneParam[i].fSpaceOccupyRation; //车道占有率,百分比计算(空间上,车辆长度与监控路段总长度的比值) - System.out.println("车道号:" + LaneNo + "车道状态:" + TrafficState + "车道流量:" + LaneVolume + "车道占有率:" + SpaceOccupyRation + "\n"); + //System.out.println("车道号:" + LaneNo + "车道状态:" + TrafficState + "车道流量:" + LaneVolume + "车道占有率:" + SpaceOccupyRation + "\n"); } break; case HCNetSDK.COMM_ALARM_TPS_REAL_TIME: //实时过车数据数据 @@ -191,7 +147,7 @@ public class AlarmDataParse { String bySpeed = new String(String.valueOf(netDvrTpsParam.struTPSRealTimeInfo.bySpeed)).trim();// 对应车速(KM/H) int dwDownwardFlow = netDvrTpsParam.struTPSRealTimeInfo.dwDownwardFlow;//当前车道 从上到下车流量 int dwUpwardFlow = netDvrTpsParam.struTPSRealTimeInfo.dwUpwardFlow; //当前车道 从下到上车流量 - System.out.println("通道号:" + channel + "; 时间:" + struTime + ";对应车道号:" + byLane + ";当前车道 从上到下车流量:" + dwDownwardFlow + ";dwUpwardFlow:" + dwUpwardFlow); + //System.out.println("通道号:" + channel + "; 时间:" + struTime + ";对应车道号:" + byLane + ";当前车道 从上到下车流量:" + dwDownwardFlow + ";dwUpwardFlow:" + dwUpwardFlow); break; case HCNetSDK.COMM_ALARM_TPS_STATISTICS: //统计过车数据 @@ -210,7 +166,7 @@ public class AlarmDataParse { String.format("%02d", netDvrTpsStatisticsInfo.struTPSStatisticsInfo.struStartTime.byMinute) + String.format("%02d", netDvrTpsStatisticsInfo.struTPSStatisticsInfo.struStartTime.bySecond); byte TotalLaneNum = netDvrTpsStatisticsInfo.struTPSStatisticsInfo.byTotalLaneNum; //有效车道总数 - System.out.println("通道号:" + Tpschannel + "; 开始统计时间:" + struStartTime + "有效车道总数:" + TotalLaneNum); + //System.out.println("通道号:" + Tpschannel + "; 开始统计时间:" + struStartTime + "有效车道总数:" + TotalLaneNum); break; case HCNetSDK.COMM_ITS_PARK_VEHICLE: //停车场数据上传 HCNetSDK.NET_ITS_PARK_VEHICLE strParkVehicle = new HCNetSDK.NET_ITS_PARK_VEHICLE(); @@ -230,27 +186,12 @@ public class AlarmDataParse { //报警图片信息 for (int i = 0; i < strParkVehicle.dwPicNum; i++) { if (strParkVehicle.struPicInfo[i].dwDataLen > 0) { - SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss"); - String newName = sf.format(new Date()); - FileOutputStream fout; - try { - String filename = "../pic/" + newName + "_ParkVehicle.jpg"; - fout = new FileOutputStream(filename); - //将字节写入文件 - long offset = 0; - ByteBuffer buffers = strParkVehicle.struPicInfo[i].pBuffer.getByteBuffer(offset, strParkVehicle.struPicInfo[i].dwDataLen); - byte[] bytes = new byte[strParkVehicle.struPicInfo[i].dwDataLen]; - 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(); - } + //将字节写入文件 + long offset = 0; + ByteBuffer buffers = strParkVehicle.struPicInfo[i].pBuffer.getByteBuffer(offset, strParkVehicle.struPicInfo[i].dwDataLen); + byte[] bytes = new byte[strParkVehicle.struPicInfo[i].dwDataLen]; + buffers.rewind(); + buffers.get(bytes); } } break; @@ -273,16 +214,15 @@ public class AlarmDataParse { byte bySubSysNo = strCIDalarm.bySubSysNo; //子系统号 if (strCIDalarm.wDefenceNo != 0xff) { - System.out.println("防区号:"+Integer.sum(strCIDalarm.wDefenceNo,1)); + //System.out.println("防区号:"+Integer.sum(strCIDalarm.wDefenceNo,1)); } - System.out.println("【CID事件】" + "触发时间:" + TriggerTime + "CID事件号:" + sCIDCode + "CID事件名:" + sCIDDescribe + "子系统号:" + - bySubSysNo); + //System.out.println("【CID事件】" + "触发时间:" + TriggerTime + "CID事件号:" + sCIDCode + "CID事件名:" + sCIDDescribe + "子系统号:" + bySubSysNo); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } break; case HCNetSDK.COMM_IPC_AUXALARM_RESULT: //PIR报警、无线报警、呼救报警信息 - System.out.println("PIR报警、无线报警、呼救报警触发"); + //System.out.println("PIR报警、无线报警、呼救报警触发"); break; case HCNetSDK.COMM_ISAPI_ALARM: //ISAPI协议报警信息 HCNetSDK.NET_DVR_ALARM_ISAPI_INFO struEventISAPI = new HCNetSDK.NET_DVR_ALARM_ISAPI_INFO(); @@ -294,29 +234,13 @@ public class AlarmDataParse { //报警数据类型:0- invalid,1- xml,2- json sAlarmInfo = "报警设备IP:" + sAlarmInfo + ":ISAPI协议报警信息, 数据格式:" + struEventISAPI.byDataType + ", 图片个数:" + struEventISAPI.byPicturesNumber; - System.out.println(sAlarmInfo); + //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(); - } + //将字节写入文件 + ByteBuffer jsonbuffers = struEventISAPI.pAlarmData.getByteBuffer(0, struEventISAPI.dwAlarmDataLen); + byte[] jsonbytes = new byte[struEventISAPI.dwAlarmDataLen]; + jsonbuffers.rewind(); + jsonbuffers.get(jsonbytes); //图片数据保存 for (int i = 0; i < struEventISAPI.byPicturesNumber; i++) { HCNetSDK.NET_DVR_ALARM_ISAPI_PICDATA struPicData = new HCNetSDK.NET_DVR_ALARM_ISAPI_PICDATA(); @@ -325,52 +249,24 @@ public class AlarmDataParse { 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(); - } + //将字节写入文件 + long offset = 0; + ByteBuffer buffers = struPicData.pPicData.getByteBuffer(offset, struPicData.dwPicLen); + byte[] bytes = new byte[struPicData.dwPicLen]; + buffers.rewind(); + buffers.get(bytes); } break; case HCNetSDK.COMM_VCA_ALARM: // 智能检测通用报警(Json或者XML数据结构) 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(); - } + //System.out.println(sAlarmInfo); + //将字节写入文件 + ByteBuffer dataBuffer = pAlarmInfo.getByteBuffer(0, dwBufLen); + byte[] dataByte = new byte[dwBufLen]; + dataBuffer.rewind(); + dataBuffer.get(dataByte); break; //行为分析信息 @@ -383,191 +279,101 @@ public class AlarmDataParse { switch (strVcaAlarm.struRuleInfo.wEventTypeEx) { case 1: //穿越警戒面 (越界侦测) - System.out.println("越界侦测报警发生"); + //System.out.println("越界侦测报警发生"); strVcaAlarm.struRuleInfo.uEventParam.setType(HCNetSDK.NET_VCA_TRAVERSE_PLANE.class); - System.out.println("检测目标:"+strVcaAlarm.struRuleInfo.uEventParam.struTraversePlane.byDetectionTarget); //检测目标,0表示所有目标(表示不锁定检测目标,所有目标都将进行检测),其他取值按位表示不同的检测目标:0x01-人,0x02-车 + //System.out.println("检测目标:"+strVcaAlarm.struRuleInfo.uEventParam.struTraversePlane.byDetectionTarget); //检测目标,0表示所有目标(表示不锁定检测目标,所有目标都将进行检测),其他取值按位表示不同的检测目标:0x01-人,0x02-车 //图片保存 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 + "VCA_TRAVERSE_PLANE" + ".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 2: //目标进入区域 - System.out.println("目标进入区域报警发生"); + //System.out.println("目标进入区域报警发生"); strVcaAlarm.struRuleInfo.uEventParam.setType(HCNetSDK.NET_VCA_AREA.class); - System.out.println("检测目标:"+strVcaAlarm.struRuleInfo.uEventParam.struArea.byDetectionTarget); + //System.out.println("检测目标:"+strVcaAlarm.struRuleInfo.uEventParam.struArea.byDetectionTarget); //图片保存 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 + "_TargetEnter" + ".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 3: //目标离开区域 - System.out.println("目标离开区域报警触发"); + //System.out.println("目标离开区域报警触发"); strVcaAlarm.struRuleInfo.uEventParam.setType(HCNetSDK.NET_VCA_AREA.class); - System.out.println("检测目标:"+strVcaAlarm.struRuleInfo.uEventParam.struArea.byDetectionTarget); + //System.out.println("检测目标:"+strVcaAlarm.struRuleInfo.uEventParam.struArea.byDetectionTarget); //图片保存 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 + "_TargetLeave" + ".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 4: //周界入侵 - System.out.println("周界入侵报警发生"); + //System.out.println("周界入侵报警发生"); strVcaAlarm.struRuleInfo.uEventParam.setType(HCNetSDK.NET_VCA_INTRUSION.class); - System.out.println("检测目标:"+strVcaAlarm.struRuleInfo.uEventParam.struIntrusion.byDetectionTarget); + //System.out.println("检测目标:"+strVcaAlarm.struRuleInfo.uEventParam.struIntrusion.byDetectionTarget); //图片保存 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 + "VCA_INTRUSION" + ".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 5: //徘徊 - System.out.println("徘徊事件触发"); + //System.out.println("徘徊事件触发"); break; case 8: //快速移动(奔跑), - System.out.println("快速移动(奔跑)事件触发"); + //System.out.println("快速移动(奔跑)事件触发"); break; case 15: //离岗 - System.out.println("离岗事件触发"); + //System.out.println("离岗事件触发"); strVcaAlarm.struRuleInfo.uEventParam.setType(HCNetSDK.NET_VCA_LEAVE_POSITION.class); - System.out.println(strVcaAlarm.struRuleInfo.uEventParam.struLeavePos.byOnPosition); + //System.out.println(strVcaAlarm.struRuleInfo.uEventParam.struLeavePos.byOnPosition); //图片保存 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 + "VCA_LEAVE_POSITION_" + ".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(); - } } case 20: //倒地检测 - System.out.println("倒地事件触发"); + //System.out.println("倒地事件触发"); break; case 44: //玩手机 - System.out.println("玩手机报警发生"); + //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("持续检测事件触发"); + //System.out.println("持续检测事件触发"); default: - System.out.println("行为事件类型:" + strVcaAlarm.struRuleInfo.wEventTypeEx); + //System.out.println("行为事件类型:" + strVcaAlarm.struRuleInfo.wEventTypeEx); break; } break; @@ -581,9 +387,8 @@ public class AlarmDataParse { strACSInfo.read(); /**门禁事件的详细信息解析,通过主次类型的可以判断当前的具体门禁类型,例如(主类型:0X5 次类型:0x4b 表示人脸认证通过, 主类型:0X5 次类型:0x4c 表示人脸认证失败)*/ - System.out.println("【门禁主机报警信息】卡号:" + new String(strACSInfo.struAcsEventInfo.byCardNo).trim() + ",卡类型:" + - strACSInfo.struAcsEventInfo.byCardType + ",报警主类型:" + Integer.toHexString(strACSInfo.dwMajor) + ",报警次类型:" + Integer.toHexString(strACSInfo.dwMinor)); - System.out.println("工号1:" + strACSInfo.struAcsEventInfo.dwEmployeeNo); + //System.out.println("【门禁主机报警信息】卡号:" + new String(strACSInfo.struAcsEventInfo.byCardNo).trim() + ",卡类型:" + strACSInfo.struAcsEventInfo.byCardType + ",报警主类型:" + Integer.toHexString(strACSInfo.dwMajor) + ",报警次类型:" + Integer.toHexString(strACSInfo.dwMinor)); + //System.out.println("工号1:" + strACSInfo.struAcsEventInfo.dwEmployeeNo); json.put("dwEmployeeNo",strACSInfo.struAcsEventInfo.dwEmployeeNo); json.put("byCardNo",new String(strACSInfo.struAcsEventInfo.byCardNo).trim()); json.put("byCardType",strACSInfo.struAcsEventInfo.byCardType); @@ -596,7 +401,7 @@ public class AlarmDataParse { Pointer pAcsInfoExV20 = strAcsInfoExV20.getPointer(); pAcsInfoExV20.write(0, strACSInfo.pAcsEventInfoExtendV20.getByteArray(0, strAcsInfoExV20.size()), 0, strAcsInfoExV20.size()); strAcsInfoExV20.read(); - System.out.println("实时温度值:" + strAcsInfoExV20.fCurrTemperature); + //System.out.println("实时温度值:" + strAcsInfoExV20.fCurrTemperature); json.put("currTemperature",strAcsInfoExV20.fCurrTemperature); } //考勤状态 @@ -606,8 +411,8 @@ public class AlarmDataParse { Pointer pAcsInfoEx = strAcsInfoEx.getPointer(); pAcsInfoEx.write(0, strACSInfo.pAcsEventInfoExtend.getByteArray(0, strAcsInfoEx.size()), 0, strAcsInfoEx.size()); strAcsInfoEx.read(); - System.out.println("考勤状态:" + strAcsInfoEx.byAttendanceStatus); - System.out.println("工号2:" + new String(strAcsInfoEx.byEmployeeNo).trim()); + //System.out.println("考勤状态:" + strAcsInfoEx.byAttendanceStatus); + //System.out.println("工号2:" + new String(strAcsInfoEx.byEmployeeNo).trim()); json.put("byEmployeeNo",new String(strAcsInfoEx.byEmployeeNo).trim()); json.put("attendanceStatus",strAcsInfoEx.byAttendanceStatus); } @@ -619,36 +424,13 @@ public class AlarmDataParse { String SwipeTime = year + strACSInfo.struTime.dwMonth + strACSInfo.struTime.dwDay + strACSInfo.struTime.dwHour + strACSInfo.struTime.dwMinute + strACSInfo.struTime.dwSecond; if (strACSInfo.dwPicDataLen > 0) { -// SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss"); -// String newName = sf.format(new Date()); - FileOutputStream fout; - try { - /** - * 人脸保存路径 - */ - String filename = "../pic/" + SwipeTime + "_ACS_Event_" + new String(strACSInfo.struAcsEventInfo.byCardNo).trim() + ".jpg"; - File file = new File(filename); - File parentFile = file.getParentFile(); - if(!parentFile.exists()){ - parentFile.mkdirs(); - } - fout = new FileOutputStream(filename); //将字节写入文件 long offset = 0; ByteBuffer buffers = strACSInfo.pPicData.getByteBuffer(offset, strACSInfo.dwPicDataLen); byte[] bytes = new byte[strACSInfo.dwPicDataLen]; buffers.rewind(); buffers.get(bytes); - fout.write(bytes); - fout.close(); - json.put("pic_bytes",bytes); - } catch (FileNotFoundException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } + json.put("pic",bytes); } callback.process(json); break; @@ -659,13 +441,12 @@ public class AlarmDataParse { Pointer pIDCardInfo = strIDCardInfo.getPointer(); pIDCardInfo.write(0, pAlarmInfo.getByteArray(0, strIDCardInfo.size()), 0, strIDCardInfo.size()); strIDCardInfo.read(); - System.out.println("报警主类型:" + Integer.toHexString(strIDCardInfo.dwMajor) + ",报警次类型:" + Integer.toHexString(strIDCardInfo.dwMinor)); + //System.out.println("报警主类型:" + Integer.toHexString(strIDCardInfo.dwMajor) + ",报警次类型:" + Integer.toHexString(strIDCardInfo.dwMinor)); /** * 身份证信息 */ String IDnum = new String(strIDCardInfo.struIDCardCfg.byIDNum).trim(); - System.out.println("【身份证信息】:身份证号码:" + IDnum + ",姓名:" + - new String(strIDCardInfo.struIDCardCfg.byName).trim() + ",住址:" + new String(strIDCardInfo.struIDCardCfg.byAddr)); + //System.out.println("【身份证信息】:身份证号码:" + IDnum + ",姓名:" + new String(strIDCardInfo.struIDCardCfg.byName).trim() + ",住址:" + new String(strIDCardInfo.struIDCardCfg.byAddr)); /** * 报警时间 @@ -678,91 +459,60 @@ public class AlarmDataParse { */ //身份证图片 if (strIDCardInfo.dwPicDataLen > 0 || strIDCardInfo.pPicData != null) { -// SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss"); -// String nowtime = sf.format(new Date()); - FileOutputStream fout; - try { - String filename = "../pic/" + SwipeTime1 + "_" + IDnum + ".jpg"; - fout = new FileOutputStream(filename); //将字节写入文件 long offset = 0; ByteBuffer buffers = strIDCardInfo.pPicData.getByteBuffer(offset, strIDCardInfo.dwPicDataLen); byte[] bytes = new byte[strIDCardInfo.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(); - } } if (strIDCardInfo.dwCapturePicDataLen > 0 || strIDCardInfo.pCapturePicData != null) { -// SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss"); -// String nowtime = sf.format(new Date()); - FileOutputStream fout; - try { - /** - * 人脸图片保存路径 - */ - String filename = "../pic/" + SwipeTime1 + "_CapturePic_" + ".jpg"; - fout = new FileOutputStream(filename); - //将字节写入文件 - long offset = 0; - ByteBuffer buffers = strIDCardInfo.pCapturePicData.getByteBuffer(offset, strIDCardInfo.dwCapturePicDataLen); - byte[] bytes = new byte[strIDCardInfo.dwCapturePicDataLen]; - 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(); - } + /** + * 人脸图片保存路径 + */ + //将字节写入文件 + long offset = 0; + ByteBuffer buffers = strIDCardInfo.pCapturePicData.getByteBuffer(offset, strIDCardInfo.dwCapturePicDataLen); + byte[] bytes = new byte[strIDCardInfo.dwCapturePicDataLen]; + buffers.rewind(); + buffers.get(bytes); } break; case HCNetSDK.COMM_ALARM_VIDEO_INTERCOM: //可视对讲报警信息 - System.out.println("可视对讲报警触发"); + //System.out.println("可视对讲报警触发"); HCNetSDK.NET_DVR_VIDEO_INTERCOM_ALARM strVideoIntercomAlarm = new HCNetSDK.NET_DVR_VIDEO_INTERCOM_ALARM(); strVideoIntercomAlarm.write(); Pointer pVideoIntercomAlarm = strVideoIntercomAlarm.getPointer(); pVideoIntercomAlarm.write(0, pAlarmInfo.getByteArray(0, strVideoIntercomAlarm.size()), 0, strVideoIntercomAlarm.size()); strVideoIntercomAlarm.read(); - System.out.println("byAlarmType:" + strVideoIntercomAlarm.byAlarmType); + //System.out.println("byAlarmType:" + strVideoIntercomAlarm.byAlarmType); if (strVideoIntercomAlarm.byAlarmType == 1) { strVideoIntercomAlarm.uAlarmInfo.setType(HCNetSDK.NET_DVR_VIDEO_INTERCOM_ALARM_INFO_UNION.class); strVideoIntercomAlarm.uAlarmInfo.read(); - System.out.println("byZoneType :" + strVideoIntercomAlarm.uAlarmInfo.struZoneAlarm.byZoneType); + //System.out.println("byZoneType :" + strVideoIntercomAlarm.uAlarmInfo.struZoneAlarm.byZoneType); } break; case HCNetSDK.COMM_UPLOAD_VIDEO_INTERCOM_EVENT: //可视对讲事件记录信息 - System.out.println("可视对讲事件记录报警触发"); + //System.out.println("可视对讲事件记录报警触发"); HCNetSDK.NET_DVR_VIDEO_INTERCOM_EVENT strVideoIntercomEvent = new HCNetSDK.NET_DVR_VIDEO_INTERCOM_EVENT(); strVideoIntercomEvent.write(); Pointer pVideoIntercomEvent = strVideoIntercomEvent.getPointer(); pVideoIntercomEvent.write(0, pAlarmInfo.getByteArray(0, strVideoIntercomEvent.size()), 0, strVideoIntercomEvent.size()); strVideoIntercomEvent.read(); - System.out.println("byEventType:" + strVideoIntercomEvent.byEventType); + //System.out.println("byEventType:" + strVideoIntercomEvent.byEventType); if (strVideoIntercomEvent.byEventType == 1) { strVideoIntercomEvent.uEventInfo.setType(HCNetSDK.NET_DVR_UNLOCK_RECORD_INFO.class); strVideoIntercomEvent.uEventInfo.read(); - System.out.println("byUnlockType:" + strVideoIntercomEvent.uEventInfo.struUnlockRecord.byUnlockType - + ",byControlSrc:" + new String(strVideoIntercomEvent.uEventInfo.struUnlockRecord.byControlSrc).trim()); + //System.out.println("byUnlockType:" + strVideoIntercomEvent.uEventInfo.struUnlockRecord.byUnlockType + ",byControlSrc:" + new String(strVideoIntercomEvent.uEventInfo.struUnlockRecord.byControlSrc).trim()); } break; case HCNetSDK.COMM_UPLOAD_FACESNAP_RESULT: //实时人脸抓拍上传 - System.out.println("UPLOAD_FACESNAP_Alarm"); + //System.out.println("UPLOAD_FACESNAP_Alarm"); HCNetSDK.NET_VCA_FACESNAP_RESULT strFaceSnapInfo = new HCNetSDK.NET_VCA_FACESNAP_RESULT(); strFaceSnapInfo.write(); Pointer pFaceSnapInfo = strFaceSnapInfo.getPointer(); @@ -788,7 +538,7 @@ public class AlarmDataParse { String sFaceAlarmInfo = "Abs时间:" + strAbsTime + ",年龄:" + strFaceSnapInfo.struFeature.byAge + ",性别:" + strFaceSnapInfo.struFeature.bySex + ",是否戴口罩:" + strFaceSnapInfo.struFeature.byMask + ",是否微笑:" + strFaceSnapInfo.struFeature.bySmile; - System.out.println("人脸信息:" + sFaceAlarmInfo); + //System.out.println("人脸信息:" + sFaceAlarmInfo); //人脸测温信息 if (strFaceSnapInfo.byAddInfo == 1) { @@ -800,7 +550,7 @@ public class AlarmDataParse { String sTemperatureInfo = "测温是否开启:" + strAddInfo.byFaceSnapThermometryEnabled + "人脸温度:" + strAddInfo.fFaceTemperature + "温度是否异常" + strAddInfo.byIsAbnomalTemperature + "报警温度阈值:" + strAddInfo.fAlarmTemperature; - System.out.println("人脸温度信息:" + sTemperatureInfo); + //System.out.println("人脸温度信息:" + sTemperatureInfo); } @@ -837,111 +587,53 @@ public class AlarmDataParse { strFaceSnapMatch.read(); //比对结果,0-保留,1-比对成功,2-比对失败 String sFaceSnapMatchInfo = "比对结果:" + strFaceSnapMatch.byContrastStatus + ",相似度:" + strFaceSnapMatch.fSimilarity; - System.out.println(sFaceSnapMatchInfo); + //System.out.println(sFaceSnapMatchInfo); 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)); + //System.out.println("人脸库ID:" + new String(bytes1)); } 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)); + //System.out.println("图片ID:" + new String(bytes2)); } if (strFaceSnapMatch.struBlockListInfo.struBlockListInfo.dwFCAdditionInfoLen > 0) { //抓拍库附加信息解析(解析人脸测温温度,人脸温度存放在附件信息的XML报文中,节点: ) - SimpleDateFormat sf2 = new SimpleDateFormat("yyyyMMddHHmmss"); - String curTime2 = sf2.format(new Date()); - FileOutputStream AddtionData; - String AddtionFile = "../pic" + new String(pAlarmer.sDeviceIP).trim() + curTime2 + "_FCAdditionInfo_" + ".xml"; - try { - Data = new FileOutputStream(AddtionFile); - //将字节写入文件 - ByteBuffer dataBuffer = strFaceSnapMatch.struBlockListInfo.struBlockListInfo.pFCAdditionInfoBuffer.getByteBuffer(0, strFaceSnapMatch.struBlockListInfo.struBlockListInfo.dwFCAdditionInfoLen); - 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(); - } + //将字节写入文件 + dataBuffer = strFaceSnapMatch.struBlockListInfo.struBlockListInfo.pFCAdditionInfoBuffer.getByteBuffer(0, strFaceSnapMatch.struBlockListInfo.struBlockListInfo.dwFCAdditionInfoLen); + dataByte = new byte[dwBufLen]; + dataBuffer.rewind(); + dataBuffer.get(dataByte); } //人脸比对报警图片保存,图片格式二进制 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(); - } + //将字节写入文件 + long offset = 0; + ByteBuffer buffers = strFaceSnapMatch.pSnapPicBuffer.getByteBuffer(offset, strFaceSnapMatch.dwSnapPicLen); + byte[] bytes = new byte[strFaceSnapMatch.dwSnapPicLen]; + buffers.rewind(); + buffers.get(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.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(); - } } //人脸比对报警图片保存,图片格式URL格式 if ((strFaceSnapMatch.dwSnapPicLen > 0) && (strFaceSnapMatch.byPicTransType == 1)) { @@ -952,7 +644,7 @@ public class AlarmDataParse { buffers.rewind(); buffers.get(bytes); String SnapPicUrl = new String(bytes); - System.out.println("抓拍图URL:" + SnapPicUrl); + //System.out.println("抓拍图URL:" + SnapPicUrl); } if ((strFaceSnapMatch.struSnapInfo.dwSnapFacePicLen > 0) && (strFaceSnapMatch.byPicTransType == 1)) { @@ -962,7 +654,7 @@ public class AlarmDataParse { buffers.rewind(); buffers.get(bytes); String SnapPicUrl = new String(bytes); - System.out.println("抓拍人脸子图URL:" + SnapPicUrl); + //System.out.println("抓拍人脸子图URL:" + SnapPicUrl); } if ((strFaceSnapMatch.struBlockListInfo.dwBlockListPicLen > 0) && (strFaceSnapMatch.byPicTransType == 1)) { @@ -972,7 +664,7 @@ public class AlarmDataParse { buffers.rewind(); buffers.get(bytes); String SnapPicUrl = new String(bytes); - System.out.println("人脸库人脸图的URL:" + SnapPicUrl); + //System.out.println("人脸库人脸图的URL:" + SnapPicUrl); } @@ -1016,7 +708,7 @@ public class AlarmDataParse { Pointer pAlarmInfo_V30 = struAlarmInfo.getPointer(); pAlarmInfo_V30.write(0, pAlarmInfo.getByteArray(0, struAlarmInfo.size()), 0, struAlarmInfo.size()); struAlarmInfo.read(); - System.out.println("报警类型:" + struAlarmInfo.dwAlarmType); // 3-移动侦测 + //System.out.println("报警类型:" + struAlarmInfo.dwAlarmType); // 3-移动侦测 break; case HCNetSDK.COMM_ALARM_V40: //移动侦测、视频丢失、遮挡、IO信号量等报警信息,报警数据为可变长 HCNetSDK.NET_DVR_ALARMINFO_V40 struAlarmInfoV40 = new HCNetSDK.NET_DVR_ALARMINFO_V40(); @@ -1024,7 +716,7 @@ public class AlarmDataParse { Pointer pAlarmInfoV40 = struAlarmInfoV40.getPointer(); pAlarmInfoV40.write(0, pAlarmInfo.getByteArray(0, struAlarmInfoV40.size()), 0, struAlarmInfoV40.size()); struAlarmInfoV40.read(); - System.out.println("报警类型:" + struAlarmInfoV40.struAlarmFixedHeader.dwAlarmType); //3-移动侦测 + //System.out.println("报警类型:" + struAlarmInfoV40.struAlarmFixedHeader.dwAlarmType); //3-移动侦测 break; case HCNetSDK.COMM_THERMOMETRY_ALARM: //温度报警信息 HCNetSDK.NET_DVR_THERMOMETRY_ALARM struTemInfo = new HCNetSDK.NET_DVR_THERMOMETRY_ALARM(); @@ -1034,57 +726,24 @@ public class AlarmDataParse { struTemInfo.read(); String sThermAlarmInfo = "规则ID:" + struTemInfo.byRuleID + "预置点号:" + struTemInfo.wPresetNo + "报警等级:" + struTemInfo.byAlarmLevel + "报警类型:" + struTemInfo.byAlarmType + "当前温度:" + struTemInfo.fCurrTemperature; - System.out.println(sThermAlarmInfo); + //System.out.println(sThermAlarmInfo); //可见光图片保存 if ((struTemInfo.dwPicLen > 0) && (struTemInfo.byPicTransType == 0)) { - SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss"); - String newName = sf.format(new Date()); - FileOutputStream fout; - - try { - String filename = "../pic/" + newName + "_" + struTemInfo.fCurrTemperature + ".jpg"; - fout = new FileOutputStream(filename); //将字节写入文件 long offset = 0; ByteBuffer buffers = struTemInfo.pPicBuff.getByteBuffer(offset, struTemInfo.dwPicLen); byte[] bytes = new byte[struTemInfo.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(); - } } if ((struTemInfo.dwThermalPicLen > 0) && (struTemInfo.byPicTransType == 0)) { - SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss"); - String newName = sf.format(new Date()); - FileOutputStream fout; - - try { - String filename = "../pic/" + newName + "_" + "_ThermalPiC" + ".jpg"; - fout = new FileOutputStream(filename); //将字节写入文件 long offset = 0; ByteBuffer buffers = struTemInfo.pThermalPicBuff.getByteBuffer(offset, struTemInfo.dwThermalPicLen); byte[] bytes = new byte[struTemInfo.dwThermalPicLen]; 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_THERMOMETRY_DIFF_ALARM: //温差检测报警 @@ -1094,56 +753,24 @@ public class AlarmDataParse { pTemDiffInfo.write(0, pAlarmInfo.getByteArray(0, strThermDiffAlarm.size()), 0, strThermDiffAlarm.size()); strThermDiffAlarm.read(); String sThremDiffInfo = "通道号:" + strThermDiffAlarm.dwChannel + ",报警规则:" + strThermDiffAlarm.byAlarmRule + ",当前温差:" + strThermDiffAlarm.fCurTemperatureDiff; - System.out.println(sThremDiffInfo); + //System.out.println(sThremDiffInfo); //可见光图片保存 if ((strThermDiffAlarm.dwPicLen > 0) && (strThermDiffAlarm.byPicTransType == 0)) { - SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss"); - String newName = sf.format(new Date()); - FileOutputStream fout; - - try { - String filename = "../pic/" + newName + "_" + strThermDiffAlarm.fCurTemperatureDiff + ".jpg"; - fout = new FileOutputStream(filename); //将字节写入文件 long offset = 0; ByteBuffer buffers = strThermDiffAlarm.pPicBuff.getByteBuffer(offset, strThermDiffAlarm.dwPicLen); byte[] bytes = new byte[strThermDiffAlarm.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(); - } } //热成像图片保存 if ((strThermDiffAlarm.dwThermalPicLen > 0) && (strThermDiffAlarm.byPicTransType == 0)) { - SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss"); - String newName = sf.format(new Date()); - FileOutputStream fout; - - try { - String filename = "../pic/" + newName + "_" + "_ThermalDiffPiC" + ".jpg"; - fout = new FileOutputStream(filename); //将字节写入文件 long offset = 0; ByteBuffer buffers = strThermDiffAlarm.pThermalPicBuff.getByteBuffer(offset, strThermDiffAlarm.dwThermalPicLen); byte[] bytes = new byte[strThermDiffAlarm.dwThermalPicLen]; 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; @@ -1155,57 +782,24 @@ public class AlarmDataParse { struShipAlarm.read(); String sShipAlarm = "绝对时间:" + struShipAlarm.dwAbsTime + ",正跨越检测线的船只数:" + struShipAlarm.byShipsNum + ",船头检测的船只数 :" + struShipAlarm.byShipsNumHead + ", 船尾检测的船只数 :" + struShipAlarm.byShipsNumEnd; - System.out.println(sShipAlarm); + //System.out.println(sShipAlarm); //可见光图片保存 if ((struShipAlarm.dwPicLen > 0) && (struShipAlarm.byPicTransType == 0)) { - SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss"); - String newName = sf.format(new Date()); - FileOutputStream fout; - - try { - String filename = "../pic/" + newName + "_ShipAlarm" + ".jpg"; - fout = new FileOutputStream(filename); //将字节写入文件 long offset = 0; ByteBuffer buffers = struShipAlarm.pPicBuffer.getByteBuffer(offset, struShipAlarm.dwPicLen); byte[] bytes = new byte[struShipAlarm.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(); - } } //热成像图片保存 if ((struShipAlarm.dwThermalPicLen > 0) && (struShipAlarm.byPicTransType == 0)) { - SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmss"); - String newName = sf.format(new Date()); - FileOutputStream fout; - - try { - String filename = "../pic/" + newName + "_" + "_ThermalShipAlarm" + ".jpg"; - fout = new FileOutputStream(filename); //将字节写入文件 long offset = 0; ByteBuffer buffers = struShipAlarm.pThermalPicBuffer.getByteBuffer(offset, struShipAlarm.dwThermalPicLen); byte[] bytes = new byte[struShipAlarm.dwThermalPicLen]; 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; @@ -1217,69 +811,36 @@ public class AlarmDataParse { struFireDecAlarm.read(); String sFireDecAlarmInfo = "绝对时间:" + struFireDecAlarm.dwAbsTime + ",报警子类型:" + struFireDecAlarm.byAlarmSubType + ",火点最高温度 :" + struFireDecAlarm.wFireMaxTemperature + ",火点目标距离:" + struFireDecAlarm.wTargetDistance; - System.out.println(sFireDecAlarmInfo); + //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_UPLOAD_AIOP_VIDEO: //AI开放平台接入视频检测报警信息 - System.out.println("AI开放平台接入视频检测报警上传"); + //System.out.println("AI开放平台接入视频检测报警上传"); HCNetSDK.NET_AIOP_VIDEO_HEAD struAIOPVideo = new HCNetSDK.NET_AIOP_VIDEO_HEAD(); struAIOPVideo.write(); Pointer pAIOPVideo = struAIOPVideo.getPointer(); pAIOPVideo.write(0, pAlarmInfo.getByteArray(0, struAIOPVideo.size()), 0, struAIOPVideo.size()); struAIOPVideo.read(); - System.out.println("视频任务ID" + new String(struAIOPVideo.szTaskID)); - System.out.println("通道号:" + struAIOPVideo.dwChannel); - System.out.println("检测模型包ID" + new String(struAIOPVideo.szMPID)); + //System.out.println("视频任务ID" + new String(struAIOPVideo.szTaskID)); + //System.out.println("通道号:" + struAIOPVideo.dwChannel); + //System.out.println("检测模型包ID" + new String(struAIOPVideo.szMPID)); String strTime = String.format("%04d", struAIOPVideo.struTime.wYear) + String.format("%02d", struAIOPVideo.struTime.wMonth) + String.format("%02d", struAIOPVideo.struTime.wDay) + @@ -1289,60 +850,32 @@ public class AlarmDataParse { String.format("%03d", struAIOPVideo.struTime.wMilliSec); //AIOPData数据 if (struAIOPVideo.dwAIOPDataSize > 0) { - FileOutputStream fout; - try { - String filename = "../pic/" + new String(pAlarmer.sDeviceIP).trim() + - "_" + strTime + "_VideoData.json"; - fout = new FileOutputStream(filename); //将字节写入文件 long offset = 0; ByteBuffer buffers = struAIOPVideo.pBufferAIOPData.getByteBuffer(offset, struAIOPVideo.dwAIOPDataSize); byte[] bytes = new byte[struAIOPVideo.dwAIOPDataSize]; 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 (struAIOPVideo.dwPictureSize > 0) { - FileOutputStream fout; - try { - String filename = "../pic/" + new String(pAlarmer.sDeviceIP).trim() + - "_" + strTime + "_VideoPic.jpg"; - fout = new FileOutputStream(filename); //将字节写入文件 long offset = 0; ByteBuffer buffers = struAIOPVideo.pBufferPicture.getByteBuffer(offset, struAIOPVideo.dwPictureSize); byte[] bytes = new byte[struAIOPVideo.dwPictureSize]; 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_UPLOAD_AIOP_PICTURE: //AI开放平台接入图片检测报警信息 - System.out.println("AI开放平台接入图片检测报警上传"); + //System.out.println("AI开放平台接入图片检测报警上传"); HCNetSDK.NET_AIOP_PICTURE_HEAD struAIOPPic = new HCNetSDK.NET_AIOP_PICTURE_HEAD(); struAIOPPic.write(); Pointer pAIOPPic = struAIOPPic.getPointer(); pAIOPPic.write(0, pAlarmInfo.getByteArray(0, struAIOPPic.size()), 0, struAIOPPic.size()); struAIOPPic.read(); - System.out.println("图片ID:" + new String(struAIOPPic.szPID)); - System.out.println("检测模型包ID:" + new String(struAIOPPic.szMPID)); + //System.out.println("图片ID:" + new String(struAIOPPic.szPID)); + //System.out.println("检测模型包ID:" + new String(struAIOPPic.szMPID)); String strPicTime = "" + String.format("%04d", struAIOPPic.struTime.wYear) + String.format("%02d", struAIOPPic.struTime.wMonth) + String.format("%02d", struAIOPPic.struTime.wDay) + @@ -1352,39 +885,25 @@ public class AlarmDataParse { String.format("%03d", struAIOPPic.struTime.wMilliSec); //AIOPData数据 if (struAIOPPic.dwAIOPDataSize > 0) { - FileOutputStream fout; - try { - String filename = "../pic/" + new String(pAlarmer.sDeviceIP).trim() + - "_" + strPicTime + "_AIO_PicData.json"; - fout = new FileOutputStream(filename); //将字节写入文件 long offset = 0; ByteBuffer buffers = struAIOPPic.pBufferAIOPData.getByteBuffer(offset, struAIOPPic.dwAIOPDataSize); byte[] bytes = new byte[struAIOPPic.dwAIOPDataSize]; 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; //AI开放平台接入轮询抓图检测报警信息 case HCNetSDK.COMM_UPLOAD_AIOP_POLLING_SNAP: - System.out.println("AI开放平台接入轮询抓图检测报警事件上传"); + //System.out.println("AI开放平台接入轮询抓图检测报警事件上传"); HCNetSDK.NET_AIOP_POLLING_SNAP_HEAD strAiopPollingPic = new HCNetSDK.NET_AIOP_POLLING_SNAP_HEAD(); strAiopPollingPic.write(); Pointer pAiopPollingPic = strAiopPollingPic.getPointer(); pAiopPollingPic.write(0, pAlarmInfo.getByteArray(0, strAiopPollingPic.size()), 0, strAiopPollingPic.size()); strAiopPollingPic.read(); - System.out.println("通道号:" + strAiopPollingPic.dwChannel); - System.out.println("轮询抓图任务ID:" + new String(strAiopPollingPic.szTaskID)); + //System.out.println("通道号:" + strAiopPollingPic.dwChannel); + //System.out.println("轮询抓图任务ID:" + new String(strAiopPollingPic.szTaskID)); String strPollingPicTime = "" + String.format("%04d", strAiopPollingPic.struTime.wYear) + String.format("%02d", strAiopPollingPic.struTime.wMonth) + String.format("%02d", strAiopPollingPic.struTime.wDay) + @@ -1394,62 +913,34 @@ public class AlarmDataParse { String.format("%03d", strAiopPollingPic.struTime.wMilliSec); //AIOPData数据保存 if (strAiopPollingPic.dwAIOPDataSize > 0) { - FileOutputStream fout; - try { - String filename = "../pic/" + new String(pAlarmer.sDeviceIP).trim() + - "_" + strPollingPicTime + "_PollingPicData.json"; - fout = new FileOutputStream(filename); //将字节写入文件 long offset = 0; ByteBuffer buffers = strAiopPollingPic.pBufferAIOPData.getByteBuffer(offset, strAiopPollingPic.dwAIOPDataSize); byte[] bytes = new byte[strAiopPollingPic.dwAIOPDataSize]; 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 (strAiopPollingPic.dwPictureSize > 0) { - FileOutputStream fout; - try { - String filename = "../pic/" + new String(pAlarmer.sDeviceIP).trim() + - "_" + strPollingPicTime + "_PollingPic.jpg"; - fout = new FileOutputStream(filename); //将字节写入文件 long offset = 0; ByteBuffer buffers = strAiopPollingPic.pBufferPicture.getByteBuffer(offset, strAiopPollingPic.dwPictureSize); byte[] bytes = new byte[strAiopPollingPic.dwPictureSize]; 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; //AI开放平台接入轮询视频检测报警信息 case HCNetSDK.COMM_UPLOAD_AIOP_POLLING_VIDEO: - System.out.println("AI开放平台接入轮询视频检测报警事件上传"); + //System.out.println("AI开放平台接入轮询视频检测报警事件上传"); HCNetSDK.NET_AIOP_POLLING_VIDEO_HEAD strAiopPollingVideo = new HCNetSDK.NET_AIOP_POLLING_VIDEO_HEAD(); strAiopPollingVideo.write(); Pointer pAiopPollingVideo = strAiopPollingVideo.getPointer(); pAiopPollingVideo.write(0, pAlarmInfo.getByteArray(0, strAiopPollingVideo.size()), 0, strAiopPollingVideo.size()); strAiopPollingVideo.read(); - System.out.println("通道号:" + strAiopPollingVideo.dwChannel); - System.out.println("轮询视频任务ID:" + new String(strAiopPollingVideo.szTaskID)); + //System.out.println("通道号:" + strAiopPollingVideo.dwChannel); + //System.out.println("轮询视频任务ID:" + new String(strAiopPollingVideo.szTaskID)); String AiopPollingVideoTime = "" + String.format("%04d", strAiopPollingVideo.struTime.wYear) + String.format("%02d", strAiopPollingVideo.struTime.wMonth) + String.format("%02d", strAiopPollingVideo.struTime.wDay) + @@ -1459,53 +950,25 @@ public class AlarmDataParse { String.format("%03d", strAiopPollingVideo.struTime.wMilliSec); //AIOPData数据保存 if (strAiopPollingVideo.dwAIOPDataSize > 0) { - FileOutputStream fout; - try { - String filename = "../pic/" + new String(pAlarmer.sDeviceIP).trim() + - "_" + AiopPollingVideoTime + "_PollingVideoData.json"; - fout = new FileOutputStream(filename); //将字节写入文件 long offset = 0; ByteBuffer buffers = strAiopPollingVideo.pBufferAIOPData.getByteBuffer(offset, strAiopPollingVideo.dwAIOPDataSize); byte[] bytes = new byte[strAiopPollingVideo.dwAIOPDataSize]; 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 (strAiopPollingVideo.dwPictureSize > 0) { - FileOutputStream fout; - try { - String filename = "../pic/" + new String(pAlarmer.sDeviceIP).trim() + - "_" + AiopPollingVideoTime + "_PollingVideo.jpg"; - fout = new FileOutputStream(filename); //将字节写入文件 long offset = 0; ByteBuffer buffers = strAiopPollingVideo.pBufferPicture.getByteBuffer(offset, strAiopPollingVideo.dwPictureSize); byte[] bytes = new byte[strAiopPollingVideo.dwPictureSize]; 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; default: - System.out.println("报警类型" + Integer.toHexString(lCommand)); + //System.out.println("报警类型" + Integer.toHexString(lCommand)); break; } } diff --git a/src/main/java/com/yzx/IHardwareEquipment.java b/src/main/java/com/yzx/IHardwareEquipment.java index 17905eb..7670f92 100644 --- a/src/main/java/com/yzx/IHardwareEquipment.java +++ b/src/main/java/com/yzx/IHardwareEquipment.java @@ -7,4 +7,9 @@ public interface IHardwareEquipment { */ void cleanup(); + String getDeployInfo(); + + //获取状态 + int getStatus(); + } diff --git a/src/main/java/com/yzx/Main.java b/src/main/java/com/yzx/Main.java index 26f58df..8798652 100644 --- a/src/main/java/com/yzx/Main.java +++ b/src/main/java/com/yzx/Main.java @@ -5,18 +5,47 @@ import com.yzx.callback.AlarmCallback; import com.yzx.impl.HKVersion; import com.yzx.impl.HardwareEquipmentInfo; +import java.util.ArrayList; +import java.util.List; + public class Main { + + private static List hardwareEquipmentList = new ArrayList<>(); + + private static AlarmCallback alarmCallback = new AlarmCallbackImpl(); public static void main(String[] args) { + new Main().run(); + } - AlarmCallback alarmCallback = new AlarmCallback() { - @Override - public void process(JSONObject json) { - System.out.println(" 告警回调触发......"); - System.out.println("json = " + json); + public void run(){ + //定时任务每分钟执行一次 + //问题 人员名称获取不到? + //1.通过isapi 的方式获取设备布防状态,如果没有布防,则更新数据库,并重新布防 + //2.一个设备开一个线程处理数据 + //3.如果文件上传失败,需要重试,如果失败了,先存在本地,利用数据库的id作为标识,写一个定时任务,重新更新和上传. + + new Thread(() -> { + IHardwareEquipment hardwareEquipment1 = new HKVersion(new HardwareEquipmentInfo("192.168.69.128",(short) 8000,"admin","yzx123456",alarmCallback)); + if(hardwareEquipment1.getStatus() == 1){ + String deployInfo1 = hardwareEquipment1.getDeployInfo(); + System.out.println("deployInfo = " + deployInfo1); } - }; + }).start(); - new HKVersion(new HardwareEquipmentInfo("192.168.69.128",(short) 8000,"admin","yzx123456",alarmCallback)); - new HKVersion(new HardwareEquipmentInfo("192.168.69.140",(short) 8000,"admin","yzx123456",alarmCallback)); + new Thread(() -> { + IHardwareEquipment hardwareEquipment2 = new HKVersion(new HardwareEquipmentInfo("192.168.69.140",(short) 8000,"admin","yzx123456",alarmCallback)); + if(hardwareEquipment2.getStatus() == 1){ + String deployInfo2 = hardwareEquipment2.getDeployInfo(); + System.out.println("deployInfo = " + deployInfo2); + } + }).start(); } + + private static class AlarmCallbackImpl implements AlarmCallback{ + @Override + public void process(JSONObject json) { + System.out.println(" 告警回调触发......"); + System.out.println("json = " + json); + } + }; } diff --git a/src/main/java/com/yzx/impl/HKVersion.java b/src/main/java/com/yzx/impl/HKVersion.java index ba3fd34..e63c1d1 100644 --- a/src/main/java/com/yzx/impl/HKVersion.java +++ b/src/main/java/com/yzx/impl/HKVersion.java @@ -13,9 +13,9 @@ public class HKVersion implements IHardwareEquipment { //海康SDK private static HCNetSDK hCNetSDK; - private int[] lUserID = new int[]{0, 0, 0, 0, 0};//用户句柄 实现对设备登录 - private int[] lAlarmHandle = new int[]{-1, -1, -1, -1, -1};//报警布防句柄 - private int[] lAlarmHandle_V50 = new int[]{-1, -1, -1, -1, -1}; //v50报警布防句柄 + private int lUserID = 0;//用户句柄 实现对设备登录 + private int lAlarmHandle = -1;//报警布防句柄 + private int lAlarmHandle_V50 = -1; //v50报警布防句柄 private int lListenHandle = -1;//报警监听句柄 private FMSGCallBack_V31 fMSFCallBack_V31 = null; private FMSGCallBack fMSFCallBack=null; @@ -59,13 +59,12 @@ public class HKVersion implements IHardwareEquipment { struNET_DVR_LOCAL_GENERAL_CFG.write(); Pointer pStrNET_DVR_LOCAL_GENERAL_CFG = struNET_DVR_LOCAL_GENERAL_CFG.getPointer(); hCNetSDK.NET_DVR_SetSDKLocalCfg(17, pStrNET_DVR_LOCAL_GENERAL_CFG); - this.Login_V40(0, info.getIp(), info.getPort(), info.getUsername(), info.getPassword()); //登录设备 - - this.SetAlarm(0);//报警布防,和报警监听二选一即可 + this.Login_V40(info.getIp(), info.getPort(), info.getUsername(), info.getPassword()); //登录设备 + this.SetAlarm();//报警布防,和报警监听二选一即可 } - private void SetAlarm(int i) { - if (lAlarmHandle[i] < 0)//尚未布防,需要布防 + private void SetAlarm() { + if (lAlarmHandle < 0)//尚未布防,需要布防 { //报警布防参数设置 HCNetSDK.NET_DVR_SETUPALARM_PARAM m_strAlarmInfo = new HCNetSDK.NET_DVR_SETUPALARM_PARAM(); @@ -74,9 +73,9 @@ public class HKVersion implements IHardwareEquipment { m_strAlarmInfo.byAlarmInfoType = 1; // 智能交通报警信息上传类型:0- 老报警信息(NET_DVR_PLATE_RESULT),1- 新报警信息(NET_ITS_PLATE_RESULT) m_strAlarmInfo.byDeployType = 0; //布防类型:0-客户端布防,1-实时布防 m_strAlarmInfo.write(); - lAlarmHandle[i] = hCNetSDK.NET_DVR_SetupAlarmChan_V41(lUserID[i], m_strAlarmInfo); - System.out.println("lAlarmHandle: " + lAlarmHandle[i]); - if (lAlarmHandle[i] == -1) { + lAlarmHandle = hCNetSDK.NET_DVR_SetupAlarmChan_V41(lUserID, m_strAlarmInfo); + System.out.println("lAlarmHandle: " + lAlarmHandle); + if (lAlarmHandle == -1) { System.out.println("布防失败,错误码为" + hCNetSDK.NET_DVR_GetLastError()); return; } else { @@ -92,13 +91,12 @@ public class HKVersion implements IHardwareEquipment { /** * 设备登录V40 与V30功能一致 * - * @param i 登录设备编号 * @param ip 设备IP * @param port SDK端口,默认设备的8000端口 * @param user 设备用户名 * @param psw 设备密码 */ - private void Login_V40(int i, String ip, short port, String user, String psw) { + private void Login_V40( String ip, short port, String user, String psw) { //注册 HCNetSDK.NET_DVR_USER_LOGIN_INFO m_strLoginInfo = new HCNetSDK.NET_DVR_USER_LOGIN_INFO();//设备登录信息 HCNetSDK.NET_DVR_DEVICEINFO_V40 m_strDeviceInfo = new HCNetSDK.NET_DVR_DEVICEINFO_V40();//设备信息 @@ -120,8 +118,8 @@ public class HKVersion implements IHardwareEquipment { // m_strLoginInfo.byLoginMode=1; //ISAPI登录 m_strLoginInfo.write(); - lUserID[i] = hCNetSDK.NET_DVR_Login_V40(m_strLoginInfo, m_strDeviceInfo); - if (lUserID[i] == -1) { + lUserID = hCNetSDK.NET_DVR_Login_V40(m_strLoginInfo, m_strDeviceInfo); + if (lUserID == -1) { System.out.println("登录失败,错误码为" + hCNetSDK.NET_DVR_GetLastError()); } else { System.out.println(ip + ":设备登录成功!"); @@ -133,6 +131,60 @@ public class HKVersion implements IHardwareEquipment { hCNetSDK.NET_DVR_Cleanup(); } + @Override + public String getDeployInfo() { + String url = "GET /ISAPI/AccessControl/DeployInfo"; + HCNetSDK.NET_DVR_XML_CONFIG_INPUT struXMLInput = new HCNetSDK.NET_DVR_XML_CONFIG_INPUT(); + struXMLInput.read(); + HCNetSDK.BYTE_ARRAY stringRequest = new HCNetSDK.BYTE_ARRAY(1024); + stringRequest.read(); + //输入ISAPI协议命令 + System.arraycopy(url.getBytes(), 0, stringRequest.byValue, 0, url.length()); + stringRequest.write(); + struXMLInput.dwSize = struXMLInput.size(); + struXMLInput.lpRequestUrl = stringRequest.getPointer(); + struXMLInput.dwRequestUrlLen = url.length(); + struXMLInput.lpInBuffer = null; + struXMLInput.dwInBufferSize = 0; + struXMLInput.write(); + + HCNetSDK.BYTE_ARRAY stringXMLOut = new HCNetSDK.BYTE_ARRAY(8 * 1024); + stringXMLOut.read(); + HCNetSDK.BYTE_ARRAY struXMLStatus = new HCNetSDK.BYTE_ARRAY(1024); + struXMLStatus.read(); + HCNetSDK.NET_DVR_XML_CONFIG_OUTPUT struXMLOutput = new HCNetSDK.NET_DVR_XML_CONFIG_OUTPUT(); + struXMLOutput.read(); + struXMLOutput.dwSize = struXMLOutput.size(); + struXMLOutput.lpOutBuffer = stringXMLOut.getPointer(); + struXMLOutput.dwOutBufferSize = stringXMLOut.size(); + struXMLOutput.lpStatusBuffer = struXMLStatus.getPointer(); + struXMLOutput.dwStatusSize = struXMLStatus.size(); + struXMLOutput.write(); + + if(hCNetSDK.NET_DVR_STDXMLConfig(lUserID,struXMLInput,struXMLOutput)){ + stringXMLOut.read(); + System.out.println("输出文本大小:" + struXMLOutput.dwReturnedXMLSize); + //打印输出XML文本 + String strOutXML = new String(stringXMLOut.byValue).trim(); + System.out.println(strOutXML); + struXMLStatus.read(); + String strStatus = new String(struXMLStatus.byValue).trim(); + System.out.println(strStatus); + return strOutXML; + }else{ + System.out.println("获取布防信息失败:" + hCNetSDK.NET_DVR_GetLastError()); + return null; + } + } + + @Override + public int getStatus() { + if(lUserID != 0 && lAlarmHandle != -1){ + return 1; + } + return -1; + } + /** * 动态库加载 *