⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 remoteserverconfig.cpp

📁 SDK DVR/DVS HIKVISION
💻 CPP
字号:
// RemoteServerConfig.cpp : implementation file
//

#include "stdafx.h"
#include "newclient.h"
#include "RemoteServerConfig.h"
#include "RemoteNetConfig.h"
#include "RemoteDDNSEx.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

extern SERVER_INFO serverinfo[MAXIPNUMBER];
/////////////////////////////////////////////////////////////////////////////
// CRemoteServerConfig dialog
BOOL checkIPStr(CString ip)
{	//Check the input ip string
	char str[20];
	strcpy(str, ip);
    char a;
    int dot=0;
    int a3,a2,a1,a0,i = 0;
	a3 = a2 = a1 = a0 = -1;
    if(strlen(str)==0)
		return TRUE;
    while(a=str[i++])
	{
        if((a==' ')||(a=='.')||((a>='0')&&(a<='9')))
		{
            if(a=='.')
                dot++;
        }
        else
			return FALSE;
    }
    if(dot!=3)
		return FALSE;
    else
	{
        sscanf(str,"%d.%d.%d.%d",&a3,&a2,&a1,&a0);
        if( (a0>255)||(a1>255)||(a2>255)||(a3>255))
			return FALSE;
		if( (a0 < 0) || (a1 < 0) || (a2 < 0) || (a3 < 0) )
			return FALSE;
    }
	return TRUE;
}

CRemoteServerConfig::CRemoteServerConfig(CWnd* pParent /*=NULL*/)
	: CDialog(CRemoteServerConfig::IDD, pParent)
{
	//{{AFX_DATA_INIT(CRemoteServerConfig)
	m_AlarmInNum = 0;
	m_AlarmOutNum = 0;
	m_ChanNum = 0;
	m_DNSIP = _T("");
	m_GateWay = _T("");
	m_ServerIP = _T("");
	m_IPMask = _T("");
	m_MultiIP = _T("");
	m_ServerName = _T("");
	m_NFSDir = _T("");
	m_NFSIP = _T("");
	m_ServerPort = 0;
	m_ServerSerial = _T("");
	m_YKQID = 0;
	m_HardNum = 0;
	m_ManageHostIP = _T("");
	m_ManageHostPort = 0;
	m_PPPoEName = _T("");
	m_PPPoEpsw = _T("");
	m_QMBVersion = 0;
	m_MacAddr = _T("");
	m_csHardVersion = _T("");
	m_csSoftVersion = _T("");
	m_csDspVersion = _T("");
	m_PPPoEIP = _T("");
	m_httpPort = 0;
	m_FirstDNS = _T("");
	m_SecondDNS = _T("");
	//}}AFX_DATA_INIT
}


void CRemoteServerConfig::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CRemoteServerConfig)
	DDX_Control(pDX, IDC_COMBOUSEZOOM, m_UseZoom);
	DDX_Control(pDX, IDC_SERVERTYPE, m_ServerTypeCtrl);
	DDX_Control(pDX, IDC_RECYCLERECORD, m_RecycleRecord);
	DDX_Control(pDX, IDC_COMBOPPPOE, m_ComPPPoE);
	DDX_Control(pDX, IDC_COMBONETFACE, m_NetFace);
	DDX_Text(pDX, IDC_ALARMINNUM, m_AlarmInNum);
	DDX_Text(pDX, IDC_ALARMOUTNUM, m_AlarmOutNum);
	DDX_Text(pDX, IDC_EDITCHANNUM, m_ChanNum);
	DDX_Text(pDX, IDC_EDITDNSIP, m_DNSIP);
	DDX_Text(pDX, IDC_EDITGATEWAY, m_GateWay);
	DDX_Text(pDX, IDC_EDITIP, m_ServerIP);
	DDX_Text(pDX, IDC_EDITIPMASK, m_IPMask);
	DDX_Text(pDX, IDC_EDITMULTIIP, m_MultiIP);
	DDX_Text(pDX, IDC_EDITNAME, m_ServerName);
	DDX_Text(pDX, IDC_EDITNFSDIR, m_NFSDir);
	DDX_Text(pDX, IDC_EDITNFSIP, m_NFSIP);
	DDX_Text(pDX, IDC_EDITPORT, m_ServerPort);
	DDX_Text(pDX, IDC_EDITSERIAL, m_ServerSerial);
	DDX_Text(pDX, IDC_EDITYKQID, m_YKQID);
	DDX_Text(pDX, IDC_HDNUM, m_HardNum);
	DDX_Text(pDX, IDC_MANAGEHOSTIP, m_ManageHostIP);
	DDX_Text(pDX, IDC_MANAGEHOSTPORT, m_ManageHostPort);
	DDX_Text(pDX, IDC_PPPoENAME, m_PPPoEName);
	DDX_Text(pDX, IDC_PPPoEPSW, m_PPPoEpsw);
	DDX_Text(pDX, IDC_QMBVERSION, m_QMBVersion);
	DDX_Text(pDX, IDC_EDITMACIP, m_MacAddr);
	DDX_Text(pDX, IDC_HWVERSION, m_csHardVersion);
	DDX_Text(pDX, IDC_SWVERSION, m_csSoftVersion);
	DDX_Text(pDX, IDC_DSPVERSION, m_csDspVersion);
	DDX_Text(pDX, IDC_PPPOEIP, m_PPPoEIP);
	DDX_Text(pDX, IDC_HTTPPORT, m_httpPort);
	DDX_Text(pDX, IDC_FIRSTDNS, m_FirstDNS);
	DDX_Text(pDX, IDC_SECONDDNS, m_SecondDNS);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CRemoteServerConfig, CDialog)
	//{{AFX_MSG_MAP(CRemoteServerConfig)
	ON_BN_CLICKED(IDSVROK, OnSvrok)
	ON_BN_CLICKED(IDEXIT, OnExit)
	ON_BN_CLICKED(IDC_SETNETPARA, OnSetnetpara)
	ON_BN_CLICKED(IDC_DDNSEXCFG, OnDdnsexcfg)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CRemoteServerConfig message handlers
BOOL CRemoteServerConfig::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	CRect rc(0, 0, 0, 0);
	GetParent()->GetClientRect(&rc);
	((CTabCtrl*)GetParent())->AdjustRect(FALSE, &rc);
	MoveWindow(&rc);
	
	if (serverinfo[m_iServer].m_dwDevSoftVersion < 0x20001)
	{
		GetDlgItem(IDC_SETNETPARA)->ShowWindow(SW_HIDE);
	}

	char cTemp[200];
	CString sTemp;
	
	bSetServerParams = FALSE;
	m_bConnectServer = TRUE;

	if(!NET_DVR_GetDVRConfig(m_lServerID, NET_DVR_GET_DEVICECFG, 0,&m_devicecfg, sizeof(NET_DVR_DEVICECFG), &dwReturned))
	{
		int iErr = NET_DVR_GetLastError();
		if (iErr == NET_DVR_USERNOTEXIST)
		{
			m_bConnectServer = FALSE;		
			sTemp.Format("The user is not existed!");
			AfxMessageBox(sTemp);
//			return FALSE;
		}
		else if(iErr == NET_DVR_NETWORK_FAIL_CONNECT)
		{
			m_bConnectServer = FALSE;		
			sTemp.Format("Can not connect DVRDVS!");
			AfxMessageBox(sTemp);
//			return FALSE;
		}
		sTemp.Format("Get server parameters failed: NET_DVR_GET_DEVICECFG = %d \n", NET_DVR_GetLastError());
		AfxMessageBox(sTemp);
//		return FALSE;
	} 

	if(!NET_DVR_GetDVRConfig(m_lServerID, NET_DVR_GET_NETCFG, 0,&m_netcfg, sizeof(NET_DVR_NETCFG), &dwReturned))
	{
		sTemp.Format("Get server parameters failed: NET_DVR_GET_NETCFG = %d \n", NET_DVR_GetLastError());
		AfxMessageBox(sTemp);	
//		return FALSE;
	}
	
	
	if (!NET_DVR_GetScaleCFG(m_lServerID, &m_dwUseZoom))
	{
		m_bSupScale = FALSE;
		sTemp.Format("get scale parameters failed: NET_DVR_GetLastError = %d \n", NET_DVR_GetLastError());
		TRACE(sTemp);
	}
	else
	{
		m_bSupScale = TRUE;	
	}


	if (m_bSupScale)
	{		
		GetDlgItem(IDC_STATICSCALE)->ShowWindow(SW_SHOW);
		m_UseZoom.ShowWindow(SW_SHOW);
		m_UseZoom.SetCurSel(m_dwUseZoom);	
	}

	ZeroMemory(cTemp, 200);
	memcpy(cTemp, m_devicecfg.sDVRName, NAME_LEN);
	m_ServerName.Format("%s", cTemp);
	m_YKQID = m_devicecfg.dwDVRID;
	ZeroMemory(cTemp, 200);
	memcpy(cTemp, m_devicecfg.sSerialNumber, SERIALNO_LEN);
	m_ServerSerial.Format("%s", cTemp);
	m_csSoftVersion.Format("V%d.%d build %02d%02d%02d", (m_devicecfg.dwSoftwareVersion>>16)&0xFFFF, m_devicecfg.dwSoftwareVersion&0xFFFF, (m_devicecfg.dwSoftwareBuildDate>>16)&0xFFFF, (m_devicecfg.dwSoftwareBuildDate>>8)&0xFF,m_devicecfg.dwSoftwareBuildDate&0xFF);
	m_csHardVersion.Format("0x%x", m_devicecfg.dwHardwareVersion);
	m_QMBVersion = m_devicecfg.dwPanelVersion;
	m_csDspVersion.Format("V%d.%d build %02d%02d%02d", (m_devicecfg.dwDSPSoftwareVersion>>16)&0xFFFF, m_devicecfg.dwDSPSoftwareVersion&0xFFFF, (m_devicecfg.dwDSPSoftwareBuildDate>>16)&0xFFFF-2000, (m_devicecfg.dwDSPSoftwareBuildDate>>8)&0xFF,m_devicecfg.dwDSPSoftwareBuildDate&0xFF);
	m_AlarmInNum = m_devicecfg.byAlarmInPortNum;
	m_AlarmOutNum = m_devicecfg.byAlarmOutPortNum;
	m_ChanNum = m_devicecfg.byChanNum;	
	//2008-03-15 we have to do this like so because of these three special numbers
	if (m_devicecfg.byDVRType == 30)
	{
		m_ServerTypeCtrl.SetCurSel(m_ServerTypeCtrl.FindString(-1, "IPCAM"));
	}
	else if (m_devicecfg.byDVRType == 40)
	{
		m_ServerTypeCtrl.SetCurSel(m_ServerTypeCtrl.FindString(-1, "IPDOME"));
	}
	else if (m_devicecfg.byDVRType == 50)
	{
		m_ServerTypeCtrl.SetCurSel(m_ServerTypeCtrl.FindString(-1, "IPMOD"));
	}
	else
	{
		m_ServerTypeCtrl.SetCurSel(m_devicecfg.byDVRType-1);
	}
	m_DNSIP = m_netcfg.sIPServer;
	m_GateWay = m_netcfg.sGatewayIP;
	m_ServerIP = m_netcfg.struEtherNet[0].sDVRIP;
	m_IPMask = m_netcfg.struEtherNet[0].sDVRIPMask;
	m_MacAddr.Format("%02x:%02x:%02x:%02x:%02x:%02x", m_netcfg.struEtherNet[0].byMACAddr[0],m_netcfg.struEtherNet[0].byMACAddr[1],m_netcfg.struEtherNet[0].byMACAddr[2],m_netcfg.struEtherNet[0].byMACAddr[3],m_netcfg.struEtherNet[0].byMACAddr[4],m_netcfg.struEtherNet[0].byMACAddr[5]);
	m_MultiIP = m_netcfg.sMultiCastIP;
	ZeroMemory(cTemp, 200);
	memcpy(cTemp, m_netcfg.sNFSDirectory, PATHNAME_LEN);
	m_NFSDir.Format("%s", cTemp);
	m_NFSIP = m_netcfg.sNFSIP;
	m_ServerPort = m_netcfg.struEtherNet[0].wDVRPort;
	m_HardNum = m_devicecfg.byDiskNum;
	m_ManageHostIP = m_netcfg.sManageHostIP;
	m_ManageHostPort = m_netcfg.wManageHostPort;
	ZeroMemory(cTemp, 200);
	memcpy(cTemp, m_netcfg.sPPPoEUser, NAME_LEN);
	m_PPPoEName.Format("%s", cTemp);
	ZeroMemory(cTemp, 200);
	memcpy(cTemp, m_netcfg.sPPPoEPassword, PASSWD_LEN);
	m_PPPoEpsw.Format("%s", cTemp);

	m_RecycleRecord.SetCurSel(m_devicecfg.dwRecycleRecord);
	m_NetFace.SetCurSel(m_netcfg.struEtherNet[0].dwNetInterface-1);
	m_ComPPPoE.SetCurSel(m_netcfg.dwPPPOE);
	m_PPPoEIP = m_netcfg.sPPPoEIP;
	m_httpPort = m_netcfg.wHttpPort;

	NET_DVR_PREVIEWCFG m_temp;
	
	if (!NET_DVR_GetDVRConfig(m_lServerID,NET_DVR_GET_PREVIEWCFG, 0,&m_temp, sizeof(NET_DVR_PREVIEWCFG), &dwReturned))	
	{
		sTemp.Format("ERROR: NET_DVR_GET_PREVIEWCFG = %d \n", NET_DVR_GetLastError());
		TRACE(sTemp);	
//		return FALSE;
	}
	
	if (!NET_DVR_SetDVRConfig(m_lServerID,NET_DVR_SET_PREVIEWCFG, 0, &m_temp, sizeof(NET_DVR_PREVIEWCFG)))
	{
		sTemp.Format("%d : ERROR: NET_DVR_SET_PREVIEWCFG = %d \n", 0, NET_DVR_GetLastError());
		TRACE(sTemp);	
//		return FALSE;
	}

	if (!NET_DVR_GetDVRConfig(m_lServerID,NET_DVR_GET_PREVIEWCFG_AUX, 0,&m_temp, sizeof(NET_DVR_PREVIEWCFG), &dwReturned))	
	{
		sTemp.Format("ERROR: NET_DVR_GET_PREVIEWCFG_AUX = %d \n", NET_DVR_GetLastError());
		TRACE(sTemp);	
		//return FALSE;
	}
	if (!NET_DVR_SetDVRConfig(m_lServerID,NET_DVR_SET_PREVIEWCFG_AUX, 0, &m_temp, sizeof(NET_DVR_PREVIEWCFG)))
	{
		sTemp.Format("ERROR: NET_DVR_SET_PREVIEWCFG-AUX = %d \n",  NET_DVR_GetLastError());
		TRACE(sTemp);	
		//return FALSE;
	}	
		
	NET_DVR_AUXOUTCFG m_auxout;
	
	if (!NET_DVR_GetDVRConfig(m_lServerID,NET_DVR_GET_AUXOUTCFG, 0,&m_auxout, sizeof(NET_DVR_AUXOUTCFG), &dwReturned))	
	{
		sTemp.Format("ERROR: NET_DVR_GET_AUXOUTCFG = %d \n", NET_DVR_GetLastError());
		TRACE(sTemp);	
		//return FALSE;
	}
	if (!NET_DVR_SetDVRConfig(m_lServerID,NET_DVR_SET_AUXOUTCFG, 0, &m_auxout, sizeof(NET_DVR_AUXOUTCFG)))
	{
		
		sTemp.Format("%d : ERROR: NET_DVR_SET_AUXOUTCFG = %d \n", 0, NET_DVR_GetLastError());
		TRACE(sTemp);	
		//return FALSE;
	}

	if (m_devicecfg.byDVRType == DEC_MAT)
	{
		//get multi-decoder DNS settings
		ZeroMemory(&m_MultiDecoder, sizeof(NET_DVR_NETCFG_OTHER));
		m_MultiDecoder.dwSize = sizeof(NET_DVR_NETCFG_OTHER);
		if (!NET_DVR_GetDVRConfig(m_lServerID, NET_DVR_GET_NETCFG_OTHER, 0, &m_MultiDecoder, sizeof(NET_DVR_NETCFG_OTHER), &dwReturned))
		{
			sTemp.Format("ERROR: NET_DVR_GET_NETCFG_OTHER = %d \n", NET_DVR_GetLastError());
			TRACE(sTemp);
		}
		m_FirstDNS.Format("%s", m_MultiDecoder.sFirstDNSIP);
		m_SecondDNS.Format("%s", m_MultiDecoder.sSecondDNSIP);
	}
	else
	{
		GetDlgItem(IDC_MDDNS1)->ShowWindow(SW_HIDE);
		GetDlgItem(IDC_MDDNS2)->ShowWindow(SW_HIDE);
		GetDlgItem(IDC_FIRSTDNS)->ShowWindow(SW_HIDE);
		GetDlgItem(IDC_SECONDDNS)->ShowWindow(SW_HIDE);
	}

	if (m_devicecfg.byDVRType == DEC || m_devicecfg.byDVRType == ENC_DEC || m_devicecfg.byDVRType == DEC_MAT)
	{
		GetDlgItem(IDC_SETNETPARA)->ShowWindow(SW_HIDE);
		GetDlgItem(IDC_DDNSEXCFG)->ShowWindow(SW_HIDE);
	}
	UpdateData(FALSE);
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}


void CRemoteServerConfig::OnSvrok() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	
	if(m_ServerPort <= 0)
	{
		AfxMessageBox("Illegal port number!");
		return;
	}
	
	if( (m_ServerIP == "0.0.0.0") || (m_ServerIP == "") || !checkIPStr(m_ServerIP))
	{
		AfxMessageBox("Illegal server IP!");
		return;
	}
	
	if(!checkIPStr(m_IPMask))
	{
		AfxMessageBox("Illegal mask IP!");
		return;
	}
	
	if(!checkIPStr(m_DNSIP))
	{
		AfxMessageBox("Illegal DNS IP!");
		return;
	}
	if(!checkIPStr(m_MultiIP))
	{
		AfxMessageBox("Illegal Multicast IP!");
		return;
	}
	if(!checkIPStr(m_GateWay))
	{
		AfxMessageBox("Illegal gateway IP!");
		return;
	}
	if(!checkIPStr(m_NFSIP))
	{
		AfxMessageBox("Illegal NAS IP!");
		return;
	}
	if(!checkIPStr(m_ManageHostIP))
	{
		AfxMessageBox("Illegal remote host IP!");
		return;
	}
	if(!checkIPStr(m_PPPoEIP))
	{
		AfxMessageBox("Illegal PPPoE IP!");
		return;
	}
	if (!checkIPStr(m_FirstDNS))
	{
		AfxMessageBox("Illegal DNS IP!");
		return;
	}
	if (!checkIPStr(m_SecondDNS))
	{
		AfxMessageBox("Illegal DNS IP!");
		return;
	}
	
	m_devicecfg.dwDVRID = m_YKQID;
	memcpy(m_devicecfg.sDVRName, m_ServerName, NAME_LEN);	
	memcpy(m_netcfg.struEtherNet[0].sDVRIP, m_ServerIP, 16);
	memcpy(m_netcfg.struEtherNet[0].sDVRIPMask, m_IPMask, 16);
	memcpy(m_netcfg.sIPServer, m_DNSIP, 16);	
	memcpy(m_netcfg.sMultiCastIP, m_MultiIP,16);
	memcpy(m_netcfg.sGatewayIP, m_GateWay,16);
	m_netcfg.struEtherNet[0].wDVRPort = m_ServerPort;
	memcpy(m_netcfg.sNFSDirectory, m_NFSDir,PATHNAME_LEN);
	memcpy(m_netcfg.sNFSIP, m_NFSIP,16);
	memcpy(m_netcfg.sManageHostIP, m_ManageHostIP,16);
	m_netcfg.wManageHostPort = m_ManageHostPort;
	memcpy(m_netcfg.sPPPoEUser, m_PPPoEName, NAME_LEN);
	memcpy(m_netcfg.sPPPoEPassword, m_PPPoEpsw, PASSWD_LEN);
	memcpy(m_netcfg.sPPPoEIP, m_PPPoEIP, 16);
	m_netcfg.struEtherNet[0].dwNetInterface = m_NetFace.GetCurSel()+1;
	m_devicecfg.dwRecycleRecord = m_RecycleRecord.GetCurSel();
	m_netcfg.dwPPPOE = m_ComPPPoE.GetCurSel();
	m_netcfg.wHttpPort = m_httpPort;
	if (m_bSupScale)
	{
		m_dwUseZoom = m_UseZoom.GetCurSel();	
	}
	sprintf(m_MultiDecoder.sFirstDNSIP, "%s", m_FirstDNS);
	sprintf(m_MultiDecoder.sSecondDNSIP, "%s", m_SecondDNS);

	bSetServerParams = TRUE;
}

void CRemoteServerConfig::OnExit() 
{
	// TODO: Add your control notification handler code here
	bSetServerParams = FALSE;
}

void CRemoteServerConfig::OnCancel() 
{
	// TODO: Add extra cleanup here
	
//	CDialog::OnCancel();
}

void CRemoteServerConfig::OnOK() 
{
	// TODO: Add extra cleanup here
	
	//	CDialog::OnOK();
}


void CRemoteServerConfig::OnSetnetpara() 
{
	// TODO: Add your control notification handler code here
	CRemoteNetConfig rnc;
	rnc.m_lServerID = m_lServerID;
	rnc.DoModal();
}

void CRemoteServerConfig::OnDdnsexcfg() 
{
	// TODO: Add your control notification handler code here
	CRemoteDDNSEx RDE(m_lServerID);

	RDE.DoModal();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -