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

📄 flashupgraderdlg.cpp

📁 PW芯片方案Flash ROM烧写程序
💻 CPP
📖 第 1 页 / 共 5 页
字号:
    CComPortCmd *pComPort = GetComPortCmdPtr();
    pComPort->CloseComPort();
    m_pComPort = NULL;
	
    if (psERROR == m_eState)
    {
        return;             // Error occured (message has already been displayed).
    }

	BOOL bVerifyFailed = (psVERIFYFAILED == m_eState);

	// 
	// Clear the selected states for all items in the list control.
	//
	for (int i=0; i<m_listRegions.GetItemCount(); i++)
	{
		m_listRegions.SetItemState(i, 0,LVIS_FOCUSED|LVIS_SELECTED);
	}

	if (m_bContinuous)
	{
		if (m_bContinuous)
		{
			m_strFileName.Format("Delay for %dms...", m_nResetTime);
			UpdateData(FALSE);

			// Sleep for 3 seconds to give the target time to bypass the
			// Flash check code.
			Sleep(m_nResetTime);

			m_strFileName = "Ready to go again...";
			UpdateData(FALSE);
		}

		BeginDownloadingFirmware();
	}
	else
	{
		m_bFlashingInProgress = FALSE;
		DisableControls(FALSE);

		if (!bVerifyFailed)
		{
            if (m_bNotify && pTheApp->m_nReturnValue==0)
            {
			    if (m_bVerifyOnly)
			    {
				    AfxMessageBox("Verification Completed Sucessfully!\nNo Differences Found",MB_ICONINFORMATION);
			    }
			    else
			    {
				    AfxMessageBox("Flash Completed!",MB_ICONINFORMATION);
			    }
            }
		}
	}

    //------------------------------------------------------------------------
    // All files were successfully downloaded. Set state to completed. Re-enable
    // and simulate pressing the Next button so next wizard page is displayed.
    //------------------------------------------------------------------------
    m_eState = psCOMPLETED;

    if (m_bExitWhenDone)
    {
        PostMessage(WM_CLOSE);
    }
}

LONG CFlashUpgraderDlg::OnComPortMessage(UINT wParam, LONG lParam)
{
	if( m_pComPort )
    	m_pComPort->OnComPortMessage(wParam, lParam);

    return 0;
}

BOOL bSaveNotify = FALSE;

void CFlashUpgraderDlg::OnChkContinuous() 
{
	UpdateData(TRUE);

	if (m_bContinuous)
	{
		bSaveNotify = m_bNotify;
		m_bNotify = FALSE;
	}
	else
	{
		m_bNotify = bSaveNotify;
	}

	UpdateControls();

	UpdateData(FALSE);
}

void CFlashUpgraderDlg::GetInitialConnection()
{
	CString strKey;
	strKey.LoadString(IDS_REGKEY_BASE);
	CString strValueName;

	// 
	// Start with Serial as the default...
	//
	m_strConnection = "Serial";

#ifdef BUILD_USB_CONFIG

	//
	// Then, get the value stored in the registry...
	//
	strValueName.LoadString(IDS_REGVALUE_CONNECTION);
	gGetValueFromRegistry(HKEY_CURRENT_USER, strKey, strValueName, &m_strConnection);

	//
	// Now, check to see if the command line overrides it...
	//
	if (pTheApp->CheckCmdLineOptions("-c"))
	{
		CString strCon = pTheApp->GetCmdLineOptions("-c");
		strCon.MakeLower();

		if (strCon == "usb")
		{
			m_strConnection = "USB";
		}
	}

#else

	// NT only supports Serial.
	m_strConnection = "Serial";
	m_cmbConnection.EnableWindow(FALSE);

#endif
}

void CFlashUpgraderDlg::GetInitialComPort()
{
	CString strKey;
	strKey.LoadString(IDS_REGKEY_BASE);
	CString strValueName;

	// 
	// Start with the default...
	//
	m_strComPort = "COM1:";

	//
	// Then, get the value stored in the registry...
	//
	CString strComPort;
	strValueName.LoadString(IDS_REGVALUE_COMPORT);
	gGetValueFromRegistry(HKEY_CURRENT_USER, strKey, strValueName, &strComPort);
	if (!strComPort.IsEmpty())
	{
		m_strComPort = strComPort;
	}

	// 
	// Check for multiple instances...
	//
	int nInstance = GetServerList();
	if (nInstance > 1)
	{
		int nPort = atoi(m_strComPort.Mid(3)) + (nInstance-1);
		m_strComPort.Format("COM%d:", nPort);
	}

	//
	// Now, check to see if the command line overrides it...
	//
	if (pTheApp->CheckCmdLineOptions("-p"))
	{
		m_strComPort = "COM"+pTheApp->GetCmdLineOptions("-p")+":";
	}
}

void CFlashUpgraderDlg::GetInitialBaudRate()
{
	CString strKey;
	strKey.LoadString(IDS_REGKEY_BASE);
	CString strValueName;

	// 
	// Start with the default...
	//
	m_strBaudRate = "115200";

	//
	// Then, get the value stored in the registry...
	//
	CString strBaudRate;
	strValueName.LoadString(IDS_REGVALUE_BAUDRATE);
	gGetValueFromRegistry(HKEY_CURRENT_USER, strKey, strValueName, &strBaudRate);
	if (!strBaudRate.IsEmpty())
	{
		m_strBaudRate = strBaudRate;
	}

	//
	// Now, check to see if the command line overrides it...
	//
	if (pTheApp->CheckCmdLineOptions("-b"))
	{
		m_strBaudRate = pTheApp->GetCmdLineOptions("-b");
	}
}

BOOL CFlashUpgraderDlg::GetInitialInfFile(CString& strDest, CString& strTarget)
{
	BOOL bResult = TRUE;

	CString strKey;
	strKey.LoadString(IDS_REGKEY_BASE);
	CString strValueName;

	CString strLast;
	CString strFile;
	CString strPath;

	BOOL bFoundFile = FALSE;

	//
	// Per Bob G (02/13/02) First check to see if there are any INF files
	// in the launch directory.  If so, then use those, choosing pwSDK.inf
	// if it exists.
	//
    CString strLaunch = ((CFlashUpgraderApp*)AfxGetApp())->m_strLaunchDir;
    CString strFound;
    CFileFind finder;
    BOOL bWorking = finder.FindFile(strLaunch+"*.inf");
    if (bWorking)
    {
        //
        // There are files here
        //
        strPath = strLaunch;

        //
        // Grab the first file found in case we don't find a pwSDK.inf
        // file, then this one will be used.
        //
        bWorking = finder.FindNextFile();
        strFile = finder.GetFileName(); 

        //
        // Look for a pwSDK.inf file.  If found, use it.
        //
        while (bWorking)
        {
            strFound = finder.GetFileName();
            if (strFound.CompareNoCase("pwSDK.inf")==0)
            {
                strFile = strFound;
                break;
            }
            else if ((strFound.CompareNoCase("QMB.inf")==0) || (strFound.CompareNoCase("QMBAll.inf")==0))
            {
                strFile = strFound;
                break;
            }
            bWorking = finder.FindNextFile();
        }
        bFoundFile = TRUE;
    }
    
    if (!bFoundFile)
    {
        //
        // Get the value stored in the registry...
	    //
	    strValueName.LoadString(IDS_REGVALUE_INFFILE);
	    gGetValueFromRegistry(HKEY_CURRENT_USER, strKey, strValueName, &strLast);

	    // 
	    // If no registry entry, the use default.
	    //
	    if (strLast.IsEmpty())
	    {
		    strLast = "pwSDK.inf";
	    }
    }

	//
	// Using the last file name stored in the registry, see if we can locate
	// the file in the following directories.  The order specified indicates
	// the priority of the search.  First one found is used.
	//
	// 1. The embedded\bin directory of the launch tree.
	// 2. The current directory.
	// 3. The previous session directory.
	// 4. Can't be located.



	//
	// 1. The embedded\bin directory of the launch tree.
	//
	if (!bFoundFile)
	{
		strFile = pTheApp->GetFilename(strLast);
		strPath = pTheApp->m_strLaunchDir+"..\\embedded\\bin\\";
		bFoundFile = FileExists(strPath + strFile);
	}

	//
	// 2. The current directory.
	//
	if (!bFoundFile)
	{
		strFile = pTheApp->GetFilename(strLast);
		strPath = "";
		bFoundFile = FileExists(strPath + strFile);
	}

	//
	// 3. The previous session directory.
	//
	if (!bFoundFile)
	{
		strFile = pTheApp->GetFilename(strLast);
		strPath = pTheApp->GetPath(strLast);
		bFoundFile = FileExists(strPath + strFile);
	}

	if (!bFoundFile)
	{
		//
		// Couldn't find the file.  Alert the user.
		//
		strPath = "";
		strFile = "";
		
	}
	bResult = bFoundFile;

	//
	// Now, check to see if the command line overrides it...
	//
	if (pTheApp->CheckCmdLineOptions("-f"))
	{
		CString strValue = pTheApp->GetCmdLineOptions("-f");
		strPath = pTheApp->GetPath(strValue);
		strFile = pTheApp->GetFilename(strValue);

		// 
		// Verify that the file exists.  First see if the 
		//
		if (!FileExists(strValue))
		{
			CString strMsg = "The file specified on the command line could\n";
			strMsg += "not be found:\n\nFile: "+strValue;
			AfxMessageBox(strMsg, MB_OK);

			bResult = FALSE;
		}
        else
        {
            bResult = TRUE;
        }
		
	}

	strTarget = strFile;
	strDest = strPath;

	return bResult;
}

void CFlashUpgraderDlg::GetInitialSwitches()
{
	CString strKey;
	strKey.LoadString(IDS_REGKEY_BASE);
	CString strValueName;

	CString strValue;

	//
	// Get the value stored in the registry...
	//
	strValueName.LoadString(IDS_REGVALUE_VERIFYONLY);
	gGetValueFromRegistry(HKEY_CURRENT_USER, strKey, strValueName, &strValue);
	if (strValue.IsEmpty())
	{
		strValue = "false";
	}

	strValue.MakeLower();
	m_bVerifyOnly = (strValue == "true");

	//
	// Now, check to see if the command line overrides it...
	//
	if (pTheApp->CheckCmdLineOptions("-v"))
	{
		m_bVerifyOnly = TRUE;
	}


	//
	// Get the value stored in the registry...
	//
	strValueName.LoadString(IDS_REGVALUE_CONTINUOUS);
	gGetValueFromRegistry(HKEY_CURRENT_USER, strKey, strValueName, &strValue);
	if (strValue.IsEmpty())
	{
		strValue = "false";
	}

	strValue.MakeLower();
	m_bContinuous = (strValue == "true");

	//
	// Now, check to see if the command line overrides it...
	//
	if (pTheApp->CheckCmdLineOptions("-r"))
	{
		m_bContinuous = TRUE;
	}

	
	//
	// Get the value stored in the registry...
	//
	strValueName.LoadString(IDS_REGVALUE_RESETTIME);
	gGetValueFromRegistry(HKEY_CURRENT_USER, strKey, strValueName, &strValue);

	//
	// Now, check to see if the command line overrides it...
	//
	if (pTheApp->CheckCmdLineOptions("-r"))
	{
		strValue = pTheApp->GetCmdLineOptions("-r");
	}

	if (strValue.IsEmpty())
	{
		m_nResetTime = 3000;
	}
	else
	{
		m_nResetTime = atoi(strValue);
	}

	//
	// Get the value stored in the registry...
	//
	strValueName.LoadString(IDS_REGVALUE_NOTIFY);
	gGetValueFromRegistry(HKEY_CURRENT_USER, strKey, strValueName, &strValue);
	m_bNotify = (strValue == "true");

	if (pTheApp->CheckCmdLineOptions("-g"))
	{
		m_bGoMode = TRUE;
	}
	
	if (pTheApp->CheckCmdLineOptions("-x"))
	{
		m_bExitWhenDone = TRUE;
	}

	// dennisd - auto flash
	m_bNoReset = FALSE;
	if (pTheApp->CheckCmdLineOptions("-a"))
	{
		m_bNoReset = TRUE;

		// default to Opal
		g_iResetDelay1 = 5000;
		g_iResetWatchDogAddr = 0x1f8d3;
		g_iResetWatchDogData = 0x2a;
		g_iResetDelay2 = 500;
		g_iResetAddr = 0x1f0f8; 
		g_iResetData = 0xc0;
		CString strValue = pTheApp->GetCmdLineOptions("-a");
		ProcessResetInfFile(strValue);
	}

	
}

BOOL CFlashUpgraderDlg::FileExists(CString strPathName)
{
	CStdioFile		File;

	if (!File.Open(strPathName,CFile::modeRead))
	{
		return FALSE;
	}
	File.Close();
	return TRUE;
}

void CFlashUpgraderDlg::OnDblclkListRegions(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;

	int nId = pNMListView->iItem;

	CString strFile = m_listRegions.GetItemText(nId, 0);
	
	CHexFileData* pFile = GetHexFileData(strFile);
	if (pFile != NULL)
	{
		pFile->m_bDownload = !pFile->m_bDownload;		
	}

	m_listRegions.SetItem(nId,

⌨️ 快捷键说明

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