#include "widget.h"
#include <iostream>
#include <stdio.h>
#pragma execution_character_set("utf-8")
using namespace std;
LLONG LoginHandle;//登录句柄
LLONG lHandle;//监视句柄
LLONG attachpassHnd;//订阅客流句柄
#include<QDebug>
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
qDebug() << "init";
//设置窗口大小
setMinimumSize(WIDTH, HIGH);
//文本名称
ltitle = new QLabel("IP地址 ");
ltitle2 = new QLabel("端口号 ");
ltitle3 = new QLabel("用户名 ");
ltitle4 = new QLabel(" 密码 ");
//网络地址 连接
laddr = new QLineEdit(IP);
lport = new QLineEdit(PORT);
luser = new QLineEdit(USER);
lpasswd = new QLineEdit(PASSWD);
//按钮
pconnect = new QPushButton("连接");
pnext = new QPushButton("显示");
popenPassengerFlow = new QPushButton("开启客流数据采集");
pclosePassengerFlow= new QPushButton("关闭客流数据采集");
//显示
lplay = new QLabel;
//控件组合
QHBoxLayout *hbox1 = new QHBoxLayout;
hbox1->addStretch();
hbox1->addWidget(ltitle);
hbox1->addWidget(laddr);
hbox1->addStretch();
hbox1->addWidget(ltitle2);
hbox1->addWidget(lport);
hbox1->addStretch();
QHBoxLayout *hbox2 = new QHBoxLayout;
hbox2->addStretch();
hbox2->addWidget(ltitle3);
hbox2->addWidget(luser);
hbox2->addStretch();
hbox2->addWidget(ltitle4);
hbox2->addWidget(lpasswd);
hbox2->addStretch();
QHBoxLayout *hbox3 = new QHBoxLayout;
hbox3->addWidget(pconnect);
hbox3->addWidget(pnext);
QHBoxLayout *hbox4 = new QHBoxLayout;
hbox4->addWidget(popenPassengerFlow);
hbox4->addWidget(pclosePassengerFlow);
QVBoxLayout *vbox1 = new QVBoxLayout;
vbox1->addLayout(hbox1);
vbox1->addLayout(hbox2);
vbox1->addLayout(hbox3);
vbox1->addLayout(hbox4);
vbox1->addWidget(lplay);
setLayout(vbox1);
//槽函数
connect(pnext, SIGNAL(clicked(bool)), this, SLOT(h_next()));
connect(pconnect, SIGNAL(clicked(bool)), this, SLOT(h_connect()));
connect(popenPassengerFlow, SIGNAL(clicked(bool)), this, SLOT(h_openPassengerFlow()));
connect(pclosePassengerFlow, SIGNAL(clicked(bool)), this, SLOT(h_closePassengerFlow()));
}
Widget::~Widget()
{
cout<<"CLOSED!"<<endl;
//停止实时监视
CLIENT_StopRealPlayEx(lHandle);
//登出设备
CLIENT_Logout(LoginHandle);
//清理SDK资源
CLIENT_Cleanup();
}
void Widget::h_connect()
{
//获取界面登录信息
strcpy(D_Ip,laddr->text().toLatin1().data());
strcpy(D_UserName,luser->text().toLatin1().data());
strcpy(D_Pasdwd,lpasswd->text().toLatin1().data());
D_Port = lport->text().toInt();
//SDK初始化
if(CLIENT_Init((fDisConnect)DisConnectFunc, (LDWORD)0))
{
cout<<"SDK INIT OK!"<<endl;
}
else
{
cout<<"SDK INIT FAIL!"<<endl;
}
//获取SDK版本信息
DWORD dwNetSdkVersion = CLIENT_GetSDKVersion();
printf("NetSDK version is [%d]\n",dwNetSdkVersion);
//设置断线重连回调接口,设置过断线重连成功回调函数后,当设备出现断线情况,SDK内部会自动进行重连操作
CLIENT_SetAutoReconnect(&HaveReConnect,0);
//设置登录超时时间和尝试次数
int nWaitTime = 5000; //登录请求响应超时时间设置为5s
int nTryTimes = 3; //登录时尝试建立连接3次
CLIENT_SetConnectTime(nWaitTime,nTryTimes);
//设置更多网络参数,NET_PARAM的nWaittime,nConnectTryNum成员与CLIENT_SetConnectTime 接口设置的登录设备超时时间和尝试次数的意义相同
NET_PARAM stuNetparm ={0};
stuNetparm.nConnectTime = 3000;//登录时尝试建立连接的超时时间
CLIENT_SetNetworkParam(&stuNetparm);
// 登录
NET_IN_LOGIN_WITH_HIGHLEVEL_SECURITY stInparam;
memset(&stInparam, 0, sizeof(stInparam));
stInparam.dwSize = sizeof(stInparam);
strncpy(stInparam.szIP, D_Ip, sizeof(stInparam.szIP) - 1);
strncpy(stInparam.szPassword, D_Pasdwd, sizeof(stInparam.szPassword) - 1);
strncpy(stInparam.szUserName, D_UserName, sizeof(stInparam.szUserName) - 1);
stInparam.nPort = D_Port;
stInparam.emSpecCap = EM_LOGIN_SPEC_CAP_TCP;
tagNET_OUT_LOGIN_WITH_HIGHLEVEL_SECURITY stOutparam;
LoginHandle = CLIENT_LoginWithHighLevelSecurity(&stInparam, &stOutparam);
if (LoginHandle)
{
QMessageBox::about(NULL,laddr->text(),"连接成功");
}
else
{
printf("login fail\n");
}
}
void Widget::h_next()
{
if(FALSE == LoginHandle)
{
QMessageBox::about(NULL,laddr->text(),"连接失败");
return;
}
//获取Label句柄
HWND hWnd = (HWND)lplay->winId();
//监视
lHandle = CLIENT_RealPlayEx(LoginHandle,0, hWnd);//实时监视句柄
if (lHandle)
{
cout << "CLIENT_RealPlayEx success!" << endl;
//设置实时监视回调函数
DWORD dwFlag = REALDATA_FLAG_RAW_DATA;//原始数据标志
CLIENT_SetRealDataCallBackEx2(lHandle, &fRealDataCB, NULL,dwFlag);
}
else
{
printf("CLIENT_RealPlayEx: failed! Error code: %x.\n",CLIENT_GetLastError());
}
}
void Widget::h_openPassengerFlow()
{
if(FALSE == LoginHandle)
{
QMessageBox::about(NULL,laddr->text(),"未连接登录");
return;
}
NET_IN_ATTACH_VIDEOSTAT_SUM
InParam={sizeof(NET_IN_ATTACH_VIDEOSTAT_SUM)};
InParam.nChannel=0;
InParam.cbVideoStatSum=&VideoStatSumCallback;
NET_OUT_ATTACH_VIDEOSTAT_SUM OutParam={0};
OutParam.dwSize=sizeof(OutParam);
int nWaitTime=5000; //wait time
// 订阅客流量统计
attachpassHnd = CLIENT_AttachVideoStatSummary(LoginHandle,&InParam,&OutParam,nWaitTime);
if(attachpassHnd)
{
cout << "CLIENT_AttachVideoStatSummary sucess!" << endl;
}
else
{
cout << "error number:" <<CLIENT_GetLastError() << endl;
}
}
void Widget::h_closePassengerFlow()
{
if(FALSE == LoginHandle)
{
QMessageBox::about(NULL,laddr->text(),"未连接登录");
return;
}
if(FALSE == attachpassHnd)
{
QMessageBox::about(NULL,laddr->text(),"未订阅客流统计");
return;
}
CLIENT_DetachVideoStatSummary(attachpassHnd);
}
//客流数据回调
void CALLBACK Widget::VideoStatSumCallback(LLONG lAttachHandle, NET_VIDEOSTAT_SUMMARY* pBuf,
DWORD dwBufLen, LDWORD dwUser)
{
// 处理回调数据
cout << "\nchannel:" <<pBuf->nChannelID << "\nname:"<< pBuf->szRuleName<< "\nenter:"<< pBuf->stuEnteredSubtotal.nTotal<< "\nleave:"<< pBuf->stuExitedSubtotal.nTotal<< endl;
}
//断线回调
void CALLBACK Widget::DisConnectFunc(LLONG lLoginID, char *pchDVRIP, LONG nDVRPort, DWORD dwUser)
{
printf("Call DisConnectFunc\n");
printf("lLoginID[0x%x]",lLoginID);
if(NULL != pchDVRIP)
{
printf("pchDVRIP[%s]\n",pchDVRIP);
}
printf("nDVRPort[%d]\n",nDVRPort);
printf("dwUser[%p]\n",dwUser);
printf("\n");
}
//数据回调
void CALLBACK Widget::fRealDataCB(LLONG lRealHandle, DWORD dwDataType, BYTE *pBuffer, DWORD dwBufSize, LLONG param,LDWORD dwUser)
{
//printf("receive real data,param:lRealHandle[%p],dwDataType[%d],pBuffer[%p],dwBufSize[%d]\n",lRealHandle,dwDataType,pBuffer,dwBufSize);
if(CLIENT_SaveRealData(lHandle,"DHvideo"))
{
//printf("Save data success\n");
}
}
//重连回调
void CALLBACK Widget::HaveReConnect(LLONG lLoginID,char *pchDVRIP,LONG nDVRPort,LDWORD dwUser)
{
printf("Call HaveReConnect\n");
printf("lLoginID[0x%x]",lLoginID);
if(NULL != pchDVRIP)
{
printf("pchDVRIP[%s]\n",pchDVRIP);
}
printf("nDVRPort[%d]\n",nDVRPort);
printf("dwUser[%p]\n",dwUser);
printf("\n
评论1
最新资源