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

MTK

开发平台:

C++ Builder

  1. /*****************************************************************************
  2. *  Copyright Statement:
  3. *  --------------------
  4. *  This software is protected by Copyright and the information contained
  5. *  herein is confidential. The software may not be copied and the information
  6. *  contained herein may not be used or disclosed except with the written
  7. *  permission of MediaTek Inc. (C) 2005
  8. *
  9. *  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  10. *  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
  11. *  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
  12. *  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
  13. *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
  14. *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
  15. *  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
  16. *  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
  17. *  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
  18. *  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
  19. *  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
  20. *  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
  21. *
  22. *  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
  23. *  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
  24. *  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
  25. *  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
  26. *  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
  27. *
  28. *  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
  29. *  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
  30. *  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
  31. *  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
  32. *  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
  33. *
  34. *****************************************************************************/
  35. /*****************************************************************************
  36.  *
  37.  * Filename:
  38.  * ---------
  39.  *   T_TXPCL_RFMD3140.cpp
  40.  *
  41.  * Project:
  42.  * --------
  43.  *   Maui META APP
  44.  *
  45.  * Description:
  46.  * ------------
  47.  *  TX PCL calibration RFMD3140 source
  48.  *
  49.  * Author:
  50.  * -------
  51.  *  Andy Ueng (mtk00490)
  52.  *
  53.  *============================================================================
  54.  *             HISTORY
  55.  * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  56.  *------------------------------------------------------------------------------
  57.  * $Revision$
  58.  * $Modtime$
  59.  * $Log$
  60.  *
  61.  *------------------------------------------------------------------------------
  62.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  63.  *============================================================================
  64. ****************************************************************************/
  65. #include <assert.h>
  66. #include <math.h>
  67. #pragma hdrstop
  68. #ifndef _T_META_FACTORY_CALIBRATION_H_
  69. #include "T_META_factory_calibration.H"
  70. #endif
  71. #ifndef _APCCAL_COMMON_H_
  72. #include "apccal_common.h"
  73. #endif
  74. #ifndef  _RF_APC_H_
  75. #include "rf_apc.h"
  76. #endif
  77. #ifndef _META_FACTORY_RF_CB_H_
  78. #include "meta_factory_rf_cb.h"
  79. #endif
  80. // form
  81. #ifndef _META_FACTORY_H_
  82. #include "META_Factory.h"
  83. #endif
  84. // equipment
  85. #ifndef _AGE1968A_H_
  86. #include "age1968a.h"
  87. #endif
  88. // callback
  89. #ifndef _META_FACTORY_NVRAM_CB_H_
  90. #include "meta_factory_nvram_cb.h"
  91. #endif
  92. // misc
  93. #ifndef  _BAND_UTILS_H_
  94. #include "band_utils.h"
  95. #endif
  96. #ifndef  _TIME_UTILS_H_
  97. #include "time_utils.h"
  98. #endif
  99. #ifndef  _FT_UTILS_H_
  100. #include "ft_utils.h"
  101. #endif
  102. //----------------------------------------------------------------------------
  103. extern CRFAPC*  MF_rf_apc_ptr;
  104. extern RfNbtx_Req *MF_rf_tx_level_req;
  105. extern bool MF_rf_tx_level_cnf;
  106. extern bool  is_suspend_cal; // in T_META_factory_calibration.cpp
  107. // equipment
  108. extern CMU_VAR cmu;
  109. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  110. /////////////////////////////     RFMD   3140          ///////////////////////
  111. //---------------------------------------------------------------------------
  112. //---------------------------------------------------------------------------
  113. ///////////////////////////////////////////////////////////////////////////////
  114. //////////////          3PCLEvaluateDac()                        //////////////
  115. ///////////////////////////////////////////////////////////////////////////////
  116. bool __fastcall T_META_factory_calibration::TXPCLCal_RFMD3140_3PCLEvalDac( void )
  117. {
  118.     AnsiString  as_wanted_p;
  119.     AnsiString  as_correction;
  120.     AnsiString  as_tx_pcl;
  121.     AnsiString  as_sub_tx_pcl;
  122.     AnsiString  as_sub_wanted_p;
  123.     AnsiString  as_sub_correction;
  124.         log->Add( "n" +DateToStr(Date()) +  " " + CurrentTimeStr() +
  125.                   " =================== Evaluate PCL DAC value begin =================== "
  126.                 );
  127.         // calculate m_dRload_high;
  128.         //int i;
  129.         double Rload_high_temp1, Rload_high_temp2;
  130.         //real_support_band_num = cfg->getFreqBankNum( m_asFreqBank);
  131.        // log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  132.        //           " real_support_band_num = " + IntToStr(real_support_band_num) + "n"
  133.        //         );
  134.          // calculate Vset DAC value
  135.         FrequencyBand eFreqBand = FrequencyBand850;
  136.         while (eFreqBand < FrequencyBandCount) // only for 900, 1800, 1900
  137.         {
  138.             switch (eFreqBand)
  139.             {
  140.                 case FrequencyBand850:
  141.                 {
  142.                     if (!IsFreqBankSupported(m_asFreqBank, eFreqBand))
  143.                     {
  144.                         eFreqBand++;
  145.                         continue;
  146.                     }
  147.                 }
  148.                 break;
  149.                 case FrequencyBand900:
  150.                 {
  151.                     if (!IsFreqBankSupported(m_asFreqBank, eFreqBand))
  152.                     {
  153.                         eFreqBand++;
  154.                         continue;
  155.                     }
  156.                 }
  157.                 break;
  158.                 case FrequencyBand1800:
  159.                 {
  160.                     if (!IsFreqBankSupported(m_asFreqBank, eFreqBand))
  161.                     {
  162.                         eFreqBand++;
  163.                         continue;
  164.                     }
  165.                 }
  166.                 break;
  167.                 case FrequencyBand1900:
  168.                 {
  169.                     if (!IsFreqBankSupported(m_asFreqBank, eFreqBand))
  170.                     {
  171.                         eFreqBand++;
  172.                         continue;
  173.                     }
  174.                 }
  175.                 break;
  176.                 default:
  177.                 {
  178.                     assert(false);
  179.                 }    
  180.                 break;
  181.             } // switch
  182.             E_BANDSEL band_index = FreqBand_To_BandIdx(eFreqBand);
  183.        // for(i=0; i<real_support_band_num; i++)
  184.        // {
  185.             if(m_dV_set[band_index][V_SET_HIGH_INDEX] >= 0 && m_dV_set[band_index][V_SET_MID_INDEX]>=0)
  186.             {
  187.                 Rload_high_temp1 = (8.0/3.0/sqrt(2)*(m_dV_set[band_index][V_SET_HIGH_INDEX]-m_dV_set[band_index][V_SET_MID_INDEX]));
  188.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  189.                           " band_index = " + IntToStr(band_index) + "," +
  190.                           " m_dV_set[band_index][V_SET_HIGH_INDEX] = " + Double_To_AnsiString(m_dV_set[band_index][V_SET_HIGH_INDEX]) + "n" +
  191.                           "                               "  +
  192.                           " m_dV_set[band_index][V_SET_MID_INDEX] = " + Double_To_AnsiString(m_dV_set[band_index][V_SET_MID_INDEX]) + "n" +
  193.                           "                               "  +
  194.                           " Rload_high_temp1 = " + Double_To_AnsiString(Rload_high_temp1));
  195.             }
  196.             else if(m_dV_set[band_index][V_SET_HIGH_INDEX] < 0)
  197.             {
  198.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  199.                           " FAIL : m_dV_set[band_index][V_SET_HIGH_INDEX] < 0"
  200.                         );
  201.                 return false;
  202.             }
  203.             else
  204.             {
  205.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  206.                           " FAIL : m_dV_set[band_index][V_SET_MID_INDEX] < 0"
  207.                         );
  208.                 return false;
  209.             }
  210.             if(m_dPCL_power[band_index][PCL_HIGH_INDEX]>=0 && m_dPCL_power[band_index][PCL_MID_INDEX]>=0)
  211.             {
  212.                 Rload_high_temp2 = sqrt(m_dPCL_power[band_index][PCL_HIGH_INDEX])-sqrt(m_dPCL_power[band_index][PCL_MID_INDEX]);
  213.                 log->Add(
  214.                           DateToStr(Date()) +  " " + CurrentTimeStr() +
  215.                           "       "  +
  216.                           " m_dPCL_power[band_index][PCL_HIGH_INDEX] = " + Double_To_AnsiString(m_dPCL_power[band_index][PCL_HIGH_INDEX]) + "n" +
  217.                           "                               "  +
  218.                           " m_dPCL_power[band_index][PCL_MID_INDEX] = " + Double_To_AnsiString(m_dPCL_power[band_index][PCL_MID_INDEX]) + "n" +
  219.                           "                               " +
  220.                           " Rload_high_temp2 = " + Double_To_AnsiString(Rload_high_temp2)
  221.                         );
  222.             }
  223.             else if( m_dPCL_power[band_index][PCL_HIGH_INDEX] < 0)
  224.             {
  225.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  226.                           " FAIL : m_dPCL_power[band_index][PCL_HIGH_INDEX] < 0"
  227.                         );
  228.                 return false;
  229.             }
  230.             else
  231.             {
  232.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  233.                          " FAIL : m_dPCL_power[band_index][PCL_MID_INDEX] < 0"
  234.                         );
  235.                 return false;
  236.             }
  237.             if(Rload_high_temp2 != 0.0)
  238.             {
  239.                 m_dRload_high[band_index] = pow(Rload_high_temp1 / Rload_high_temp2, 2.0);
  240.                 log->Add(  DateToStr(Date()) +  " " + CurrentTimeStr() +
  241.                            "       " +
  242.                            " m_dRload_high[band_index] = " + Double_To_AnsiString(m_dRload_high[band_index])
  243.                         );
  244.             }
  245.             if(m_dRload_high[band_index]*m_dPCL_power[band_index][PCL_MID_INDEX] >= 0)
  246.             {
  247.                 m_dK1_high[band_index] = 8.0/3.0/sqrt(2)*m_dV_set[band_index][V_SET_MID_INDEX]-sqrt(m_dRload_high[band_index]*m_dPCL_power[band_index][PCL_MID_INDEX]);
  248.                 log->Add(  DateToStr(Date()) +  " " + CurrentTimeStr() +
  249.                             "       " +
  250.                             " m_dK1_high[band_index] = " + Double_To_AnsiString(m_dK1_high[band_index]) + "n"
  251.                         );
  252.             }
  253.             else
  254.             {
  255.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  256.                           " FAIL : m_dRload_high[band_index]*m_dPCL_power[band_index][PCL_MID_INDEX] < 0" +
  257.                           ", band_index = "+IntToStr(band_index)+ "n" +
  258.                           "m_dRload_high[band_index] = " + Double_To_AnsiString(m_dRload_high[band_index]) +  "n" +
  259.                           "PCL_MID_INDEX = " + IntToStr(PCL_MID_INDEX) + "n" +
  260.                           "m_dPCL_power[band_index][PCL_MID_INDEX] = " + Double_To_AnsiString(m_dPCL_power[band_index][PCL_MID_INDEX])
  261.                         );
  262.                 return false;
  263.             }
  264.             eFreqBand++;
  265.         } // while
  266.         //------------------------------------------------------------------
  267.         // calculate Rload_low
  268.         double Rload_low_temp1, Rload_low_temp2;
  269.         eFreqBand = FrequencyBand850;
  270.         while (eFreqBand < FrequencyBandCount)
  271.         {
  272.             switch (eFreqBand)
  273.             {
  274.                 case FrequencyBand850:
  275.                 {
  276.                     if (!IsFreqBankSupported(m_asFreqBank, eFreqBand))
  277.                     {
  278.                         eFreqBand++;
  279.                         continue;
  280.                     }
  281.                 }
  282.                 break;
  283.                 case FrequencyBand900:
  284.                 {
  285.                     if (!IsFreqBankSupported(m_asFreqBank, eFreqBand))
  286.                     {
  287.                         eFreqBand++;
  288.                         continue;
  289.                     }
  290.                 }
  291.                 break;
  292.                 case FrequencyBand1800:
  293.                 {
  294.                     if (!IsFreqBankSupported(m_asFreqBank, eFreqBand))
  295.                     {
  296.                         eFreqBand++;
  297.                         continue;
  298.                     }
  299.                 }
  300.                 break;
  301.                 case FrequencyBand1900:
  302.                 {
  303.                     if (!IsFreqBankSupported(m_asFreqBank, eFreqBand))
  304.                     {
  305.                         eFreqBand++;
  306.                         continue;
  307.                     }
  308.                 }
  309.                 break;
  310.                 default:
  311.                     assert(false);
  312.                 break;
  313.             } // switch
  314.             E_BANDSEL band_index = FreqBand_To_BandIdx(eFreqBand);
  315.         //for(i=0; i<real_support_band_num; i++)
  316.         //{
  317.             Rload_low_temp1 = (8.0/3.0/sqrt(2.0)*(m_dV_set[band_index][V_SET_MID_INDEX]-m_dV_set[band_index][V_SET_LOW_INDEX]));
  318.             if(m_dPCL_power[band_index][PCL_MID_INDEX] >=0 && m_dPCL_power[band_index][PCL_LOW_INDEX]>=0)
  319.             {
  320.                 Rload_low_temp2 = sqrt(m_dPCL_power[band_index][PCL_MID_INDEX])-sqrt(m_dPCL_power[band_index][PCL_LOW_INDEX]);
  321.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  322.                           " i = " + IntToStr(band_index) + "," +
  323.                           " Rload_low_temp2 = " + Double_To_AnsiString(Rload_low_temp2)
  324.                         );
  325.             }
  326.             else if (m_dPCL_power[band_index][PCL_MID_INDEX] < 0)
  327.             {
  328.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  329.                           " FAIL : m_dPCL_power[band_index][PCL_MID_INDEX] < 0"
  330.                          );
  331.                 return false;
  332.             }
  333.             else
  334.             {
  335.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  336.                           " FAIL : m_dPCL_power[band_index][PCL_LOW_INDEX] < 0"
  337.                         );
  338.                 return false;
  339.             }
  340.             if(Rload_low_temp2 != 0.0)
  341.             {
  342.                 Rload_low[band_index] = pow(Rload_low_temp1 / Rload_low_temp2, 2.0);
  343.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  344.                           "       " +
  345.                           " Rload_low[band_index] = " + Double_To_AnsiString(Rload_low[band_index])
  346.                         );
  347.             }
  348.             else
  349.             {
  350.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  351.                           " FAIL : Rload_low_temp2 = 0");
  352.                 return false;
  353.             }
  354.             if(Rload_low[band_index]*m_dPCL_power[band_index][PCL_LOW_INDEX] >= 0.0)
  355.             {
  356.                 K1_low[band_index] = 8.0/3.0/sqrt(2)*m_dV_set[band_index][V_SET_MID_INDEX]-sqrt(Rload_low[band_index]*m_dPCL_power[band_index][PCL_MID_INDEX]);
  357.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  358.                           "       " +
  359.                           " K1_low[band_index] = " + Double_To_AnsiString(K1_low[band_index]) );
  360.             }
  361.             else
  362.             {
  363.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  364.                           " FAIL : Rload_low[band_index]*m_dPCL_power[band_index][PCL_MID_INDEX] < 0");
  365.             }
  366.             eFreqBand++;
  367.         } // while
  368.         //------------------------------------------------------------------
  369.         // calculate Vset DAC value
  370.         eFreqBand = FrequencyBand850;
  371.         as_wanted_p = "";
  372.         as_correction = "";
  373.         while (eFreqBand < FrequencyBandCount)
  374.         {
  375.             as_tx_pcl = "";
  376.             if (this->Terminated)
  377.             {
  378.                 this->OnTerminate = neByUser;
  379.                 return false;
  380.             }
  381.             switch (eFreqBand)
  382.             {
  383.                 case FrequencyBand850:
  384.                 {
  385.                     if (!IsFreqBankSupported(m_asFreqBank, eFreqBand))
  386.                     {
  387.                         eFreqBand++;
  388.                         continue;
  389.                     }
  390.                     i_TX_level_index_high = TX_LEVEL_HIGH_INDEX_GSM;
  391.                     i_TX_level_index_mid = TX_LEVEL_MID_INDEX_GSM;
  392.                     i_TX_level_index_low = TX_LEVEL_LOW_INDEX_GSM;
  393.                     as_wanted_p = m_as_gsm850_wanted_p;
  394.                     as_correction = m_as_gsm850_correction;
  395.                     as_tx_pcl = m_as_gsm850_tx_pcl;
  396.                 }
  397.                 break;
  398.                 case FrequencyBand900:
  399.                 {
  400.                     if (!IsFreqBankSupported(m_asFreqBank, eFreqBand))
  401.                     {
  402.                         eFreqBand++;
  403.                         continue;
  404.                     }
  405.                     i_TX_level_index_high = TX_LEVEL_HIGH_INDEX_GSM;
  406.                     i_TX_level_index_mid = TX_LEVEL_MID_INDEX_GSM;
  407.                     i_TX_level_index_low = TX_LEVEL_LOW_INDEX_GSM;
  408.                     as_wanted_p = m_as_gsm900_wanted_p;
  409.                     as_correction = m_as_gsm900_correction;
  410.                     as_tx_pcl = m_as_gsm900_tx_pcl;
  411.                 }
  412.                 break;
  413.                 case FrequencyBand1800:
  414.                 {
  415.                     if (!IsFreqBankSupported(m_asFreqBank, eFreqBand))
  416.                     {
  417.                         eFreqBand++;
  418.                         continue;
  419.                     }
  420.                     i_TX_level_index_high = TX_LEVEL_HIGH_INDEX_DCS;
  421.                     i_TX_level_index_mid = TX_LEVEL_MID_INDEX_DCS;
  422.                     i_TX_level_index_low = TX_LEVEL_LOW_INDEX_DCS;
  423.                     as_wanted_p = m_as_dcs1800_wanted_p;
  424.                     as_correction = m_as_dcs1800_correction;
  425.                     as_tx_pcl = m_as_dcs1800_tx_pcl;
  426.                 }
  427.                 break;
  428.                 case FrequencyBand1900:
  429.                 {
  430.                     if (!IsFreqBankSupported(m_asFreqBank, eFreqBand))
  431.                     {
  432.                         eFreqBand++;
  433.                         continue;
  434.                     }
  435.                     i_TX_level_index_high = TX_LEVEL_HIGH_INDEX_PCS;
  436.                     i_TX_level_index_mid = TX_LEVEL_MID_INDEX_PCS;
  437.                     i_TX_level_index_low = TX_LEVEL_LOW_INDEX_PCS;
  438.                     as_wanted_p = m_as_pcs1900_wanted_p;
  439.                     as_correction = m_as_pcs1900_correction;
  440.                     as_tx_pcl = m_as_pcs1900_tx_pcl;
  441.                 }
  442.                 break;
  443.                 default:
  444.                 {
  445.                     assert(false);
  446.                 }    
  447.                 break;
  448.             } // switch
  449.             E_BANDSEL band_index = FreqBand_To_BandIdx(eFreqBand);
  450.             for ( int N=i_TX_level_index_high; N>=i_TX_level_index_mid; N--)  // DCS,PCS:16~1 or GSM:15~1
  451.             {
  452.                 if (! getAnsiStrSubItem( as_wanted_p, N, DEFAULT_SEP_CHAR, as_sub_wanted_p) )
  453.                 {
  454.                     CalErrorHandler( WM_MF_CFG_READ_FAIL );
  455.                     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  456.                               " FAIL: Read config file fail(as_sub_wanted_p)."
  457.                             );
  458.                     return false;
  459.                 }
  460.                 if (! getAnsiStrSubItem( as_correction, N, DEFAULT_SEP_CHAR, as_sub_correction))
  461.                 {
  462.                     CalErrorHandler( WM_MF_CFG_READ_FAIL );
  463.                     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  464.                               " FAIL: Read config file fail(as_sub_correction 1)."
  465.                             );
  466.                     return false;
  467.                 }
  468.                 // added by Andy Ueng for save result
  469.                 if (! getAnsiStrSubItem( as_tx_pcl, N, DEFAULT_SEP_CHAR, as_sub_tx_pcl))
  470.                 {
  471.                     CalErrorHandler( WM_MF_CFG_READ_FAIL );
  472.                     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  473.                               " FAIL: Read config file fail(as_sub_tx_pcl)."
  474.                             );
  475.                     return false;
  476.                 }
  477.               //sprintf(tempbuf, "%3d", as_sub_tx_pcl.ToInt());
  478.               //ResultHeaderBuf2 = ResultHeaderBuf2 + tempbuf + " ";
  479.               // end of added
  480.                 m_dPCL_power_ideal[band_index][N-1] =  pow(10.0, (atof(as_sub_wanted_p.c_str())+ atof(as_sub_correction.c_str()))/10.0)/1000.0;
  481.                 log->Add( "n" + DateToStr(Date()) +  " " + CurrentTimeStr() +
  482.                            " band_index = "+IntToStr(band_index)+","+
  483.                           " N-1 = " + IntToStr(N-1) +  "," +
  484.                           " m_dPCL_power_ideal[band_index][N-1] = " + Double_To_AnsiString(m_dPCL_power_ideal[band_index][N-1])
  485.                         );
  486.                 if(m_dRload_high[band_index]*m_dPCL_power_ideal[band_index][N-1]>=0.0)
  487.                 {
  488.                     m_dV_set_ideal[band_index][N-1] = (3.0/8.0)*sqrt(2.0)*(sqrt(m_dRload_high[band_index]*m_dPCL_power_ideal[band_index][N-1]) + m_dK1_high[band_index]);
  489.                     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  490.                               "                          " +
  491.                               " m_dV_set_ideal[band_index][N-1] = " + Double_To_AnsiString(m_dV_set_ideal[band_index][N-1])
  492.                             );
  493.                 }
  494.                 else
  495.                 {
  496.                     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  497.                                " FAIL: m_dRload_high[band_index]*m_dPCL_power_ideal[band_index][N-1] < 0"
  498.                             );
  499.                     return false;
  500.                 }
  501.                // m_usPCLDacValue_ideal[band_index][N-1] = m_dV_set_ideal[band_index][N-1]*1024.0/2.8 * 25.0 / 15.0 - MF_rf_apc_ptr->Get_HighApcDcOffset(band_index);
  502.                 if( ! MF_rf_apc_ptr->Get_RealApcDcOffset( m_pCal->b_TADOSupport, band_index, as_sub_tx_pcl.ToInt(), m_iApcDcOffset ) )
  503.                 {
  504.                     CalErrorHandler( WM_MF_RF_TX_LEVEL_FAIL );
  505.                     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  506.                               " FAIL: Get APC DC offset " +
  507.                               " TADO support = " + IntToStr( m_pCal->b_TADOSupport ) +
  508.                               " eFreqBand = " + IntToStr( eFreqBand ) +
  509.                               " pcl = " + as_sub_tx_pcl
  510.                         );
  511.                     return false;
  512.                 }
  513.                 m_usPCLDacValue_ideal[band_index][N-1] = m_dV_set_ideal[band_index][N-1]*1024.0/2.8 * 25.0 / 15.0 - m_iApcDcOffset;
  514.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  515.                            "                          " +
  516.                            " m_usPCLDacValue_ideal[band_index][N-1] = " + IntToStr(m_usPCLDacValue_ideal[band_index][N-1]) + "n"
  517.                          );
  518.                // MF_rf_apc_ptr->ApcProfile[band_index].rampData.power[N-1] = m_usPCLDacValue_ideal[band_index][N-1];
  519.                 MF_rf_apc_ptr->Set_ApcProfilePower( band_index, N-1, m_usPCLDacValue_ideal[band_index][N-1] );
  520.                 
  521.                 //PCL_dbm_ideal[band_index][N-1] = 10.0*log10(m_dPCL_power_ideal[band_index][N-1]*1000.0);
  522.                 // sprintf(tempbuf, "%2.1f", PCL_dbm_ideal[band_index][N-1]);
  523.                 // ResultBuf = ResultBuf + tempbuf + ", ";
  524.                 //ResultBuf = ResultBuf + IntToStr(MF_rf_apc_ptr->ApcProfile[band_index].rampData.power[N-1]) + ", ";
  525.             } // for
  526.             for ( int N=i_TX_level_index_mid-1; N>=i_TX_level_index_low; N--)  // DCS,PCS:16~1 or GSM:15~1
  527.             {
  528.                 if (! getAnsiStrSubItem( as_wanted_p, N, DEFAULT_SEP_CHAR, as_sub_wanted_p) )
  529.                 {
  530.                     CalErrorHandler( WM_MF_CFG_READ_FAIL );
  531.                     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  532.                               " FAIL: Read config file fail(sub_wanted_p 4)."
  533.                             );
  534.                     return false;
  535.                 }
  536.                 if (! getAnsiStrSubItem( as_correction, N, DEFAULT_SEP_CHAR, as_sub_correction))
  537.                 {
  538.                     CalErrorHandler( WM_MF_CFG_READ_FAIL );
  539.                     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  540.                               " FAIL: Read config file fail(as_sub_correction 2)."
  541.                             );
  542.                     return false;
  543.                 }
  544.                 // added by Andy Ueng for save result
  545.                 if (! getAnsiStrSubItem( as_tx_pcl, N, DEFAULT_SEP_CHAR, as_sub_tx_pcl))
  546.                 {
  547.                     CalErrorHandler( WM_MF_CFG_READ_FAIL );
  548.                     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  549.                               " FAIL: Read config file fail(as_sub_tx_pcl)."
  550.                             );
  551.                     return false;
  552.                 }
  553.              // sprintf(tempbuf, "%3d", as_sub_tx_pcl.ToInt());
  554.              // ResultHeaderBuf2 = ResultHeaderBuf2 + tempbuf + " ";
  555.              // end of added
  556.                 m_dPCL_power_ideal[band_index][N-1] =  pow(10.0, (atof(as_sub_wanted_p.c_str())+atof(as_sub_correction.c_str()))/10.0)/1000.0;
  557.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  558.                           " band_index = " + IntToStr(band_index) + "," +
  559.                           " N-1 = " + IntToStr(N-1) +  "," +
  560.                           " m_dPCL_power_ideal[band_index][N-1] = " + Double_To_AnsiString(m_dPCL_power_ideal[band_index][N-1])
  561.                         );
  562.                 if(Rload_low[band_index]*m_dPCL_power_ideal[band_index][N-1] >=0.0)
  563.                 {
  564.                     m_dV_set_ideal[band_index][N-1] = (3.0/8.0)*sqrt(2)*(sqrt(Rload_low[band_index]*m_dPCL_power_ideal[band_index][N-1]) + K1_low[band_index]);
  565.                     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  566.                               "                         " +
  567.                               " m_dV_set_ideal[band_index][N-1] = " + Double_To_AnsiString(m_dV_set_ideal[band_index][N-1])
  568.                             );
  569.                 }
  570.                 else
  571.                 {
  572.                     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  573.                               " FAIL: Rload_low[band_index]*m_dPCL_power_ideal[band_index][N-1] < 0.0"
  574.                             );
  575.                     return false;
  576.                 }
  577.                // m_usPCLDacValue_ideal[band_index][N-1] = m_dV_set_ideal[band_index][N-1]*1024.0/2.8 * 25.0 / 15.0 - MF_rf_apc_ptr->Get_HighApcDcOffset(band_index);
  578.                 if( ! MF_rf_apc_ptr->Get_RealApcDcOffset( m_pCal->b_TADOSupport, band_index, as_sub_tx_pcl.ToInt(), m_iApcDcOffset ) )
  579.                 {
  580.                     CalErrorHandler( WM_MF_RF_TX_LEVEL_EVALDAC_FAIL );
  581.                     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  582.                               " FAIL: PCL to dBm " +
  583.                               " TADO support = " + IntToStr( m_pCal->b_TADOSupport ) +
  584.                               " eFreqBand = " + IntToStr( eFreqBand ) +
  585.                               " pcl = " + as_sub_tx_pcl
  586.                         );
  587.                     return false;
  588.                 }
  589.                 m_usPCLDacValue_ideal[band_index][N-1] = m_dV_set_ideal[band_index][N-1]*1024.0/2.8 * 25.0 / 15.0 - m_iApcDcOffset;
  590.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  591.                            "                         " +
  592.                            " m_usPCLDacValue_ideal[band_index][N-1] = " + Double_To_AnsiString(m_usPCLDacValue_ideal[band_index][N-1]) + "n"
  593.                         );
  594.                // MF_rf_apc_ptr->ApcProfile[band_index].rampData.power[N-1] = m_usPCLDacValue_ideal[band_index][N-1];
  595.                  MF_rf_apc_ptr->Set_ApcProfilePower( band_index, N-1, m_usPCLDacValue_ideal[band_index][N-1] );
  596.              // PCL_dbm_ideal[band_index][N-1] = 10.0*log10(m_dPCL_power_ideal[band_index][N-1]*1000.0);
  597.              // sprintf(tempbuf, "%2.1f", PCL_dbm_ideal[band_index][N-1]);
  598.              // ResultBuf = ResultBuf + tempbuf + ", ";
  599.               //ResultBuf = ResultBuf + IntToStr(MF_rf_apc_ptr->ApcProfile[band_index].rampData.power[N-1]) + ", ";
  600.             } // for
  601.             
  602.             MF_rf_apc_ptr->ConfirmCallback = ccb_write_apc_to_nvram;
  603.             MF_rf_apc_ptr->REQ_Write_APC_To_NVRAM_Single_Band_Start(m_pCal->ui_rf_id, band_index, m_pCal->b_TADOSupport );
  604.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  605.                       " Write to NVRAM band_index = " + IntToStr(band_index)
  606.                     );
  607.            // log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  608.            //          " TimerCal->Enabled 15= " + IntToStr((int)frmFatcory->TimerCal->Enabled) + "n"
  609.            //        );
  610.             RestartTimerCal( WM_MF_NVRAM_LEVEL_RAMP_WRITE_FAIL );
  611.         // end of added
  612.             if ( this->Terminated )
  613.             {
  614.                 this->OnTerminate = neByUser;
  615.                 return false;
  616.             }
  617.             is_suspend_cal = true;
  618.             this->Suspend();
  619.             is_suspend_cal = false;
  620.             E_METAAPP_RESULT_T state = MF_rf_apc_ptr->Get_ConfirmState();
  621.             if (state != METAAPP_SUCCESS)
  622.             {
  623.                 if (METAAPP_NVRAM_LID_VER_NOT_SUPPORT == state)
  624.                 {
  625.                     CalErrorHandler(WM_MF_NVRAM_EF_L1_RAMPTABLE_xxx_LID_VERNO_FAIL);
  626.                     log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  627.                              " FAIL : NVRAM_EF_L1_RAMPTABLE_xxx_LID version is not support, please update META to latest version. "
  628.                              );
  629.                 }
  630.                 else
  631.                 {
  632.                     CalErrorHandler(WM_MF_NVRAM_LEVEL_RAMP_WRITE_FAIL);
  633.                     log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  634.                                       " FAIL: Target < write APC to NVRAM "
  635.                                     );
  636.                 }
  637.                 return false;
  638.             }
  639.             WriteAPCCalResultToFile(as_ID+".cal",Application->ExeName, m_pCal->b_CalResultPath, FreqBand_To_BandIdx(eFreqBand) );
  640.             eFreqBand++;
  641.         } // while
  642.         frmFatcory->DisableAllCalTimer();
  643.         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  644.                  " ===================== Evaluate other PCL DAC value end =========== n "
  645.                 );
  646.        // ========================= Evaluate other PCL DAC value end ==================
  647.     return true;
  648. }