Crystal_Sweep_TX.cpp
上传用户:gelin96
上传日期:2017-01-08
资源大小:20993k
文件大小:18k
- /*****************************************************************************
- * 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:
- * ---------
- * Crystal_Sweep_TX.cpp
- *
- * Project:
- * --------
- * Maui META APP
- *
- * Description:
- * ------------
- * Crystal sweep tx 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_RFTool.h"
- #include "Crystal_Sweep_TX.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 _CTS_CTRL_H_
- #include "cts_ctrl.h"
- #endif
- // misc
- #ifndef _BAND_UTILS_H_
- #include "band_utils.h"
- #endif
- //---------------------------------------------------------------------------
- #define ONE_SECOND 1
- //------------------------------------------------------------------------------
- static CMU_VAR cmu_crystal;
- static ViInt16 vi_Band_Crystal;
- //==============================================================================
- static void cb_set_CAPID(void)
- {
- if (frmRFTool->pt_Age8960_Crystal_Sweep_TX != NULL)
- {
- frmRFTool->pt_Age8960_Crystal_Sweep_TX->Resume();
- }
- }
- //----------------------------------------------------------------------------
- static void cb_read_CrystalAFC_from_nvram_tx(void)
- {
- if (frmRFTool->pt_Age8960_Crystal_Sweep_TX != NULL)
- {
- frmRFTool->pt_Age8960_Crystal_Sweep_TX->Resume();
- }
- }
- //------------------------------------------------------------------------------
- static void cb_write_CrystalAFC_to_nvram_tx( void )
- {
- if(frmRFTool->pt_Age8960_Crystal_Sweep_TX != NULL )
- {
- frmRFTool->pt_Age8960_Crystal_Sweep_TX->Resume();
- }
- }
- //------------------------------------------------------------------------------
- void __stdcall cb_rf_tx_level_tx(const unsigned char cnf, const short token, void *usrData)
- {
- if(frmRFTool->pt_Age8960_Crystal_Sweep_TX != NULL )
- {
- frmRFTool->pt_Age8960_Crystal_Sweep_TX->Resume();
- }
- }
- //------------------------------------------------------------------------------
- static void cb_rf_stop_tx( void )
- {
- if(frmRFTool->pt_Age8960_Crystal_Sweep_TX != NULL )
- {
- frmRFTool->pt_Age8960_Crystal_Sweep_TX->Resume();
- }
- }
- //==============================================================================
- void _fastcall Crystal_Sweep_TX::ShowMsg()
- {
- ShowMessage( as_Msg );
- }
- //------------------------------------------------------------------------------
- void _fastcall Crystal_Sweep_TX::SyncShowMsg(AnsiString as)
- {
- as_Msg = as;
- Synchronize( ShowMsg );
- }
- //=========================================================================================
- __fastcall Crystal_Sweep_TX::Crystal_Sweep_TX(bool CreateSuspended, S_CAS_T *cas): TThread(CreateSuspended)
- {
- CAS = cas;
- }
- //---------------------------------------------------------------------------
- void __fastcall Crystal_Sweep_TX::Execute()
- {
- ViInt16 vi_Band;
- m_rct.device_type = CAS->e_device_type;
- if (CAS->e_device_type == AGILENT_8960 )
- {
- if((! CAS->crystal_cfg->getGSM400_CableLoss( m_rct.age.d400 )) ||
- (! CAS->crystal_cfg->getGSM850_CableLoss( m_rct.age.d850 )) ||
- (! CAS->crystal_cfg->getGSM900_CableLoss( m_rct.age.d900 )) ||
- (! CAS->crystal_cfg->getDCS1800_CableLoss( m_rct.age.d1800 )) ||
- (! CAS->crystal_cfg->getPCS1900_CableLoss( m_rct.age.d1900 ))
- )
- {
- SyncShowMsg( " Agilent 8960 read config file (cable loss) fail " );
- return;
- }
- if(! CAS->crystal_cfg->getTimeOut( m_rct.age.TMO ) )
- {
- SyncShowMsg( "Get Time Out from file fail" );
- return;
- }
- if(! CAS->crystal_cfg->getGPIB_Addr( m_rct.age.ADD ) )
- {
- SyncShowMsg( "Get GPIB address from file fail" );
- return;
- }
- }
- else // CMU 200
- {
- if(
- (! CAS->crystal_cfg->getCMU200_INPUT_GSM850_CableLoss( m_rct.cmu.loss_gsm850_i )) ||
- (! CAS->crystal_cfg->getCMU200_INPUT_GSM900_CableLoss( m_rct.cmu.loss_gsm_i )) ||
- (! CAS->crystal_cfg->getCMU200_INPUT_DCS1800_CableLoss( m_rct.cmu.loss_dcs_i )) ||
- (! CAS->crystal_cfg->getCMU200_INPUT_PCS1900_CableLoss( m_rct.cmu.loss_pcs_i ))
- )
- {
- SyncShowMsg( " CMU200 read config file (input cable loss) fail " );
- return;
- }
- //*************************************************************
- //************************************************************
- if(
- (! CAS->crystal_cfg->getCMU200_OUTPUT_GSM850_CableLoss( m_rct.cmu.loss_gsm850_o )) ||
- (! CAS->crystal_cfg->getCMU200_OUTPUT_GSM900_CableLoss( m_rct.cmu.loss_gsm_o )) ||
- (! CAS->crystal_cfg->getCMU200_OUTPUT_DCS1800_CableLoss( m_rct.cmu.loss_dcs_o )) ||
- (! CAS->crystal_cfg->getCMU200_OUTPUT_PCS1900_CableLoss( m_rct.cmu.loss_pcs_o ))
- )
- {
- SyncShowMsg( " CMU200 read config file (output cable loss) fail " );
- return;
- }
- if(! CAS->crystal_cfg->getCMU200_TimeOut( m_rct.cmu.TMO ) )
- {
- SyncShowMsg( "Get Time Out from file fail" );
- return;
- }
- if(! CAS->crystal_cfg->getCMU200_GPIB_Addr( m_rct.cmu.ADD ) )
- {
- SyncShowMsg( "Get GPIB address from file fail" );
- return;
- }
- m_rct.cmu.ADD = m_rct.cmu.ADD.SubString(0, m_rct.cmu.ADD.Pos("::INSTR")-1);
- }
- if( CAS->b_temp_sweep )
- {
- if( ! m_cts_ctrl.CTS_Init(CAS->com_port) )
- {
- SyncShowMsg( "Initialize CTS fail" );
- return;
- }
- // if( ! m_cts_ctrl.CTS_Close() )
- // {
- // SyncShowMsg( "Close CTS fail" );
- /// return;
- // }
- CAS->hCOM = m_cts_ctrl.CTS_GetComHandle();
- CAS->original_dcb = m_cts_ctrl.Get_OriginalDCB();
- if( ! m_cts_ctrl.CTS_Start() )
- {
- SyncShowMsg( "Start CTS fail" );
- return;
- }
- }
- if( ! m_rct_ctrl.RCT_Init( &m_rct, BandIdx_To_FreqBandString(CAS->e_band) ) )
- {
- SyncShowMsg( "Initialize equipment fail" );
- return;
- }
- if( ! m_rct_ctrl.RCT_operatingMode( &m_rct, OPERATING_MODE_GSM_BCH_TCH ) )
- {
- SyncShowMsg( "Set operation mode fail" );
- return;
- }
- /////////////////////////////////////////////////////////////////////////////
- switch ( CAS->e_band )
- {
- case BANDSEL_GSM900:
- vi_Band = age1960_EGSM_BAND;
- cmu_crystal.BAND="GSM";
- vi_Band_Crystal=CMU_EGSM_BAND;
- break;
- case BANDSEL_DCS1800:
- vi_Band = age1960_DCS1800_BAND;
- cmu_crystal.BAND="DCS";
- vi_Band_Crystal=CMU_DCS1800_BAND;
- break;
- case BANDSEL_PCS1900:
- vi_Band = age1960_PCS1900_BAND;
- cmu_crystal.BAND="PCS";
- vi_Band_Crystal=CMU_PCS1900_BAND;
- break;
- case BANDSEL_GSM850:
- vi_Band = age1960_GSM850_BAND;
- cmu_crystal.BAND="GSM850";
- vi_Band_Crystal=CMU_GSM850_BAND;
- break;
- } // switch
- if( ! m_rct_ctrl.RCT_cellBand( &m_rct, vi_Band) )
- {
- if ( CAS->e_device_type == AGILENT_8960)
- {
- SyncShowMsg( " Agilent 8960 set cell band fail ");
- }
- else
- {
- SyncShowMsg( " CMU 200 set cell band fail ");
- }
- return;
- }
- /////////////////////////////////////////////////////////////////////////////
- if( ! m_rct_ctrl.RCT_TCHARFCN( &m_rct, CAS->s_arfcn) )
- {
- if ( CAS->e_device_type == AGILENT_8960)
- {
- SyncShowMsg( " Agilent 8960 set TCH ARFCN fail " );
- }
- else
- {
- SyncShowMsg( " CMU 200 set TCH ARFCN fail " );
- }
- }
- /////////////////////////////////////////////////////////////////////////////
- if( ! m_rct_ctrl.RCT_ConfigTSC( &m_rct, CAS->c_TSC ) )
- {
- if ( CAS->e_device_type == AGILENT_8960)
- {
- SyncShowMsg( " Agilent 8960 set TSC fail ");
- }
- else
- {
- SyncShowMsg( " CMU 200 set TSC fail ");
- }
- return;
- }
- /////////////////////////////////////////////////////////////////////////////
- if( ! m_rct_ctrl.RCT_MSTXLevel( &m_rct, CAS->pcl ) )
- {
- if ( CAS->e_device_type == AGILENT_8960)
- {
- SyncShowMsg( " Agilent 8960 set PCL fail ");
- }
- else
- {
- SyncShowMsg( " CMU 200 set PCL fail ");
- }
- return;
- }
- /////////////////////////////////////////////////////////////////////////////
- //MeasFcnDone = -999; /* Set to unknown state to start */
- Sleep(50);
- //_VI_PTR pvi = vi;
- // read xo AFC from NVRAM
- CRYSTAL_AFC_Object.ConfirmCallback = ::cb_read_CrystalAFC_from_nvram_tx;
- CRYSTAL_AFC_Object.REQ_Read_CAPID_From_NVRAM_Start();
- this->Suspend();
- if(CRYSTAL_AFC_Object.Get_ConfirmState() != METAAPP_SUCCESS)
- {
- Application->MessageBox( "Execution Failure : read crystal AFC from NVRAM ", "FAILURE", MB_OK );
- return;
- }
- // save header to log
- buf[0]=' ';
- for( int j=CAS->s_min_afc_dac; j<=CAS->s_max_afc_dac; j=j+CAS->s_afc_dac_step )
- {
- sprintf(buf1, "%15d", j );
- strcat(buf, buf1);
- }
- CAS->st_Log->Add(buf);
- frmRFTool->write_CAS_log();
- if( ! CAS->b_temp_sweep ) CAS->max_temp = CAS->min_temp;
- for(float temp=CAS->min_temp; temp<=CAS->max_temp; temp+=CAS->temp_step)
- {
- if( CAS->b_temp_sweep )
- {
- if( ! m_cts_ctrl.CTS_SetTemp( temp ) )
- {
- SyncShowMsg( "CTS set temp fail" );
- return;
- }
- double current_temp, setting_temp;
- do
- {
- if ( this->Terminated )
- {
- this->OnTerminate = CAS->ne_onTermByUser;
- return;
- }
- if( ! m_cts_ctrl.CTS_GetTemp( current_temp, setting_temp ) )
- {
- continue;
- // SyncShowMsg( "CTS get temp successful" );
- // break;
- }
- }
- while(temp != current_temp);
- }
- for( int i=CAS->min_cap_id; i<=CAS->max_cap_id; i=i+CAS->cap_id_step )
- {
- buf[0]=' ';
- if( CAS->b_temp_sweep )
- {
- sprintf(buf1, "%3.1f ", temp );
- strcat(buf, buf1);
- }
- else
- {
- sprintf(buf1, " ");
- strcat(buf, buf1);
- }
- // CRYSTAL_AFC_Object.Set_cap_id(i);
- // CRYSTAL_AFC_Object.ConfirmCallback = ::cb_write_CrystalAFC_to_nvram_tx;
- // CRYSTAL_AFC_Object.REQ_Write_CAPID_To_NVRAM_Start();
-
- CRYSTAL_AFC_Object.ConfirmCallback = ::cb_set_CAPID;
- CRYSTAL_AFC_Object.REQ_SetCapID_Start(i);
- this->Suspend();
- sprintf(buf0, "%3d", i);
- strcat(buf, buf0);
- if(CRYSTAL_AFC_Object.Get_ConfirmState() != METAAPP_SUCCESS)
- {
- Application->MessageBox( "Execution Failure : write crystal AFC to NVRAM ", "FAILURE", MB_OK );
- return;
- }
- for( int j=CAS->s_min_afc_dac; j<=CAS->s_max_afc_dac; j=j+CAS->s_afc_dac_step )
- {
- if ( this->Terminated )
- {
- this->OnTerminate = CAS->ne_onTermByUser;
- return;
- }
- //sprintf(buf1, "AFC DAC = %d : ", j);
- Sleep(50);
- MF_rf_tx_level_req.arfcn = CAS->s_arfcn;
- MF_rf_tx_level_req.bsic = CAS->c_TSC;
- MF_rf_tx_level_req.power = CAS->pcl;
- MF_rf_tx_level_req.frames = 1000;
- MF_rf_tx_level_req.dacValue = j;
- MF_rf_tx_level_req.burstTypeNB = NB_TX_RANDOM_WITH_TSC; // NB burst
- if ( META_Rf_NB_TX_r( m_META_HANDLE_Obj.Get_MainHandle(),
- &MF_rf_tx_level_req,
- ::cb_rf_tx_level_tx,
- &MF_rf_tx_level_token,
- NULL
- ) != META_SUCCESS)
- {
- return;
- }
- this->Suspend();
- //*******************************************
- //------------- Read frequency Error--------
- //**********************************************
- if ( this->Terminated )
- {
- this->OnTerminate = CAS->ne_onTermByUser;
- return;
- }
- // if( ! m_rct_ctrl.RCT_initMeasFcn_PFER( &m_rct ) )
- // {
- // if ( CAS->device_type == AGILENT_8960)
- // {
- // SyncShowMsg( " Agilent 8960 initialize PFER measurement fail ");
- // }
- // else
- // {
- // SyncShowMsg( " CMU 200 set initialize PFER measurement fail ");
- // }
- // return;
- // }
- Sleep(50);
- if( ! m_rct_ctrl.RCT_FetchAvgFreqErr( &m_rct, PFERFreqError ) )
- {
- if ( CAS->e_device_type == AGILENT_8960)
- {
- SyncShowMsg( " Agilent 8960 fetch average frequency error fail ");
- }
- else
- {
- SyncShowMsg( " CMU 200 fetch average frequency error fail ");
- }
- return;
- }
- //******************************************************************************
- FreqError = PFERFreqError;
- sprintf(buf1, "%12.4f", FreqError );
- strcat(buf, buf1);
- strcat(buf, " ");
- //strcat(buf, buf2);
- //sprintf(buf, " " );
- //st_Log_CAS->Add(buf);
- Sleep(50);
- MF_rf_stop.REQ_Start();
- }
- CAS->st_Log->Add(buf);
- frmRFTool->write_CAS_log();
- }
- }
- this->OnTerminate = CAS->ne_onTermSuccess;
- }