⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 isocmdtab.cpp

📁 基于ARM的应用Source6
💻 CPP
字号:
/*----------------------------------------------------------------------------
 *  Copyright (c) 2001 by National Semiconductor Corporation
 *  National Semiconductor Corporation
 *  2900 Semiconductor Drive
 *  Santa Clara, California 95051
 *
 *  All rights reserved
 *
 *<<<-------------------------------------------------------------------------
 * File Contents:
 *	isoCmdTab.cpp - this class defines Isochronous test GUI tab. The Isochronous tests settings
 *					 are received from the user and are transfered to the IsoFunc class.
 *
 *  Project: USB Demo Application
 *  Author : Yan Nosovitsky
 *  Date   : Dec 2001
 *----------------------------------------------------------------------->>>*/

// isoCmdTab.cpp : implementation file
//

#include "stdafx.h"
#include "Demo.h"
#include "isoCmdTab.h"
#include "USBDriver.h"
#include "IsoFunc.h"
#include <afxtempl.h>

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

/////////////////////////////////////////////////////////////////////////////
// isoCmdTab dialog


isoCmdTab::isoCmdTab(CWnd* pParent /*=NULL*/)
	: CDialog(isoCmdTab::IDD, pParent)
{
	//{{AFX_DATA_INIT(isoCmdTab)
	//}}AFX_DATA_INIT
	isoFunc = new IsoFunc(this);
	isUnderTest = FALSE;
}


void isoCmdTab::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(isoCmdTab)
	DDX_Control(pDX, IDC_LIST_ISO_PIPES, m_pipesList);
	DDX_Control(pDX, IDC_PROGRESS_BAR, m_progressBar);
	DDX_Control(pDX, IDC_LOOP_SIZE_EDIT, m_loopSize);
	DDX_Control(pDX, IDC_HEX_BYTE_EDIT, m_hexByte);
	DDX_Control(pDX, IDC_DATA_SIZE_EDIT, m_dataSize);
	DDX_Control(pDX, IDC_FILE_RADIO, m_fileRadio);
	DDX_Control(pDX, IDC_INCR_RADIO, m_incrRadio);
	DDX_Control(pDX, IDC_FILE_NAME, m_fileName);
//	DDX_Control(pDX, IDC_DMA_USE, m_dmaUse);
	DDX_Control(pDX, IDC_BUTTON_ISO_GO, m_buttonGo);
	DDX_Control(pDX, IDC_BUTTON_ISO_DET, m_buttonDet);
	DDX_Control(pDX, IDC_BUTTON_BROWSE, m_buttonBrowse);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(isoCmdTab, CDialog)
	//{{AFX_MSG_MAP(isoCmdTab)
	ON_BN_CLICKED(IDC_BUTTON_BROWSE, OnButtonBrowse)
	ON_LBN_SELCHANGE(IDC_LIST_ISO_PIPES, OnSelchangeListIsoPipes)
	ON_BN_CLICKED(IDC_BUTTON_ISO_GO, OnButtonIsoGo)
	ON_BN_CLICKED(IDC_BUTTON_ISO_DET, OnButtonIsoDet)
	ON_BN_CLICKED(IDC_FILE_RADIO, OnFileRadio)
	ON_BN_CLICKED(IDC_INCR_RADIO, OnIncrRadio)
	ON_COMMAND(IDCANCEL, OnCancel)
	ON_COMMAND(IDOK, OnOK)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

void isoCmdTab::UpdatePipes()
{
	int i;
	int numOfPipes =  isoFunc->CheckPipes() ;
	CString pipeDMA;

	if (!isUnderTest)
	{
		/* clean previous pipes and choise*/
		m_pipesList.ResetContent();
//		m_dmaUse.ResetContent();
//		m_dmaUse.AddString(_T("None"));
		for (i = 0; i < numOfPipes; i++)
		{
			m_pipesList.AddString(isoFunc->getPipeInfo(i));
			pipeDMA.Format(_T("Pipe num %d"),i+1);
//			m_dmaUse.AddString(pipeDMA);
		}
//		m_dmaUse.SetCurSel(0);

		EnableLoopbackControl(FALSE);
		EnableOneDirControl(FALSE);
		m_buttonGo.EnableWindow(FALSE);
		m_buttonDet.EnableWindow(FALSE);
//		m_dmaUse.EnableWindow(FALSE);
	}
	else
	{
		/* restore previos choise */

	}
}

void isoCmdTab::EnableLoopbackControl(bool bEnable)
{

	m_fileRadio.EnableWindow(bEnable);
	m_incrRadio.EnableWindow(bEnable);
	if ( !bEnable )
	{
		m_buttonBrowse.EnableWindow(FALSE);
		m_fileName.EnableWindow(FALSE);
		m_loopSize.EnableWindow(FALSE);
	}
	else
	{
		if (m_fileRadio.GetCheck())
		{
			m_fileName.EnableWindow(TRUE);
			m_buttonBrowse.EnableWindow(TRUE);
		}
		else
			m_loopSize.EnableWindow(TRUE);
	}
}

void isoCmdTab::EnableOneDirControl(bool bEnable)
{
	m_dataSize.EnableWindow(bEnable);
	m_hexByte.EnableWindow(bEnable);
}

void isoCmdTab::processStoped()
{
	m_buttonGo.EnableWindow(TRUE);
	m_buttonDet.EnableWindow(TRUE);
	m_pipesList.EnableWindow(TRUE);
	m_progressBar.SetPos(0);
	isUnderTest = FALSE;
}
/////////////////////////////////////////////////////////////////////////////
// isoCmdTab message handlers

void isoCmdTab::OnButtonBrowse() 
{
	CString m_cstrFileName;

	CFileDialog dlg( TRUE,_T("All"),_T("*.*"),
					 OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
					 _T("All Files (*.*)|") );

	if( dlg.DoModal()==IDOK )
	{
		m_cstrFileName = dlg.GetPathName();
		UpdateData(FALSE);
		//ApplyChanges();
	}

	m_fileName.SetWindowText(m_cstrFileName);
	
}

void isoCmdTab::OnSelchangeListIsoPipes() 
{
	int num;
	CArray<int,int> selectedItems;
	USBDriver *curUSBDriver = USBDriver::GetUSBDriver();

	num = m_pipesList.GetSelCount();

	selectedItems.SetSize(num);
	
	m_pipesList.GetSelItems(num,selectedItems.GetData());

	if (num == 1)
	{
		selPipe = selectedItems.GetAt(0);
		EnableLoopbackControl(FALSE);
		EnableOneDirControl(TRUE);
	}
	
	if (num == 2)
	{
		selPipe = -1; /* Loopback test */
		EnableOneDirControl(FALSE);
		EnableLoopbackControl(TRUE);
	}

	m_buttonGo.EnableWindow(TRUE);
	m_buttonDet.EnableWindow(FALSE);
/*	if (curUSBDriver->IsDMAinUSE())
		m_dmaUse.EnableWindow(FALSE);
	else
		m_dmaUse.EnableWindow(TRUE); */
}

void isoCmdTab::OnButtonIsoGo() 
{
	if (!isUnderTest)
	{
		int pipeForDMA = 0 ; //m_dmaUse.GetCurSel();
		if (selPipe == -1)
		{ /* loopback test */
			int dataSize;
			int chunkNum;

			if (m_fileRadio.GetCheck())
			{
				CString fileName;
				CFileFind finder;
				m_fileName.GetWindowText(fileName);
				fileName.TrimLeft();
				fileName.TrimRight();

				if (fileName.IsEmpty())
				{
					MessageBox("Input data file is not specified.","Error",MB_ICONERROR | MB_OK);
					return;
				}
				if (!finder.FindFile(fileName)) 
				{
					/* file not found */
					MessageBox("Data file does not exist.","Error",MB_ICONERROR | MB_OK);
					return;
				}

				finder.FindNextFile();
				dataSize = finder.GetLength();
				
				if (( dataSize > (SIZE_LIM_ONE_DIR_TEST/2))||(dataSize < 1))
				{
					/* file too big */
					MessageBox("Data file size must be between 1 Byte and 10 MBytes.","Error",MB_ICONERROR | MB_OK);
					return;
				}
				
				chunkNum = dataSize/DATA_CHUNK_SIZE;
				if (dataSize%DATA_CHUNK_SIZE)
					chunkNum++;
				m_progressBar.SetRange(0,chunkNum);
				m_progressBar.SetPos(0);
				
				if (!isoFunc->ProcessLoopTestFile(fileName,pipeForDMA))
				{	
					return;
				}
			}
			else
			{
				CString dataSizeStr;

				m_loopSize.GetWindowText(dataSizeStr);
				if (dataSizeStr.IsEmpty())
				{
					MessageBox("Data size is not specified.","Error",MB_ICONERROR | MB_OK);
					return;
				}

				sscanf(dataSizeStr.GetBuffer(dataSizeStr.GetLength()),"%d",&dataSize);

				if ((dataSize > (SIZE_LIM_ONE_DIR_TEST/2))||(dataSize < 1))
				{/* file too big */
					MessageBox("Data size must be an integer between 1 Byte and 10 MBytes.","Error",MB_ICONERROR | MB_OK);
					return;
				}				
				chunkNum = dataSize/DATA_CHUNK_SIZE;
				if (dataSize%DATA_CHUNK_SIZE)
					chunkNum++;
				m_progressBar.SetRange(0,chunkNum);
				m_progressBar.SetPos(0);
				
				if (!isoFunc->ProcessLoopTestData(dataSize,pipeForDMA))
				{	
					return;
				}
			}

		}
		else
		{
			/* one direction test */
			CString dataSizeStr;
			CString byteStr;
			int dataSize;
			int byte;
			int chunkNum;

//			bool DMAuse = (selPipe == pipeForDMA);

			m_dataSize.GetWindowText(dataSizeStr);
			if (dataSizeStr.IsEmpty())
			{
				MessageBox("Data size is not specified.","Error",MB_ICONERROR | MB_OK);
				return;
			}

			m_hexByte.GetWindowText(byteStr);
			if (byteStr.IsEmpty())
			{
				MessageBox("Hex byte is not specified.","Error",MB_ICONERROR | MB_OK);
				return;
			}

			sscanf(dataSizeStr.GetBuffer(dataSizeStr.GetLength()),"%d",&dataSize);


			if ((dataSize > SIZE_LIM_ONE_DIR_TEST)||(dataSize < 1))
			{
			/* size too big */
				MessageBox("Data size must be an integer between 1 Byte and 20 MBytes.","Error",MB_ICONERROR | MB_OK);
				return;
			}

			byteStr.MakeLower();
		
			int i =0;
			for (i = 0; i < byteStr.GetLength(); i++)
				if ((((CString)byteStr[i] < "a")||((CString)byteStr[i] > "f"))&&(((CString)byteStr[i] < "0")||((CString)byteStr[i] > "9")))
				{
					MessageBox("Hex byte must be an integer between 0 and FF","Error",MB_ICONERROR | MB_OK);
					return;
				}

			sscanf(byteStr.GetBuffer(byteStr.GetLength()),"%x",&byte);

			chunkNum = dataSize/DATA_CHUNK_SIZE;
			if (dataSize%DATA_CHUNK_SIZE)
				chunkNum++;

			m_progressBar.SetRange(0,chunkNum);
			m_progressBar.SetPos(0);

			if (!isoFunc->ProcessOneDirTest(selPipe,dataSize,byte,FALSE))
			{	
					return;
			}
		}
		
		m_progressBar.SetPos(0);
//		m_buttonGo.SetWindowText("Stop");
		m_buttonGo.EnableWindow(FALSE);
		m_buttonDet.EnableWindow(FALSE);
		m_pipesList.EnableWindow(FALSE);
		isUnderTest = TRUE;

	}
	else
	{
		/* stop test */
		isoFunc->StopLastProcess();
		m_buttonGo.SetWindowText("GO !");
		m_buttonDet.EnableWindow(TRUE);
		isUnderTest = FALSE;
	}

	
}

void isoCmdTab::OnButtonIsoDet() 
{
	MessageBox((LPCTSTR)isoFunc->GetDetails(),"Isochronous Test",MB_ICONINFORMATION | MB_OK);	
}

void isoCmdTab::OnFileRadio() 
{
	m_loopSize.EnableWindow(FALSE);
	m_fileName.EnableWindow(TRUE);
	m_buttonBrowse.EnableWindow(TRUE);	
}

void isoCmdTab::OnIncrRadio() 
{
	m_fileName.EnableWindow(FALSE);
	m_buttonBrowse.EnableWindow(FALSE);	
	m_loopSize.EnableWindow(TRUE);	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -