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

📄 burnnanddlg.cpp.svn-base

📁 vc环境下编译的一个对USB设备进行烧录的驱动程序
💻 SVN-BASE
📖 第 1 页 / 共 3 页
字号:
// burnNANDDlg.cpp : implementation file
//

#include "stdafx.h"
#include "burnNAND.h"
#include "burnNANDDlg.h"
#include "burn.h"
#include "record.h"
#include "ConfigDlg.h"
#include "PassWordDlg.h"
#include <setupapi.h>
#include "burn_lib.h"
#include "dbt.h"

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

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

volatile bool m_dlgInit;

CBrush *m_brStaticBrush[MAX_DEVICE_NUM];

CBrush m_brRedBrush;	// fail
CBrush m_brGreenBrush;	// success
CBrush m_brBlueBrush;	// work
CBrush m_brYellowBrush;	// standby
CBrush m_brBlackBrush;	// init

COLORREF	m_StaticColor[MAX_DEVICE_NUM];	

CStatic *m_static[MAX_DEVICE_NUM];


CString m_arrive_name[16];
CString m_remove_name[16];

int m_nWorkNum;

BOOL m_bWorking[MAX_DEVICE_NUM];

LONG m_text_width;

extern bool count_downloadfile_size();

DEFINE_GUID(M3USB_GUID, 
                0x6e7ac6a7, 0x1a4c, 0x4a72, 0x83, 0x54, 0x89, 0x95, 0x11, 0xf8, 0x13, 0x51);


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)
	virtual BOOL OnInitDialog();
	//}}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)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBurnNANDDlg dialog

CBurnNANDDlg::CBurnNANDDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CBurnNANDDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CBurnNANDDlg)
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	m_dlgInit = FALSE;
}

void CBurnNANDDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CBurnNANDDlg)
	DDX_Control(pDX, IDC_PROGRESS_COM9, m_progress_com9);
	DDX_Control(pDX, IDC_STATIC_COLOR_COM9, m_color_com9);
	DDX_Control(pDX, IDC_STATIC_COLOR_COM16, m_color_com16);
	DDX_Control(pDX, IDC_STATIC_COLOR_COM15, m_color_com15);
	DDX_Control(pDX, IDC_STATIC_COLOR_COM14, m_color_com14);
	DDX_Control(pDX, IDC_STATIC_COLOR_COM13, m_color_com13);
	DDX_Control(pDX, IDC_STATIC_COLOR_COM12, m_color_com12);
	DDX_Control(pDX, IDC_STATIC_COLOR_COM11, m_color_com11);
	DDX_Control(pDX, IDC_STATIC_COLOR_COM10, m_color_com10);
	DDX_Control(pDX, IDC_PROGRESS_COM16, m_progress_com16);
	DDX_Control(pDX, IDC_PROGRESS_COM15, m_progress_com15);
	DDX_Control(pDX, IDC_PROGRESS_COM14, m_progress_com14);
	DDX_Control(pDX, IDC_PROGRESS_COM13, m_progress_com13);
	DDX_Control(pDX, IDC_PROGRESS_COM12, m_progress_com12);
	DDX_Control(pDX, IDC_PROGRESS_COM11, m_progress_com11);
	DDX_Control(pDX, IDC_PROGRESS_COM10, m_progress_com10);
	DDX_Control(pDX, IDC_PROGRESS_COM8, m_progress_com8);
	DDX_Control(pDX, IDC_PROGRESS_COM7, m_progress_com7);
	DDX_Control(pDX, IDC_PROGRESS_COM6, m_progress_com6);
	DDX_Control(pDX, IDC_PROGRESS_COM5, m_progress_com5);
	DDX_Control(pDX, IDC_PROGRESS_COM4, m_progress_com4);
	DDX_Control(pDX, IDC_PROGRESS_COM3, m_progress_com3);
	DDX_Control(pDX, IDC_PROGRESS_COM2, m_progress_com2);
	DDX_Control(pDX, IDC_PROGRESS_COM1, m_progress_com1);
	DDX_Control(pDX, IDC_STATIC_COLOR_COM8, m_color_com8);
	DDX_Control(pDX, IDC_STATIC_COLOR_COM7, m_color_com7);
	DDX_Control(pDX, IDC_STATIC_COLOR_COM6, m_color_com6);
	DDX_Control(pDX, IDC_STATIC_COLOR_COM5, m_color_com5);
	DDX_Control(pDX, IDC_STATIC_COLOR_COM4, m_color_com4);
	DDX_Control(pDX, IDC_STATIC_COLOR_COM3, m_color_com3);
	DDX_Control(pDX, IDC_STATIC_COLOR_COM2, m_color_com2);
	DDX_Control(pDX, IDC_STATIC_COLOR_COM1, m_color_com1);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CBurnNANDDlg, CDialog)
	//{{AFX_MSG_MAP(CBurnNANDDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_CLOSE()
	ON_COMMAND(IDM_CONFIG, OnConfig)
	ON_WM_SIZE()
	ON_WM_CTLCOLOR()
	ON_BN_CLICKED(IDC_BUTTON_BURN, OnButtonBurn)
	ON_COMMAND(IDM_SETTING_HELP, OnSettingHelp)
	//}}AFX_MSG_MAP
	ON_MESSAGE(ON_COM_RECEIVE, On_Receive)
	ON_MESSAGE(ON_BURNFLASH_MESSAGE, On_Message)
    ON_MESSAGE(ON_BURNFLASH_DEVICE_ARRIVE, On_DeviceArrive)
    ON_MESSAGE(ON_BURNFLASH_DEVICE_REMOVE, On_DeviceRemove)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBurnNANDDlg message handlers

#define MAX_RECEIVE_BUF_LEN (1024 * 1024)
extern configuration config;

static char *receive_buf[MAX_DEVICE_NUM];
static int receive_index[MAX_DEVICE_NUM];
static char erase_buf[MAX_DEVICE_NUM][255] = {0}; 
static bool erase_start[MAX_DEVICE_NUM] = {FALSE};
static int erase_buf_index[MAX_DEVICE_NUM] = {0};



extern HANDLE mutex_usb;
extern HANDLE mutex_time;
extern HANDLE usb_init_event;
extern BOOL g_bInit;

extern bool open_config(T_LOAD LoadType);

#define MAX_EDIT_BUF_SIZE (0x7FFE) 
#define EDIT_BUF_SIZE (0x6000)   
#define EDIT_BUF_DEC_SIZE (0x2000)

BOOL CBurnNANDDlg::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

	bool ret = open_config();

	if(!ret)
	{
		LoadDefaultCfg();
		close_config();
	}
	
	m_brRedBrush.CreateSolidBrush(RGB(255, 0, 0));
	m_brGreenBrush.CreateSolidBrush(RGB(0, 255, 0));
	m_brBlueBrush.CreateSolidBrush(RGB(0, 0, 255));
	m_brYellowBrush.CreateSolidBrush(RGB(255, 255, 0));
	m_brBlackBrush.CreateSolidBrush(RGB(0, 0, 0));

	for(int i = 0; i < MAX_DEVICE_NUM; i++)
	{

        burnflash[i].set_id(i);
        burnflash[i].set_wnd(m_hWnd);

		receive_buf[i] = (char *)malloc(MAX_RECEIVE_BUF_LEN);
		receive_index[i] = 0;

		((CTextProgressCtrl *)GetDlgItem(IDC_PROGRESS_COM1 + i))->SetRange32(0, config.total_download_file_len);
		((CTextProgressCtrl *)GetDlgItem(IDC_PROGRESS_COM1 + i))->SetPos(0);
		((CTextProgressCtrl *)GetDlgItem(IDC_PROGRESS_COM1 + i))->SetBkColour(RGB(200, 200, 200));
		((CTextProgressCtrl *)GetDlgItem(IDC_PROGRESS_COM1 + i))->SetForeColour(RGB(0, 0, 255));

	
		((CEdit *) GetDlgItem(IDC_SCREEN_COM1 + i))->SetLimitText(MAX_EDIT_BUF_SIZE);
	}

    if(config.bOpenCom)
    {
        for(i = 0; i < config.com_count; i++)
        {
            ret = burnflash[i].set_dcb(config.BaudRate,config.ByteSize, config.Parity, config.StopBits);
		    if(!ret)
		    {
			    MessageBox("设置串口出错!", NULL, MB_OK);
		    }

		    ret = burnflash[i].open_com(config.base_com + i, config.BaudRate, m_hWnd);
		    if(!ret)
		    {
			    CString str;
			    str.Format("打开串口%d失败", config.base_com + i);
			    MessageBox(str, NULL, MB_OK);
		    }

            receive_buf[i] = (char *)malloc(MAX_RECEIVE_BUF_LEN);
		    receive_index[i] = 0;
        }
    }

    for(i = 0; i < MAX_DEVICE_NUM; i++)
    {
        m_arrive_name[i].Empty();
        m_remove_name[i].Empty();
    }
	
	mutex_usb = CreateMutex(NULL, FALSE, NULL);
	mutex_time = CreateMutex(NULL, FALSE, NULL);

	usb_init_event = CreateEvent(NULL, TRUE, FALSE, NULL);

	g_bInit = FALSE;

	m_static[0] = &m_color_com1;
	m_static[1] = &m_color_com2;
	m_static[2] = &m_color_com3;
	m_static[3] = &m_color_com4;
	m_static[4] = &m_color_com5;
	m_static[5] = &m_color_com6;
	m_static[6] = &m_color_com7;
	m_static[7] = &m_color_com8;
    m_static[8] = &m_color_com9;
    m_static[9] = &m_color_com10;
    m_static[10] = &m_color_com11;
    m_static[11] = &m_color_com12;
    m_static[12] = &m_color_com13;
    m_static[13] = &m_color_com14;
    m_static[14] = &m_color_com15;
    m_static[15] = &m_color_com16;

	for(i = 0; i < MAX_DEVICE_NUM; i++)
	{
		m_brStaticBrush[i] = &m_brBlackBrush; 
		m_StaticColor[i] =  RGB(0, 0, 0);
	}

	m_nWorkNum = 0;
	
	for(i=0; i<MAX_DEVICE_NUM; i++)
	{
		m_bWorking[i] = FALSE;
	}

	m_dlgInit = TRUE;

    CDC* dc = GetDC();

    TEXTMETRIC tm;

    GetTextMetrics(dc->m_hDC, &tm);// 调用GetTextMetrics函数获取字符大小相关信息。

    LONG iLFx = tm.tmAveCharWidth;


    LONG iCFx = (tm.tmPitchAndFamily & 1 ? 3 : 2) * iLFx / 2;

    ReleaseDC (dc) ;

    m_text_width = iCFx;

	if(config.bAutoDownload)
	{
		GetDlgItem(IDC_BUTTON_BURN)->ShowWindow(SW_HIDE);
	}

	MoveWindow(0,0,800,700,TRUE);

    DoRegisterDeviceInterface( M3USB_GUID );

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

void CBurnNANDDlg::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 CBurnNANDDlg::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();
	}

	//set the title by modify mobile type. add by fufuqing
	CString str;

    str.Format("BurnNand V%d.%d.%dc [%s]", MAIN_VERSION, SUB_VERSION, SUB1_VERSION, config.mobile_type);

	SetWindowText(str);	
}

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

LRESULT CBurnNANDDlg::On_DeviceArrive(WPARAM wp, LPARAM lp)
{
	if(config.bUBoot)
	{
		if(m_nWorkNum > 0)
		{
			return 0;
		}

        CString dbcc_name = m_arrive_name[wp]; 

        m_arrive_name[wp].Empty();

        for(int i = 0; i < config.equipment_count; i++)
        {
            if(!burnflash[i].is_standby())
            {
                burnflash[i].set_usb_name(dbcc_name);

                m_brStaticBrush[i] = &m_brYellowBrush;
		        m_StaticColor[i] = RGB(255, 255, 0);

		        GetDlgItem(IDC_STATIC_COLOR_COM1 + i)->Invalidate();
	        
		        burnflash[i].set_standby(TRUE);

		        ((CTextProgressCtrl *)GetDlgItem(IDC_PROGRESS_COM1 + i))->SetPos(0);
		        ((CTextProgressCtrl *)GetDlgItem(IDC_PROGRESS_COM1 + i))->SetForeColour(RGB(0, 0, 255));
                ::SendMessage(((CTextProgressCtrl *)GetDlgItem(IDC_PROGRESS_COM1 + i))->GetSafeHwnd(), WM_SETTEXT, 0, (IN LPARAM)"");

//                m_nWorkNum++;
                break;
            }
        }
	}
	else
	{
		SetEvent(usb_init_event);
	}

	return 0;
}

LRESULT CBurnNANDDlg::On_DeviceRemove(WPARAM wp, LPARAM lp)
{
	if(config.bUBoot)
	{
		if(m_nWorkNum > 0)
		{
			return 0;
		}

        CString dbcc_name = m_remove_name[wp];

        m_remove_name[wp].Empty();

        for(int i = 0; i< config.equipment_count; i++)
        {
            if(burnflash[i].is_standby() && (dbcc_name == burnflash[i].get_usb_name()))
            {
                m_brStaticBrush[i] = &m_brBlackBrush;
		        m_StaticColor[i] = RGB(255, 255, 0);

		        GetDlgItem(IDC_STATIC_COLOR_COM1 + i)->Invalidate();
	        
		        burnflash[i].set_standby(FALSE);

⌨️ 快捷键说明

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