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

📄 dsp51hpidlg.cpp

📁 EADSP5402DEMO的所有资料
💻 CPP
字号:
// Dsp51HPIDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Dsp51HPI.h"
#include "Dsp51HPIDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// 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()

/////////////////////////////////////////////////////////////////////////////
// CDsp51HPIDlg dialog

CDsp51HPIDlg::CDsp51HPIDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CDsp51HPIDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDsp51HPIDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CDsp51HPIDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDsp51HPIDlg)
    DDX_Control(pDX, IDC_PROGRESS, m_Progress);
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CDsp51HPIDlg, CDialog)
	//{{AFX_MSG_MAP(CDsp51HPIDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_FILEOPEN, OnFileOpen)
	ON_BN_CLICKED(IDC_RESTART, OnRestart)
	ON_BN_CLICKED(IDC_CONNECT, OnConnect)
	ON_BN_CLICKED(IDC_LIGHT, OnLight)
	ON_BN_CLICKED(IDC_READHPI, OnReadHpi)
	ON_BN_CLICKED(IDC_READRAM, OnReadRam)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDsp51HPIDlg message handlers

BOOL CDsp51HPIDlg::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
	if(!m_comDev.OpenConnection())
	{
		AfxMessageBox("COM Open Error!");
		return FALSE;
	}

	m_Progress.SetRange(0,100);
	m_Progress.SetStep(1);

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

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

CString strFileName,thisPath;
UINT MyThreadProc(LPVOID pParam) 
{ 
	WinExec("Hex500 "+thisPath+"Boot.cmd "+strFileName, NULL);
	return 0;
} 

void CDsp51HPIDlg::OnFileOpen() 
{
	AfxBeginThread(MyThreadProc,0);
	// TODO: Add your control notification handler code here
	CString strFileName,thisPath;
	static char szFilter[] = "DSP out file format(*.out) |*.out|All file format(*.*) |*.*||";
	CFileDialog OpenDlg( TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_EXPLORER, szFilter, NULL );
	if(OpenDlg.DoModal()==IDOK)
	{
		char path[200];
		strFileName = OpenDlg.GetPathName();
		GetModuleFileName(NULL, path, MAX_PATH);
		thisPath = path;
		thisPath = thisPath.Left(strlen(thisPath)-12);
		
		if(memicmp(OpenDlg.GetFileExt(),"out",3)==0)
		{
			strFileName = strFileName.Left(strlen(strFileName)-strlen(OpenDlg.GetFileName()))+"dsp.hex";

			CStdioFile readfile; 
			CString readstr,dspdata;
			Sleep(50);

			if(readfile.Open(strFileName,CFile::modeRead))
			{
				while(readfile.ReadString(readstr))//逐行查询,至到文件尾
				{
					dspdata+=readstr;
				}
				readfile.Close();
			}
			else
			{
				AfxMessageBox("打开文件失败,请从试!");
				return;
			}

			unsigned char data[5];
			unsigned char hd,ld;
			data[0]='w';
			::WriteCommBlock(m_comDev,data,1);
			Sleep(100);
			CString temp,temp2;
			int adtab;
			for(int i=0;i<(int)strlen(dspdata);i++)
			{
				if(dspdata[i+2]==':')
				{
					i=i+2;
				}
				if(dspdata[i]==':')
				{
					adtab=i;
					i++;
				}
				if(i-adtab==7) i=i+2;
				if(dspdata[i]>'9') hd=dspdata[i]-55;
				else hd=dspdata[i]-48;
				i++;
				if(dspdata[i]>'9') ld=dspdata[i]-55;
				else ld=dspdata[i]-48;
				data[0] = hd*16+ld;
				::WriteCommBlock(m_comDev,data,1);
				int timeout=50000;
				char chBuf;
				while(timeout--)
				{
					if(timeout<5)
					{
						AfxMessageBox("下载失败!");
						return;
					}
					::ReadCommBlock(m_comDev,&chBuf,1);
					if (chBuf == 's') break;
					//else if (chBuf == 'o') return;
				}
				temp.Format("%2X ",data[0]);
				temp2+=temp;
				SetPos(100*(i+1)/(int)strlen(dspdata));
			}
		}
		else
		{
			AfxMessageBox("不能识别的文件格式!");
		}
	}
	else
	{
		AfxMessageBox("文件打开失败,请从试!");
	}
}


void CDsp51HPIDlg::OnRestart() 
{
	// TODO: Add your control notification handler code here
	unsigned char data[1];
	data[0] = 'r';
	::WriteCommBlock(m_comDev,data,1);
}

void CDsp51HPIDlg::OnConnect() 
{
	// TODO: Add your control notification handler code here
	unsigned char data[2];
	data[0] = 'r';
	char chBuf;
	::WriteCommBlock(m_comDev,data,1);
	int timeout=50000;
	while(timeout--)
	{
		if(timeout<5)
		{
			AfxMessageBox("没有连接成功!");
			return;
		}
		::ReadCommBlock(m_comDev,&chBuf,1);
		if (chBuf == 's')
		{
			AfxMessageBox("已经连接成功!");
			break;
		}
	}
}

void CDsp51HPIDlg::OnLight() 
{
	// TODO: Add your control notification handler code here
	unsigned char data[1];
	data[0] = 'l';
	::WriteCommBlock(m_comDev,data,1);
}

void CDsp51HPIDlg::SetPos(int pos)
{
	CString temp;
	m_Progress.SetPos(pos);
	temp.Format("%3d",pos);
	SetDlgItemText(IDC_PRENUM,temp+"%");
}

void CDsp51HPIDlg::OnReadHpi()
{
	unsigned char data[1];
	data[0] = 'i';
	::WriteCommBlock(m_comDev,data,1);

	char inbuf[2];
	::ReadCommBlockEx(m_comDev,inbuf,2,100);
	CString aaa;
	aaa.Format("%X",(inbuf[1]+256)%256);
	SetDlgItemText(IDC_HPI,aaa);
}

void CDsp51HPIDlg::OnReadRam()
{
 	CString str;
	int addr;
	GetDlgItemText(IDC_ADDR,str);
	if(str.GetLength()!=4)
	{
		AfxMessageBox("地址必需为四位十六进制数!");
		return;
	}
	if(str[0]>='0' && str[0]<='9') addr = (str[0]-48)*0x1000;
	if(str[0]>='A' && str[0]<='F') addr = (str[0]-55)*0x1000;
	if(str[0]>='a' && str[0]<='f') addr = (str[0]-87)*0x1000;

	if(str[1]>='0' && str[1]<='9') addr += (str[1]-48)*0x100;
	if(str[1]>='A' && str[1]<='F') addr += (str[1]-55)*0x100;
	if(str[1]>='a' && str[1]<='f') addr += (str[1]-87)*0x100;

	if(str[2]>='0' && str[2]<='9') addr += (str[2]-48)*0x10;
	if(str[2]>='A' && str[2]<='F') addr += (str[2]-55)*0x10;
	if(str[2]>='a' && str[2]<='f') addr += (str[2]-87)*0x10;

	if(str[3]>='0' && str[3]<='9') addr += (str[3]-48);
	if(str[3]>='A' && str[3]<='F') addr += (str[3]-55);
	if(str[3]>='a' && str[3]<='f') addr += (str[3]-87);

	unsigned char data[3];
	data[0] = 'a';
	data[1] = addr/256;
	data[2] = addr%256;
	::WriteCommBlock(m_comDev,data,3);

	char inbuf[5];
	::ReadCommBlockEx(m_comDev,inbuf,5,100);
	CString aaa;
	aaa.Format("%X",((inbuf[3]+256)%256)*256+((inbuf[4]+256)%256));
	SetDlgItemText(IDC_RAM,aaa);
}

⌨️ 快捷键说明

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