form_RFPathLoss.cpp
上传用户:gelin96
上传日期:2017-01-08
资源大小:20993k
文件大小:20k
- /*****************************************************************************
- * 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_RFPathLoss.cpp
- *
- * Project:
- * --------
- * Maui META APP
- *
- * Description:
- * ------------
- * RF RX path loss 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_RFPathLoss.h"
- #include "misc.h"
- #include "man_fdm.h"
- #include "form_main.h"
- //---------------------------------------------------------------------------
- //#define GSM850_CURRENT_BAND -1
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- //---------------------------------------------------------------------------
- TfrmPathLoss *frmPathLoss;
- //---------------------------------------------------------------------------
- static void CNF_ResetNVRAMData( void )
- {
- frmPathLoss->CNF_ResetNVRAMData();
- }
- //===========================================================================
- __fastcall TfrmPathLoss::TfrmPathLoss(TComponent* Owner)
- : TForm(Owner)
- {
- int i, j;
- for(i=0; i<FrequencyBandCount; i++)
- {
- for(j=0; j<PLTABLE_SIZE; j++)
- {
- RFCal_PathLoss.agcPathLoss[i][j].max_arfcn = -1;
- RFCal_PathLoss.agcPathLoss[i][j].gain_offset = 0;
- }
- }
- m_eCurBand = BANDSEL_GSM900;
- RF_AGC_Obj = 0;
- lastTabIndex = 0; // GSM 900
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmPathLoss::FormShow(TObject *Sender)
- {
- static bool init=true;
- if(init)
- {
- edtARFCN[ 0]=edtARFCN00; edtLoss[ 0]=edtLoss00;
- edtARFCN[ 1]=edtARFCN01; edtLoss[ 1]=edtLoss01;
- edtARFCN[ 2]=edtARFCN02; edtLoss[ 2]=edtLoss02;
- edtARFCN[ 3]=edtARFCN03; edtLoss[ 3]=edtLoss03;
- edtARFCN[ 4]=edtARFCN04; edtLoss[ 4]=edtLoss04;
- edtARFCN[ 5]=edtARFCN05; edtLoss[ 5]=edtLoss05;
- edtARFCN[ 6]=edtARFCN06; edtLoss[ 6]=edtLoss06;
- edtARFCN[ 7]=edtARFCN07; edtLoss[ 7]=edtLoss07;
- edtARFCN[ 8]=edtARFCN08; edtLoss[ 8]=edtLoss08;
- edtARFCN[ 9]=edtARFCN09; edtLoss[ 9]=edtLoss09;
- edtARFCN[10]=edtARFCN10; edtLoss[10]=edtLoss10;
- edtARFCN[11]=edtARFCN11; edtLoss[11]=edtLoss11;
- frmPathLoss->AutoScroll = true;
- ReDrawFields();
- init = false;
- }
- }
- //===========================================================================
- void TfrmPathLoss::ReDrawFields( void )
- {
- int i;
- int band = m_eCurBand+2;
- for(i=0; i<PLTABLE_SIZE-1; i++)
- { edtARFCN[i]->Text = RFCal_PathLoss.agcPathLoss[band][i].max_arfcn;
- edtLoss[i]->Text = RFCal_PathLoss.agcPathLoss[band][i].gain_offset/8.0;
- }
- }
- //===========================================================================
- void TfrmPathLoss::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 TfrmPathLoss::CheckFields( void )
- {
- int i;
- short sdata[2][PLTABLE_SIZE];
- int data[2][PLTABLE_SIZE];
- AnsiString text;
- E_BANDSEL band;
- //if(m_eCurBand == GSM850_CURRENT_BAND)
- //{ band = BANDSEL_GSM850; }
- //else
- { band = m_eCurBand;
- }
- for(i=0; i<PLTABLE_SIZE-1; i++)
- { text = edtARFCN[i]->Text; if( !IsValidARFCN2( text, band, sdata[0][i] ) ) { edtARFCNCheck(edtARFCN[i]); return(false); }
- if (sdata[0][i]==-1) break;
- text = edtLoss[i]->Text; if( !IsValidGain( text, data[1][i] ) ) { edtLossCheck(edtLoss[i]); return(false); }
- }
- band = m_eCurBand+2;
- for(i=0; i<PLTABLE_SIZE-1; i++)
- { RFCal_PathLoss.agcPathLoss[band][i].max_arfcn = data[0][i];
- if(data[0][i]==-1) break;
- RFCal_PathLoss.agcPathLoss[band][i].gain_offset = data[1][i];
- }
- return(true);
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmPathLoss::edtARFCNCheck(TObject *Sender)
- {
- AnsiString text;
- short sdata;
- E_BANDSEL band;
- 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 ",
- };
- //if (m_eCurBand == GSM850_CURRENT_BAND) // GSM850
- //{
- // band = BANDSEL_GSM850;
- //}
- //else
- {
- band = m_eCurBand;
- }
- text = edit->Text;
- if (!IsValidARFCN2(text, band, sdata))
- {
- ShowHintLabel( edit, hint[band] );
- edit->SetFocus();
- return;
- }
- band = m_eCurBand+2;
- RFCal_PathLoss.agcPathLoss[band][edit->Tag].max_arfcn = sdata;
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmPathLoss::edtLossCheck(TObject *Sender)
- {
- AnsiString text;
- int data;
- int band;
- TEdit *edit = (TEdit*)Sender;
- char hint[] = " character is not valid ";
- text = edit->Text;
- if( !IsValidGain( text, data ) )
- { ShowHintLabel( edit, hint );
- edit->SetFocus();
- return;
- }
- band = m_eCurBand+2;
- RFCal_PathLoss.agcPathLoss[band][edit->Tag].gain_offset = data;
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmPathLoss::tctlPathLossChange(TObject *Sender)
- {
- if (!frmMainSel->cbGSM850->Checked)
- {
- if (BANDSEL_GSM850 == (E_BANDSEL)tctlPathLoss->TabIndex)
- {
- tctlPathLoss->TabIndex = lastTabIndex;
- sbAGCPathLoss->Panels->Items[0]->Text = (AnsiString) " Please check GSM 850 on main menu";
- Application->MessageBox( "Please check GSM 850 on main menu", "FAILURE", MB_OK );
- return;
- }
- }
- if( ! CheckFields() )
- {
- tctlPathLoss->TabIndex = m_eCurBand;
- return;
- }
- //if (BANDSEL_GSM850 == (E_BANDSEL)tctlPathLoss->TabIndex) // GSM 850
- //{
- // m_eCurBand = GSM850_CURRENT_BAND;
- //}
- //else
- {
- m_eCurBand = (E_BANDSEL) tctlPathLoss->TabIndex;
- lastTabIndex = tctlPathLoss->TabIndex;
- }
- ReDrawFields();
- }
- //===========================================================================
- static void CNF_ReadFromNVRAM( void )
- { frmPathLoss->UploadFromFlashDone();
- }
- //-----------------------------------------------
- void __fastcall TfrmPathLoss::UploadFromFlashStart(TObject *Sender)
- {
- if( ! NVRAMMan->Get_IsInit() )
- { frmMainSel->mnuFDMDatabaseClick(Sender);
- }
- if( ! NVRAMMan->Get_IsInit() )
- {
- sbAGCPathLoss->Panels->Items[0]->Text = (AnsiString) " NVRAM database file initialization fail";
- Application->MessageBox( "Execution Failure : NVRAM database file initialization", "FAILURE", MB_OK );
- return;
- }
- RF_AGC_Obj->ConfirmCallback = ::CNF_ReadFromNVRAM;
- RF_AGC_Obj->REQ_Read_From_NVRAM_Start();
- CurrentPageLock();
- }
- //-----------------------------------------------
- void TfrmPathLoss::UploadFromFlashDone(void)
- {
- E_METAAPP_RESULT_T state = RF_AGC_Obj->Get_ConfirmState();
- CurrentPageReset();
- switch (state)
- {
- case METAAPP_SUCCESS:
- {
- l1cal_agcPathLoss_T* p_path_loss = RF_AGC_Obj->Get_PathLoss();
- RFCal_PathLoss = *p_path_loss;
- sbAGCPathLoss->Panels->Items[0]->Text = (AnsiString) " Upload AGC path loss setting from flash successfully";
- ReDrawFields();
- }
- break;
- case METAAPP_FAIL:
- {
- sbAGCPathLoss->Panels->Items[0]->Text = (AnsiString) " Upload AGC path loss setting from flash fail, please check the version of load and NVRAM database are same.";
- Application->MessageBox( "Execution Failure : Upload AGC Path Loss form flash, please check the version of load and NVRAM database are same.", "FAILURE", MB_OK );
- }
- break;
- case METAAPP_TIMEOUT:
- {
- sbAGCPathLoss->Panels->Items[0]->Text = (AnsiString) " Upload AGC path loss setting from flash timeout";
- Application->MessageBox( "Execution Timeout : Upload AGC Path Loss form flash", "TIMEOUT", MB_OK );
- }
- break;
- case METAAPP_STOP:
- {
- sbAGCPathLoss->Panels->Items[0]->Text = (AnsiString) " Upload AGC path loss setting from flash stop";
- }
- break;
- }
- }
- //---------------------------------------------------------------------------
- static void CNF_WriteToNVRAM( void )
- { frmPathLoss->DownloadToFlashDone();
- }
- //-----------------------------------------------
- void __fastcall TfrmPathLoss::DownloadToFlashStart(TObject *Sender)
- {
- if( !CheckFields() )
- {
- sbAGCPathLoss->Panels->Items[0]->Text = (AnsiString) " Download AGC path loss setting to flash fail";
- Application->MessageBox( "Execution Failure : Download AGC Path Loss form flash", "FAILURE", MB_OK );
- return;
- }
- if( ! NVRAMMan->Get_IsInit() )
- { frmMainSel->mnuFDMDatabaseClick(Sender);
- }
- if( ! NVRAMMan->Get_IsInit() )
- {
- sbAGCPathLoss->Panels->Items[0]->Text = (AnsiString) " NVRAM database file initialization fail";
- Application->MessageBox( "Execution Failure : NVRAM database file initialization fail", "FAILURE", MB_OK );
- return;
- }
- RF_AGC_Obj->Set_PathLoss(RFCal_PathLoss);
- RF_AGC_Obj->ConfirmCallback = ::CNF_WriteToNVRAM;
- RF_AGC_Obj->REQ_Write_To_NVRAM_Start();
- CurrentPageLock();
- }
- //-----------------------------------------------
- void TfrmPathLoss::DownloadToFlashDone(void)
- {
- E_METAAPP_RESULT_T state = RF_AGC_Obj->Get_ConfirmState();
- CurrentPageReset();
- switch (state)
- {
- case METAAPP_SUCCESS:
- {
- sbAGCPathLoss->Panels->Items[0]->Text = (AnsiString) " Download AGC path loss setting to flash successfully";
- }
- break;
- case METAAPP_FAIL:
- {
- sbAGCPathLoss->Panels->Items[0]->Text = (AnsiString) " Download AGC path loss setting to flash fail, please check the version of load and NVRAM database are same.";
- Application->MessageBox( "Execution Failure : Download AGC Path Loss form flash, please check the version of load and NVRAM database are same.", "FAILURE", MB_OK );
- }
- break;
- case METAAPP_TIMEOUT:
- {
- sbAGCPathLoss->Panels->Items[0]->Text = (AnsiString) " Download AGC path loss setting to flash timeout";
- Application->MessageBox( "Execution Timeout : Download AGC Path Loss form flash", "TIMEOUT", MB_OK );
- }
- break;
- case METAAPP_STOP:
- {
- sbAGCPathLoss->Panels->Items[0]->Text = (AnsiString) " Download AGC path loss setting to flash stop";
- }
- break;
- case METAAPP_NVRAM_LID_VER_NOT_SUPPORT:
- {
- sbAGCPathLoss->Panels->Items[0]->Text = (AnsiString) " NVRAM_EF_L1_AGCPATHLOSS_LID version is not support, please update META to latest version";
- Application->MessageBox("Execution Warning : NVRAM_EF_L1_AGCPATHLOSS_LID version is not support, please update META to latest version", "WARNING", MB_OK);
- }
- break;
- default:
- {
- }
- break;
- }
- }
- //===========================================================================
- void __fastcall TfrmPathLoss::btnLoadFromFileClick(TObject *Sender)
- {
- char str[512];
- bool ok;
- FrequencyBand FrequencyBandStart;
- ok = OpenDialog->Execute();
- if( !ok )
- {
- sbAGCPathLoss->Panels->Items[0]->Text = (AnsiString) " Load AGC Path Loss from file fail";
- Application->MessageBox( "Execution Failure : Load AGC Path Loss from file", "FAILURE", MB_OK );
- return;
- }
- strcpy(str, OpenDialog->FileName.c_str());
- if (frmMainSel->cbGSM850->Checked)
- {
- FrequencyBandStart = FrequencyBand850;
- }
- else
- { FrequencyBandStart = FrequencyBand900;
- }
- for (FrequencyBand freqband = FrequencyBandStart; freqband <= FrequencyBand1900; freqband++)
- {
- if (RF_AGC_Obj->RxLossSectionExist(str, freqband))
- {
- if (!RF_AGC_Obj->REQ_Read_From_File_Single_Band(str, freqband))
- {
- sbAGCPathLoss->Panels->Items[0]->Text = (AnsiString) " Load AGC Path Loss from file fail";
- Application->MessageBox( "Execution Failure : Load AGC Path Loss from file", "FAILURE", MB_OK );
- return;
- }
- }
- }
- l1cal_agcPathLoss_T* p_path_loss = RF_AGC_Obj->Get_PathLoss();
- RFCal_PathLoss = *p_path_loss;
- ReDrawFields();
- sbAGCPathLoss->Panels->Items[0]->Text = (AnsiString) " Load AGC Path Loss from file successfully";
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmPathLoss::btnSaveToFileClick(TObject *Sender)
- {
- char str[512];
- bool ok;
- ok = CheckFields();
- if(!ok)
- {
- sbAGCPathLoss->Panels->Items[0]->Text = (AnsiString) " Save AGC Path Loss to file fail";
- Application->MessageBox( "Execution Failure : Save AGC Path Loss to file", "FAILURE", MB_OK );
- return;
- }
- ok = SaveDialog->Execute();
- if( !ok )
- {
- sbAGCPathLoss->Panels->Items[0]->Text = (AnsiString) " Save AGC Path Loss to file fail";
- Application->MessageBox( "Execution Failure : Save AGC Path Loss to file", "FAILURE", MB_OK );
- return;
- }
- strcpy( str, SaveDialog->FileName.c_str() );
- RF_AGC_Obj->Set_PathLoss(RFCal_PathLoss);
- ok = RF_AGC_Obj->REQ_Write_To_File( str );
- if( !ok )
- {
- sbAGCPathLoss->Panels->Items[0]->Text = (AnsiString) " Save AGC Path Loss to file fail";
- Application->MessageBox( "Execution Failure : Save AGC Path Loss to file", "FAILURE", MB_OK );
- }
- sbAGCPathLoss->Panels->Items[0]->Text = (AnsiString) " Save AGC Path Loss to file successfully";
- }
- //===========================================================================
- void __fastcall TfrmPathLoss::HintTimerTimer(TObject *Sender)
- {
- HintTimer->Enabled = false;
- lblHint->Visible = false;
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmPathLoss::btnChangeDBClick(TObject *Sender)
- {
- CurrentPageLock();
- frmMainSel->mnuFDMDatabaseClick(Sender);
- if( ! NVRAMMan->Get_IsInit() )
- {
- sbAGCPathLoss->Panels->Items[0]->Text = (AnsiString) " NVRAM database file initialization fail";
- Application->MessageBox( "Execution Failure : NVRAM database file initialization fail", "FAILURE", MB_OK );
- return;
- }
- sbAGCPathLoss->Panels->Items[0]->Text = (AnsiString) " Change NVRAM database file successfully";
- CurrentPageReset();
- }
- //---------------------------------------------------------------------------
- void __fastcall TfrmPathLoss::btnResetNVRAMDataClick(TObject *Sender)
- {
- if( ! NVRAMMan->Get_IsInit() )
- { frmMainSel->mnuFDMDatabaseClick(Sender);
- }
- if( ! NVRAMMan->Get_IsInit() )
- {
- sbAGCPathLoss->Panels->Items[0]->Text = (AnsiString) " NVRAM database file initialization fail";
- Application->MessageBox( "Execution Failure : NVRAM database file initialization", "FAILURE", MB_OK );
- return;
- }
- RF_AGC_Obj->ConfirmCallback = ::CNF_ResetNVRAMData;
- RF_AGC_Obj->REQ_Reset_NVRAM_Data();
- CurrentPageLock();
- }
- //-----------------------------------------------
- void TfrmPathLoss::CNF_ResetNVRAMData( void )
- {
- int state = RF_AGC_Obj->Get_ConfirmState();
- CurrentPageReset();
- if( state==METAAPP_SUCCESS )
- {
- sbAGCPathLoss->Panels->Items[0]->Text = (AnsiString) " Reset AGC path loss setting in flash successfully";
- }
- else if( state==METAAPP_FAIL )
- {
- sbAGCPathLoss->Panels->Items[0]->Text = (AnsiString) " Reset AGC path loss setting in flash fail, please check the version of load and NVRAM database are same.";
- Application->MessageBox( "Execution Failure : Reset AGC path loss setting in flash, please check the version of load and NVRAM database are same.", "FAILURE", MB_OK );
- }
- else if( state==METAAPP_TIMEOUT )
- {
- sbAGCPathLoss->Panels->Items[0]->Text = (AnsiString) " Reset AGC path loss setting in flash timeout";
- Application->MessageBox( "Execution Timeout : Reset AGC path loss setting in flash", "TIMEOUT", MB_OK );
- }
- else if( state==METAAPP_STOP )
- {
- sbAGCPathLoss->Panels->Items[0]->Text = (AnsiString) " Reset AGC path loss setting in flash stop";
- // Application->MessageBox( "Execution Stop : Reset AGC path loss setting in flash", "STOP", MB_OK );
- }
- }
- //---------------------------------------------------------------------------
- void TfrmPathLoss::CurrentPageLock( void )
- {
- btnUploadFromFlash->Enabled = false;
- btnDownloadToFlash->Enabled = false;
- // btnResetNVRAMData->Enabled = false;
- btnChangeDB->Enabled = false;
- btnLoadFromFile->Enabled = false;
- btnSaveToFile->Enabled = false;
- }
- //----------------------------------------------------------------------------
- void TfrmPathLoss::CurrentPageReset( void )
- {
- btnUploadFromFlash->Enabled = true;
- btnDownloadToFlash->Enabled = true;
- // btnResetNVRAMData->Enabled = true;
- btnChangeDB->Enabled = true;
- btnLoadFromFile->Enabled = true;
- btnSaveToFile->Enabled = true;
- }