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

📄 zdusbmp_dutdlg.cpp

📁 这个是无线网卡WirelessLAN 测试程序NDIS
💻 CPP
📖 第 1 页 / 共 3 页
字号:
// ZDUSBMP_DUTDlg.cpp : implementation file
//

#include "stdafx.h"
#include "ZDUSBMP_DUT.h"
#include "ZDUSBMP_DUTDlg.h"

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

#include "EXTEEDlg.h"
#include "ParaDlg.h"
#include "InstrumentDlg.h"
#include "CommunicationDlg.h"

#include <math.h>

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CZDUSBMP_DUTDlg dialog

CZDUSBMP_DUTDlg::CZDUSBMP_DUTDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CZDUSBMP_DUTDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CZDUSBMP_DUTDlg)
	m_ShowDetial = TRUE;
	m_Amount = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CZDUSBMP_DUTDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CZDUSBMP_DUTDlg)
	DDX_Control(pDX, IDC_STOP_BUTTON, m_StopButt);
	DDX_Control(pDX, IDC_LIST1, m_StateList);
	DDX_Control(pDX, IDC_START_BUTTON, m_StartButt);
	DDX_Control(pDX, IDC_COMM_BUTTON, m_CommButt);
	DDX_Control(pDX, IDC_PARAMETER_BUTTON, m_ParametersButt);
	DDX_Control(pDX, IDC_INSTRUMENT_BUTTON, m_InstrumentButt);
	DDX_Control(pDX, IDC_VIEW_BUTTON, m_ViewButt);
	DDX_Control(pDX, IDC_MSCOMM1, m_MSComCtrl);
	DDX_Check(pDX, IDC_SHOW_DETIAL_CHECK, m_ShowDetial);
	DDX_Text(pDX, IDC_AMOUNT, m_Amount);
	DDV_MaxChars(pDX, m_Amount, 16);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CZDUSBMP_DUTDlg, CDialog)
	//{{AFX_MSG_MAP(CZDUSBMP_DUTDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_OPENFILE_BUTTON, OnOpenfileButton)
	ON_BN_CLICKED(IDC_VIEW_BUTTON, OnViewButton)
	ON_BN_CLICKED(IDC_PARAMETER_BUTTON, OnParameterButton)
	ON_WM_CLOSE()
	ON_BN_CLICKED(IDC_EXIT, OnExit)
	ON_BN_CLICKED(IDC_INSTRUMENT_BUTTON, OnInstrumentButton)
	ON_BN_CLICKED(IDC_COMM_BUTTON, OnCommButton)
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_START_BUTTON, OnStartButton)
	ON_BN_CLICKED(IDC_STOP_BUTTON, OnStopButton)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CZDUSBMP_DUTDlg message handlers

BOOL CZDUSBMP_DUTDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	mE2promCtrl.ClearCurrData(4);

	bComPortPresent = FALSE;
	bInstrumentPresent = FALSE;

	///initial COM port
 	m_MSComCtrl.SetCommPort(mCommuCtrl.ConnectPort+1); // port settings start at 1
	m_MSComCtrl.SetSettings(_T(COM_PARA));

	UpdateData(FALSE);

	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CZDUSBMP_DUTDlg::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 CZDUSBMP_DUTDlg::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 CZDUSBMP_DUTDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

BOOL CZDUSBMP_DUTDlg::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	if (pMsg->message == WM_KEYDOWN)
	{	
		if (pMsg->wParam == 0x1B)//Esc
			return true;
		if (pMsg->wParam == 0x0F)//Enter
			return true;
	}
	
	return CDialog::PreTranslateMessage(pMsg);
}

void CZDUSBMP_DUTDlg::PumpMessages()
{
    MSG msg;
    // Handle dialog messages
    while(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
    {
      if(!IsDialogMessage(&msg))
      {
        TranslateMessage(&msg);
        DispatchMessage(&msg);  
      }
    }
}

void CZDUSBMP_DUTDlg::OnOpenfileButton() 
{
	// TODO: Add your control notification handler code here
	CFile	EEBinFile;
	char	csFileName[_MAX_PATH];
	CString	sEEPROMBinFile;
	int		nFileLength;
	char	szBuffer[512];

	//Create open file dialog
	CFileDialog EE_OpenFile(TRUE);
	CString strFiles;

	strFiles += "BIN Files (*.bin)";
	strFiles += (TCHAR)'\0';   // next string please
	strFiles += _T("*.bin");
	strFiles += (TCHAR)'\0';
	EE_OpenFile.m_ofn.nMaxCustFilter++;
	EE_OpenFile.m_ofn.lpstrFilter = strFiles;

	if (EE_OpenFile.DoModal() == IDOK)
		sEEPROMBinFile = EE_OpenFile.GetPathName();
	else return;

	sprintf(csFileName, sEEPROMBinFile);

	if(EEBinFile.Open(csFileName, CFile::modeRead | CFile::shareDenyWrite) == 0) {
		sprintf(szBuffer, "Can't open file \"%s\"!!!",  csFileName);
		AfxMessageBox(szBuffer);
		return;
	}

	nFileLength = EEBinFile.GetLength();
	if(nFileLength > MAX_USB_EEPROM_SIZE) {
		nFileLength = MAX_USB_EEPROM_SIZE;
	}
	EEBinFile.Read(mE2promCtrl.pDLTempBuf, (UINT)nFileLength);
	EEBinFile.Close();

	//buffer has contain all data of EEPROM
	mE2promCtrl.bOpenFile = true;

	//enable button
	m_ViewButt.EnableWindow(TRUE);
//	m_InstrumentButt.EnableWindow(TRUE);
//	m_ParametersButt.EnableWindow(TRUE);
//	m_CommButt.EnableWindow(TRUE);
	m_StartButt.EnableWindow(TRUE);

	//write into the current data
	mE2promCtrl.WriteBuffToCurrData(0, &mE2promCtrl.pDLTempBuf[EE_MAC_ADDRESS]);
	mE2promCtrl.WriteBuffToCurrData(1, &mE2promCtrl.pDLTempBuf[EE_SERIAL_NUMBER_ADDRESS]);

	ProcedureState = STATE_IDLE;
	bComPortPresent = FALSE;
	bInstrumentPresent = FALSE;
}

void CZDUSBMP_DUTDlg::OnViewButton() 
{
	// TODO: Add your control notification handler code here
	CEXTEEDlg* pClientDlg = new CEXTEEDlg;

	pClientDlg->pParent = this;
	pClientDlg->DoModal();

	delete pClientDlg;
}

void CZDUSBMP_DUTDlg::OnParameterButton() 
{
	// TODO: Add your control notification handler code here
	CParaDlg* pClientDlg = new CParaDlg;

	pClientDlg->pParent = this;
	pClientDlg->DoModal();

	delete pClientDlg;
}

void CZDUSBMP_DUTDlg::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	TRACE("Close windows.\n");

	if (bComPortPresent){
		//clear data buffer for transmit
		mCommuCtrl.SetHandle(CMD_CLASS_BINDWITH);
		mCommuCtrl.SetBindwithCmd(CMD_BINDWITH_QUEST_OFFLINE);

		Sleep(300);

		//Close COM port
		if (m_MSComCtrl.GetPortOpen()){		
			m_MSComCtrl.SetPortOpen(FALSE);
		}
	}

	if (bInstrumentPresent){
		mGPIBCtrl.OffLine();
	}

	AdapterCtrl.Test_SetNormalMode(	&AdapterCtrl.pAdapterInfo[0] );

	CDialog::OnClose();
}

void CZDUSBMP_DUTDlg::OnExit() 
{
	// TODO: Add your control notification handler code here
	OnClose();
	this->OnCancel();
}

void CZDUSBMP_DUTDlg::OnInstrumentButton() 
{
	// TODO: Add your control notification handler code here
	CInstrumentDlg* pClientDlg = new CInstrumentDlg;

	pClientDlg->pParent = this;
	pClientDlg->DoModal();

	delete pClientDlg;
}

void CZDUSBMP_DUTDlg::OnCommButton() 
{
	// TODO: Add your control notification handler code here
	CCommunicationDlg* pClientDlg = new CCommunicationDlg;

	pClientDlg->pParent = this;
	pClientDlg->DoModal();

	delete pClientDlg;
}

VOID CZDUSBMP_DUTDlg::SendByteToCOMPort(char Buff[])
{	
	LPWSTR pchData = new WCHAR[1];
	VARIANT TX_var;

	MultiByteToWideChar(CP_ACP, 0, Buff, 1, pchData, 1);

	TX_var.vt = VT_BSTR;
	TX_var.bstrVal = ::SysAllocStringLen(pchData,1);

	// Send data to comm port.
	m_MSComCtrl.SetOutput(TX_var);

	// Wait for the transmit buffer to empty.
	while (m_MSComCtrl.GetOutBufferCount() > 0) 
		PumpMessages();

	SysFreeString(TX_var.bstrVal);

	delete []pchData;
}

VOID CZDUSBMP_DUTDlg::ReceiverByteFromCOMPort(char *Buff)
{
	VARIANT RX_var;

	RX_var = m_MSComCtrl.GetInput();
	
	WideCharToMultiByte(CP_ACP, 0, RX_var.bstrVal, 25, Buff, 25,NULL, NULL);
}

BEGIN_EVENTSINK_MAP(CZDUSBMP_DUTDlg, CDialog)
    //{{AFX_EVENTSINK_MAP(CZDUSBMP_DUTDlg)
	ON_EVENT(CZDUSBMP_DUTDlg, IDC_MSCOMM1, 1 /* OnComm */, OnOnCommMscomm1, VTS_NONE)
	//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()

void CZDUSBMP_DUTDlg::OnOnCommMscomm1() 
{
	// TODO: Add your control notification handler code here
	switch(m_MSComCtrl.GetCommEvent()){
 		case 1: //comEvSend
 			break;
 
 		case 2:	//comEvReceive
			mCommuCtrl.ClearReceiverBuff();
			ReceiverByteFromCOMPort(mCommuCtrl.InBuff);
			switch (mCommuCtrl.InBuff[1]){
			case CMD_CLASS_SEND:
				mCommuCtrl.ClearSendCmd();
				mCommuCtrl.GetSendCmd(&cTmpCmd, &dTmpCh, &dTmpPower, &dTmpAnt, &dwTmpInterval, &dwTmpLength, &dwTmpTXAmount);
				if(!mCommuCtrl.CheckSendCmd(cTmpCmd, dTmpCh, dTmpPower, dTmpAnt, dwTmpInterval, dwTmpLength, dwTmpTXAmount)){
					ProcedureState = STATE_FAIL_RESEND;
					mCommuCtrl.dTimes++;
					break;
				}
				if (!mCommuCtrl.CheckHandle(mCommuCtrl.mSendCmd.mHand)){
					ProcedureState = STATE_FAIL_RESEND;
					mCommuCtrl.dTimes++;
					break;
				}

				ProcedureState = STATE_RECEIVER_COMPLETE;
				mCommuCtrl.dTimes=0;
				break;

			case CMD_CLASS_REPLY:
				mCommuCtrl.ClearReplyCmd();
				mCommuCtrl.GetReplyCmd(&cTmpResult, &cTmpValue);
				if (!mCommuCtrl.CheckHandle(mCommuCtrl.mReplyCmd.mHand)){
					ProcedureState = STATE_FAIL_RESEND;
					mCommuCtrl.dTimes++;
					break;
				}
				if(!mCommuCtrl.CheckReplyCmd(cTmpResult, cTmpValue)){
					ProcedureState = STATE_FAIL_RESEND;
					mCommuCtrl.dTimes++;
					break;
				}
				
				ProcedureState = STATE_RECEIVER_COMPLETE;
				mCommuCtrl.dTimes=0;
				break;

			case CMD_CLASS_BINDWITH:
				mCommuCtrl.ClearBindwithCmd();
				mCommuCtrl.GetBindwithCmd(&cTmpQue);
				if (!mCommuCtrl.CheckHandle(mCommuCtrl.mBindwithCmd.mHand)){
					ProcedureState = STATE_FAIL_RESEND;
					mCommuCtrl.dTimes++;
					break;
				}
				if(!mCommuCtrl.CheckBindwithCmd(cTmpQue)){
					ProcedureState = STATE_FAIL_RESEND;
					mCommuCtrl.dTimes++;
					break;
				}
				
				ProcedureState = STATE_RECEIVER_COMPLETE;
				mCommuCtrl.dTimes=0;
				break;

			default:
					ProcedureState = STATE_FAIL_RESEND;
					mCommuCtrl.dTimes++;
					break;
			}

			if (mCommuCtrl.dTimes >= TIMES){
				ProcedureState = STATE_OVERTIMES;
			}

			break;
	
	}
}


void CZDUSBMP_DUTDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	CString c;

	TRACE(_T("OnTimer\n"));

	switch (nIDEvent){
	case 1001:
		KillTimer(1001);
		ProcedureState = STATE_TIMEOUT;
		break;
	case 2001: //TX packets
		TX_Total = ZDTxGetPacketSent(m_htx);

		if (TX_Total >= mParameterCtrl.mTXPackageParameter.TXAmount){ 
			TRXPackFinish = true;
			KillTimer(2001);
		}

		break;

	case 2002: //RX packets
		AdapterCtrl.GetNICAdapterTally(&AdapterCtrl.pAdapterInfo[0], &DisplayTallyStruct);

		//DisplayTallyStruct.rxPLCPCRCErrCnt -= StartTallyStruct.rxPLCPCRCErrCnt;		
        DisplayTallyStruct.rxCRC32ErrCnt -= StartTallyStruct.rxCRC32ErrCnt;
		DisplayTallyStruct.rxTotalCnt -= StartTallyStruct.rxTotalCnt;

		RX_Total = DisplayTallyStruct.rxTotalCnt;
		Bad = DisplayTallyStruct.rxCRC32ErrCnt/* + DisplayTallyStruct.rxPLCPCRCErrCnt*/;

		//get FER
		if (Bad > 0){ 
			PER = 100 * Bad / RX_Total; //100%
		}

⌨️ 快捷键说明

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