form_Convert.cpp
上传用户:gelin96
上传日期:2017-01-08
资源大小:20993k
文件大小:13k
- /*****************************************************************************
- * 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_Convert.cpp
- *
- * Project:
- * --------
- * Maui META APP
- *
- * Description:
- * ------------
- * Convert 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
- // form
- #include "form_convert.h"
- #include "form_RFPathLoss.h"
- #include "form_RFTool.h"
- #include "form_main.h"
- #include "man_fdm.h"
- // misc
- #ifndef _MISC_H_
- #include "misc.h"
- #endif
- //------------------------------------------------------------------------------
- #define CHICAGO2003_FOUNTAIN2 4
- #define CHICAGO2003_AERO 5
- #define KLM2003_FOUNTAIN2 6
- #define KLM2003_SPRING 7
- #define FOUNTAIN 8
- #define FOUNTAIN2 9
- #define SPRING 10
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TfrmConvert *frmConvert;
- //---------------------------------------------------------------------------
- static const int DEFAULT_TXDELAY[] =
- { 32, 29, 40, 58
- };
- //---------------------------------------------------------------------------
- __fastcall TfrmConvert::TfrmConvert(TComponent* Owner)
- : TForm(Owner)
- {
- m_bFirstFormShow = true;
- }
- //---------------------------------------------------------------------------
- void TfrmConvert::Init(void)
- {
- m_bInit = true;
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmConvert::FormCreate(TObject *Sender)
- {
- Init();
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmConvert::FormShow(TObject *Sender)
- {
- if (m_bFirstFormShow)
- {
- frmConvert->AutoScroll = true;
- cbxRFModule->ItemIndex = RFMODULE_MT6119;
- RF_AGC_Obj = frmRFTool->Get_AgcObject();
- RF_APC_Obj = frmRFTool->Get_ApcObject();
- m_bFirstFormShow = false;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmConvert::FormActivate(TObject *Sender)
- {
- if (m_bInit)
- {
- m_bInit = false;
- m_uiFinalRFID = frmMainSel->Get_FinalRFID();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmConvert::HintTimerTimer(TObject *Sender)
- {
- HintTimer->Enabled = false;
- lblHint->Visible = false;
- txtStatus->Caption = "";
- }
- //---------------------------------------------------------------------------
- void TfrmConvert::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;
- }
- //---------------------------------------------------------------------------
- bool TfrmConvert::CheckTxDelay( void )
- {
- int i;
- int data;
- AnsiString text;
- char hint[] = " invalid numeric value ";
- text = edtTxDelay->Text;
- if( !IsValidDelay( text, data ) )
- { ShowHintLabel( edtTxDelay, hint );
- edtTxDelay->SetFocus();
- return(false);
- }
- edtTxDelay->Tag = data;
- return(true);
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmConvert::edtTxDelayCheck(TObject *Sender)
- {
- CheckTxDelay();
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmConvert::btnConvertClick(TObject *Sender)
- {
- bool ok = CheckTxDelay();
- if(!ok) return;
- if(rbtFromIni->Checked)
- {
- ConverFromINIFile();
- }
- else if(rbtFromFlash->Checked)
- {
- ConverFromFlash();
- }
- }
- //===========================================================================
- void TfrmConvert::ConverFromINIFile( void )
- {
- bool ok;
- char filename[2048];
- ok = OpenDialog->Execute();
- if( !ok ) return;
- ok = SaveDialog->Execute();
- if( !ok ) return;
- strcpy( filename, OpenDialog->FileName.c_str() );
- if(ok)
- { ok = RF_AGC_Obj->REQ_Read_From_File( filename );
- }
- if(ok)
- { ok = RF_APC_Obj->REQ_Read_APC_From_File(filename, m_uiFinalRFID, m_bTADOSupport);
- }
- if(ok)
- {
- strcpy( filename, SaveDialog->FileName.c_str() );
- ok = Generate_M12193(filename, cbxRFModule->ItemIndex, edtTxDelay->Tag, RF_AGC_Obj, RF_APC_Obj, m_uiFinalRFID);
- }
- if(ok)
- { txtStatus->Caption = "Generate OK!";
- HintTimer->Enabled = true;
- //Application->MessageBox( "Generate m12193.c ok!", "CONVERT", MB_OK );
- }
- else
- { txtStatus->Caption = "Generate FAIL!";
- HintTimer->Enabled = true;
- //Application->MessageBox( "Generate m12193.c fail!", "CONVERT", MB_OK );
- }
- }
- //---------------------------------------------------------------------------
- static void CNF_ConverFromFlash_AGC( void )
- { frmConvert->ConverFromFlashDone_AGC();
- }
- static void CNF_ConverFromFlash_APC( void )
- { frmConvert->ConverFromFlashDone_APC();
- }
- //-----------------------------------------------
- void TfrmConvert::ConverFromFlash( void )
- {
- if( ! NVRAMMan->Get_IsInit() )
- { frmMainSel->mnuFDMDatabaseClick(NULL);
- }
- if( ! NVRAMMan->Get_IsInit() )
- {
- Application->MessageBox( "Execution Failure : NVRAM database file initialize fail", "FAILURE", MB_OK );
- return;
- }
- RF_AGC_Obj->ConfirmCallback = ::CNF_ConverFromFlash_AGC;
- RF_AGC_Obj->REQ_Read_From_NVRAM_Start();
- }
- //-----------------------------------------------
- void TfrmConvert::ConverFromFlashDone_AGC( void )
- {
- E_METAAPP_RESULT_T state = RF_AGC_Obj->Get_ConfirmState();
- if (METAAPP_SUCCESS == state)
- {
- RF_APC_Obj->ConfirmCallback = ::CNF_ConverFromFlash_APC;
- RF_APC_Obj->REQ_Read_APC_From_NVRAM_Start(m_uiFinalRFID, m_bTADOSupport);
- }
- else
- {
- txtStatus->Caption = "Generate FAIL!";
- HintTimer->Enabled = true;
- // Application->MessageBox( "Read AGC data from flash fail!", "CONVERT", MB_OK );
- }
- }
- //------------------------------------------------------------------------
- void TfrmConvert::ConverFromFlashDone_APC( void )
- {
- E_METAAPP_RESULT_T state = RF_APC_Obj->Get_ConfirmState();
- if (METAAPP_SUCCESS == state )
- {
- bool ok;
- char filename[2048];
- ok = SaveDialog->Execute();
- if( !ok ) return;
- if(ok)
- {
- strcpy( filename, SaveDialog->FileName.c_str() );
- ok = Generate_M12193( filename, cbxRFModule->ItemIndex, edtTxDelay->Tag, RF_AGC_Obj, RF_APC_Obj, m_uiFinalRFID );
- }
- if(ok)
- { txtStatus->Caption = "Generate OK!";
- HintTimer->Enabled = true;
- // Application->MessageBox( "Generate m12193.c ok!", "CONVERT", MB_OK );
- }
- else
- { txtStatus->Caption = "Generate FAIL!";
- HintTimer->Enabled = true;
- // Application->MessageBox( "Generate m12193.c fail!", "CONVERT", MB_OK );
- }
- }
- else
- {
- Application->MessageBox( "Read APC data from flash fail!", "CONVERT", MB_OK );
- }
- }
- //---------------------------------------------------------------------------
- //static void CNF_WriteToFDM( void )
- static void CNF_WriteToNVRAM( void )
- { frmPathLoss->DownloadToFlashDone();
- }
- //===========================================================================
- void __fastcall TfrmConvert::cbxRFModuleChange(TObject *Sender)
- {
- edtTxDelay->Text = DEFAULT_TXDELAY[ cbxRFModule->ItemIndex ];
- edtTxDelay->Tag = DEFAULT_TXDELAY[ cbxRFModule->ItemIndex ];
- }
- //---------------------------------------------------------------------------
- //==============================================================================
- static const char RFMODULE_NAME[8][32] =
- { "BRIGHT2",
- "BRIGHT4",
- "MT6119",
- "AERO",
- "CHICAGO2003 FOUNTAN2",
- "CHICAGO2003 AERO",
- "KLM2003 FOUNTAN2",
- "KLM2003 SPRING"
- };
- //------------------------------------------------------------------------------
- bool TfrmConvert::Generate_M12193(char* filename, int rf_module, int tx_delay, CRFAGC* agc_ptr, CRFAPC* apc_ptr, unsigned int rf_id)
- {
- FILE *fs;
- bool ok;
- fs = fopen( filename, "w+t" );
- if(fs==0) return(false);
- fprintf( fs, "#include "l1d_cid.h"n");
- fprintf( fs, "#include "m12190.h"n");
- fprintf( fs, "n");
- // modified by Andy Ueng
- if(rf_module <= 3) // EVB
- {
- fprintf( fs, "#if IS_RF_%sn", RFMODULE_NAME[rf_module]);
- }
- else
- {
- switch(rf_module)
- {
- case CHICAGO2003_FOUNTAIN2:
- fprintf( fs, "%s", "#if !defined(CHICAGO2003_FOUNTAIN2)n");
- break;
- case CHICAGO2003_AERO:
- fprintf( fs, "%s", "#if !defined(CHICAGO2003_AERO)n");
- break;
- case KLM2003_FOUNTAIN2:
- fprintf( fs, "%s", "#if !defined(KLM2003_FOUNTAIN2)n");
- break;
- case KLM2003_SPRING:
- fprintf( fs, "%s", "#if !defined(KLM2003_SPRING)n");
- break;
- case FOUNTAIN:
- fprintf( fs, "%s", "#if !defined(FOUNTAIN_EVB)n");
- break;
- case FOUNTAIN2:
- fprintf( fs, "%s", "#if !defined(FOUNTAIN2_EVB)n");
- break;
- case SPRING:
- fprintf( fs, "%s", "#if !defined(SPRING_EVB)n");
- break;
- }
- fprintf( fs, "%s", " #error "rf files mismatch with compile option!"n");
- fprintf( fs, "%s", "#endifn");
- }
- fprintf( fs, "/*===============================================================================================*/n");
- fprintf( fs, "n");
- // marked by Andy Ueng
- // fprintf( fs, "/*----------------------------------------*/n");
- // fprintf( fs, "/* Calibration data for round trip delay */n");
- // fprintf( fs, "/*----------------------------------------*/n");
- // fprintf( fs, "n");
- // fprintf( fs, "const short TxPropagationDelay = %d;n", tx_delay);
- // end of marked
- fprintf( fs, "n");
- fclose(fs);
- ok = agc_ptr->REQ_Write_To_M12193( filename );
- if(!ok) return(false);
- ok = apc_ptr->REQ_Write_To_M12193(filename, rf_id);
- if(!ok) return(false);
- fs = fopen( filename, "a+t" );
- if(fs==0) return(false);
- fprintf( fs, "/*===============================================================================================*/n");
- if(rf_module <= 3) // EVB, modified by Andy Ueng
- {
- fprintf( fs, "#endifn");
- }
- fclose(fs);
- return(true);
- }