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

📄 bulkcmdtab.cpp

📁 国半usbn9604芯片开发办的源码
💻 CPP
字号:
/*----------------------------------------------------------------------------
 *  Copyright (c) 2001 by National Semiconductor Corporation
 *  National Semiconductor Corporation
 *  2900 Semiconductor Drive
 *  Santa Clara, California 95051
 *
 *  All rights reserved
 *
 *<<<-------------------------------------------------------------------------
 * File Contents:
 *	BulkCmdTab.cpp - this class defines Bulk test GUI tab. The Bulk tests settings
 *					 are received from the user and are transfered to the BulkFunc class.
 *
 *  Project: USB Demo Application
 *  Author : Yan Nosovitsky
 *  Date   : Dec 2001
 *----------------------------------------------------------------------->>>*/

// BulkCmdTab.cpp : implementation file
//

#include "stdafx.h"
#include "Demo.h"

#include "BulkCmdTab.h"

#include "USBDriver.h"
#include <afxtempl.h>

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

/////////////////////////////////////////////////////////////////////////////
// BulkCmdTab dialog


BulkCmdTab::BulkCmdTab(CWnd* pParent /*=NULL*/)
	: CDialog(BulkCmdTab::IDD, pParent)
{
	//{{AFX_DATA_INIT(BulkCmdTab)
	//}}AFX_DATA_INIT
	bulkFunc = new BulkFunc(this);
	isUnderTest = FALSE;

}


void BulkCmdTab::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(BulkCmdTab)
	DDX_Control(pDX, IDC_PROGRESS_BULK, m_progressBar);
	DDX_Control(pDX, IDC_IMMED_RADIO, m_immedRadio);
	DDX_Control(pDX, IDC_DEL_RADIO, m_delRadio);
	DDX_Control(pDX, IDC_BUTTON_BULK_GO, m_buttonGo);
	DDX_Control(pDX, IDC_BUTTON_BULK_DET, m_buttonDet);
	DDX_Control(pDX, IDC_BUTTON_BROWSE, m_buttonBrowse);
	DDX_Control(pDX, IDC_FILE_RADIO, m_fileRadio);
	DDX_Control(pDX, IDC_INCR_RADIO, m_incrRadio);
	DDX_Control(pDX, IDC_EDIT_HEX_BYTE, m_hexByte);
	DDX_Control(pDX, IDC_EDIT_LOOP_SIZE, m_loopSize);
	DDX_Control(pDX, IDC_FILE_NAME, m_fileName);
	DDX_Control(pDX, IDC_EDIT_DATA_SIZE, m_dataSize);
	DDX_Control(pDX, IDC_LIST_BULK_PIPES, m_pipesList);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(BulkCmdTab, CDialog)
	//{{AFX_MSG_MAP(BulkCmdTab)
	ON_BN_CLICKED(IDC_BUTTON_BROWSE, OnButtonBrowse)
	ON_LBN_SELCHANGE(IDC_LIST_BULK_PIPES, OnSelchangeListBulkPipes)
	ON_BN_CLICKED(IDC_BUTTON_BULK_GO, OnButtonBulkGo)
	ON_BN_CLICKED(IDC_BUTTON_BULK_DET, OnButtonBulkDet)
	ON_BN_CLICKED(IDC_INCR_RADIO, OnIncrRadio)
	ON_BN_CLICKED(IDC_FILE_RADIO, OnFileRadio)
	ON_COMMAND(IDCANCEL, OnCancel)
	ON_COMMAND(IDOK, OnOK)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

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

	if (!isUnderTest)
	{
		/* clean previous pipes and choise*/
		m_pipesList.ResetContent();

		for (i = 0; i < numOfPipes; i++)
		{
			m_pipesList.AddString(bulkFunc->getPipeInfo(i));
			pipeDMA.Format(_T("Pipe num %d"),i+1);


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

	}
}

void BulkCmdTab::EnableLoopbackControl(bool bEnable)
{
	m_immedRadio.EnableWindow(bEnable );
	m_fileRadio.EnableWindow(bEnable);
	m_delRadio.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 BulkCmdTab::EnableOneDirControl(bool bEnable)
{
	m_dataSize.EnableWindow(bEnable);
	m_hexByte.EnableWindow(bEnable);
}

void BulkCmdTab::processStoped()
{
//	m_buttonGo.SetWindowText("GO !");
	m_buttonGo.EnableWindow(TRUE);
	m_buttonDet.EnableWindow(TRUE);
	m_pipesList.EnableWindow(TRUE);
	m_progressBar.SetPos(0);
	isUnderTest = FALSE;
}
/////////////////////////////////////////////////////////////////////////////
// BulkCmdTab message handlers

void BulkCmdTab::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 BulkCmdTab::OnSelchangeListBulkPipes() 
{
	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);

}



void BulkCmdTab::OnButtonBulkGo() 
{
	if (!isUnderTest)
	{
		int pipeForDMA = 0;
		if (selPipe == -1)
		{ /* loopback test */
			int dataSize;
			int chunkNum;
			LoopbackTest testType = m_immedRadio.GetCheck() ? IMMEDIATE : DELAYED;

			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 ( testType == DELAYED)
				{
					if (( dataSize > SIZE_LIM_DEL_TEST) || (dataSize < 1))
					{
						/* file too big */
						MessageBox("Data file size must be between 1 Byte and 2 KBytes.","Error",MB_ICONERROR | MB_OK);
						return;
					}
					m_progressBar.SetRange(0,2);
					m_progressBar.SetPos(0);
				}
				else
				{
					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 (!bulkFunc->ProcessLoopTestFile(testType,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 ( testType == DELAYED)
				{
					
					if ((dataSize > SIZE_LIM_DEL_TEST)||(dataSize < 1))
					{
						/* size too big */
						MessageBox("Data size must be an integer between 1 Byte and 2 KBytes.","Error",MB_ICONERROR | MB_OK);
						return;
					}
					m_progressBar.SetRange(0,2);
					m_progressBar.SetPos(0);
				}
				else
				{
					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 (!bulkFunc->ProcessLoopTestData(dataSize,testType,pipeForDMA))
				{	
					return;
				}
			}

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


			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 (!bulkFunc->ProcessOneDirTest(selPipe,dataSize,byte,FALSE))
			{	
					return;
			}
		}
		
		m_progressBar.SetPos(0);
		m_buttonGo.EnableWindow(FALSE);
		m_buttonDet.EnableWindow(FALSE);
		m_pipesList.EnableWindow(FALSE);
		isUnderTest = TRUE;

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

}

void BulkCmdTab::OnButtonBulkDet() 
{
	MessageBox((LPCTSTR)bulkFunc->GetDetails(),"Bulk Test",MB_ICONINFORMATION | MB_OK);	
}

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

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

⌨️ 快捷键说明

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