add ptzTrack toPreset fun
| | |
| | | # Compiled Object files, Static and Dynamic libs (Shared Objects) |
| | | |
| | | .idea/ |
| | | .vscode/ |
| | | |
| | | # Folders |
| | | _obj |
New file |
| | |
| | | #include "HCNetSDK.h" |
| | | #include <stdio.h> |
| | | #include <string.h> |
| | | #include <time.h> |
| | | using namespace std; |
| | | |
| | | #include "hikptz.h" |
| | | |
| | | void ptzTrack(char *ip, char *userName, char *password, int port, int channel, int xBottom, int xTop, int yBottom, int yTop) |
| | | { |
| | | // 初始化 |
| | | NET_DVR_Init(); |
| | | |
| | | //设置连接时间与重连时间 |
| | | NET_DVR_SetConnectTime(2000, 1); |
| | | NET_DVR_SetReconnect(10000, true); |
| | | |
| | | //设置异常消息回调函数 |
| | | NET_DVR_SetExceptionCallBack_V30(0, NULL, NULL, NULL); |
| | | |
| | | // 注册设备 |
| | | |
| | | //登录参数,包括设备地址、登录用户、密码等 |
| | | NET_DVR_USER_LOGIN_INFO struLoginInfo = {0}; |
| | | struLoginInfo.bUseAsynLogin = 0; //同步登录方式 |
| | | strcpy(struLoginInfo.sDeviceAddress, ip); //设备IP地址 |
| | | struLoginInfo.wPort = port; //设备服务端口 |
| | | strcpy(struLoginInfo.sUserName, userName); //设备登录用户名 |
| | | strcpy(struLoginInfo.sPassword, password); //设备登录密码 |
| | | |
| | | //设备信息, 输出参数 |
| | | NET_DVR_DEVICEINFO_V40 struDeviceInfoV40 = {0}; |
| | | |
| | | LONG lUserID; |
| | | lUserID = NET_DVR_Login_V40(&struLoginInfo, &struDeviceInfoV40); |
| | | if (lUserID < 0) |
| | | { |
| | | printf("Login failed, error code: %d\n", NET_DVR_GetLastError()); |
| | | NET_DVR_Cleanup(); |
| | | return; |
| | | } |
| | | |
| | | LPNET_DVR_POINT_FRAME zoneInfo = {0}; |
| | | zoneInfo->xTop = xTop; // |
| | | zoneInfo->yTop = yTop; // |
| | | zoneInfo->xBottom = xBottom; // |
| | | zoneInfo->yBottom = yBottom; // |
| | | |
| | | int iChannel = channel; //设备通道号 |
| | | if (!NET_DVR_PTZSelZoomIn_EX(lUserID, iChannel, zoneInfo)) |
| | | { |
| | | printf("PAN_LEFT start failed, error code: %d\n", NET_DVR_GetLastError()); |
| | | NET_DVR_Logout(lUserID); |
| | | NET_DVR_Cleanup(); |
| | | return; |
| | | } |
| | | |
| | | //注销用户 |
| | | NET_DVR_Logout(lUserID); |
| | | |
| | | //释放SDK资源 |
| | | NET_DVR_Cleanup(); |
| | | |
| | | return; |
| | | } |
| | | |
| | | void toPreset(char *ip, char *userName, char *password, int port, int channel) |
| | | { |
| | | // 初始化 |
| | | NET_DVR_Init(); |
| | | //设置连接时间与重连时间 |
| | | NET_DVR_SetConnectTime(2000, 1); |
| | | NET_DVR_SetReconnect(10000, true); |
| | | |
| | | //--------------------------------------- |
| | | //设置异常消息回调函数 |
| | | NET_DVR_SetExceptionCallBack_V30(0, NULL, NULL, NULL); |
| | | |
| | | //--------------------------------------- |
| | | // 注册设备 |
| | | LONG lUserID; |
| | | //登录参数,包括设备地址、登录用户、密码等 |
| | | NET_DVR_USER_LOGIN_INFO struLoginInfo = {0}; |
| | | struLoginInfo.bUseAsynLogin = 0; //同步登录方式 |
| | | strcpy(struLoginInfo.sDeviceAddress, ip); //设备IP地址 |
| | | struLoginInfo.wPort = port; //设备服务端口 |
| | | strcpy(struLoginInfo.sUserName, userName); //设备登录用户名 |
| | | strcpy(struLoginInfo.sPassword, password); //设备登录密码 |
| | | |
| | | //设备信息, 输出参数 |
| | | NET_DVR_DEVICEINFO_V40 struDeviceInfoV40 = {0}; |
| | | |
| | | lUserID = NET_DVR_Login_V40(&struLoginInfo, &struDeviceInfoV40); |
| | | if (lUserID < 0) |
| | | { |
| | | printf("Login failed, error code: %d\n", NET_DVR_GetLastError()); |
| | | NET_DVR_Cleanup(); |
| | | return; |
| | | } |
| | | |
| | | int iChannel = channel; //设备通道号 |
| | | DWORD dwPTZCommand = GOTO_PRESET; //转到预置点 |
| | | if (!NET_DVR_PTZPreset_Other(lUserID, iChannel, GOTO_PRESET, 1)) |
| | | { |
| | | printf("PAN_LEFT start failed, error code: %d\n", NET_DVR_GetLastError()); |
| | | NET_DVR_Logout(lUserID); |
| | | NET_DVR_Cleanup(); |
| | | return; |
| | | } |
| | | //注销用户 |
| | | NET_DVR_Logout(lUserID); |
| | | |
| | | //释放SDK资源 |
| | | NET_DVR_Cleanup(); |
| | | |
| | | return; |
| | | } |
| | |
| | | package hikvoice
|
| | | package hikControl
|
| | |
|
| | | /*
|
| | | #cgo CFLAGS: -I${SRCDIR}/include -w -g
|
| | | #cgo LDFLAGS: -L${SRCDIR}/libs
|
| | | #cgo LDFLAGS: -lHikVoice -lAudioRender -lHCCore -lhcnetsdk -lhpr
|
| | | #cgo LDFLAGS: -ldl -lm
|
| | |
|
| | | #cgo CXXFLAGS: -I${SRCDIR}/include -w -g
|
| | | #cgo LDFLAGS: -L${SRCDIR}/lib
|
| | | #cgo LDFLAGS: -lhcnetsdk -lhpr -lHCCore
|
| | | #include <stdlib.h>
|
| | | #include "hikptz.h"
|
| | | */
|
| | | import "C"
|
| | |
|
| | | import (
|
| | | "unsafe"
|
| | | "unsafe"
|
| | | )
|
| | |
|
| | | // SendVoice Send Voice
|
| | | func PtzTrack(ip,password,userName string, port, channel,xBottom,xTop,yBottom,yTop int) {
|
| | | |
| | | cip := C.CString(ip)
|
| | | defer C.free(unsafe.Pointer(cip))
|
| | | cusrname := C.CString(userName)
|
| | | defer C.free(unsafe.Pointer(cusrname))
|
| | | cpasswd := C.CString(password)
|
| | | defer C.free(unsafe.Pointer(cpasswd))
|
| | | |
| | | func PtzTrack(ip, userName, password string, port, channel, xBottom, xTop, yBottom, yTop int) {
|
| | |
|
| | | C.PtzTrack(cip, cusrname, cpasswd, C.int(port), C.int(channel),C.int(xBottom),C.int(xTop),C.int(yBottom),C.int(yTop) )
|
| | | cIp := C.CString(ip)
|
| | | cUsrname := C.CString(userName)
|
| | | cPasswd := C.CString(password)
|
| | |
|
| | | defer C.free(unsafe.Pointer(cIp))
|
| | | defer C.free(unsafe.Pointer(cUsrname))
|
| | | defer C.free(unsafe.Pointer(cPasswd))
|
| | |
|
| | | C.ptzTrack(cIp, cUsrname, cPasswd, C.int(port), C.int(channel), C.int(xBottom), C.int(xTop), C.int(yBottom), C.int(yTop))
|
| | | }
|
| | |
|
| | | // void ToPreset(char *ip, char *userName, char *password, char *port ,int channel )
|
| | | func ToPreset(ip, userName, password string, port, ch int) {
|
| | |
|
| | | func ToPreset(ip,userName,password string, port , ch int) {
|
| | | |
| | | cip := C.CString(ip)
|
| | | defer C.free(unsafe.Pointer(cip))
|
| | | cusrname := C.CString(userName)
|
| | | defer C.free(unsafe.Pointer(cusrname))
|
| | | cpasswd := C.CString(password)
|
| | | defer C.free(unsafe.Pointer(cpasswd))
|
| | | |
| | | defer C.free(unsafe.Pointer(cip))
|
| | | cusrname := C.CString(userName)
|
| | | defer C.free(unsafe.Pointer(cusrname))
|
| | | cpasswd := C.CString(password)
|
| | | defer C.free(unsafe.Pointer(cpasswd))
|
| | |
|
| | | C.PtzTrack(cip, cusrname, cpasswd, C.int(port), C.int(ch) )
|
| | | } |
| | | C.toPreset(cip, cusrname, cpasswd, C.int(port), C.int(ch))
|
| | | }
|
| | |
| | | #ifndef _HIKPTZ_H
|
| | | #define _HIKPTZ_H
|
| | | |
| | |
|
| | | #ifdef __cplusplus
|
| | | extern "C" { |
| | | extern "C"
|
| | | {
|
| | | #endif
|
| | | |
| | | void PtzTrack(char *ip, char *userName, char *password, char *port ,int channel ,int xBottom ,int xTop ,int yBottom ,int yTop )
|
| | | void ToPreset(char *ip, char *userName, char *password, int port ,int channel )
|
| | | |
| | |
|
| | | void ptzTrack(char *ip, char *userName, char *password, int port, int channel, int xBottom, int xTop, int yBottom, int yTop);
|
| | | void toPreset(char *ip, char *userName, char *password, int port, int channel);
|
| | | #ifdef __cplusplus
|
| | | }
|
| | | #endif
|
| | | |
| | |
|
| | | #endif |
New file |
| | |
| | | package hikControl |
| | | |
| | | import ( |
| | | "fmt" |
| | | "testing" |
| | | ) |
| | | |
| | | func TestMain(m *testing.M) { |
| | | fmt.Println("begin") |
| | | ip := "192.168.5.35" |
| | | username := "admin" |
| | | passwd := "a1234567" |
| | | port := 8000 |
| | | PtzTrack(ip, username, passwd, port, 1, 50, 50, 50, 50) |
| | | fmt.Println("end PtzTrack") |
| | | |
| | | ToPreset(ip, username, passwd, port, 1) |
| | | fmt.Println("end ToPreset") |
| | | } |