rf_pmch_sweep.cpp
上传用户:gelin96
上传日期:2017-01-08
资源大小:20993k
文件大小:16k
- /*****************************************************************************
- * 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:
- * ---------
- * rf_pmch_sweep.cpp
- *
- * Project:
- * --------
- * Maui META APP
- *
- * Description:
- * ------------
- * RF PM channel sweep 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>
- #include <math.h>
- #pragma hdrstop
- #include "rf_pmch_sweep.h"
- #include "meta_utils.h"
- #ifndef _FORM_RFTOOL_H_
- #include "form_rftool.h"
- #endif
- #include "man_dll.h"
- // equipment
- #include "ageCommon.h"
- #include "age1968A.h"
- #include "cmu200.h"
- #ifndef _RCT_COMMON_H_
- #include "rct_common.h"
- #endif
- #ifndef _RCT_CTRL_H_
- #include "rct_ctrl.h"
- #endif
- // misc
- #ifndef _BAND_UTILS_H_
- #include "band_utils.h"
- #endif
- //---------------------------------------------------------------------------
- //#define ONE_SECOND 1
- //------------------------------------------------------------------------------
- //==============================================================================
- static void ConfirmCallback_PMCS( void )
- {
- if(frmRFTool->pt_PMCH_sweep != NULL )
- {
- frmRFTool->pt_PMCH_sweep->Resume();
- }
- }
- //------------------------------------------------------------------------------
- static void cb_rf_stop_PMCH()
- {
- if(frmRFTool->pt_PMCH_sweep != NULL )
- {
- frmRFTool->pt_PMCH_sweep->Resume();
- }
- }
- //==============================================================================
- void _fastcall CRF_PMCH_SWEEP::ShowMsg()
- {
- ShowMessage( as_Msg );
- }
- //------------------------------------------------------------------------------
- void _fastcall CRF_PMCH_SWEEP::SyncShowMsg(AnsiString as)
- {
- as_Msg = as;
- Synchronize( ShowMsg );
- }
- //=========================================================================================
- __fastcall CRF_PMCH_SWEEP::CRF_PMCH_SWEEP(
- bool CreateSuspended,
- sPMCHSweep *p_pmch_sweep
- // ViSession &vs_Age196x,
- // AnsiString &as_TaModel
- ): TThread(CreateSuspended)
- {
- pmch_sweep = p_pmch_sweep;
- b_title = true;
- // as_pAgeTaModel = &as_TaModel;
- // pvi = &vs_Age196x;
- }
- //---------------------------------------------------------------------------
- void __fastcall CRF_PMCH_SWEEP::Execute()
- {
- rct.device_type = pmch_sweep->e_device_type;
- if (!PMCH_CfgRead())
- {
- SyncShowMsg("Read CFG file fail");
- return;
- }
- if (!rct_ctrl.RCT_Init(&rct, BandIdx_To_FreqBandString(pmch_sweep->e_band)))
- {
- SyncShowMsg("Initialize equipment fail");
- return;
- }
- if (!PMCH_Sweep())
- {
- return;
- }
- this->OnTerminate = pmch_sweep->ne_onTermSuccess;
- }
- //---------------------------------------------------------------------------
- bool __fastcall CRF_PMCH_SWEEP::PMCH_CfgRead( void )
- {
- if (pmch_sweep->e_device_type == AGILENT_8960)
- {
- if((! pmch_sweep->rf_cfg->getGSM400_CableLoss( rct.age.d400 )) ||
- (! pmch_sweep->rf_cfg->getGSM850_CableLoss( rct.age.d850 )) ||
- (! pmch_sweep->rf_cfg->getGSM900_CableLoss( rct.age.d900 )) ||
- (! pmch_sweep->rf_cfg->getDCS1800_CableLoss( rct.age.d1800 )) ||
- (! pmch_sweep->rf_cfg->getPCS1900_CableLoss( rct.age.d1900 ))
- )
- {
- SyncShowMsg( " Agilent 8960 read config file (cable loss) fail " );
- return false;
- }
- if(! pmch_sweep->rf_cfg->getTimeOut( rct.age.TMO ) )
- {
- SyncShowMsg( "Get Time Out from file fail" );
- return false;
- }
- if(! pmch_sweep->rf_cfg->getGPIB_Addr( rct.age.ADD ) )
- {
- SyncShowMsg( "Get GPIB address from file fail" );
- return false;
- }
- }
- else // CMU 200
- {
- if(
- (! pmch_sweep->rf_cfg->getCMU200_INPUT_GSM850_CableLoss( rct.cmu.loss_gsm850_i )) ||
- (! pmch_sweep->rf_cfg->getCMU200_INPUT_GSM900_CableLoss( rct.cmu.loss_gsm_i )) ||
- (! pmch_sweep->rf_cfg->getCMU200_INPUT_DCS1800_CableLoss( rct.cmu.loss_dcs_i )) ||
- (! pmch_sweep->rf_cfg->getCMU200_INPUT_PCS1900_CableLoss( rct.cmu.loss_pcs_i ))
- )
- {
- SyncShowMsg( " CMU200 read config file (input cable loss) fail " );
- return false;
- }
- //*************************************************************
- //************************************************************
- if(
- (! pmch_sweep->rf_cfg->getCMU200_OUTPUT_GSM850_CableLoss( rct.cmu.loss_gsm850_o )) ||
- (! pmch_sweep->rf_cfg->getCMU200_OUTPUT_GSM900_CableLoss( rct.cmu.loss_gsm_o )) ||
- (! pmch_sweep->rf_cfg->getCMU200_OUTPUT_DCS1800_CableLoss( rct.cmu.loss_dcs_o )) ||
- (! pmch_sweep->rf_cfg->getCMU200_OUTPUT_PCS1900_CableLoss( rct.cmu.loss_pcs_o ))
- )
- {
- SyncShowMsg( " CMU200 read config file (output cable loss) fail " );
- return false;
- }
- if(! pmch_sweep->rf_cfg->getCMU200_TimeOut( rct.cmu.TMO ) )
- {
- SyncShowMsg( "Get Time Out from file fail" );
- return false;
- }
- if(! pmch_sweep->rf_cfg->getCMU200_GPIB_Addr( rct.cmu.ADD ) )
- {
- SyncShowMsg( "Get GPIB address from file fail" );
- return false;
- }
- rct.cmu.ADD = rct.cmu.ADD.SubString(0, rct.cmu.ADD.Pos("::INSTR")-1);
- }
- return true;
- }
- //---------------------------------------------------------------------------
- bool __fastcall CRF_PMCH_SWEEP::PMCH_Sweep( void )
- {
- const char BAND_STR[4][10] =
- { "GSM900 ",
- "DCS1800",
- "PCS1900",
- "GSM850"
- };
- ViInt16 vi_Band;
- char buf[40000], buf1[10000];
- switch ( pmch_sweep->e_band )
- {
- case BANDSEL_GSM900:
- vi_Band = age1960_EGSM_BAND;
- break;
- case BANDSEL_DCS1800:
- vi_Band = age1960_DCS1800_BAND;
- break;
- case BANDSEL_PCS1900:
- vi_Band = age1960_PCS1900_BAND;
- break;
- case BANDSEL_GSM850:
- vi_Band = age1960_GSM850_BAND;
- break;
- default:
- break;
- }; // switch
- //int i;
- if( ! rct_ctrl.RCT_cellBand( &rct, vi_Band ) )
- {
- if ( pmch_sweep->e_device_type == AGILENT_8960)
- {
- SyncShowMsg( " Agilent 8960 set cell band fail ");
- }
- else
- {
- SyncShowMsg( " CMU 200 set cell band fail ");
- }
- return false;
- }
- if( ! rct_ctrl.RCT_ContModTran( &rct ) )
- {
- if ( pmch_sweep->e_device_type == AGILENT_8960)
- {
- SyncShowMsg( " Agilent 8960 set continuous transmition mode fail " );
- }
- else
- {
- SyncShowMsg( " CMU 200 set continuous transmition mode fail " );
- }
- return false;
- }
- if( ! rct_ctrl.RCT_cellPower( &rct, pmch_sweep->d_P_DL) )
- {
- if ( pmch_sweep->e_device_type == AGILENT_8960)
- {
- SyncShowMsg( " Agilent 8960 set downlink power fail " );
- }
- else
- {
- SyncShowMsg( " CMU 200 set downlink power fail " );
- }
- return false;
- }
- for(int arfcn=pmch_sweep->s_arfcn_start; arfcn<=pmch_sweep->s_arfcn_stop; arfcn +=pmch_sweep->s_arfcn_step )
- {
- if ( this->Terminated )
- {
- this->OnTerminate = pmch_sweep->ne_onTermByUser;
- return false;
- }
- if( pmch_sweep->e_band == BANDSEL_GSM900 && arfcn>=125 && arfcn < 975)
- {
- arfcn = arfcn - 125 + 975;
- }
- if( ! rct_ctrl.RCT_BCHARFCN( &rct, arfcn ) )
- {
- SyncShowMsg( "Set equipment BCH ARFCN="+IntToStr(arfcn)+" fail" );
- return false;
- }
- Sleep(200);
- RF_PM_Object.ConfirmCallback = ::ConfirmCallback_PMCS;
- RF_PM_Object.REQ_Start( pmch_sweep->e_band, arfcn, pmch_sweep->pm_per_frame, pmch_sweep->pm_count,
- NULL, true, pmch_sweep->gain, pmch_sweep->gain, 0 );
- this->Suspend();
- if( RF_PM_Object.Get_ConfirmState() != METAAPP_SUCCESS )
- {
- SyncShowMsg( "Power measurement fail" );
- return false;
- }
- RfPm_Cnf RFCnf_PM = RF_PM_Object.Get_RfPmCnf();
- buf[0]=' ';
- if( b_title )
- {
- b_title = false;
- if( RFCnf_PM.extra_info.valid && RFCnf_PM.extra_info.validSamples )
- {
- sprintf( buf, " DSP Ant. Used Valid " );
- pmch_sweep->st_Log->Add(buf);
- frmRFTool->write_PMCH_log_file(pmch_sweep->as_Log);
- sprintf( buf, " BAND ARFCN Power Power Gain Deviation I_DC Q_DC sample" );
- pmch_sweep->st_Log->Add(buf);
- frmRFTool->write_PMCH_log_file(pmch_sweep->as_Log);
- sprintf( buf, "=========================================================================" );
- pmch_sweep->st_Log->Add(buf);
- frmRFTool->write_PMCH_log_file(pmch_sweep->as_Log);
- }
- else
- {
- sprintf( buf, " DSP Ant. Used " );
- pmch_sweep->st_Log->Add(buf);
- frmRFTool->write_PMCH_log_file(pmch_sweep->as_Log);
- sprintf( buf, " BAND ARFCN Power Power Gain Deviation " );
- pmch_sweep->st_Log->Add(buf);
- frmRFTool->write_PMCH_log_file(pmch_sweep->as_Log);
- sprintf( buf, "========================================================" );
- pmch_sweep->st_Log->Add(buf);
- frmRFTool->write_PMCH_log_file(pmch_sweep->as_Log);
- }
- }
- if(RFCnf_PM.power!=1)
- {
- if(RFCnf_PM.deviation >= 0)
- {
- if( RFCnf_PM.extra_info.valid && RFCnf_PM.extra_info.validSamples )
- {
- sprintf( buf, "%s %4d %8.3f %8.3f %8.3f %8.3f %4d %4d %4d",
- BAND_STR[pmch_sweep->e_band],
- arfcn,
- (RFCnf_PM.power+RFCnf_PM.usedGain)/8.0,
- RFCnf_PM.power/8.0,
- RFCnf_PM.usedGain/8.0,
- sqrt(RFCnf_PM.deviation)/8.0,
- RFCnf_PM.extra_info.iOffset,
- RFCnf_PM.extra_info.qOffset,
- RFCnf_PM.extra_info.validSamples);
- }
- else
- {
- sprintf( buf, "%s %4d %8.3f %8.3f %8.3f %8.3f ",
- BAND_STR[pmch_sweep->e_band],
- arfcn,
- (RFCnf_PM.power+RFCnf_PM.usedGain)/8.0,
- RFCnf_PM.power/8.0,
- RFCnf_PM.usedGain/8.0,
- sqrt(RFCnf_PM.deviation)/8.0 );
- }
- }
- else
- {
- if( RFCnf_PM.extra_info.valid && RFCnf_PM.extra_info.validSamples )
- {
- sprintf( buf, "%s %4d %8.3f %8.3f %8.3f invalid %4d %4d %4d",
- BAND_STR[pmch_sweep->e_band],
- arfcn,
- (RFCnf_PM.power+RFCnf_PM.usedGain)/8.0,
- RFCnf_PM.power/8.0,
- RFCnf_PM.usedGain/8.0,
- RFCnf_PM.extra_info.iOffset,
- RFCnf_PM.extra_info.qOffset,
- RFCnf_PM.extra_info.validSamples );
- }
- else
- {
- sprintf( buf, "%s %4d %8.3f %8.3f %8.3f invalid ",
- BAND_STR[pmch_sweep->e_band],
- arfcn,
- (RFCnf_PM.power+RFCnf_PM.usedGain)/8.0,
- RFCnf_PM.power/8.0,
- RFCnf_PM.usedGain/8.0);
- }
- }
- }
- else
- {
- if( RFCnf_PM.extra_info.valid && RFCnf_PM.extra_info.validSamples )
- {
- sprintf( buf, "%s %4d Invalid Invalid %8.3f Invalid %4d %4d %4d",
- BAND_STR[pmch_sweep->e_band],
- arfcn,
- RFCnf_PM.usedGain/8.0,
- RFCnf_PM.extra_info.iOffset,
- RFCnf_PM.extra_info.qOffset,
- RFCnf_PM.extra_info.validSamples );
- }
- else
- {
- sprintf( buf, "%s %4d Invalid Invalid %8.3f Invalid ",
- BAND_STR[pmch_sweep->e_band],
- arfcn,
- RFCnf_PM.usedGain/8.0
- );
- }
- }
- pmch_sweep->st_Log->Add(buf);
- frmRFTool->write_PMCH_log_file(pmch_sweep->as_Log);
- Sleep(50);
- RF_STOP_Object.REQ_Start();
- }
- return true;
- }