/////////////////////////////////////////////////////////////////////////////// // // (c) Digi International Inc. 2003. All Rights Reserved // // Digi provides this document "as is," without warranty of any kind, // either expressed or implied, including, but not limited to, the implied // warranties of fitness or merchantability for a particular purpose. Digi // may make improvements and/or changes in this document or in the product(s) // and/or the program(s) described in this document at any time. // // This document could include technical inaccuracies or typographical errors. // Changes are periodically made to the information herein; these changes may // be incorporated in new editions of the publication. // // Digi International Inc. // 11001 Bren Road East // Minnetonka, MN 55343, USA // Tel: +1 (952) 912-3444 // Fax: +1 (952) 912-4952 // http://www.digi.com/ // /////////////////////////////////////////////////////////////////////////////// // ConfigIP.cpp : implementation file // #include "stdafx.h" #include "Finder.h" #include "ConfigIP.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CConfigIP dialog CConfigIP::CConfigIP(CWnd* pParent /*=NULL*/) : CDialog(CConfigIP::IDD, pParent) { //{{AFX_DATA_INIT(CConfigIP) m_Password = _T(""); m_MacAddress = _T(""); m_ProductName = _T(""); m_DhcpState = -1; //}}AFX_DATA_INIT } void CConfigIP::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CConfigIP) DDX_Control(pDX, IDC_IPADDRESS1, m_IpAddress); DDX_Control(pDX, IDC_IPADDRESS3, m_DefaultGateway); DDX_Control(pDX, IDC_IPADDRESS2, m_SubnetMask); DDX_Text(pDX, IDC_EDIT1, m_Password); DDX_Text(pDX, IDC_MACADDRESS, m_MacAddress); DDX_Text(pDX, IDC_PRODUCT, m_ProductName); DDX_Radio(pDX, IDC_DHCP_ENABLE, m_DhcpState); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CConfigIP, CDialog) //{{AFX_MSG_MAP(CConfigIP) ON_BN_CLICKED(IDC_DHCP_ENABLE, OnEnableDHCP) ON_BN_CLICKED(IDC_DHCP_DISABLE, OnDisableDHCP) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CConfigIP message handlers BOOL CConfigIP::OnInitDialog() { CDialog::OnInitDialog(); if(m_DevInfo->dhcp_mode == ADDP_DHCP_MODE_ENABLED) { OnEnableDHCP(); } else { OnDisableDHCP(); } UpdateData(FALSE); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CConfigIP::OnOK() { addp_handle_t Handle = ADDPOpen(ADDP_VENDOR_ID_DIGI); ASSERT(Handle != NULL); UpdateData(TRUE); if(m_DhcpState == RadioButtonDhcpEnabled) { if(ADDP_SUCCESS == ADDPSetDHCP(Handle, m_DevInfo->mac_address, ADDP_DHCP_MODE_ENABLED, m_Password)) { //reboot device here for changes to take effect //ADDPRebootDevice(Handle, m_DevInfo->mac_address, m_Password); } else ReportError(Handle); } else { //////Convert CIPAddressCtrl Fields into IN_ADDR DWORD Address; IN_ADDR IpAddress, SubnetMask, DefaultGateway; m_IpAddress.GetAddress(Address); IpAddress.S_un.S_addr = htonl(Address); m_DefaultGateway.GetAddress(Address); DefaultGateway.S_un.S_addr = htonl(Address); m_SubnetMask.GetAddress(Address); SubnetMask.S_un.S_addr = htonl(Address); //////END CONVERSION PORTION if(ADDP_SUCCESS == ADDPSetNetwork(Handle, m_DevInfo->mac_address, IpAddress, SubnetMask, DefaultGateway, m_Password)) { //reboot device here for changes to take effect //ADDPRebootDevice(Handle, m_DevInfo->mac_address, m_Password); } else ReportError(Handle); } ADDPClose(Handle); CDialog::OnOK(); } void CConfigIP::OnEnableDHCP() { SetWindowStatus(FALSE); } void CConfigIP::OnDisableDHCP() { SetWindowStatus(TRUE); } void CConfigIP::ReportError(addp_handle_t Handle) { CString RebootErrorMessage; char DevErrorMessage[ADDP_MAX_STRING_LENGTH]; int LastError; LastError = ADDPGetLastError(Handle); ADDPGetLastErrorMessage(Handle, DevErrorMessage, sizeof(DevErrorMessage)); RebootErrorMessage.Format("An Error occured while rebooting the device.\nError Number: %d\nError Message: %s\n", LastError, DevErrorMessage); MessageBox(RebootErrorMessage); } void CConfigIP::SetWindowStatus(bool State) { CString MacAddress; MacAddress.Format("%02x:%02x:%02x:%02x:%02x:%02x", m_DevInfo->mac_address[0], m_DevInfo->mac_address[1], m_DevInfo->mac_address[2], m_DevInfo->mac_address[3], m_DevInfo->mac_address[4], m_DevInfo->mac_address[5]); m_DhcpState = (int)State; // Enable IP settings dialog elements m_IpAddress.EnableWindow(State); m_SubnetMask.EnableWindow(State); m_DefaultGateway.EnableWindow(State); m_IpAddress.SetAddress(m_DevInfo->ip_address.S_un.S_un_b.s_b1, m_DevInfo->ip_address.S_un.S_un_b.s_b2, m_DevInfo->ip_address.S_un.S_un_b.s_b3, m_DevInfo->ip_address.S_un.S_un_b.s_b4); m_SubnetMask.SetAddress(m_DevInfo->subnet_mask.S_un.S_un_b.s_b1, m_DevInfo->subnet_mask.S_un.S_un_b.s_b2, m_DevInfo->subnet_mask.S_un.S_un_b.s_b3, m_DevInfo->subnet_mask.S_un.S_un_b.s_b4); m_DefaultGateway.SetAddress(m_DevInfo->gateway_address.S_un.S_un_b.s_b1, m_DevInfo->gateway_address.S_un.S_un_b.s_b2, m_DevInfo->gateway_address.S_un.S_un_b.s_b3, m_DevInfo->gateway_address.S_un.S_un_b.s_b4); m_ProductName = m_DevInfo->product_name; m_MacAddress = MacAddress; UpdateData(FALSE); }