From f64883252bf183ef08b95954e5f04e99b14c039c Mon Sep 17 00:00:00 2001
From: heyujie <516346543@qq.com>
Date: 星期四, 14 十月 2021 15:09:08 +0800
Subject: [PATCH] topreset

---
 hikptz.go |   20 +++++++---
 hikptz.h  |    1 
 hikptz.c  |   52 ++++++++++++++++++++++++++
 3 files changed, 67 insertions(+), 6 deletions(-)

diff --git a/hikptz.c b/hikptz.c
index 0db4181..e033bfa 100644
--- a/hikptz.c
+++ b/hikptz.c
@@ -60,3 +60,55 @@
   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,g_ExceptionCallBack, 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))
+    {
+        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;
+}
diff --git a/hikptz.go b/hikptz.go
index 449c42c..45d0d19 100644
--- a/hikptz.go
+++ b/hikptz.go
@@ -16,7 +16,7 @@
 )
 
 // SendVoice Send Voice
-func PtzTrack(ip,password,port,userName string, channel,xBottom,xTop,yBottom,yTop int)  {
+func PtzTrack(ip,password,userName string, port, channel,xBottom,xTop,yBottom,yTop int)  {
 	
 	cip := C.CString(ip)
     defer C.free(unsafe.Pointer(cip))
@@ -24,14 +24,22 @@
     defer C.free(unsafe.Pointer(cusrname))
     cpasswd := C.CString(password)
     defer C.free(unsafe.Pointer(cpasswd))
-    cport := C.CString(port)
-    defer C.free(unsafe.Pointer(cport))
+ 
 
-	C.PtzTrack(cip, cusrname, cpasswd, cport, C.int(channel),C.int(xBottom),C.int(xTop),C.int(yBottom),C.int(yTop) )
+	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,password,port,userName string, 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))
+    
+
+	C.PtzTrack(cip, cusrname, cpasswd,  C.int(port), C.int(ch) )
 }
\ No newline at end of file
diff --git a/hikptz.h b/hikptz.h
index 14b3cba..66090b4 100644
--- a/hikptz.h
+++ b/hikptz.h
@@ -6,6 +6,7 @@
 #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 )
  
 #ifdef __cplusplus
 }

--
Gitblit v1.8.0