form_CFGPhErr.cpp
上传用户:gelin96
上传日期:2017-01-08
资源大小:20993k
文件大小:12k
- /*****************************************************************************
- * 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_CFGPhErr.cpp
- *
- * Project:
- * --------
- * Maui META APP
- *
- * Description:
- * ------------
- * Tx Phase error CFG 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
- #ifndef _META_UTILS_H_
- #include "meta_utils.h"
- #endif
- #ifndef _MISC_H_
- #include "misc.h"
- #endif
- #ifndef _META_FACTORY_H_
- #include "meta_factory.h"
- #endif
- #include "form_CFGPhErr.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TfrmCFGPhErr *frmCFGPhErr;
- //---------------------------------------------------------------------------
- __fastcall TfrmCFGPhErr::TfrmCFGPhErr(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmCFGPhErr::btnLoadFromCFGFileClick(TObject *Sender)
- {
- bool ok;
- int i;
- AnsiString asPath, asFileName;
- static bool isFirstOpen = true;
- if( isFirstOpen )
- {
- isFirstOpen = false;
- if( getPathFromStr( Form_META_Factory->stCFGFile->Caption, asPath ) )
- {
- OpenDlg->InitialDir = asPath;
- if( getFilenameFromStr( Form_META_Factory->stCFGFile->Caption, asFileName ) )
- {
- OpenDlg->FileName = asFileName;
- }
- }
- else
- {
- if( getPathFromStr(Application->ExeName, asPath) )
- {
- OpenDlg->InitialDir = asPath;
- }
- else
- {
- OpenDlg->InitialDir = "C:\";
- }
- }
- }
- ok = OpenDlg->Execute();
- if( !ok )
- {
- sbCFGPhErr->Panels->Items[0]->Text = (AnsiString) " Load ADC setting from file fail";
- Application->MessageBox( "Execution Failure : Load ADC setting from file fail", "FAILURE", MB_OK );
- return;
- }
- if( ! cfg->ReadFromIniFile( OpenDlg->FileName ) )
- {
- sbCFGPhErr->Panels->Items[0]->Text = (AnsiString) " Read CFG file fail";
- Application->MessageBox( "Execution Failure : Read CFG file", "FAILURE", MB_OK );
- return;
- }
- // PHASE_ERROR_BAND
- cfg->get_PHASE_ERROR_BAND( as_PHASE_ERROR_BAND );
- edtPHASE_ERROR_BAND->Text = as_PHASE_ERROR_BAND;
- // PHASE_ERROR_ARFCN
- cfg->get_PHASE_ERROR_ARFCN( m_sPHASE_ERROR_ARFCN );
- edtPHASE_ERROR_ARFCN->Text = IntToStr( m_sPHASE_ERROR_ARFCN );
- // PHASE_ERROR_PCL
- cfg->get_PHASE_ERROR_PCL( i_PHASE_ERROR_PCL );
- edtPHASE_ERROR_PCL->Text = IntToStr( i_PHASE_ERROR_PCL );
- // PHASE_ERROR_RMS_ERROR
- cfg->get_PHASE_ERROR_RMS_ERROR( d_PHASE_ERROR_RMS_ERROR );
- edtPHASE_ERROR_RMS_ERROR->Text = Double_To_AnsiString( d_PHASE_ERROR_RMS_ERROR );
-
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmCFGPhErr::btnSaveToCFGFileClick(TObject *Sender)
- {
- bool ok;
- int i;
- AnsiString asPath, asFileName;
- static bool isFirstSave = true;
- if( isFirstSave )
- {
- isFirstSave = false;
- if( getPathFromStr( Form_META_Factory->stCFGFile->Caption, asPath ) )
- {
- SaveDlg->InitialDir = asPath;
- if( getFilenameFromStr( Form_META_Factory->stCFGFile->Caption, asFileName ) )
- {
- SaveDlg->FileName = asFileName;
- }
- }
- else
- {
- if( getPathFromStr(Application->ExeName, asPath) )
- {
- SaveDlg->InitialDir = asPath;
- }
- else
- {
- SaveDlg->InitialDir = "C:\";
- }
- }
- }
- if( ! CheckFields() )
- {
- sbCFGPhErr->Panels->Items[0]->Text = (AnsiString) " Save phase error setting to file fail";
- Application->MessageBox( "Execution Failure : Save phase error setting to file", "FAILURE", MB_OK );
- return;
- }
- ok = SaveDlg->Execute();
- if( !ok )
- {
- sbCFGPhErr->Panels->Items[0]->Text = (AnsiString) " Save phase error setting to file fail";
- Application->MessageBox( "Execution Failure : Save phase error setting to file", "FAILURE", MB_OK );
- return;
- }
- cfg->SavePhErrToCfgFile( SaveDlg->FileName );
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmCFGPhErr::edtPHASE_ERROR_ARFCNCheck(TObject *Sender)
- {
- short sdata;
- AnsiString text;
- TEdit *edit = (TEdit*)Sender;
-
- char hint[][256] =
- { " value shall be 0~124 or 975~1023 ",
- " value shall be 512~885 ",
- " value shall be 512~810 ",
- " value shall be 128~251 ",
- };
- text = edit->Text;
- E_BANDSEL CurBand = Get_CurrentBand(edtPHASE_ERROR_BAND->Text);
- if (!IsValidARFCN(text, CurBand, sdata))
- {
- edit->Text = IntToStr(Default_ARFCN[CurBand]);
- ShowHintLabel(edit, hint[CurBand]);
- edit->SetFocus();
- return;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmCFGPhErr::edtPHASE_ERROR_BANDCheck(TObject *Sender)
- {
- int i;
- //int data;
- AnsiString text;
- TEdit *edit = (TEdit*)Sender;
- char hint[] = " Support band: GSM, DCS, PCS, GSM850 ";
- text = edit->Text;
- if( !IsValidBand( text ) )
- {
- ShowHintLabel( edit, hint );
- edit->Text = "GSM";
- edit->SetFocus();
- return;
- }
- edtPHASE_ERROR_ARFCNCheck( edtPHASE_ERROR_ARFCN );
- }
- //---------------------------------------------------------------------------
- bool TfrmCFGPhErr::CheckFields( void )
- {
- AnsiString text;
- text = edtPHASE_ERROR_BAND->Text; if( !IsValidBand( text ) ) { edtPHASE_ERROR_BANDCheck(edtPHASE_ERROR_BAND); return false; }
- as_PHASE_ERROR_BAND = text;
- cfg->set_PHASE_ERROR_BAND( as_PHASE_ERROR_BAND );
- E_BANDSEL CurBand = Get_CurrentBand(edtPHASE_ERROR_BAND->Text);
- text = edtPHASE_ERROR_ARFCN->Text; if( !IsValidARFCN( text, CurBand, m_sPHASE_ERROR_ARFCN ) ) { edtPHASE_ERROR_ARFCNCheck(edtPHASE_ERROR_ARFCN); return false; }
- cfg->set_PHASE_ERROR_ARFCN( m_sPHASE_ERROR_ARFCN );
- int CurFreqBand = Get_CurrentFreqBand(edtPHASE_ERROR_BAND->Text);
- text = edtPHASE_ERROR_PCL->Text; if( !IsValidCFGPCL( text, CurFreqBand, i_PHASE_ERROR_PCL ) ) { edtPHASE_ERROR_PCLCheck(edtPHASE_ERROR_PCL); return false; }
- cfg->set_PHASE_ERROR_PCL( i_PHASE_ERROR_PCL );
-
- return true;
- }
- //-----------------------------------------------------------------------
- void __fastcall TfrmCFGPhErr::edtPHASE_ERROR_PCLCheck(TObject *Sender)
- {
- int data;
- AnsiString text;
- TEdit *edit = (TEdit*)Sender;
- char hint[][256] =
- {
- " value shall be 4~31 ", // GSM400
- " value shall be 4~31 ", // GSM850
- " value shall be 4~31 ", // GSM900
- " value shall be 0~28 ", // DCS1800
- " value shall be 0~15 ", // PCS1900
- };
- // int Default_PCL = 10;
-
- text = edit->Text;
- int CurFreqBand = Get_CurrentFreqBand(edtPHASE_ERROR_BAND->Text);
- if( !IsValidCFGPCL( text, CurFreqBand, data ) )
- { ShowHintLabel( edit, hint[CurFreqBand] );
- edit->Text = IntToStr( Default_PCL );
- edit->SetFocus();
- return;
- }
- i_PHASE_ERROR_PCL = data;
- }
- //---------------------------------------------------------------------------
- E_BANDSEL TfrmCFGPhErr::Get_CurrentBand(AnsiString as_band)
- {
- AnsiString BAND_NAME[]=
- {
- "GSM",
- "DCS",
- "PCS",
- "GSM850"
- };
- E_BANDSEL band;
- for (int i=0; i<sizeof(BAND_NAME)/sizeof(BAND_NAME[0]); i++)
- {
- if( BAND_NAME[i].AnsiCompareIC(as_band) == 0 )
- {
- band = (E_BANDSEL) i;
- break;
- }
- }
- return band;
- }
- //---------------------------------------------------------------------------
- int TfrmCFGPhErr::Get_CurrentFreqBand(AnsiString &as_band)
- {
- AnsiString BAND_NAME[]=
- {
- "GSM400",
- "GSM850",
- "GSM",
- "DCS",
- "PCS",
- };
- for(int i=0; i<sizeof(BAND_NAME)/sizeof(BAND_NAME[0]); i++)
- {
- if( BAND_NAME[i].AnsiCompareIC(as_band) == 0 )
- {
- return i;
- }
- }
- }
- //---------------------------------------------------------------------------
- void TfrmCFGPhErr::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 TfrmCFGPhErr::HintTimerTimer(TObject *Sender)
- {
- HintTimer->Enabled = false;
- lblHint->Visible = false;
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmCFGPhErr::edtPHASE_ERROR_RMS_ERRORCheck(
- TObject *Sender)
- {
- double data;
- AnsiString text;
- TEdit *edit = (TEdit*)Sender;
- char hint[] = " Phase error is not valid ";
- text = edit->Text;
- if( !IsValidPhaseError( text, data ) )
- {
- ShowHintLabel( edit, hint );
- edit->Text = Double_To_AnsiString( 1.5 );
- edit->SetFocus();
- return;
- }
- d_PHASE_ERROR_RMS_ERROR = data;
- }
- //---------------------------------------------------------------------------