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

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_RX_path_loss.cpp
  40.  *
  41.  * Project:
  42.  * --------
  43.  *   Maui META APP
  44.  *
  45.  * Description:
  46.  * ------------
  47.  *  RX path loss calibration 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 _CAL_COMMON_H_
  72. #include "cal_common.h"
  73. #endif
  74. // callback
  75. #ifndef _META_FACTORY_RF_CB_H_
  76. #include "meta_factory_rf_cb.h"
  77. #endif
  78. #ifndef _META_FACTORY_NVRAM_CB_H_
  79. #include "meta_factory_nvram_cb.h"
  80. #endif
  81. // form
  82. #ifndef _META_FACTORY_H_
  83. #include "META_Factory.h"
  84. #endif
  85. #ifndef _FORM_MAIN_H_
  86. #include "form_main.h"
  87. #endif
  88. // equipment
  89. #ifndef _AGECOMMON_H_
  90. #include "agecommon.h"
  91. #endif
  92. #ifndef  _AGE_MISC_H_
  93. #include "age_misc.h"
  94. #endif
  95. // misc
  96. #ifndef  _FT_UTILS_H_
  97. #include "ft_utils.h"
  98. #endif
  99. #ifndef  _MATH_UTILS_H_
  100. #include "math_utils.h"
  101. #endif
  102. #ifndef  _GSM_UTILS_H_
  103. #include "gsm_utils.h"
  104. #endif
  105. #ifndef  _BAND_UTILS_H_
  106. #include "band_utils.h"
  107. #endif
  108. #ifndef  _TIME_UTILS_H_
  109. #include "time_utils.h"
  110. #endif
  111. //----------------------------------------------------------------------------
  112. // RX path loss
  113. extern CRFAGC*  MF_rf_agc_ptr;
  114. extern RfPm_Req  *MF_rf_pm_req;
  115. extern RfPm_Cnf  *MF_rf_pm_cnf;
  116. extern bool  is_suspend_cal; // in T_META_factory_calibration.cpp
  117. //******************************************************************************
  118. //                         RX path loss calibration
  119. //******************************************************************************
  120. bool __fastcall T_META_factory_calibration::RxPathLossCal( void )
  121. {
  122.     AnsiString as_all_arfcn, as_arfcn;
  123.     char tempbuf[256];
  124.     
  125.     PostMessage(
  126.                      ctrl.hPostMsgDestHandle,
  127.                      WM_MF_RF_PM_BEGIN,
  128.                      0,
  129.                      0
  130.                     );
  131.     log->Add( "n" + DateToStr(Date()) +  " " + CurrentTimeStr() +
  132.              " ================== Path loss calibration begin ==================="
  133.            );
  134.     if(! m_rct_ctrl.RCT_operatingMode( m_pRct, OPERATING_MODE_GSM_BCH ))
  135.     {
  136.         CalErrorHandler( WM_MF_AGE8960_SET_OPERATION_MODE_FAIL );
  137.         if ( frmFatcory->rbAgilent8960->Checked )
  138.         {
  139.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  140.                               " FAIL :"+
  141.                               " Agilent 8960< Operation mode = GSM BCH"
  142.                             );
  143.         }
  144.         else
  145.         {
  146.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  147.                               " FAIL :"+
  148.                               " cmu200 < Band = Operation mode = GSM BCH"
  149.                             );
  150.         }
  151.         return false;
  152.     }
  153.     FrequencyBand eFreqBand = FrequencyBand850;
  154.     for (int J=0; J< FrequencyBandCount; J++)
  155.     {
  156.         for ( int K=0; K < PLTABLE_SIZE; K++)
  157.             MF_rf_pm_power[J][K] = 0;
  158.     }
  159.     if ( this->Terminated )
  160.     {
  161.         this->OnTerminate = neByUser;
  162.         return false;
  163.     }
  164.     l1cal_agcPathLoss_T* p_path_loss = MF_rf_agc_ptr->Get_PathLoss();
  165.     l1cal_agcPathLoss_T path_loss = *p_path_loss;
  166.     int vi_Band;
  167.     while (eFreqBand < FrequencyBandCount)
  168.     {
  169.         switch (eFreqBand)
  170.         {
  171.             case FrequencyBand850:
  172.             {
  173.                 if (! IsFreqBankSupported(  m_asFreqBank, eFreqBand))
  174.                 {
  175.                    eFreqBand++;
  176.                    continue;
  177.                 }
  178.                 vi_Band = age1960_GSM850_BAND;
  179.             }
  180.             break;
  181.             case FrequencyBand900:
  182.             {
  183.                 if (! IsFreqBankSupported(  m_asFreqBank, eFreqBand))
  184.                 {
  185.                     eFreqBand++;
  186.                     continue;
  187.                 }
  188.                 vi_Band = age1960_EGSM_BAND;
  189.             }
  190.             break;
  191.             case FrequencyBand1800:
  192.             {
  193.                 if (! IsFreqBankSupported(  m_asFreqBank, eFreqBand))
  194.                 {
  195.                     eFreqBand++;
  196.                     continue;
  197.                 }
  198.                 vi_Band = age1960_DCS1800_BAND;
  199.             }
  200.             break;
  201.             case FrequencyBand1900:
  202.             {
  203.                 if (! IsFreqBankSupported(  m_asFreqBank, eFreqBand))
  204.                 {
  205.                     eFreqBand++;
  206.                     continue;
  207.                 }
  208.                 vi_Band = age1960_PCS1900_BAND;
  209.             }
  210.             break;
  211.             default:
  212.                 assert(false);
  213.             break;
  214.         } // switch
  215.         if ( this->Terminated )
  216.         {
  217.             this->OnTerminate = neByUser;
  218.             return false;
  219.         }
  220.         if (!MF_rf_agc_ptr->RxLossSectionExist(m_pCal->as_IniFile.c_str(), eFreqBand))
  221.         {
  222.             CalErrorHandler(WM_MF_RF_PM_INI_FAIL);
  223.             log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  224.                               " FAIL :"+
  225.                               " RX pathloss section is not in initial file: " + FreqBand_To_Str(eFreqBand)
  226.                             );
  227.             return false;
  228.         }
  229.         if( ! m_rct_ctrl.RCT_cellBand( m_pRct, vi_Band ) )
  230.         {
  231.             CalErrorHandler( WM_MF_AGE8960_SET_BAND_FAIL );
  232.             if ( frmFatcory->rbAgilent8960->Checked )
  233.             {
  234.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  235.                               " FAIL :"+
  236.                               " Agilent 8960< Band = " + ViBand_To_Str( vi_Band )
  237.                             );
  238.             }
  239.             else
  240.             {
  241.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  242.                               " FAIL :"+
  243.                               " cmu200 < Band = " + ViBand_To_Str( vi_Band )
  244.                             );
  245.             }
  246.             return false;
  247.         }
  248.         if( ! m_rct_ctrl.RCT_PowTranCont( m_pRct ) )
  249.         {
  250.             CalErrorHandler( WM_MF_AGE8960_SET_BAND_FAIL );
  251.             if ( frmFatcory->rbAgilent8960->Checked )
  252.             {
  253.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  254.                               " FAIL :"+
  255.                               " Agilent 8960< Band = " + ViBand_To_Str( vi_Band )
  256.                             );
  257.             }
  258.             else
  259.             {
  260.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  261.                               " FAIL :"+
  262.                               " cmu200 < Band = " + ViBand_To_Str( vi_Band )
  263.                             );
  264.             }
  265.             return false;
  266.         }
  267.         if ( this->Terminated )
  268.         {
  269.             this->OnTerminate = neByUser;
  270.             return false;
  271.         }
  272.         if ( frmFatcory->rbAgilent8960->Checked  )
  273.         {
  274.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " Agilent 8960< band = " +
  275.                       FreqBand_To_Str( eFreqBand) );
  276.         }
  277.         else
  278.         {
  279.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " CMU 200< band = " +
  280.                       FreqBand_To_Str( eFreqBand) );
  281.         }
  282.         if( ! m_rct_ctrl.RCT_cellPower( m_pRct, d_P_DL ) )
  283.         {
  284.             CalErrorHandler( WM_MF_AGE8960_SET_POWER_FAIL );
  285.             if( frmFatcory->rbAgilent8960->Checked )
  286.             {
  287.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " FAIL: Agilent 8960< Power = " +
  288.                 Double_To_AnsiString( d_P_DL) ) + " dBm";
  289.             }
  290.             else
  291.             {
  292.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " FAIL: cmu200< Power = " +
  293.                 Double_To_AnsiString( d_P_DL) ) + " dBm";
  294.             }
  295.             return false;
  296.         }
  297.                     
  298.         if ( this->Terminated )
  299.         {
  300.             this->OnTerminate = neByUser;
  301.             return false;
  302.         }
  303.         if( frmFatcory->rbAgilent8960->Checked )
  304.         {
  305.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " Agilent 8960< Power = " +
  306.                       Double_To_AnsiString( d_P_DL) );
  307.         }
  308.         else
  309.         {
  310.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " CMU 200< Power = " +
  311.                               Double_To_AnsiString( d_P_DL) );
  312.         }
  313.         if (IsFreqBankSupported(  m_asFreqBank, eFreqBand))
  314.         {
  315.             if(eFreqBand == FrequencyBand1900)
  316.             {
  317.                 if(META_Rf_SelectFrequencyBand1900_r( m_pCal->i_MainMETAHandle, 1, MF_SelectBand_cnf_cb, &MF_SelectBand_token, NULL) !=  META_SUCCESS)
  318.                 {
  319.                     CalErrorHandler( WM_MF_RF_PM_SELECT_BAND_FAIL );
  320.                     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  321.                                               " FAIL:  Target < set Band1900 flag = 1 "
  322.                                              );
  323.                     return false;
  324.                 }
  325.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  326.                            " Target < set Band1900 flag = 1"
  327.                          );
  328.             }
  329.             else
  330.             {
  331.                 if(META_Rf_SelectFrequencyBand1900_r( m_pCal->i_MainMETAHandle, 0, MF_SelectBand_cnf_cb, &MF_SelectBand_token, NULL) !=  META_SUCCESS)
  332.                 {
  333.                     CalErrorHandler( WM_MF_RF_PM_SELECT_BAND_FAIL );
  334.                     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  335.                                            " FAIL:  Target < set Band1900 flag = 0 "
  336.                                           );
  337.                     return false;
  338.                 }
  339.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  340.                             " Target < set Band1900 flag = 0"
  341.                          );
  342.             }
  343.             is_suspend_cal = true;
  344.             this->Suspend();
  345.             is_suspend_cal = false;
  346.         }
  347.         {
  348.             for ( int I=0; I< PLTABLE_SIZE; I++)
  349.             {
  350.                 short s_pm_arfcn = path_loss.agcPathLoss[eFreqBand][I].max_arfcn;
  351.                 if ( s_pm_arfcn != MF_RF_LAST_ELEMENT )
  352.                 {
  353.                     if ( s_pm_arfcn >=1024)
  354.                     s_pm_arfcn = 1023;
  355.                     if ( this->Terminated )
  356.                     {
  357.                         this->OnTerminate = neByUser;
  358.                         return false;
  359.                     }
  360.                     if( ! m_rct_ctrl.RCT_BCHARFCN( m_pRct, s_pm_arfcn ) )
  361.                     {
  362.                         CalErrorHandler( WM_MF_AGE8960_SET_BCH_ARFCN_FAIL );
  363.                         if ( frmFatcory->rbAgilent8960->Checked )
  364.                         {
  365.                             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " FAIL: Agilent 8960< BCH ARFCN = " +
  366.                             IntToStr(s_pm_arfcn)
  367.                         );
  368.                     }
  369.                     else
  370.                     {
  371.                          log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " FAIL: cmu200 < BCH ARFCN = " +
  372.                            IntToStr(s_pm_arfcn)
  373.                          );
  374.                     }
  375.                     return false;
  376.                  }
  377.                     
  378.                     if ( this->Terminated )
  379.                     {
  380.                         this->OnTerminate = neByUser;
  381.                         return false;
  382.                     }
  383.                     if ( frmFatcory->rbAgilent8960->Checked )
  384.                     {
  385.                         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " Agilent 8960< BCH ARFCN = " +
  386.                                   AnsiString(s_pm_arfcn)
  387.                                 );
  388.                     }
  389.                     else
  390.                     {
  391.                         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " CMU 200< BCH ARFCN = " +
  392.                                   AnsiString(s_pm_arfcn)
  393.                                 );
  394.                     }
  395.                    
  396.        #ifdef _MYDEBUG
  397.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  398.                          " Sleep 100 " + AnsiString(__FILE__)
  399.                     );
  400.        #endif
  401.                   //  if( frmFatcory->cbAFC->Checked )
  402.                   //  {
  403.                   //      Sleep( 100 );  // wait Agilent 8960 ready!
  404.                   //  }
  405.                   //  else
  406.                     {
  407.                         Sleep( 200 );  // wait Agilent 8960 ready!
  408.                     }
  409.             // if Agilent 8960 not read, target will get error power!
  410.                     MF_rf_pm_cnf->deviation = 0;
  411.                     MF_rf_pm_cnf->power = 0;
  412.                     MF_rf_pm_cnf->usedGain = 0;
  413.                     MF_rf_pm_req->arfcn = s_pm_arfcn;
  414.                     MF_rf_pm_req->sampleNoPerFrame = cM_PM;
  415.                     MF_rf_pm_req->gain = (MF_RF_GAIN_TO_BE_SUB - d_P_DL) *AVG_POWER_PC_SIDE_MULTIPLY ;
  416.                     MF_rf_pm_req->frames = iN_PM;
  417.                     if( META_Rf_PM_r( m_pCal->i_MainMETAHandle, MF_rf_pm_req, MF_rf_pm_cnf_cb, &MF_rf_pm_token, NULL ) != META_SUCCESS )
  418.                     {
  419.                         CalErrorHandler( WM_MF_RF_PM_FAIL );
  420.                         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  421.                               " FAIL: "+
  422.                               " Target < PM : ARFCN = " + IntToStr( s_pm_arfcn ) +
  423.                               " sample per frame = " + IntToStr( cM_PM) +
  424.                               " gain = " + IntToStr( MF_rf_pm_req->gain ) +
  425.                               " frames = " + IntToStr( iN_PM)
  426.                             );
  427.                         return false;
  428.                     } // if
  429.                     if ( this->Terminated )
  430.                     {
  431.                         this->OnTerminate = neByUser;
  432.                         return false;
  433.                     }
  434.                     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  435.                            " Target < PM : ARFCN = " + IntToStr( s_pm_arfcn) +
  436.                            ", sample per frame = " + IntToStr( cM_PM) +
  437.                            ", gain = " + IntToStr( MF_rf_pm_req->gain ) +
  438.                            ", frames = " + IntToStr( iN_PM)
  439.                         );
  440.              //  Sleep(100);// delay for power measurement
  441.                   
  442.                     RestartTimerCal( WM_MF_RF_PM_FAIL );
  443.                     is_suspend_cal = true;
  444.                     this->Suspend();
  445.                     is_suspend_cal = false;
  446.                     if ( this->Terminated )
  447.                     {
  448.                         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  449.                                   " Terminate at line " + AnsiString(__FILE__) + " " + AnsiString(__LINE__)
  450.                                 );
  451.                         this->OnTerminate = neByUser;
  452.                         return false;
  453.                     }
  454.                     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  455.                              " Target > power  = " + Double_To_AnsiString(MF_rf_pm_cnf->power/8.0)
  456.                             );
  457.                  // (db)
  458.                     MF_rf_pm_power[eFreqBand][ I ] =
  459.                          (d_P_DL - (MF_rf_pm_cnf->power)/AVG_POWER_PC_SIDE_MULTIPLY );
  460.                    // gain_offset = MF_rf_agc_ptr->AgcPathLoss.agcPathLoss[eFreqBand][I].gain_offset + ( MF_rf_pm_power[eFreqBand][ I ]*GAIN_OFFSET_PC_MULTIPLY);
  461.                     float gain_offset = path_loss.agcPathLoss[eFreqBand][I].gain_offset + ( MF_rf_pm_power[eFreqBand][ I ]*GAIN_OFFSET_PC_MULTIPLY);
  462.                     if( gain_offset <= -128 || gain_offset >= 127)
  463.                     {
  464.                         CalErrorHandler( WM_MF_RF_PM_FAIL );
  465.                         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  466.                             " FAIL: "+
  467.                             " Target < PM : ARFCN = " + IntToStr( s_pm_arfcn ) +
  468.                             " sample per frame = " + IntToStr( cM_PM) +
  469.                             " gain = " + IntToStr( MF_rf_pm_req->gain ) +
  470.                             " frames = " + IntToStr( iN_PM) +
  471.                             " path loss = " + Double_To_AnsiString( gain_offset / GAIN_OFFSET_PC_MULTIPLY )
  472.                           );
  473.                         return false;
  474.                     }
  475.                     path_loss.agcPathLoss[eFreqBand][I].gain_offset +=
  476.                     (signed char)( MF_rf_pm_power[eFreqBand][ I ]*GAIN_OFFSET_PC_MULTIPLY);
  477.                     //MF_rf_agc_ptr->AgcPathLoss.agcPathLoss[eFreqBand][I].gain_offset +=
  478.                     //   (signed char)( MF_rf_pm_power[eFreqBand][ I ]*GAIN_OFFSET_PC_MULTIPLY);
  479.                     //sprintf(tempbuf, "%2.3f", MF_rf_agc_ptr->AgcPathLoss.agcPathLoss[eFreqBand][I].gain_offset/GAIN_OFFSET_PC_MULTIPLY);
  480.                     sprintf(tempbuf, "%2.3f", path_loss.agcPathLoss[eFreqBand][I].gain_offset/GAIN_OFFSET_PC_MULTIPLY);
  481.                     m_pCal->as_ResultBuf = m_pCal->as_ResultBuf + tempbuf + ", ";
  482.                     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  483.                               " delta L = " +
  484.                              IntToStr((signed char)( MF_rf_pm_power[eFreqBand][ I ]*GAIN_OFFSET_PC_MULTIPLY))+
  485.                              "n"
  486.                             );
  487.                     if ( this->Terminated )
  488.                     {
  489.                         this->OnTerminate = neByUser;
  490.                         return false;
  491.                     }
  492.                 }
  493.                 else // if ( as_arfcn.ToInt() != MF_RF_LAST_ELEMENT )
  494.                 {
  495.                     if ( this->Terminated )
  496.                     {
  497.                         this->OnTerminate = neByUser;
  498.                         return false;
  499.                     }
  500.                     break;
  501.                 } // else
  502.             } // for 1 Band
  503.         } // if
  504.         MF_rf_agc_ptr->Set_PathLoss(path_loss);
  505.         WriteAGCCalResultToFile(as_ID+".cal",Application->ExeName, m_pCal->b_CalResultPath, eFreqBand );
  506.         eFreqBand++;
  507.     } // while ( eFreqBand <= 5 )
  508.    //WriteAGCCalResultToFile(as_ID+".cal",Application->ExeName, frmFatcory->b_CalResultPath );
  509.     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  510.               " =================== Path loss calibration end ==================== n "
  511.             );
  512.     // ---------------------------- RX path loss check begin --------------------------
  513.     log->Add( "n" + DateToStr(Date()) +  " " + CurrentTimeStr() +
  514.              " ================ Path loss calibration check begin =============== "
  515.            );
  516.     AnsiString as_max_rx_loss_p, as_min_rx_loss_p;
  517.     AnsiString sub_max_rx_loss_p, sub_min_rx_loss_p;
  518.     as_max_rx_loss_p = "";
  519.     as_min_rx_loss_p = "";
  520.     eFreqBand =FrequencyBand850;
  521.     while (eFreqBand < FrequencyBandCount) // only for 850, 900, 1800, 1900
  522.     {
  523.         if ( this->Terminated )
  524.         {
  525.             this->OnTerminate = neByUser;
  526.             return false;
  527.         }
  528. //////
  529.         switch ( eFreqBand )
  530.         {
  531.             case FrequencyBand850:
  532.             {
  533.                 if (! IsFreqBankSupported(  m_asFreqBank, eFreqBand))
  534.                 {
  535.                     eFreqBand++;
  536.                     continue;
  537.                 }
  538.                 cfg->getGSM850_MAX_RX_LOSS( as_max_rx_loss_p );
  539.                 cfg->getGSM850_MIN_RX_LOSS( as_min_rx_loss_p );
  540.             }
  541.             break;
  542.             case FrequencyBand900:
  543.             {
  544.                 if (! IsFreqBankSupported(  m_asFreqBank, eFreqBand))
  545.                 {
  546.                     eFreqBand++;
  547.                     continue;
  548.                 }
  549.                 cfg->getGSM900_MAX_RX_LOSS( as_max_rx_loss_p );
  550.                 cfg->getGSM900_MIN_RX_LOSS( as_min_rx_loss_p );
  551.             }
  552.             break;
  553.             case FrequencyBand1800:
  554.             {
  555.                 if (! IsFreqBankSupported(  m_asFreqBank, eFreqBand))
  556.                 {
  557.                     eFreqBand++;
  558.                     continue;
  559.                 }
  560.                 cfg->getDCS1800_MAX_RX_LOSS(as_max_rx_loss_p);
  561.                 cfg->getDCS1800_MIN_RX_LOSS(as_min_rx_loss_p);
  562.             }
  563.             break;
  564.             case FrequencyBand1900:
  565.             {
  566.                 if (! IsFreqBankSupported(m_asFreqBank, eFreqBand))
  567.                 {
  568.                     eFreqBand++;
  569.                     continue;
  570.                 }
  571.                 cfg->getPCS1900_MAX_RX_LOSS( as_max_rx_loss_p );
  572.                 cfg->getPCS1900_MIN_RX_LOSS( as_min_rx_loss_p );
  573.             }
  574.             break;
  575.             default:
  576.                 assert(false);
  577.             break;
  578.         } // switch
  579.         log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  580.                  " -------------------------------------------------- "
  581.                 );
  582.         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  583.                           FreqBand_To_Str(eFreqBand)
  584.                         );
  585.         for ( int I=1; I< PLTABLE_SIZE; I++)
  586.         {
  587.            // if ( MF_rf_agc_ptr->AgcPathLoss.agcPathLoss[eFreqBand][I-1].max_arfcn == -1)
  588.             if (-1 == path_loss.agcPathLoss[eFreqBand][I-1].max_arfcn)
  589.             {   break;
  590.             }
  591.             if ( this->Terminated )
  592.             {
  593.                 this->OnTerminate = neByUser;
  594.                 return false;
  595.             }
  596.             sub_max_rx_loss_p ="0";
  597.             if(! getAnsiStrSubItem( as_max_rx_loss_p, I, DEFAULT_SEP_CHAR, sub_max_rx_loss_p ))
  598.             {
  599.                 CalErrorHandler( WM_MF_CFG_READ_FAIL );
  600.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  601.                           " FAIL: Read config file fail.5"
  602.                         );
  603.                 return false;
  604.             }
  605.             sub_min_rx_loss_p ="0";
  606.             if(! getAnsiStrSubItem( as_min_rx_loss_p, I, DEFAULT_SEP_CHAR, sub_min_rx_loss_p ))
  607.             {
  608.                 CalErrorHandler( WM_MF_CFG_READ_FAIL );
  609.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  610.                           " FAIL: Read config file fail.6"
  611.                         );
  612.                 return false;
  613.             }
  614.             if(  sub_min_rx_loss_p != NULL &&  sub_max_rx_loss_p != NULL)
  615.             {
  616.                 double d_min_rx_loss_p = atof(sub_min_rx_loss_p.c_str());
  617.               //  double d_rx_loss_p = MF_rf_agc_ptr->AgcPathLoss.agcPathLoss[eFreqBand][I-1].gain_offset / AVG_POWER_PC_SIDE_MULTIPLY;
  618.                 double d_rx_loss_p = path_loss.agcPathLoss[eFreqBand][I-1].gain_offset / AVG_POWER_PC_SIDE_MULTIPLY;
  619.                 double d_max_rx_loss_p = atof(sub_max_rx_loss_p.c_str());
  620.                 if( (d_min_rx_loss_p<=d_rx_loss_p) && (d_rx_loss_p<= d_max_rx_loss_p))
  621.                 {
  622.                     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  623.                             //  " PASS: RX path loss check -- " + "ARFCN = " + IntToStr(MF_rf_agc_ptr->AgcPathLoss.agcPathLoss[eFreqBand][I-1].max_arfcn) + "n" +
  624.                               " PASS: RX path loss check -- " + "ARFCN = " + IntToStr(path_loss.agcPathLoss[eFreqBand][I-1].max_arfcn) + "n" +
  625.                               "                         path loss = " + Double_To_AnsiString(d_rx_loss_p)+ "n" +
  626.                               "                         min rx path loss = " +  Double_To_AnsiString(d_min_rx_loss_p) + "n" +
  627.                               "                         max rx path loss = " +  Double_To_AnsiString(d_max_rx_loss_p) + "n"
  628.                             );
  629.                 }
  630.                 else
  631.                 {
  632.                     CalErrorHandler( WM_MF_RF_PM_CHECK_FAIL );
  633.                     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  634.                             //  " Fail: RX path loss check -- " + "ARFCN = " + IntToStr(MF_rf_agc_ptr->AgcPathLoss.agcPathLoss[eFreqBand][I-1].max_arfcn) + "n" +
  635.                               " Fail: RX path loss check -- " + "ARFCN = " + IntToStr(path_loss.agcPathLoss[eFreqBand][I-1].max_arfcn) + "n" +
  636.                               "                          path loss = " + Double_To_AnsiString(d_rx_loss_p)+ "n" +
  637.                               "                          min rx path loss = " +  Double_To_AnsiString(d_min_rx_loss_p) + "n" +
  638.                               "                          max rx path loss = " +  Double_To_AnsiString(d_max_rx_loss_p) + "n"
  639.                             );
  640.                     return false;
  641.                 }
  642.             }//if
  643.         } // for
  644.         eFreqBand++;
  645.     } // while
  646.     // ---------------------------- RX path loss check end ----------------------------
  647.     //////////////// write to agc fdm
  648.     MF_rf_agc_ptr->Set_PathLoss(path_loss);
  649.     MF_rf_agc_ptr->ConfirmCallback = ccb_write_agc_to_nvram;
  650.     MF_rf_agc_ptr->REQ_Write_To_NVRAM_Start();
  651.     if ( this->Terminated )
  652.     {
  653.         this->OnTerminate = neByUser;
  654.         return false;
  655.     }
  656.    // log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  657.    //           " TimerCal->Enabled -3= " + IntToStr((int)frmFatcory->TimerCal->Enabled)
  658.    //         );
  659.     RestartTimerCal(WM_MF_NVRAM_PATH_LOSS_WRITE_FAIL);
  660.     is_suspend_cal = true;
  661.     this->Suspend();
  662.     is_suspend_cal = false;
  663.     E_METAAPP_RESULT_T state = MF_rf_agc_ptr->Get_ConfirmState();
  664.     if (state != METAAPP_SUCCESS)
  665.     {
  666.         if (METAAPP_NVRAM_LID_VER_NOT_SUPPORT == state)
  667.         {
  668.             CalErrorHandler(WM_MF_NVRAM_EF_L1_AGCPATHLOSS_LID_VERNO_FAIL);
  669.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  670.                                   " FAIL : NVRAM_EF_L1_AGCPATHLOSS_LID version is not support, please update META to latest version. "
  671.                                 );
  672.         }
  673.         else
  674.         {
  675.             CalErrorHandler(WM_MF_NVRAM_PATH_LOSS_WRITE_FAIL);
  676.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  677.                                   " FAIL:  Target < Write path loss to NVRAM "
  678.                                 );
  679.         }
  680.         return false;
  681.     }
  682.     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  683.                   " Target < Write path loss to NVRAM "
  684.                 );
  685.     if ( this->Terminated )
  686.     {
  687.         this->OnTerminate = neByUser;
  688.         return false;
  689.     }
  690.     PostMessage(
  691.                      ctrl.hPostMsgDestHandle,
  692.                      WM_MF_RF_PM_CALIBRATION_DONE,
  693.                      0,
  694.                      0
  695.                     );
  696.     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  697.              " ================ Path loss calibration check end ================= n "
  698.            );
  699.     //// Path loss calibration end ///////////////////////////////////////////////
  700.     frmFatcory->DisableAllCalTimer();
  701.     return true;
  702. }