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

MTK

开发平台:

C++ Builder

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