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

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) 2001
  8. *
  9. *****************************************************************************/
  10. /*****************************************************************************
  11.  *
  12.  * Filename:
  13.  * ---------
  14.  *   rf_sn_sweep.cpp
  15.  *
  16.  * Project:
  17.  * --------
  18.  *   Maui META APP
  19.  *
  20.  * Description:
  21.  * ------------
  22.  *  RF saturate and noise floor point auto search source
  23.  *
  24.  * Author:
  25.  * -------
  26.  *  Andy Ueng (mtk00490)
  27.  *
  28.  *============================================================================
  29.  *             HISTORY
  30.  * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  31.  *------------------------------------------------------------------------------
  32.  * $Revision$
  33.  * $Modtime$
  34.  * $Log$
  35.  * 
  36.  *------------------------------------------------------------------------------
  37.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  38.  *============================================================================
  39.  ****************************************************************************/
  40. //---------------------------------------------------------------------------
  41. #include <vcl.h>
  42. #include <math.h>
  43. #pragma hdrstop
  44. #include "form_RFTool.h"
  45. #include "rf_pmch_sweep.h"
  46. #include "meta_utils.h"
  47. //#include "Crystal_INIFileHandle.h"
  48. #include "man_dll.h"
  49. // equipment
  50. #include "ageCommon.h"
  51. #include "age1968A.h"
  52. #include "cmu200.h"
  53. #ifndef  _RCT_COMMON_H_
  54. #include "rct_common.h"
  55. #endif
  56. #ifndef  _RCT_CTRL_H_
  57. #include "rct_ctrl.h"
  58. #endif
  59. // misc
  60. #ifndef  _BAND_UTILS_H_
  61. #include "band_utils.h"
  62. #endif
  63. //---------------------------------------------------------------------------
  64. //------------------------------------------------------------------------------
  65. //==============================================================================
  66. static void  ConfirmCallback_SN( void )
  67. {
  68.     if(frmRFTool->m_pt_SN_sweep != NULL )
  69.     {
  70.         frmRFTool->m_pt_SN_sweep->Resume();
  71.     }
  72. }
  73. //------------------------------------------------------------------------------
  74. static void cb_rf_stop_SN()
  75. {
  76.     if(frmRFTool->m_pt_SN_sweep != NULL )
  77.     {
  78.         frmRFTool->m_pt_SN_sweep->Resume();
  79.     }
  80. }
  81. //==============================================================================
  82. void _fastcall CRF_SN_SWEEP::ShowMsg()
  83. {
  84.     ShowMessage( as_Msg );
  85. }
  86. //------------------------------------------------------------------------------
  87. void _fastcall CRF_SN_SWEEP::SyncShowMsg(AnsiString as)
  88. {
  89.     as_Msg = as;
  90.     Synchronize( ShowMsg );
  91. }
  92. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  93. void _fastcall CRF_SN_SWEEP::FillSNResult( void )
  94. {
  95.     frmRFTool->FillSNResult( tb_title, ts_snresult );
  96. }
  97. //------------------------------------------------------------------------------
  98. void _fastcall CRF_SN_SWEEP::SyncFillSNResult(bool  is_title, S_SNResult &sn_result)
  99. {
  100.     ts_snresult = sn_result;
  101.     tb_title = is_title;
  102.     Synchronize( FillSNResult );
  103. }
  104. //==============================================================================
  105. __fastcall CRF_SN_SWEEP::CRF_SN_SWEEP(
  106.                                            bool CreateSuspended,
  107.                                            S_SNSweep *p_Sn_Sweep
  108.                                           ): TThread(CreateSuspended)
  109. {
  110.     p_sn_sweep = p_Sn_Sweep;
  111.     b_title = true;
  112. }
  113. //---------------------------------------------------------------------------
  114. void __fastcall CRF_SN_SWEEP::Execute()
  115. {
  116.     rct.device_type = p_sn_sweep->e_device_type;
  117.     if( ! SN_CfgRead() )
  118.     {
  119.         SyncShowMsg( "Read CFG file fail" );
  120.         return;
  121.     }
  122.     if( ! rct_ctrl.RCT_Init( &rct, BandIdx_To_FreqBandString(p_sn_sweep->e_band) ) )
  123.     {
  124.         SyncShowMsg( "Initialize equipment fail" );
  125.         return;
  126.     }
  127.     if( ! SN_Sweep() )
  128.     {
  129.         return;
  130.     }
  131.     this->OnTerminate = p_sn_sweep->ne_onTermSuccess;
  132. }
  133. //---------------------------------------------------------------------------
  134. bool __fastcall CRF_SN_SWEEP::SN_CfgRead( void )
  135. {
  136.     if( p_sn_sweep->e_device_type == AGILENT_8960 )
  137.     {
  138.         if((! p_sn_sweep->rf_cfg->getGSM400_CableLoss( rct.age.d400 )) ||
  139.            (! p_sn_sweep->rf_cfg->getGSM850_CableLoss( rct.age.d850 )) ||
  140.            (! p_sn_sweep->rf_cfg->getGSM900_CableLoss( rct.age.d900 )) ||
  141.            (! p_sn_sweep->rf_cfg->getDCS1800_CableLoss( rct.age.d1800 )) ||
  142.            (! p_sn_sweep->rf_cfg->getPCS1900_CableLoss( rct.age.d1900 ))
  143.           )
  144.         {
  145.             SyncShowMsg( " Agilent 8960 read config file (cable loss) fail " );
  146.             return false;
  147.         }
  148.         if(! p_sn_sweep->rf_cfg->getTimeOut( rct.age.TMO ) )
  149.         {
  150.             SyncShowMsg( "Get Time Out from file fail" );
  151.             return false;
  152.         }
  153.         if(! p_sn_sweep->rf_cfg->getGPIB_Addr( rct.age.ADD ) )
  154.         {
  155.             SyncShowMsg( "Get GPIB address from file fail" );
  156.             return false;
  157.         }
  158.     }
  159.     else // CMU 200
  160.     {
  161.         if(
  162.              (! p_sn_sweep->rf_cfg->getCMU200_INPUT_GSM850_CableLoss( rct.cmu.loss_gsm850_i )) ||
  163.              (! p_sn_sweep->rf_cfg->getCMU200_INPUT_GSM900_CableLoss( rct.cmu.loss_gsm_i    )) ||
  164.              (! p_sn_sweep->rf_cfg->getCMU200_INPUT_DCS1800_CableLoss( rct.cmu.loss_dcs_i   )) ||
  165.              (! p_sn_sweep->rf_cfg->getCMU200_INPUT_PCS1900_CableLoss( rct.cmu.loss_pcs_i   ))
  166.           )
  167.         {
  168.              SyncShowMsg(  " CMU200 read config file (input cable loss) fail " );
  169.              return false;
  170.         }
  171.         //*************************************************************
  172.         //************************************************************
  173.         if(
  174.                (! p_sn_sweep->rf_cfg->getCMU200_OUTPUT_GSM850_CableLoss( rct.cmu.loss_gsm850_o )) ||
  175.                (! p_sn_sweep->rf_cfg->getCMU200_OUTPUT_GSM900_CableLoss( rct.cmu.loss_gsm_o ))    ||
  176.                (! p_sn_sweep->rf_cfg->getCMU200_OUTPUT_DCS1800_CableLoss( rct.cmu.loss_dcs_o ))   ||
  177.                (! p_sn_sweep->rf_cfg->getCMU200_OUTPUT_PCS1900_CableLoss( rct.cmu.loss_pcs_o ))
  178.                                                       )
  179.         {
  180.              SyncShowMsg(  " CMU200 read config file (output cable loss) fail " );
  181.              return false;
  182.         }
  183.         if(! p_sn_sweep->rf_cfg->getCMU200_TimeOut( rct.cmu.TMO ) )
  184.         {
  185.             SyncShowMsg( "Get Time Out from file fail" );
  186.             return false;
  187.         }
  188.         if(! p_sn_sweep->rf_cfg->getCMU200_GPIB_Addr( rct.cmu.ADD ) )
  189.         {
  190.             SyncShowMsg( "Get GPIB address from file fail" );
  191.             return false;
  192.         }
  193.         rct.cmu.ADD = rct.cmu.ADD.SubString(0, rct.cmu.ADD.Pos("::INSTR")-1);
  194.     }
  195.     return true;
  196. }
  197. //---------------------------------------------------------------------------
  198. bool __fastcall CRF_SN_SWEEP::SN_Sweep( void )
  199. {
  200.     //const char  BAND_STR[4][10] =
  201.     //{
  202.     //   "GSM900 ",
  203.     //   "DCS1800",
  204.     //   "PCS1900",
  205.     //   "GSM850"
  206.     //};
  207.     ViInt16 vi_Band;
  208.     char buf[40000], buf1[10000];
  209.     switch ( p_sn_sweep->e_band )
  210.     {
  211.          case BANDSEL_GSM900:
  212.             vi_Band = age1960_EGSM_BAND;
  213.          break;
  214.          case BANDSEL_DCS1800:
  215.             vi_Band = age1960_DCS1800_BAND;
  216.          break;
  217.          case BANDSEL_PCS1900:
  218.             vi_Band = age1960_PCS1900_BAND;
  219.          break;
  220.          case BANDSEL_GSM850:
  221.             vi_Band = age1960_GSM850_BAND;
  222.          break;
  223.          default:
  224.          break;
  225.     }; // switch
  226.     if( ! rct_ctrl.RCT_cellBand( &rct, vi_Band ) )
  227.     {
  228.         if ( p_sn_sweep->e_device_type == AGILENT_8960)
  229.         {
  230.             SyncShowMsg( " Agilent 8960 set cell e_band fail ");
  231.         }
  232.         else
  233.         {
  234.             SyncShowMsg( " CMU 200 set cell e_band fail ");
  235.         }
  236.         return false;
  237.     }
  238.     if( ! rct_ctrl.RCT_ContModTran( &rct ) )
  239.     {
  240.         if ( p_sn_sweep->e_device_type == AGILENT_8960)
  241.         {
  242.             SyncShowMsg( " Agilent 8960 set continuous transmition mode fail " );
  243.         }
  244.         else
  245.         {
  246.             SyncShowMsg( " CMU 200 set continuous transmition mode fail " );
  247.         }
  248.         return false;
  249.     }
  250.     if( ! rct_ctrl.RCT_BCHARFCN( &rct, p_sn_sweep->s_arfcn ) )
  251.     {
  252.         SyncShowMsg( "Set equipment BCH ARFCN="+IntToStr(p_sn_sweep->s_arfcn)+" fail" );
  253.         return false;
  254.     }                            
  255.     SyncFillSNResult( true, ts_snresult );
  256.     if( ! p_sn_sweep->b_gain_change_first )// DN power change first
  257.     {
  258.         double d_dn;
  259.         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 )
  260.         {
  261.             bool b_saturate = false;
  262.             bool b_noise_floor = false;
  263.             ts_snresult.d_saturate_equ_power = 0;
  264.             ts_snresult.d_noise_floor_equ_power = 0;
  265.             ts_snresult.d_saturate_dsppwr = 0;
  266.             ts_snresult.d_saturate_antpwr = 0;
  267.             ts_snresult.d_noise_floor_dsppwr = 0;
  268.             ts_snresult.d_noise_floor_antpwr = 0;
  269.             Sleep(200);
  270.            // int min_gain, max_gain;
  271.             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 )
  272.             {
  273.                 if( ! rct_ctrl.RCT_cellPower( &rct, d_dn ) )
  274.                 {
  275.                     if ( p_sn_sweep->e_device_type == AGILENT_8960)
  276.                     {
  277.                         SyncShowMsg( " Agilent 8960 set downlink power fail " );
  278.                     }
  279.                     else
  280.                     {
  281.                         SyncShowMsg( " CMU 200 set downlink power fail " );
  282.                     }
  283.                     return false;
  284.                 }
  285.                 if ( this->Terminated )
  286.                 {
  287.                     this->OnTerminate = p_sn_sweep->ne_onTermByUser;
  288.                     return false;
  289.                 }
  290.                 RF_PM_Object.ConfirmCallback   = ::ConfirmCallback_SN;
  291.                 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,
  292.                                         NULL, true, i_gain, i_gain, 0 );
  293.                 this->Suspend();
  294.                 if( RF_PM_Object.Get_ConfirmState() != METAAPP_SUCCESS )
  295.                 {
  296.                     SyncShowMsg( "Power measurement fail" );
  297.                     return false;
  298.                 }
  299.                 RfPm_Cnf  RFCnf_PM = RF_PM_Object.Get_RfPmCnf();
  300.                 ts_snresult.i_saturate_used_gain = RFCnf_PM.usedGain/8.0;
  301.                 ts_snresult.i_noise_floor_used_gain = RFCnf_PM.usedGain/8.0;
  302.                 
  303.                 if( RFCnf_PM.ok && RFCnf_PM.power != 1)
  304.                 {
  305.                     if( (RFCnf_PM.power / 8.0 + p_sn_sweep->d_threshold) <= d_dn )
  306.                     {
  307.                         b_saturate = true;
  308.                         ts_snresult.i_band_idx = p_sn_sweep->e_band;
  309.                         ts_snresult.i_arfcn = p_sn_sweep->s_arfcn;
  310.                         ts_snresult.i_saturate_used_gain  = RFCnf_PM.usedGain/8.0;
  311.                         ts_snresult.d_saturate_equ_power = d_dn;
  312.                         ts_snresult.d_saturate_dsppwr = (RFCnf_PM.power + RFCnf_PM.usedGain)/8.0;
  313.                         ts_snresult.d_saturate_antpwr = RFCnf_PM.power/8.0;
  314.                         ts_snresult.d_linear_range = ts_snresult.d_saturate_dsppwr - ts_snresult.d_noise_floor_dsppwr;
  315.                         if( p_sn_sweep->d_min_P_DL < p_sn_sweep->d_max_P_DL  )
  316.                         {
  317.                             SyncFillSNResult( false, ts_snresult );
  318.                             break;
  319.                         }
  320.                     }
  321.                     else if( (RFCnf_PM.power / 8.0 - p_sn_sweep->d_threshold) >= d_dn )
  322.                     {
  323.                         b_noise_floor = true;
  324.                         ts_snresult.i_band_idx = p_sn_sweep->e_band;
  325.                         ts_snresult.i_arfcn = p_sn_sweep->s_arfcn;
  326.                         ts_snresult.d_noise_floor_equ_power = d_dn;
  327.                         ts_snresult.i_noise_floor_used_gain  = RFCnf_PM.usedGain/8.0;
  328.                         ts_snresult.d_noise_floor_dsppwr = (RFCnf_PM.power + RFCnf_PM.usedGain)/8.0;
  329.                         ts_snresult.d_noise_floor_antpwr =  RFCnf_PM.power/8.0;
  330.                         ts_snresult.d_linear_range = ts_snresult.d_saturate_dsppwr - ts_snresult.d_noise_floor_dsppwr;
  331.                         if( p_sn_sweep->d_min_P_DL > p_sn_sweep->d_max_P_DL  )
  332.                         {
  333.                             SyncFillSNResult( false, ts_snresult );
  334.                             break;
  335.                         }
  336.                     }
  337.                 }
  338.                 Sleep(50);
  339.                 RF_STOP_Object.REQ_Start();
  340.             }
  341.             if( ( (! b_saturate) && (p_sn_sweep->d_min_P_DL < p_sn_sweep->d_max_P_DL) )  ||
  342.                 ( (! b_noise_floor) && (p_sn_sweep->d_min_P_DL > p_sn_sweep->d_max_P_DL) )
  343.               )
  344.             {
  345.                 ts_snresult.i_band_idx = p_sn_sweep->e_band;
  346.                 ts_snresult.i_arfcn = p_sn_sweep->s_arfcn;
  347.                 ts_snresult.d_linear_range = ts_snresult.d_saturate_dsppwr - ts_snresult.d_noise_floor_dsppwr;
  348.                 SyncFillSNResult( false, ts_snresult );
  349.             }
  350.         }
  351.     }
  352.     if( p_sn_sweep->b_gain_change_first )
  353.     {
  354.         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 )
  355.         {
  356.             bool b_saturate = false;
  357.             bool b_noise_floor = false;
  358.             ts_snresult.d_saturate_equ_power = d_dn;
  359.             ts_snresult.d_saturate_dsppwr = 0;
  360.             ts_snresult.d_saturate_antpwr = 0;
  361.             ts_snresult.d_noise_floor_equ_power = d_dn;
  362.             ts_snresult.d_noise_floor_dsppwr = 0;
  363.             ts_snresult.d_noise_floor_antpwr = 0;
  364.             if( ! rct_ctrl.RCT_cellPower( &rct, d_dn ) )
  365.             {
  366.                 if ( p_sn_sweep->e_device_type == AGILENT_8960)
  367.                 {
  368.                     SyncShowMsg( " Agilent 8960 set downlink power fail " );
  369.                 }
  370.                 else
  371.                 {
  372.                     SyncShowMsg( " CMU 200 set downlink power fail " );
  373.                 }
  374.                 return false;
  375.             }
  376.             Sleep(200);
  377.             int min_gain, max_gain;
  378.             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 )
  379.             {
  380.                 if ( this->Terminated )
  381.                 {
  382.                     this->OnTerminate = p_sn_sweep->ne_onTermByUser;
  383.                     return false;
  384.                 }
  385.                 RF_PM_Object.ConfirmCallback   = ::ConfirmCallback_SN;
  386.                 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,
  387.                                         NULL, true, i_gain, i_gain, 0 );
  388.                 this->Suspend();
  389.                 if( RF_PM_Object.Get_ConfirmState() != METAAPP_SUCCESS )
  390.                 {
  391.                     SyncShowMsg( "Power measurement fail" );
  392.                     return false;
  393.                 }
  394.                 RfPm_Cnf  RFCnf_PM = RF_PM_Object.Get_RfPmCnf();
  395.                 if( RFCnf_PM.ok && RFCnf_PM.power != 1)
  396.                 {
  397.                     if( (RFCnf_PM.power / 8.0 + p_sn_sweep->d_threshold) <= d_dn )
  398.                     {
  399.                         b_saturate = true;
  400.                         ts_snresult.i_band_idx = p_sn_sweep->e_band;
  401.                         ts_snresult.i_arfcn = p_sn_sweep->s_arfcn;
  402.                         ts_snresult.i_saturate_used_gain  = RFCnf_PM.usedGain/8.0;
  403.                         ts_snresult.d_saturate_equ_power = d_dn;
  404.                         ts_snresult.d_saturate_dsppwr = (RFCnf_PM.power + RFCnf_PM.usedGain)/8.0;
  405.                         ts_snresult.d_saturate_antpwr = RFCnf_PM.power/8.0;
  406.                         ts_snresult.d_linear_range = ts_snresult.d_saturate_dsppwr - ts_snresult.d_noise_floor_dsppwr;
  407.                         if( p_sn_sweep->min_gain < p_sn_sweep->max_gain )
  408.                         {
  409.                             SyncFillSNResult( false, ts_snresult );
  410.                             break;
  411.                         }
  412.                     }
  413.                     else if( (RFCnf_PM.power / 8.0 - p_sn_sweep->d_threshold) >= d_dn )
  414.                     {
  415.                         b_noise_floor = true;
  416.                         ts_snresult.i_band_idx = p_sn_sweep->e_band;
  417.                         ts_snresult.i_arfcn = p_sn_sweep->s_arfcn;
  418.                         ts_snresult.i_noise_floor_used_gain  = RFCnf_PM.usedGain/8.0;
  419.                         ts_snresult.d_noise_floor_equ_power = d_dn;
  420.                         ts_snresult.d_noise_floor_dsppwr = (RFCnf_PM.power + RFCnf_PM.usedGain)/8.0;
  421.                         ts_snresult.d_noise_floor_antpwr =  RFCnf_PM.power/8.0;
  422.                         ts_snresult.d_linear_range = ts_snresult.d_saturate_dsppwr - ts_snresult.d_noise_floor_dsppwr;
  423.                         if( p_sn_sweep->min_gain > p_sn_sweep->max_gain )
  424.                         {
  425.                             SyncFillSNResult( false, ts_snresult );
  426.                             break;
  427.                         }
  428.                     }
  429.                 }
  430.                 Sleep(50);
  431.                 RF_STOP_Object.REQ_Start();
  432.             }
  433.             if( ( (! b_saturate) && (p_sn_sweep->min_gain < p_sn_sweep->max_gain) ) ||
  434.                 ( (! b_noise_floor) && (p_sn_sweep->min_gain > p_sn_sweep->max_gain) )
  435.               )
  436.             {
  437.                 ts_snresult.i_band_idx = p_sn_sweep->e_band;
  438.                 ts_snresult.i_arfcn = p_sn_sweep->s_arfcn;
  439.                 ts_snresult.d_linear_range = ts_snresult.d_saturate_dsppwr - ts_snresult.d_noise_floor_dsppwr;
  440.                 SyncFillSNResult( false, ts_snresult );
  441.             }
  442.         }
  443.     }
  444.     
  445.     return true;
  446. }