布防
HCNetSDK hCNetSDK = HCNetSDK.INSTANCE;
//初始化SDK
boolean initSuc = hCNetSDK.NET_DVR_Init();
//设置连接超时时间与重连功能
hCNetSDK.NET_DVR_SetConnectTime(2000,1);
hCNetSDK.NET_DVR_SetReconnect(10000,true);
NativeLong lUserID;//用户ID
HCNetSDK.NET_DVR_DEVICEINFO_V30 m_strDeviceInfo;//设备信息
lUserID = new NativeLong(-1);
String m_sDeviceIP = "";//已登录设备的IP地址
int port = ;//设备端口号
String userName = "";//用户名
String password = "";//密码
m_strDeviceInfo = new HCNetSDK.NET_DVR_DEVICEINFO_V30();
//注册设备
lUserID = hCNetSDK.NET_DVR_Login_V30(m_sDeviceIP, (short) port, userName, password, m_strDeviceInfo);
//如果注册失败返回-1,获取错误码
if (lUserID.intValue()<0){
System.out.println("Login failed, error code="+hCNetSDK.NET_DVR_GetLastError());
}
//设置报警回调函数
FMSGCallBack_V31 fmsgCallBack_v31=new FMSGCallBack_V31();
boolean b = hCNetSDK.NET_DVR_SetDVRMessageCallBack_V31(fmsgCallBack_v31, null);
//如果设置报警回调失败,获取错误码
if (!b){
System.out.println("SetDVRMessageCallBack failed, error code="+hCNetSDK.NET_DVR_GetLastError());
}
//建立报警上传通道(布防)
//布防参数
HCNetSDK.NET_DVR_SETUPALARM_PARAM net_dvr_setupalarm_param=new HCNetSDK.NET_DVR_SETUPALARM_PARAM();
NativeLong nativeLong = hCNetSDK.NET_DVR_SetupAlarmChan_V41(lUserID, net_dvr_setupalarm_param);
//如果布防失败返回-1
if (nativeLong.intValue()<0){
System.out.println("SetupAlarmChan failed, error code="+hCNetSDK.NET_DVR_GetLastError());
//注销
hCNetSDK.NET_DVR_Logout(lUserID);
//释放SDK资源
hCNetSDK.NET_DVR_Cleanup();
}
try {
//等待设备上传报警信息
Thread.sleep(600001);
} catch (InterruptedException e) {
e.printStackTrace();
}
//撤销布防上传通道
if(!hCNetSDK.NET_DVR_CloseAlarmChan_V30(nativeLong)){
//System.out.println("NET_DVR_CloseAlarmChan_V30 failed, error code="+hCNetSDK.NET_DVR_GetLastError());
//注销
hCNetSDK.NET_DVR_Logout(lUserID);
//释放SDK资源
hCNetSDK.NET_DVR_Cleanup();
}
//注销用户
hCNetSDK.NET_DVR_Logout(lUserID);
//释放SDK资源
hCNetSDK.NET_DVR_Cleanup();
报警回调函数
public class FMSGCallBack_V31 implements HCNetSDK.FMSGCallBack_V31 {
//lCommand 上传消息类型 pAlarmer 报警设备信息 pAlarmInfo 报警信息 dwBufLen 报警信息缓存大小 pUser 用户数据
public boolean invoke(int lCommand, HCNetSDK.NET_DVR_ALARMER pAlarmer, Pointer pAlarmInfo, int dwBufLen, Pointer pUser) {
switch (lCommand){
/**
* 这里根据SDK获取
*/
}
return true;
}
}
public static interface FMSGCallBack_V31 extends StdCallCallback {
public boolean invoke(int lCommand, NET_DVR_ALARMER pAlarmer, Pointer pAlarmInfo, int dwBufLen, Pointer pUser);
}