rf_sn_sweep.cpp
上传用户:gelin96
上传日期:2017-01-08
资源大小:20993k
文件大小:19k
- /*****************************************************************************
- * 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) 2001
- *
- *****************************************************************************/
- /*****************************************************************************
- *
- * Filename:
- * ---------
- * rf_sn_sweep.cpp
- *
- * Project:
- * --------
- * Maui META APP
- *
- * Description:
- * ------------
- * RF saturate and noise floor point auto search 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 "form_RFTool.h"
- #include "rf_pmch_sweep.h"
- #include "meta_utils.h"
- //#include "Crystal_INIFileHandle.h"
- #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
- //---------------------------------------------------------------------------
- //------------------------------------------------------------------------------
- //==============================================================================
- static void ConfirmCallback_SN( void )
- {
- if(frmRFTool->m_pt_SN_sweep != NULL )
- {
- frmRFTool->m_pt_SN_sweep->Resume();
- }
- }
- //------------------------------------------------------------------------------
- static void cb_rf_stop_SN()
- {
- if(frmRFTool->m_pt_SN_sweep != NULL )
- {
- frmRFTool->m_pt_SN_sweep->Resume();
- }
- }
- //==============================================================================
- void _fastcall CRF_SN_SWEEP::ShowMsg()
- {
- ShowMessage( as_Msg );
- }
- //------------------------------------------------------------------------------
- void _fastcall CRF_SN_SWEEP::SyncShowMsg(AnsiString as)
- {
- as_Msg = as;
- Synchronize( ShowMsg );
- }
- //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- void _fastcall CRF_SN_SWEEP::FillSNResult( void )
- {
- frmRFTool->FillSNResult( tb_title, ts_snresult );
- }
- //------------------------------------------------------------------------------
- void _fastcall CRF_SN_SWEEP::SyncFillSNResult(bool is_title, S_SNResult &sn_result)
- {
- ts_snresult = sn_result;
- tb_title = is_title;
- Synchronize( FillSNResult );
- }
- //==============================================================================
- __fastcall CRF_SN_SWEEP::CRF_SN_SWEEP(
- bool CreateSuspended,
- S_SNSweep *p_Sn_Sweep
- ): TThread(CreateSuspended)
- {
- p_sn_sweep = p_Sn_Sweep;
- b_title = true;
- }
- //---------------------------------------------------------------------------
- void __fastcall CRF_SN_SWEEP::Execute()
- {
- rct.device_type = p_sn_sweep->e_device_type;
- if( ! SN_CfgRead() )
- {
- SyncShowMsg( "Read CFG file fail" );
- return;
- }
- if( ! rct_ctrl.RCT_Init( &rct, BandIdx_To_FreqBandString(p_sn_sweep->e_band) ) )
- {
- SyncShowMsg( "Initialize equipment fail" );
- return;
- }
- if( ! SN_Sweep() )
- {
- return;
- }
- this->OnTerminate = p_sn_sweep->ne_onTermSuccess;
- }
- //---------------------------------------------------------------------------
- bool __fastcall CRF_SN_SWEEP::SN_CfgRead( void )
- {
- if( p_sn_sweep->e_device_type == AGILENT_8960 )
- {
- if((! p_sn_sweep->rf_cfg->getGSM400_CableLoss( rct.age.d400 )) ||
- (! p_sn_sweep->rf_cfg->getGSM850_CableLoss( rct.age.d850 )) ||
- (! p_sn_sweep->rf_cfg->getGSM900_CableLoss( rct.age.d900 )) ||
- (! p_sn_sweep->rf_cfg->getDCS1800_CableLoss( rct.age.d1800 )) ||
- (! p_sn_sweep->rf_cfg->getPCS1900_CableLoss( rct.age.d1900 ))
- )
- {
- SyncShowMsg( " Agilent 8960 read config file (cable loss) fail " );
- return false;
- }
- if(! p_sn_sweep->rf_cfg->getTimeOut( rct.age.TMO ) )
- {
- SyncShowMsg( "Get Time Out from file fail" );
- return false;
- }
- if(! p_sn_sweep->rf_cfg->getGPIB_Addr( rct.age.ADD ) )
- {
- SyncShowMsg( "Get GPIB address from file fail" );
- return false;
- }
- }
- else // CMU 200
- {
- if(
- (! p_sn_sweep->rf_cfg->getCMU200_INPUT_GSM850_CableLoss( rct.cmu.loss_gsm850_i )) ||
- (! p_sn_sweep->rf_cfg->getCMU200_INPUT_GSM900_CableLoss( rct.cmu.loss_gsm_i )) ||
- (! p_sn_sweep->rf_cfg->getCMU200_INPUT_DCS1800_CableLoss( rct.cmu.loss_dcs_i )) ||
- (! p_sn_sweep->rf_cfg->getCMU200_INPUT_PCS1900_CableLoss( rct.cmu.loss_pcs_i ))
- )
- {
- SyncShowMsg( " CMU200 read config file (input cable loss) fail " );
- return false;
- }
- //*************************************************************
- //************************************************************
- if(
- (! p_sn_sweep->rf_cfg->getCMU200_OUTPUT_GSM850_CableLoss( rct.cmu.loss_gsm850_o )) ||
- (! p_sn_sweep->rf_cfg->getCMU200_OUTPUT_GSM900_CableLoss( rct.cmu.loss_gsm_o )) ||
- (! p_sn_sweep->rf_cfg->getCMU200_OUTPUT_DCS1800_CableLoss( rct.cmu.loss_dcs_o )) ||
- (! p_sn_sweep->rf_cfg->getCMU200_OUTPUT_PCS1900_CableLoss( rct.cmu.loss_pcs_o ))
- )
- {
- SyncShowMsg( " CMU200 read config file (output cable loss) fail " );
- return false;
- }
- if(! p_sn_sweep->rf_cfg->getCMU200_TimeOut( rct.cmu.TMO ) )
- {
- SyncShowMsg( "Get Time Out from file fail" );
- return false;
- }
- if(! p_sn_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_SN_SWEEP::SN_Sweep( void )
- {
- //const char BAND_STR[4][10] =
- //{
- // "GSM900 ",
- // "DCS1800",
- // "PCS1900",
- // "GSM850"
- //};
- ViInt16 vi_Band;
- char buf[40000], buf1[10000];
- switch ( p_sn_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
- if( ! rct_ctrl.RCT_cellBand( &rct, vi_Band ) )
- {
- if ( p_sn_sweep->e_device_type == AGILENT_8960)
- {
- SyncShowMsg( " Agilent 8960 set cell e_band fail ");
- }
- else
- {
- SyncShowMsg( " CMU 200 set cell e_band fail ");
- }
- return false;
- }
- if( ! rct_ctrl.RCT_ContModTran( &rct ) )
- {
- if ( p_sn_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_BCHARFCN( &rct, p_sn_sweep->s_arfcn ) )
- {
- SyncShowMsg( "Set equipment BCH ARFCN="+IntToStr(p_sn_sweep->s_arfcn)+" fail" );
- return false;
- }
- SyncFillSNResult( true, ts_snresult );
- if( ! p_sn_sweep->b_gain_change_first )// DN power change first
- {
- double d_dn;
- for( int i_gain=p_sn_sweep->min_gain; (i_gain<=p_sn_sweep->max_gain && p_sn_sweep->min_gain < p_sn_sweep->max_gain)||(i_gain>=p_sn_sweep->max_gain && p_sn_sweep->min_gain > p_sn_sweep->max_gain); i_gain+=p_sn_sweep->gain_step )
- {
- bool b_saturate = false;
- bool b_noise_floor = false;
- ts_snresult.d_saturate_equ_power = 0;
- ts_snresult.d_noise_floor_equ_power = 0;
- ts_snresult.d_saturate_dsppwr = 0;
- ts_snresult.d_saturate_antpwr = 0;
- ts_snresult.d_noise_floor_dsppwr = 0;
- ts_snresult.d_noise_floor_antpwr = 0;
- Sleep(200);
- // int min_gain, max_gain;
- for( d_dn=p_sn_sweep->d_min_P_DL; (d_dn<=p_sn_sweep->d_max_P_DL && p_sn_sweep->d_min_P_DL < p_sn_sweep->d_max_P_DL) || (d_dn>=p_sn_sweep->d_max_P_DL && p_sn_sweep->d_min_P_DL > p_sn_sweep->d_max_P_DL); d_dn+=p_sn_sweep->d_P_DL_step )
- {
- if( ! rct_ctrl.RCT_cellPower( &rct, d_dn ) )
- {
- if ( p_sn_sweep->e_device_type == AGILENT_8960)
- {
- SyncShowMsg( " Agilent 8960 set downlink power fail " );
- }
- else
- {
- SyncShowMsg( " CMU 200 set downlink power fail " );
- }
- return false;
- }
- if ( this->Terminated )
- {
- this->OnTerminate = p_sn_sweep->ne_onTermByUser;
- return false;
- }
- RF_PM_Object.ConfirmCallback = ::ConfirmCallback_SN;
- RF_PM_Object.REQ_Start( p_sn_sweep->e_band, p_sn_sweep->s_arfcn, p_sn_sweep->pm_per_frame, p_sn_sweep->pm_count,
- NULL, true, i_gain, i_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();
- ts_snresult.i_saturate_used_gain = RFCnf_PM.usedGain/8.0;
- ts_snresult.i_noise_floor_used_gain = RFCnf_PM.usedGain/8.0;
-
- if( RFCnf_PM.ok && RFCnf_PM.power != 1)
- {
- if( (RFCnf_PM.power / 8.0 + p_sn_sweep->d_threshold) <= d_dn )
- {
- b_saturate = true;
- ts_snresult.i_band_idx = p_sn_sweep->e_band;
- ts_snresult.i_arfcn = p_sn_sweep->s_arfcn;
- ts_snresult.i_saturate_used_gain = RFCnf_PM.usedGain/8.0;
- ts_snresult.d_saturate_equ_power = d_dn;
- ts_snresult.d_saturate_dsppwr = (RFCnf_PM.power + RFCnf_PM.usedGain)/8.0;
- ts_snresult.d_saturate_antpwr = RFCnf_PM.power/8.0;
- ts_snresult.d_linear_range = ts_snresult.d_saturate_dsppwr - ts_snresult.d_noise_floor_dsppwr;
- if( p_sn_sweep->d_min_P_DL < p_sn_sweep->d_max_P_DL )
- {
- SyncFillSNResult( false, ts_snresult );
- break;
- }
- }
- else if( (RFCnf_PM.power / 8.0 - p_sn_sweep->d_threshold) >= d_dn )
- {
- b_noise_floor = true;
- ts_snresult.i_band_idx = p_sn_sweep->e_band;
- ts_snresult.i_arfcn = p_sn_sweep->s_arfcn;
- ts_snresult.d_noise_floor_equ_power = d_dn;
- ts_snresult.i_noise_floor_used_gain = RFCnf_PM.usedGain/8.0;
- ts_snresult.d_noise_floor_dsppwr = (RFCnf_PM.power + RFCnf_PM.usedGain)/8.0;
- ts_snresult.d_noise_floor_antpwr = RFCnf_PM.power/8.0;
- ts_snresult.d_linear_range = ts_snresult.d_saturate_dsppwr - ts_snresult.d_noise_floor_dsppwr;
- if( p_sn_sweep->d_min_P_DL > p_sn_sweep->d_max_P_DL )
- {
- SyncFillSNResult( false, ts_snresult );
- break;
- }
- }
- }
- Sleep(50);
- RF_STOP_Object.REQ_Start();
- }
- if( ( (! b_saturate) && (p_sn_sweep->d_min_P_DL < p_sn_sweep->d_max_P_DL) ) ||
- ( (! b_noise_floor) && (p_sn_sweep->d_min_P_DL > p_sn_sweep->d_max_P_DL) )
- )
- {
- ts_snresult.i_band_idx = p_sn_sweep->e_band;
- ts_snresult.i_arfcn = p_sn_sweep->s_arfcn;
- ts_snresult.d_linear_range = ts_snresult.d_saturate_dsppwr - ts_snresult.d_noise_floor_dsppwr;
- SyncFillSNResult( false, ts_snresult );
- }
- }
- }
- if( p_sn_sweep->b_gain_change_first )
- {
- for( double d_dn=p_sn_sweep->d_min_P_DL; (d_dn<=p_sn_sweep->d_max_P_DL && p_sn_sweep->d_min_P_DL < p_sn_sweep->d_max_P_DL) || (d_dn>=p_sn_sweep->d_max_P_DL && p_sn_sweep->d_min_P_DL > p_sn_sweep->d_max_P_DL); d_dn+=p_sn_sweep->d_P_DL_step )
- {
- bool b_saturate = false;
- bool b_noise_floor = false;
- ts_snresult.d_saturate_equ_power = d_dn;
- ts_snresult.d_saturate_dsppwr = 0;
- ts_snresult.d_saturate_antpwr = 0;
- ts_snresult.d_noise_floor_equ_power = d_dn;
- ts_snresult.d_noise_floor_dsppwr = 0;
- ts_snresult.d_noise_floor_antpwr = 0;
- if( ! rct_ctrl.RCT_cellPower( &rct, d_dn ) )
- {
- if ( p_sn_sweep->e_device_type == AGILENT_8960)
- {
- SyncShowMsg( " Agilent 8960 set downlink power fail " );
- }
- else
- {
- SyncShowMsg( " CMU 200 set downlink power fail " );
- }
- return false;
- }
- Sleep(200);
- int min_gain, max_gain;
- for( int i_gain=p_sn_sweep->min_gain; (i_gain<=p_sn_sweep->max_gain && p_sn_sweep->min_gain < p_sn_sweep->max_gain)||(i_gain>=p_sn_sweep->max_gain && p_sn_sweep->min_gain > p_sn_sweep->max_gain); i_gain+=p_sn_sweep->gain_step )
- {
- if ( this->Terminated )
- {
- this->OnTerminate = p_sn_sweep->ne_onTermByUser;
- return false;
- }
- RF_PM_Object.ConfirmCallback = ::ConfirmCallback_SN;
- RF_PM_Object.REQ_Start( p_sn_sweep->e_band, p_sn_sweep->s_arfcn, p_sn_sweep->pm_per_frame, p_sn_sweep->pm_count,
- NULL, true, i_gain, i_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();
- if( RFCnf_PM.ok && RFCnf_PM.power != 1)
- {
- if( (RFCnf_PM.power / 8.0 + p_sn_sweep->d_threshold) <= d_dn )
- {
- b_saturate = true;
- ts_snresult.i_band_idx = p_sn_sweep->e_band;
- ts_snresult.i_arfcn = p_sn_sweep->s_arfcn;
- ts_snresult.i_saturate_used_gain = RFCnf_PM.usedGain/8.0;
- ts_snresult.d_saturate_equ_power = d_dn;
- ts_snresult.d_saturate_dsppwr = (RFCnf_PM.power + RFCnf_PM.usedGain)/8.0;
- ts_snresult.d_saturate_antpwr = RFCnf_PM.power/8.0;
- ts_snresult.d_linear_range = ts_snresult.d_saturate_dsppwr - ts_snresult.d_noise_floor_dsppwr;
- if( p_sn_sweep->min_gain < p_sn_sweep->max_gain )
- {
- SyncFillSNResult( false, ts_snresult );
- break;
- }
- }
- else if( (RFCnf_PM.power / 8.0 - p_sn_sweep->d_threshold) >= d_dn )
- {
- b_noise_floor = true;
- ts_snresult.i_band_idx = p_sn_sweep->e_band;
- ts_snresult.i_arfcn = p_sn_sweep->s_arfcn;
- ts_snresult.i_noise_floor_used_gain = RFCnf_PM.usedGain/8.0;
- ts_snresult.d_noise_floor_equ_power = d_dn;
- ts_snresult.d_noise_floor_dsppwr = (RFCnf_PM.power + RFCnf_PM.usedGain)/8.0;
- ts_snresult.d_noise_floor_antpwr = RFCnf_PM.power/8.0;
- ts_snresult.d_linear_range = ts_snresult.d_saturate_dsppwr - ts_snresult.d_noise_floor_dsppwr;
- if( p_sn_sweep->min_gain > p_sn_sweep->max_gain )
- {
- SyncFillSNResult( false, ts_snresult );
- break;
- }
- }
- }
- Sleep(50);
- RF_STOP_Object.REQ_Start();
- }
- if( ( (! b_saturate) && (p_sn_sweep->min_gain < p_sn_sweep->max_gain) ) ||
- ( (! b_noise_floor) && (p_sn_sweep->min_gain > p_sn_sweep->max_gain) )
- )
- {
- ts_snresult.i_band_idx = p_sn_sweep->e_band;
- ts_snresult.i_arfcn = p_sn_sweep->s_arfcn;
- ts_snresult.d_linear_range = ts_snresult.d_saturate_dsppwr - ts_snresult.d_noise_floor_dsppwr;
- SyncFillSNResult( false, ts_snresult );
- }
- }
- }
-
- return true;
- }