0
点赞
收藏
分享

微信扫一扫

大华SDK二次开发,JAVA

木匠0819 2022-03-30 阅读 126
java

最近对接大华接口要控制摄像头的旋转,SDK源码中注释比较少也没有详细的技术文档,自己研究下写了这个帮助类可以实现摄像头8个方向的控制,首先需要引入netsdk的jar包,直接上源码:

public class PTZControlUtil {

// 登陆句柄
private static NetSDKLib.LLong m_hLoginHandle = new NetSDKLib.LLong(0);

// 网络断线处理
private static DisConnect disConnect = new DisConnect();

// 设备连接恢复,实现设备连接恢复接口
private static HaveReConnect haveReConnect = new HaveReConnect();


/**
* 云台控制
* @param m_strIp ip
* @param m_nPort 端口
* @param m_strUser 登录名
* @param m_strPassword 密码
* @param nChannelID 通道id 默认为0
* @param command 命令
* @param lParam1 默认 0,当有左上或左下等操作时才会传值 (1-8)
* @param lParam2 垂直/水平 移动速度 (1-8)
*/

public static void upControlPtz(String m_strIp, int m_nPort, String m_strUser, String m_strPassword, int nChannelID, String command, int lParam1, int lParam2) {
// 初始化
LoginModule.init(disConnect, haveReConnect);
// 若未登录,先登录
if (m_hLoginHandle.longValue() == 0) {
LoginModule.login(m_strIp, m_nPort, m_strUser, m_strPassword);
}
// 开始移动,若超过角度则会变为左右移动
if (m_hLoginHandle.longValue() != 0) {
control(nChannelID, command, lParam1, lParam2);
}
// 退出
LoginModule.logout();
// 释放资源
LoginModule.cleanup();
}

/**
* 云台控制
* @param nChannelID
* @param command
* @param lParam1
* @param lParam2
*/

private static void control(int nChannelID, String command, int lParam1, int lParam2) {
if ("UP".equals(command)) {
PtzControlModule.ptzControlUpStart(nChannelID, 0, lParam2);
PtzControlModule.ptzControlUpEnd(nChannelID);
} else if ("DOWN".equals(command)) {
PtzControlModule.ptzControlDownStart(nChannelID, 0, lParam2);
PtzControlModule.ptzControlDownEnd(nChannelID);
} else if ("LEFT".equals(command)) {
PtzControlModule.ptzControlLeftStart(nChannelID, 0, lParam2);
PtzControlModule.ptzControlLeftEnd(nChannelID);
} else if ("RIGHT".equals(command)) {
PtzControlModule.ptzControlRightStart(nChannelID, 0, lParam2);
PtzControlModule.ptzControlRightEnd(nChannelID);
} else if ("LEFT_UP".equals(command)) {
PtzControlModule.ptzControlLeftUpStart(nChannelID, lParam1, lParam2);
PtzControlModule.ptzControlLeftUpEnd(nChannelID);
} else if ("LEFT_DOWN".equals(command)) {
PtzControlModule.ptzControlLeftDownStart(nChannelID, lParam1, lParam2);
PtzControlModule.ptzControlLeftDownEnd(nChannelID);
} else if ("RIGHT_UP".equals(command)) {
PtzControlModule.ptzControlRightUpStart(nChannelID, lParam1, lParam2);
PtzControlModule.ptzControlRightUpEnd(nChannelID);
} else if ("RIGHT_DOWN".equals(command)) {
PtzControlModule.ptzControlRightDownStart(nChannelID, lParam1, lParam2);
PtzControlModule.ptzControlRightDownEnd(nChannelID);
} else if ("FOCUS_NEAR".equals(command)) {
PtzControlModule.ptzControlFocusAddStart(nChannelID, lParam2);
PtzControlModule.ptzControlFocusAddEnd(nChannelID);
} else if ("FOCUS_FAR".equals(command)) {
PtzControlModule.ptzControlFocusDecStart(nChannelID, lParam2);
PtzControlModule.ptzControlFocusDecEnd(nChannelID);
} else if ("ZOOM_IN".equals(command)) {
PtzControlModule.ptzControlZoomAddStart(nChannelID, lParam2);
PtzControlModule.ptzControlZoomAddEnd(nChannelID);
} else if ("ZOOM_OUT".equals(command)) {
PtzControlModule.ptzControlZoomDecStart(nChannelID, lParam2);
PtzControlModule.ptzControlZoomDecEnd(nChannelID);
} else if ("IRIS_ENLARGE".equals(command)) {
PtzControlModule.ptzControlIrisAddStart(nChannelID, lParam2);
PtzControlModule.ptzControlIrisAddEnd(nChannelID);
} else if ("IRIS_REDUCE".equals(command)) {
PtzControlModule.ptzControlIrisDecStart(nChannelID, lParam2);
PtzControlModule.ptzControlIrisDecEnd(nChannelID);
}
}

// 设备断线回调: 通过 CLIENT_Init 设置该回调函数,当设备出现断线时,SDK会调用该函数
private static class DisConnect implements NetSDKLib.fDisConnect {
public void invoke(NetSDKLib.LLong m_hLoginHandle, String pchDVRIP, int nDVRPort, Pointer dwUser) {
System.out.printf("Device[%s] Port[%d] DisConnect!\n", pchDVRIP, nDVRPort);
}
}

// 网络连接恢复,设备重连成功回调
// 通过 CLIENT_SetAutoReconnect 设置该回调函数,当已断线的设备重连成功时,SDK会调用该函数
private static class HaveReConnect implements NetSDKLib.fHaveReConnect {
public void invoke(NetSDKLib.LLong m_hLoginHandle, String pchDVRIP, int nDVRPort, Pointer dwUser) {
System.out.printf("ReConnect Device[%s] Port[%d]\n", pchDVRIP, nDVRPort);
}
}

}
举报

相关推荐

0 条评论