/////////////////////////////////////////////////////////////////////////////// // // (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/ // /////////////////////////////////////////////////////////////////////////////// // CReboot.cpp : implementation file // #include "stdafx.h" #include "finder.h" #include "Reboot.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif #define MAX_ITERATIONS 40 #define RETRY_TIME 500 ///////////////////////////////////////////////////////////////////////////// // CReboot dialog CReboot::CReboot(CWnd* pParent /*=NULL*/) : CDialog(CReboot::IDD, pParent) { //{{AFX_DATA_INIT(CReboot) m_ProductName = _T(""); m_MacAddress = _T(""); m_Password = _T(""); m_Status = _T(""); //}}AFX_DATA_INIT } void CReboot::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CReboot) DDX_Text(pDX, IDC_DEVICENAME, m_ProductName); DDX_Text(pDX, IDC_MAC_Address, m_MacAddress); DDX_Text(pDX, IDC_PASSWORD, m_Password); DDX_Text(pDX, IDC_STATUS, m_Status); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CReboot, CDialog) //{{AFX_MSG_MAP(CReboot) ON_BN_CLICKED(IDC_BUTTON1, OnReboot) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CReboot message handlers BOOL CReboot::OnInitDialog() { CDialog::OnInitDialog(); //Set current device settings into IPDialog m_MacAddress.Format("MAC Address: %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_ProductName = "Product Name: "; m_ProductName += m_DevInfo->product_name; UpdateData(FALSE); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CReboot::OnOK() { CDialog::OnOK(); } void CReboot::ReportError(addp_handle_t const 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.\n" "Error Number: %d\n" "Error Message: %s\n", LastError, DevErrorMessage); MessageBox(RebootErrorMessage); } void CReboot::OnReboot() { addp_handle_t Handle = ADDPOpen(ADDP_VENDOR_ID_DIGI); ASSERT(Handle != NULL); UpdateData(TRUE); if(ADDP_SUCCESS == ADDPRebootDevice(Handle, m_DevInfo->mac_address, m_Password)) { m_Status = "Status: Rebooting"; UpdateData(FALSE); BeginWaitCursor(); addp_device_info_t Result; int Iterations = 0; while((ADDP_SUCCESS != ADDPGetDeviceInfo(Handle, m_DevInfo->mac_address, &Result)) && (Iterations < MAX_ITERATIONS)) { Sleep(RETRY_TIME); Iterations++; } if(Iterations == MAX_ITERATIONS) //notify the user if the device didn't return m_Status = "Status: Timed out"; else m_Status = "Status: Ready"; UpdateData(FALSE); EndWaitCursor(); } else { ReportError(Handle); } ADDPClose(Handle); }