// PageNetwork.cpp : implementation file // #include "stdafx.h" #include "mgrnve.h" #include "ConnectionManager.h" #include "PageNetwork.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CPageNetwork dialog CPageNetwork::CPageNetwork(CWnd* pParent, CMgrNVE* pMgrCM, CConnectionManager *pConnMgr) : CParamDlg(CPageNetwork::IDD, pParent, pMgrCM, pConnMgr) { //{{AFX_DATA_INIT(CPageNetwork) m_strDNS1 = _T(""); m_strDNS2 = _T(""); m_strGateway = _T(""); m_strIP = _T(""); m_strMAC = _T(""); m_strNetmask = _T(""); m_uNTPUpdate = 0; m_strNTP1 = _T(""); m_strNTP2 = _T(""); m_uRTSPPort = 0; m_uTimeout = 0; m_uHTTPPort = 0; //}}AFX_DATA_INIT m_pNet5Api = NULL; m_pMsgMgr = NULL; } void CPageNetwork::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CPageNetwork) DDX_Control(pDX, IDC_CB_TIME_MODE, m_cbTimeMode); DDX_Control(pDX, IDC_CB_IP_CONFIG, m_cbIPConfig); DDX_Text(pDX, IDC_EDIT_DNS1, m_strDNS1); DDX_Text(pDX, IDC_EDIT_DNS2, m_strDNS2); DDX_Text(pDX, IDC_EDIT_GATEWAY, m_strGateway); DDX_Text(pDX, IDC_EDIT_IP, m_strIP); DDX_Text(pDX, IDC_EDIT_MAC, m_strMAC); DDX_Text(pDX, IDC_EDIT_NETMASK, m_strNetmask); DDX_Text(pDX, IDC_EDIT_NTP_UPDATE, m_uNTPUpdate); DDX_Text(pDX, IDC_EDIT_NTP1, m_strNTP1); DDX_Text(pDX, IDC_EDIT_NTP2, m_strNTP2); DDX_Text(pDX, IDC_EDIT_RTSP_PORT, m_uRTSPPort); DDX_Text(pDX, IDC_EDIT_TIMEOUT, m_uTimeout); DDX_Text(pDX, IDC_EDIT_HTTP_PORT, m_uHTTPPort); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CPageNetwork, CDialog) //{{AFX_MSG_MAP(CPageNetwork) ON_BN_CLICKED(IDC_BTN_NETWORK_SET, OnBtnNetworkSet) ON_CBN_SELCHANGE(IDC_CB_IP_CONFIG, OnSelchangeCbIpConfig) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CPageNetwork message handlers BOOL CPageNetwork::SaveSetting() { return TRUE; } BOOL CPageNetwork::ResetSetting() { return TRUE; } BOOL CPageNetwork::UpdateSetting() { return TRUE; } BOOL CPageNetwork::OnInitDialog() { CDialog::OnInitDialog(); // TODO: Add extra initialization here m_pNet5Api = m_pConnection->GetNet5Api(); m_pMsgMgr = m_pMgrNVE->GetMsgManager(); m_cbIPConfig.AddString("STATIC"); m_cbIPConfig.AddString("DHCP"); m_cbIPConfig.SetCurSel(0); m_cbTimeMode.AddString("NTP"); m_cbTimeMode.AddString("RTC"); m_cbTimeMode.AddString("NTP2RTC"); m_cbTimeMode.SetCurSel(0); char szCmd[NVE_MAX_EXT_CMD_LENGTH]; char szTimeMode[NVE_SHORT_STR_LENGTH]; char szMac[NVE_MAX_STR_LENGTH]; ULONG uNtpUpdate; _snprintf(szCmd, sizeof(szCmd), "EXT_CMD %s/ RTSP/1.0\r\n" "CSeq: 1\r\n" "CmdCount: 1\r\n" "GET NETWORK time_mode, mac, ntp_update\r\n\r\n", m_pConnection->GetServerAddr()); CHECK_AND_RETURN_FALSE(m_pNet5Api->Net5Command(NET5_NC_SEND_RTSP_REQUEST, (ULONG*)szCmd, NULL, NULL, NULL), "Cannot get time mode"); CHECK_AND_RETURN_FALSE(m_pNet5Api->Net5Command(NET5_NC_RECV_RTSP_RESPONSE, (ULONG*)szCmd, NULL, NULL, NULL), "Cannot receive response(time mode)"); ParseRTSPResponse(szCmd, m_RtspValue, NVE_MAX_RTSP_VALUE); FindRTSPValue(m_RtspValue, "time_mode", szTimeMode, NVE_RTSP_VALUE_STR); FindRTSPValue(m_RtspValue, "mac", szMac, NVE_RTSP_VALUE_STR); FindRTSPValue(m_RtspValue, "ntp_update", &uNtpUpdate, NVE_RTSP_VALUE_INT); if (strcmp(szTimeMode, "ntp") == 0) { m_cbTimeMode.SetCurSel(0); } else if (strcmp(szTimeMode, "rtc") == 0) { m_cbTimeMode.SetCurSel(1); } else if (strcmp(szTimeMode, "ntp_to_rtc") == 0) { m_cbTimeMode.SetCurSel(2); } GetAddress(); SetDlgItemText(IDC_EDIT_MAC, szMac); SetDlgItemInt(IDC_EDIT_NTP_UPDATE, uNtpUpdate); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CPageNetwork::GetAddress() { // TODO: Add your control notification handler code here NET5_ADDR_INFO Info; char szNTP[2][NVE_MAX_STR_LENGTH]; ULONG uIPAddrConf; CHECK_AND_RETURN(m_pNet5Api->Net5Command(NET5_NC_GET_IP_ADDR_CONFIG, &uIPAddrConf, NULL, NULL, NULL), "Cannot get IP address config"); if (uIPAddrConf == NET5_IAC_DHCP) { m_cbIPConfig.SetCurSel(1); (CEdit*)(GetDlgItem(IDC_EDIT_IP))->EnableWindow(FALSE); (CEdit*)(GetDlgItem(IDC_EDIT_NETMASK))->EnableWindow(FALSE); (CEdit*)(GetDlgItem(IDC_EDIT_GATEWAY))->EnableWindow(FALSE); } else { m_cbIPConfig.SetCurSel(0); (CEdit*)(GetDlgItem(IDC_EDIT_IP))->EnableWindow(TRUE); (CEdit*)(GetDlgItem(IDC_EDIT_NETMASK))->EnableWindow(TRUE); (CEdit*)(GetDlgItem(IDC_EDIT_GATEWAY))->EnableWindow(TRUE); } CHECK_AND_RETURN(m_pNet5Api->Net5Command(NET5_NC_GET_SERVER_ADDR, (ULONG*)&Info, NULL, NULL, NULL), "Cannot get server address"); CHECK_AND_RETURN(m_pNet5Api->Net5Command(NET5_NC_GET_PORT, (ULONG*)&m_uHTTPPort, (ULONG*)&m_uRTSPPort, NULL, NULL), "Cannot get ports"); CHECK_AND_RETURN(m_pNet5Api->Net5Command(NET5_NC_GET_SNTP_ADDRESS, (ULONG*)szNTP[0], (ULONG*)szNTP[1], NULL, NULL), "Cannot get NTP address"); CHECK_AND_RETURN(m_pNet5Api->Net5GetApiTimeOut((ULONG*)&m_uTimeout), "Cannot get network timeout"); m_strIP = Info.Address; m_strNetmask = Info.SubnetMask; m_strGateway = Info.Gateway; m_strDNS1 = Info.DNS[0]; m_strDNS2 = Info.DNS[1]; m_strNTP1 = szNTP[0]; m_strNTP2 = szNTP[1]; UpdateData(FALSE); } void CPageNetwork::OnBtnNetworkSet() { // TODO: Add your control notification handler code here NET5_ADDR_INFO Info; char szNTP[2][NVE_MAX_STR_LENGTH]; UpdateData(TRUE); if (m_cbIPConfig.GetCurSel() == 1) { ULONG uIPAddrConf = NET5_IAC_DHCP; CHECK_AND_RETURN(m_pNet5Api->Net5Command(NET5_NC_SET_IP_ADDR_CONFIG, &uIPAddrConf, NULL, NULL, NULL), "Cannot set DHCP"); }else{ strcpy(Info.Address, (LPSTR)(LPCSTR)m_strIP); strcpy(Info.SubnetMask, (LPSTR)(LPCSTR)m_strNetmask); strcpy(Info.Gateway, (LPSTR)(LPCSTR)m_strGateway); strcpy(Info.DNS[0], (LPSTR)(LPCSTR)m_strDNS1); strcpy(Info.DNS[1], (LPSTR)(LPCSTR)m_strDNS2); CHECK_AND_RETURN(m_pNet5Api->Net5Command(NET5_NC_SET_ADDR, (ULONG*)&Info, NULL, NULL, NULL), "Cannot set address"); } CHECK_AND_RETURN(m_pNet5Api->Net5Command(NET5_NC_SET_PORT, (ULONG*)&m_uHTTPPort, (ULONG*)&m_uRTSPPort, NULL, NULL), "Cannot set ports"); strcpy(szNTP[0], (LPSTR)(LPCSTR)m_strNTP1); strcpy(szNTP[1], (LPSTR)(LPCSTR)m_strNTP2); CHECK_AND_RETURN(m_pNet5Api->Net5Command(NET5_NC_SET_SNTP_ADDRESS, (ULONG*)szNTP[0], (ULONG*)szNTP[1], NULL, NULL), "Cannot set NTP address"); CHECK_AND_RETURN(m_pNet5Api->Net5SetApiTimeOut(m_uTimeout), "Cannot set network timeout"); char szCmd[NVE_MAX_EXT_CMD_LENGTH]; char szTimeMode[NVE_SHORT_STR_LENGTH]; switch(m_cbTimeMode.GetCurSel()) { case 0: safe_strcpy(szTimeMode, "ntp"); break; case 1: safe_strcpy(szTimeMode, "rtc"); break; case 2: safe_strcpy(szTimeMode, "ntp_to_rtc"); break; } _snprintf(szCmd, sizeof(szCmd), "EXT_CMD %s/ RTSP/1.0\r\n" "CSeq: 1\r\n" "CmdCount: 1\r\n" "SET NETWORK time_mode=\"%s\", ntp_update=%d\r\n\r\n", m_pConnection->GetServerAddr(), szTimeMode, m_uNTPUpdate); CHECK_AND_RETURN(m_pNet5Api->Net5Command(NET5_NC_SEND_RTSP_REQUEST, (ULONG*)szCmd, NULL, NULL, NULL), "Cannot set time mode"); CHECK_AND_RETURN(m_pNet5Api->Net5Command(NET5_NC_RECV_RTSP_RESPONSE, (ULONG*)szCmd, NULL, NULL, NULL), "Cannot receive response(time mode)"); } void CPageNetwork::OnSelchangeCbIpConfig() { // TODO: Add your control notification handler code here if (m_cbIPConfig.GetCurSel() == 0) { (CEdit*)(GetDlgItem(IDC_EDIT_IP))->EnableWindow(TRUE); (CEdit*)(GetDlgItem(IDC_EDIT_NETMASK))->EnableWindow(TRUE); (CEdit*)(GetDlgItem(IDC_EDIT_GATEWAY))->EnableWindow(TRUE); } else if (m_cbIPConfig.GetCurSel() == 1) { (CEdit*)(GetDlgItem(IDC_EDIT_IP))->EnableWindow(FALSE); (CEdit*)(GetDlgItem(IDC_EDIT_NETMASK))->EnableWindow(FALSE); (CEdit*)(GetDlgItem(IDC_EDIT_GATEWAY))->EnableWindow(FALSE); } }