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

📄 addwritedlg.cpp

📁 一个amccs5933芯片的驱动程序开发源程序和部分文档
💻 CPP
字号:
// AddWriteDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Test3042.h"
#include "AddWriteDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// AddWriteDlg dialog


AddWriteDlg::AddWriteDlg(CWnd* pParent /*=NULL*/)
	: CDialog(AddWriteDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(AddWriteDlg)
	m_EvalWriteData = _T("");
	m_EvalWriteAdd = _T("");
	m_EvalRadioWrite = -1;
	m_EvalRadioWrType = -1;
	m_EvalWriteLoops = 0;
	//}}AFX_DATA_INIT
}


void AddWriteDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(AddWriteDlg)
	DDX_Text(pDX, IDC_WRITE_DATA, m_EvalWriteData);
	DDV_MaxChars(pDX, m_EvalWriteData, 8);
	DDX_Text(pDX, IDC_WRITE_ADD, m_EvalWriteAdd);
	DDV_MaxChars(pDX, m_EvalWriteAdd, 4);
	DDX_Radio(pDX, IDC_WR_8_BIT, m_EvalRadioWrite);
	DDX_Radio(pDX, IDC_WR_SAME, m_EvalRadioWrType);
	DDX_Text(pDX, IDC_WRITE_LOOPS, m_EvalWriteLoops);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(AddWriteDlg, CDialog)
	//{{AFX_MSG_MAP(AddWriteDlg)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// AddWriteDlg message handlers

BOOL AddWriteDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
//	theApp.Out("In Write Dlg Init part.\n");	
	
	UpdateData(FALSE);	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void AddWriteDlg::OnOK() 
{
	DWORD lastAdd, maxData;
	UpdateData(TRUE);

	if (m_EvalWriteLoops < 1 || m_EvalWriteLoops > 1000000)
	{
		MessageBox ("The number of writes has to be a number between 1 and 1000000.");
		return;
	}

	CString tmpStr("Out of range:\n\tData range: 0-");
	CString aString("Out of range:\n\tAddress range: 0-");
	CString aStr2("The 'Number of Writes' must be 1 for address range 0x0000 to 0x3fff when 'Consecutive' write type is selected.");
	switch (m_EvalRadioWrite)
	{
	case 0:
		tmpStr += "ff";
		maxData = 0xff;
		aString += "7fff.";
		lastAdd = 0x7fff;
		break;
	case 1:
		tmpStr += "ffff";
		maxData = 0xffff;
		aString += "7ffe.";
		lastAdd = 0x7ffe;
		break;
	case 2:
		tmpStr += "ffffffff";
		maxData = 0xffffffff;
		aString += "7ffc.";
		lastAdd = 0x7ffc;
		break;
	default:
		MessageBox("Invalid word size. Please select a valid word size.");
		return;
		break;
	}

//	theApp.Out("Before Address: string: %s\tint:%x\n",m_EvalWriteAdd, m_HexWriteAdd);
//	theApp.Out("Before Data: string: %s\tint:%x\n",m_EvalWriteData, m_HexWriteData);

	if (hex2dec2(m_HexWriteAdd, m_EvalWriteAdd) == false 
		|| hex2dec2(m_HexWriteData, m_EvalWriteData) == false)
	{
		MessageBox("Invalid input:\n\tPlease enter valid Hex values.");
		return;
	}
	else
	{
//		theApp.Out("After Address: string: %s\tint:%x\n",m_EvalWriteAdd, m_HexWriteAdd);
//		theApp.Out("After Data: string: %s\tint:%x\n",m_EvalWriteData, m_HexWriteData);
		if (m_HexWriteAdd < 0 || m_HexWriteAdd > lastAdd)
		{
			MessageBox(aString);
			return;
		}
		else if (m_EvalRadioWrType == 1 && m_HexWriteAdd < 0x4000 && m_EvalWriteLoops != 1)
		{
			MessageBox(aStr2);
			return;
		}
		if (m_HexWriteData < 0 || m_HexWriteData > maxData)
		{
			MessageBox(tmpStr);
			return;
		}
	}
	CDialog::OnOK();
}

// Function converts valid hex input string to an integer.
// Valid input is a string of length 8 with values 0-9 or a-f or A-F.
bool AddWriteDlg::hex2dec2(DWORD & outInt, CString inStr)
{
	char tmp;
	DWORD tmpLong = 0, result = 0;
//	theApp.Out("String: %s\tInt init:%x\n",inStr, outInt);
	inStr.MakeLower();	// make all letters lowercase
	inStr.TrimRight();	// get rid of whitespaces
	inStr.TrimLeft();	// get rid of whitespaces

	result = 0;
	for (int i=0; i < inStr.GetLength(); ++i)
	{
		tmpLong = 0;
		tmp = inStr[i];
		switch( tmp )
		{	//NOTE: For some reason, atol() doesn't work properly on some
			// machines. So, I manually did the case statement.
		case '0':	tmpLong = 0;break;
		case '1':	tmpLong = 1;break;
		case '2':	tmpLong = 2;break;
		case '3':	tmpLong = 3;break;
		case '4':	tmpLong = 4;break;
		case '5':	tmpLong = 5;break;
		case '6':	tmpLong = 6;break;
		case '7':	tmpLong = 7;break;
		case '8':	tmpLong = 8;break;
		case '9':	tmpLong = 9;break;
		case 'a':	tmpLong = 10;break;
		case 'b':	tmpLong = 11;break;
		case 'c':	tmpLong = 12;break;
		case 'd':	tmpLong = 13;break;
		case 'e':	tmpLong = 14;break;
		case 'f':	tmpLong = 15;break;
		default:	return false;break;
		}
		result = result + tmpLong;
		if (i < (inStr.GetLength() - 1)) // no need to multiply on the last test
			result = result * 16;
	}
	outInt = result;
//	theApp.Out("String: %s\tInt init:%x\n",inStr, outInt);
	return true;
}
#if 0
{
	char tmp;
	DWORD tmpLong = 0, result = 0;
	theApp.Out("String: %s\tInt init:%x\n",inStr, outInt);
//	theApp.Out("a gf\n");
	inStr.MakeLower();	// make all letters lowercase
	inStr.TrimRight();	// get rid of whitespaces
	inStr.TrimLeft();	// get rid of whitespaces
	for (int i=0; i < inStr.GetLength(); ++i)
	{
		if (inStr[i] != '0')
		{
			tmp = inStr[i];
			tmpLong = atol(&tmp);
			if (tmpLong == 0)	// inStr[i] is not a digit
			{
				switch( tmp )
				{
				case 'a':
					tmpLong = 10;
					break;
				case 'b':
					tmpLong = 11;
					break;
				case 'c':
					tmpLong = 12;
					break;
				case 'd':
					tmpLong = 13;
					break;
				case 'e':
					tmpLong = 14;
					break;
				case 'f':
					tmpLong = 15;
					break;
				default:
					return false;
					break;
				}
			}

			result = result + tmpLong;
		}	
		// else if inStr(i) is a zero, don't add anything to result
		if (i < (inStr.GetLength() - 1)) // no need to multiply on the last test
			result = result * 16;
	}
	outInt = result;
//	theApp.Out("String: %s\tInt init:%x\n",inStr, outInt);
//	theApp.Out("");
	return true;
}
#endif

⌨️ 快捷键说明

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