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

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.  *   T_Init_Age8960.cpp
  40.  *
  41.  * Project:
  42.  * --------
  43.  *   Maui META APP
  44.  *
  45.  * Description:
  46.  * ------------
  47.  *  Equipement thread 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. #pragma hdrstop
  68. #include "man_dll.h"
  69. #include "META_Factory.h"
  70. #include "t_init_age8960.h"
  71. #include "meta_utils.h"
  72. #include "meta_factory_cfg.h"
  73. // equipment
  74. #include "ageCommon.h"
  75. #include "age1968A.h"
  76. //#ifndef hpe3631a_INCLUDE
  77. //#include "hpe3631a.h"
  78. //#endif
  79. #pragma package(smart_init)
  80. //---------------------------------------------------------------------------
  81. //   Important: Methods and properties of objects in VCL can only be
  82. //   used in a method called using Synchronize, for example:
  83. //
  84. //      Synchronize(UpdateCaption);
  85. //
  86. //   where UpdateCaption could look like:
  87. //
  88. //      void __fastcall Unit1::UpdateCaption()
  89. //      {
  90. //        Form1->Caption = "Updated in a thread";
  91. //      }
  92. //---------------------------------------------------------------------------
  93. bool is_Age8960_start = false;
  94. bool is_age1960_fail = false;
  95. bool is_AgilentPowerSupply_fail = false;
  96. // added by Andy Ueng for ADC calibration
  97. bool IS_AgilentPowerSupply_INITIALISE = false;
  98. // end of added
  99. //------------------------------------------------------------------------------
  100. //------------------------------------------------------------------------------
  101. //R&S
  102. #include "cmu200.h"
  103. #include "K2302.h"
  104. extern K2302_VAR k2302;
  105. CMU_VAR cmu;
  106. //------------------------------------------------------------------------------
  107. void _fastcall T_Init_Age8960::ShowMsg()
  108. {
  109.    ShowMessage( as_Msg );
  110. }
  111. //------------------------------------------------------------------------------
  112. //------------------------------------------------------------------------------
  113. void _fastcall T_Init_Age8960::SyncShowMsg(AnsiString as)
  114. {
  115.    as_Msg = as;
  116.    Synchronize( ShowMsg );
  117. }
  118. //------------------------------------------------------------------------------
  119. __fastcall T_Init_Age8960::T_Init_Age8960(
  120.                                             bool CreateSuspended,
  121.                                             AnsiString as_ADDR,
  122.                                             AnsiString as_Agilent_Power_Supply_addr,
  123.                                             int i_TimeOut,
  124.                                             signed short ss_Band,
  125.                                             TNotifyEvent ne_OnTermHandler,
  126.                                             ViSession &vs_Age196x,
  127.                                             ViSession &vs_AgePowerSupply, // for ADC calibration
  128.                                             TMETA_factory_cfg *cfg,
  129.                                             TStringList *st_Log,
  130.                                             AnsiString &as_TaModel
  131.                                           )
  132.         : TThread(CreateSuspended)
  133. {
  134.     as_RF_Equipment_ADDR = as_ADDR;
  135.     as_AGE8960_ADDR = as_ADDR;
  136.     as_Agilent_Power_Supply_ADDR = as_Agilent_Power_Supply_addr;
  137.     i_AGE8960_TimeOut = i_TimeOut;
  138.     ss_CellBand = ss_Band;
  139.     ne_OnTerminate = ne_OnTermHandler;
  140.     pvi_Age196x = &vs_Age196x;
  141.     pvi_AgePowerSupply = &vs_AgePowerSupply; // for ADC calibration
  142.     MF_cfg = cfg;
  143.     log = st_Log; // for log
  144.     as_pAgeTaModel = &as_TaModel;
  145.     is_Age8960_start = true;
  146. }
  147. //---------------------------------------------------------------------------
  148. void __fastcall T_Init_Age8960::Execute()
  149. {
  150.     //////////////////////////// RF calibration ///////////////////////////////////////
  151.     if( Form_META_Factory->cbAFC->Checked || Form_META_Factory->cbRxPathLoss->Checked || Form_META_Factory->cbIP2->Checked ||
  152.         Form_META_Factory->cbTxPcl->Checked  || Form_META_Factory->cbTxPhaseError->Checked )
  153.     {
  154.         if ( Form_META_Factory->rbAgilent8960->Checked )
  155.         {
  156.             if ((vistat = age1960_init( as_AGE8960_ADDR.c_str(), 0, 0, &vi_Age196x)) != VI_SUCCESS)
  157.             {
  158.                 is_age1960_fail = true;
  159.                 Application->MessageBox( " Initialize Agilent 8960 fail ", "Fail", MB_OK );
  160.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " FAIL: Agilent 8960 < Initialize (init)"
  161.                         );
  162.                 return;
  163.             }
  164.             if ( (vistat = age_QueryTaModel( vi_Age196x, as_pAgeTaModel )) != VI_SUCCESS)
  165.             {
  166.                 is_age1960_fail = true;
  167.                 Application->MessageBox( " Query Agilent 8960 TA Model fail ", "Fail", MB_OK );
  168.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " FAIL: Agilent 8960 < Query Agilent 8960 TA Model (init)"
  169.                         );
  170.                 return;
  171.             }    
  172.             //////////////////////////////////////////////////////////////////////////////
  173.             Sleep(50);
  174.             if ( vi_Age196x != VI_NULL)
  175.             {
  176.                 if ( age1960_dcl(vi_Age196x)!= VI_SUCCESS)
  177.                 {
  178.                     is_age1960_fail = true;
  179.                     Application->MessageBox( " Agilent 8960 DCL fail ", "Fail", MB_OK );
  180.                     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " FAIL: Agilent 8960 < DCL (init)"
  181.                             );
  182.                     return;
  183.                 }
  184.             }
  185.             Sleep(50);
  186.             if ( vi_Age196x != VI_NULL)
  187.             {
  188.                 if ((vistat = age1960_reset( vi_Age196x )) != VI_SUCCESS)
  189.                 {
  190.                     is_age1960_fail = true;
  191.                     Application->MessageBox( " Reset Agilent 8960 fail ", "Fail", MB_OK );
  192.                     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " FAIL: Agilent 8960 < reset (init) "
  193.                              );
  194.                     return;
  195.                 }
  196.             }
  197.             /////////////////////////////////////////////////////////////////////////////
  198.             if ((vistat = age1960_timeOut (
  199.                                              vi_Age196x,
  200.                                              i_AGE8960_TimeOut
  201.                                            )) != VI_SUCCESS)
  202.             {
  203.                 is_age1960_fail = true;
  204.                 Application->MessageBox( " Agilent 8960 set timeout fail ", "Fail", MB_OK );
  205.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " FAIL: Agilent 8960 < set timeout (init)"
  206.                         );
  207.                 return;
  208.             }
  209.             /////////////////////////////////////////////////////////////////////////////
  210.  /*
  211. ViStatus _VI_FUNC age1960_amplitudeOffset(ViSession instrumentHandle, ViReal64 frequencyArray
  212. [燷, ViReal64 offsetArray[燷, ViInt32 ampOffsetItems);
  213. */
  214.             const AMP_OFFSET_ITEMS = 10;
  215.             ViReal64  freqArray[AMP_OFFSET_ITEMS] = { 400000000.0,
  216.                                                       641000000.0,
  217.                                                       641100000.0,
  218.                                                       876000000.0,
  219.                                                       876100000.0,
  220.                                                       1312000000.0,
  221.                                                       1312100000.0,
  222.                                                       1880000000.0,
  223.                                                       1881000000.0,
  224.                                                       2000000000.0 };
  225. //   ViReal64  offsetArray[AMP_OFFSET_ITEMS] = { d_dB_CableLoss, d_dB_CableLoss };
  226.             double d400,d850,d900,d1800,d1900;
  227.             if((! MF_cfg->getGSM400_CableLoss( d400 )) ||
  228.                (! MF_cfg->getGSM850_CableLoss( d850 )) ||
  229.                (! MF_cfg->getGSM900_CableLoss( d900 )) ||
  230.                (! MF_cfg->getDCS1800_CableLoss( d1800 )) ||
  231.                (! MF_cfg->getPCS1900_CableLoss( d1900 ))
  232.               )
  233.             {
  234.                 //SyncShowMsg("Agilent 8960 read config file cable loss fail");
  235.                 Application->MessageBox( " Agilent 8960 read config file (cable loss) fail ", "Fail", MB_OK );
  236.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " FAIL: Agilent 8960 < read config file (cable loss) (init)"
  237.                         );
  238.                 return;
  239.             }
  240.             ViReal64  offsetArray[AMP_OFFSET_ITEMS] = { d400,
  241.                                                         d400,
  242.                                                         d850,
  243.                                                         d850,
  244.                                                         d900,
  245.                                                         d900,
  246.                                                         d1800,
  247.                                                         d1800,
  248.                                                         d1900,
  249.                                                         d1900
  250.                                                       };
  251.             if ((vistat = age1960_amplitudeOffset (
  252.                                                       vi_Age196x,
  253.                                                       freqArray,
  254.                                                       offsetArray,
  255.                                                      AMP_OFFSET_ITEMS
  256.                                                   )) != VI_SUCCESS)
  257.             {
  258.                 is_age1960_fail = true;
  259.                 Application->MessageBox( " Agilent 8960 set cable loss fail ", "Fail", MB_OK );
  260.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " FAIL: Agilent 8960 < set cable loss (init)"
  261.                          );
  262.                 return;
  263.             }
  264.             /////////////////////////////////////////////////////////////////////////////
  265.             if( as_pAgeTaModel->AnsiCompareIC( "E1968A" ) == 0 || as_pAgeTaModel->AnsiCompareIC( "E6701C" ) == 0 || as_pAgeTaModel->AnsiCompareIC( "E6701D" ) == 0 )
  266.             {
  267.                 if ((vistat = age1968A_operatingMode(
  268.                                                      vi_Age196x,
  269.                                                     (ViInt16) OPERATING_MODE_GSM_BCH_TCH
  270.                                                    ))!= VI_SUCCESS)
  271.                 {
  272.                     is_age1960_fail = true;
  273.                     Application->MessageBox( " Agilent 8960 set operation mode fail ", "Fail", MB_OK );
  274.                     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " FAIL: Agilent 8960 < set opeartion mode (init)"
  275.                              );
  276.                     return;
  277.                 }
  278.             }
  279.             else  // Agilent 1960A
  280.             {
  281.                 if ((vistat = age1960_operatingMode(
  282.                                                      vi_Age196x,
  283.                                                     (ViInt16) age1960_TEST_MODE
  284.                                                    ))!= VI_SUCCESS)
  285.                 {
  286.                     is_age1960_fail = true;
  287.                     Application->MessageBox( " Agilent 8960 set operation mode fail ", "Fail", MB_OK );
  288.                     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " FAIL: Agilent 8960 < set opeartion mode (init)"
  289.                              );
  290.                     return;
  291.                 }
  292.             }
  293.             /////////////////////////////////////////////////////////////////////////////
  294.             /*
  295.             if ((vistat = age1960_cellBand(
  296.                                               vi,
  297.                                              age1960_CELL_1,
  298. //                                           (short)( cbox_Cell_Band->ItemIndex+1)
  299.                                              ss_CellBand
  300.                                           ))!= VI_SUCCESS)
  301.             {
  302.                 //SyncShowMsg("Agilent 8960 set Cell Band fail");
  303.                 Application->MessageBox( " Agilent 8960 set cell band fail ", "Fail", MB_OK );
  304.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " FAIL: Agilent 8960 < set cell band (init)"
  305.                        );
  306.                 return;
  307.             }
  308.             */
  309.             _VI_PTR pvi_Age196x = vi_Age196x;
  310.         } // Agilent 8960
  311.         else  // CMU 200                           
  312.         {
  313.             double d400,d850,d900,d1800,d1900,Out400,Out850,Out900,Out1800,Out1900;
  314.             if((! MF_cfg->getCMU200_INPUT_GSM400_CableLoss( d400 )) ||
  315.                (! MF_cfg->getCMU200_INPUT_GSM850_CableLoss( d850 )) ||
  316.                (! MF_cfg->getCMU200_INPUT_GSM900_CableLoss( d900 )) ||
  317.                (! MF_cfg->getCMU200_INPUT_DCS1800_CableLoss( d1800 )) ||
  318.                (! MF_cfg->getCMU200_INPUT_PCS1900_CableLoss( d1900 )) )
  319.             {
  320.                   Application->MessageBox( "CMU 200 read config file cable loss fail", "Fail", MB_OK );
  321.                   return;
  322.             }
  323.             if((! MF_cfg->getCMU200_OUTPUT_GSM400_CableLoss( Out400 )) ||
  324.                (! MF_cfg->getCMU200_OUTPUT_GSM850_CableLoss( Out850 )) ||
  325.                (! MF_cfg->getCMU200_OUTPUT_GSM900_CableLoss( Out900 )) ||
  326.                (! MF_cfg->getCMU200_OUTPUT_DCS1800_CableLoss( Out1800 )) ||
  327.                (! MF_cfg->getCMU200_OUTPUT_PCS1900_CableLoss( Out1900 )) )
  328.             {
  329.                   Application->MessageBox( "CMU 200 read config file cable loss fail", "Fail", MB_OK );
  330.                   return;
  331.             }
  332.             cmu.loss_gsm850_i=d850;
  333.             cmu.loss_gsm850_o=Out850;
  334.             cmu.loss_gsm_i=d900;
  335.             cmu.loss_gsm_o=Out900;
  336.             cmu.loss_dcs_i=d1800;
  337.             cmu.loss_dcs_o=Out1800;
  338.             cmu.loss_pcs_i=d1900;
  339.             cmu.loss_pcs_o=Out1900;
  340.             cmu.ADD=as_RF_Equipment_ADDR.SubString(0, as_RF_Equipment_ADDR.Pos("::INSTR")-1);
  341.             cmu.TMO=i_AGE8960_TimeOut;
  342.             cmu.BAND="GSM";
  343.             if( !cmu_init(&cmu) )
  344.             {
  345.                 Application->MessageBox( "Initial CMU200 fail", "Fail", MB_OK );
  346.                 return;
  347.             }
  348.             Sleep(1500);
  349.             _VI_PTR pvi_Age196x = vi_Age196x;
  350.         }
  351.     } // RF calibration checked
  352.     ///////////////////////  ADC calibration  /////////////////////////////////////
  353.     if (m_pCal->s_CalItem.b_adc_cal)
  354.     {
  355.         if( Form_META_Factory->rbAgilent661x->Checked )
  356.         {
  357.             if((vistat = hp661x_init( as_Agilent_Power_Supply_ADDR.c_str(), 0, 0, &vi_AgePowerSupply)) != VI_SUCCESS)
  358.             {
  359.                 is_AgilentPowerSupply_fail = true;
  360.                 Application->MessageBox( " Initialize Agilent 661x fail ", "Fail", MB_OK );
  361.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " FAIL: Agilent 661x < initialize (init)"
  362.                          );
  363.                 return;
  364.             }
  365.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " Agilent 661x ok < initialize (init)"
  366.                       );
  367.         }
  368.         else if ( Form_META_Factory->rbAgilent663x2->Checked )
  369.         {
  370.             if((vistat = hp663x2_init(as_Agilent_Power_Supply_ADDR.c_str(), 0, 0, &vi_AgePowerSupply)) != VI_SUCCESS)
  371.             {
  372.                 is_AgilentPowerSupply_fail = true;
  373.                 Application->MessageBox( " Initialize Agilent 663x2 fail ", "Fail", MB_OK );
  374.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " FAIL: Agilent 663x2 < initialize (init)"
  375.                          );
  376.                 return;
  377.             }
  378.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " Agilent 663x2 ok < initialize (init)"
  379.                       );
  380.         }
  381.         else if ( Form_META_Factory->rbAgilentE3631A->Checked )
  382.         {
  383.             if((vistat = hpe3631a_init(as_Agilent_Power_Supply_ADDR.c_str(), 0, 0, &vi_AgePowerSupply)) != VI_SUCCESS)
  384.             {
  385.                 is_AgilentPowerSupply_fail = true;
  386.                 Application->MessageBox( " Initialize Agilent E3631A fail ", "Fail", MB_OK );
  387.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " FAIL: Agilent E3631A < initialize (init)"
  388.                          );
  389.                 return;
  390.             }
  391.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " Agilent E3631A ok < initialize (init)"
  392.                       );
  393.         }
  394.         IS_AgilentPowerSupply_INITIALISE = true;
  395.         _VI_PTR pvi_AgePowerSupply = vi_AgePowerSupply;
  396.     }
  397.     ///////////////////// RF or ADC calibration //////////////////////////////////
  398.     if( Form_META_Factory->cbAFC->Checked || Form_META_Factory->cbRxPathLoss->Checked ||  Form_META_Factory->cbIP2->Checked ||
  399.         Form_META_Factory->cbTxPcl->Checked  || Form_META_Factory->cbTxPhaseError->Checked ||
  400.         m_pCal->s_CalItem.b_adc_cal
  401.       )
  402.     {
  403.         this->OnTerminate = ne_OnTerminate;
  404.         (void)vistat;
  405.     }
  406. }
  407. //---------------------------------------------------------------------------