www.pudn.com > DalsaNetlink.rar > CyTimeoutDialog.cpp


// CyTimeoutDialog.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "resource.h" 
#include "resource.hm" 
#include "CyTimeoutDialog.h" 
 
#ifdef _DEBUG 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CyTimeoutDialog dialog 
 
 
CyTimeoutDialog::CyTimeoutDialog(CWnd* pParent /*=NULL*/) 
	: CDialog(CyTimeoutDialog::IDD, pParent) 
    , mInitialized( false ) 
{ 
	//{{AFX_DATA_INIT(CyTimeoutDialog) 
	mFirstPacketTimeout = 0; 
	mImageSize = 0; 
	mLinkType = -1; 
	mPacketTimeout = 0; 
	mRequestTimeout = 0; 
	mPacketSize = 0; 
	mMaxTime = 0; 
	mLineScan = FALSE; 
	mLineCount = 0; 
	//}}AFX_DATA_INIT 
 
    mLinkType = 0; 
    mLineCount = 1; 
} 
 
 
void CyTimeoutDialog::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CyTimeoutDialog) 
	DDX_Control(pDX, IDC_LINE_SCAN, mLineScanControl); 
	DDX_Control(pDX, IDC_LINE_COUNT_SPIN, mLineCountSpin); 
	DDX_Control(pDX, IDC_LINE_COUNT_TEXT, mLineCountText); 
	DDX_Control(pDX, IDC_LINE_COUNT, mLineCountControl); 
	DDX_Control(pDX, IDC_WAIT_TIME, mWaitTimeControl); 
	DDX_Control(pDX, IDC_PACKET_SIZE, mPacketSizeControl); 
	DDX_Control(pDX, IDC_LINK_TYPE, mLinkTypeControl); 
	DDX_Control(pDX, IDC_IMAGE_SIZE, mImageSizeControl); 
	DDX_Control(pDX, IDC_WAIT_TIME_SPIN, mWaitTimeSpin); 
	DDX_Control(pDX, IDC_PACKET_SIZE_SPIN, mPacketSizeSpin); 
	DDX_Control(pDX, IDC_IMAGE_SIZE_SPIN, mImageSizeSpin); 
	DDX_Text(pDX, IDC_FIRST_PACKET_TIMEOUT, mFirstPacketTimeout); 
	DDX_Text(pDX, IDC_IMAGE_SIZE, mImageSize); 
	DDV_MinMaxUInt(pDX, mImageSize, 32, 2147483647); 
	DDX_CBIndex(pDX, IDC_LINK_TYPE, mLinkType); 
	DDX_Text(pDX, IDC_PACKET_TIMEOUT, mPacketTimeout); 
	DDX_Text(pDX, IDC_REQUEST_TIMEOUT, mRequestTimeout); 
	DDX_Text(pDX, IDC_PACKET_SIZE, mPacketSize); 
	DDV_MinMaxUInt(pDX, mPacketSize, 32, 16224); 
	DDX_Text(pDX, IDC_WAIT_TIME, mMaxTime); 
	DDV_MinMaxUInt(pDX, mMaxTime, 1, 2147483647); 
	DDX_Check(pDX, IDC_LINE_SCAN, mLineScan); 
	DDX_Text(pDX, IDC_LINE_COUNT, mLineCount); 
	DDV_MinMaxUInt(pDX, mLineCount, 1, 16383); 
	//}}AFX_DATA_MAP 
 
    if ( pDX->m_bSaveAndValidate ) 
    { 
        pDX->PrepareEditCtrl( IDC_IMAGE_SIZE ); 
        if ( mImageSize % 4 ) 
        { 
            MessageBox( "Image size must be a multiple of 4!" ); 
            pDX->Fail(); 
        } 
 
        pDX->PrepareEditCtrl( IDC_PACKET_SIZE ); 
        if ( mPacketSize % 32 ) 
        { 
            MessageBox( "Packet size must be a multiple of 32!" ); 
            pDX->Fail(); 
        } 
    } 
} 
 
 
BEGIN_MESSAGE_MAP(CyTimeoutDialog, CDialog) 
	//{{AFX_MSG_MAP(CyTimeoutDialog) 
	ON_WM_HELPINFO() 
	//}}AFX_MSG_MAP 
 
	ON_EN_CHANGE(IDC_IMAGE_SIZE, OnControlChanged) 
	ON_CBN_SELCHANGE(IDC_LINK_TYPE, OnControlChanged) 
	ON_EN_CHANGE(IDC_WAIT_TIME, OnControlChanged) 
    ON_EN_CHANGE(IDC_PACKET_SIZE, OnControlChanged) 
	ON_BN_CLICKED(IDC_LINE_SCAN, OnControlChanged) 
	ON_EN_CHANGE(IDC_LINE_COUNT, OnControlChanged) 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CyTimeoutDialog message handlers 
 
void CyTimeoutDialog::OnControlChanged()  
{ 
    if ( !mInitialized ) 
        return; 
 
    // get the values from the dialog 
    CString lTemp; 
    mLinkType = mLinkTypeControl.GetCurSel(); 
    mImageSizeControl.GetWindowText( lTemp ); 
    mImageSize = atol( lTemp ); 
    mPacketSizeControl.GetWindowText( lTemp ); 
    mPacketSize = atol( lTemp ); 
    mWaitTimeControl.GetWindowText( lTemp ); 
    mMaxTime = atol( lTemp ); 
    mLineScan = mLineScanControl.GetCheck(); 
    mLineCountControl.GetWindowText( lTemp ); 
    mLineCount = atol( lTemp ); 
    if ( mLineCount < 1 ) 
        mLineCount = 1; 
 
    ComputeTimeouts(); 
 
    mLineCountControl.EnableWindow( mLineScan ); 
    mLineCountText.EnableWindow( mLineScan ); 
 
    // replace the values in the dialog 
    UpdateData( FALSE ); 
} 
 
BOOL CyTimeoutDialog::OnInitDialog()  
{ 
    if ( mImageSize < 32 ) 
        mImageSize = 32; 
    ComputeTimeouts(); 
 
    CDialog::OnInitDialog(); 
	 
	mPacketSizeSpin.SetRange32( 32, 16224 ); 
    mWaitTimeSpin.SetRange32( 1, 2147483647 ); 
    mImageSizeSpin.SetRange32( 32, 2147483647 ); 
    mLineCountSpin.SetRange( 1, 16383 ); 
 
    mLineCountControl.EnableWindow( FALSE ); 
    mLineCountText.EnableWindow( FALSE ); 
 
    // Clear the image size 
    mImageSizeControl.SetWindowText( "" ); 
 
    mInitialized = true; 
 
	return TRUE;  // return TRUE unless you set the focus to a control 
	              // EXCEPTION: OCX Property Pages should return FALSE 
} 
 
 
static DWORD rgmapCHID[] =  
{ 
    IDC_IMAGE_SIZE, HIDC_IMAGE_SIZE, 
 
    IDC_IMAGE_SIZE_SPIN, HIDC_IMAGE_SIZE, 
 
    IDC_LINK_TYPE, HIDC_LINK_TYPE, 
 
    IDC_WAIT_TIME, HIDC_WAIT_TIME, 
    IDC_WAIT_TIME_SPIN, HIDC_WAIT_TIME, 
 
    IDC_PACKET_SIZE, HIDC_PACKET_SIZE, 
 
    IDC_PACKET_SIZE_SPIN, HIDC_PACKET_SIZE, 
 
    IDC_FIRST_PACKET_TIMEOUT, HIDC_FIRST_PACKET_TIMEOUT, 
 
    IDC_PACKET_TIMEOUT, HIDC_PACKET_TIMEOUT, 
 
    IDC_REQUEST_TIMEOUT, HIDC_REQUEST_TIMEOUT, 
 
    0,0 
}; 
 
BOOL CyTimeoutDialog::OnHelpInfo(HELPINFO* pHelpInfo)  
{ 
    return  ::WinHelp( (HWND)pHelpInfo->hItemHandle, 
                       AfxGetApp()->m_pszHelpFilePath, 
                       HELP_WM_HELP, 
                       (DWORD)(LPVOID)rgmapCHID); 
} 
 
 
void CyTimeoutDialog::ComputeTimeouts() 
{ 
    // compute the transfer rate 
    double lRate; 
    if ( mLinkType == 0 ) 
        lRate = 100000000; // 1000 mb/sec 
    else 
        lRate = 10000000; // 10 mb / sec 
 
    // compute the number of packets in an image 
    unsigned long lPacketCount = mImageSize / mPacketSize; 
    lPacketCount += ( mImageSize % mPacketSize ? 1 : 0 ); 
 
    // compute the total transfer time of the image, which is: 
    //      image size / data rate 
    double lTransferTime = (double)mImageSize / lRate; 
    lTransferTime *= 1000; // convert to ms 
 
    // The maximum time to wait for the start of an image is: 
    //      Total time - optimal transfer time. 
    mFirstPacketTimeout = (unsigned int)( (double)mMaxTime - lTransferTime ); 
 
    // The maximum time to wait in between packet is: 
    //      the transfer time / packet count; 
    mPacketTimeout = (unsigned int)( (double)mMaxTime / (double) lPacketCount ); 
 
    // In line scan mode, each line can be in a different packet, therefore 
    // the time to wait for other packets is higher that in area scan 
    if ( mLineScan ) 
    { 
        // compute the number of lines per packet 
        unsigned long lBytesPerLine = mImageSize / mLineCount; 
        double lLinesPerPacket = mPacketSize / (double) lBytesPerLine; 
 
        mPacketTimeout = (unsigned int)( (double)mPacketTimeout * lLinesPerPacket ); 
    } 
 
    // For fast ethernet, multiply that packet time by 10, to give it a chance 
    if ( mLinkType == 1 ) 
        mPacketTimeout *= 10; 
 
    // Make sure that the packet TO is 20, otherwise we may get timeouts that 
    // are lower than the transfer time.  Since packet time out dissapears on the 
    // development branch (future versions), then we can use this kludge here. 
    if ( mPacketTimeout < 20 ) 
        mPacketTimeout = 20; 
 
    // The total time to wait for an complete image is: 
    //      The total request time... 
    mRequestTimeout = mMaxTime; 
}