Crystal_Init_Age8960.cpp
上传用户:gelin96
上传日期:2017-01-08
资源大小:20993k
文件大小:22k
源码类别:
MTK
开发平台:
C++ Builder
- /*****************************************************************************
- * 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_Init_Age8960.cpp
- *
- * Project:
- * --------
- * Maui META APP
- *
- * Description:
- * ------------
- * Crystal Initalize Agilent 8960 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 "man_dll.h"
- #include "form_RFTool.h"
- #include "Crystal_Init_Age8960.h"
- #include "meta_utils.h"
- #include "Crystal_INIFileHandle.h"
- // equipment
- #ifndef _AGECOMMON_H_
- #include "agecommon.h"
- #endif
- #include "cmu200.h"
- //---------------------------------------------------------------------------
- //#define ONE_SECOND 1
- //------------------------------------------------------------------------------
- CMU_VAR cmu_crystal_tx;
- static ViInt16 vi_Band_Crystal_tx;
- extern TfrmRFTool *frmRFTool;
- //=================================================================================
- //------------------------------------------------------------------------------
- void _fastcall Crystal_Init_Age8960::ShowMsg()
- {
- ShowMessage( as_Msg );
- }
- //------------------------------------------------------------------------------
- //------------------------------------------------------------------------------
- void _fastcall Crystal_Init_Age8960::SyncShowMsg(AnsiString as)
- {
- as_Msg = as;
- Synchronize( ShowMsg );
- }
- //=========================================================================================
- __fastcall Crystal_Init_Age8960::Crystal_Init_Age8960(
- bool CreateSuspended,
- AnsiString as_ADDR,
- int i_TimeOut,
- signed short ss_Band,
- TNotifyEvent ne_OnTermHandler,
- ViSession &vs_Age196x,
- TMETA_crystal_cfg *crystal_cfg,
- AnsiString &as_TaModel
- )
- : TThread(CreateSuspended)
- {
- as_AGE8960_ADDR = as_ADDR;
- i_AGE8960_TimeOut = i_TimeOut;
- ss_CellBand = ss_Band;
- ne_OnTerminate = ne_OnTermHandler;
- pvi = &vs_Age196x;
- cfg = crystal_cfg;
- as_pAgeTaModel = &as_TaModel;
- }
- //---------------------------------------------------------------------------
- void __fastcall Crystal_Init_Age8960::Execute()
- {
- #if 0
- if(frmRFTool->rb8960_TXErr->Checked)
- {
- if ((vistat = age1960_init( as_AGE8960_ADDR.c_str(), 0, 0, &vi)) != VI_SUCCESS)
- {
- Application->MessageBox( " Initialize Agilent 8960 fail 2", "Fail", MB_OK );
- return;
- }
- //////////////////////////////////////////////////////////////////////////////
- if ( (vistat = age_QueryTaModel( vi, as_pAgeTaModel )) != VI_SUCCESS)
- {
- Application->MessageBox( " Query Agilent 8960 TA Model fail ", "Fail", MB_OK );
- return;
- }
- //////////////////////////////////////////////////////////////////////////////
- Sleep(50);
- if ( vi != VI_NULL)
- {
- if ( age1960_dcl(vi)!= VI_SUCCESS)
- {
- Application->MessageBox( " Agilent 8960 DCL fail ", "Fail", MB_OK );
- return;
- }
- }
- //////////////////////////////////////////////////////////////////////////////
- Sleep(50);
- if ( vi != VI_NULL)
- {
- if (vistat = age1960_reset( vi ) != VI_SUCCESS)
- {
- Application->MessageBox( " Reset Agilent 8960 fail ", "Fail", MB_OK );
- return;
- }
- }
- /////////////////////////////////////////////////////////////////////////////
- if(! cfg->getTimeOut( i_AGE8960_TimeOut ) )
- {
- Application->MessageBox( "Execution Failure : Get Time Out from file fail", "FAILURE", MB_OK );
- return;
- }
- if ((vistat = age1960_timeOut (vi,i_AGE8960_TimeOut)) != VI_SUCCESS)
- {
- Application->MessageBox( " Agilent 8960 set timeout fail ", "Fail", MB_OK );
- return;
- }
- /////////////////////////////////////////////////////////////////////////////
- if((! cfg->getGSM400_CableLoss( d400 )) ||
- (! cfg->getGSM850_CableLoss( d850 )) ||
- (! cfg->getGSM900_CableLoss( d900 )) ||
- (! cfg->getDCS1800_CableLoss( d1800 )) ||
- (! cfg->getPCS1900_CableLoss( d1900 ))
- )
- {
- Application->MessageBox( " Agilent 8960 read config file (cable loss) fail ", "Fail", MB_OK );
- return;
- }
- const AMP_OFFSET_ITEMS = 10;
- ViReal64 freqArray[AMP_OFFSET_ITEMS] = { 400000000.0,
- 641000000.0,
- 641100000.0,
- 876000000.0,
- 876100000.0,
- 1312000000.0,
- 1312100000.0,
- 1880000000.0,
- 1881000000.0,
- 2000000000.0 };
- ViReal64 offsetArray[AMP_OFFSET_ITEMS] = { d400,
- d400,
- d850,
- d850,
- d900,
- d900,
- d1800,
- d1800,
- d1900,
- d1900
- };
- if ((vistat = age1960_amplitudeOffset (
- vi,
- freqArray,
- offsetArray,
- AMP_OFFSET_ITEMS
- )) != VI_SUCCESS)
- {
- Application->MessageBox( " Agilent 8960 set cable loss fail ", "Fail", MB_OK );
- return;
- }
- /////////////////////////////////////////////////////////////////////////////
- if( as_pAgeTaModel->AnsiCompareIC( "E1968A" ) == 0 || as_pAgeTaModel->AnsiCompareIC( "E6701C" ) == 0 || as_pAgeTaModel->AnsiCompareIC( "E6701D" ) == 0)
- {
- if ((vistat = age1968A_operatingMode(
- vi,
- (ViInt16) OPERATING_MODE_GSM_BCH_TCH
- ))!= VI_SUCCESS)
- {
- Application->MessageBox( " Agilent 8960 set operation mode fail ", "Fail", MB_OK );
- return;
- }
- }
- else // Agilent 1960A
- {
- if ((vistat = age1960_operatingMode(
- vi,
- (ViInt16) age1960_TEST_MODE
- ))!= VI_SUCCESS)
- {
- Application->MessageBox( " Agilent 8960 set operation mode fail ", "Fail", MB_OK );
- return;
- }
- }
- }
- else // CMU200
- {
- //******************************************************************
- double d900,Out900,d400,Out400,d850,Out850,d1800,Out1800,d1900,Out1900;
- AnsiString as_CMU_ADDR;
- int as_CMU_TimeOut;
- AnsiString CMU_GSM_INP,CMU_GSM_OUT;
- AnsiString as_RF_Equipment_ADDR;
- //************************************************************
- if((! cfg->getCMU200_INPUT_GSM400_CableLoss( d400 )) ||
- (! cfg->getCMU200_INPUT_GSM850_CableLoss( d850 )) ||
- (! cfg->getCMU200_INPUT_GSM900_CableLoss( d900 )) ||
- (! cfg->getCMU200_INPUT_DCS1800_CableLoss( d1800 )) ||
- (! cfg->getCMU200_INPUT_PCS1900_CableLoss( d1900 ))
- )
- {
- Application->MessageBox( " CMU200 read config file (cable loss) fail ", "Fail", MB_OK );
- return;
- }
- //*************************************************************
- //************************************************************
- if((! cfg->getCMU200_OUTPUT_GSM400_CableLoss( Out400 )) ||
- (! cfg->getCMU200_OUTPUT_GSM850_CableLoss( Out850 )) ||
- (! cfg->getCMU200_OUTPUT_GSM900_CableLoss( Out900 )) ||
- (! cfg->getCMU200_OUTPUT_DCS1800_CableLoss( Out1800 )) ||
- (! cfg->getCMU200_OUTPUT_PCS1900_CableLoss( Out1900 ))
- )
- {
- Application->MessageBox( " CMU200 read config file (cable loss) fail ", "Fail", MB_OK );
- return;
- }
- //*************************************************************
- cfg->getCMU200_GPIB_Addr( as_RF_Equipment_ADDR );
- cfg->getCMU200_TimeOut(as_CMU_TimeOut);
- cmu_crystal_tx.loss_gsm_i=d900;
- cmu_crystal_tx.loss_gsm_o=Out900;
- cmu_crystal_tx.loss_dcs_i=d1800;
- cmu_crystal_tx.loss_dcs_o=Out1800;
- cmu_crystal_tx.loss_pcs_i=d1900;
- cmu_crystal_tx.loss_pcs_o=Out1900;
- //****************************************************************
- //cmu.ADD=as_CMU_ADDR;
- cmu_crystal_tx.ADD=as_RF_Equipment_ADDR.SubString(0, as_RF_Equipment_ADDR.Pos("::INSTR")-1);
- cmu_crystal_tx.TMO= StrToInt(as_CMU_TimeOut);
- cmu_crystal_tx.BAND="GSM";
- if( !cmu_init_TX_FreqErr(&cmu_crystal_tx) )
- {
- Application->MessageBox( "Initial CMU200 fail", "Fail", MB_OK );
- return;
- }
- Sleep(1500);
- }
- int_band = frmRFTool->cbxTXFreqErrBand->ItemIndex;
- switch ( int_band )
- {
- case 0:
- vi_Band = age1960_EGSM_BAND;
- cmu_crystal_tx.BAND="GSM";
- vi_Band_Crystal_tx=1;
- break;
- case 1:
- vi_Band = age1960_DCS1800_BAND;
- cmu_crystal_tx.BAND="DCS";
- vi_Band_Crystal_tx=3;
- break;
- case 2:
- vi_Band = age1960_PCS1900_BAND;
- cmu_crystal_tx.BAND="PCS";
- vi_Band_Crystal_tx=4;
- break;
- } // switch
- //***********************************************
- if(frmRFTool->rb8960_TXErr->Checked)
- {
- if ( age1960_cellBand(
- vi,
- age1960_CELL_1,
- vi_Band
- ) != VI_SUCCESS )
- {
- age1960_error_message(vi, vistat, errmsg);
- AnsiString as_error_msg;
- as_error_msg = (AnsiString) errmsg;
- Application->MessageBox( as_error_msg.c_str() , "Error", MB_OK );
- Application->MessageBox( " Agilent 8960 set cell band fail ", "Fail", MB_OK );
- return;
- }
- }
- else
- {
- if( !cmu_cellband(vi_Band_Crystal_tx, &cmu_crystal_tx) )
- {
- Application->MessageBox( " CMU200 set cell band fail ", "Fail", MB_OK );
- return ;
- } // if
- }
- /////////////////////////////////////////////////////////////////////////////
- s_pm_arfcn = frmRFTool->edtTXFreqErrARFCN->Text.ToInt();
- if(frmRFTool->rb8960_TXErr->Checked)
- {
- vistat = age1960_BCHARFCN(
- vi,
- age1960_CELL_1,
- s_pm_arfcn,
- age1960_CURRENT_BAND,
- VI_TRUE
- );
- if ( vistat != VI_SUCCESS )
- {
- age1960_error_message(vi, vistat, errmsg);
- AnsiString as_error_msg;
- as_error_msg = (AnsiString) errmsg;
- Application->MessageBox( as_error_msg.c_str() , "Error", MB_OK );
- Application->MessageBox( " Agilent 8960 set BCCH ARFCN fail ", "Fail", MB_OK );
- return;
- }
- }
- else
- {
- if( !cmu_bcharfcn(s_pm_arfcn, &cmu_crystal_tx) )
- {
- Application->MessageBox( " CMU200 set BCCH ARFCN fail ", "Fail", MB_OK );
- return;
- }
- }
- /////////////////////////////////////////////////////////////////////////////
- d_P_DL = -60;
- if(frmRFTool->rb8960_TXErr->Checked)
- {
- if ( age1960_cellPower(
- vi,
- age1960_CELL_1,
- d_P_DL,
- 0
- ) != VI_SUCCESS)
- {
- age1960_error_message(vi, vistat, errmsg);
- AnsiString as_error_msg;
- as_error_msg = (AnsiString) errmsg;
- Application->MessageBox( as_error_msg.c_str() , "Error", MB_OK );
- Application->MessageBox( " Agilent 8960 set cell power fail ", "Fail", MB_OK );
- return;
- }
- }
- else
- {
- if( !cmu_cellpower(d_P_DL, &cmu_crystal_tx) )
- {
- Application->MessageBox( " CMU200 set cell power fail ", "Fail", MB_OK );
- return;
- } // if
- }
- /////////////////////////////////////////////////////////////////////////////
- short s_ARFCN = frmRFTool->edtTXFreqErrARFCN->Text.ToInt();
- if(frmRFTool->rbAg8960_CryAfc->Checked)
- {
- if ( age1960_TCHARFCN(
- vi,
- s_ARFCN,
- (short) 0, // current band
- VI_TRUE
- )!= VI_SUCCESS)
- {
- age1960_error_message(vi, vistat, errmsg);
- AnsiString as_error_msg;
- as_error_msg = (AnsiString) errmsg;
- Application->MessageBox( as_error_msg.c_str() , "Error", MB_OK );
- Application->MessageBox( " Agilent 8960 set TCH ARFCN fail ", "Fail", MB_OK );
- return;
- }
- }
- else
- {
- if( !cmu_tcharfcn(s_ARFCN, &cmu_crystal_tx) )
- {
- Application->MessageBox( " CMU200 set TCH ARFCN fail ", "Fail", MB_OK );
- return;
- }
- }
- /////////////////////////////////////////////////////////////////////////////
- c_TSC = frmRFTool->cbxTXFreqErrTSC->Text.ToInt();
- if(frmRFTool->rb8960_TXErr->Checked)
- {
- if( age1968A_ConfigTSC(vi, c_TSC, NULL) != VI_SUCCESS )
- {
- Application->MessageBox( " Agilent 8960 config TSC fail ", "Fail", MB_OK );
- return;
- }
- }
- /////////////////////////////////////////////////////////////////////////////
- if(frmRFTool->rb8960_TXErr->Checked)
- {
- if ( age1960_MSTXLevel(
- vi,
- frmRFTool->edtTXFreqErrPCL->Text.ToInt(),
- (short) 0, // current band
- VI_TRUE
- )!= VI_SUCCESS)
- {
- age1960_error_message(vi, vistat, errmsg);
- AnsiString as_error_msg;
- as_error_msg = (AnsiString) errmsg;
- Application->MessageBox( as_error_msg.c_str() , "Error", MB_OK );
- Application->MessageBox( " Agilent 8960 MS TX level fail ", "Fail", MB_OK );
- return;
- }
- }
- else
- {
- if( !cmu_mxtxlevel(frmRFTool->edtTXFreqErrPCL->Text.ToInt(), &cmu_crystal_tx) )
- {
- Application->MessageBox( " CMU200 MS TX level fail ", "Fail", MB_OK );
- return;
- }
- }
- /////////////////////////////////////////////////////////////////////////////
- if(frmRFTool->rb8960_TXErr->Checked)
- {
- if ( age1960_initMeasFcn(
- vi,
- age1960_PFER // modified by Andy Ueng
- ) != VI_SUCCESS)
- {
- age1960_error_message(vi, vistat, errmsg);
- AnsiString as_error_msg;
- as_error_msg = (AnsiString) errmsg;
- Application->MessageBox( as_error_msg.c_str() , "Error", MB_OK );
- Application->MessageBox( " Agilent 8960 initialize measure function (PFER) fail ", "Fail", MB_OK );
- return;
- }
- /////////////////////////////////////////////////////////////////////////////
- MeasFcnDone = -999; /* Set to unknown state to start */
- // if ( age1960_fetchPFER_Q(
- // vi,
- // &PFERIntegrity,
- // &PFERRMSError,
- // &PFERPeakError,
- // &PFERFreqError
- // )!= VI_SUCCESS)
- if( age_FetchAvgFreqError( vi, &PFERFreqError ) != VI_SUCCESS )
- {
- Application->MessageBox( " Fetch average frequency error init error", "ERROR", MB_OK );
- return;
- }
- else
- {
- // ShowMessage("age1960_fetchPFER_Q() init ok");
- }
- }
- else
- {
- if( !cmu_mod_read(&cmu_crystal_tx, FREQ_ERR_AVERAGE, &PFERFreqError) )
- {
- Application->MessageBox( "CMU200_fetchPFER_Q() read error" , "Error", MB_OK );
- return;
- }
- }
- frmRFTool->TimerTXFreq->Enabled =true;
- frmRFTool->FirstTime = true;
- // end of added
- _VI_PTR pvi = vi;
- // marked by Andy Ueng
- this->OnTerminate = ne_OnTerminate;
- // (void)vistat;
- // end of marked
- #endif
- }
- //------------------------------------------------------------------------
- bool __fastcall Crystal_Init_Age8960::CheckError(ViStatus ErrorStatus)
- {
- /*------------------------------------------------*/
- /* Check for driver errors. */
- /* If an error occurred reset the instrument and */
- /* return true else return false. */
- /*------------------------------------------------*/
- ViChar ErrorMessage[256];
- ViChar message[100];
- if (VI_SUCCESS > ErrorStatus){
- /* Query the error */
- age1960_error_message(vi, ErrorStatus, ErrorMessage);
- /* set the mouse pointer for the form back to the default */
- Screen->Cursor = crDefault;
- /* Display the error */
- sprintf(message, "Instrument Error: %ld %s",ErrorStatus, ErrorMessage);
- ShowMessage (message);
- /* Send a device clear - to ensure communication with the instrument */
- //age1960_dcl(vi);
- /* reset the instrument */
- age1960_reset(vi);
- return true;
- }
- return false;
- }
- //---------------------------------------------------------------------------