rf_pmch_sweep.cpp
上传用户:gelin96
上传日期:2017-01-08
资源大小:20993k
文件大小:16k
源码类别:

MTK

开发平台:

C++ Builder

  1. /*****************************************************************************
  2. *  Copyright Statement:
  3. *  --------------------
  4. *  This software is protected by Copyright and the information contained
  5. *  herein is confidential. The software may not be copied and the information
  6. *  contained herein may not be used or disclosed except with the written
  7. *  permission of MediaTek Inc. (C) 2005
  8. *
  9. *  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  10. *  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
  11. *  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
  12. *  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
  13. *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
  14. *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
  15. *  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
  16. *  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
  17. *  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
  18. *  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
  19. *  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
  20. *  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
  21. *
  22. *  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
  23. *  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
  24. *  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
  25. *  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
  26. *  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
  27. *
  28. *  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
  29. *  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
  30. *  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
  31. *  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
  32. *  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
  33. *
  34. *****************************************************************************/
  35. /*****************************************************************************
  36.  *
  37.  * Filename:
  38.  * ---------
  39.  *   rf_pmch_sweep.cpp
  40.  *
  41.  * Project:
  42.  * --------
  43.  *   Maui META APP
  44.  *
  45.  * Description:
  46.  * ------------
  47.  *  RF PM channel sweep source
  48.  *
  49.  * Author:
  50.  * -------
  51.  *  Andy Ueng (mtk00490)
  52.  *
  53.  *============================================================================
  54.  *             HISTORY
  55.  * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  56.  *------------------------------------------------------------------------------
  57.  * $Revision$
  58.  * $Modtime$
  59.  * $Log$
  60.  * 
  61.  *------------------------------------------------------------------------------
  62.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  63.  *============================================================================
  64.  ****************************************************************************/
  65. //---------------------------------------------------------------------------
  66. #include <vcl.h>
  67. #include <math.h>
  68. #pragma hdrstop
  69. #include "rf_pmch_sweep.h"
  70. #include "meta_utils.h"
  71. #ifndef _FORM_RFTOOL_H_
  72. #include "form_rftool.h"
  73. #endif
  74. #include "man_dll.h"
  75. // equipment
  76. #include "ageCommon.h"
  77. #include "age1968A.h"
  78. #include "cmu200.h"
  79. #ifndef  _RCT_COMMON_H_
  80. #include "rct_common.h"
  81. #endif
  82. #ifndef  _RCT_CTRL_H_
  83. #include "rct_ctrl.h"
  84. #endif
  85. // misc
  86. #ifndef  _BAND_UTILS_H_
  87. #include "band_utils.h"
  88. #endif
  89. //---------------------------------------------------------------------------
  90. //#define ONE_SECOND 1
  91. //------------------------------------------------------------------------------
  92. //==============================================================================
  93. static void  ConfirmCallback_PMCS( void )
  94. {
  95.     if(frmRFTool->pt_PMCH_sweep != NULL )
  96.     {
  97.         frmRFTool->pt_PMCH_sweep->Resume();
  98.     }
  99. }
  100. //------------------------------------------------------------------------------
  101. static void cb_rf_stop_PMCH()
  102. {
  103.     if(frmRFTool->pt_PMCH_sweep != NULL )
  104.     {
  105.         frmRFTool->pt_PMCH_sweep->Resume();
  106.     }
  107. }
  108. //==============================================================================
  109. void _fastcall CRF_PMCH_SWEEP::ShowMsg()
  110. {
  111.     ShowMessage( as_Msg );
  112. }
  113. //------------------------------------------------------------------------------
  114. void _fastcall CRF_PMCH_SWEEP::SyncShowMsg(AnsiString as)
  115. {
  116.     as_Msg = as;
  117.     Synchronize( ShowMsg );
  118. }
  119. //=========================================================================================
  120. __fastcall CRF_PMCH_SWEEP::CRF_PMCH_SWEEP(
  121.                                            bool CreateSuspended,
  122.                                            sPMCHSweep *p_pmch_sweep
  123.                                           // ViSession &vs_Age196x,
  124.                                           // AnsiString &as_TaModel
  125.                                           ): TThread(CreateSuspended)
  126. {
  127.     pmch_sweep = p_pmch_sweep;
  128.     b_title = true;
  129.   //  as_pAgeTaModel = &as_TaModel;
  130.   //  pvi = &vs_Age196x;
  131. }
  132. //---------------------------------------------------------------------------
  133. void __fastcall CRF_PMCH_SWEEP::Execute()
  134. {
  135.     rct.device_type = pmch_sweep->e_device_type;
  136.     if (!PMCH_CfgRead())
  137.     {
  138.         SyncShowMsg("Read CFG file fail");
  139.         return;
  140.     }
  141.     if (!rct_ctrl.RCT_Init(&rct, BandIdx_To_FreqBandString(pmch_sweep->e_band)))
  142.     {
  143.         SyncShowMsg("Initialize equipment fail");
  144.         return;
  145.     }
  146.     if (!PMCH_Sweep())
  147.     {
  148.         return;
  149.     }
  150.     this->OnTerminate = pmch_sweep->ne_onTermSuccess;
  151. }
  152. //---------------------------------------------------------------------------
  153. bool __fastcall CRF_PMCH_SWEEP::PMCH_CfgRead( void )
  154. {
  155.     if (pmch_sweep->e_device_type == AGILENT_8960)
  156.     {
  157.         if((! pmch_sweep->rf_cfg->getGSM400_CableLoss( rct.age.d400 )) ||
  158.            (! pmch_sweep->rf_cfg->getGSM850_CableLoss( rct.age.d850 )) ||
  159.            (! pmch_sweep->rf_cfg->getGSM900_CableLoss( rct.age.d900 )) ||
  160.            (! pmch_sweep->rf_cfg->getDCS1800_CableLoss( rct.age.d1800 )) ||
  161.            (! pmch_sweep->rf_cfg->getPCS1900_CableLoss( rct.age.d1900 ))
  162.           )
  163.         {
  164.             SyncShowMsg( " Agilent 8960 read config file (cable loss) fail " );
  165.             return false;
  166.         }
  167.         if(! pmch_sweep->rf_cfg->getTimeOut( rct.age.TMO ) )
  168.         {
  169.             SyncShowMsg( "Get Time Out from file fail" );
  170.             return false;
  171.         }
  172.         if(! pmch_sweep->rf_cfg->getGPIB_Addr( rct.age.ADD ) )
  173.         {
  174.             SyncShowMsg( "Get GPIB address from file fail" );
  175.             return false;
  176.         }
  177.     }
  178.     else // CMU 200
  179.     {
  180.         if(
  181.              (! pmch_sweep->rf_cfg->getCMU200_INPUT_GSM850_CableLoss( rct.cmu.loss_gsm850_i )) ||
  182.              (! pmch_sweep->rf_cfg->getCMU200_INPUT_GSM900_CableLoss( rct.cmu.loss_gsm_i    )) ||
  183.              (! pmch_sweep->rf_cfg->getCMU200_INPUT_DCS1800_CableLoss( rct.cmu.loss_dcs_i   )) ||
  184.              (! pmch_sweep->rf_cfg->getCMU200_INPUT_PCS1900_CableLoss( rct.cmu.loss_pcs_i   ))
  185.           )
  186.         {
  187.              SyncShowMsg(  " CMU200 read config file (input cable loss) fail " );
  188.              return false;
  189.         }
  190.         //*************************************************************
  191.         //************************************************************
  192.         if(
  193.                (! pmch_sweep->rf_cfg->getCMU200_OUTPUT_GSM850_CableLoss( rct.cmu.loss_gsm850_o )) ||
  194.                (! pmch_sweep->rf_cfg->getCMU200_OUTPUT_GSM900_CableLoss( rct.cmu.loss_gsm_o ))    ||
  195.                (! pmch_sweep->rf_cfg->getCMU200_OUTPUT_DCS1800_CableLoss( rct.cmu.loss_dcs_o ))   ||
  196.                (! pmch_sweep->rf_cfg->getCMU200_OUTPUT_PCS1900_CableLoss( rct.cmu.loss_pcs_o ))
  197.                                                       )
  198.         {
  199.              SyncShowMsg(  " CMU200 read config file (output cable loss) fail " );
  200.              return false;
  201.         }
  202.         if(! pmch_sweep->rf_cfg->getCMU200_TimeOut( rct.cmu.TMO ) )
  203.         {
  204.             SyncShowMsg( "Get Time Out from file fail" );
  205.             return false;
  206.         }
  207.         if(! pmch_sweep->rf_cfg->getCMU200_GPIB_Addr( rct.cmu.ADD ) )
  208.         {
  209.             SyncShowMsg( "Get GPIB address from file fail" );
  210.             return false;
  211.         }
  212.         rct.cmu.ADD = rct.cmu.ADD.SubString(0, rct.cmu.ADD.Pos("::INSTR")-1);
  213.     }
  214.     return true;
  215. }
  216. //---------------------------------------------------------------------------
  217. bool __fastcall CRF_PMCH_SWEEP::PMCH_Sweep( void )
  218. {
  219.     const char  BAND_STR[4][10] =
  220. {  "GSM900 ",
  221.    "DCS1800",
  222.    "PCS1900",
  223.    "GSM850"
  224. };
  225.     ViInt16 vi_Band;
  226.     char buf[40000], buf1[10000];
  227.     switch ( pmch_sweep->e_band )
  228.     {
  229.          case BANDSEL_GSM900:
  230.             vi_Band = age1960_EGSM_BAND;
  231.          break;
  232.          case BANDSEL_DCS1800:
  233.             vi_Band = age1960_DCS1800_BAND;
  234.          break;
  235.          case BANDSEL_PCS1900:
  236.             vi_Band = age1960_PCS1900_BAND;
  237.          break;
  238.          case BANDSEL_GSM850:
  239.             vi_Band = age1960_GSM850_BAND;
  240.          break;
  241.          default:
  242.          break;
  243.     }; // switch
  244.     //int i;
  245.     if( ! rct_ctrl.RCT_cellBand( &rct, vi_Band ) )
  246.     {
  247.         if ( pmch_sweep->e_device_type == AGILENT_8960)
  248.         {
  249.             SyncShowMsg( " Agilent 8960 set cell band fail ");
  250.         }
  251.         else
  252.         {
  253.             SyncShowMsg( " CMU 200 set cell band fail ");
  254.         }
  255.         return false;
  256.     }
  257.     if( ! rct_ctrl.RCT_ContModTran( &rct ) )
  258.     {
  259.         if ( pmch_sweep->e_device_type == AGILENT_8960)
  260.         {
  261.             SyncShowMsg( " Agilent 8960 set continuous transmition mode fail " );
  262.         }
  263.         else
  264.         {
  265.             SyncShowMsg( " CMU 200 set continuous transmition mode fail " );
  266.         }
  267.         return false;
  268.     }
  269.     if( ! rct_ctrl.RCT_cellPower( &rct, pmch_sweep->d_P_DL) )
  270.     {
  271.         if ( pmch_sweep->e_device_type == AGILENT_8960)
  272.         {
  273.             SyncShowMsg( " Agilent 8960 set downlink power fail " );
  274.         }
  275.         else
  276.         {
  277.             SyncShowMsg( " CMU 200 set downlink power fail " );
  278.         }
  279.         return false;
  280.     }
  281.     for(int arfcn=pmch_sweep->s_arfcn_start; arfcn<=pmch_sweep->s_arfcn_stop; arfcn +=pmch_sweep->s_arfcn_step )
  282.     {
  283.         if ( this->Terminated )
  284.         {
  285.             this->OnTerminate = pmch_sweep->ne_onTermByUser;
  286.             return false;
  287.         }
  288.         if( pmch_sweep->e_band == BANDSEL_GSM900 && arfcn>=125 && arfcn < 975)
  289.         {
  290.             arfcn = arfcn - 125 + 975;
  291.         }
  292.         if( ! rct_ctrl.RCT_BCHARFCN( &rct, arfcn ) )
  293.         {
  294.             SyncShowMsg( "Set equipment BCH ARFCN="+IntToStr(arfcn)+" fail" );
  295.             return false;
  296.         }
  297.         Sleep(200);
  298.         RF_PM_Object.ConfirmCallback   = ::ConfirmCallback_PMCS;
  299.         RF_PM_Object.REQ_Start( pmch_sweep->e_band, arfcn, pmch_sweep->pm_per_frame, pmch_sweep->pm_count,
  300.                                 NULL, true, pmch_sweep->gain, pmch_sweep->gain, 0 );
  301.         this->Suspend();
  302.         if( RF_PM_Object.Get_ConfirmState() != METAAPP_SUCCESS )
  303.         {
  304.             SyncShowMsg( "Power measurement fail" );
  305.             return false;
  306.         }
  307.         RfPm_Cnf  RFCnf_PM = RF_PM_Object.Get_RfPmCnf();
  308.         buf[0]='';
  309.         if( b_title )
  310.         {
  311.             b_title = false;
  312.             if( RFCnf_PM.extra_info.valid && RFCnf_PM.extra_info.validSamples )
  313.             {
  314.                 sprintf( buf, "                 DSP       Ant.     Used                           Valid " );
  315.                 pmch_sweep->st_Log->Add(buf);
  316.                 frmRFTool->write_PMCH_log_file(pmch_sweep->as_Log);
  317.                 sprintf( buf, " BAND   ARFCN    Power     Power    Gain    Deviation  I_DC  Q_DC  sample" );
  318.                 pmch_sweep->st_Log->Add(buf);
  319.                 frmRFTool->write_PMCH_log_file(pmch_sweep->as_Log);
  320.                 sprintf( buf, "=========================================================================" );
  321.                 pmch_sweep->st_Log->Add(buf);
  322.                 frmRFTool->write_PMCH_log_file(pmch_sweep->as_Log);
  323.             }
  324.             else
  325.             {
  326.                 sprintf( buf, "                 DSP       Ant.       Used              " );
  327.                 pmch_sweep->st_Log->Add(buf);
  328.                 frmRFTool->write_PMCH_log_file(pmch_sweep->as_Log);
  329.                 sprintf( buf, " BAND   ARFCN    Power     Power      Gain    Deviation " );
  330.                 pmch_sweep->st_Log->Add(buf);
  331.                 frmRFTool->write_PMCH_log_file(pmch_sweep->as_Log);
  332.                 sprintf( buf, "========================================================" );
  333.                 pmch_sweep->st_Log->Add(buf);
  334.                 frmRFTool->write_PMCH_log_file(pmch_sweep->as_Log);
  335.             }
  336.         }
  337.         if(RFCnf_PM.power!=1)
  338.         {
  339.             if(RFCnf_PM.deviation >= 0)
  340.             {
  341.                 if( RFCnf_PM.extra_info.valid && RFCnf_PM.extra_info.validSamples )
  342.                 {
  343.                         sprintf( buf, "%s %4d  %8.3f  %8.3f  %8.3f   %8.3f  %4d  %4d  %4d",
  344.                              BAND_STR[pmch_sweep->e_band],
  345.                              arfcn,
  346.                              (RFCnf_PM.power+RFCnf_PM.usedGain)/8.0,
  347.                              RFCnf_PM.power/8.0,
  348.                              RFCnf_PM.usedGain/8.0,
  349.                              sqrt(RFCnf_PM.deviation)/8.0,
  350.                              RFCnf_PM.extra_info.iOffset,
  351.                              RFCnf_PM.extra_info.qOffset,
  352.                              RFCnf_PM.extra_info.validSamples);
  353.                 }
  354.                 else
  355.                 {
  356.                        sprintf( buf, "%s %4d  %8.3f  %8.3f  %8.3f     %8.3f  ",
  357.                              BAND_STR[pmch_sweep->e_band],
  358.                              arfcn,
  359.                              (RFCnf_PM.power+RFCnf_PM.usedGain)/8.0,
  360.                              RFCnf_PM.power/8.0,
  361.                              RFCnf_PM.usedGain/8.0,
  362.                              sqrt(RFCnf_PM.deviation)/8.0 );
  363.                 }
  364.             }
  365.             else
  366.             {
  367.                 if( RFCnf_PM.extra_info.valid && RFCnf_PM.extra_info.validSamples )
  368.                 {
  369.                         sprintf( buf, "%s %4d  %8.3f  %8.3f  %8.3f     invalid  %4d  %4d  %4d",
  370.                              BAND_STR[pmch_sweep->e_band],
  371.                              arfcn,
  372.                              (RFCnf_PM.power+RFCnf_PM.usedGain)/8.0,
  373.                              RFCnf_PM.power/8.0,
  374.                              RFCnf_PM.usedGain/8.0,
  375.                              RFCnf_PM.extra_info.iOffset,
  376.                              RFCnf_PM.extra_info.qOffset,
  377.                              RFCnf_PM.extra_info.validSamples );
  378.                 }
  379.                 else
  380.                 {
  381.                         sprintf( buf, "%s %4d  %8.3f  %8.3f  %8.3f     invalid ",
  382.                              BAND_STR[pmch_sweep->e_band],
  383.                              arfcn,
  384.                              (RFCnf_PM.power+RFCnf_PM.usedGain)/8.0,
  385.                              RFCnf_PM.power/8.0,
  386.                              RFCnf_PM.usedGain/8.0);
  387.                 }
  388.             }
  389.         }
  390.         else
  391.         {
  392.             if( RFCnf_PM.extra_info.valid && RFCnf_PM.extra_info.validSamples )
  393.             {
  394.                     sprintf( buf, "%s %4d  Invalid   Invalid   %8.3f     Invalid  %4d  %4d  %4d",
  395.                          BAND_STR[pmch_sweep->e_band],
  396.                          arfcn,
  397.                          RFCnf_PM.usedGain/8.0,
  398.                          RFCnf_PM.extra_info.iOffset,
  399.                          RFCnf_PM.extra_info.qOffset,
  400.                          RFCnf_PM.extra_info.validSamples );
  401.             }
  402.             else
  403.             {
  404.                     sprintf( buf, "%s %4d  Invalid   Invalid   %8.3f     Invalid ",
  405.                          BAND_STR[pmch_sweep->e_band],
  406.                          arfcn,
  407.                          RFCnf_PM.usedGain/8.0
  408.                          );
  409.             }
  410.         }
  411.         pmch_sweep->st_Log->Add(buf);
  412.         frmRFTool->write_PMCH_log_file(pmch_sweep->as_Log);
  413.         Sleep(50);
  414.         RF_STOP_Object.REQ_Start();
  415.     }
  416.     return true;
  417. }