form_BarcodeDownload.cpp
上传用户:gelin96
上传日期:2017-01-08
资源大小:20993k
文件大小:16k
源码类别:
MTK
开发平台:
C++ Builder
- /*****************************************************************************
- * 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) 2005
- *
- * BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
- * THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
- * RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
- * AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
- * NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
- * SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
- * SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
- * THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
- * NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
- * SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
- *
- * BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
- * LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
- * AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
- * OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
- * MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
- *
- * THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
- * WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
- * LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
- * RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
- * THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
- *
- *****************************************************************************/
- /*****************************************************************************
- *
- * Filename:
- * ---------
- * form_BarcodeDownload.cpp
- *
- * Project:
- * --------
- * Maui META APP
- *
- * Description:
- * ------------
- * Barcode upload/download form source
- *
- * Author:
- * -------
- * Andy Ueng (mtk00490)
- *
- *============================================================================
- * HISTORY
- * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
- *------------------------------------------------------------------------------
- * $Revision$
- * $Modtime$
- * $Log$
- *
- *------------------------------------------------------------------------------
- * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
- *============================================================================
- ****************************************************************************/
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include "form_BarcodeDownload.h"
- #include "form_main.h"
- #include "man_fdm.h"
- #ifndef _MISC_BARCODE_H_
- #include "misc_barcode.h"
- #endif
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TfrmBarcodeDownload *frmBarcodeDownload;
- //===========================================================================
- //////////////////////// static function ///////////////////////////////////
- //===========================================================================
- //---------------------------------------------------------------------------
- static void CNF_ReadFromNVRAM( void )
- { frmBarcodeDownload->UploadFromFlashDone();
- }
- //---------------------------------------------------------------------------
- static void CNF_WriteToNVRAM( void )
- { frmBarcodeDownload->DownloadToFlashDone();
- }
- //---------------------------------------------------------------------------
- void DisplayNVRAMDatabaseFile( void )
- {
- frmBarcodeDownload->DisplayNVRAMDatabaseFile();
- }
- //===========================================================================
- //////////////////////// method ////////////////////////////////////////////
- //===========================================================================
- //---------------------------------------------------------------------------
- __fastcall TfrmBarcodeDownload::TfrmBarcodeDownload(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmBarcodeDownload::btnLoadFromFlashClick(TObject *Sender)
- {
- if( ! NVRAMMan->Get_IsInit() )
- { frmMainSel->mnuFDMDatabaseClick(Sender);
- }
- if( ! NVRAMMan->Get_IsInit() )
- {
- sbBarcode->Panels->Items[0]->Text = (AnsiString) " NVRAM database file initialization fail";
- Application->MessageBox( "Execution Failure : NVRAM database file initialization fail", "FAILURE", MB_OK );
- return;
- }
- BARCODE_Object.ConfirmCallback = ::CNF_ReadFromNVRAM;
- BARCODE_Object.REQ_Read_From_NVRAM();
- btnLoadFromFlash->Enabled = false;
- btnSaveToFlash->Enabled = false;
- sbBarcode->Panels->Items[0]->Text = (AnsiString) " Upload barcode from flash progressing";
- }
- //---------------------------------------------------------------------------
- void TfrmBarcodeDownload::UploadFromFlashDone( void )
- {
- int state = BARCODE_Object.Get_ConfirmState();
- int i;
- btnLoadFromFlash->Enabled = true;
- btnSaveToFlash->Enabled = true;
- switch( state )
- {
- case METAAPP_SUCCESS:
- {
- // strcpy(Barcode, BARCODE_Object.Barcode);
- m_sBarcode = BARCODE_Object.Get_Barcode();
- edtBarcode->Text = (AnsiString) m_sBarcode.c_Barcode;
- sbBarcode->Panels->Items[0]->Text = (AnsiString) " Upload barcode from flash successfully";
- }
- break;
- case METAAPP_FAIL:
- {
- sbBarcode->Panels->Items[0]->Text = (AnsiString) " Upload barcode from flash fail, please check the version of load and NVRAM database are same.";
- Application->MessageBox( "Execution Failure : Upload barcode form flash, please check the version of load and NVRAM database are same.", "FAILURE", MB_OK );
- }
- break;
- case METAAPP_TIMEOUT:
- {
- sbBarcode->Panels->Items[0]->Text = (AnsiString) " Upload barcode from flash timeout";
- Application->MessageBox( "Execution Timeout : Upload barcode form flash", "TIMEOUT", MB_OK );
- }
- break;
- case METAAPP_STOP:
- {
- sbBarcode->Panels->Items[0]->Text = (AnsiString) " Upload barcode from flash stop";
- }
- break;
- }
- }
- //==============================================================================
- void __fastcall TfrmBarcodeDownload::btnSaveToFlashClick(TObject *Sender)
- {
- if( ! NVRAMMan->Get_IsInit() )
- { frmMainSel->mnuFDMDatabaseClick(Sender);
- }
- if( ! NVRAMMan->Get_IsInit() )
- {
- sbBarcode->Panels->Items[0]->Text = (AnsiString) " NVRAM database file initialization fail";
- Application->MessageBox( "Execution Failure : NVRAM database file initialize fail", "FAILURE", MB_OK );
- return;
- }
- S_BARCODE barcode;
- strcpy(barcode.c_Barcode, edtBarcode->Text.c_str());
- BARCODE_Object.Set_Barcode( barcode );
- BARCODE_Object.ConfirmCallback = ::CNF_WriteToNVRAM;
- BARCODE_Object.REQ_Write_To_NVRAM();
- btnLoadFromFlash->Enabled = false;
- btnSaveToFlash->Enabled = false;
- sbBarcode->Panels->Items[0]->Text = (AnsiString) " Download barcode to flash progressing";
- }
- //---------------------------------------------------------------------------
- void TfrmBarcodeDownload::DownloadToFlashDone( void )
- {
- int state = BARCODE_Object.Get_ConfirmState();
- btnLoadFromFlash->Enabled = true;
- btnSaveToFlash->Enabled = true;
- switch (state)
- {
- case METAAPP_SUCCESS:
- {
- AnsiString temp_as_Barcode;
- temp_as_Barcode = AnsiStringAdd( edtBarcode->Text , cbBarcodeIncreasement->ItemIndex );
- edtBarcode->Text = temp_as_Barcode;
- sbBarcode->Panels->Items[0]->Text = (AnsiString) " Download barcode to flash successfully";
- }
- break;
- case METAAPP_FAIL:
- {
- sbBarcode->Panels->Items[0]->Text = (AnsiString) " Download barcode to flash fail, please check the version of load and NVRAM database are same.";
- Application->MessageBox( "Execution Failure : Download barcode to flash, please check the version of load and NVRAM database are same.", "FAILURE", MB_OK );
- }
- break;
- case METAAPP_TIMEOUT:
- {
- sbBarcode->Panels->Items[0]->Text = (AnsiString) " Download barcode to flash timeout";
- Application->MessageBox( "Execution Timeout : Download barcode to flash", "TIMEOUT", MB_OK );
- }
- break;
- case METAAPP_STOP:
- {
- sbBarcode->Panels->Items[0]->Text = (AnsiString) " Download barcode to flash stop";
- }
- break;
- case METAAPP_NVRAM_LID_VER_NOT_SUPPORT:
- {
- sbBarcode->Panels->Items[0]->Text = (AnsiString) " NVRAM_EF_BARCODE_NUM_LID version is not support, please update META to latest version";
- Application->MessageBox("Execution Warning : NVRAM_EF_BARCODE_NUM_LID version is not support, please update META to latest version", "WARNING", MB_OK);
- }
- break;
- default:
- {
- }
- break;
- }
- }
- //==============================================================================
- void __fastcall TfrmBarcodeDownload::btnLoadFromFileClick(TObject *Sender)
- {
- char str[512];
- bool ok;
- int i;
- ok = OpenDialog->Execute();
- if( !ok )
- {
- sbBarcode->Panels->Items[0]->Text = (AnsiString) " Load barcode from file fail";
- Application->MessageBox( "Execution Failure : Load barcode from file", "FAILURE", MB_OK );
- return;
- }
- strcpy( str, OpenDialog->FileName.c_str() );
- ok = BARCODE_Object.REQ_Read_From_File( str );
- if( ok )
- {
- m_sBarcode = BARCODE_Object.Get_Barcode();
- edtBarcode->Text = m_sBarcode.c_Barcode;
- sbBarcode->Panels->Items[0]->Text = (AnsiString) " Load barcode from file successfully";
- }
- else
- {
- sbBarcode->Panels->Items[0]->Text = (AnsiString) " Load barcode from file fail";
- Application->MessageBox( "Execution Failure : Load barcode from file", "FAILURE", MB_OK );
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmBarcodeDownload::btnSaveToFileClick(TObject *Sender)
- {
- char str[512];
- bool ok;
- int i;
- ok = SaveDialog->Execute();
- if( !ok )
- {
- sbBarcode->Panels->Items[0]->Text = (AnsiString) " Save barcode to file fail";
- Application->MessageBox( "Execution Failure : Save barcode to file", "FAILURE", MB_OK );
- return;
- }
- S_BARCODE barcode;
- strcpy(barcode.c_Barcode, edtBarcode->Text.c_str());
- BARCODE_Object.Set_Barcode( barcode );
- strcpy( str, SaveDialog->FileName.c_str() );
- ok = BARCODE_Object.REQ_Write_To_File( str );
- if( !ok )
- {
- sbBarcode->Panels->Items[0]->Text = (AnsiString) " Save barcode to file fail";
- Application->MessageBox( "Execution Failure : Save barcode to file", "FAILURE", MB_OK );
- }
- }
- //==============================================================================
- void __fastcall TfrmBarcodeDownload::BarcodeCheck(TObject *Sender)
- {
- int i;
- int data;
- AnsiString text;
- TEdit *edit = (TEdit*)Sender;
- char hint[] = " Barcode length shall be less or equal 63 ";
- text = edit->Text;
- if( !IsValidBarcode( text) )
- {
- ShowHintLabel( edit, hint );
- edit->SetFocus();
- return;
- }
- }
- //---------------------------------------------------------------------------
- void TfrmBarcodeDownload::ShowHintLabel( TControl *sender, char* hint )
- {
- TPoint pt0 = this->ClientOrigin;
- TPoint pt1 = sender->ClientOrigin;
- lblHint->Left = (pt1.x-pt0.x);
- lblHint->Top = (pt1.y-pt0.y)+sender->Height+3;
- lblHint->Caption = hint;
- lblHint->Visible = true;
- HintTimer->Enabled = true;
- }
- //-----------------------------------------------------------------------------
- void __fastcall TfrmBarcodeDownload::HintTimerTimer(TObject *Sender)
- {
- HintTimer->Enabled = false;
- lblHint->Visible = false;
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmBarcodeDownload::btnChangeNVRAMDatabaseFileClick(TObject *Sender)
- {
- frmMainSel->mnuFDMDatabaseClick(Sender);
- if( ! NVRAMMan->Get_IsInit() )
- {
- sbBarcode->Panels->Items[0]->Text = (AnsiString) " NVRAM database file init fail, please change NVRAM database file";
- Application->MessageBox( "NVRAM database file init fail", "FAILURE", MB_OK );
- }
- else
- {
- sbBarcode->Panels->Items[0]->Text = (AnsiString) " NVRAM database file init success";
- stNVRAMDatabaseFile->Caption = frmMainSel->as_NVRAM_database_file_name;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmBarcodeDownload::FormShow(TObject *Sender)
- {
- static bool firstBarcodeDownloadFromShow = true;
- if ( firstBarcodeDownloadFromShow == true )
- {
- ActiveMan->SetActiveFunction( ::DisplayNVRAMDatabaseFile );
- firstBarcodeDownloadFromShow = false;
- }
- }
- //---------------------------------------------------------------------------
- void TfrmBarcodeDownload::DisplayNVRAMDatabaseFile( void )
- {
- unsigned long nvram_idb;
- META_RESULT meta_result;
- as_NVRAM_DATABASE_FILE = read_NVRAM_DATABASE_FILE("MF_setup.txt", Application->ExeName);
- stNVRAMDatabaseFile->Caption = as_NVRAM_DATABASE_FILE;
- meta_result = META_NVRAM_Init_r( m_META_HANDLE_Obj.Get_MainHandle(), as_NVRAM_DATABASE_FILE.c_str(), &nvram_idb);
- if( meta_result !=META_SUCCESS )
- {
- NVRAMMan->Set_IsInit( false );
- if( META_MAUI_DB_INCONSISTENT == meta_result )
- {
- sbBarcode->Panels->Items[0]->Text = (AnsiString) " NVRAM database file and target load is inconsistent";
- Application->MessageBox( "NVRAM database file and target load is inconsistent ", "WARNING", MB_OK );
- }
- else
- {
- sbBarcode->Panels->Items[0]->Text = (AnsiString) " NVRAM database file initialization fail, please change NVRAM database file";
- Application->MessageBox( "NVRAM database file init fail", "FAILURE", MB_OK );
- }
- }
- else
- {
- NVRAMMan->Set_IsInit( true );
- sbBarcode->Panels->Items[0]->Text = (AnsiString) " NVRAM database file initialization successful";
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmBarcodeDownload::FormClose(TObject *Sender,
- TCloseAction &Action)
- {
- SaveNVRAMDatabaseFile();
- }
- //---------------------------------------------------------------------------
- void TfrmBarcodeDownload::SaveNVRAMDatabaseFile( void )
- {
- write_NVRAM_DATABASE_FILE( "MF_setup.txt", Application->ExeName, stNVRAMDatabaseFile->Caption );
- }