package com.netsdk.demo.customize; import com.netsdk.demo.util.CaseMenu; import com.netsdk.lib.NetSDKLib; import com.netsdk.lib.ToolKits; import com.netsdk.lib.enumeration.EM_EVENT_TYPE; import com.netsdk.lib.utils.Initialization; import com.sun.jna.Pointer; import java.io.File; import java.io.UnsupportedEncodingException; /** * @author 291189 * @version 1.0 * @description ERR220215041 * @date 2022/2/16 9:14 */ public class CrossregionDetectionDemo extends Initialization { int channel=0; NetSDKLib.LLong attachHandle=new NetSDKLib.LLong(0); /** * 订阅智能任务 */ public NetSDKLib.LLong AttachEventRealLoadPic() { // 先退订,设备不会对重复订阅作校验,重复订阅后会有重复的事件返回 if(attachHandle.longValue()!=0){ this.DetachEventRealLoadPic(); } // 需要图片 int bNeedPicture = 1; attachHandle = netSdk.CLIENT_RealLoadPictureEx(loginHandle, channel, EM_EVENT_TYPE.EVENT_IVS_CROSSREGIONDETECTION.getType(), bNeedPicture, AnalyzerDataCB.getInstance(), null, null); if (attachHandle.longValue() != 0) { System.out.printf("Chn[%d] CLIENT_RealLoadPictureEx Success\n", channel); } else { System.out.printf("Chn[%d] CLIENT_RealLoadPictureEx Failed!LastError = %s\n", channel, ToolKits.getErrorCode()); } return attachHandle; } /** * 报警事件(智能)回调 */ private static class AnalyzerDataCB implements NetSDKLib.fAnalyzerDataCallBack { private final File picturePath; private static AnalyzerDataCB instance; private AnalyzerDataCB() { picturePath = new File("./AnalyzerPicture/"); if (!picturePath.exists()) { picturePath.mkdirs(); } } public static AnalyzerDataCB getInstance() { if (instance == null) { synchronized (AnalyzerDataCB.class) { if (instance == null) { instance = new AnalyzerDataCB(); } } } return instance; } @Override public int invoke(NetSDKLib.LLong lAnalyzerHandle, int dwAlarmType, Pointer pAlarmInfo, Pointer pBuffer, int dwBufSize, Pointer dwUser, int nSequence, Pointer reserved) { if (lAnalyzerHandle == null || lAnalyzerHandle.longValue() == 0) { return -1; } switch (dwAlarmType) { case NetSDKLib.EVENT_IVS_CROSSREGIONDETECTION : { // 警戒区事件(对应 DEV_EVENT_CROSSREGION_INFO) System.out.println("警戒区事件"); NetSDKLib.DEV_EVENT_CROSSREGION_INFO msg = new NetSDKLib.DEV_EVENT_CROSSREGION_INFO(); ToolKits.GetPointerData(pAlarmInfo, msg); //采用该字段区分是区域入侵还是事件,该字段不携带则是通用的区域入侵事件,携带则根据内容区分实际的事件类型,目前只有IllegalDumping(垃圾违规投放) byte[] szRealEventType = msg.szRealEventType; try { System.out.println("szRealEventType UTF-8:"+new String(szRealEventType,"UTF-8")); System.out.println("szRealEventType GBK:"+new String(szRealEventType,"GBK")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } break; } default: System.out.println("其他事件--------------------"+ dwAlarmType); break; } return 0; } } /** * 停止侦听智能事件 */ public void DetachEventRealLoadPic() { if (this.attachHandle.longValue() != 0) { netSdk.CLIENT_StopLoadPic(this.attachHandle); } } public void RunTest() { System.out.println("Run Test"); CaseMenu menu = new CaseMenu();; menu.addItem((new CaseMenu.Item(this , "AttachEventRealLoadPic" , "AttachEventRealLoadPic"))); menu.addItem((new CaseMenu.Item(this , "DetachEventRealLoadPic" , "DetachEventRealLoadPic"))); menu.run(); } public static void main(String[] args) { CrossregionDetectionDemo crossregionDetectionDemo=new CrossregionDetectionDemo(); InitTest("172.30.2.189",37777,"admin","admin123"); crossregionDetectionDemo.RunTest(); LoginOut(); } }