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

📄 multiportflashdownloadtool.cpp_bak

📁 多串口下载手机软件的软件
💻 CPP_BAK
📖 第 1 页 / 共 5 页
字号:
/*****************************************************************************
*  Copyright Statement:
*  --------------------
*  This software is protected by Copyright and the information contained
*  herein is confidential. The software may not be copied and the information
*  contained herein may not be used or disclosed except with the written
*  permission of MediaTek Inc. (C) 2001
*
*****************************************************************************/

/*****************************************************************************
 *
 * Filename:
 * ---------
 *   MultiPortFlashDownloadTool.cpp
 *
 * Project:
 * --------
 *   Multiport download
 *
 * Description:
 * ------------
 *  Multiport download form source
 *
 * Author:
 * -------
 *  Andy Ueng (mtk00490)
 *
 *============================================================================
 *             HISTORY
 * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
 *------------------------------------------------------------------------------
 * $Revision:   1.12  $
 * $Modtime:   Jun 24 2005 15:13:30  $
 * $Log:   //mtkvs01/vmdata/Multiport_Download/archives/Multiport_Download/MultiPortFlashDownloadTool.cpp-arc  $
 * 
 *    Rev 1.12   Jun 24 2005 15:25:08   mtk00490
 * Support maximum 16 port download, format only type, multi-bin option
 * 
 *    Rev 1.11   Apr 14 2005 16:08:36   mtk00490
 * add stop button to stop specific or all mobile downloading and formatting
 * 
 *    Rev 1.10   Apr 14 2005 16:05:48   mtk00490
 * add stop button to stop specific or all mobile downloading and formatting
 * 
 *    Rev 1.9   Feb 18 2005 11:18:38   mtk00490
 * Update brom.dll and download agent ver 2.4.1009 to resolve INTEL W18/W30 series flash doesn't support Buffered-Program
 * 
 *    Rev 1.8   Dec 01 2004 10:00:16   mtk00490
 * Multiport download tool ver 2.4.1007 (Add status indicator--download successful:green light, download fail:red light)
 * 
 *    Rev 1.7   Nov 05 2004 17:15:32   mtk00490
 * Multiport download tool ver 2.4.1007 (Support automatic baseband chip and external clock rate detection)
 * 
 *    Rev 1.6   Sep 08 2004 19:48:50   mtk00490
 * Multiport download tool ver 2.4.1004
 * 
 *    Rev 1.4   Aug 28 2004 21:10:28   mtk00490
 * Multiport download ver 2.4.1003
 * 
 *    Rev 1.3   Aug 28 2004 20:47:52   mtk00490
 * Multiport download ver 2.4.1002
 * 
 *    Rev 1.2   Jul 19 2004 17:27:52   mtk00490
 * Multiport download ver 2.4.0
 * 
 *    Rev 1.1   Jun 02 2004 21:15:52   mtk00490
 * Multiport download ver 2.3.0
 * Resolution for 2: Multiport download ver 2.3.0
 * 
 *    Rev 1.0   Mar 22 2004 15:13:00   mtk00490
 * Initial revision.
 * Resolution for 1: Multiport download ver 2.1.0
 * 
 *------------------------------------------------------------------------------
 * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
 *============================================================================
 ****************************************************************************/
//---------------------------------------------------------------------------

#include <vcl.h>
#include <inifiles.hpp>
#include <fcntl.h>
#include <io.h>
#include "com_enum.h"

#pragma hdrstop

#ifndef form_AboutH
#include "form_About.h"
#endif

#include "Multiport_Common.h"

#ifndef _MD_MSG_
#include "MD_msg.h"
#endif

#include "MultiPortFlashDownloadTool.h"
#include "FlashDownLoad.h"
#include "WaitForFinish.h"

// database
#ifndef _FACTORY_COMMON_H_
#include "factory_common.h"
#endif

#ifndef  _FILE_UTILS_H_
#include "file_utils.h"
#endif

//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "CGAUGES"
#pragma resource "*.dfm"
TMainForm *MainForm;
//EXT_CLOCK	g_EXT_CLOCK=EXT_26M;
//BBCHIP_TYPE	g_MCU_TYPE=MT6218;
struct DL_HANDLE	*g_DL_HANDLE = NULL;
struct DA_HANDLE	*g_DA_HANDLE = NULL;
struct RB_HANDLE	*g_RB_HANDLE = NULL;
//int m_DownLoadTimeSec;
int m_TheFirstComNo;
//int iBaudRate;

HANDLE hPostMsgDestHandle;
bool isStopTrigger[MAX_SUPPORT_PORT_NUM];

// access
HANDLE hSemaphore;

extern  bool isShowNoFormatInfo;
extern  bool isShowFileNotLoaded;
extern  int boot_stop;
extern  HANDLE Flash_Download_Event[MAX_SUPPORT_PORT_NUM];
extern  int    stopflag[MAX_SUPPORT_PORT_NUM];
//---------------------------------------------------------------------------
__fastcall TMainForm::TMainForm(TComponent* Owner)
        : TForm(Owner)
{
    
}

//---------------------------------------------------------------------------
void _fastcall TMainForm::SubClassWndProc( Messages::TMessage &Message)
{



    switch ( Message.Msg )
    {
        case WM_MD_SELECT_DOWNLOAD_TYPE_FAIL:
             Enable_UIComponent();
        break;

        case WM_MD_DOWNLOAD_SUCCESSFUL:
        {
             
             if( MainForm->cbAutoPollingArray[Message.WParam]->Checked )
             {
                 MainForm->btnCOMDownloadClick( Message.WParam );
             }

        }
        break;


        
        default:
           this->WndProc( Message );
        break;
    }


}

//---------------------------------------------------------------------------
void __fastcall TMainForm::OpenDownloadAgentClick(TObject *Sender)
{
    FileOpenDownloadAgentExecute();    
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::OpenScatterClick(TObject *Sender)
{
    FileOpenScatExecute();    
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::OpenLoadClick(TObject *Sender)
{
    //FileOpenROMExecute();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::tbOpenFATFileClick(TObject *Sender)
{
    //OpenFATFile();
}

//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
bool TMainForm::FileOpenDownloadAgentExecute()
{


    int iLastDel=0;

    if (asDA_Path.Length()>0)
    {
       OpenDownloadAgentDialog->InitialDir = asDA_Path;
    }

    if ( OpenDownloadAgentDialog->Execute() )    // *.bin file
    {
         if ( OpenReadDA_File( OpenDownloadAgentDialog->FileName ))
         {
            asDAFileName = OpenDownloadAgentDialog->FileName;
            iLastDel = asDAFileName.LastDelimiter("\\:");

            if ( iLastDel > 0)
            {
               asDA_Path = asDAFileName.SubString(1, iLastDel-1 );

            }

            return true;
         }
         else
           return false;
    }
    else
        return false;
}

//--------------------------------------------------------------------------
bool TMainForm::FileOpenScatExecute()
{

    int iLastDel=0;

    if (asScat_Path.Length()>0)
    {
       OpenScatterDialog->InitialDir = asScat_Path;
    }

    if ( OpenScatterDialog->Execute() )    // *.bin file
    {
         if ( OpenReadScat_File( OpenScatterDialog->FileName ))
         {
            asScatFileName = OpenScatterDialog->FileName;
            iLastDel = asScatFileName.LastDelimiter("\\:");

            if ( iLastDel > 0)
            {
               asScat_Path = asScatFileName.SubString(1, iLastDel-1 );

            }


            // reopen bin
          //  if(asROMFileName.AnsiCompareIC("") != 0)
          //  {
          //      OpenReadROM_File(asROMFileName);
          //  }
          //  // reopen FAT
          //  #ifndef SERVICE_CENTER
          //  if( cbType->ItemIndex == DOWNLOAD_ROM_AND_FAT_INDEX )
          //  {
          //       isFATFileLoaded == false;
          //       LoadFATFile();
          //  }
          //  #endif
            return true;
         }
         else
           return false;
    }
    else
        return false;

}

//-------------------------------------------------------------------------
bool TMainForm::FileOpenROMExecute()
{

    int iLastDel=0;

    if (asROM_Path.Length()>0)
    {
       OpenROMDialog->InitialDir = asROM_Path;
    }

    if ( OpenROMDialog->Execute() )    // *.bin file
    {
         if ( OpenReadROM_File( OpenROMDialog->FileName ))
         {
            asROMFileName = OpenROMDialog->FileName;
            iLastDel = asROMFileName.LastDelimiter("\\:");

            if ( iLastDel > 0)
            {
               asROM_Path = asROMFileName.SubString(1, iLastDel-1 );

            }

            return true;
         }
         else
           return false;
    }
    else
        return false;

}

//---------------------------------------------------------------------------
bool TMainForm::OpenReadDA_File( AnsiString asFileName)
{
	int ret;

	if(ret=DA_LoadByFilepath(g_DA_HANDLE, asFileName.c_str()))
        {
		if( FTHND_HANDLE_BUSY_NOW == ret )
                {
			ShowMessage("Program is busy! Can not reload DA right now.");
		}
		else
                {
			ShowMessage(" Load DA file " + asFileName + " error ");
		}
		return false;
	}

	lblDAFileName->Caption = asFileName;

	return true;
}

//--------------------------------------------------------------------------
bool TMainForm::OpenReadScat_File(AnsiString asMapFileName)
{
    int ret;
    unsigned short rom_count;
    //ROM_INFO   rom_info[MAX_LOAD_SECTIONS];
    
    // load scatter
    if(ret=DL_LoadScatter(g_DL_HANDLE, asMapFileName.c_str()))
    {
        if( FTHND_HANDLE_BUSY_NOW == ret )
        {
            ShowMessage("Program is busy! Can not reload scat file right now.");
        }
        else
        {
            ShowMessage("Incorrect scatter file format!");
        }
        return false;
    }

    lblScatFileName->Caption = asMapFileName;
    if(!DL_GetCount(g_DL_HANDLE, &rom_count))
    {

        if( !DL_Rom_GetInfoAll(g_DL_HANDLE, rom_info, MAX_LOAD_SECTIONS) )
        {
            TListItem	*p_list_item;
            AnsiString   as_reg_prefix;

            lv->Items->Clear();
            for( int i=0; i<rom_count; i++ )
            {
                p_list_item = lv->Items->Add();
                p_list_item->Caption = rom_info[i].name;
                p_list_item->Checked = true;
    	        DL_Rom_SetEnableAttr(g_DL_HANDLE, i, p_list_item->Checked);
                if( rom_info[i].addr_type == ABSOLUTE_ADDR )
                {
                    as_reg_prefix = "";

                }
                else
                {
                    as_reg_prefix = "+";
            	}

                p_list_item->SubItems->Add( as_reg_prefix + "0x" + IntToHex((int)rom_info[i].region_addr, 8) );
                p_list_item->SubItems->Add( "0x" + IntToHex((int)rom_info[i].begin_addr, 8) );
                p_list_item->SubItems->Add( "0x" + IntToHex((int)rom_info[i].end_addr, 8) );
            }
	}
    }
    return true;
}

//---------------------------------------------------------------------------
bool TMainForm::OpenReadROM_File(AnsiString asLoadFileName)
{
    #if 0
    int ret;

    // loading ROM Load

    if(ret=DL_Rom_LoadByFilepath(g_DL_HANDLE, ROM_LOAD_INDEX, asLoadFileName.c_str()))
    {
        if( FTHND_HANDLE_BUSY_NOW == ret )
        {
            ShowMessage("Program is busy! Can not reload scat file right now.");
        }
        else
        {
            ShowMessage("Incorrect ROM LOAD");
        }
        return false;
    }

    lblROMFileName->Caption = asLoadFileName;

    return true;
    #endif
}

//---------------------------------------------------------------------------
bool TMainForm::OpenReadFAT_File(AnsiString asFATFileName)
{
        #if 0

⌨️ 快捷键说明

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