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

MTK

开发平台:

C++ Builder

  1. /*****************************************************************************
  2. *  Copyright Statement:
  3. *  --------------------
  4. *  This software is protected by Copyright and the information contained
  5. *  herein is confidential. The software may not be copied and the information
  6. *  contained herein may not be used or disclosed except with the written
  7. *  permission of MediaTek Inc. (C) 2001
  8. *
  9. *****************************************************************************/
  10. /*****************************************************************************
  11.  *
  12.  * Filename:
  13.  * ---------
  14.  *   T_TXPCL_EPSK_common.cpp
  15.  *
  16.  * Project:
  17.  * --------
  18.  *   Maui META APP
  19.  *
  20.  * Description:
  21.  * ------------
  22.  *  TX PCL EPSK calibration common source
  23.  *
  24.  * Author:
  25.  * -------
  26.  *  Andy Ueng (mtk00490)
  27.  *
  28.  *============================================================================
  29.  *             HISTORY
  30.  * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  31.  *------------------------------------------------------------------------------
  32.  * $Revision$
  33.  * $Modtime$
  34.  * $Log$
  35.  *
  36.  *------------------------------------------------------------------------------
  37.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  38.  *============================================================================
  39. ****************************************************************************/
  40. #include <assert.h>
  41. #include <math.h>
  42. #pragma hdrstop
  43. #ifndef _T_META_FACTORY_CALIBRATION_H_
  44. #include "T_META_factory_calibration.H"
  45. #endif
  46. #ifndef _APCCAL_COMMON_H_
  47. #include "apccal_common.h"
  48. #endif
  49. #ifndef  _RF_APC_H_
  50. #include "rf_apc.h"
  51. #endif
  52. // callback
  53. #ifndef _META_FACTORY_RF_CB_H_
  54. #include "meta_factory_rf_cb.h"
  55. #endif
  56. #ifndef _META_FACTORY_NVRAM_CB_H_
  57. #include "meta_factory_nvram_cb.h"
  58. #endif
  59. // form
  60. #ifndef _META_FACTORY_H_
  61. #include "META_Factory.h"
  62. #endif
  63. // equipment
  64. #ifndef _AGECOMMON_H_
  65. #include "agecommon.h"
  66. #endif
  67. #ifndef _AGE1968A_H_
  68. #include "age1968a.h"
  69. #endif
  70. // misc
  71. #ifndef  _FT_UTILS_H_
  72. #include "ft_utils.h"
  73. #endif
  74. #ifndef  _BAND_UTILS_H_
  75. #include "band_utils.h"
  76. #endif
  77. #ifndef  _GSM_UTILS_H_
  78. #include "gsm_utils.h"
  79. #endif
  80. #ifndef  _TIME_UTILS_H_
  81. #include "time_utils.h"
  82. #endif
  83. //----------------------------------------------------------------------------
  84. // equipment
  85. extern CMU_VAR cmu;
  86. extern CRFAPC*  MF_rf_apc_ptr;
  87. extern CRFAPC8PSK*  MF_rf_apc_8psk_ptr;
  88. //extern RfNbtx_Req *MF_rf_tx_level_req;
  89. //extern bool MF_rf_tx_level_cnf;
  90. extern bool  is_suspend_cal; // in T_META_factory_calibration.cpp
  91. //============================================================================
  92. bool __fastcall T_META_factory_calibration::TXPCLCal_EPSK_1cal(void)
  93. {
  94.     int FIRST_PCL;
  95.     AnsiString  as_epsk_tx_pcl;
  96.     short  s_epsk_tx_1cal_pcl;
  97.     AnsiString  as_epsk_max_p;
  98.     AnsiString  as_epsk_wanted_p;
  99.     AnsiString  as_epsk_min_p;
  100.     AnsiString  as_epsk_c;
  101.     AnsiString  as_epsk_sub_tx_pcl;
  102.     AnsiString  as_epsk_sub_max_p;
  103.     AnsiString  as_epsk_sub_wanted_p;
  104.     AnsiString  as_epsk_sub_min_p;
  105.     AnsiString  as_epsk_sub_c;
  106.     log->Add( "n" + DateToStr(Date()) +  " " + CurrentTimeStr() +
  107.              " ========== EPSK TX power control level calibration begin ========== n "
  108.            );
  109.     if( ! m_rct_ctrl.RCT_operatingMode( m_pRct, OPERATING_MODE_EGPRS_BCH_PDTCH ) )
  110.     {
  111.         CalErrorHandler( WM_MF_AGE8960_SET_OPERATION_MODE_FAIL );
  112.         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  113.                               " FAIL : "+
  114.                               m_pRct->as_RCT + " < Operation mode = EGPRS BCH+PDTCH"
  115.                             );
  116.             return false;
  117.     }
  118.     if( ! m_rct_ctrl.RCT_Config_EPSK_CodingScheme( m_pRct, MCS5 ) )
  119.     {
  120.         CalErrorHandler( WM_MF_AGE8960_SET_CODING_SCHEME_FAIL );
  121.         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  122.                               " FAIL: "+
  123.                               m_pRct->as_RCT + " < Coding scheme = MCS5"
  124.                             );
  125.         return false;
  126.     }
  127.     short s_arfcn;
  128.     E_BANDSEL band_index;
  129.     int vi_Band;
  130.     FrequencyBand eFreqBand = FrequencyBand850;
  131.     i_N_TX = -99; // TX frames
  132.     //---------------------------------------------------------------------------
  133.     while (eFreqBand < FrequencyBandCount)
  134.     {
  135.         switch (eFreqBand)
  136.         {
  137.             case FrequencyBand850:
  138.             {
  139.                 if (! IsFreqBankSupported(m_asFreqBank, eFreqBand))
  140.                 {
  141.                     eFreqBand++;
  142.                     continue;
  143.                 }
  144.                 FIRST_PCL = GSM850_FIRST_PCL;
  145.                 vi_Band = age1960_GSM850_BAND;
  146.                 band_index = BANDSEL_GSM850;
  147.                 s_arfcn = m_sARFCN_C0_GSM850;
  148.                 i_TX_level_count = RF_TX_LEVEL_1_CAL_COUNT;
  149.                 s_epsk_tx_1cal_pcl = m_s_gsm850_epsk_tx_1cal_pcl;
  150.                 as_epsk_tx_pcl = m_as_gsm850_epsk_tx_pcl;
  151.                 as_epsk_max_p = m_as_gsm850_epsk_max_p;
  152.                 as_epsk_wanted_p = m_as_gsm850_epsk_wanted_p;
  153.                 as_epsk_min_p = m_as_gsm850_epsk_min_p;
  154.                 as_epsk_c = m_as_gsm850_epsk_c;
  155.             }
  156.             break;
  157.             case FrequencyBand900:
  158.             {
  159.                 if (!IsFreqBankSupported(m_asFreqBank, eFreqBand))
  160.                 {
  161.                     eFreqBand++;
  162.                     continue;
  163.                 }
  164.                 FIRST_PCL = GSM900_FIRST_PCL;
  165.                 vi_Band = age1960_EGSM_BAND;
  166.                 band_index = BANDSEL_GSM900;
  167.                 s_arfcn = m_sARFCN_C0_GSM;
  168.                 i_TX_level_count = RF_TX_LEVEL_1_CAL_COUNT;
  169.                 s_epsk_tx_1cal_pcl = m_s_gsm900_epsk_tx_1cal_pcl;
  170.                 as_epsk_tx_pcl = m_as_gsm900_epsk_tx_pcl;
  171.                 as_epsk_max_p = m_as_gsm900_epsk_max_p;
  172.                 as_epsk_wanted_p = m_as_gsm900_epsk_wanted_p;
  173.                 as_epsk_min_p = m_as_gsm900_epsk_min_p;
  174.                 as_epsk_c = m_as_gsm900_epsk_c;
  175.             }
  176.             break;
  177.             case FrequencyBand1800:
  178.             {
  179.                 if (!IsFreqBankSupported(m_asFreqBank, eFreqBand))
  180.                 {
  181.                     eFreqBand++;
  182.                     continue;
  183.                 }
  184.                 FIRST_PCL = DCS1800_FIRST_PCL;
  185.                 vi_Band = age1960_DCS1800_BAND;
  186.                 band_index = BANDSEL_DCS1800;
  187.                 s_arfcn = m_sARFCN_C0_DCS;
  188.                 i_TX_level_count = RF_TX_LEVEL_1_CAL_COUNT;
  189.                 s_epsk_tx_1cal_pcl = m_s_dcs1800_epsk_tx_1cal_pcl;
  190.                 as_epsk_tx_pcl = m_as_dcs1800_epsk_tx_pcl;
  191.                 as_epsk_max_p = m_as_dcs1800_epsk_max_p;
  192.                 as_epsk_wanted_p = m_as_dcs1800_epsk_wanted_p;
  193.                 as_epsk_min_p = m_as_dcs1800_epsk_min_p;
  194.                 as_epsk_c = m_as_dcs1800_epsk_c;
  195.             }
  196.             break;
  197.             case FrequencyBand1900:
  198.             {
  199.                 if (!IsFreqBankSupported(m_asFreqBank, eFreqBand))
  200.                 {
  201.                     eFreqBand++;
  202.                     continue;
  203.                 }
  204.                 FIRST_PCL = PCS1900_FIRST_PCL;
  205.                 vi_Band = age1960_PCS1900_BAND;
  206.                 band_index = BANDSEL_PCS1900;
  207.                 s_arfcn = m_sARFCN_C0_PCS;
  208.                 i_TX_level_count = RF_TX_LEVEL_1_CAL_COUNT;
  209.                 s_epsk_tx_1cal_pcl = m_s_pcs1900_epsk_tx_1cal_pcl;
  210.                 as_epsk_tx_pcl = m_as_pcs1900_epsk_tx_pcl;
  211.                 as_epsk_max_p = m_as_pcs1900_epsk_max_p;
  212.                 as_epsk_wanted_p = m_as_pcs1900_epsk_wanted_p;
  213.                 as_epsk_min_p = m_as_pcs1900_epsk_min_p;
  214.                 as_epsk_c = m_as_pcs1900_epsk_c;
  215.             }
  216.             break;
  217.             default:
  218.                 assert(false);
  219.             break;
  220.         } // switch
  221.         if ( this->Terminated )
  222.         {
  223.             this->OnTerminate = neByUser;
  224.             return false;
  225.         }
  226.         log->Add("n" + DateToStr(Date()) +  " " + CurrentTimeStr() +
  227.                          " ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
  228.                        );
  229.         if (!MF_rf_apc_8psk_ptr->ApcSectionExist(m_pCal->as_IniFile.c_str(), band_index))
  230.         {
  231.             CalErrorHandler(WM_MF_RF_TX_LEVEL_INI_FAIL);
  232.             log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  233.                      " FAIL :"+
  234.                      " APC section is not in initial file: " + FreqBand_To_Str(eFreqBand)
  235.                      );
  236.             return false;
  237.         }
  238.         if(IsFreqBankSupported(  m_asFreqBank, eFreqBand))
  239.         {
  240.             if( FrequencyBand1900 == eFreqBand )
  241.             {
  242.                 if(META_Rf_SelectFrequencyBand1900_r( m_pCal->i_MainMETAHandle, 1, MF_SelectBand_cnf_cb, &MF_SelectBand_token, NULL) !=  META_SUCCESS)
  243.                 {
  244.                     CalErrorHandler( WM_MF_RF_TX_LEVEL_FAIL );
  245.                     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  246.                                   " FAIL: target < set Band1900 flag = 1"
  247.                                 );
  248.                     return false;
  249.                 }
  250.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  251.                               " target < set Band1900 flag = 1"
  252.                             );
  253.             }
  254.             else
  255.             {
  256.                 if(META_Rf_SelectFrequencyBand1900_r( m_pCal->i_MainMETAHandle, 0, MF_SelectBand_cnf_cb, &MF_SelectBand_token, NULL) !=  META_SUCCESS)
  257.                 {
  258.                     CalErrorHandler( WM_MF_RF_TX_LEVEL_FAIL );
  259.                     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  260.                                   " FAIL: target < set Band1900 flag = 0"
  261.                                 );
  262.                     return false;
  263.                 }
  264.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  265.                               " target < set Band1900 flag = 0"
  266.                             );
  267.             }
  268.             is_suspend_cal = true;
  269.             this->Suspend();
  270.             is_suspend_cal = false;
  271.         }
  272.         if( ! m_rct_ctrl.RCT_cellBand( m_pRct, vi_Band ) )
  273.         {
  274.             CalErrorHandler( WM_MF_AGE8960_SET_BAND_FAIL );
  275.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  276.                               " FAIL: "+
  277.                               m_pRct->as_RCT + " < Band = " + ViBand_To_Str( vi_Band )
  278.                             );
  279.             return false;
  280.         }
  281.         Sleep( 100 );  // wait Agilent 8960 cell band setup ready!
  282.                    // if Agilent 8960 not read, target will get error power!
  283.         if ( this->Terminated )
  284.         {
  285.             this->OnTerminate = neByUser;
  286.             return false;
  287.         }
  288.         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +  " " +
  289.                           m_pRct->as_RCT + " < Band = " + ViBand_To_Str( vi_Band )
  290.                         );
  291.         short bch_arfcn = ::Get_SeperateChannel( vi_Band, s_arfcn );
  292.         if( ! m_rct_ctrl.RCT_BCHARFCN( m_pRct, bch_arfcn) )
  293.         {
  294.             CalErrorHandler( WM_MF_AGE8960_SET_BCH_ARFCN_FAIL );
  295.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  296.                               " FAIL: "+
  297.                               m_pRct->as_RCT + " < BCH ARFCN = " + IntToStr( bch_arfcn )
  298.                     );
  299.             return false;
  300.         }
  301.         if( ! m_rct_ctrl.RCT_PDTCHARFCN( m_pRct, s_arfcn ) )
  302.         {
  303.             CalErrorHandler( WM_MF_AGE8960_SET_PDTCH_ARFCN_FAIL );
  304.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  305.                               " FAIL: "+
  306.                               m_pRct->as_RCT + " < PDTCH ARFCN = " + IntToStr( s_arfcn )
  307.                             );
  308.             return false;
  309.         }
  310.         if( this->Terminated )
  311.         {
  312.             this->OnTerminate = neByUser;
  313.             return false;
  314.         }
  315.         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +  " " +
  316.                           m_pRct->as_RCT + " < PDTCH ARFCN = " + IntToStr( s_arfcn )
  317.                         );
  318.         if( ! m_rct_ctrl.RCT_ConfigTSC( m_pRct, m_cTSC ) )
  319.         {
  320.             CalErrorHandler( WM_MF_AGE8960_SET_TSC_FAIL );
  321.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +  " " +
  322.                               "FAIL : " + m_pRct->as_RCT + " < set TSC fail."
  323.                             );
  324.             return false;
  325.         }
  326.         if ( this->Terminated )
  327.         {
  328.             this->OnTerminate = neByUser;
  329.             return false;
  330.         }
  331.         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +  " " +
  332.                           m_pRct->as_RCT + " < TSC = " + IntToStr( m_cTSC)
  333.                         );
  334.         if( ! m_rct_ctrl.RCT_EPSK_TXPowerContOff( m_pRct ) )
  335.         {
  336.             CalErrorHandler( WM_MF_AGE8960_SET_TX_POWER_CONT_OFF_FAIL );
  337.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +  " " +
  338.                               " FAIL : " + m_pRct->as_RCT + " < set TX power continuous OFF "
  339.                             );
  340.             return false;
  341.         }
  342.         if ( this->Terminated )
  343.         {
  344.             this->OnTerminate = neByUser;
  345.             return false;
  346.         }
  347.         //log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  348.         //                  " TimerCal->Enabled 8= " + IntToStr((int)frmFatcory->TimerCal->Enabled)
  349.         //                );
  350.         RestartTimerCal( WM_MF_AGE8960_CONFIG_TX_POWER_FAIL );
  351.         if( ! m_rct_ctrl.RCT_confTXPower_EPSK( m_pRct ) )
  352.         {
  353.             CalErrorHandler( WM_MF_AGE8960_CONFIG_TX_POWER_FAIL );
  354.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  355.                                   " FAIL: " + m_pRct->as_RCT + " < config TX power 1."
  356.                                 );
  357.             return false;
  358.         }
  359.         // calibration from high power to low power
  360.         // index from big to little.
  361.         // PCL string in config file from right to left.
  362.         int iRealRecursiveTimes = 0;
  363.         if( TX_SLOT_SINGLE == m_pCal->e_tx_slot )
  364.         {
  365.             for ( int N=0; N<i_TX_level_count; N++)  // DCS,PCS:16~1 or GSM:15~1
  366.             {
  367.                 log->Add( "n" + DateToStr(Date()) +  " " + CurrentTimeStr() +
  368.                           " ------------------------------------------------------------------ "
  369.                         );
  370.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  371.                           " N = " + N
  372.                         );
  373.                 for( iRealRecursiveTimes=0; iRealRecursiveTimes<i_TXlevelRecusiveTimes;
  374.                      iRealRecursiveTimes++) // marked by Andy Ueng for no iteration test
  375.                 {
  376.                     log->Add( "n" + DateToStr(Date()) +  " " + CurrentTimeStr() +
  377.                               " RecursiveTimes = " + IntToStr(iRealRecursiveTimes)
  378.                             );
  379.                     if( iRealRecursiveTimes == 0)
  380.                     {
  381.                         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  382.                               " MF_rf_apc_8psk_ptr->ApcProfile[" + IntToStr(band_index) + "].rampData.power[" +
  383.                                 IntToStr(FIRST_PCL-s_epsk_tx_1cal_pcl) + "] = " +
  384.                                 IntToStr(MF_rf_apc_8psk_ptr->Get_ApcProfilePower(band_index, FIRST_PCL-s_epsk_tx_1cal_pcl) )
  385.                             );
  386.                         m_usPCLDacValue_EPSK[band_index][N] = MF_rf_apc_8psk_ptr->Get_ApcProfilePower(band_index, FIRST_PCL-s_epsk_tx_1cal_pcl);
  387.                         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  388.                                   " m_usPCLDacValue_EPSK[" +IntToStr(band_index) + "][" + IntToStr(N) + "] = " +
  389.                                     IntToStr(m_usPCLDacValue_EPSK[band_index][N])
  390.                                 );
  391.                     }
  392.                     if(! getAnsiStrSubItem( as_epsk_max_p, FIRST_PCL-s_epsk_tx_1cal_pcl+1, DEFAULT_SEP_CHAR, as_epsk_sub_max_p) )
  393.                     {
  394.                         CalErrorHandler( WM_MF_CFG_READ_FAIL );
  395.                         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  396.                               " FAIL: Read config file fail(sub_max_p)."
  397.                             );
  398.                         return false;
  399.                     }
  400.                     if(! getAnsiStrSubItem( as_epsk_min_p, FIRST_PCL-s_epsk_tx_1cal_pcl+1, DEFAULT_SEP_CHAR, as_epsk_sub_min_p) )
  401.                     {
  402.                         CalErrorHandler( WM_MF_CFG_READ_FAIL );
  403.                         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  404.                               " FAIL: Read config file fail(sub_min_p)."
  405.                             );
  406.                         return false;
  407.                     }
  408.                     if(! getAnsiStrSubItem( as_epsk_wanted_p, FIRST_PCL-s_epsk_tx_1cal_pcl+1, DEFAULT_SEP_CHAR, as_epsk_sub_wanted_p) )
  409.                     {
  410.                         CalErrorHandler( WM_MF_CFG_READ_FAIL );
  411.                         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  412.                               " FAIL: Read config file fail(sub_wanted_p)."
  413.                             );
  414.                         return false;
  415.                     }
  416.                     if(! getAnsiStrSubItem( as_epsk_c, FIRST_PCL-s_epsk_tx_1cal_pcl+1, DEFAULT_SEP_CHAR, as_epsk_sub_c) )
  417.                     {
  418.                         CalErrorHandler( WM_MF_CFG_READ_FAIL );
  419.                         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  420.                               " FAIL: Read config file fail(c)."
  421.                             );
  422.                         return false;
  423.                     }
  424.                     if (!m_rct_ctrl.RCT_PDTCHMSTxLevel(m_pRct, s_epsk_tx_1cal_pcl))
  425.                     {
  426.                         CalErrorHandler( WM_MF_AGE8960_SET_MS_TX_LEVEL_FAIL );
  427.                         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  428.                                   " FAIL: " + m_pRct->as_RCT + " < MS TX level = " + IntToStr(s_epsk_tx_1cal_pcl)
  429.                                 );
  430.                         return false;
  431.                     }
  432.                     if( this->Terminated )
  433.                     {
  434.                         this->OnTerminate = neByUser;
  435.                         return false;
  436.                     }
  437.                     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +  " " +
  438.                               m_pRct->as_RCT + " < MS TX level = " + IntToStr(s_epsk_tx_1cal_pcl)
  439.                             );
  440.                     RestartTimerCal(WM_MF_RF_STOP_FAIL);
  441.                     if (!MF_rf_stop.REQ_Start())
  442.                     {
  443.                         CalErrorHandler(WM_MF_RF_STOP_FAIL);
  444.                         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  445.                                  " FAIL: Target < stop RF fail."
  446.                                 );
  447.                         return false;
  448.                     }
  449.                     int   pcl[4];
  450.                     CodingScheme  cs[4];
  451.                     cs[0]    = CodingSchemeMCS5;
  452.                     cs[1]    = CodingSchemeMCS5;
  453.                     cs[2]    = CodingSchemeMCS5;
  454.                     cs[3]    = CodingSchemeMCS5;
  455.                     pcl[0]   = s_epsk_tx_1cal_pcl;
  456.                     pcl[1]   = s_epsk_tx_1cal_pcl;
  457.                     pcl[2]   = s_epsk_tx_1cal_pcl;
  458.                     pcl[3]   = s_epsk_tx_1cal_pcl;
  459.                     S_MULTI_SLOT_TX_T multi_slot_tx;
  460.                     multi_slot_tx.b_MultiSlotTXExSupport = m_pCal->b_MultiSlotTxExSupport;
  461.                     multi_slot_tx.e_bandsel = band_index;
  462.                     multi_slot_tx.req.arfcn = s_arfcn;
  463.                     multi_slot_tx.req.bsic  = m_cTSC;
  464.                     multi_slot_tx.req.timeSlotmask = 0x01;
  465.                     for (int i=0; i<4; i++)
  466.                     {
  467.                         multi_slot_tx.req.powerLev[i] = pcl[i];
  468.                         multi_slot_tx.req.cs[i]       = cs[i];
  469.                     }
  470.                     multi_slot_tx.req.ta = 0;
  471.                     multi_slot_tx.req.frames = -99;
  472.                     multi_slot_tx.req.dacValue = m_sDefault_value;
  473.                     multi_slot_tx.req.pattern = NB_TX_RANDOM_WITH_TSC;
  474.                     multi_slot_tx.req.pattern_data = 0;
  475.                     RF_MULTI_SLOT_TX_Obj.ConfirmCallback = ::ConfirmCallback_MultiSlotTX;
  476.                     RF_MULTI_SLOT_TX_Obj.REQ_Start(multi_slot_tx);
  477.                     if( this->Terminated )
  478.                     {
  479.                         this->OnTerminate = neByUser;
  480.                         return false;
  481.                     }
  482.                     #ifdef _MYDEBUG_
  483.                         TDateTime::CurrentTime().DecodeTime(&hr, &min, &sec, &ms );
  484.                     #endif
  485.                     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  486.                     #ifdef _MYDEBUG_
  487.                      ":" + AnsiString( ms ) +
  488.                     #endif
  489.                     " Target< TX: ARFCN = " + IntToStr( s_arfcn ) +
  490.                     ", TSC = " + IntToStr( m_cTSC ) +
  491.                     ", power = " + as_epsk_sub_tx_pcl +
  492.                     ", frames = " + IntToStr(i_N_TX) +
  493.                     ", dac value = " + IntToStr( m_sDefault_value )
  494.                     );
  495.                     #ifdef _MYDEBUG_
  496.                     TDateTime::CurrentTime().DecodeTime(&hr, &min, &sec, &ms );
  497.                     log->Add( " before suspend " + DateToStr(Date()) +  " " + CurrentTimeStr() +
  498.                           ":" + AnsiString( ms )
  499.                         );
  500.                     #endif
  501.                // log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  502.                //           " TimerCal->Enabled 7= " + IntToStr((int)frmFatcory->TimerCal->Enabled)
  503.                //         );
  504.                     RestartTimerCal( WM_MF_RF_TX_LEVEL_FAIL );
  505.                     SUSPEND_CAL_THREAD
  506.                     if( RF_MULTI_SLOT_TX_Obj.Get_ConfirmState() != METAAPP_SUCCESS )
  507.                     {
  508.                         CalErrorHandler( WM_MF_RF_TX_LEVEL_FAIL );
  509.                         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  510.                                  " FAIL: Target < multislot TX fail."
  511.                                 );
  512.                         return false;
  513.                     }
  514.                     #ifdef _MYDEBUG_
  515.                     TDateTime::CurrentTime().DecodeTime(&hr, &min, &sec, &ms );
  516.                     log->Add( " after resume " + DateToStr(Date()) +  " " + CurrentTimeStr() +
  517.                           ":" + AnsiString( ms )
  518.                          );
  519.                     #endif
  520.                     if( this->Terminated )
  521.                     {
  522.                         this->OnTerminate = neByUser;
  523.                         return false;
  524.                     }
  525.                     #ifdef _MYDEBUG_
  526.                     TDateTime::CurrentTime().DecodeTime(&hr, &min, &sec, &ms );
  527.                     log->Add( " before read TX power Q " + DateToStr(Date()) +  " " + CurrentTimeStr() +
  528.                               ":" + AnsiString( ms )
  529.                             );
  530.                     #endif
  531.                     RestartTimerCal( WM_MF_AGE8960_READ_TX_POWER_FAIL );
  532.                     if( ! m_rct_ctrl.RCT_ReadTxPower_EPSK( m_pRct, m_virTX) )
  533.                     {
  534.                         CalErrorHandler( WM_MF_AGE8960_READ_TX_POWER_FAIL );
  535.                         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  536.                                   " FAIL: " + m_pRct->as_RCT + " < read TX power 1."
  537.                                 );
  538.                         return false;
  539.                     }
  540.                     frmFatcory->DisableAllCalTimer();
  541.                     m_dPCL_dBm_EPSK[band_index][N] = m_virTX ;
  542.                     m_dPCL_power_EPSK[band_index][N] =  pow(10.0, m_dPCL_dBm_EPSK[band_index][N]/10.0)/1000.0;
  543.                     #ifdef _MYDEBUG_
  544.                     TDateTime::CurrentTime().DecodeTime(&hr, &min, &sec, &ms );
  545.                     log->Add( " after read TX power Q " + DateToStr(Date()) +  " " + CurrentTimeStr() +
  546.                           ":" + AnsiString( ms )
  547.                         );
  548.                     #endif
  549.                     if( this->Terminated )
  550.                     {
  551.                         this->OnTerminate = neByUser;
  552.                         return false;
  553.                     }
  554.                     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +  " " +
  555.                               m_pRct->as_RCT + " < read TX power = "+ Double_To_AnsiString( m_virTX )
  556.                             );
  557.                     signed short  ss1;
  558.                     double d1;
  559.                     if(iRealRecursiveTimes != i_TXlevelRecusiveTimes-1) //iteration
  560.                     {
  561.                         if ( m_virTX > (atof(as_epsk_sub_wanted_p.c_str()) + m_dAPC_Delta) ||
  562.                              m_virTX < (atof(as_epsk_sub_wanted_p.c_str()) - m_dAPC_Delta))
  563.                         {
  564.                             d1 = atof(as_epsk_sub_c.c_str()) * (atof(as_epsk_sub_wanted_p.c_str()) - m_virTX );
  565.                             ss1 = (signed short) (d1>0) ? floor(d1+1.0): ceil(d1-1.0);
  566.                             if ((MF_rf_apc_8psk_ptr->Get_ApcProfilePower(band_index, FIRST_PCL - s_epsk_tx_1cal_pcl) + ss1) <= 0 )
  567.                             {
  568.                                 MF_rf_apc_8psk_ptr->Set_ApcProfilePower(band_index, FIRST_PCL - s_epsk_tx_1cal_pcl, 1);
  569.                             }
  570.                             else if ((MF_rf_apc_8psk_ptr->Get_ApcProfilePower(band_index, FIRST_PCL - s_epsk_tx_1cal_pcl) + ss1) > MAX_APC_DAC)
  571.                             {
  572.                                 MF_rf_apc_8psk_ptr->Set_ApcProfilePower(band_index, FIRST_PCL - s_epsk_tx_1cal_pcl, MAX_APC_DAC);
  573.                             }
  574.                             else
  575.                             {
  576.                                 MF_rf_apc_8psk_ptr->Set_ApcProfilePower( band_index, FIRST_PCL - s_epsk_tx_1cal_pcl, MF_rf_apc_8psk_ptr->Get_ApcProfilePower(band_index, FIRST_PCL - s_epsk_tx_1cal_pcl) + ss1);
  577.                             }
  578.                             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  579.                                       " band_index = " + IntToStr(band_index) + "," +
  580.                                       " power_index = " + IntToStr(FIRST_PCL - s_epsk_tx_1cal_pcl) + "," +
  581.                                       " MF_rf_apc_8psk_ptr->ApcProfile[band_index].rampData.power[power_index] = " + IntToStr(MF_rf_apc_8psk_ptr->Get_ApcProfilePower(band_index, FIRST_PCL - s_epsk_tx_1cal_pcl))
  582.                                     );
  583.                             m_usPCLDacValue_EPSK[band_index][N] = MF_rf_apc_8psk_ptr->Get_ApcProfilePower(band_index, FIRST_PCL - s_epsk_tx_1cal_pcl);
  584.                             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  585.                                       " m_usPCLDacValue_EPSK[" + IntToStr(band_index) +"][" + IntToStr(N) +"] = " +
  586.                                       IntToStr(m_usPCLDacValue_EPSK[band_index][N])
  587.                                     );
  588.                             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  589.                                       " new S = " +
  590.                                       AnsiString( MF_rf_apc_8psk_ptr->Get_ApcProfilePower(band_index, FIRST_PCL - s_epsk_tx_1cal_pcl))
  591.                                     );
  592.                             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  593.                                       " delta s = "+
  594.                                       AnsiString( ss1 )
  595.                                     );
  596.                             RfSetRampApcLevel_Req  RfSetApcDac;
  597.                             RfSetApcDac.rf_band = eFreqBand;
  598.                             RfSetApcDac.power_level = s_epsk_tx_1cal_pcl;
  599.                             RfSetApcDac.apc_dac = MF_rf_apc_8psk_ptr->Get_ApcProfilePower(band_index, FIRST_PCL - s_epsk_tx_1cal_pcl);
  600.                             MF_rf_apc_8psk_ptr->ConfirmCallback = ::ccb_set_apc_level;
  601.                             MF_rf_apc_8psk_ptr->REQ_EPSK_SetRampApcLevel_Start( &RfSetApcDac );
  602.                             if( this->Terminated )
  603.                             {
  604.                                 this->OnTerminate = neByUser;
  605.                                 return false;
  606.                             }
  607.                             RestartTimerCal(WM_MF_SET_APC_DAC_FAIL);
  608.                             is_suspend_cal = true;
  609.                             this->Suspend();
  610.                             is_suspend_cal = false;
  611.                             E_METAAPP_RESULT_T state = MF_rf_apc_8psk_ptr->Get_ConfirmState();
  612.                             if (state != METAAPP_SUCCESS)
  613.                             {
  614.                                 CalErrorHandler( WM_MF_SET_APC_DAC_FAIL );
  615.                                 log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  616.                                              " FAIL: Target< set APC level fail. PCL = " + IntToStr(s_epsk_tx_1cal_pcl) +
  617.                                              " APC DAC = " +  IntToStr(MF_rf_apc_8psk_ptr->Get_ApcProfilePower(band_index, FIRST_PCL - s_epsk_tx_1cal_pcl))  + "n"
  618.                                             );
  619.                                 return false;
  620.                             }
  621.                             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  622.                                       " Target< set APC level ok. PCL = "+ IntToStr(s_epsk_tx_1cal_pcl) + "," +
  623.                                       " APC DAC = " +  IntToStr(MF_rf_apc_8psk_ptr->Get_ApcProfilePower(band_index, FIRST_PCL - s_epsk_tx_1cal_pcl))  + "n"
  624.                                     );
  625.                             if (this->Terminated)
  626.                             {
  627.                                 this->OnTerminate = neByUser;
  628.                                 return false;
  629.                             }
  630.                         }
  631.                         else
  632.                         {
  633.                             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  634.                                   " delta s = 0 "
  635.                                 );
  636.                             break; // for iRealRecursiveTimes
  637.                         }
  638.                     } // if no iteration
  639.                     if( this->Terminated )
  640.                     {
  641.                         this->OnTerminate = neByUser;
  642.                         return false;
  643.                     }
  644.                 } // for iRealRecursiveTimes
  645.             } // for N
  646.         } // single slot TX
  647.         else // multi-slot TX
  648.         {
  649.         }
  650.         eFreqBand++;
  651.         if ( this->Terminated )
  652.         {
  653.             this->OnTerminate = neByUser;
  654.             return false;
  655.         }
  656.     } // while
  657.         log->Add( "n" + DateToStr(Date()) +  " " + CurrentTimeStr() +
  658.              " =========== EPSK TX power control level calibration end =========== n "
  659.            );
  660.     RestartTimerCal(WM_MF_RF_STOP_FAIL);
  661.     if (!MF_rf_stop.REQ_Start())
  662.     {
  663.         CalErrorHandler(WM_MF_RF_STOP_FAIL);
  664.         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  665.                           " FAIL: Target < stop RF fail."
  666.                         );
  667.         return false;
  668.     }
  669.     frmFatcory->DisableAllCalTimer();
  670.     return true;
  671. }
  672. //============================================================================
  673. bool __fastcall T_META_factory_calibration::TXPCLCal_EPSK_2cal(void)
  674. {
  675.     int FIRST_PCL=0;
  676.     AnsiString  as_epsk_tx_pcl;
  677.     AnsiString  as_epsk_tx_2cal_pcl;
  678.     AnsiString  as_epsk_sub_tx_2cal_pcl;
  679.     AnsiString  as_epsk_max_p;
  680.     AnsiString  as_epsk_wanted_p;
  681.     AnsiString  as_epsk_min_p;
  682.     AnsiString  as_epsk_c;
  683.     AnsiString  as_epsk_sub_tx_pcl;
  684.     AnsiString  as_epsk_sub_max_p;
  685.     AnsiString  as_epsk_sub_wanted_p;
  686.     AnsiString  as_epsk_sub_min_p;
  687.     AnsiString  as_epsk_sub_c;
  688.     log->Add( "n" + DateToStr(Date()) +  " " + CurrentTimeStr() +
  689.              " ========== EPSK TX power control level calibration begin ========== n "
  690.            );
  691.     if( ! m_rct_ctrl.RCT_operatingMode( m_pRct, OPERATING_MODE_EGPRS_BCH_PDTCH ) )
  692.     {
  693.         CalErrorHandler( WM_MF_AGE8960_SET_OPERATION_MODE_FAIL );
  694.         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  695.                               " FAIL : "+
  696.                               m_pRct->as_RCT + " < Operation mode = EGPRS BCH+PDTCH"
  697.                             );
  698.             return false;
  699.     }
  700.     if( ! m_rct_ctrl.RCT_Config_EPSK_CodingScheme( m_pRct, MCS5 ) )
  701.     {
  702.         CalErrorHandler( WM_MF_AGE8960_SET_CODING_SCHEME_FAIL );
  703.         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  704.                               " FAIL: "+
  705.                               m_pRct->as_RCT + " < Coding scheme = MCS5"
  706.                             );
  707.         return false;
  708.     }
  709.     short s_arfcn;
  710.     E_BANDSEL band_index;
  711.     int vi_Band;
  712.     FrequencyBand eFreqBand = FrequencyBand850;
  713.     i_N_TX = -99; // TX frames
  714.     //---------------------------------------------------------------------------
  715.     while (eFreqBand < FrequencyBandCount)
  716.     {
  717.         switch (eFreqBand)
  718.         {
  719.             case FrequencyBand850:
  720.             {
  721.                 if (! IsFreqBankSupported(m_asFreqBank, eFreqBand))
  722.                 {
  723.                     eFreqBand++;
  724.                     continue;
  725.                 }
  726.                 FIRST_PCL = GSM850_FIRST_PCL;
  727.                 vi_Band = age1960_GSM850_BAND;
  728.                 band_index = BANDSEL_GSM850;
  729.                 s_arfcn = m_sARFCN_C0_GSM850;
  730.                 i_TX_level_count = RF_TX_LEVEL_2_CAL_COUNT;
  731.                 as_epsk_tx_2cal_pcl = m_as_gsm850_epsk_tx_2cal_pcl;
  732.                 as_epsk_tx_pcl = m_as_gsm850_epsk_tx_pcl;
  733.                 as_epsk_max_p = m_as_gsm850_epsk_max_p;
  734.                 as_epsk_wanted_p = m_as_gsm850_epsk_wanted_p;
  735.                 as_epsk_min_p = m_as_gsm850_epsk_min_p;
  736.                 as_epsk_c = m_as_gsm850_epsk_c;
  737.             }
  738.             break;
  739.             case FrequencyBand900:
  740.             {
  741.                 if (!IsFreqBankSupported(m_asFreqBank, eFreqBand))
  742.                 {
  743.                     eFreqBand++;
  744.                     continue;
  745.                 }
  746.                 FIRST_PCL = GSM900_FIRST_PCL;
  747.                 vi_Band = age1960_EGSM_BAND;
  748.                 band_index = BANDSEL_GSM900;
  749.                 s_arfcn = m_sARFCN_C0_GSM;
  750.                 i_TX_level_count = RF_TX_LEVEL_2_CAL_COUNT;
  751.                 as_epsk_tx_2cal_pcl = m_as_gsm900_epsk_tx_2cal_pcl;
  752.                 as_epsk_tx_pcl = m_as_gsm900_epsk_tx_pcl;
  753.                 as_epsk_max_p = m_as_gsm900_epsk_max_p;
  754.                 as_epsk_wanted_p = m_as_gsm900_epsk_wanted_p;
  755.                 as_epsk_min_p = m_as_gsm900_epsk_min_p;
  756.                 as_epsk_c = m_as_gsm900_epsk_c;
  757.             }
  758.             break;
  759.             case FrequencyBand1800:
  760.             {
  761.                 if (!IsFreqBankSupported(m_asFreqBank, eFreqBand))
  762.                 {
  763.                     eFreqBand++;
  764.                     continue;
  765.                 }
  766.                 FIRST_PCL = DCS1800_FIRST_PCL;
  767.                 vi_Band = age1960_DCS1800_BAND;
  768.                 band_index = BANDSEL_DCS1800;
  769.                 s_arfcn = m_sARFCN_C0_DCS;
  770.                 i_TX_level_count = RF_TX_LEVEL_2_CAL_COUNT;
  771.                 as_epsk_tx_2cal_pcl = m_as_dcs1800_epsk_tx_2cal_pcl;
  772.                 as_epsk_tx_pcl = m_as_dcs1800_epsk_tx_pcl;
  773.                 as_epsk_max_p = m_as_dcs1800_epsk_max_p;
  774.                 as_epsk_wanted_p = m_as_dcs1800_epsk_wanted_p;
  775.                 as_epsk_min_p = m_as_dcs1800_epsk_min_p;
  776.                 as_epsk_c = m_as_dcs1800_epsk_c;
  777.             }
  778.             break;
  779.             case FrequencyBand1900:
  780.             {
  781.                 if (!IsFreqBankSupported(m_asFreqBank, eFreqBand))
  782.                 {
  783.                     eFreqBand++;
  784.                     continue;
  785.                 }
  786.                 FIRST_PCL = PCS1900_FIRST_PCL;
  787.                 vi_Band = age1960_PCS1900_BAND;
  788.                 band_index = BANDSEL_PCS1900;
  789.                 s_arfcn = m_sARFCN_C0_PCS;
  790.                 i_TX_level_count = RF_TX_LEVEL_2_CAL_COUNT;
  791.                 as_epsk_tx_2cal_pcl = m_as_pcs1900_epsk_tx_2cal_pcl;
  792.                 as_epsk_tx_pcl = m_as_pcs1900_epsk_tx_pcl;
  793.                 as_epsk_max_p = m_as_pcs1900_epsk_max_p;
  794.                 as_epsk_wanted_p = m_as_pcs1900_epsk_wanted_p;
  795.                 as_epsk_min_p = m_as_pcs1900_epsk_min_p;
  796.                 as_epsk_c = m_as_pcs1900_epsk_c;
  797.             }
  798.             break;
  799.             default:
  800.                 assert(false);
  801.             break;
  802.         } // switch
  803.         if ( this->Terminated )
  804.         {
  805.             this->OnTerminate = neByUser;
  806.             return false;
  807.         }
  808.         log->Add("n" + DateToStr(Date()) +  " " + CurrentTimeStr() +
  809.                          " ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
  810.                        );
  811.         if (!MF_rf_apc_8psk_ptr->ApcSectionExist(m_pCal->as_IniFile.c_str(), band_index))
  812.         {
  813.             CalErrorHandler(WM_MF_RF_TX_LEVEL_INI_FAIL);
  814.             log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  815.                      " FAIL :"+
  816.                      " APC section is not in initial file: " + FreqBand_To_Str(eFreqBand)
  817.                      );
  818.             return false;
  819.         }
  820.         if(IsFreqBankSupported(  m_asFreqBank, eFreqBand))
  821.         {
  822.             if( FrequencyBand1900 == eFreqBand )
  823.             {
  824.                 if(META_Rf_SelectFrequencyBand1900_r( m_pCal->i_MainMETAHandle, 1, MF_SelectBand_cnf_cb, &MF_SelectBand_token, NULL) !=  META_SUCCESS)
  825.                 {
  826.                     CalErrorHandler( WM_MF_RF_TX_LEVEL_FAIL );
  827.                     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  828.                                   " FAIL: target < set Band1900 flag = 1"
  829.                                 );
  830.                     return false;
  831.                 }
  832.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  833.                               " target < set Band1900 flag = 1"
  834.                             );
  835.             }
  836.             else
  837.             {
  838.                 if(META_Rf_SelectFrequencyBand1900_r( m_pCal->i_MainMETAHandle, 0, MF_SelectBand_cnf_cb, &MF_SelectBand_token, NULL) !=  META_SUCCESS)
  839.                 {
  840.                     CalErrorHandler( WM_MF_RF_TX_LEVEL_FAIL );
  841.                     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  842.                                   " FAIL: target < set Band1900 flag = 0"
  843.                                 );
  844.                     return false;
  845.                 }
  846.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  847.                               " target < set Band1900 flag = 0"
  848.                             );
  849.             }
  850.             is_suspend_cal = true;
  851.             this->Suspend();
  852.             is_suspend_cal = false;
  853.         }
  854.         if( ! m_rct_ctrl.RCT_cellBand( m_pRct, vi_Band ) )
  855.         {
  856.             CalErrorHandler( WM_MF_AGE8960_SET_BAND_FAIL );
  857.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  858.                               " FAIL: "+
  859.                               m_pRct->as_RCT + " < Band = " + ViBand_To_Str( vi_Band )
  860.                             );
  861.             return false;
  862.         }
  863.         Sleep( 100 );  // wait Agilent 8960 cell band setup ready!
  864.                    // if Agilent 8960 not read, target will get error power!
  865.         if ( this->Terminated )
  866.         {
  867.             this->OnTerminate = neByUser;
  868.             return false;
  869.         }
  870.         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +  " " +
  871.                           m_pRct->as_RCT + " < Band = " + ViBand_To_Str( vi_Band )
  872.                         );
  873.         short bch_arfcn = ::Get_SeperateChannel( vi_Band, s_arfcn );
  874.         if( ! m_rct_ctrl.RCT_BCHARFCN( m_pRct, bch_arfcn) )
  875.         {
  876.             CalErrorHandler( WM_MF_AGE8960_SET_BCH_ARFCN_FAIL );
  877.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  878.                               " FAIL: "+
  879.                               m_pRct->as_RCT + " < BCH ARFCN = " + IntToStr( bch_arfcn )
  880.                     );
  881.             return false;
  882.         }
  883.         if( ! m_rct_ctrl.RCT_PDTCHARFCN( m_pRct, s_arfcn ) )
  884.         {
  885.             CalErrorHandler( WM_MF_AGE8960_SET_PDTCH_ARFCN_FAIL );
  886.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  887.                               " FAIL: "+
  888.                               m_pRct->as_RCT + " < PDTCH ARFCN = " + IntToStr( s_arfcn )
  889.                             );
  890.             return false;
  891.         }
  892.         if( this->Terminated )
  893.         {
  894.             this->OnTerminate = neByUser;
  895.             return false;
  896.         }
  897.         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +  " " +
  898.                           m_pRct->as_RCT + " < PDTCH ARFCN = " + IntToStr( s_arfcn )
  899.                         );
  900.         if( ! m_rct_ctrl.RCT_ConfigTSC( m_pRct, m_cTSC ) )
  901.         {
  902.             CalErrorHandler( WM_MF_AGE8960_SET_TSC_FAIL );
  903.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +  " " +
  904.                               "FAIL : " + m_pRct->as_RCT + " < set TSC fail."
  905.                             );
  906.             return false;
  907.         }
  908.         if ( this->Terminated )
  909.         {
  910.             this->OnTerminate = neByUser;
  911.             return false;
  912.         }
  913.         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +  " " +
  914.                           m_pRct->as_RCT + " < TSC = " + IntToStr( m_cTSC)
  915.                         );
  916.         if( ! m_rct_ctrl.RCT_EPSK_TXPowerContOff( m_pRct ) )
  917.         {
  918.             CalErrorHandler( WM_MF_AGE8960_SET_TX_POWER_CONT_OFF_FAIL );
  919.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +  " " +
  920.                               " FAIL : " + m_pRct->as_RCT + " < set TX power continuous OFF "
  921.                             );
  922.             return false;
  923.         }
  924.         if ( this->Terminated )
  925.         {
  926.             this->OnTerminate = neByUser;
  927.             return false;
  928.         }
  929.         //log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  930.         //                  " TimerCal->Enabled 8= " + IntToStr((int)frmFatcory->TimerCal->Enabled)
  931.         //                );
  932.         RestartTimerCal( WM_MF_AGE8960_CONFIG_TX_POWER_FAIL );
  933.         if( ! m_rct_ctrl.RCT_confTXPower_EPSK( m_pRct ) )
  934.         {
  935.             CalErrorHandler( WM_MF_AGE8960_CONFIG_TX_POWER_FAIL );
  936.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  937.                                   " FAIL: " + m_pRct->as_RCT + " < config TX power 1."
  938.                                 );
  939.             return false;
  940.         }
  941.         // calibration from high power to low power
  942.         // index from big to little.
  943.         // PCL string in config file from right to left.
  944.         int iRealRecursiveTimes = 0;
  945.         if( TX_SLOT_SINGLE == m_pCal->e_tx_slot )
  946.         {
  947.             for ( int N=0; N<i_TX_level_count; N++)  // DCS,PCS:16~1 or GSM:15~1
  948.             {
  949.                 log->Add( "n" + DateToStr(Date()) +  " " + CurrentTimeStr() +
  950.                           " ------------------------------------------------------------------ "
  951.                         );
  952.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  953.                           " N = " + N
  954.                         );
  955.                 if (! getAnsiStrSubItem( as_epsk_tx_2cal_pcl, N+1, DEFAULT_SEP_CHAR, as_epsk_sub_tx_2cal_pcl) )
  956.                 {
  957.                     CalErrorHandler( WM_MF_CFG_READ_FAIL );
  958.                     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  959.                               " FAIL: Read config file fail(epsk_sub_tx_2cal_pcl)."
  960.                             );
  961.                     return false;
  962.                 }
  963.                 for( iRealRecursiveTimes=0; iRealRecursiveTimes<i_TXlevelRecusiveTimes;
  964.                      iRealRecursiveTimes++) // marked by Andy Ueng for no iteration test
  965.                 {
  966.                     log->Add( "n" + DateToStr(Date()) +  " " + CurrentTimeStr() +
  967.                               " RecursiveTimes = " + IntToStr(iRealRecursiveTimes)
  968.                             );
  969.                     if( iRealRecursiveTimes == 0)
  970.                     {
  971.                         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  972.                              // " band_index = " + IntToStr(band_index) + "," +
  973.                              // " power_index = " + IntToStr(FIRST_PCL-as_sub_tx_2cal_pcl.ToInt()) + "," +
  974.                               " MF_rf_apc_8psk_ptr->ApcProfile[" + IntToStr(band_index) + "].rampData.power[" +
  975.                                 IntToStr(FIRST_PCL-as_epsk_sub_tx_2cal_pcl.ToInt()) + "] = " +
  976.                                // IntToStr(MF_rf_apc_ptr->ApcProfile[band_index].rampData.power[FIRST_PCL-as_sub_tx_2cal_pcl.ToInt()])
  977.                                 IntToStr(MF_rf_apc_8psk_ptr->Get_ApcProfilePower( band_index, FIRST_PCL-as_epsk_sub_tx_2cal_pcl.ToInt() ) )
  978.                             );
  979.                         // not support GSM400
  980.                        // PCLDacValue[band_index][N] = MF_rf_apc_ptr->ApcProfile[band_index].rampData.power[FIRST_PCL-as_sub_tx_2cal_pcl.ToInt()];
  981.                         m_usPCLDacValue_EPSK[band_index][N] = MF_rf_apc_8psk_ptr->Get_ApcProfilePower( band_index, FIRST_PCL-as_epsk_sub_tx_2cal_pcl.ToInt() );
  982.                         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  983.                                 //  " band_index = " + IntToStr(band_index) + "," +
  984.                                 //  " N = " + IntToStr(N) + "," +
  985.                                   " m_usPCLDacValue_EPSK[" +IntToStr(band_index) + "][" + IntToStr(N) + "] = " +
  986.                                     IntToStr(m_usPCLDacValue_EPSK[band_index][N])
  987.                                 );
  988.                     }
  989.                 // index start from 1
  990.                     if(! getAnsiStrSubItem( as_epsk_tx_pcl, FIRST_PCL-as_epsk_sub_tx_2cal_pcl.ToInt()+1, DEFAULT_SEP_CHAR, as_epsk_sub_tx_pcl) )
  991.                     {
  992.                         CalErrorHandler( WM_MF_CFG_READ_FAIL );
  993.                         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  994.                               " FAIL: Read config file fail(sub_tx_cal_pcl 2)."
  995.                             );
  996.                         return false;
  997.                     }
  998.                     if(! getAnsiStrSubItem( as_epsk_max_p, FIRST_PCL-as_epsk_sub_tx_2cal_pcl.ToInt()+1, DEFAULT_SEP_CHAR, as_epsk_sub_max_p) )
  999.                     {
  1000.                         CalErrorHandler( WM_MF_CFG_READ_FAIL );
  1001.                         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1002.                               " FAIL: Read config file fail(sub_max_p)."
  1003.                             );
  1004.                         return false;
  1005.                     }
  1006.                     if(! getAnsiStrSubItem( as_epsk_min_p, FIRST_PCL-as_epsk_sub_tx_2cal_pcl.ToInt()+1, DEFAULT_SEP_CHAR, as_epsk_sub_min_p) )
  1007.                     {
  1008.                         CalErrorHandler( WM_MF_CFG_READ_FAIL );
  1009.                         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1010.                               " FAIL: Read config file fail(sub_min_p)."
  1011.                             );
  1012.                         return false;
  1013.                     }
  1014.                     if(! getAnsiStrSubItem( as_epsk_wanted_p, FIRST_PCL-as_epsk_sub_tx_2cal_pcl.ToInt()+1, DEFAULT_SEP_CHAR, as_epsk_sub_wanted_p) )
  1015.                     {
  1016.                         CalErrorHandler( WM_MF_CFG_READ_FAIL );
  1017.                         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1018.                               " FAIL: Read config file fail(sub_wanted_p)."
  1019.                             );
  1020.                         return false;
  1021.                     }
  1022.                     if(! getAnsiStrSubItem( as_epsk_c, FIRST_PCL-as_epsk_sub_tx_2cal_pcl.ToInt()+1, DEFAULT_SEP_CHAR, as_epsk_sub_c) )
  1023.                     {
  1024.                         CalErrorHandler( WM_MF_CFG_READ_FAIL );
  1025.                         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1026.                               " FAIL: Read config file fail(c)."
  1027.                             );
  1028.                         return false;
  1029.                     }
  1030.                     if( ! m_rct_ctrl.RCT_PDTCHMSTxLevel( m_pRct, as_epsk_sub_tx_pcl.ToInt()) )
  1031.                     {
  1032.                         CalErrorHandler( WM_MF_AGE8960_SET_MS_TX_LEVEL_FAIL );
  1033.                         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1034.                                   " FAIL: " + m_pRct->as_RCT + " < MS TX level = " + IntToStr( as_epsk_sub_tx_pcl.ToInt())
  1035.                                 );
  1036.                         return false;
  1037.                     }
  1038.                     if( this->Terminated )
  1039.                     {
  1040.                         this->OnTerminate = neByUser;
  1041.                         return false;
  1042.                     }
  1043.                     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +  " " +
  1044.                               m_pRct->as_RCT + " < MS TX level = " + IntToStr( as_epsk_sub_tx_pcl.ToInt())
  1045.                             );
  1046.                     RestartTimerCal(WM_MF_RF_STOP_FAIL);
  1047.                     if (!MF_rf_stop.REQ_Start())
  1048.                     {
  1049.                         CalErrorHandler(WM_MF_RF_STOP_FAIL);
  1050.                         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1051.                                  " FAIL: Target < stop RF fail."
  1052.                                 );
  1053.                         return false;
  1054.                     }
  1055.                     int   pcl[4];
  1056.                     CodingScheme  cs[4];
  1057.                     cs[0]    = CodingSchemeMCS5;
  1058.                     cs[1]    = CodingSchemeMCS5;
  1059.                     cs[2]    = CodingSchemeMCS5;
  1060.                     cs[3]    = CodingSchemeMCS5;
  1061.                     pcl[0]   = as_epsk_sub_tx_pcl.ToInt();
  1062.                     pcl[1]   = as_epsk_sub_tx_pcl.ToInt();
  1063.                     pcl[2]   = as_epsk_sub_tx_pcl.ToInt();
  1064.                     pcl[3]   = as_epsk_sub_tx_pcl.ToInt();
  1065.                     S_MULTI_SLOT_TX_T multi_slot_tx;
  1066.                     multi_slot_tx.b_MultiSlotTXExSupport = m_pCal->b_MultiSlotTxExSupport;
  1067.                     multi_slot_tx.e_bandsel = band_index;
  1068.                     multi_slot_tx.req.arfcn = s_arfcn;
  1069.                     multi_slot_tx.req.bsic  = m_cTSC;
  1070.                     multi_slot_tx.req.timeSlotmask = 0x01;
  1071.                     for (int i=0; i<4; i++)
  1072.                     {
  1073.                         multi_slot_tx.req.powerLev[i] = pcl[i];
  1074.                         multi_slot_tx.req.cs[i]       = cs[i];
  1075.                     }
  1076.                     multi_slot_tx.req.ta = 0;
  1077.                     multi_slot_tx.req.frames = -99;
  1078.                     multi_slot_tx.req.dacValue = m_sDefault_value;
  1079.                     multi_slot_tx.req.pattern = NB_TX_RANDOM_WITH_TSC;
  1080.                     multi_slot_tx.req.pattern_data = 0;
  1081.                     RF_MULTI_SLOT_TX_Obj.ConfirmCallback = ::ConfirmCallback_MultiSlotTX;
  1082.                     RF_MULTI_SLOT_TX_Obj.REQ_Start(multi_slot_tx);
  1083.                     if( this->Terminated )
  1084.                     {
  1085.                         this->OnTerminate = neByUser;
  1086.                         return false;
  1087.                     }
  1088.                     #ifdef _MYDEBUG_
  1089.                         TDateTime::CurrentTime().DecodeTime(&hr, &min, &sec, &ms );
  1090.                     #endif
  1091.                     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1092.                     #ifdef _MYDEBUG_
  1093.                      ":" + AnsiString( ms ) +
  1094.                     #endif
  1095.                     " Target< TX: ARFCN = " + IntToStr( s_arfcn ) +
  1096.                     ", TSC = " + IntToStr( m_cTSC ) +
  1097.                     ", power = " + as_epsk_sub_tx_pcl +
  1098.                     ", frames = " + IntToStr(i_N_TX) +
  1099.                     ", dac value = " + IntToStr( m_sDefault_value )
  1100.                     );
  1101.                     #ifdef _MYDEBUG_
  1102.                     TDateTime::CurrentTime().DecodeTime(&hr, &min, &sec, &ms );
  1103.                     log->Add( " before suspend " + DateToStr(Date()) +  " " + CurrentTimeStr() +
  1104.                           ":" + AnsiString( ms )
  1105.                         );
  1106.                     #endif
  1107.                // log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1108.                //           " TimerCal->Enabled 7= " + IntToStr((int)frmFatcory->TimerCal->Enabled)
  1109.                //         );
  1110.                     RestartTimerCal( WM_MF_RF_TX_LEVEL_FAIL );
  1111.                     SUSPEND_CAL_THREAD
  1112.                     if( RF_MULTI_SLOT_TX_Obj.Get_ConfirmState() != METAAPP_SUCCESS )
  1113.                     {
  1114.                         CalErrorHandler( WM_MF_RF_TX_LEVEL_FAIL );
  1115.                         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1116.                                  " FAIL: Target < multislot TX fail."
  1117.                                 );
  1118.                         return false;
  1119.                     }
  1120.                     #ifdef _MYDEBUG_
  1121.                     TDateTime::CurrentTime().DecodeTime(&hr, &min, &sec, &ms );
  1122.                     log->Add( " after resume " + DateToStr(Date()) +  " " + CurrentTimeStr() +
  1123.                           ":" + AnsiString( ms )
  1124.                          );
  1125.                     #endif
  1126.                     if( this->Terminated )
  1127.                     {
  1128.                         this->OnTerminate = neByUser;
  1129.                         return false;
  1130.                     }
  1131.                     #ifdef _MYDEBUG_
  1132.                     TDateTime::CurrentTime().DecodeTime(&hr, &min, &sec, &ms );
  1133.                     log->Add( " before read TX power Q " + DateToStr(Date()) +  " " + CurrentTimeStr() +
  1134.                               ":" + AnsiString( ms )
  1135.                             );
  1136.                     #endif
  1137.                     RestartTimerCal( WM_MF_AGE8960_READ_TX_POWER_FAIL );
  1138.                     if( ! m_rct_ctrl.RCT_ReadTxPower_EPSK( m_pRct, m_virTX) )
  1139.                     {
  1140.                         CalErrorHandler( WM_MF_AGE8960_READ_TX_POWER_FAIL );
  1141.                         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1142.                                   " FAIL: " + m_pRct->as_RCT + " < read TX power 1."
  1143.                                 );
  1144.                         return false;
  1145.                     }
  1146.                     frmFatcory->DisableAllCalTimer();
  1147.                     m_dPCL_dBm_EPSK[band_index][N] = m_virTX ;
  1148.                     m_dPCL_power_EPSK[band_index][N] =  pow(10.0, m_dPCL_dBm_EPSK[band_index][N]/10.0)/1000.0;
  1149.                     #ifdef _MYDEBUG_
  1150.                     TDateTime::CurrentTime().DecodeTime(&hr, &min, &sec, &ms );
  1151.                     log->Add( " after read TX power Q " + DateToStr(Date()) +  " " + CurrentTimeStr() +
  1152.                           ":" + AnsiString( ms )
  1153.                         );
  1154.                     #endif
  1155.                     if( this->Terminated )
  1156.                     {
  1157.                         this->OnTerminate = neByUser;
  1158.                         return false;
  1159.                     }
  1160.                     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +  " " +
  1161.                               m_pRct->as_RCT + " < read TX power = "+ Double_To_AnsiString( m_virTX )
  1162.                             );
  1163.                     signed short  ss1;
  1164.                     double d1;
  1165.                     if(iRealRecursiveTimes != i_TXlevelRecusiveTimes-1) //iteration
  1166.                     {
  1167.                         if ( m_virTX > (atof(as_epsk_sub_wanted_p.c_str()) + m_dAPC_Delta) ||
  1168.                              m_virTX < (atof(as_epsk_sub_wanted_p.c_str()) - m_dAPC_Delta))
  1169.                         {
  1170.                             d1 = atof(as_epsk_sub_c.c_str()) * (atof(as_epsk_sub_wanted_p.c_str()) - m_virTX );
  1171.                             ss1 = (signed short) (d1>0) ? floor(d1+1.0): ceil(d1-1.0);
  1172.                             if ((MF_rf_apc_8psk_ptr->Get_ApcProfilePower(band_index, FIRST_PCL-as_epsk_sub_tx_2cal_pcl.ToInt() ) + ss1) <= 0 )
  1173.                             {
  1174.                                 MF_rf_apc_8psk_ptr->Set_ApcProfilePower(band_index, FIRST_PCL-as_epsk_sub_tx_2cal_pcl.ToInt(), 1);
  1175.                             }
  1176.                             else if ((MF_rf_apc_8psk_ptr->Get_ApcProfilePower(band_index, FIRST_PCL-as_epsk_sub_tx_2cal_pcl.ToInt()) + ss1) > MAX_APC_DAC)
  1177.                             {
  1178.                                 MF_rf_apc_8psk_ptr->Set_ApcProfilePower(band_index, FIRST_PCL-as_epsk_sub_tx_2cal_pcl.ToInt(), MAX_APC_DAC);
  1179.                             }
  1180.                             else
  1181.                             {
  1182.                                 MF_rf_apc_8psk_ptr->Set_ApcProfilePower( band_index, FIRST_PCL-as_epsk_sub_tx_2cal_pcl.ToInt(), MF_rf_apc_8psk_ptr->Get_ApcProfilePower( band_index, FIRST_PCL-as_epsk_sub_tx_2cal_pcl.ToInt() )+ss1 );
  1183.                             }
  1184.                             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1185.                                       " band_index = " + IntToStr(band_index) + "," +
  1186.                                       " power_index = " + IntToStr(FIRST_PCL-as_epsk_sub_tx_2cal_pcl.ToInt()) + "," +
  1187.                                       " MF_rf_apc_8psk_ptr->ApcProfile[band_index].rampData.power[power_index] = " + IntToStr(MF_rf_apc_8psk_ptr->Get_ApcProfilePower( band_index, FIRST_PCL-as_epsk_sub_tx_2cal_pcl.ToInt() ) )
  1188.                                     );
  1189.                             m_usPCLDacValue_EPSK[band_index][N] = MF_rf_apc_8psk_ptr->Get_ApcProfilePower( band_index, FIRST_PCL-as_epsk_sub_tx_2cal_pcl.ToInt() );
  1190.                             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1191.                                       " m_usPCLDacValue_EPSK[" + IntToStr(band_index) +"][" + IntToStr(N) +"] = " +
  1192.                                       IntToStr(m_usPCLDacValue_EPSK[band_index][N])
  1193.                                     );
  1194.                             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1195.                                       " new S = " +
  1196.                                       AnsiString( MF_rf_apc_8psk_ptr->Get_ApcProfilePower( band_index, FIRST_PCL-as_epsk_sub_tx_2cal_pcl.ToInt() )  )
  1197.                                     );
  1198.                             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1199.                                       " delta s = "+
  1200.                                       AnsiString( ss1 )
  1201.                                     );
  1202.                             RfSetRampApcLevel_Req  RfSetApcDac;
  1203.                             RfSetApcDac.rf_band = eFreqBand;
  1204.                             RfSetApcDac.power_level = as_epsk_sub_tx_2cal_pcl.ToInt();
  1205.                             RfSetApcDac.apc_dac = MF_rf_apc_8psk_ptr->Get_ApcProfilePower( band_index, FIRST_PCL-as_epsk_sub_tx_2cal_pcl.ToInt() );
  1206.                             MF_rf_apc_8psk_ptr->ConfirmCallback = ::ccb_set_apc_level;
  1207.                             MF_rf_apc_8psk_ptr->REQ_EPSK_SetRampApcLevel_Start( &RfSetApcDac );
  1208.                             if( this->Terminated )
  1209.                             {
  1210.                                 this->OnTerminate = neByUser;
  1211.                                 return false;
  1212.                             }
  1213.                             RestartTimerCal( WM_MF_SET_APC_DAC_FAIL );
  1214.                             is_suspend_cal = true;
  1215.                             this->Suspend();
  1216.                             is_suspend_cal = false;
  1217.                             E_METAAPP_RESULT_T state = MF_rf_apc_8psk_ptr->Get_ConfirmState();
  1218.                             if (state != METAAPP_SUCCESS)
  1219.                             {
  1220.                                 CalErrorHandler( WM_MF_SET_APC_DAC_FAIL );
  1221.                                 log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  1222.                                              " FAIL: Target< set APC level fail. PCL = "+ as_epsk_sub_tx_2cal_pcl +
  1223.                                              " APC DAC = " +  IntToStr(MF_rf_apc_8psk_ptr->Get_ApcProfilePower( band_index, FIRST_PCL-as_epsk_sub_tx_2cal_pcl.ToInt() ))  + "n"
  1224.                                             );
  1225.                                 return false;
  1226.                             }
  1227.                             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1228.                                       " Target< set APC level ok. PCL = "+ as_epsk_sub_tx_2cal_pcl + "," +
  1229.                                       " APC DAC = " +  IntToStr(MF_rf_apc_8psk_ptr->Get_ApcProfilePower( band_index, FIRST_PCL-as_epsk_sub_tx_2cal_pcl.ToInt() ))  + "n"
  1230.                                     );
  1231.                             if( this->Terminated )
  1232.                             {
  1233.                                 this->OnTerminate = neByUser;
  1234.                                 return false;
  1235.                             }
  1236.                         }
  1237.                         else
  1238.                         {
  1239.                             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1240.                                   " delta s = 0 "
  1241.                                 );
  1242.                             break; // for iRealRecursiveTimes
  1243.                         }
  1244.                     } // if no iteration
  1245.                     if( this->Terminated )
  1246.                     {
  1247.                         this->OnTerminate = neByUser;
  1248.                         return false;
  1249.                     }
  1250.                 } // for iRealRecursiveTimes
  1251.             } // for N
  1252.         } // single slot TX
  1253.         else // multi-slot TX
  1254.         {
  1255.         }
  1256.         eFreqBand++;
  1257.         if ( this->Terminated )
  1258.         {
  1259.             this->OnTerminate = neByUser;
  1260.             return false;
  1261.         }
  1262.     } // while
  1263.         log->Add( "n" + DateToStr(Date()) +  " " + CurrentTimeStr() +
  1264.              " =========== EPSK TX power control level calibration end =========== n "
  1265.            );
  1266.     RestartTimerCal(WM_MF_RF_STOP_FAIL);
  1267.     if (!MF_rf_stop.REQ_Start())
  1268.     {
  1269.         CalErrorHandler(WM_MF_RF_STOP_FAIL);
  1270.         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1271.                           " FAIL: Target < stop RF fail."
  1272.                         );
  1273.         return false;
  1274.     }
  1275.     frmFatcory->DisableAllCalTimer();
  1276.     return true;
  1277. }
  1278. //=========================================================================
  1279. bool __fastcall T_META_factory_calibration::TXPCLCal_EPSK_3cal(void)
  1280. {
  1281.     AnsiString  as_epsk_tx_pcl;
  1282.     AnsiString  as_epsk_tx_cal_pcl;
  1283.     AnsiString  as_epsk_max_p;
  1284.     AnsiString  as_epsk_wanted_p;
  1285.     AnsiString  as_epsk_min_p;
  1286.     AnsiString  as_epsk_c;
  1287.     AnsiString  as_epsk_sub_tx_pcl;
  1288.     AnsiString  as_epsk_sub_tx_cal_pcl;
  1289.     AnsiString  as_epsk_sub_max_p;
  1290.     AnsiString  as_epsk_sub_wanted_p;
  1291.     AnsiString  as_epsk_sub_min_p;
  1292.     AnsiString  as_epsk_sub_c;
  1293.     int FIRST_PCL=0;
  1294.     log->Add( "n" + DateToStr(Date()) +  " " + CurrentTimeStr() +
  1295.              " ========== EPSK TX power control level calibration begin ========== n "
  1296.            );
  1297.     if( ! m_rct_ctrl.RCT_operatingMode( m_pRct, OPERATING_MODE_EGPRS_BCH_PDTCH ) )
  1298.     {
  1299.         CalErrorHandler( WM_MF_AGE8960_SET_OPERATION_MODE_FAIL );
  1300.         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1301.                               " FAIL: "+
  1302.                               m_pRct->as_RCT + " < Operation mode = EGPRS BCH+PDTCH"
  1303.                             );
  1304.         return false;
  1305.     }
  1306.     if( ! m_rct_ctrl.RCT_Config_EPSK_CodingScheme( m_pRct, MCS5 ) )
  1307.     {
  1308.         CalErrorHandler( WM_MF_AGE8960_SET_CODING_SCHEME_FAIL );
  1309.         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1310.                               " FAIL: "+
  1311.                               m_pRct->as_RCT + " < Coding scheme = MCS5"
  1312.                             );
  1313.         return false;
  1314.     }
  1315.     short s_arfcn;
  1316.     E_BANDSEL band_index;
  1317.     int vi_Band;
  1318.     FrequencyBand eFreqBand = FrequencyBand850;
  1319.     i_N_TX = -99; // TX frames
  1320.     //---------------------------------------------------------------------------
  1321.     while (eFreqBand < FrequencyBandCount)
  1322.     {
  1323.         switch (eFreqBand)
  1324.         {
  1325.             case FrequencyBand850:
  1326.             {
  1327.                 if (!IsFreqBankSupported(m_asFreqBank, eFreqBand))
  1328.                 {
  1329.                     eFreqBand++;
  1330.                     continue;
  1331.                 }
  1332.                 FIRST_PCL = GSM850_FIRST_PCL;
  1333.                 vi_Band = age1960_GSM850_BAND;
  1334.                 band_index = BANDSEL_GSM850;
  1335.                 s_arfcn = m_sARFCN_C0_GSM850;
  1336.                 i_TX_level_count = RF_TX_LEVEL_3_CAL_COUNT;
  1337.                 as_epsk_tx_cal_pcl    = m_as_gsm850_epsk_tx_cal_pcl;
  1338.                 as_epsk_tx_pcl        = m_as_gsm850_epsk_tx_pcl;
  1339.                 as_epsk_max_p         = m_as_gsm850_epsk_max_p;
  1340.                 as_epsk_wanted_p      = m_as_gsm850_epsk_wanted_p;
  1341.                 as_epsk_min_p         = m_as_gsm850_epsk_min_p;
  1342.                 as_epsk_c             = m_as_gsm850_epsk_c;
  1343.             }
  1344.             break;
  1345.             case FrequencyBand900:
  1346.             {
  1347.                 if (!IsFreqBankSupported(m_asFreqBank, eFreqBand))
  1348.                 {
  1349.                     eFreqBand++;
  1350.                     continue;
  1351.                 }
  1352.                 FIRST_PCL = GSM900_FIRST_PCL;
  1353.                 vi_Band = age1960_EGSM_BAND;
  1354.                 band_index = BANDSEL_GSM900;
  1355.                 s_arfcn = m_sARFCN_C0_GSM;
  1356.                 i_TX_level_count = RF_TX_LEVEL_3_CAL_COUNT;
  1357.                 as_epsk_tx_cal_pcl    = m_as_gsm900_epsk_tx_cal_pcl;
  1358.                 as_epsk_tx_pcl        = m_as_gsm900_epsk_tx_pcl;
  1359.                 as_epsk_max_p         = m_as_gsm900_epsk_max_p;
  1360.                 as_epsk_wanted_p      = m_as_gsm900_epsk_wanted_p;
  1361.                 as_epsk_min_p         = m_as_gsm900_epsk_min_p;
  1362.                 as_epsk_c             = m_as_gsm900_epsk_c;
  1363.             }
  1364.             break;
  1365.             case FrequencyBand1800:
  1366.             {
  1367.                 if (!IsFreqBankSupported(m_asFreqBank, eFreqBand))
  1368.                 {
  1369.                     eFreqBand++;
  1370.                     continue;
  1371.                 }
  1372.                 FIRST_PCL = DCS1800_FIRST_PCL;
  1373.                 vi_Band = age1960_DCS1800_BAND;
  1374.                 band_index = BANDSEL_DCS1800;
  1375.                 s_arfcn = m_sARFCN_C0_DCS;
  1376.                 i_TX_level_count = RF_TX_LEVEL_3_CAL_COUNT;
  1377.                 as_epsk_tx_cal_pcl    = m_as_dcs1800_epsk_tx_cal_pcl;
  1378.                 as_epsk_tx_pcl        = m_as_dcs1800_epsk_tx_pcl;
  1379.                 as_epsk_max_p         = m_as_dcs1800_epsk_max_p;
  1380.                 as_epsk_wanted_p      = m_as_dcs1800_epsk_wanted_p;
  1381.                 as_epsk_min_p         = m_as_dcs1800_epsk_min_p;
  1382.                 as_epsk_c             = m_as_dcs1800_epsk_c;
  1383.             }
  1384.             break;
  1385.             case FrequencyBand1900:
  1386.             {
  1387.                 if (!IsFreqBankSupported(m_asFreqBank, eFreqBand))
  1388.                 {
  1389.                     eFreqBand++;
  1390.                     continue;
  1391.                 }
  1392.                 FIRST_PCL = PCS1900_FIRST_PCL;
  1393.                 vi_Band = age1960_PCS1900_BAND;
  1394.                 band_index = BANDSEL_PCS1900;
  1395.                 s_arfcn = m_sARFCN_C0_PCS;
  1396.                 i_TX_level_count = RF_TX_LEVEL_3_CAL_COUNT;
  1397.                 as_epsk_tx_cal_pcl    = m_as_pcs1900_epsk_tx_cal_pcl;
  1398.                 as_epsk_tx_pcl        = m_as_pcs1900_epsk_tx_pcl;
  1399.                 as_epsk_max_p         = m_as_pcs1900_epsk_max_p;
  1400.                 as_epsk_wanted_p      = m_as_pcs1900_epsk_wanted_p;
  1401.                 as_epsk_min_p         = m_as_pcs1900_epsk_min_p;
  1402.                 as_epsk_c             = m_as_pcs1900_epsk_c;
  1403.             }
  1404.             break;
  1405.             default:
  1406.                 assert(false);
  1407.             break;
  1408.         } // switch
  1409.         if( this->Terminated )
  1410.         {
  1411.             this->OnTerminate = neByUser;
  1412.             return false;
  1413.         }
  1414.         log->Add( "n" + DateToStr(Date()) +  " " + CurrentTimeStr() +
  1415.                          " ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
  1416.                        );
  1417.         if (!MF_rf_apc_8psk_ptr->ApcSectionExist(m_pCal->as_IniFile.c_str(), band_index))
  1418.         {
  1419.             CalErrorHandler(WM_MF_RF_TX_LEVEL_INI_FAIL);
  1420.             log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  1421.                      " FAIL :"+
  1422.                      " APC section is not in initial file: " + FreqBand_To_Str(eFreqBand)
  1423.                      );
  1424.             return false;
  1425.         }
  1426.         if (IsFreqBankSupported(m_asFreqBank, eFreqBand))
  1427.         {
  1428.             if(eFreqBand == FrequencyBand1900)
  1429.             {
  1430.                 if(META_Rf_SelectFrequencyBand1900_r( m_pCal->i_MainMETAHandle, 1, MF_SelectBand_cnf_cb, &MF_SelectBand_token, NULL) !=  META_SUCCESS)
  1431.                 {
  1432.                     CalErrorHandler( WM_MF_RF_TX_LEVEL_FAIL );
  1433.                     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1434.                                   " FAIL: target < target < set Band1900 flag = 1"
  1435.                                 );
  1436.                     return false;
  1437.                 }
  1438.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1439.                               " target < set Band1900 flag = 1"
  1440.                             );
  1441.             }
  1442.             else
  1443.             {
  1444.                 if(META_Rf_SelectFrequencyBand1900_r( m_pCal->i_MainMETAHandle, 0, MF_SelectBand_cnf_cb, &MF_SelectBand_token, NULL) !=  META_SUCCESS)
  1445.                 {
  1446.                     CalErrorHandler( WM_MF_RF_TX_LEVEL_FAIL );
  1447.                     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1448.                                   " FAIL: target < set Band1900 flag = 0"
  1449.                                 );
  1450.                     return false;
  1451.                 }
  1452.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1453.                               " target < set Band1900 flag = 0"
  1454.                             );
  1455.             }
  1456.             is_suspend_cal = true;
  1457.             this->Suspend();
  1458.             is_suspend_cal = false;
  1459.         }
  1460.         if( ! m_rct_ctrl.RCT_cellBand( m_pRct, vi_Band ) )
  1461.         {
  1462.             CalErrorHandler( WM_MF_AGE8960_SET_BAND_FAIL );
  1463.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1464.                               " FAIL: "+
  1465.                               m_pRct->as_RCT + " < Band = " + ViBand_To_Str( vi_Band )
  1466.                             );
  1467.             return false;
  1468.         }
  1469.   #ifdef _MYDEBUG_
  1470.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1471.                       " Sleep 100 " + AnsiString(__FILE__)
  1472.                     );
  1473.   #endif
  1474.         Sleep( 100 );  // wait Agilent 8960 cell band setup ready!
  1475.                    // if Agilent 8960 not read, target will get error power!
  1476.         if( this->Terminated )
  1477.         {
  1478.             this->OnTerminate = neByUser;
  1479.             return false;
  1480.         }
  1481.         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +  " " +
  1482.                           m_pRct->as_RCT + " < Band = " + ViBand_To_Str( vi_Band )
  1483.                         );
  1484.         short bch_arfcn = ::Get_SeperateChannel( vi_Band, s_arfcn );
  1485.         if( ! m_rct_ctrl.RCT_BCHARFCN( m_pRct, bch_arfcn) )
  1486.         {
  1487.             CalErrorHandler( WM_MF_AGE8960_SET_BCH_ARFCN_FAIL );
  1488.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1489.                               " FAIL: "+
  1490.                               m_pRct->as_RCT + " < BCH ARFCN = " + IntToStr( bch_arfcn )
  1491.                     );
  1492.             return false;
  1493.         }
  1494.         if( ! m_rct_ctrl.RCT_PDTCHARFCN( m_pRct, s_arfcn ) )
  1495.         {
  1496.             CalErrorHandler( WM_MF_AGE8960_SET_PDTCH_ARFCN_FAIL );
  1497.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1498.                               " FAIL: "+
  1499.                               m_pRct->as_RCT + " < PDTCH ARFCN = " + IntToStr( s_arfcn )
  1500.                             );
  1501.             return false;
  1502.         }
  1503.         if( this->Terminated )
  1504.         {
  1505.             this->OnTerminate = neByUser;
  1506.             return false;
  1507.         }
  1508.         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +  " " +
  1509.                           m_pRct->as_RCT + " < PDTCH ARFCN = " + IntToStr( s_arfcn )
  1510.                         );
  1511.         if( ! m_rct_ctrl.RCT_ConfigTSC( m_pRct, m_cTSC ) )
  1512.         {
  1513.             CalErrorHandler( WM_MF_AGE8960_SET_TSC_FAIL );
  1514.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +  " " +
  1515.                               "FAIL: " + m_pRct->as_RCT + " < set TSC fail."
  1516.                             );
  1517.             return false;
  1518.         }
  1519.         if ( this->Terminated )
  1520.         {
  1521.             this->OnTerminate = neByUser;
  1522.             return false;
  1523.         }
  1524.         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +  " " +
  1525.                       m_pRct->as_RCT + " < TSC = " + IntToStr( m_cTSC)
  1526.                     );
  1527.         if( ! m_rct_ctrl.RCT_EPSK_TXPowerContOff( m_pRct ) )
  1528.         {
  1529.             CalErrorHandler( WM_MF_AGE8960_SET_TX_POWER_CONT_OFF_FAIL );
  1530.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1531.                               " FAIL: " + m_pRct->as_RCT + " < set TX power continuous OFF "
  1532.                             );
  1533.             return false;
  1534.         }
  1535.         if ( this->Terminated )
  1536.         {
  1537.             this->OnTerminate = neByUser;
  1538.             return false;
  1539.         }
  1540.        // log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1541.        //                   " TimerCal->Enabled 8= " + IntToStr((int)frmFatcory->TimerCal->Enabled)
  1542.        //                 );
  1543.         RestartTimerCal( WM_MF_AGE8960_CONFIG_TX_POWER_FAIL );
  1544.         if( ! m_rct_ctrl.RCT_confTXPower_EPSK( m_pRct ) )
  1545.         {
  1546.             CalErrorHandler( WM_MF_AGE8960_CONFIG_TX_POWER_FAIL );
  1547.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1548.                                   " FAIL: " + m_pRct->as_RCT + " < config TX power 1."
  1549.                                 );
  1550.             return false;
  1551.         }
  1552.         // calibration from high power to low power
  1553.         // index from big to little.
  1554.         // PCL string in config file from right to left.
  1555.         int iRealRecursiveTimes = 0;
  1556.         if( TX_SLOT_SINGLE == m_pCal->e_tx_slot )
  1557.         {
  1558.             for ( int N=0; N<i_TX_level_count; N++)  // DCS,PCS:16~1 or GSM:15~1
  1559.             {
  1560.                 log->Add( "n" + DateToStr(Date()) +  " " + CurrentTimeStr() +
  1561.                           " ------------------------------------------------------------------ "
  1562.                         );
  1563.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1564.                           " N = " + N
  1565.                         );
  1566.                 if(! getAnsiStrSubItem( as_epsk_tx_cal_pcl, N+1, DEFAULT_SEP_CHAR, as_epsk_sub_tx_cal_pcl) )
  1567.                 {
  1568.                     CalErrorHandler( WM_MF_CFG_READ_FAIL );
  1569.                     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1570.                               " FAIL: Read config file fail(epsk_sub_tx_cal_pcl)."
  1571.                             );
  1572.                     return false;
  1573.                 }
  1574.                 for( iRealRecursiveTimes=0; iRealRecursiveTimes<i_TXlevelRecusiveTimes;
  1575.                      iRealRecursiveTimes++) // marked by Andy Ueng for no iteration test
  1576.                 {
  1577.                     log->Add( "n" + DateToStr(Date()) +  " " + CurrentTimeStr() +
  1578.                           " RecursiveTimes = " + IntToStr(iRealRecursiveTimes)
  1579.                         );
  1580.                     if( iRealRecursiveTimes == 0)
  1581.                     {
  1582.                         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1583.                               " band_index = " + IntToStr(band_index) + "," +
  1584.                               " power_index = " + IntToStr(FIRST_PCL-as_epsk_sub_tx_cal_pcl.ToInt()) + "," +
  1585.                               " MF_rf_apc_8psk_ptr->ApcProfile[band_index].rampData.power[power_index] = " + IntToStr(MF_rf_apc_8psk_ptr->Get_ApcProfilePower( band_index, FIRST_PCL-as_epsk_sub_tx_cal_pcl.ToInt() ))
  1586.                             );
  1587.                         m_usPCLDacValue_EPSK[band_index][N] = MF_rf_apc_8psk_ptr->Get_ApcProfilePower( band_index, FIRST_PCL-as_epsk_sub_tx_cal_pcl.ToInt() );
  1588.                         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1589.                               " band_index = " + IntToStr(band_index) + "," +
  1590.                               " N = " + IntToStr(N) + "," +
  1591.                               " m_usPCLDacValue_EPSK[band_index][N] = " + IntToStr(m_usPCLDacValue_EPSK[band_index][N])
  1592.                             );
  1593.                         if( ! MF_rf_apc_ptr->Get_RealApcDcOffset( m_pCal->b_TADOSupport, band_index, as_epsk_sub_tx_cal_pcl.ToInt(), m_iApcDcOffset ) )
  1594.                         {
  1595.                             CalErrorHandler( WM_MF_RF_TX_LEVEL_FAIL );
  1596.                             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1597.                                       " FAIL: Get APC DC offset " +
  1598.                                       " TADO support = " + IntToStr( m_pCal->b_TADOSupport ) +
  1599.                                       " eFreqBand = " + IntToStr( eFreqBand ) +
  1600.                                       " pcl = " + as_epsk_sub_tx_cal_pcl
  1601.                                     );
  1602.                             return false;
  1603.                         }
  1604.                         m_dV_set_EPSK[band_index][N] = (m_iApcDcOffset + m_usPCLDacValue_EPSK[band_index][N]) / 1024.0 * 2.8 * 15.0 / 25.0;
  1605.                         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1606.                                   " band_index = " + IntToStr(band_index) + "," +
  1607.                                   " N  = " + IntToStr(N) + "," +
  1608.                                   " m_dV_set_EPSK[band_index][N] = " + Double_To_AnsiString(m_dV_set_EPSK[band_index][N])
  1609.                                 );
  1610.                     }
  1611.                     if(! getAnsiStrSubItem( as_epsk_tx_pcl, FIRST_PCL-as_epsk_sub_tx_cal_pcl.ToInt()+1, DEFAULT_SEP_CHAR, as_epsk_sub_tx_pcl) )
  1612.                     {
  1613.                         CalErrorHandler( WM_MF_CFG_READ_FAIL );
  1614.                         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1615.                               " FAIL: Read config file fail(sub_tx_cal_pcl 2)."
  1616.                             );
  1617.                         return false;
  1618.                     }
  1619.                     if(! getAnsiStrSubItem( as_epsk_max_p, FIRST_PCL-as_epsk_sub_tx_cal_pcl.ToInt()+1, DEFAULT_SEP_CHAR, as_epsk_sub_max_p) )
  1620.                     {
  1621.                         CalErrorHandler( WM_MF_CFG_READ_FAIL );
  1622.                         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1623.                               " FAIL: Read config file fail(sub_max_p)."
  1624.                             );
  1625.                         return false;
  1626.                     }
  1627.                     if(! getAnsiStrSubItem( as_epsk_min_p, FIRST_PCL-as_epsk_sub_tx_cal_pcl.ToInt()+1, DEFAULT_SEP_CHAR, as_epsk_sub_min_p) )
  1628.                     {
  1629.                         CalErrorHandler( WM_MF_CFG_READ_FAIL );
  1630.                         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1631.                               " FAIL: Read config file fail(sub_min_p)."
  1632.                             );
  1633.                         return false;
  1634.                     }
  1635.                     if(! getAnsiStrSubItem( as_epsk_wanted_p, FIRST_PCL-as_epsk_sub_tx_cal_pcl.ToInt()+1, DEFAULT_SEP_CHAR, as_epsk_sub_wanted_p) )
  1636.                     {
  1637.                         CalErrorHandler( WM_MF_CFG_READ_FAIL );
  1638.                         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1639.                               " FAIL: Read config file fail(sub_wanted_p)."
  1640.                             );
  1641.                         return false;
  1642.                     }
  1643.                     if(! getAnsiStrSubItem( as_epsk_c, FIRST_PCL-as_epsk_sub_tx_cal_pcl.ToInt()+1, DEFAULT_SEP_CHAR, as_epsk_sub_c) )
  1644.                     {
  1645.                         CalErrorHandler( WM_MF_CFG_READ_FAIL );
  1646.                         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1647.                                   " FAIL: Read config file fail(c)."
  1648.                                 );
  1649.                         return false;
  1650.                     }
  1651.                     if( this->Terminated )
  1652.                     {
  1653.                         this->OnTerminate = neByUser;
  1654.                         return false;
  1655.                     }
  1656.                     if( ! m_rct_ctrl.RCT_PDTCHMSTxLevel( m_pRct, as_epsk_sub_tx_pcl.ToInt()) )
  1657.                     {
  1658.                         CalErrorHandler( WM_MF_AGE8960_SET_MS_TX_LEVEL_FAIL );
  1659.                         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1660.                                   " FAIL: " + m_pRct->as_RCT + " < MS TX level = " + IntToStr( as_epsk_sub_tx_pcl.ToInt())
  1661.                                 );
  1662.                         return false;
  1663.                     }
  1664.                     if ( this->Terminated )
  1665.                     {
  1666.                         this->OnTerminate = neByUser;
  1667.                         return false;
  1668.                     }
  1669.                     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +  " " +
  1670.                               m_pRct->as_RCT + " < MS TX level = " + IntToStr( as_epsk_sub_tx_pcl.ToInt())
  1671.                             );
  1672.                     RestartTimerCal(WM_MF_RF_STOP_FAIL);
  1673.                     if (!MF_rf_stop.REQ_Start())
  1674.                     {
  1675.                         CalErrorHandler(WM_MF_RF_STOP_FAIL);
  1676.                         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1677.                                   " FAIL: Target < stop RF fail."
  1678.                                 );
  1679.                         return false;
  1680.                     }
  1681.                     int   pcl[4];
  1682.                     CodingScheme cs[4];
  1683.                     cs[0]    = CodingSchemeMCS5;
  1684.                     cs[1]    = CodingSchemeMCS5;
  1685.                     cs[2]    = CodingSchemeMCS5;
  1686.                     cs[3]    = CodingSchemeMCS5;
  1687.                     pcl[0]   = as_epsk_sub_tx_pcl.ToInt();
  1688.                     pcl[1]   = as_epsk_sub_tx_pcl.ToInt();
  1689.                     pcl[2]   = as_epsk_sub_tx_pcl.ToInt();
  1690.                     pcl[3]   = as_epsk_sub_tx_pcl.ToInt();
  1691.                     S_MULTI_SLOT_TX_T multi_slot_tx;
  1692.                     multi_slot_tx.b_MultiSlotTXExSupport = m_pCal->b_MultiSlotTxExSupport;
  1693.                     multi_slot_tx.e_bandsel = band_index;
  1694.                     multi_slot_tx.req.arfcn = s_arfcn;
  1695.                     multi_slot_tx.req.bsic  = m_cTSC;
  1696.                     multi_slot_tx.req.timeSlotmask = 0x01;
  1697.                     for (int i=0; i<4; i++)
  1698.                     {
  1699.                         multi_slot_tx.req.powerLev[i] = pcl[i];
  1700.                         multi_slot_tx.req.cs[i]       = cs[i];
  1701.                     }
  1702.                     multi_slot_tx.req.ta = 0;
  1703.                     multi_slot_tx.req.frames = -99;
  1704.                     multi_slot_tx.req.dacValue = m_sDefault_value;
  1705.                     multi_slot_tx.req.pattern = NB_TX_RANDOM_WITH_TSC;
  1706.                     multi_slot_tx.req.pattern_data = 0;
  1707.                     RF_MULTI_SLOT_TX_Obj.ConfirmCallback = ::ConfirmCallback_MultiSlotTX;
  1708.                     RF_MULTI_SLOT_TX_Obj.REQ_Start(multi_slot_tx);
  1709.                     if( this->Terminated )
  1710.                     {
  1711.                         this->OnTerminate = neByUser;
  1712.                         return false;
  1713.                     }
  1714.                     #ifdef _MYDEBUG_
  1715.                         TDateTime::CurrentTime().DecodeTime(&hr, &min, &sec, &ms );
  1716.                     #endif
  1717.                     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1718.                     #ifdef _MYDEBUG_
  1719.                     ":" + AnsiString( ms ) +
  1720.                     #endif
  1721.                          " Target< TX: ARFCN = " + IntToStr( s_arfcn ) +
  1722.                          ", TSC = " + IntToStr( m_cTSC ) +
  1723.                          ", power = " + as_epsk_sub_tx_pcl +
  1724.                          ", frames = " + IntToStr(i_N_TX) +
  1725.                          ", dac value = " + IntToStr( m_sDefault_value )
  1726.                     );
  1727.                     if( this->Terminated )
  1728.                     {
  1729.                         this->OnTerminate = neByUser;
  1730.                         return false;
  1731.                     }
  1732.                     #ifdef _MYDEBUG_
  1733.                     TDateTime::CurrentTime().DecodeTime(&hr, &min, &sec, &ms );
  1734.                     log->Add( " before suspend " + DateToStr(Date()) +  " " + CurrentTimeStr() +
  1735.                               ":" + AnsiString( ms )
  1736.                             );
  1737.                     #endif
  1738.                     //log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1739.                     //          " TimerCal->Enabled 7= " + IntToStr((int)frmFatcory->TimerCal->Enabled)
  1740.                     //        );
  1741.                     RestartTimerCal( WM_MF_RF_TX_LEVEL_FAIL );
  1742.                     SUSPEND_CAL_THREAD
  1743.                     if( RF_MULTI_SLOT_TX_Obj.Get_ConfirmState() != METAAPP_SUCCESS )
  1744.                     {
  1745.                         CalErrorHandler( WM_MF_RF_TX_LEVEL_FAIL );
  1746.                         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1747.                                   " FAIL: Target < multislot TX fail."
  1748.                                 );
  1749.                         return false;
  1750.                     }
  1751.                     #ifdef _MYDEBUG_
  1752.                     TDateTime::CurrentTime().DecodeTime(&hr, &min, &sec, &ms );
  1753.                     log->Add( " after resume " + DateToStr(Date()) +  " " + CurrentTimeStr() +
  1754.                           ":" + AnsiString( ms )
  1755.                          );
  1756.                     #endif
  1757.                     if( this->Terminated )
  1758.                     {
  1759.                         this->OnTerminate = neByUser;
  1760.                         return false;
  1761.                     }
  1762.                     #ifdef _MYDEBUG_
  1763.                     TDateTime::CurrentTime().DecodeTime(&hr, &min, &sec, &ms );
  1764.                     log->Add( " before read TX power Q " + DateToStr(Date()) +  " " + CurrentTimeStr() +
  1765.                               ":" + AnsiString( ms )
  1766.                             );
  1767.                     #endif
  1768.                     RestartTimerCal( WM_MF_AGE8960_READ_TX_POWER_FAIL );
  1769.                     if( ! m_rct_ctrl.RCT_ReadTxPower_EPSK( m_pRct, m_virTX ) )
  1770.                     {
  1771.                         CalErrorHandler( WM_MF_AGE8960_READ_TX_POWER_FAIL );
  1772.                         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1773.                                   " FAIL: " + m_pRct->as_RCT + " < read TX power 1."
  1774.                                 );
  1775.                         return false;
  1776.                     }
  1777.                     frmFatcory->DisableAllCalTimer();
  1778.                     m_dPCL_dBm_EPSK[band_index][N] = m_virTX ;
  1779.                     m_dPCL_power_EPSK[band_index][N] =  pow(10.0, m_dPCL_dBm_EPSK[band_index][N]/10.0)/1000.0;
  1780.                     #ifdef _MYDEBUG_
  1781.                     TDateTime::CurrentTime().DecodeTime(&hr, &min, &sec, &ms );
  1782.                     log->Add( " after read TX power Q " + DateToStr(Date()) +  " " + CurrentTimeStr() +
  1783.                           ":" + AnsiString( ms )
  1784.                         );
  1785.                     #endif
  1786.                     if( this->Terminated )
  1787.                     {
  1788.                         this->OnTerminate = neByUser;
  1789.                         return false;
  1790.                     }
  1791.                     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +  " " +
  1792.                               m_pRct->as_RCT + " < read TX power = "+ Double_To_AnsiString( m_virTX )
  1793.                             );
  1794.                     signed short  ss1;
  1795.                     double d1;
  1796.                     if(iRealRecursiveTimes != i_TXlevelRecusiveTimes-1) //iteration
  1797.                     {
  1798.                         if ( m_virTX > (atof(as_epsk_sub_wanted_p.c_str()) + m_dAPC_Delta) ||
  1799.                              m_virTX < (atof(as_epsk_sub_wanted_p.c_str()) - m_dAPC_Delta))
  1800.                         {
  1801.                             d1 = atof(as_epsk_sub_c.c_str()) * (atof(as_epsk_sub_wanted_p.c_str()) - m_virTX );
  1802.                             // modified by Andy Ueng for always increment 1
  1803.                             //  ss1 = (signed short) (d1>0) ? floor(d1+0.5): ceil(d1-0.5);  // to round up or down
  1804.                             ss1 = (signed short) (d1>0) ? floor(d1+1.0): ceil(d1-1.0);
  1805.                             // end of modified
  1806. //                          MF_rf_level_ramp_struct.rampData[eFreqBand].power[N] += ss1;
  1807.          //                 MF_rf_apc_ptr->ApcProfile[band_index].rampData[0].power[N] += ss1;
  1808.                       //    if( MF_rf_apc_ptr->ApcProfile[band_index].rampData.power[FIRST_PCL-as_sub_tx_cal_pcl.ToInt()] + ss1 <= 0 )
  1809.                             if ((MF_rf_apc_8psk_ptr->Get_ApcProfilePower(band_index, FIRST_PCL-as_epsk_sub_tx_cal_pcl.ToInt()) + ss1) <= 0)
  1810.                             {
  1811.                                 MF_rf_apc_8psk_ptr->Set_ApcProfilePower(band_index, FIRST_PCL-as_epsk_sub_tx_cal_pcl.ToInt(), 1 );
  1812.                             }
  1813.                             else if ((MF_rf_apc_8psk_ptr->Get_ApcProfilePower(band_index, FIRST_PCL-as_epsk_sub_tx_cal_pcl.ToInt()) + ss1) > MAX_APC_DAC)
  1814.                             {
  1815.                                 MF_rf_apc_8psk_ptr->Set_ApcProfilePower(band_index, FIRST_PCL-as_epsk_sub_tx_cal_pcl.ToInt(), MAX_APC_DAC);
  1816.                             }
  1817.                             else
  1818.                             {
  1819.                                 MF_rf_apc_8psk_ptr->Set_ApcProfilePower( band_index, FIRST_PCL-as_epsk_sub_tx_cal_pcl.ToInt(), MF_rf_apc_8psk_ptr->Get_ApcProfilePower(band_index, FIRST_PCL-as_epsk_sub_tx_cal_pcl.ToInt()) + ss1 );
  1820.                             }
  1821.                             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1822.                                   " band_index = " + IntToStr(band_index) + "," +
  1823.                                   " power_index = " + IntToStr(FIRST_PCL-as_epsk_sub_tx_cal_pcl.ToInt()) + "," +
  1824.                                   " MF_rf_apc_8psk_ptr->ApcProfile[band_index].rampData.power[power_index] = " + IntToStr(MF_rf_apc_8psk_ptr->Get_ApcProfilePower(band_index, FIRST_PCL-as_epsk_sub_tx_cal_pcl.ToInt()))
  1825.                                 );
  1826.                             m_usPCLDacValue_EPSK[band_index][N] = MF_rf_apc_8psk_ptr->Get_ApcProfilePower( band_index, FIRST_PCL-as_epsk_sub_tx_cal_pcl.ToInt() );
  1827.                             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1828.                                   " band_index = " + IntToStr(band_index) + "," +
  1829.                                   " N = " + IntToStr(N) + "," +
  1830.                                   " m_usPCLDacValue_EPSK[band_index][N] = " + IntToStr(m_usPCLDacValue_EPSK[band_index][N])
  1831.                                 );
  1832.                             if( ! MF_rf_apc_ptr->Get_RealApcDcOffset( m_pCal->b_TADOSupport, band_index, as_epsk_sub_tx_cal_pcl.ToInt(), m_iApcDcOffset ) )
  1833.                             {
  1834.                                 CalErrorHandler( WM_MF_RF_TX_LEVEL_FAIL );
  1835.                                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +