From 0bad0e6b94c566f63bb97661850899f679fd1d12 Mon Sep 17 00:00:00 2001
From: pans <pans@454eff88-639b-444f-9e54-f578c98de674>
Date: 星期三, 04 一月 2017 16:06:48 +0800
Subject: [PATCH] 

---
 ProxyConsole/proxyconsole-hc.cpp |   40 ++++++++++++++++++++++++++++++++++------
 1 files changed, 34 insertions(+), 6 deletions(-)

diff --git a/ProxyConsole/proxyconsole-hc.cpp b/ProxyConsole/proxyconsole-hc.cpp
index a0bfacd..992de13 100644
--- a/ProxyConsole/proxyconsole-hc.cpp
+++ b/ProxyConsole/proxyconsole-hc.cpp
@@ -41,6 +41,8 @@
 #define MAX 1024
 #define fileread_buf 128
 
+volatile time_t last_alarmout;
+
 typedef std::map<std::string, int> hcnetsdk_user_t; // decoder_ip, userid
 hcnetsdk_user_t g_hcnetsdk_user;
 
@@ -55,6 +57,16 @@
 	ET_HCNET_DECODER__LAST,
 	ET__LAST
 };
+
+struct HCNetSDKConfig
+{
+	std::string serverIP;
+	int serverport;
+	std::string username;
+	std::string passwd;
+};
+
+HCNetSDKConfig g_hcnetsdkconfig;
 
 struct HCNetCameraConfig
 {
@@ -311,11 +323,15 @@
 	if(NET_DVR_SetAlarmOut(lUserID,camConfig.lAlarmOutPort,1) == FALSE){
 		printf("NET_DVR_SetAlarmOut failed, err: %d\n", NET_DVR_GetLastError());
 	}
+	last_alarmout = time(NULL);
 	
 	sleep(3);
 	
-	//瑙i櫎璀︽姤
-	NET_DVR_SetAlarmOut(lUserID,camConfig.lAlarmOutPort,0);
+	if (time(NULL) - last_alarmout >= 3)
+	{
+		//瑙i櫎璀︽姤
+		NET_DVR_SetAlarmOut(lUserID,camConfig.lAlarmOutPort,0);
+	}
 }
 
 int hcnetsdk_alarm_popwin(LONG lUserID, const HCNetCameraConfig& camConfig)
@@ -426,14 +442,15 @@
 	LONG lUserID;
 
 	NET_DVR_DEVICEINFO_V30 struDeviceInfo;
-	lUserID = NET_DVR_Login_V30("192.168.1.101", 8000, "admin", "a1234567", &struDeviceInfo);
+	lUserID = NET_DVR_Login_V30((char*)g_hcnetsdkconfig.serverIP.c_str(), g_hcnetsdkconfig.serverport, 
+		(char*)g_hcnetsdkconfig.username.c_str(), (char*)g_hcnetsdkconfig.passwd.c_str(), &struDeviceInfo);
 	if (lUserID < 0) {
 		printf("NET_DVR_Login_V30 failed, err: %d\n", NET_DVR_GetLastError());
 		NET_DVR_Cleanup();
 		return -1;
 	}
 	
-	g_hcnetsdk_user.insert(std::make_pair("192.168.1.101", int(lUserID)));
+	g_hcnetsdk_user.insert(std::make_pair(g_hcnetsdkconfig.serverIP, int(lUserID)));
 	
 	return lUserID;
 }
@@ -496,12 +513,16 @@
 	   timer.it_interval.tv_usec=250000;
 	   /*Start a virtual timer.It counts down whenever this process is executing.*/
 
-	   setitimer(ITIMER_VIRTUAL,&timer,NULL);
+	   //setitimer(ITIMER_VIRTUAL,&timer,NULL);
 	   
 	   
 	   
 	   
-	   while(1);
+		while ( 1 )
+		{
+			zclock_sleep(250);
+			timer_handler(0);
+		} 
 }
 
 void* createServerthread_hcnetsdk(void* arg)
@@ -775,6 +796,13 @@
 		std::cout << "open config.json error" << std::endl;
 		exit(EXIT_FAILURE);
 	}
+	
+	//HCNetSDKConfig
+	Json::Value jsonHcsdk = root["hcsdk"];
+	g_hcnetsdkconfig.serverIP = jsonHcsdk["serverIP"].asString();
+	g_hcnetsdkconfig.serverport = jsonHcsdk["serverport"].asInt();
+	g_hcnetsdkconfig.username = jsonHcsdk["username"].asString();
+	g_hcnetsdkconfig.passwd = jsonHcsdk["passwd"].asString();
 
 	Json::Value jsonEquipments = root["equipments"];
 	for (int i = 0; i < jsonEquipments.size() && i < sizeof(equipments) / sizeof(sockinfo); i++)

--
Gitblit v1.8.0