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

MTK

开发平台:

C++ Builder

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