/*****************************************************************************
* Copyright (c) 1990-98 Digi International Inc., All Rights Reserved
* 
* This software contains proprietary and confidential information of Digi
* International Inc.  By accepting transfer of this copy, Recipient agrees
* to retain this software in confidence, to prevent disclosure to others,
* and to make no use of this software other than that for which it was
* delivered.  This is an unpublished copyrighted work of Digi International
* Inc.  Except as permitted by federal law, 17 USC 117, copying is strictly
* prohibited.
* 
* Restricted Rights Legend
*
* Use, duplication, or disclosure by the Government is subject to
* restrictions set forth in sub-paragraph (c)(1)(ii) of The Rights in
* Technical Data and Computer Software clause at DFARS 252.227-7031 or
* subparagraphs (c)(1) and (2) of the Commercial Computer Software -
* Restricted Rights at 48 CFR 52.227-19, as applicable.
*
* Digi International Inc. 11001 Bren Road East, Minnetonka, MN 55343
*
*****************************************************************************/


// PropAdvCSU.cpp : implementation file
//

#include "stdafx.h"
#include "PropAdvCSU.h"
#include "Helpers.h"

#include "dxbtypes.h"
#include "mgmthlc.h"

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

/////////////////////////////////////////////////////////////////////////////
// CPropAdvCSU property page

IMPLEMENT_DYNCREATE(CPropAdvCSU, CPropertyPage)

CPropAdvCSU::CPropAdvCSU() : CPropertyPage(CPropAdvCSU::IDD)
{
	//{{AFX_DATA_INIT(CPropAdvCSU)
	m_fUseFixedChannelMapping = FALSE;
	//}}AFX_DATA_INIT
}

CPropAdvCSU::~CPropAdvCSU()
{
}

void CPropAdvCSU::SetClocking(DWORD const dwClocking)
{
	m_fUseFixedChannelMapping = ((dwClocking & TIMING_CHAN_MAPPING) == TIMING_CHAN_MAPPING);
	m_dwClocking = (dwClocking & ~TIMING_CHAN_MAPPING);
}

void CPropAdvCSU::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPropAdvCSU)
	DDX_Control(pDX, IDC_AdvCSUJitter, m_ctrlJitter);
	DDX_Control(pDX, IDC_AdvCSUClocking, m_ctrlClocking);
	DDX_Check(pDX, IDC_AdvCSUFixedChannelMapping, m_fUseFixedChannelMapping);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CPropAdvCSU, CPropertyPage)
	//{{AFX_MSG_MAP(CPropAdvCSU)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPropAdvCSU message handlers

static DWORD const g_adwJitterValues[] =
{
   JITTER_AUTO,
   JITTER_RX,  
   JITTER_TX,  
   JITTER_NONE,
};

static DWORD const g_adwClockingValues[] =
{
   TIMING_LOOP,
   TIMING_LOCAL,
   // TIMING_MVIP,
};

void CPropAdvCSU::OnOK() 
{
   UpdateData();

   m_dwJitter = g_adwJitterValues[m_ctrlJitter.GetCurSel()];
   m_dwClocking = g_adwClockingValues[m_ctrlClocking.GetCurSel()];

	if (m_fUseFixedChannelMapping)
	{
		m_dwClocking |= TIMING_CHAN_MAPPING;
	}

	CPropertyPage::OnOK();
}

BOOL CPropAdvCSU::OnInitDialog() 
{
	CPropertyPage::OnInitDialog();
	
   SetCurSelFromValue(m_ctrlJitter, m_dwJitter, g_adwJitterValues, ElementCount(g_adwJitterValues));
   SetCurSelFromValue(m_ctrlClocking, m_dwClocking, g_adwClockingValues, ElementCount(g_adwClockingValues));

   UpdateData(FALSE);

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
