代码拉取完成,页面将自动刷新
#include "netcameractl.h"
NetCameraCtl::NetCameraCtl(QObject *parent) : QObject(parent)
{
m_OnvifPTZ = nullptr;
m_Ip.clear();
m_Port.clear();
m_UserName.clear();
m_PassWord.clear();
m_ConnectedSta = false;
m_DataDictionary = DataDictionary::GetInstance();
m_ReconnectTimer = new QTimer;
m_ReconnectTimer->setInterval(RECONNECT_TIMEOUT);
m_CtlHMinAngle = (H_MAX_ANGLE-H_MIN_ANGLE)/((H_MAX_VALUE-H_MIN_VALUE)/CTL_MIN_STEP);
m_CtlVMinAngle = (V_MAX_ANGLE-V_MIN_ANGLE)/((V_MAX_VALUE-V_MIN_VALUE)/CTL_MIN_STEP);
qDebug() << "m_CtlHMinAngle : " << m_CtlHMinAngle;
qDebug() << "m_CtlVMinAngle : " << m_CtlVMinAngle;
int tmpZoom = m_DataDictionary->GetMisData(MIS_CAMERA_MAX_ZOOM).toInt();
m_ZoomMaxLimit = ZOOM_MAX_VALUE*((double)tmpZoom/(double)100);
qDebug() << "m_ZoomMaxLimit : " << m_ZoomMaxLimit << ":ZOOM_MAX_VALUE" << ZOOM_MAX_VALUE;
qDebug() << "MIS_CAMERA_MAX_ZOOM" << m_DataDictionary->GetMisData(MIS_CAMERA_MAX_ZOOM).toDouble();
if(m_ZoomMaxLimit < ZOOM_MIN_VALUE){
m_ZoomMaxLimit = ZOOM_MIN_VALUE;
}else if(m_ZoomMaxLimit > ZOOM_MAX_VALUE){
m_ZoomMaxLimit = ZOOM_MAX_VALUE;
}
qDebug() << "m_ZoomMaxLimit : " << m_ZoomMaxLimit;
m_MaxDistance = m_DataDictionary->GetMisData(MIS_CAMERA_MAX_DISTANCE).toDouble();
m_ReqHValue = m_DataDictionary->GetCameraCtlData(CAM_REQ_H_VALUE).toDouble();
if(m_ReqHValue > H_MAX_VALUE){
m_ReqHValue = H_MAX_VALUE;
}else if(m_ReqHValue < H_MIN_VALUE){
m_ReqHValue = H_MIN_VALUE;
}
m_ReqVValue = m_DataDictionary->GetCameraCtlData(CAM_REQ_V_VALUE).toDouble();
if(m_ReqVValue > V_MAX_VALUE){
m_ReqVValue = V_MAX_VALUE;
}else if(m_ReqVValue < V_MIN_VALUE){
m_ReqVValue = V_MIN_VALUE;
}
m_ReqZoomValue = m_DataDictionary->GetCameraCtlData(CAM_REQ_ZOOM_VALUE).toDouble();
if(m_ReqZoomValue > m_ZoomMaxLimit){
m_ReqZoomValue = m_ZoomMaxLimit;
}else if(m_ReqZoomValue < ZOOM_MIN_VALUE){
m_ReqZoomValue = ZOOM_MIN_VALUE;
}
m_PtzControl = true;
if(m_DataDictionary->GetMisData(MIS_CAMERA_GUN_STA).toInt() == CAMERA_GUN_CHECK)
{
m_PtzControl = false;
}
Init(m_DataDictionary->GetSystemData(SYS_CAMERA_IP1),
m_DataDictionary->GetSystemData(SYS_PTZ_PORT),
m_DataDictionary->GetSystemData(SYS_CAMERA_USERNAME1),
m_DataDictionary->GetSystemData(SYS_CAMERA_PASSWORD1));
connect(m_DataDictionary,SIGNAL(SystemDataChange(SystemDataIndex_t)),
this,SLOT(SystemDataChangeProcess(SystemDataIndex_t)));
connect(m_DataDictionary,SIGNAL(MisDataChange(MisDataIndex_t)),this,SLOT(MisDataChangeProcess(MisDataIndex_t)));
connect(m_ReconnectTimer,SIGNAL(timeout()),this,SLOT(Reconnect()));
connect(m_DataDictionary,SIGNAL(CameraCtlDataChange(CameraCtlIndex_t)),this,SLOT(CameraCtlDataChangeProcess(CameraCtlIndex_t)));
}
NetCameraCtl::~NetCameraCtl()
{
if(m_OnvifPTZ)
{
delete m_OnvifPTZ;
m_OnvifPTZ = nullptr;
}
if(m_ReconnectTimer)
{
m_ReconnectTimer->stop();
delete m_ReconnectTimer;
m_ReconnectTimer = nullptr;
}
}
void NetCameraCtl::Reconnect()
{
m_ConnectedSta = false;
QString PtzAddr = m_DataDictionary->GetSystemData(SYS_PTZ_ADDR);
if(PtzAddr.isEmpty())
{
PtzAddr = m_DataDictionary->GetSystemData(SYS_CAMERA_IP1);
}
m_OnvifPTZ->SetInfo(PtzAddr,
m_DataDictionary->GetSystemData(SYS_PTZ_PORT),
m_DataDictionary->GetSystemData(SYS_CAMERA_USERNAME1),
m_DataDictionary->GetSystemData(SYS_CAMERA_PASSWORD1));
//Init(m_Ip,m_Port,m_UserName,m_PassWord);
if(!m_OnvifPTZ->GetCapabilities())
{
qDebug() << "m_OnvifPTZ GetCapabilities failed";
m_ReconnectTimer->start();
return ;
}
}
void NetCameraCtl::Init(QString Ip, QString Port, QString UserName, QString PassWord)
{
// if(m_DataDictionary->GetMisData(MIS_CAMERA_STA).toUInt() == CAMERA_OFFLINE)
// return ;
if(m_ConnectedSta)
return ;
m_Ip = Ip;
m_Port = Port;
m_UserName = UserName;
m_PassWord = PassWord;
//m_ReconnectTimer->start();
if(!m_PtzControl)
{
m_ReqHValue = 0;
m_ReqVValue = 0;
}
if(m_OnvifPTZ == nullptr)
m_OnvifPTZ = new OnvifPTZ(Ip,Port,UserName,PassWord);
connect(m_OnvifPTZ,SIGNAL(GetCapabilitiesRes(bool)),\
this,SLOT(GetCapabilitiesRes(bool)));
connect(m_OnvifPTZ,SIGNAL(GetServicesRes(bool)),\
this,SLOT(GetServicesRes(bool)));
connect(m_OnvifPTZ,SIGNAL(GetProfilesRes(bool)),\
this,SLOT(GetProfilesRes(bool)));
connect(m_OnvifPTZ,SIGNAL(MoveToRes(bool)),\
this,SLOT(MoveToRes(bool)));
if(!m_OnvifPTZ->GetCapabilities())
{
qDebug() << "m_OnvifPTZ GetCapabilities failed";
m_ReconnectTimer->start();
return ;
}
// if(!m_OnvifPTZ->MoveTo(m_ReqHValue,m_ReqVValue,m_ReqZoomValue)){
// qDebug() << "m_OnvifPTZ MoveTo failed";
// }
// else {
// }
}
void NetCameraCtl::Release()
{
m_ReconnectTimer->stop();
if(m_OnvifPTZ != nullptr)
{
disconnect(m_OnvifPTZ,SIGNAL(GetCapabilitiesRes(bool)),\
this,SLOT(GetCapabilitiesRes(bool)));
disconnect(m_OnvifPTZ,SIGNAL(GetServicesRes(bool)),\
this,SLOT(GetServicesRes(bool)));
disconnect(m_OnvifPTZ,SIGNAL(GetProfilesRes(bool)),\
this,SLOT(GetProfilesRes(bool)));
disconnect(m_OnvifPTZ,SIGNAL(MoveToRes(bool)),\
this,SLOT(MoveToRes(bool)));
delete m_OnvifPTZ;
m_OnvifPTZ = nullptr;
}
m_Ip.clear();
m_Port.clear();
m_UserName.clear();
m_PassWord.clear();
m_ConnectedSta = false;
disconnect(m_DataDictionary,SIGNAL(CameraCtlDataChange(CameraCtlIndex_t)),this,SLOT(CameraCtlDataChangeProcess(CameraCtlIndex_t)));
}
void NetCameraCtl::GetCapabilitiesRes(bool Res)
{
if(Res && m_OnvifPTZ->GetServices())
{
qDebug() << "m_OnvifPTZ GetCapabilitiesRes scuess";
return ;
}
else
{
qDebug() << "m_OnvifPTZ GetCapabilitiesRes failed";
m_ReconnectTimer->start();
}
}
void NetCameraCtl::GetServicesRes(bool Res)
{
if(Res && m_OnvifPTZ->GetProfiles())
{
qDebug() << "m_OnvifPTZ GetServicesRes scuess";
return ;
}
else
{
qDebug() << "m_OnvifPTZ GetServicesRes failed";
m_ReconnectTimer->start();
}
}
void NetCameraCtl::GetProfilesRes(bool Res)
{
if(Res)
{
if(!m_OnvifPTZ->MoveTo(m_ReqHValue,m_ReqVValue,m_ReqZoomValue)){
qDebug() << "m_OnvifPTZ MoveTo failed";
}
else {
qDebug() << "NetCameraCtl::Init Success";
m_ConnectedSta = true;
m_ReconnectTimer->stop();
m_CurHValue = m_ReqHValue;
m_CurVValue = m_ReqVValue;
m_CurZoomValue = m_ReqZoomValue;
//m_DataDictionary->SetCameraCtlData(CAM_CUR_H_VALUE,m_CurHValue);
//m_DataDictionary->SetCameraCtlData(CAM_CUR_H_ANGLE,(m_CurHValue*100)*m_CtlHMinAngle);
//m_DataDictionary->SetCameraCtlData(CAM_CUR_V_VALUE,m_CurVValue);
//m_DataDictionary->SetCameraCtlData(CAM_CUR_V_ANGLE,V_ALIGN_ANGLE-(m_CurVValue*100)*m_CtlVMinAngle);
//m_DataDictionary->SetCameraCtlData(CAM_CUR_ZOOM_VALUE,m_CurZoomValue);
CameraCtlDataChangeProcess(CAM_REQ_H_ANGLE);
CameraCtlDataChangeProcess(CAM_REQ_V_ANGLE);
}
}
else
{
qDebug() << "m_OnvifPTZ GetProfilesRes failed";
m_ReconnectTimer->start();
}
}
void NetCameraCtl::MoveToRes(bool Res)
{
if(Res)
{
m_CurHValue = m_ReqHValue;
m_DataDictionary->SetCameraCtlData(CAM_CUR_H_VALUE,m_CurHValue);
m_DataDictionary->SetCameraCtlData(CAM_CUR_H_ANGLE,(m_CurHValue*100)*m_CtlHMinAngle);
m_CurVValue = m_ReqVValue;
m_DataDictionary->SetCameraCtlData(CAM_CUR_V_VALUE,m_CurVValue);
double Val = (double)((double)V_ALIGN_ANGLE-(m_CurVValue*100)*m_CtlVMinAngle);
m_DataDictionary->SetCameraCtlData(CAM_CUR_V_ANGLE,QString("%1").arg(Val,0,'f',1));
m_CurZoomValue = m_ReqZoomValue;
m_DataDictionary->SetCameraCtlData(CAM_CUR_ZOOM_VALUE,m_CurZoomValue);
}
}
void NetCameraCtl::MisDataChangeProcess(MisDataIndex_t Index)
{
switch (Index) {
case MIS_CAMERA_MAX_ZOOM:
{
int tmpZoom = m_DataDictionary->GetMisData(MIS_CAMERA_MAX_ZOOM).toInt();
m_ZoomMaxLimit = ZOOM_MAX_VALUE*((double)tmpZoom/(double)100);
if(m_ZoomMaxLimit < ZOOM_MIN_VALUE){
m_ZoomMaxLimit = ZOOM_MIN_VALUE;
}else if(m_ZoomMaxLimit > ZOOM_MAX_VALUE){
m_ZoomMaxLimit = ZOOM_MAX_VALUE;
}
}
break;
case MIS_CAMERA_MAX_DISTANCE:
m_MaxDistance = m_DataDictionary->GetMisData(MIS_CAMERA_MAX_DISTANCE).toDouble();
break;
case MIS_CAMERA_GUN_STA:
if(m_DataDictionary->GetMisData(MIS_CAMERA_GUN_STA).toInt() == CAMERA_GUN_CHECK)
{
m_PtzControl = false;
}
else
{
m_PtzControl = true;
}
break;
default:
break;
}
}
void NetCameraCtl::CameraCtlDataChangeProcess(CameraCtlIndex_t Index)
{
switch(Index)
{
case CAM_REQ_H_VALUE:
if(!m_PtzControl)
return ;
m_ReqHValue = m_DataDictionary->GetCameraCtlData(CAM_REQ_H_VALUE).toDouble();
SetCamerHValue(m_ReqHValue);
break;
case CAM_REQ_H_ANGLE:
{
if(!m_PtzControl)
return ;
double Angle = m_DataDictionary->GetCameraCtlData(CAM_REQ_H_ANGLE).toDouble();;
m_ReqHValue = Angle/m_CtlHMinAngle/100;
qDebug() << "m_ReqHValue:"<<m_ReqHValue;
QString str = QString::number(m_ReqHValue,'f',2);
m_ReqHValue = str.toDouble();
qDebug() << "Angle:"<<Angle;
qDebug() << "m_ReqHValue:"<<m_ReqHValue;
SetCamerHValue(m_ReqHValue);
}
break;
case CAM_REQ_V_VALUE:
if(!m_PtzControl)
return ;
m_ReqVValue = m_DataDictionary->GetCameraCtlData(CAM_REQ_V_VALUE).toDouble();
SetCamerVValue(m_ReqVValue);
break;
case CAM_REQ_V_ANGLE:
{
if(!m_PtzControl)
return ;
double Angle = m_DataDictionary->GetCameraCtlData(CAM_REQ_V_ANGLE).toDouble();;
m_ReqVValue = (V_ALIGN_ANGLE-Angle)/m_CtlVMinAngle/100;
//qDebug() << "m_ReqVValue:"<<m_ReqVValue;
QString str = QString::number(m_ReqVValue,'f',2);
m_ReqVValue = str.toDouble();
//qDebug() << "Angle:"<<Angle;
//qDebug() << "m_ReqVValue:"<<m_ReqVValue;
SetCamerVValue(m_ReqVValue);
}
break;
case CAM_REQ_ZOOM_VALUE:
m_ReqZoomValue = m_DataDictionary->GetCameraCtlData(CAM_REQ_ZOOM_VALUE).toDouble();
SetCamerZoomValue(m_ReqZoomValue);
break;
case CAM_REQ_ZOOM_FROCE:
{
double Froce = m_DataDictionary->GetCameraCtlData(Index).toDouble();
m_ReqZoomValue = m_ZoomMaxLimit*Froce;
SetCamerZoomValue(m_ReqZoomValue);
}
break;
default:
break;
}
}
void NetCameraCtl::SystemDataChangeProcess(SystemDataIndex_t index)
{
switch (index) {
case SYS_CAMERA_IP1:
case SYS_PTZ_PORT:
case SYS_CAMERA_USERNAME1:
case SYS_CAMERA_PASSWORD1:
case SYS_PTZ_ADDR:
Reconnect();
break;
}
}
void NetCameraCtl::SetCamerHValue(double v)
{
if(v > H_MAX_VALUE){
v = H_MAX_VALUE;
}else if(v < H_MIN_VALUE){
v = H_MIN_VALUE;
}
if(v == m_CurHValue)
return ;
if(!m_ConnectedSta)
return ;
if(!m_OnvifPTZ->MoveTo(v,m_CurVValue,m_CurZoomValue)){
qDebug() << "m_OnvifPTZ MoveTo failed";
}
// else {
// m_CurHValue = v;
// m_DataDictionary->SetCameraCtlData(CAM_CUR_H_VALUE,m_CurHValue);
// m_DataDictionary->SetCameraCtlData(CAM_CUR_H_ANGLE,(m_CurHValue*100)*m_CtlHMinAngle);
// }
}
void NetCameraCtl::SetCamerVValue(double v)
{
if(v > V_MAX_VALUE){
v = V_MAX_VALUE;
}else if(v < V_MIN_VALUE){
v = V_MIN_VALUE;
}
if(v == m_CurVValue)
return ;
if(!m_ConnectedSta)
return ;
if(!m_OnvifPTZ->MoveTo(m_CurHValue,v,m_CurZoomValue)){
qDebug() << "m_OnvifPTZ MoveTo failed";
}
// else {
// m_CurVValue = v;
// m_DataDictionary->SetCameraCtlData(CAM_CUR_V_VALUE,m_CurVValue);
// double Val = (double)((double)V_ALIGN_ANGLE-(m_CurVValue*100)*m_CtlVMinAngle);
// m_DataDictionary->SetCameraCtlData(CAM_CUR_V_ANGLE,QString("%1").arg(Val,0,'f',1));
// }
}
void NetCameraCtl::SetCamerZoomValue(double v)
{
if(v > m_ZoomMaxLimit){
v = m_ZoomMaxLimit;
}else if(v < ZOOM_MIN_VALUE){
v = ZOOM_MIN_VALUE;
}
if(v == m_CurZoomValue)
return ;
if(!m_ConnectedSta)
return ;
if(!m_OnvifPTZ->MoveTo(m_CurHValue,m_CurVValue,v)){
qDebug() << "m_OnvifPTZ MoveTo failed";
}
// else {
// m_CurZoomValue = v;
m_DataDictionary->SetCameraCtlData(CAM_CUR_ZOOM_VALUE,m_CurZoomValue);
// }
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。