form_CFGAfc.cpp
上传用户:gelin96
上传日期:2017-01-08
资源大小:20993k
文件大小:14k
- /*****************************************************************************
- * 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_CFGAFC.cpp
- *
- * Project:
- * --------
- * Maui META APP
- *
- * Description:
- * ------------
- * AFC CFG file 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_CFGAfc.h"
- #include "META_Factory.h"
- #include "misc.h"
- #include "meta_utils.h"
- #ifndef _FT_UTILS_H_
- #include "ft_utils.h"
- #endif
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TfrmCFGAfc *frmCFGAfc;
- //static int Default_AFC = 4100;
- static int Default_N_AFC = 5;
- //---------------------------------------------------------------------------
- __fastcall TfrmCFGAfc::TfrmCFGAfc(TComponent* Owner)
- : TForm(Owner)
- {
- m_sDAC[0] = m_sDAC1;
- m_sDAC[1] = m_sDAC2;
- m_sINIT_AFC_DAC[0] = m_sMAX_INIT_AFC_DAC;
- m_sINIT_AFC_DAC[1] = m_sMIN_INIT_AFC_DAC;
- dAFC_SLOPE[0] = dMAX_AFC_SLOPE;
- dAFC_SLOPE[1] = dMIN_AFC_SLOPE;
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmCFGAfc::edtN_AFCCheck(TObject *Sender)
- {
- short sdata;
- AnsiString text;
- TEdit *edit = (TEdit*)Sender;
- char hint[] = "value shall be 0~32767 ";
- text = edit->Text;
- if (!IsValidAFCCount(text, sdata))
- {
- ShowHintLabel(edit, hint);
- edit->Text = IntToStr(Default_N_AFC);
- edit->SetFocus();
- return;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmCFGAfc::edtInitAfcDacCheck(TObject *Sender)
- {
- short s_data;
- AnsiString text;
- TEdit *edit = (TEdit*)Sender;
- char hint[] = " value shall be 0~8191 ";
- text = edit->Text;
- if (!IsValidAFC(text, s_data))
- {
- ShowHintLabel(edit, hint);
- edit->Text = IntToStr(Default_AFC);
- edit->SetFocus();
- return;
- }
- m_sINIT_AFC_DAC[edit->Tag] = s_data;
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmCFGAfc::edtAfcSlopeCheck(TObject *Sender)
- {
- int i;
- double data;
- AnsiString text;
- TEdit *edit = (TEdit*)Sender;
- char hint[] = " value shall be -32~31 ";
- text = edit->Text;
- if( !IsValidCFGAFCSlope( text, data ) )
- {
- ShowHintLabel( edit, hint );
- edit->SetFocus();
- return;
- }
- dAFC_SLOPE[edit->Tag] = data;
- }
- //---------------------------------------------------------------------------
- void TfrmCFGAfc::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 TfrmCFGAfc::CheckFields( void )
- {
- AnsiString text;
- text = edtAFC_BAND->Text; if( !IsValidBand( text ) ) { edtAfcBandCheck(edtAFC_BAND); return(false); }
- as_AFC_BAND = text;
- cfg->setAFC_BAND( as_AFC_BAND );
-
- E_BANDSEL CurBand = Get_CurrentBand(edtAFC_BAND->Text);
- text = edtAFC_ARFCN->Text; if( !IsValidARFCN( text, CurBand, m_sAFC_ARFCN) ) { edtAfcArfcnCheck(edtAFC_ARFCN); return(false); }
- cfg->setAFC_ARFCN(m_sAFC_ARFCN);
- text = edtN_AFC->Text; if( !IsValidAFCCount( text, m_sN_AFC ) ) { edtN_AFCCheck(edtN_AFC); return(false); }
- cfg->setN_AFC( m_sN_AFC );
- text = edtDAC1->Text; if( !IsValidAFC( text, m_sDAC1 ) ) { edtAfcDacCheck(edtDAC1); return(false); }
- cfg->set_DAC1(m_sDAC1);
- text = edtDAC2->Text; if( !IsValidAFC( text, m_sDAC2 ) ) { edtAfcDacCheck(edtDAC2); return(false); }
- cfg->set_DAC2(m_sDAC2);
- text = edtMAX_INIT_AFC_DAC->Text; if( !IsValidAFC( text, m_sMAX_INIT_AFC_DAC ) ) { edtAfcDacCheck(edtMAX_INIT_AFC_DAC); return(false); }
- cfg->set_MAX_INIT_AFC_DAC(m_sMAX_INIT_AFC_DAC);
- text = edtMIN_INIT_AFC_DAC->Text; if( !IsValidAFC( text, m_sMIN_INIT_AFC_DAC ) ) { edtAfcDacCheck(edtMIN_INIT_AFC_DAC); return(false); }
- cfg->set_MIN_INIT_AFC_DAC(m_sMIN_INIT_AFC_DAC);
- text = edtMAX_AFC_SLOPE->Text; if( !IsValidCFGAFCSlope( text, dMAX_AFC_SLOPE ) ) { edtAfcSlopeCheck(edtMAX_AFC_SLOPE); return(false); }
- cfg->set_MAX_AFC_SLOPE( dMAX_AFC_SLOPE );
- text = edtMIN_AFC_SLOPE->Text; if( !IsValidCFGAFCSlope( text, dMIN_AFC_SLOPE ) ) { edtAfcSlopeCheck(edtMIN_AFC_SLOPE); return(false); }
- cfg->set_MIN_AFC_SLOPE( dMIN_AFC_SLOPE );
- return true;
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmCFGAfc::HintTimerTimer(TObject *Sender)
- {
- HintTimer->Enabled = false;
- lblHint->Visible = false;
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmCFGAfc::btnLoadFromCFGFileClick(TObject *Sender)
- {
- bool ok;
- int i;
- AnsiString asPath, asFileName;
- static bool isFirstOpen = true;
- if( isFirstOpen )
- {
- isFirstOpen = false;
- if( getPathFromStr( frmFatcory->stCFGFile->Caption, asPath ) )
- {
- OpenDlg->InitialDir = asPath;
- if( getFilenameFromStr( frmFatcory->stCFGFile->Caption, asFileName ) )
- {
- OpenDlg->FileName = asFileName;
- }
- }
- else
- {
- if( getPathFromStr(Application->ExeName, asPath) )
- {
- OpenDlg->InitialDir = asPath;
- }
- else
- {
- OpenDlg->InitialDir = "C:\";
- }
- }
- }
- ok = OpenDlg->Execute();
- if( !ok )
- {
- sbCFGAfc->Panels->Items[0]->Text = (AnsiString) " Load AFC setting from file fail";
- Application->MessageBox( "Execution Failure : Load AFC setting from file fail", "FAILURE", MB_OK );
- return;
- }
- if (!cfg->ReadFromIniFile(OpenDlg->FileName))
- {
- sbCFGAfc->Panels->Items[0]->Text = (AnsiString) " Read CFG file fail";
- Application->MessageBox("Execution Failure : Read CFG file", "FAILURE", MB_OK);
- return;
- }
- // AFC BAND
- cfg->getAFC_BAND( as_AFC_BAND );
- edtAFC_BAND->Text = as_AFC_BAND;
- // AFC ARFCN
- cfg->getAFC_ARFCN(m_sAFC_ARFCN);
- edtAFC_ARFCN->Text = IntToStr(m_sAFC_ARFCN);
- // N_AFC
- cfg->getN_AFC(m_sN_AFC);
- edtN_AFC->Text = IntToStr(m_sN_AFC);
- // DAC1
- cfg->get_DAC1(m_sDAC1);
- edtDAC1->Text = IntToStr(m_sDAC1);
- // DAC2
- cfg->get_DAC2(m_sDAC2);
- edtDAC2->Text = IntToStr(m_sDAC2);
- // MAX_INIT_AFC_DAC
- cfg->get_MAX_INIT_AFC_DAC(m_sMAX_INIT_AFC_DAC);
- edtMAX_INIT_AFC_DAC->Text = IntToStr(m_sMAX_INIT_AFC_DAC);
- // MIN_INIT_AFC_DAC
- cfg->get_MIN_INIT_AFC_DAC( m_sMIN_INIT_AFC_DAC );
- edtMIN_INIT_AFC_DAC->Text = IntToStr( m_sMIN_INIT_AFC_DAC );
- // MAX_AFC_SLOPE
- cfg->get_MAX_AFC_SLOPE( dMAX_AFC_SLOPE );
- edtMAX_AFC_SLOPE->Text = Double_To_AnsiString( dMAX_AFC_SLOPE );
- // MIN_AFC_SLOPE
- cfg->get_MIN_AFC_SLOPE( dMIN_AFC_SLOPE );
- edtMIN_AFC_SLOPE->Text = Double_To_AnsiString( dMIN_AFC_SLOPE );
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmCFGAfc::FormClose(TObject *Sender,
- TCloseAction &Action)
- {
- if(cfg != NULL)
- {
- delete cfg;
- cfg = NULL;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmCFGAfc::btnSaveToCFGFileClick(TObject *Sender)
- {
- bool ok;
- int i;
- AnsiString asPath, asFileName;
- static bool isFirstSave = true;
- if( isFirstSave )
- {
- isFirstSave = false;
- if( getPathFromStr( frmFatcory->stCFGFile->Caption, asPath ) )
- {
- SaveDlg->InitialDir = asPath;
- if( getFilenameFromStr( frmFatcory->stCFGFile->Caption, asFileName ) )
- {
- SaveDlg->FileName = asFileName;
- }
- }
- else
- {
- if( getPathFromStr(Application->ExeName, asPath) )
- {
- SaveDlg->InitialDir = asPath;
- }
- else
- {
- SaveDlg->InitialDir = "C:\";
- }
- }
- }
- if( ! CheckFields() )
- {
- sbCFGAfc->Panels->Items[0]->Text = (AnsiString) " Save AFC setting to file fail";
- Application->MessageBox( "Execution Failure : Save AFC setting to file", "FAILURE", MB_OK );
- return;
- }
- ok = SaveDlg->Execute();
- if( !ok )
- {
- sbCFGAfc->Panels->Items[0]->Text = (AnsiString) " Save AFC setting to file fail";
- Application->MessageBox( "Execution Failure : Save AFC setting to file", "FAILURE", MB_OK );
- return;
- }
- cfg->SaveAfcToCfgFile( SaveDlg->FileName );
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmCFGAfc::FormShow(TObject *Sender)
- {
- if(cfg == NULL)
- {
- cfg = new TMETA_factory_cfg();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmCFGAfc::edtAfcDacCheck(TObject *Sender)
- {
- short sdata;
- AnsiString text;
- TEdit *edit = (TEdit*)Sender;
- char hint[] = " value shall be 0~8191 ";
- text = edit->Text;
- if (!IsValidAFC(text, sdata))
- {
- ShowHintLabel( edit, hint );
- edit->Text = IntToStr( Default_AFC );
- edit->SetFocus();
- return;
- }
- m_sDAC[edit->Tag] = sdata;
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmCFGAfc::edtAfcBandCheck(TObject *Sender)
- {
- int i;
- //int data;
- AnsiString text;
- TEdit *edit = (TEdit*)Sender;
- char hint[] = " Support band: GSM850, GSM, DCS, PCS ";
- text = edit->Text;
- if( !IsValidBand( text ) )
- {
- ShowHintLabel( edit, hint );
- edit->Text = "GSM";
- edit->SetFocus();
- return;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmCFGAfc::edtAfcArfcnCheck(TObject *Sender)
- {
- short sdata;
- E_BANDSEL CurBand = Get_CurrentBand(edtAFC_BAND->Text);
- AnsiString text;
- TEdit *edit = (TEdit*)Sender;
- // int Default_ARFCN[4] = { 0, 512, 512, 128 };
- 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;
- if (!IsValidARFCN(text, CurBand, sdata))
- {
- edit->Text = IntToStr( Default_ARFCN[CurBand] );
- ShowHintLabel( edit, hint[CurBand] );
- edit->SetFocus();
- return;
- }
- }
- //---------------------------------------------------------------------------
- E_BANDSEL TfrmCFGAfc::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;
- }