From aa636724fd38f795e775d211a3cfa44de86799d3 Mon Sep 17 00:00:00 2001
From: xuxiuxi <xuxiuxi@454eff88-639b-444f-9e54-f578c98de674>
Date: 星期一, 27 三月 2017 18:36:58 +0800
Subject: [PATCH]
---
ProxyConsole/proxyconsole-hc.cpp | 251 ++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 214 insertions(+), 37 deletions(-)
diff --git a/ProxyConsole/proxyconsole-hc.cpp b/ProxyConsole/proxyconsole-hc.cpp
index 992de13..57907dd 100644
--- a/ProxyConsole/proxyconsole-hc.cpp
+++ b/ProxyConsole/proxyconsole-hc.cpp
@@ -29,11 +29,11 @@
#include <unistd.h>
-#include <jsoncpp/json/json.h>
+#include <json/json.h>
#include "MD5Linux.h"
-#include "HCNetSDK/incCn/HCNetSDK.h"
+#include "HCNetSDK64/incCn/HCNetSDK.h"
#define HPR_OK 0
#define HPR_ERROR -1
@@ -51,9 +51,9 @@
ET__FIRST,
ET_PC_SERVER,
ET_HCNET_DECODER__FIRST,
- ET_HCNET_DECODER_POPWIN,
- ET_HCNET_DECODER_LOGO,
- ET_HCNET_DECODER_ALARMOUT,
+ ET_HCNET_DECODER_POPWIN, // 3
+ ET_HCNET_DECODER_LOGO, // 4
+ ET_HCNET_DECODER_ALARMOUT, // 5
ET_HCNET_DECODER__LAST,
ET__LAST
};
@@ -231,7 +231,7 @@
}
SupperConnectedflag[i]=1;
SupperConnectedIP[i] = equipments[i].serverIP;
- printf("server connect Success=:%s:%s\n",equipments[i].serverIP,equipments[i].serverport);
+ //printf("server connect Success=:%s:%s\n",equipments[i].serverIP,equipments[i].serverport);
pthread_create(&thread_no[i],NULL,&createServerthread,(void*)i);//super
}
}
@@ -422,14 +422,51 @@
std::cout << "hcnetsdk_alarm_popwin" << std::endl;
}
-int hcnetsdk_alarm_logo()
-{
-}
-
void hcnetsdk_finial()
{
//NET_DVR_Logout(lUserID); //#todo
NET_DVR_Cleanup();
+}
+
+int hcnetsdk_init_logo(LONG lUserID)
+{
+ //logo淇℃伅
+ NET_DVR_MATRIX_LOGO_INFO net_dvr_matrix_logocfg1;
+ net_dvr_matrix_logocfg1.byRes[32]=0;
+ net_dvr_matrix_logocfg1.dwSize=0;
+ net_dvr_matrix_logocfg1.dwLogoSize=0;
+
+ char logobuf[5000];
+ {
+ FILE * pFile;
+ pFile = fopen("./ico.bmp","rb");
+ if (pFile!=NULL)
+ {
+ net_dvr_matrix_logocfg1.dwLogoSize = fread(logobuf, 1, sizeof(logobuf), pFile);
+ fclose (pFile);
+ }
+ else
+ {
+ perror ("Error opening file");
+ return -1;
+ }
+ }
+
+ net_dvr_matrix_logocfg1.dwSize= sizeof(net_dvr_matrix_logocfg1);
+
+ //涓婁紶logo
+ if (TRUE != NET_DVR_UploadLogo_NEW(lUserID, 1, &net_dvr_matrix_logocfg1 , logobuf))
+ {
+ printf("NET_DVR_UploadLogo_NEW error, err: %d\n", NET_DVR_GetLastError());
+ return -1;
+ }
+ else
+ {
+ printf("NET_DVR_UploadLogo_NEW done.\n");
+ return 0;
+ }
+
+ return -1;
}
int hcnetsdk_init()
@@ -452,6 +489,8 @@
g_hcnetsdk_user.insert(std::make_pair(g_hcnetsdkconfig.serverIP, int(lUserID)));
+ hcnetsdk_init_logo(lUserID);
+
return lUserID;
}
@@ -469,6 +508,84 @@
}
return NULL;
+}
+
+sockinfo* hcnetsdk_find_equip(const std::string& decoder_ip)
+{
+ for (size_t i = 0; i < NUM; i++)
+ {
+ sockinfo* equip = &(equipments[i]);
+ if (equip->m_type > ET_HCNET_DECODER__FIRST || equip->m_type < ET_HCNET_DECODER__LAST)
+ {
+ if (equip->serverIP == decoder_ip)
+ return equip;
+ }
+ }
+
+ return NULL;
+}
+
+sockinfo* hcnetsdk_find_equip(const std::string& decoder_ip, int channel)
+{
+ for (size_t i = 0; i < NUM; i++)
+ {
+ sockinfo* equip = &(equipments[i]);
+ if (equip->m_type > ET_HCNET_DECODER__FIRST || equip->m_type < ET_HCNET_DECODER__LAST)
+ {
+ HCNetCameraConfig* camConfig = (HCNetCameraConfig*)equip->user_config;
+ if (camConfig != NULL && camConfig->channel == channel && equip->serverIP == decoder_ip)
+ return equip;
+ }
+ }
+
+ return NULL;
+}
+
+int hcnetsdk_alarm_logo(LONG lUserID, const HCNetCameraConfig& _camConfig, const std::string& ip, int channel, bool disalarm)
+{
+ HCNetCameraConfig camConfig(_camConfig);
+ if (camConfig.channel != channel)
+ {
+ camConfig.channel = -1;
+ sockinfo* equipConfig = hcnetsdk_find_equip(ip, channel);
+ if (equipConfig != NULL)
+ camConfig = *(HCNetCameraConfig*)(equipConfig->user_config);
+ }
+
+ printf("hcnetsdk_alarm_logo, channel=%d, matchc=%d\n", channel, camConfig.channel);
+
+ if (camConfig.channel < 0)
+ return -1;
+
+ //绐楀彛閰嶇疆淇℃伅
+ NET_DVR_WIN_LOGO_CFG net_dvr_win_logo_cfg;
+ net_dvr_win_logo_cfg.dwLogoNo = 1;
+ net_dvr_win_logo_cfg.byEnable = (disalarm ? 0 : 1);//0:hidden,1:visible
+ net_dvr_win_logo_cfg.byRes1[3] =0;
+ net_dvr_win_logo_cfg.dwCoordinateX = 5;
+ net_dvr_win_logo_cfg.dwCoordinateY =5;
+ net_dvr_win_logo_cfg.byFlash = 1;
+ net_dvr_win_logo_cfg.byTranslucent = 0;
+ net_dvr_win_logo_cfg.byRes2[34] = 0;
+
+ net_dvr_win_logo_cfg.dwSize = sizeof(net_dvr_win_logo_cfg);
+ //璁剧疆绐楀彛杈撳嚭logo
+ int byWallNo=1,dwSubWinNo=2,dwWinNo=1;
+ DWORD dwDecChanNum=(camConfig.byWallNo << 24) | (camConfig.dwSubWinNo << 16) | camConfig.dwWinNo;
+ if(!NET_DVR_SetDVRConfig(lUserID,NET_DVR_SET_WIN_LOGO_CFG,dwDecChanNum,&net_dvr_win_logo_cfg,net_dvr_win_logo_cfg.dwSize))
+ {
+ printf("NET_DVR_SetDVRConfig2 error, err: %d\n", NET_DVR_GetLastError());
+ return -1;
+ }
+ else
+ {
+ printf("NET_DVR_SetDVRConfig2 done.\n");
+ //return 0;
+ }
+
+ //sleep(3);
+ //net_dvr_win_logo_cfg.byEnable = 0;
+ //NET_DVR_SetDVRConfig(lUserID,NET_DVR_SET_WIN_LOGO_CFG,dwDecChanNum,&net_dvr_win_logo_cfg,net_dvr_win_logo_cfg.dwSize);
}
int main(int argc,char **argv)
@@ -498,7 +615,7 @@
if (hcnetsdk_user < 0)
{
printf("hcnetsdk_user < 0");
- exit(EXIT_FAILURE);
+ exit(EXIT_FAILURE);//#todo if debug equipment(analizer), remove this
}
/*Install timer_handler as th siganl handler for SIGVTALRM */
@@ -555,16 +672,16 @@
}
data[idx++]=0x16;
write(sock_upper[sidx],&data,idx);//send to equipment;
- printf("Send equipment's info to Server OK! len=:%d\n",idx);
+ //printf("Send equipment's info to Server OK! len=:%d\n",idx);
//=======================================data================================================
while(1)
{
int j;
length=read(sock_upper[sidx],&buff,sizeof(buff)-1);
- printf("from Server received data===============:%d\n",length);
+ //printf("from Server received data===============:%d\n",length);
if(length<=0)
{
- printf(" Upper Socket closed \n");
+ //printf(" Upper Socket closed \n");
break;
}
else {
@@ -576,7 +693,7 @@
// length-=3;
// if(length<=0) continue;
//}
-
+
if(buff[0]==0x68 && buff[1]==0x03 )
{
@@ -636,7 +753,7 @@
continue;
}
}
- puts("Server Thread is stoped..");
+ //puts("Server Thread is stoped..");
close(sock_upper[sidx]);
sock_upper[sidx] = -1;
SupperConnectedflag[sidx]=0;//?//#todo
@@ -707,11 +824,23 @@
}
else if(length>0)
{
+ std::cout << "buff: " << buff<<std::endl;
+
+ bool isDisalarm = false;
if (strstr(buff, "ViqEventNotificationAlert") == NULL) // <urn
continue;
if (strstr(buff, "startTime") == NULL) // <urn
- continue;
- //std::cout << buff<<std::endl;
+ isDisalarm = true;
+
+ int channel = -1;
+ {
+ const char* strChannel = strstr(buff, "<urn:channelId>");
+ if (strChannel != NULL)
+ {
+ channel = strtol(strChannel + strlen("<urn:channelId>"), NULL, 10);
+ }
+ }
+
if(gCapturing[eidx]==1)
{
int k;
@@ -753,17 +882,21 @@
if(SupperConnectedIP.size() > k)
{
const std::string& ip(SupperConnectedIP[k]);
+ sockinfo* equipConfig = hcnetsdk_find_equip(ip);
HCNetCameraConfig* camConfig = hcnetsdk_find_config(ip);
int lUserData = hcnetsdk_get_userid(ip);
- if (camConfig != NULL && lUserData >= 0)
+ if (camConfig != NULL && equipConfig != NULL && lUserData >= 0)
{
- std::cout << "alarm begin k=" << k << std::endl;
- hcnetsdk_alarm_alarmout(lUserData, *camConfig);
- std::cout << "alarm end k=" << k << std::endl;
+ std::cout << "......alarm begin k=" << k << std::endl;
+ if (equipConfig->m_type == ET_HCNET_DECODER_ALARMOUT && !isDisalarm)
+ hcnetsdk_alarm_alarmout(lUserData, *camConfig);
+ else if (equipConfig->m_type == ET_HCNET_DECODER_LOGO)
+ hcnetsdk_alarm_logo(lUserData, *camConfig, ip, channel, isDisalarm);
+ std::cout << "......alarm end k=" << k << std::endl;
}
else
{
- //std::cout << "alarm lost k=" << k << std::endl;
+ std::cout << "alarm lost k=" << k << std::endl;
}
}
}
@@ -1060,16 +1193,16 @@
int i;
int retVal;
int result;
- printf("Step.3 ========>GPIO manupulation===> AnalyEquipmentNum=%d \n",equip_num);
+ //printf("Step.3 ========>GPIO manupulation===> AnalyEquipmentNum=%d \n",equip_num);
for(i=0;i<equip_num;i++)
{
retVal = -1;
result=-1;
- printf("=============================:%d \n",equipments[i].reboot);
+ //printf("=============================:%d \n",equipments[i].reboot);
result=net_test(equipments[i].ip,equipments[i].port);
if(result<0)
{
- printf("Equipment(%d) check=%s:%s\n",i+1,equipments[i].ip,equipments[i].port);
+ //printf("Equipment(%d) check=%s:%s\n",i+1,equipments[i].ip,equipments[i].port);
retVal = GPIO_OPEN(PortNum);
if(retVal == 0)
{
@@ -1079,7 +1212,10 @@
}
else printf("GPIO OPEN FAIL! \n");
}
- else printf("Equipment(%d) Check Success!=%s:%s\n",i+1,equipments[i].ip,equipments[i].port);
+ else
+ {
+ //printf("Equipment(%d) Check Success!=%s:%s\n",i+1,equipments[i].ip,equipments[i].port);
+ }
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -1221,7 +1357,7 @@
return n;
}
//for real event
-void MakeAuthorizedPacketReal(char* buff,int length, char* Method,char* uri,int Idx)
+void MakeAuthorizedPacketReal_Digest(char* buff,int length, char* Method,char* uri,int Idx)
{
char Device[150] ;
char Realm_buf1[512] ;
@@ -1234,7 +1370,7 @@
memset(domain_buf4,0,512);
CharToByte((char*)buff, Device, length,Realm_buf1,nonce_buf2,auth_buf3,domain_buf4, len);
- const char* cnonce_buf="163acd0e58793a190f29ee879d4b224f";//"08a9d86c1b5e45963cf82f43dca59c51";
+ const char* cnonce_buf="1oBAAAqkwXP9q9MorVCzgw5LNPc";//"08a9d86c1b5e45963cf82f43dca59c51";
Realm_buf1[len[0]]=0;
nonce_buf2[len[1]]=0;
auth_buf3[len[2]]=0;
@@ -1283,7 +1419,32 @@
byte_array[iidx]=0;
}
+
+void MakeAuthorizedPacketReal_Basic(char* buff,int length, char* Method,char* uri,int Idx)
+{
+ /*
+POST /PSIA/VIQ/System/sessions HTTP/1.1
+Content-Length: 0
+Host: 192.168.1.5:80
+Connection: Keep-Alive
+Authorization: Basic c3VwZXJ2aXNvcjpzdXBlcnZpc29y
+ */
+ int i = 0;
+ sprintf(byte_array,
+ "%s %s HTTP/1.1\r\n"
+ "Content-Length: 0\r\n"
+ "Host: %s:80\r\n"
+ "Connection: Keep-Alive\r\n"
+ "Authorization: Basic %s\r\n"
+ "\r\n",
+ Method,
+ uri,
+ equipments[Idx].ip,
+ "c3VwZXJ2aXNvcjpzdXBlcnZpc29y" // base64(supervisor:supervisor)
+ );
+}
+
//// 鍔熻兘锛氬紑濮嬫煡鐪嬪疄鏃剁洃鎺�
//// 杈撳叆锛氬垎鏋愬櫒IP,鐢ㄦ埛,瀵嗙爜
//// 杈撳嚭锛�0锛堟垚鍔燂級, -1(鍒濆鍖栧け璐�),-2(杩炴帴澶辫触)
@@ -1325,9 +1486,10 @@
sigset(SIGALRM, u_alarm_handler);//add 2016.11.22
alarm(2);
length=read(rsock_down[Idx],&buff,sizeof(buff));
+ //printf("RESPONSE: %s\n",&buff);
alarm(0);
sigrelse(SIGALRM);
- printf("Myequipment connect ==================length =%d:\n",length);
+ //printf("Myequipment connect ==================length =%d:\n",length);
if(length<=0)
{
close(rsock_down[Idx]);
@@ -1336,14 +1498,23 @@
if(memorycmp((unsigned char*)buff,length, "WWW-Authenticate:",17)>0 && bbbb==0)
{
// analyse reception
- MakeAuthorizedPacketReal(buff,length,"POST","/PSIA/VIQ/System/sessions/permanent",Idx);
- zclock_sleep(100);
- write(rsock_down[Idx],byte_array,strlen(byte_array));
-// printf("%s\n",(char*)byte_array);
+ MakeAuthorizedPacketReal_Basic(buff,length,"POST","/PSIA/VIQ/System/sessions/permanent",Idx);
+ //for(int ii=0;ii<4;ii++)
+ //{
+ zclock_sleep(100);
+ write(rsock_down[Idx],byte_array,strlen(byte_array));
+ //}
+ printf("%s\n",(char*)byte_array);
bbbb=1;
- continue;
+ continue;//#todo 20170325
+ //break;
}
if(bbbb==1){
+ //if (strstr((char*)buff,"Unauthorized") != NULL)
+ //{
+ // bbbb=0;
+ //}
+
int sidx = stringcmp((char*)buff,"<urn:id>",8);
if(sidx >=0){//<urn:ViqDateTimeInterval urn:version="1.0" xmlns:urn="urn:videoiq-com"><urn:startTime urn:version="1.0"><urn:date>2016-08-18T01:07:20.749</urn:date><urn:offset>0</urn:offset></urn:startTime><urn:endTime urn:version="1.0"><urn:date>2016-08-29T08:33:48.231</urn:date><urn:offset>0</urn:offset></urn:endTime></urn:ViqDateTimeInterval>
int eidx = stringcmp((char*)buff,"</urn:id>",9);
@@ -1378,6 +1549,8 @@
}
char uri[200];
sprintf(uri,"/PSIA/Custom/Event/notification/notificationStream?sessionId=%s",sessions[Idx]);
+ //sprintf(uri,"/PSIA/Custom/Event/notification/notificationStream?sessionId=5");
+ printf("/PSIA/Custom/Event/notification/notificationStream?sessionId=%s\n",sessions[Idx]);
length = sprintf(byte_array,"GET %s HTTP/1.1\r\nContent-Type: text/xml\r\nHost: %s\r\nContent-Length: 0\r\nConnection: Keep-Alive\r\n\r\n",uri,equipments[Idx].ip);
write(rsock_down[Idx],byte_array,strlen(byte_array));
while(1){
@@ -1396,9 +1569,13 @@
{
char uri[200];
sprintf(uri,"/PSIA/Custom/Event/notification/notificationStream?sessionId=%s",sessions[Idx]);
- MakeAuthorizedPacketReal(buff,length,"GET",uri,Idx);
+ MakeAuthorizedPacketReal_Basic(buff,length,"GET",uri,Idx);
+ //for(int ii=0;ii<4;ii++)
+ //{
+ zclock_sleep(100);
write(rsock_down[Idx],byte_array,strlen(byte_array));
-// printf("%s\n",(char*)byte_array);
+ //}
+ printf("%s\n",(char*)byte_array);
bbbb=3;
continue;
}
--
Gitblit v1.8.0