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

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_IP2_Skyworks74117.cpp
  40.  *
  41.  * Project:
  42.  * --------
  43.  *   Maui META APP
  44.  *
  45.  * Description:
  46.  * ------------
  47.  * Skyworks 74117  IP2 calibration 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. #include <assert.h>
  66. #include <math.h>
  67. #pragma hdrstop
  68. #ifndef _T_META_FACTORY_CALIBRATION_H_
  69. #include "T_META_factory_calibration.H"
  70. #endif
  71. #ifndef _CAL_COMMON_H_
  72. #include "cal_common.h"
  73. #endif
  74. // form
  75. #ifndef _META_FACTORY_H_
  76. #include "META_Factory.h"
  77. #endif
  78. // call back
  79. #ifndef _META_FACTORY_NVRAM_CB_H_
  80. #include "meta_factory_nvram_cb.h"
  81. #endif
  82. #ifndef _META_FACTORY_RF_CB_H_
  83. #include "meta_factory_rf_cb.h"
  84. #endif
  85. // equipment
  86. #ifndef _AGECOMMON_H_
  87. #include "agecommon.h"
  88. #endif
  89. // misc
  90. #ifndef  _FT_UTILS_H_
  91. #include "ft_utils.h"
  92. #endif
  93. #ifndef  _BAND_UTILS_H_
  94. #include "band_utils.h"
  95. #endif
  96. #ifndef  _GSM_UTILS_H_
  97. #include "gsm_utils.h"
  98. #endif
  99. #ifndef  _TIME_UTILS_H_
  100. #include "time_utils.h"
  101. #endif
  102. static const  SKY74117_RCX_MIN =  -63;
  103. static const  SKY74117_RCX_MAX =   63;
  104. //----------------------------------------------------------------------------
  105. // IP2
  106. extern CRFPM*  MF_rf_pm_ptr;
  107. extern RfPm_Cnf  *MF_rf_pm_cnf;   // define in T_META_factory_calibration.cpp
  108. extern RfPm_Req  *MF_rf_pm_req;
  109. // Tthread
  110. extern T_META_factory_calibration* pt_calibration;
  111. extern bool  is_suspend_cal; // in T_META_factory_calibration.cpp
  112. //----------------------------------------------------------------------------
  113. bool __fastcall T_META_factory_calibration::IP2Cal_sky74117_cal( void )
  114. {
  115.     char tempbuf[256];
  116.     PostMessage(
  117.                      ctrl.hPostMsgDestHandle,
  118.                      WM_MF_RF_IP2_BEGIN,
  119.                      0,
  120.                      0
  121.                     );
  122.      log->Add( "n" + DateToStr(Date()) +  " " + CurrentTimeStr() +
  123.              " ================== IP2 calibration begin ==================="
  124.            );
  125.     
  126.     // read IP2 register from NVRAM
  127.     MF_rf_pm_ptr->ConfirmCallback = ::ccb_read_ip2_from_nvram;
  128.     MF_rf_pm_ptr->REQ_Read_IP2Reg_From_NVRAM_Start(m_pCal->ui_rf_id);
  129.     CHECK_TERMINATE_BY_USER
  130.     RestartTimerCal( WM_MF_NVRAM_IP2_READ_FAIL );
  131.     SUSPEND_CAL_THREAD
  132.     if (MF_rf_pm_ptr->Get_ConfirmState() != METAAPP_SUCCESS)
  133.     {
  134.         CalErrorHandler( WM_MF_NVRAM_IP2_READ_FAIL );
  135.         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  136.                       " FAIL: Target > read IP2 from NVRAM fail."
  137.                     );
  138.             return false;
  139.     }
  140.     else
  141.     {
  142.         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  143.                       " Target > read IP2 from NVRAM."
  144.                     );
  145.     }
  146.     mc_sky74117_coef = MF_rf_pm_ptr->Get_c_sky74117_coef(  );
  147.     if( ! m_rct_ctrl.RCT_operatingMode( m_pRct, OPERATING_MODE_GSM_BCH ) )
  148.     {
  149.         CalErrorHandler( WM_MF_AGE8960_SET_OPERATION_MODE_FAIL );
  150.         if ( frmFatcory->rbAgilent8960->Checked )
  151.         {
  152.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  153.                               " FAIL :"+
  154.                               " Agilent 8960< Operation mode = GSM BCH"
  155.                             );
  156.         }
  157.         else
  158.         {
  159.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  160.                               " FAIL :"+
  161.                               " cmu200 < Band = Operation mode = GSM BCH"
  162.                             );
  163.         }
  164.         return false;
  165.     }
  166.     short s_ARFCN;
  167.     FrequencyBand eFreqBand = FrequencyBand850;
  168.     while (eFreqBand < FrequencyBandCount)
  169.     {
  170.         int vi_Band;
  171.         switch (eFreqBand)
  172.         {
  173.             case FrequencyBand850:
  174.             {
  175.                 if (!IsFreqBankSupported(m_asFreqBank, eFreqBand))
  176.                 {
  177.                    eFreqBand++;
  178.                    continue;
  179.                 }
  180.                 vi_Band = age1960_GSM850_BAND;
  181.                 s_ARFCN = m_sIP2_arfcn_C0_GSM850;
  182.             }
  183.             break;
  184.             case FrequencyBand900:
  185.             {
  186.                 if (!IsFreqBankSupported(m_asFreqBank, eFreqBand))
  187.                 {
  188.                     eFreqBand++;
  189.                     continue;
  190.                 }
  191.                 vi_Band = age1960_EGSM_BAND;
  192.                 s_ARFCN = m_sIP2_arfcn_C0_GSM;
  193.             }
  194.             break;
  195.             case FrequencyBand1800:
  196.             {
  197.                 if (!IsFreqBankSupported(m_asFreqBank, eFreqBand))
  198.                 {
  199.                     eFreqBand++;
  200.                     continue;
  201.                 }
  202.                 vi_Band = age1960_DCS1800_BAND;
  203.                 s_ARFCN = m_sIP2_arfcn_C0_DCS;
  204.             }
  205.             break;
  206.             case FrequencyBand1900:
  207.             {
  208.                 if (!IsFreqBankSupported(m_asFreqBank, eFreqBand))
  209.                 {
  210.                     eFreqBand++;
  211.                     continue;
  212.                 }
  213.                 vi_Band = age1960_PCS1900_BAND;
  214.                 s_ARFCN = m_sIP2_arfcn_C0_PCS;
  215.             }
  216.             break;
  217.             default:
  218.             {
  219.                 assert(false);
  220.             }
  221.             break;
  222.         } // switch
  223.         if( ! m_rct_ctrl.RCT_cellBand( m_pRct, vi_Band ) )
  224.         {
  225.             CalErrorHandler( WM_MF_AGE8960_SET_BAND_FAIL );
  226.             if ( frmFatcory->rbAgilent8960->Checked )
  227.             {
  228.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  229.                               " FAIL :"+
  230.                               " Agilent 8960< Band = " + ViBand_To_Str( vi_Band )
  231.                             );
  232.             }
  233.             else
  234.             {
  235.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  236.                               " FAIL :"+
  237.                               " cmu200 < Band = " + ViBand_To_Str( vi_Band )
  238.                             );
  239.             }
  240.             return false;
  241.         }
  242.         if( ! m_rct_ctrl.RCT_ContModTran( m_pRct ) )
  243.         {
  244.             CalErrorHandler( WM_MF_AGE8960_SET_BAND_FAIL );
  245.             if ( frmFatcory->rbAgilent8960->Checked )
  246.             {
  247.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  248.                               " FAIL :"+
  249.                               " Agilent 8960< set continous mode transmition " 
  250.                             );
  251.             }
  252.             else
  253.             {
  254.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  255.                               " FAIL : "+
  256.                               " cmu200 < set continous mode transmition " 
  257.                             );
  258.             }
  259.             return false;
  260.         }
  261.         if ( this->Terminated )
  262.         {
  263.             this->OnTerminate = neByUser;
  264.             return false;
  265.         }
  266.         if ( frmFatcory->rbAgilent8960->Checked  )
  267.         {
  268.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " Agilent 8960< band = " +
  269.                       FreqBand_To_Str( eFreqBand) );
  270.         }
  271.         else
  272.         {
  273.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " CMU 200< band = " +
  274.                       FreqBand_To_Str( eFreqBand) );
  275.         }
  276.         if (IsFreqBankSupported(  m_asFreqBank, eFreqBand))
  277.         {
  278.             if(eFreqBand == FrequencyBand1900)
  279.             {
  280.                 if(META_Rf_SelectFrequencyBand1900_r( m_pCal->i_MainMETAHandle, 1, MF_SelectBand_cnf_cb, &MF_SelectBand_token, NULL) !=  META_SUCCESS)
  281.                 {
  282.                     CalErrorHandler( WM_MF_RF_PM_SELECT_BAND_FAIL );
  283.                     pt_calibration->log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  284.                                               " FAIL:  Target < set Band1900 flag = 1 "
  285.                                              );
  286.                     return false;
  287.                 }
  288.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  289.                            " Target < set Band1900 flag = 1"
  290.                          );
  291.             }
  292.             else
  293.             {
  294.                 if(META_Rf_SelectFrequencyBand1900_r( m_pCal->i_MainMETAHandle, 0, MF_SelectBand_cnf_cb, &MF_SelectBand_token, NULL) !=  META_SUCCESS)
  295.                 {
  296.                     CalErrorHandler( WM_MF_RF_PM_SELECT_BAND_FAIL );
  297.                     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  298.                                            " FAIL:  Target < set Band1900 flag = 0 "
  299.                                           );
  300.                     return false;
  301.                 }
  302.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  303.                             "  Target < set Band1900 flag = 0"
  304.                          );
  305.             }
  306.             is_suspend_cal = true;
  307.             this->Suspend();
  308.             is_suspend_cal = false;
  309.         }
  310.         if( ! m_rct_ctrl.RCT_BCHARFCN( m_pRct, s_ARFCN ) )
  311.         {
  312.             CalErrorHandler( WM_MF_AGE8960_SET_BCH_ARFCN_FAIL );
  313.             if ( frmFatcory->rbAgilent8960->Checked )
  314.             {
  315.                  log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " FAIL: Agilent 8960< BCH ARFCN = " +
  316.                            IntToStr(s_ARFCN)
  317.                          );
  318.             }
  319.             else
  320.             {
  321.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " FAIL: cmu200 < BCH ARFCN = " +
  322.                            IntToStr(s_ARFCN)
  323.                          );
  324.             }
  325.             return false;
  326.         }
  327.         if ( this->Terminated )
  328.         {
  329.             this->OnTerminate = neByUser;
  330.             return false;
  331.         }
  332.         if ( frmFatcory->rbAgilent8960->Checked )
  333.         {
  334.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " Agilent 8960< BCH ARFCN = " +
  335.                       AnsiString(s_ARFCN)
  336.                      );
  337.         }
  338.         else
  339.         {
  340.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " CMU 200< BCH ARFCN = " +
  341.                       AnsiString(s_ARFCN)
  342.                     );
  343.         }
  344.         i_IP2_ICORRECTION[0]=i_IP2_ICORRECTION1_SKY74117;
  345.         i_IP2_ICORRECTION[1]=i_IP2_ICORRECTION2_SKY74117;
  346.         i_IP2_QCORRECTION[0]=i_IP2_QCORRECTION1_SKY74117;
  347.         i_IP2_QCORRECTION[1]=i_IP2_QCORRECTION2_SKY74117;
  348.         for( int i=0; i<2; i++)
  349.         {
  350.             if( ! m_rct_ctrl.RCT_cellPower( m_pRct, d_IP2_CAL_P_DL_OFF_SKY ) )
  351.         {
  352.             CalErrorHandler( WM_MF_AGE8960_SET_POWER_FAIL );
  353.             if( frmFatcory->rbAgilent8960->Checked )
  354.             {
  355.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " FAIL: Agilent 8960< Power = " +
  356.                           Double_To_AnsiString( d_IP2_CAL_P_DL_OFF_SKY ) ) + " dBm";
  357.             }
  358.             else
  359.             {
  360.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " FAIL: cmu200< Power = " +
  361.                           Double_To_AnsiString( d_IP2_CAL_P_DL_OFF_SKY ) ) + " dBm";
  362.             }
  363.             return false;
  364.         }
  365.         if ( this->Terminated )
  366.         {
  367.             this->OnTerminate = neByUser;
  368.             return false;
  369.         }
  370.         if( frmFatcory->rbAgilent8960->Checked )
  371.         {
  372.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " Agilent 8960< Power = " +
  373.                       Double_To_AnsiString( d_IP2_CAL_P_DL_OFF_SKY) );
  374.         }
  375.         else
  376.         {
  377.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " CMU 200< Power = " +
  378.                               Double_To_AnsiString( d_IP2_CAL_P_DL_OFF_SKY) );
  379.         }
  380.        // if( frmFatcory->cbAFC->Checked )
  381.        // {
  382.       //      Sleep( 100 );  // wait Agilent 8960 ready!
  383.       //  }
  384.       //  else
  385.         {
  386.             Sleep( 200 );  // wait Agilent 8960 ready!
  387.         }
  388.             mc_sky74117_coef.rx.coef[eFreqBand].icorrection = i_IP2_ICORRECTION[i];
  389.             mc_sky74117_coef.rx.coef[eFreqBand].qcorrection = i_IP2_QCORRECTION[i];
  390.             EvalPmrcx_I_sky[i] = i_IP2_ICORRECTION[i];
  391.             EvalPmrcx_Q_sky[i] = i_IP2_QCORRECTION[i];
  392.             MF_rf_pm_ptr->Set_cSky74117Coef( mc_sky74117_coef );
  393.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  394.                           " Target < Set icorrection = " + IntToStr( EvalPmrcx_I_sky[i] ) +
  395.                           ", Qcorrection = " + IntToStr( EvalPmrcx_Q_sky[i] )
  396.                         );
  397.             // write IP2 register to NVRAM
  398.             MF_rf_pm_ptr->ConfirmCallback = ccb_write_ip2_to_nvram;
  399.             MF_rf_pm_ptr->REQ_Write_IP2Reg_To_NVRAM_Start(m_pCal->ui_rf_id);
  400.             CHECK_TERMINATE_BY_USER
  401.             RestartTimerCal(WM_MF_NVRAM_IP2_WRITE_FAIL);
  402.             SUSPEND_CAL_THREAD
  403.             E_METAAPP_RESULT_T state = MF_rf_pm_ptr->Get_ConfirmState();
  404.             if (state != METAAPP_SUCCESS)
  405.             {
  406.                 if (METAAPP_NVRAM_LID_VER_NOT_SUPPORT == state)
  407.                 {
  408.                     CalErrorHandler(WM_MF_NVRAM_EF_L1_RFSPECIALCOEF_LID_VERNO_FAIL);
  409.                     log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  410.                          " FAIL : NVRAM_EF_L1_RFSPECIALCOEF_LID version is not support, please update META to latest version. "
  411.                          );
  412.                 }
  413.                 else
  414.                 {
  415.                     CalErrorHandler(WM_MF_NVRAM_IP2_WRITE_FAIL);
  416.                     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  417.                           " FAIL: Target < write IP2 to NVRAM fail."
  418.                         );
  419.                 }        
  420.                 return false;
  421.             }
  422.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  423.                       " Target < write IP2 to NVRAM."
  424.                     );
  425.             // set Skyworks 74117, 74400 mag to register
  426.             SKY74117_IP2CW_MAG  sky74117_mag_par;
  427.             MF_rf_pm_ptr->Compose_Sky74117_Mag( eFreqBand, mc_sky74117_coef, sky74117_mag_par );
  428.             MF_rf_pm_ptr->ConfirmCallback = ::CNF_SetSky74117IP2MagToReg;
  429.             MF_rf_pm_ptr->Set_Sky74117IP2MagToReg_Start( eFreqBand, sky74117_mag_par );
  430.             CHECK_TERMINATE_BY_USER
  431.             RestartTimerCal( WM_MF_RF_IP2_SET_MAG_FAIL );
  432.             SUSPEND_CAL_THREAD
  433.             if (MF_rf_pm_ptr->Get_ConfirmState() != METAAPP_SUCCESS)
  434.             {
  435.                 CalErrorHandler( WM_MF_NVRAM_IP2_READ_FAIL );
  436.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  437.                           " FAIL: Target < Set IP2 mag to register."
  438.                         );
  439.                 return false;
  440.             }
  441.             else
  442.             {
  443.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  444.                       " Target < Set IP2 mag to register."
  445.                     );
  446.             }
  447.             // set Skyworks 74117, 74400 pol to register
  448.             SKY74117_IP2CW_POL  sky74117_pol_par;
  449.             MF_rf_pm_ptr->Compose_Sky74117_Pol( mc_sky74117_coef, sky74117_pol_par );
  450.             MF_rf_pm_ptr->ConfirmCallback = ::CNF_SetSky74117IP2PolToReg;
  451.             MF_rf_pm_ptr->Set_Sky74117IP2PolToReg_Start( sky74117_pol_par );
  452.             CHECK_TERMINATE_BY_USER
  453.             RestartTimerCal( WM_MF_RF_IP2_SET_POL_FAIL );
  454.             SUSPEND_CAL_THREAD
  455.             if (MF_rf_pm_ptr->Get_ConfirmState() != METAAPP_SUCCESS)
  456.             {
  457.                 CalErrorHandler( WM_MF_NVRAM_IP2_READ_FAIL );
  458.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  459.                           " FAIL: Target < Set IP2 POL to register."
  460.                         );
  461.                 return false;
  462.             }
  463.             else
  464.             {
  465.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  466.                       " Target < Set IP2 POL to register."
  467.                     );
  468.             }
  469.            // if Agilent 8960 not read, target will get error power!
  470.            MF_rf_pm_cnf->deviation = 0;
  471.            MF_rf_pm_cnf->power = 0;
  472.            MF_rf_pm_cnf->usedGain = 0;
  473.            MF_rf_pm_cnf->extra_info.valid =0;
  474.            MF_rf_pm_cnf->extra_info.iOffset=0;
  475.    MF_rf_pm_cnf->extra_info.qOffset=0;
  476.    MF_rf_pm_cnf->extra_info.validSamples =0;
  477.            MF_rf_pm_req->arfcn = s_ARFCN-30;
  478.            MF_rf_pm_req->sampleNoPerFrame = c_IP2_M_PM;
  479.            MF_rf_pm_req->gain = d_IP2_GAIN *AVG_POWER_PC_SIDE_MULTIPLY ;
  480.            MF_rf_pm_req->frames = i_IP2_N_PM;
  481.            if( META_Rf_PM_r( m_pCal->i_MainMETAHandle, MF_rf_pm_req, MF_rf_pm_cnf_cb, &MF_rf_pm_token, NULL ) != META_SUCCESS )
  482.            {
  483.                 CalErrorHandler( WM_MF_RF_IP2_PM_FAIL );
  484.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  485.                                " FAIL: "+
  486.                               " Target < PM : ARFCN = " + IntToStr( s_ARFCN-30 ) +
  487.                               " sample per frame = " + IntToStr( c_IP2_M_PM) +
  488.                               " gain = " + IntToStr( MF_rf_pm_req->gain ) +
  489.                               " frames = " + IntToStr( i_IP2_N_PM)
  490.                             );
  491.                         return false;
  492.             } // if
  493.             if ( this->Terminated )
  494.             {
  495.                 this->OnTerminate = neByUser;
  496.                 return false;
  497.             }
  498.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  499.                       " Target < PM : ARFCN = " + IntToStr( s_ARFCN-30 ) +
  500.                       ", sample per frame = " + IntToStr( c_IP2_M_PM) +
  501.                       ", gain = " + IntToStr( MF_rf_pm_req->gain ) +
  502.                       ", frames = " + IntToStr( i_IP2_N_PM)
  503.                     );
  504.            //  Sleep(100);// delay for power measurement
  505.             RestartTimerCal( WM_MF_RF_IP2_PM_FAIL );
  506.             is_suspend_cal = true;
  507.             this->Suspend();
  508.             is_suspend_cal = false;
  509.             if ( this->Terminated )
  510.             {
  511.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  512.                       " Terminate at line " + AnsiString(__FILE__) + " " + AnsiString(__LINE__)
  513.                         );
  514.                 this->OnTerminate = neByUser;
  515.                 return false;
  516.             }
  517.             if( !MF_rf_pm_cnf->ok )
  518.             {
  519.                 CalErrorHandler( WM_MF_RF_IP2_FAIL );
  520.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  521.                           " Target < ok = " + IntToStr(MF_rf_pm_cnf->ok) +
  522.                           ", power = " + Double_To_AnsiString(MF_rf_pm_cnf->power/8.0) +
  523.                           ", deviation = " + Double_To_AnsiString(sqrt(MF_rf_pm_cnf->deviation)/8.0) +
  524.                           ", usedGain = " + Double_To_AnsiString(MF_rf_pm_cnf->usedGain/8.0) +
  525.                           ", valid = " + IntToStr(MF_rf_pm_cnf->extra_info.valid) +
  526.                           ", I_DC = " + IntToStr(MF_rf_pm_cnf->extra_info.iOffset) +
  527.                           ", Q_DC = " + IntToStr(MF_rf_pm_cnf->extra_info.qOffset) +
  528.                           ", valid sample = " + IntToStr(MF_rf_pm_cnf->extra_info.validSamples)
  529.                         );
  530.                 return false;
  531.             }
  532.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  533.                       " Target > power = " + Double_To_AnsiString(MF_rf_pm_cnf->power/8.0) +
  534.                       ", deviation = " + Double_To_AnsiString(sqrt(MF_rf_pm_cnf->deviation)/8.0) +
  535.                       ", usedGain = " + Double_To_AnsiString(MF_rf_pm_cnf->usedGain/8.0) +
  536.                       ", valid = " + IntToStr(MF_rf_pm_cnf->extra_info.valid) +
  537.                       ", I_DC = " + IntToStr(MF_rf_pm_cnf->extra_info.iOffset) +
  538.                       ", Q_DC = " + IntToStr(MF_rf_pm_cnf->extra_info.qOffset) +
  539.                       ", valid sample = " + IntToStr(MF_rf_pm_cnf->extra_info.validSamples)
  540.                    );
  541.             EvalMDC1_I_sky[i] = MF_rf_pm_cnf->extra_info.iOffset;
  542.             EvalMDC1_Q_sky[i] = MF_rf_pm_cnf->extra_info.qOffset;
  543.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  544.                       " Target > " +
  545.                       ", MDC1_I = " + IntToStr(MF_rf_pm_cnf->extra_info.iOffset) +
  546.                       ", MDC1_Q = " + IntToStr(MF_rf_pm_cnf->extra_info.qOffset)
  547.                    );
  548.             //===========================================================
  549.             // 1.1 SS power on
  550.             if( ! m_rct_ctrl.RCT_cellPower( m_pRct, d_IP2_CAL_P_DL_ON_SKY ) )
  551.             {
  552.                 CalErrorHandler( WM_MF_AGE8960_SET_POWER_FAIL );
  553.                 if( frmFatcory->rbAgilent8960->Checked )
  554.                 {
  555.                     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " FAIL: Agilent 8960< Power = " +
  556.                           Double_To_AnsiString( d_IP2_CAL_P_DL_ON_SKY ) ) + " dBm";
  557.                 }
  558.                 else
  559.                 {
  560.                     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " FAIL: cmu200< Power = " +
  561.                           Double_To_AnsiString( d_IP2_CAL_P_DL_ON_SKY ) ) + " dBm";
  562.                 }
  563.                 return false;
  564.             }
  565.             if ( this->Terminated )
  566.             {
  567.                 this->OnTerminate = neByUser;
  568.                 return false;
  569.             }
  570.             if( frmFatcory->rbAgilent8960->Checked )
  571.             {
  572.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " Agilent 8960< Power = " +
  573.                       Double_To_AnsiString( d_IP2_CAL_P_DL_ON_SKY) );
  574.             }
  575.             else
  576.             {
  577.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " CMU 200< Power = " +
  578.                               Double_To_AnsiString( d_IP2_CAL_P_DL_ON_SKY) );
  579.             }
  580.             Sleep( 200 );  // wait Agilent 8960 ready!
  581.             
  582.             mc_sky74117_coef.rx.coef[eFreqBand].icorrection = i_IP2_ICORRECTION[i];
  583.             mc_sky74117_coef.rx.coef[eFreqBand].qcorrection = i_IP2_QCORRECTION[i];
  584.             EvalPmrcx_I_sky[i] = i_IP2_ICORRECTION[i];
  585.             EvalPmrcx_Q_sky[i] = i_IP2_QCORRECTION[i];
  586.             MF_rf_pm_ptr->Set_cSky74117Coef( mc_sky74117_coef );
  587.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  588.                           " Target < Set icorrection = " + IntToStr( EvalPmrcx_I_sky[i] ) +
  589.                           ", Qcorrection = " + IntToStr( EvalPmrcx_Q_sky[i] )
  590.                         );
  591.             // write IP2 register to NVRAM
  592.             MF_rf_pm_ptr->ConfirmCallback = ccb_write_ip2_to_nvram;
  593.             MF_rf_pm_ptr->REQ_Write_IP2Reg_To_NVRAM_Start(m_pCal->ui_rf_id);
  594.             CHECK_TERMINATE_BY_USER
  595.             RestartTimerCal(WM_MF_NVRAM_IP2_WRITE_FAIL);
  596.             SUSPEND_CAL_THREAD
  597.             state = MF_rf_pm_ptr->Get_ConfirmState();
  598.             if (state != METAAPP_SUCCESS)
  599.             {
  600.                 if (METAAPP_NVRAM_LID_VER_NOT_SUPPORT == state)
  601.                 {
  602.                     CalErrorHandler(WM_MF_NVRAM_EF_L1_RFSPECIALCOEF_LID_VERNO_FAIL);
  603.                     log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  604.                          " FAIL : NVRAM_EF_L1_RFSPECIALCOEF_LID version is not support, please update META to latest version. "
  605.                          );
  606.                 }
  607.                 else
  608.                 {
  609.                     CalErrorHandler( WM_MF_NVRAM_IP2_READ_FAIL );
  610.                     log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  611.                               " FAIL: Target < write IP2 to NVRAM fail."
  612.                              );
  613.                     return false;
  614.                 }
  615.             }
  616.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  617.                       " Target < write IP2 to NVRAM."
  618.                     );
  619.             // set Skyworks 74117, 74400 mag to register
  620.            // SKY74117_IP2CW_MAG  sky74117_mag_par;
  621.             MF_rf_pm_ptr->Compose_Sky74117_Mag( eFreqBand, mc_sky74117_coef, sky74117_mag_par );
  622.             MF_rf_pm_ptr->ConfirmCallback = ::CNF_SetSky74117IP2MagToReg;
  623.             MF_rf_pm_ptr->Set_Sky74117IP2MagToReg_Start( eFreqBand, sky74117_mag_par );
  624.             CHECK_TERMINATE_BY_USER
  625.             RestartTimerCal( WM_MF_RF_IP2_SET_MAG_FAIL );
  626.             SUSPEND_CAL_THREAD
  627.             if (MF_rf_pm_ptr->Get_ConfirmState() != METAAPP_SUCCESS)
  628.             {
  629.                 CalErrorHandler( WM_MF_NVRAM_IP2_READ_FAIL );
  630.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  631.                           " FAIL: Target < Set IP2 mag to register."
  632.                         );
  633.                 return false;
  634.             }
  635.             else
  636.             {
  637.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  638.                       " Target < Set IP2 mag to register."
  639.                     );
  640.             }
  641.             // set Skyworks 74117, 74400 pol to register
  642.            // SKY74117_IP2CW_POL  sky74117_pol_par;
  643.             MF_rf_pm_ptr->Compose_Sky74117_Pol( mc_sky74117_coef, sky74117_pol_par );
  644.             MF_rf_pm_ptr->ConfirmCallback = ::CNF_SetSky74117IP2PolToReg;
  645.             MF_rf_pm_ptr->Set_Sky74117IP2PolToReg_Start( sky74117_pol_par );
  646.             CHECK_TERMINATE_BY_USER
  647.             RestartTimerCal( WM_MF_RF_IP2_SET_POL_FAIL );
  648.             SUSPEND_CAL_THREAD
  649.             if (MF_rf_pm_ptr->Get_ConfirmState() != METAAPP_SUCCESS)
  650.             {
  651.                 CalErrorHandler( WM_MF_NVRAM_IP2_READ_FAIL );
  652.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  653.                           " FAIL: Target < Set IP2 POL to register."
  654.                         );
  655.                 return false;
  656.             }
  657.             else
  658.             {
  659.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  660.                       " Target < Set IP2 POL to register."
  661.                     );
  662.             }
  663.            // if Agilent 8960 not read, target will get error power!
  664.            MF_rf_pm_cnf->deviation = 0;
  665.            MF_rf_pm_cnf->power = 0;
  666.            MF_rf_pm_cnf->usedGain = 0;
  667.            MF_rf_pm_cnf->extra_info.valid =0;
  668.            MF_rf_pm_cnf->extra_info.iOffset=0;
  669.    MF_rf_pm_cnf->extra_info.qOffset=0;
  670.    MF_rf_pm_cnf->extra_info.validSamples =0;
  671.            MF_rf_pm_req->arfcn = s_ARFCN-30;
  672.            MF_rf_pm_req->sampleNoPerFrame = c_IP2_M_PM;
  673.            MF_rf_pm_req->gain = d_IP2_GAIN *AVG_POWER_PC_SIDE_MULTIPLY ;
  674.            MF_rf_pm_req->frames = i_IP2_N_PM;
  675.            if( META_Rf_PM_r( m_pCal->i_MainMETAHandle, MF_rf_pm_req, MF_rf_pm_cnf_cb, &MF_rf_pm_token, NULL ) != META_SUCCESS )
  676.            {
  677.                 CalErrorHandler( WM_MF_RF_IP2_PM_FAIL );
  678.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  679.                                " FAIL: "+
  680.                               " Target < PM : ARFCN = " + IntToStr( s_ARFCN-30 ) +
  681.                               " sample per frame = " + IntToStr( c_IP2_M_PM) +
  682.                               " gain = " + IntToStr( MF_rf_pm_req->gain ) +
  683.                               " frames = " + IntToStr( i_IP2_N_PM)
  684.                             );
  685.                         return false;
  686.             } // if
  687.             if ( this->Terminated )
  688.             {
  689.                 this->OnTerminate = neByUser;
  690.                 return false;
  691.             }
  692.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  693.                       " Target < PM : ARFCN = " + IntToStr( s_ARFCN-30 ) +
  694.                       ", sample per frame = " + IntToStr( c_IP2_M_PM) +
  695.                       ", gain = " + IntToStr( MF_rf_pm_req->gain ) +
  696.                       ", frames = " + IntToStr( i_IP2_N_PM)
  697.                     );
  698.            //  Sleep(100);// delay for power measurement
  699.             RestartTimerCal( WM_MF_RF_IP2_PM_FAIL );
  700.             is_suspend_cal = true;
  701.             this->Suspend();
  702.             is_suspend_cal = false;
  703.             if ( this->Terminated )
  704.             {
  705.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  706.                       " Terminate at line " + AnsiString(__FILE__) + " " + AnsiString(__LINE__)
  707.                         );
  708.                 this->OnTerminate = neByUser;
  709.                 return false;
  710.             }
  711.             if( !MF_rf_pm_cnf->ok )
  712.             {
  713.                 CalErrorHandler( WM_MF_RF_IP2_FAIL );
  714.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  715.                           " Target < ok = " + IntToStr(MF_rf_pm_cnf->ok) +
  716.                           ", power = " + Double_To_AnsiString(MF_rf_pm_cnf->power/8.0) +
  717.                           ", deviation = " + Double_To_AnsiString(sqrt(MF_rf_pm_cnf->deviation)/8.0) +
  718.                           ", usedGain = " + Double_To_AnsiString(MF_rf_pm_cnf->usedGain/8.0) +
  719.                           ", valid = " + IntToStr(MF_rf_pm_cnf->extra_info.valid) +
  720.                           ", I_DC = " + IntToStr(MF_rf_pm_cnf->extra_info.iOffset) +
  721.                           ", Q_DC = " + IntToStr(MF_rf_pm_cnf->extra_info.qOffset) +
  722.                           ", valid sample = " + IntToStr(MF_rf_pm_cnf->extra_info.validSamples)
  723.                         );
  724.                 return false;
  725.             }
  726.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  727.                       " Target > power = " + Double_To_AnsiString(MF_rf_pm_cnf->power/8.0) +
  728.                       ", deviation = " + Double_To_AnsiString(sqrt(MF_rf_pm_cnf->deviation)/8.0) +
  729.                       ", usedGain = " + Double_To_AnsiString(MF_rf_pm_cnf->usedGain/8.0) +
  730.                       ", valid = " + IntToStr(MF_rf_pm_cnf->extra_info.valid) +
  731.                       ", I_DC = " + IntToStr(MF_rf_pm_cnf->extra_info.iOffset) +
  732.                       ", Q_DC = " + IntToStr(MF_rf_pm_cnf->extra_info.qOffset) +
  733.                       ", valid sample = " + IntToStr(MF_rf_pm_cnf->extra_info.validSamples)
  734.                    );
  735.             EvalMDC2_I_sky[i] = MF_rf_pm_cnf->extra_info.iOffset;
  736.             EvalMDC2_Q_sky[i] = MF_rf_pm_cnf->extra_info.qOffset;
  737.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  738.                       " Target > " +
  739.                       ", MDC2_I = " + IntToStr(MF_rf_pm_cnf->extra_info.iOffset) +
  740.                       ", MDC2_Q = " + IntToStr(MF_rf_pm_cnf->extra_info.qOffset)
  741.                    );
  742.         } // for
  743.         // Evaluate
  744.         unsigned char  c0_I = MF_rf_pm_ptr->Get_cxofrealcoef(EvalPmrcx_I_sky[0], m_pCal->ui_rf_id);
  745.         unsigned char  c1_I = MF_rf_pm_ptr->Get_cxofrealcoef(EvalPmrcx_I_sky[1], m_pCal->ui_rf_id);
  746.         unsigned char  c0_Q = MF_rf_pm_ptr->Get_cxofrealcoef(EvalPmrcx_Q_sky[0], m_pCal->ui_rf_id);
  747.         unsigned char  c1_Q = MF_rf_pm_ptr->Get_cxofrealcoef(EvalPmrcx_Q_sky[1], m_pCal->ui_rf_id);
  748.         int  f0_I = EvalMDC2_I_sky[0] - EvalMDC1_I_sky[0];
  749.         int  f1_I = EvalMDC2_I_sky[1] - EvalMDC1_I_sky[1];
  750.         int  f0_Q = EvalMDC2_Q_sky[0] - EvalMDC1_Q_sky[0]  ;
  751.         int  f1_Q = EvalMDC2_Q_sky[1] - EvalMDC1_Q_sky[1];
  752.         signed char rcx_I = 0;
  753.         signed char rcx_Q = 0;
  754.         if( (c1_I - c0_I) == 0 && (c1_Q - c0_Q)==0 )  return false;
  755.         // display evaluate error
  756.         if( (c1_I - c0_I) != 0 )
  757.         {
  758.             float  slope_I = 1.0*(f1_I - f0_I) / (c1_I - c0_I);
  759.             int  offset_I = f0_I - slope_I*c0_I;
  760.             if( slope_I != 0 )
  761.             {
  762.                 unsigned char cx_I =  - offset_I/slope_I;
  763.                 rcx_I = MF_rf_pm_ptr->Get_realcoefofcx( cx_I, m_pCal->ui_rf_id );
  764.                 if( rcx_I < SKY74117_RCX_MIN ) rcx_I = SKY74117_RCX_MIN;
  765.                 else if( rcx_I > SKY74117_RCX_MAX ) rcx_I = SKY74117_RCX_MAX;
  766.             }
  767.         }
  768.         if( (c1_Q - c0_Q) != 0 )
  769.         {
  770.             float  slope_Q = 1.0*(f1_Q - f0_Q) / (c1_Q - c0_Q);
  771.             int  offset_Q = f0_Q - slope_Q*c0_Q;
  772.             if( slope_Q != 0 )
  773.             {
  774.                 unsigned char cx_Q =  - offset_Q/slope_Q;
  775.                 rcx_Q = MF_rf_pm_ptr->Get_realcoefofcx( cx_Q, m_pCal->ui_rf_id );
  776.                 if( rcx_Q < SKY74117_RCX_MIN ) rcx_Q = SKY74117_RCX_MIN;
  777.                 else if( rcx_Q > SKY74117_RCX_MAX ) rcx_Q = SKY74117_RCX_MAX;
  778.             }
  779.         }
  780.         mc_sky74117_coef.rx.coef[eFreqBand].icorrection = rcx_I;
  781.         mc_sky74117_coef.rx.coef[eFreqBand].qcorrection = rcx_Q;
  782.         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  783.                       " rcx_I = " + IntToStr(rcx_I) +
  784.                       " rcx_Q = " + IntToStr(rcx_Q)
  785.                    );
  786.         sprintf( tempbuf, "%8d", rcx_I );
  787.         m_pCal->as_ResultBuf = m_pCal->as_ResultBuf + tempbuf + ", ";
  788.         sprintf( tempbuf, "%8d", rcx_Q );
  789.         m_pCal->as_ResultBuf = m_pCal->as_ResultBuf + tempbuf + ", ";
  790.         MF_rf_pm_ptr->Set_c_sky74117_coef( mc_sky74117_coef );
  791.         // set Skyworks 74117, 74400 mag to register
  792.         SKY74117_IP2CW_MAG  sky74117_mag_par;
  793.         MF_rf_pm_ptr->Compose_Sky74117_Mag( eFreqBand, mc_sky74117_coef, sky74117_mag_par );
  794.         MF_rf_pm_ptr->ConfirmCallback = ::CNF_SetSky74117IP2MagToReg;
  795.         MF_rf_pm_ptr->Set_Sky74117IP2MagToReg_Start( eFreqBand, sky74117_mag_par );
  796.         CHECK_TERMINATE_BY_USER
  797.         RestartTimerCal( WM_MF_RF_IP2_SET_MAG_FAIL );
  798.         SUSPEND_CAL_THREAD
  799.         if (MF_rf_pm_ptr->Get_ConfirmState() != METAAPP_SUCCESS)
  800.         {
  801.             CalErrorHandler( WM_MF_NVRAM_IP2_READ_FAIL );
  802.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  803.                           " FAIL: Target < Set IP2 mag to register."
  804.                         );
  805.             return false;
  806.         }
  807.         else
  808.         {
  809.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  810.                       " Target < Set IP2 mag to register."
  811.                     );
  812.         }
  813.         // set Skyworks 74117, 74400 pol to register
  814.         SKY74117_IP2CW_POL  sky74117_pol_par;
  815.         MF_rf_pm_ptr->Compose_Sky74117_Pol( mc_sky74117_coef, sky74117_pol_par );
  816.         MF_rf_pm_ptr->ConfirmCallback = ::CNF_SetSky74117IP2PolToReg;
  817.         MF_rf_pm_ptr->Set_Sky74117IP2PolToReg_Start( sky74117_pol_par );
  818.         CHECK_TERMINATE_BY_USER
  819.         RestartTimerCal( WM_MF_RF_IP2_SET_POL_FAIL );
  820.         SUSPEND_CAL_THREAD
  821.         if (MF_rf_pm_ptr->Get_ConfirmState() != METAAPP_SUCCESS)
  822.         {
  823.             CalErrorHandler( WM_MF_NVRAM_IP2_READ_FAIL );
  824.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  825.                           " FAIL: Target < Set IP2 POL to register."
  826.                         );
  827.             return false;
  828.         }
  829.         else
  830.         {
  831.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  832.                       " Target < Set IP2 POL to register."
  833.                     );
  834.         }
  835.         if (!WriteIP2CalResultToFile(as_ID+".cal",Application->ExeName, m_pCal->b_CalResultPath, m_pCal->ui_rf_id, eFreqBand ) )
  836.         {
  837.             CalErrorHandler( WM_MF_RF_AFC_WRITE_CAL_RESULT_FAIL );
  838.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  839.                 " FAIL : write IP2 parameter to cal file "
  840.               );
  841.             return false;
  842.         }
  843.         eFreqBand++;
  844.     } // while
  845.    // if( ! frmFatcory->WriteIP2CalResultToFile(as_ID+".cal",Application->ExeName, frmFatcory->b_CalResultPath, m_pCal->ui_rf_id ) )
  846.    // {
  847.    //     CalErrorHandler( WM_MF_RF_AFC_WRITE_CAL_RESULT_FAIL );
  848.     //    log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  849.     //            " FAIL : write IP2 parameter to cal file "
  850.     //          );
  851.     //    return false;
  852.     //}
  853.     // write IP2 register to NVRAM
  854.     MF_rf_pm_ptr->ConfirmCallback = ccb_write_ip2_to_nvram;
  855.     MF_rf_pm_ptr->REQ_Write_IP2Reg_To_NVRAM_Start(m_pCal->ui_rf_id);
  856.     CHECK_TERMINATE_BY_USER
  857.     RestartTimerCal(WM_MF_NVRAM_IP2_WRITE_FAIL);
  858.     SUSPEND_CAL_THREAD
  859.     E_METAAPP_RESULT_T state = MF_rf_pm_ptr->Get_ConfirmState();
  860.     if (state != METAAPP_SUCCESS)
  861.     {
  862.         if (METAAPP_NVRAM_LID_VER_NOT_SUPPORT == state)
  863.         {
  864.             CalErrorHandler(WM_MF_NVRAM_EF_L1_RFSPECIALCOEF_LID_VERNO_FAIL);
  865.             log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  866.                          " FAIL : NVRAM_EF_L1_RFSPECIALCOEF_LID version is not support, please update META to latest version. "
  867.                          );
  868.         }
  869.         else
  870.         {
  871.             CalErrorHandler( WM_MF_NVRAM_IP2_READ_FAIL );
  872.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  873.                   " FAIL: Target < write IP2 to NVRAM fail."
  874.                 );
  875.         }
  876.         return false;
  877.     }
  878.     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  879.                       " Target < write IP2 to NVRAM."
  880.                 );
  881.     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  882.              " =================== IP2 calibration end ==================== n "
  883.            );
  884.     return true;       
  885. }
  886. //===========================================================================
  887. bool __fastcall T_META_factory_calibration::IP2Cal_sky74117_check( void )
  888. {
  889.     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  890.              " ===================   IP2 check begin   ==================== n "
  891.            );
  892.     
  893.     int MDCI[2];
  894.     int MDCQ[2];
  895.     int DCI;
  896.     int DCQ;
  897.     short s_ARFCN;
  898.     FrequencyBand eFreqBand = FrequencyBand850;
  899.     while (eFreqBand < FrequencyBandCount)
  900.     {
  901.         int vi_Band;
  902.         switch (eFreqBand)
  903.         {
  904.             case FrequencyBand850:
  905.             {
  906.                 if (! IsFreqBankSupported(  m_asFreqBank, eFreqBand))
  907.                 {
  908.                    eFreqBand++;
  909.                    continue;
  910.                 }
  911.                 vi_Band = age1960_GSM850_BAND;
  912.                 s_ARFCN = m_sIP2_arfcn_C0_GSM850;
  913.             }
  914.             break;
  915.             case FrequencyBand900:
  916.             {
  917.                 if (! IsFreqBankSupported(  m_asFreqBank, eFreqBand))
  918.                 {
  919.                     eFreqBand++;
  920.                     continue;
  921.                 }
  922.                 vi_Band = age1960_EGSM_BAND;
  923.                 s_ARFCN = m_sIP2_arfcn_C0_GSM;
  924.             }
  925.             break;
  926.             case FrequencyBand1800:
  927.             {
  928.                 if (! IsFreqBankSupported(  m_asFreqBank, eFreqBand))
  929.                 {
  930.                     eFreqBand++;
  931.                     continue;
  932.                 }
  933.                 vi_Band = age1960_DCS1800_BAND;
  934.                 s_ARFCN = m_sIP2_arfcn_C0_DCS;
  935.             }
  936.             break;
  937.             case FrequencyBand1900:
  938.             {
  939.                 if (! IsFreqBankSupported(  m_asFreqBank, eFreqBand))
  940.                 {
  941.                     eFreqBand++;
  942.                     continue;
  943.                 }
  944.                 vi_Band = age1960_PCS1900_BAND;
  945.                 s_ARFCN = m_sIP2_arfcn_C0_PCS;
  946.             }
  947.             break;
  948.             default:
  949.                 assert(false);
  950.             break;
  951.         } // switch
  952.         if( ! m_rct_ctrl.RCT_cellBand( m_pRct, vi_Band ) )
  953.         {
  954.             CalErrorHandler( WM_MF_AGE8960_SET_BAND_FAIL );
  955.             if ( frmFatcory->rbAgilent8960->Checked )
  956.             {
  957.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  958.                               " FAIL :"+
  959.                               " Agilent 8960< Band = " + ViBand_To_Str( vi_Band )
  960.                             );
  961.             }
  962.             else
  963.             {
  964.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  965.                               " FAIL :"+
  966.                               " cmu200 < Band = " + ViBand_To_Str( vi_Band )
  967.                             );
  968.             }
  969.             return false;
  970.         }
  971.         if( ! m_rct_ctrl.RCT_ContModTran( m_pRct ) )
  972.         {
  973.             CalErrorHandler( WM_MF_AGE8960_SET_BAND_FAIL );
  974.             if ( frmFatcory->rbAgilent8960->Checked )
  975.             {
  976.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  977.                               " FAIL :"+
  978.                               " Agilent 8960< set continous mode transmition " 
  979.                             );
  980.             }
  981.             else
  982.             {
  983.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  984.                               " FAIL : "+
  985.                               " cmu200 < set continous mode transmition " 
  986.                             );
  987.             }
  988.             return false;
  989.         }
  990.         if ( this->Terminated )
  991.         {
  992.             this->OnTerminate = neByUser;
  993.             return false;
  994.         }
  995.         if ( frmFatcory->rbAgilent8960->Checked  )
  996.         {
  997.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " Agilent 8960< band = " +
  998.                       FreqBand_To_Str( eFreqBand) );
  999.         }
  1000.         else
  1001.         {
  1002.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " CMU 200< band = " +
  1003.                       FreqBand_To_Str( eFreqBand) );
  1004.         }
  1005.         if (IsFreqBankSupported(  m_asFreqBank, eFreqBand))
  1006.         {
  1007.             if(eFreqBand == FrequencyBand1900)
  1008.             {
  1009.                 if(META_Rf_SelectFrequencyBand1900_r( m_pCal->i_MainMETAHandle, 1, MF_SelectBand_cnf_cb, &MF_SelectBand_token, NULL) !=  META_SUCCESS)
  1010.                 {
  1011.                     CalErrorHandler( WM_MF_RF_PM_SELECT_BAND_FAIL );
  1012.                     pt_calibration->log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1013.                                               " FAIL: Target < set Band1900 flag = 1 "
  1014.                                              );
  1015.                     return false;
  1016.                 }
  1017.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1018.                            " Target < set Band1900 flag = 1"
  1019.                          );
  1020.             }
  1021.             else
  1022.             {
  1023.                 if(META_Rf_SelectFrequencyBand1900_r( m_pCal->i_MainMETAHandle, 0, MF_SelectBand_cnf_cb, &MF_SelectBand_token, NULL) !=  META_SUCCESS)
  1024.                 {
  1025.                     CalErrorHandler( WM_MF_RF_PM_SELECT_BAND_FAIL );
  1026.                     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1027.                                            " FAIL: Target < set Band1900 flag = 0 "
  1028.                                           );
  1029.                     return false;
  1030.                 }
  1031.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1032.                             " Target < set Band1900 flag = 0"
  1033.                          );
  1034.             }
  1035.             is_suspend_cal = true;
  1036.             this->Suspend();
  1037.             is_suspend_cal = false;
  1038.         }
  1039.         if( ! m_rct_ctrl.RCT_BCHARFCN( m_pRct, s_ARFCN ) )
  1040.         {
  1041.             CalErrorHandler( WM_MF_AGE8960_SET_BCH_ARFCN_FAIL );
  1042.             if ( frmFatcory->rbAgilent8960->Checked )
  1043.             {
  1044.                  log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " FAIL: Agilent 8960< BCH ARFCN = " +
  1045.                            IntToStr(s_ARFCN)
  1046.                          );
  1047.             }
  1048.             else
  1049.             {
  1050.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " FAIL: cmu200 < BCH ARFCN = " +
  1051.                            IntToStr(s_ARFCN)
  1052.                          );
  1053.             }
  1054.             return false;
  1055.         }
  1056.         if ( this->Terminated )
  1057.         {
  1058.             this->OnTerminate = neByUser;
  1059.             return false;
  1060.         }
  1061.         if ( frmFatcory->rbAgilent8960->Checked )
  1062.         {
  1063.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " Agilent 8960< BCH ARFCN = " +
  1064.                       AnsiString(s_ARFCN)
  1065.                      );
  1066.         }
  1067.         else
  1068.         {
  1069.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " CMU 200< BCH ARFCN = " +
  1070.                       AnsiString(s_ARFCN)
  1071.                     );
  1072.         }
  1073.         if( ! m_rct_ctrl.RCT_cellPower( m_pRct, d_IP2_CHECK_P_DL_OFF ) )
  1074.         {
  1075.             CalErrorHandler( WM_MF_AGE8960_SET_POWER_FAIL );
  1076.             if( frmFatcory->rbAgilent8960->Checked )
  1077.             {
  1078.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " FAIL: Agilent 8960< Power = " +
  1079.                           Double_To_AnsiString( d_IP2_CHECK_P_DL_OFF) ) + " dBm";
  1080.             }
  1081.             else
  1082.             {
  1083.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " FAIL: cmu200< Power = " +
  1084.                           Double_To_AnsiString( d_IP2_CHECK_P_DL_OFF) ) + " dBm";
  1085.             }
  1086.             return false;
  1087.         }
  1088.         if ( this->Terminated )
  1089.         {
  1090.             this->OnTerminate = neByUser;
  1091.             return false;
  1092.         }
  1093.         if( frmFatcory->rbAgilent8960->Checked )
  1094.         {
  1095.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " Agilent 8960< Power = " +
  1096.                       Double_To_AnsiString( d_IP2_CHECK_P_DL_OFF) );
  1097.         }
  1098.         else
  1099.         {
  1100.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " CMU 200< Power = " +
  1101.                               Double_To_AnsiString( d_IP2_CHECK_P_DL_OFF) );
  1102.         }
  1103.        // if( frmFatcory->cbAFC->Checked )
  1104.         //{
  1105.         //    Sleep( 100 );  // wait Agilent 8960 ready!
  1106.         //}
  1107.         //else
  1108.         {
  1109.             Sleep( 200 );  // wait Agilent 8960 ready!
  1110.         }
  1111.         
  1112.       MF_rf_pm_cnf->deviation = 0;
  1113.       MF_rf_pm_cnf->power = 0;
  1114.       MF_rf_pm_cnf->usedGain = 0;
  1115.       MF_rf_pm_cnf->extra_info.valid =0;
  1116.       MF_rf_pm_cnf->extra_info.iOffset=0;
  1117.       MF_rf_pm_cnf->extra_info.qOffset=0;
  1118.       MF_rf_pm_cnf->extra_info.validSamples =0;
  1119.       MF_rf_pm_req->arfcn = s_ARFCN-30;
  1120.       MF_rf_pm_req->sampleNoPerFrame = c_IP2_M_PM;
  1121.       MF_rf_pm_req->gain = d_IP2_GAIN *AVG_POWER_PC_SIDE_MULTIPLY ;
  1122.       MF_rf_pm_req->frames = i_IP2_N_PM;
  1123.     if( META_Rf_PM_r( m_pCal->i_MainMETAHandle, MF_rf_pm_req, MF_rf_pm_cnf_cb, &MF_rf_pm_token, NULL ) != META_SUCCESS )
  1124.     {
  1125.         CalErrorHandler( WM_MF_RF_IP2_PM_FAIL );
  1126.         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1127.                                " FAIL: "+
  1128.                               " Target < PM : ARFCN = " + IntToStr( s_ARFCN-30 ) +
  1129.                               " sample per frame = " + IntToStr( c_IP2_M_PM) +
  1130.                               " gain = " + IntToStr( MF_rf_pm_req->gain ) +
  1131.                               " frames = " + IntToStr( i_IP2_N_PM)
  1132.                             );
  1133.                         return false;
  1134.     } // if
  1135.     if ( this->Terminated )
  1136.     {
  1137.        this->OnTerminate = neByUser;
  1138.        return false;
  1139.     }
  1140.     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1141.                       " Target < PM : ARFCN = " + IntToStr( s_ARFCN-30 ) +
  1142.                       ", sample per frame = " + IntToStr( c_IP2_M_PM) +
  1143.                       ", gain = " + IntToStr( MF_rf_pm_req->gain ) +
  1144.                       ", frames = " + IntToStr( i_IP2_N_PM)
  1145.                     );
  1146.            //  Sleep(100);// delay for power measurement
  1147.     RestartTimerCal( WM_MF_RF_IP2_PM_FAIL );
  1148.     is_suspend_cal = true;
  1149.     this->Suspend();
  1150.     is_suspend_cal = false;
  1151.     if ( this->Terminated )
  1152.     {
  1153.         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1154.                       " Terminate at line " + AnsiString(__FILE__) + " " + AnsiString(__LINE__)
  1155.                 );
  1156.         this->OnTerminate = neByUser;
  1157.         return false;
  1158.     }
  1159.     if( !MF_rf_pm_cnf->ok )
  1160.     {
  1161.         CalErrorHandler( WM_MF_RF_IP2_PM_FAIL );
  1162.         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1163.                           " Target < ok = " + IntToStr(MF_rf_pm_cnf->ok) +
  1164.                           ", power = " + Double_To_AnsiString(MF_rf_pm_cnf->power/8.0) +
  1165.                           ", deviation = " + Double_To_AnsiString(sqrt(MF_rf_pm_cnf->deviation)/8.0) +
  1166.                           ", usedGain = " + Double_To_AnsiString(MF_rf_pm_cnf->usedGain/8.0) +
  1167.                           ", valid = " + IntToStr(MF_rf_pm_cnf->extra_info.valid) +
  1168.                           ", I_DC = " + IntToStr(MF_rf_pm_cnf->extra_info.iOffset) +
  1169.                           ", Q_DC = " + IntToStr(MF_rf_pm_cnf->extra_info.qOffset) +
  1170.                           ", valid sample = " + IntToStr(MF_rf_pm_cnf->extra_info.validSamples)
  1171.                         );
  1172.         return false;
  1173.     }
  1174.     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1175.                       " Target > power = " + Double_To_AnsiString(MF_rf_pm_cnf->power/8.0) +
  1176.                       ", deviation = " + Double_To_AnsiString(sqrt(MF_rf_pm_cnf->deviation)/8.0) +
  1177.                       ", usedGain = " + Double_To_AnsiString(MF_rf_pm_cnf->usedGain/8.0) +
  1178.                       ", valid = " + IntToStr(MF_rf_pm_cnf->extra_info.valid) +
  1179.                       ", I_DC = " + IntToStr(MF_rf_pm_cnf->extra_info.iOffset) +
  1180.                       ", Q_DC = " + IntToStr(MF_rf_pm_cnf->extra_info.qOffset) +
  1181.                       ", valid sample = " + IntToStr(MF_rf_pm_cnf->extra_info.validSamples)
  1182.                    );
  1183.         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1184.                   " I_MDC_OFF = " + IntToStr(MF_rf_pm_cnf->extra_info.iOffset) +
  1185.                   ", Q_MDC_OFF = " + IntToStr(MF_rf_pm_cnf->extra_info.qOffset) 
  1186.                 );
  1187.         MDCI[0] = MF_rf_pm_cnf->extra_info.iOffset;
  1188.         MDCQ[0] = MF_rf_pm_cnf->extra_info.qOffset;
  1189.         //----------------------------------------------------------------
  1190.         // cell power on
  1191.         if( ! m_rct_ctrl.RCT_cellPower( m_pRct, d_IP2_CHECK_P_DL_ON ) )
  1192.         {
  1193.             CalErrorHandler( WM_MF_AGE8960_SET_POWER_FAIL );
  1194.             if( frmFatcory->rbAgilent8960->Checked )
  1195.             {
  1196.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " FAIL: Agilent 8960< Power = " +
  1197.                           Double_To_AnsiString( d_IP2_CHECK_P_DL_ON) ) + " dBm";
  1198.             }
  1199.             else
  1200.             {
  1201.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " FAIL: cmu200< Power = " +
  1202.                           Double_To_AnsiString( d_IP2_CHECK_P_DL_ON) ) + " dBm";
  1203.             }
  1204.             return false;
  1205.         }
  1206.         if ( this->Terminated )
  1207.         {
  1208.             this->OnTerminate = neByUser;
  1209.             return false;
  1210.         }
  1211.         if( frmFatcory->rbAgilent8960->Checked )
  1212.         {
  1213.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " Agilent 8960< Power = " +
  1214.                       Double_To_AnsiString( d_IP2_CHECK_P_DL_ON) );
  1215.         }
  1216.         else
  1217.         {
  1218.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " CMU 200< Power = " +
  1219.                               Double_To_AnsiString( d_IP2_CHECK_P_DL_ON) );
  1220.         }
  1221.        // if( frmFatcory->cbAFC->Checked )
  1222.         //{
  1223.         //    Sleep( 100 );  // wait Agilent 8960 ready!
  1224.         //}
  1225.         //else
  1226.         {
  1227.             Sleep( 200 );  // wait Agilent 8960 ready!
  1228.         }
  1229.         MF_rf_pm_cnf->deviation = 0;
  1230.         MF_rf_pm_cnf->power = 0;
  1231.         MF_rf_pm_cnf->usedGain = 0;
  1232.         MF_rf_pm_cnf->extra_info.valid =0;
  1233.         MF_rf_pm_cnf->extra_info.iOffset=0;
  1234.         MF_rf_pm_cnf->extra_info.qOffset=0;
  1235.         MF_rf_pm_cnf->extra_info.validSamples =0;
  1236.         MF_rf_pm_req->arfcn = s_ARFCN-30;
  1237.         MF_rf_pm_req->sampleNoPerFrame = c_IP2_M_PM;
  1238.         MF_rf_pm_req->gain = d_IP2_GAIN *AVG_POWER_PC_SIDE_MULTIPLY ;
  1239.         MF_rf_pm_req->frames = i_IP2_N_PM;
  1240.         if( META_Rf_PM_r( m_pCal->i_MainMETAHandle, MF_rf_pm_req, MF_rf_pm_cnf_cb, &MF_rf_pm_token, NULL ) != META_SUCCESS )
  1241.         {
  1242.             CalErrorHandler( WM_MF_RF_IP2_PM_FAIL );
  1243.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1244.                                " FAIL: "+
  1245.                               " Target < PM : ARFCN = " + IntToStr( s_ARFCN-30 ) +
  1246.                               " sample per frame = " + IntToStr( c_IP2_M_PM) +
  1247.                               " gain = " + IntToStr( MF_rf_pm_req->gain ) +
  1248.                               " frames = " + IntToStr( i_IP2_N_PM)
  1249.                             );
  1250.                         return false;
  1251.         } // if
  1252.         if ( this->Terminated )
  1253.         {
  1254.             this->OnTerminate = neByUser;
  1255.             return false;
  1256.         }
  1257.         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1258.                       " Target < PM : ARFCN = " + IntToStr( s_ARFCN-30 ) +
  1259.                       ", sample per frame = " + IntToStr( c_IP2_M_PM) +
  1260.                       ", gain = " + IntToStr( MF_rf_pm_req->gain ) +
  1261.                       ", frames = " + IntToStr( i_IP2_N_PM)
  1262.                     );
  1263.            //  Sleep(100);// delay for power measurement
  1264.         RestartTimerCal( WM_MF_RF_IP2_PM_FAIL );
  1265.         is_suspend_cal = true;
  1266.         this->Suspend();
  1267.         is_suspend_cal = false;
  1268.         if ( this->Terminated )
  1269.         {
  1270.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1271.                       " Terminate at line " + AnsiString(__FILE__) + " " + AnsiString(__LINE__)
  1272.                 );
  1273.             this->OnTerminate = neByUser;
  1274.             return false;
  1275.         }
  1276.         if( !MF_rf_pm_cnf->ok )
  1277.         {
  1278.             CalErrorHandler( WM_MF_RF_IP2_PM_FAIL );
  1279.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1280.                           " Target < ok = " + IntToStr(MF_rf_pm_cnf->ok) +
  1281.                           ", power = " + Double_To_AnsiString(MF_rf_pm_cnf->power/8.0) +
  1282.                           ", deviation = " + Double_To_AnsiString(sqrt(MF_rf_pm_cnf->deviation)/8.0) +
  1283.                           ", usedGain = " + Double_To_AnsiString(MF_rf_pm_cnf->usedGain/8.0) +
  1284.                           ", valid = " + IntToStr(MF_rf_pm_cnf->extra_info.valid) +
  1285.                           ", I_DC = " + IntToStr(MF_rf_pm_cnf->extra_info.iOffset) +
  1286.                           ", Q_DC = " + IntToStr(MF_rf_pm_cnf->extra_info.qOffset) +
  1287.                           ", valid sample = " + IntToStr(MF_rf_pm_cnf->extra_info.validSamples)
  1288.                         );
  1289.             return false;
  1290.         }
  1291.         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1292.                       " Target > power = " + Double_To_AnsiString(MF_rf_pm_cnf->power/8.0) +
  1293.                       ", deviation = " + Double_To_AnsiString(sqrt(MF_rf_pm_cnf->deviation)/8.0) +
  1294.                       ", usedGain = " + Double_To_AnsiString(MF_rf_pm_cnf->usedGain/8.0) +
  1295.                       ", valid = " + IntToStr(MF_rf_pm_cnf->extra_info.valid) +
  1296.                       ", I_DC = " + IntToStr(MF_rf_pm_cnf->extra_info.iOffset) +
  1297.                       ", Q_DC = " + IntToStr(MF_rf_pm_cnf->extra_info.qOffset) +
  1298.                       ", valid sample = " + IntToStr(MF_rf_pm_cnf->extra_info.validSamples)
  1299.                    );
  1300. #if 0
  1301.         int abs_iOffset = abs(MF_rf_pm_cnf->extra_info.iOffset);
  1302.         int abs_qOffset = abs(MF_rf_pm_cnf->extra_info.qOffset);
  1303.         if( abs_iOffset > i_IP2_MAX_IDC || abs_qOffset > i_IP2_MAX_QDC)
  1304.         {
  1305.             CalErrorHandler( WM_MF_RF_IP2_CHECK_FAIL );
  1306.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1307.                   " Fail: IP2 check ." + " I_MDC_ON = " + IntToStr(MF_rf_pm_cnf->extra_info.iOffset) +
  1308.                   ", Q_MDC_ON = " + IntToStr(MF_rf_pm_cnf->extra_info.qOffset) +
  1309.                   ", IP2_MAX_IDC = " + IntToStr( i_IP2_MAX_IDC ) +
  1310.                   ", IP2_MAX_QDC = " + IntToStr( i_IP2_MAX_QDC )
  1311.                 );
  1312.             return false;
  1313.         }
  1314.         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1315.                   " Pass: IP2 check ." + " I_MDC_ON = " + IntToStr(MF_rf_pm_cnf->extra_info.iOffset) +
  1316.                   ", Q_MDC_ON = " + IntToStr(MF_rf_pm_cnf->extra_info.qOffset) +
  1317.                   ", IP2_MAX_IDC = " + IntToStr( i_IP2_MAX_IDC ) +
  1318.                   ", IP2_MAX_QDC = " + IntToStr( i_IP2_MAX_QDC )
  1319.                 );
  1320. #endif
  1321.         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1322.                   " I_MDC_ON = " + IntToStr(MF_rf_pm_cnf->extra_info.iOffset) +
  1323.                   ", Q_MDC_ON = " + IntToStr(MF_rf_pm_cnf->extra_info.qOffset) 
  1324.                 );
  1325.         MDCI[1] = MF_rf_pm_cnf->extra_info.iOffset;
  1326.         MDCQ[1] = MF_rf_pm_cnf->extra_info.qOffset;
  1327.         DCI = MDCI[1] - MDCI[0];
  1328.         DCQ = MDCQ[1] - MDCQ[0];
  1329.         int ab_DCI = abs(DCI);
  1330.         int ab_QCQ = abs(DCQ);
  1331.         if( ab_DCI > m_iIP2_MAX_IDC_SKY74117 || ab_QCQ > m_iIP2_MAX_QDC_SKY74117)
  1332.         {
  1333.             CalErrorHandler( WM_MF_RF_IP2_CHECK_FAIL );
  1334.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1335.                   " Fail: IP2 check ." + " I_DC = " + IntToStr(DCI) +
  1336.                   ", Q_DC = " + IntToStr(DCQ)  +
  1337.                   ", IP2_MAX_IDC = " + IntToStr( m_iIP2_MAX_IDC_SKY74117 ) +
  1338.                   ", IP2_MAX_QDC = " + IntToStr( m_iIP2_MAX_QDC_SKY74117 )
  1339.                 );
  1340.             return false;
  1341.         }
  1342.         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1343.                   " Pass: IP2 check ." + " I_DC = " + IntToStr(DCI) +
  1344.                   ", Q_DC = " + IntToStr(DCQ) +
  1345.                   ", IP2_MAX_IDC = " + IntToStr( m_iIP2_MAX_IDC_SKY74117 ) +
  1346.                   ", IP2_MAX_QDC = " + IntToStr( m_iIP2_MAX_QDC_SKY74117 )
  1347.                 );
  1348.         eFreqBand++;
  1349.     } // while            
  1350.     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1351.              " ===================    IP2 check end    ==================== n "
  1352.            );
  1353.     PostMessage(
  1354.                      ctrl.hPostMsgDestHandle,
  1355.                      WM_MF_RF_IP2_CALIBRATION_DONE,
  1356.                      0,
  1357.                      0
  1358.                     );
  1359.     frmFatcory->DisableAllCalTimer();                
  1360.     return true;
  1361. }