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

MTK

开发平台:

C++ Builder

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