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

📄 flashupgraderdlg.cpp

📁 PW芯片方案Flash ROM烧写程序
💻 CPP
📖 第 1 页 / 共 5 页
字号:
//---------------------------------------------------------------------------
// Pixelworks Inc. Company Confidential Strictly Private
//
// $Archive: $
// $Revision: 1.11 $
// $Author: PIX_NT\dennisd $
// $Date: 2006/01/03 21:07:01 $
//
// --------------------------------------------------------------------------
// >>>>>>>>>>>>>>>>>>>>>>>>> COPYRIGHT NOTICE <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// --------------------------------------------------------------------------
// Copyright 1997-2003 (c) Pixelworks Inc.
//
// Pixelworks owns the sole copyright to this software. Under international 
// copyright laws you (1) may not make a copy of this software except for 
// the purposes of maintaining a single archive copy, (2) may not derive
// works herefrom, (3) may not distribute this work to others. These rights 
// are provided for information clarification, other restrictions of rights 
// may apply as well.
//
// This is an unpublished work.
// --------------------------------------------------------------------------
// >>>>>>>>>>>>>>>>>>>>>>>>>>>> WARRANTEE <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
// --------------------------------------------------------------------------
// Pixelworks Inc. MAKES NO WARRANTY OF ANY KIND WITH REGARD TO THE USE OF
// THIS SOFTWARE, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
// THE IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR
// PURPOSE.
// --------------------------------------------------------------------------
//
// FlashUpgraderDlg.cpp : implementation file
//

#include "stdafx.h"
#include "FlashUpgrader.h"
#include "FlashUpgraderDlg.h"
#include "DlgProxy.h"
#include "FileDialogPW.h"

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

CFlashUpgraderDlg *CFlashUpgraderDlg::m_pThis = NULL;
CString g_strFileName;
CWnd* g_pFileLabel;
CWnd* g_pByteLabel;
CWnd* g_pPercentLabel;


static const char lpszReturnedSuccessText[] = { "success" };

typedef struct
{
	HWND	hwnd;
	ccp		title;
} FindWnd;

static bool bSortByNameAsc = FALSE;
static int CALLBACK SortByName(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
    // lParamSort contains a pointer to the list view control.
    // CListCtrl* pListCtrl = (CListCtrl*) lParamSort;
    CHexFileData* pHex1 = (CHexFileData*)lParam1;
    CHexFileData* pHex2 = (CHexFileData*)lParam2;

	int nResult = strcmp(pHex1->m_strName, pHex2->m_strName);

	if (bSortByNameAsc) nResult = -nResult;

	return nResult;
}

static bool bSortByStartAsc = FALSE;
static int CALLBACK SortByStart(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
    // lParamSort contains a pointer to the list view control.
    // CListCtrl* pListCtrl = (CListCtrl*) lParamSort;
    CHexFileData* pHex1 = (CHexFileData*)lParam1;
    CHexFileData* pHex2 = (CHexFileData*)lParam2;

	int nResult = pHex1->GetStart() - pHex2->GetStart();

	if (bSortByStartAsc) nResult = -nResult;

	return nResult;
}

static bool bSortByLengthAsc = FALSE;
static int CALLBACK SortByLength(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
    // lParamSort contains a pointer to the list view control.
    // CListCtrl* pListCtrl = (CListCtrl*) lParamSort;
    CHexFileData* pHex1 = (CHexFileData*)lParam1;
    CHexFileData* pHex2 = (CHexFileData*)lParam2;

	int nResult = pHex1->GetLength() - pHex2->GetLength();

	if (bSortByLengthAsc) nResult = -nResult;

	return nResult;
}

static bool bSortByEndAsc = FALSE;
static int CALLBACK SortByEnd(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
{
    // lParamSort contains a pointer to the list view control.
    // CListCtrl* pListCtrl = (CListCtrl*) lParamSort;
    CHexFileData* pHex1 = (CHexFileData*)lParam1;
    CHexFileData* pHex2 = (CHexFileData*)lParam2;

	int nEnd1 = pHex1->GetStart() + pHex1->GetLength();
	int nEnd2 = pHex2->GetStart() + pHex2->GetLength();
	int nResult = nEnd1 - nEnd2;

	if (bSortByEndAsc) nResult = -nResult;

	return nResult;
}

#define TRANS_COLOR RGB(128,128,128)

int g_nTop = 0;
int g_nLeft = 0;

CALLBACK GatherWndTitles( HWND hwnd, LPARAM lParam )
{
	char	buffer[MAX_PATH];
	GetWindowText( hwnd, buffer, sizeof( buffer ) );
	
	CString Title;
	Title.LoadString(IDS_APP_TITLE);

	FindWnd * fw = (FindWnd *)lParam;
	if( strncmp( buffer, Title, Title.GetLength()) == 0 )
	{
		CStringList* pCS = (CStringList*)lParam;
		pCS->AddTail(buffer);

		RECT WndRect;

		GetWindowRect( hwnd, &WndRect);
		if (WndRect.top > g_nTop)
			g_nTop = WndRect.top;

		if (WndRect.left > g_nLeft)
			g_nLeft = WndRect.left;
	}
	return TRUE;
}

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

/////////////////////////////////////////////////////////////////////////////
// CFlashUpgraderDlg dialog

IMPLEMENT_DYNAMIC(CFlashUpgraderDlg, CDialog);

CFlashUpgraderDlg::CFlashUpgraderDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CFlashUpgraderDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CFlashUpgraderDlg)
	m_bContinuous = FALSE;
	m_strComPort = _T("COM1:");
	m_strConnection = _T("Serial");
	m_strInfFile = _T("");
	m_strFileName = _T("");
	m_strBaudRate = _T("115200");
	m_nResetTime = 0;
	m_strBytes = _T("");
	m_strPercent = _T("");
	m_strStatus = _T("");
	m_bNotify = FALSE;
	m_bResetAfterLastFileLoaded = FALSE;
	m_strDirectory = _T("");
	m_nFlashMode = 0;
	m_chkBinary = FALSE;
	//}}AFX_DATA_INIT

	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

	m_bVerifyOnly = FALSE;
	m_bEraseOnly = FALSE;

	m_pAutoProxy = NULL;

	m_bFirstInstance = TRUE;

	m_bFirstTime = TRUE;

	m_bFlashingInProgress = FALSE;

	m_bCancel = FALSE;

	m_pThis = this;

	m_pComPort = NULL;

	m_bGoMode = FALSE;

	m_pCurHexFile = NULL;

    m_bExitWhenDone = FALSE;
	m_bBrowsed = FALSE;
}

CFlashUpgraderDlg::~CFlashUpgraderDlg()
{
	// If there is an automation proxy for this dialog, set
	//  its back pointer to this dialog to NULL, so it knows
	//  the dialog has been deleted.
	if (m_pAutoProxy != NULL)
		m_pAutoProxy->m_pDialog = NULL;

	if (m_pComPort)
		delete m_pComPort;

	DeleteHexFileData();
}

void CFlashUpgraderDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CFlashUpgraderDlg)
	DDX_Control(pDX, IDC_CHK_RESET, m_butReset);
	DDX_Control(pDX, IDC_CHK_NOTIFY, m_butNotify);
	DDX_Control(pDX, IDC_BUT_LOGO, m_butLogo);
	DDX_Control(pDX, IDC_BITMAP_LOGO, m_bmLogo);
	DDX_Control(pDX, IDC_EDIT_RESETTIME, m_editResetTime);
	DDX_Control(pDX, IDC_PROGRESS, m_ctrlProgress);
	DDX_Control(pDX, ID_HELP, m_butHelp);
	DDX_Control(pDX, IDC_BUT_CLOSE, m_butClose);
	DDX_Control(pDX, IDC_CHK_CONTINUOUS, m_chkContinuous);
	DDX_Control(pDX, IDC_BUT_BROWSE, m_butBrowse);
	DDX_Control(pDX, IDC_BUT_FLASH, m_butFlash);
	DDX_Control(pDX, IDC_LIST_REGIONS, m_listRegions);
	DDX_Control(pDX, IDC_CMB_INFFILE, m_cmbInfFile);
	DDX_Control(pDX, IDC_CMB_CONNECTION, m_cmbConnection);
	DDX_Control(pDX, IDC_CMB_COMPORT, m_cmbComPort);
	DDX_Control(pDX, IDC_CMB_BAUDRATE, m_cmbBaudRate);
	DDX_Check(pDX, IDC_CHK_CONTINUOUS, m_bContinuous);
	DDX_CBString(pDX, IDC_CMB_COMPORT, m_strComPort);
	DDX_CBString(pDX, IDC_CMB_CONNECTION, m_strConnection);
	DDX_CBString(pDX, IDC_CMB_INFFILE, m_strInfFile);
	DDX_Text(pDX, IDC_LABEL_FILENAME, m_strFileName);
	DDX_CBString(pDX, IDC_CMB_BAUDRATE, m_strBaudRate);
	DDX_Text(pDX, IDC_EDIT_RESETTIME, m_nResetTime);
	DDX_Text(pDX, IDC_LABEL_BYTES, m_strBytes);
	DDX_Text(pDX, IDC_LABEL_PERCENT, m_strPercent);
	DDX_Text(pDX, IDC_EDIT_STATUS, m_strStatus);
	DDX_Check(pDX, IDC_CHK_NOTIFY, m_bNotify);
	DDX_Check(pDX, IDC_CHK_RESET, m_bResetAfterLastFileLoaded);
	DDX_Text(pDX, IDC_EDIT_DIRECTORY, m_strDirectory);
	DDX_Radio(pDX, IDC_RADIO_MODE, m_nFlashMode);
	DDX_Check(pDX, IDC_CHK_BINARY, m_chkBinary);
	//}}AFX_DATA_MAP

	if (pDX->m_bSaveAndValidate)
	{
		if (m_strBaudRate.IsEmpty())
		{
			m_nBaudRate = 115200;
		}
		else
		{
			m_nBaudRate = atoi(m_strBaudRate);
		}

		if (m_strComPort.IsEmpty())
		{
			m_nComPort = 0;
		}
		else
		{
			m_nComPort = atoi(m_strComPort.Mid(3));
		}

		//
		// Com port numbers are zero based...
		//
		m_nComPort--;

		if (m_strConnection == "USB")
		{
			//
			// Special case for USB
			//
			m_nComPort = -1;
		}
	}
}

BEGIN_MESSAGE_MAP(CFlashUpgraderDlg, CDialog)
	//{{AFX_MSG_MAP(CFlashUpgraderDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_DESTROY()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_CLOSE()
	ON_CBN_SELCHANGE(IDC_CMB_CONNECTION, OnSelchangeCmbConnection)
	ON_BN_CLICKED(IDC_BUT_BROWSE, OnButBrowse)
	ON_BN_CLICKED(IDC_BUT_FLASH, OnButFlash)
	ON_CBN_SELCHANGE(IDC_CMB_INFFILE, OnSelchangeCmbInffile)
	ON_BN_CLICKED(IDOK, OnCmdEnterKey)
	ON_BN_CLICKED(IDCANCEL, OnButClose)
	ON_CBN_KILLFOCUS(IDC_CMB_INFFILE, OnKillfocusCmbInffile)
	ON_NOTIFY(LVN_COLUMNCLICK, IDC_LIST_REGIONS, OnColumnclickListRegions)
	ON_MESSAGE(DOWNLOAD_COMPLETED_MESSAGE, OnDownloadCompletedMessage)
	ON_BN_CLICKED(IDC_CHK_CONTINUOUS, OnChkContinuous)
	ON_NOTIFY(NM_DBLCLK, IDC_LIST_REGIONS, OnDblclkListRegions)
	ON_NOTIFY(NM_CLICK, IDC_LIST_REGIONS, OnClickListRegions)
	ON_NOTIFY(NM_RCLICK, IDC_LIST_REGIONS, OnRclickListRegions)
	ON_BN_CLICKED(IDC_CHK_NOTIFY, OnChkNotify)
	ON_BN_CLICKED(IDC_CHK_RESET, OnChkReset)
	ON_BN_CLICKED(IDC_RADIO_MODE, OnRadioMode)
	ON_BN_CLICKED(IDC_RADIO_ERASE, OnRadioErase)
	ON_BN_CLICKED(IDC_RADIO_VERIFY, OnRadioVerify)
	ON_BN_CLICKED(IDC_CHK_BINARY, OnChkBinary)
	ON_BN_CLICKED(IDC_BUT_CLOSE, OnButClose)
	ON_MESSAGE(COM_PORT_MESSAGE, OnComPortMessage)
	ON_WM_SHOWWINDOW()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFlashUpgraderDlg message handlers

#define FU_LOGO_FILE		"FlashUpgrader.bmp"

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

	CString strTitle;
	strTitle.LoadString(IDS_APP_TITLE);
	SetWindowText(strTitle);

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

	if (FileExists( FU_LOGO_FILE ))
	{
		m_butLogo.SetPlainRender();
		m_butLogo.SetGraphicAllowScale(TRUE);
		m_butLogo.SetBitmapFile( FU_LOGO_FILE );
		m_bmLogo.ShowWindow( SW_HIDE );
	}
	else
	{
		m_butLogo.ShowWindow( SW_HIDE );
		m_bmLogo.ShowWindow( SW_SHOW );
	}

	// 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);
		}
	}

	m_strFileName = "";

	g_pFileLabel = GetDlgItem(IDC_LABEL_FILENAME);
	g_pByteLabel = GetDlgItem(IDC_LABEL_BYTES);
	g_pPercentLabel = GetDlgItem(IDC_LABEL_PERCENT);

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

	CRect rect;
	m_listRegions.GetClientRect(&rect);
	int nWidth = rect.Width() / 18;

	m_ImageList.Create(16, 16, ILC_COLOR, 4, 4);
	AddBitmap(IDB_FLASH, &m_ImageList, TRANS_COLOR);
	AddBitmap(IDB_EXECUTE, &m_ImageList, TRANS_COLOR);
	AddBitmap(IDB_CONFLICT, &m_ImageList, TRANS_COLOR);
	AddBitmap(IDB_NOGO, &m_ImageList, TRANS_COLOR);
	AddBitmap(IDB_MISSING, &m_ImageList, TRANS_COLOR);
	AddBitmap(IDB_CHECKED, &m_ImageList, TRANS_COLOR);
	AddBitmap(IDB_ERASE, &m_ImageList, TRANS_COLOR);

	m_listRegions.SetImageList(&m_ImageList,  LVSIL_SMALL);

	//m_listRegions.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES);
	m_listRegions.SetExtendedStyle(LVS_EX_FULLROWSELECT);
	//m_listRegions.SetExtendedStyle(LVS_EX_GRIDLINES);
	int nCol = 0;
	m_listRegions.InsertColumn(nCol++, "File", LVCFMT_LEFT, nWidth*6);
	m_listRegions.InsertColumn(nCol++, "Start", LVCFMT_LEFT, nWidth*4);
	m_listRegions.InsertColumn(nCol++, "End", LVCFMT_LEFT, nWidth*4);
	m_listRegions.InsertColumn(nCol++, "Length", LVCFMT_LEFT, (rect.Width()-(nWidth*14)));
	
	m_cmbConnection.AddString("Serial");
#ifdef BUILD_USB_CONFIG
	m_cmbConnection.AddString("USB");
#endif

	for (int i=1; i<26; i++)
	{
		CString strPort;
		strPort.Format("COM%d:", i);
		m_cmbComPort.AddString(strPort);
	}

	m_cmbBaudRate.AddString("19200");
	m_cmbBaudRate.AddString("57600");
  // 115200 doesn't current work with MIPS serial
  // Problem with Tobisha chip
	m_cmbBaudRate.AddString("115200");

	GetInitialConnection();
	GetInitialComPort();
	GetInitialBaudRate();
	GetInitialSwitches();
	
	// Load the default values into the controls...
	UpdateData(FALSE);

	// Get the last filename used from the registry...
	CString strFile;
	CString strPath = pTheApp->m_strLaunchDir+"..\\embedded\\bin\\";
		
	//
	// The strPath parameter is used to fill in the default path in the
	// case where only the filename is provided on the command line.
	//
	if (GetInitialInfFile(strPath, strFile))
	{
		m_cmbInfFile.SetCurSel(GatherInfFiles(strPath, strFile));
		m_strDirectory = strPath;
		UpdateData(FALSE);

		ProcessInfFile();
	}
	
	EnableSerialControls();

	m_editResetTime.EnableWindow(m_bContinuous);

	// Position this instance of the application according to the
	// position of the previous instances.
	if (GetServerList()>1)
	{
		CRect WndRect;
		GetWindowRect(&WndRect);
		g_nLeft += 20;
		g_nTop += 20;

		WndRect.SetRect(g_nLeft, g_nTop,
			WndRect.Width()+g_nLeft, WndRect.Height()+g_nTop);

		MoveWindow(&WndRect);
	}


⌨️ 快捷键说明

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