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

📄 amccpci3windlg.cpp

📁 The PCI Local bus concept was developed to break the PC data I/O bottleneck and clearly opens the d
💻 CPP
📖 第 1 页 / 共 2 页
字号:
			}
		}
	}
}

void CAMCCPCI3WinDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CAMCCPCI3WinDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CAMCCPCI3WinDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CAMCCPCI3WinDlg::DelayWait( DWORD waittime )
{

	MSG msg;
	DWORD StartTime;

	StartTime = GetTickCount();
	while( (GetTickCount() - StartTime) < waittime ) {
		if( ::PeekMessage( &msg, NULL,0,0,PM_REMOVE ) ) {
			::TranslateMessage( &msg );
			::DispatchMessage( &msg );
		}
	}

}

void CAMCCPCI3WinDlg::BroadcastUpdateDisplay(void)
{

	int i;

	for( i=0 ; i < NUM_BOARDS ; i++ ) {
	}
}

void CAMCCPCI3WinDlg::SetBoards( void )
{

	int i;
	INT32  ret;
	UINT32 rdata[128];
	UINT32 data1[NUM_BOARDS];
	UINT32 data2[NUM_BOARDS];
	char sztemp[128];

	max_boards = 0;

	m_Combo_BOARD_SELECT.ResetContent();

	for( i=0 ; i < NUM_BOARDS ; i++ ) {

		gbl_vid[i] = 0;
		gbl_did[i] = 0;

		// Reads from config space
		ret = Sample_ReadConfigurationSpace( i, 16, 0, (UINT32 *)&rdata );
		//TestError( ret );

		if( ret == e_Err_NoError ) {
			gbl_vid[max_boards] = rdata[0] & 0x00ffff;
			gbl_did[max_boards] = (rdata[0] >> 16) & 0x0ffff;
			gbl_svid[max_boards] = rdata[11] & 0x00ffff;
			gbl_sdid[max_boards] = (rdata[11] >> 16) & 0x0ffff;
			max_boards++;
		}

	}

	if( !max_boards ) {
		GetWindowText( sztemp, sizeof( sztemp ) );
		MessageBox( "No PCI Boards Found!",sztemp,MB_OK | MB_ICONEXCLAMATION );
		cur_board = -1;
	}
	else {
		for( i=0 ; i < max_boards ; i++ ) {
			sprintf( sztemp,"%d (VID %04x, DID %04x)", i, gbl_vid[i], gbl_did[i] );
			m_Combo_BOARD_SELECT.AddString( sztemp );
		}
		m_Combo_BOARD_SELECT.SetCurSel( 0 );
		cur_board = 0;
	}

}

int CAMCCPCI3WinDlg::atoh( char *str )
{

	int value;

	value = 0;
	while( *str != 0 ) {
		if( *str == ',' )
			break;
		if( *str >= '0' && *str <= '9' ) {
			value = (value * 16) + (*str - '0');
		}
		else {
			if( *str >= 'a' && *str <= 'f' ) {
				value = (value * 16) + (*str - 'a' + 10);
			}
			else {
				if( *str >= 'A' && *str <= 'F' ) {
					value = (value * 16) + (*str - 'A' + 10);
				}
				else
					return -1;
			}
		}
		str++;
	}

	return value;
}

//-----------------------------------------------------------------
// ConvertNumberToString
//
// This will convert a value based on the active number base.
//-----------------------------------------------------------------
int CAMCCPCI3WinDlg::ConvertStringToNumber( int base, char *string )
{

	int value;

	if( string[0] == '\'' ) {
		return (int)string[1];
	}

	switch( base ) {
	default:
	case 16:
		value = atoh( string );
		break;
	case 10:
		value = atoi( string );
		break;
	case 2:
		value = 0;
		while( 1 ) {
			if( *string == '1' )
				value = (value << 1) | 1;
			else {
				if( *string == '0' )
					value = value << 1;
				else
					if( *string != ' ' )
						break;
			}
			string++;
		}
		break;
	}

	return value;

}

//-----------------------------------------------------------------
// ConvertNumberToString
//
// This will convert a value based on the active number base.
//-----------------------------------------------------------------
void CAMCCPCI3WinDlg::ConvertNumberToString( unsigned short number, unsigned short count, int base, char *string )
{

	int i;
	unsigned short mask;

	switch( base ) {
	default:
	case 16:
		if( count == 0 )
			wsprintf(string, "%x", number);
		else {
			if( count > 12 )
				wsprintf(string, "%04x", number);
			else {
				if( count > 8 )
					wsprintf(string, "%03x", number);
				else {
					if( count > 4 )
						wsprintf(string, "%02x", number);
					else
						wsprintf(string, "%01x", number);
				}
			}
		}
		break;
	case 10:
		if( count == 0 )
			wsprintf(string, "%u", number);
		else {
			if( count > 12 )
				wsprintf(string, "%05u", number);
			else {
				if( count > 8 )
					wsprintf(string, "%04u", number);
				else {
					if( count > 4 )
						wsprintf(string, "%03u", number);
					else {
						if( count > 3 )
							wsprintf(string, "%02u", number);
						else
							wsprintf(string, "%01u", number);
					}
				}
			}
		}
		break;
	case 2:
		if( count == 0 )	// No upper zero's does not work here - Set to 8 data bits
			count = 8;
		string[0] = 0;
		mask = 1 << (count-1);
		for( i=0 ; i < count ; i++ ) {
			if( (number & mask) != 0 ) 
				strcat( string,"1" );
			else
				strcat( string,"0" );
			if( count > 8 && i == 7 )
				strcat( string," " );
			number = number << 1;
		}
		break;
	}

}

void CAMCCPCI3WinDlg::TestError( UINT32 error_code )
{

	int i;
	bool found;
	char head[128];

	switch( error_code ) {
	case e_Err_NoError:
		break;
	default:
		found = FALSE;
		for( i=0 ;  ; i++ ) {
			if( ErrorData[i].num == error_code ) {
				found = TRUE;
				break;
			}
			if( ErrorData[i].num <= -1000 )
				break;
		}

		if( found ) {
			sprintf( err_msg,"Error in Operation, Code: %d\n%s (%s,%d)", error_code,
				ErrorData[i].text,ErrorData[i].type,ErrorData[i].num );
		}
		else
			sprintf( err_msg,"Error in Operation, Code: %d", error_code );

		strcpy( head, APP_NAME );
		strcat( head, " - Low Level Error" );
		MessageBox( err_msg,head, MB_OK | MB_ICONSTOP );

		break;
	}
}

void CAMCCPCI3WinDlg::TestErrorString( UINT32 error_code, LPSTR str1, LPSTR str2 )
{

	int i;
	bool found;
	char head[128];

	switch( error_code ) {
	case e_Err_NoError:
		break;
	default:
		found = FALSE;
		for( i=0 ;  ; i++ ) {
			if( ErrorData[i].num == error_code ) {
				found = TRUE;
				break;
			}
			if( ErrorData[i].num <= -1000 )
				break;
		}

		if( found ) {
			sprintf( str1,"Error in Operation, Code: %d\n%s (%s,%d)", error_code,
				ErrorData[i].text,ErrorData[i].type,ErrorData[i].num );
		}
		else
			sprintf( str1,"Error in Operation, Code: %d", error_code );

		strcpy( str2, APP_NAME );
		strcat( str2, " - Low Level Error" );

		break;
	}
}

void CAMCCPCI3WinDlg::OnButtonNvramBuild() 
{
	// TODO: Add your control notification handler code here
	if( pNVRAMBuild[cur_board] )
		return;

	// Create the dialog box
	pNVRAMBuild[cur_board] = new CNVRAMBuild;

	// Display the dialog box as modeless
	pNVRAMBuild[cur_board]->Create(IDD_DIALOG_NVRAM_BUILD, GetDesktopWindow() );

	// Initialize the newly-created object - this _must_ be done first!
	pNVRAMBuild[cur_board]->Initialize(this, cur_board );

	pNVRAMBuild[cur_board]->ShowWindow(SW_SHOW);
	
}

void CAMCCPCI3WinDlg::OnSelchangeComboBoardSelect() 
{
	// TODO: Add your control notification handler code here
	int index;

	index = m_Combo_BOARD_SELECT.GetCurSel();
	m_Combo_BOARD_SELECT.GetLBText( index, (LPTSTR) &err_msg );

	cur_board = index;

}

void CAMCCPCI3WinDlg::OnCancel() 
{
	// TODO: Add extra cleanup here
	ShutDownAll();

	CDialog::OnCancel();
}

void CAMCCPCI3WinDlg::ShutDownAll( void ) 
{

	int i;

	for( i=0 ; i < NUM_BOARDS ; i++ ) {
	}

}

BOOL CAMCCPCI3WinDlg::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class

	// Note: This test stops the Enter key from killing the 
	// application. It causes nothing to happen. There must be a better way!
	if( pMsg->message == 256 && pMsg->wParam == 13 ) {
		return FALSE;
	}
	
	return CDialog::PreTranslateMessage(pMsg);
}

⌨️ 快捷键说明

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