rf_rtc.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.  *   rf_rtc.cpp
  40.  *
  41.  * Project:
  42.  * --------
  43.  *   Maui META APP
  44.  *
  45.  * Description:
  46.  * ------------
  47.  *   RF RTC 32K colock 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 <IniFiles.hpp>
  66. #include <stdio.h>
  67. #pragma hdrstop
  68. // RF
  69. #ifndef  _RF_COMMON_H_
  70. #include "rf_common.h"
  71. #endif
  72. #ifndef  _RF_STOP_H_
  73. #include "rf_stop.h"
  74. #endif
  75. #ifndef  _RF_RTC_H_
  76. #include "rf_rtc.h"
  77. #endif
  78. #ifndef  _RF_AFC_H_
  79. #include "rf_afc.h"
  80. #endif
  81. #ifndef  _RF_TX_H_
  82. #include "rf_tx.h"
  83. #endif
  84. #ifndef _META_CONST_H_
  85. #include "meta_const.h"
  86. #endif
  87. // message
  88. #ifndef _META_LAB_MSG_H_
  89. #include "meta_lab_msg.h"
  90. #endif
  91. // equipment
  92. #ifndef  _RCT_CTRL_H_
  93. #include "rct_ctrl.h"
  94. #endif
  95. #ifndef _AGECOMMON_H_
  96. #include "AgeCommon.h"
  97. #endif
  98. // misc
  99. #ifndef  _BAND_UTILS_H_
  100. #include "band_utils.h"
  101. #endif
  102. #ifndef  _TIME_UTILS_H_
  103. #include "time_utils.h"
  104. #endif
  105. #ifndef  _FT_UTILS_H_
  106. #include "ft_utils.h"
  107. #endif
  108. #ifndef  _MATH_UTILS_H_
  109. #include "math_utils.h"
  110. #endif
  111. CRFRTC* g_rf_rtc_ptr;
  112. //==============================================================================
  113. static void CNF_ReadFromNVRAM(void)
  114. {
  115.     g_rf_rtc_ptr->CNF_ReadFromNVRAM();
  116. }
  117. //------------------------------------------------------------------------------
  118. static void CNF_RF_STOP(void)
  119. {
  120.     g_rf_rtc_ptr->CNF_RF_STOP();
  121. }
  122. //------------------------------------------------------------------------------
  123. static void __stdcall CNF_SelectPcs1900(const unsigned char cnf, const short token, void *usrData)
  124. {
  125.     g_rf_rtc_ptr->CNF_SelectPcs1900(cnf, token, usrData);
  126. }
  127. //------------------------------------------------------------------------------
  128. static void __stdcall CNF_RfAfc(const RfAfc_Cnf *cnf, const short token, void *usrData)
  129. {
  130.     g_rf_rtc_ptr->CNF_RfAfc(cnf, token, usrData);
  131. }
  132. //------------------------------------------------------------------------------
  133. static void __stdcall CNF_RfNbTx(const unsigned char cnf, const short token, void *usrData)
  134. {
  135.     g_rf_rtc_ptr->CNF_RfNbTx(cnf, token, usrData);
  136. }
  137. //==============================================================================
  138. void CRFRTC::CNF_ReadFromNVRAM(void)
  139. {
  140.     this->Resume();
  141. }
  142. //-----------------------------------------------------------------------------
  143. void CRFRTC::CNF_RF_STOP(void)
  144. {
  145.     this->Resume();
  146. }
  147. //-----------------------------------------------------------------------------
  148. void __stdcall CRFRTC::CNF_SelectPcs1900(const unsigned char cnf, const short token, void *usrData)
  149. {
  150.     m_ucSelectPcsCnf = cnf;
  151.     this->Resume();
  152. }
  153. //-----------------------------------------------------------------------------
  154. void __stdcall CRFRTC::CNF_RfAfc(const RfAfc_Cnf *cnf, const short token, void *usrData)
  155. {
  156.     m_sRfAfcCnf = *cnf;
  157.     this->Resume();
  158. }
  159. //-----------------------------------------------------------------------------
  160. void __stdcall CRFRTC::CNF_RfNbTx(const unsigned char cnf, const short token, void *usrData)
  161. {
  162.     m_ucNbTxCnf = cnf;
  163.     this->Resume();
  164. }
  165. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  166. void _fastcall CRFRTC::ShowMsg()
  167. {
  168.     ShowMessage(m_asMsg);
  169. }
  170. //------------------------------------------------------------------------------
  171. void _fastcall CRFRTC::SyncShowMsg(AnsiString as)
  172. {
  173.     m_asMsg = as;
  174.     Synchronize(ShowMsg);
  175. }
  176. //=========================================================================================
  177. __fastcall CRFRTC::CRFRTC(bool CreateSuspended, S_RF_RTC_T* p_rf_rtc, S_RCT* p_rct): TThread(CreateSuspended)
  178. {
  179.     m_psRfRtc = p_rf_rtc;
  180.     m_psRct   = p_rct;
  181. }
  182. //---------------------------------------------------------------------------
  183. void __fastcall CRFRTC::Execute()
  184. {
  185.     g_rf_rtc_ptr = this;
  186.     read_cfg_file();
  187.     if (AGILENT_8960 == m_psRct->device_type)
  188.     {
  189.         if (!m_rct_ctrl.RCT_Init(m_psRct, m_psRfRtc->as_FreqBand))
  190.         {
  191.             PostMessage(m_psRfRtc->hPostMsgDestHandle,
  192.                         WM_ML_RCT_INIT_FAIL,
  193.                         0,
  194.                         0
  195.                         );
  196.             m_psRfRtc->p_stLog->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  197.                                     " FAIL: " + m_psRct->as_RCT + " < Initialize"
  198.                                     );
  199.             return;
  200.         }
  201.     }
  202.     else
  203.     {
  204.         if (!m_rct_ctrl.RCT_sig_Init(m_psRct, m_psRfRtc->as_FreqBand))
  205.         {
  206.             PostMessage(m_psRfRtc->hPostMsgDestHandle,
  207.                         WM_ML_RCT_INIT_FAIL,
  208.                         0,
  209.                         0
  210.                         );
  211.             m_psRfRtc->p_stLog->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  212.                                     " FAIL: " + m_psRct->as_RCT + " < Initialize"
  213.                                     );
  214.             return;
  215.         }
  216.     }
  217.     if (this->Terminated)
  218.     {
  219.         this->OnTerminate = m_psRfRtc->ne_onTermByUser;
  220.         return;
  221.     }
  222.     if (!m_rct_ctrl.RCT_operatingMode(m_psRct, OPERATING_MODE_GSM_BCH_TCH))
  223.     {
  224.         PostMessage(m_psRfRtc->hPostMsgDestHandle,
  225.                     WM_ML_RCT_SET_OPERATION_MODE_FAIL,
  226.                     0,
  227.                     0
  228.                    );
  229.         m_psRfRtc->p_stLog->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  230.                               " FAIL :"+
  231.                               m_psRct->as_RCT + " < Operation mode = GSM BCH+TCH"
  232.                             );
  233.         return;
  234.     }
  235.     if (this->Terminated)
  236.     {
  237.         this->OnTerminate = m_psRfRtc->ne_onTermByUser;
  238.         return;
  239.     }
  240.     int vi_Band = BandIdx_To_AgeBand(m_psRfRtc->e_band);
  241.     if (AGILENT_8960 == m_psRct->device_type)
  242.     {
  243.         if (!m_rct_ctrl.RCT_cellBand(m_psRct, vi_Band))
  244.         {
  245.             PostMessage(m_psRfRtc->hPostMsgDestHandle,
  246.                         WM_ML_RCT_SET_BAND_FAIL,
  247.                         0,
  248.                         0
  249.                         );
  250.             m_psRfRtc->p_stLog->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  251.                                    " FAIL :"+
  252.                                    " Agilent 8960 < Band = " + ViBand_To_Str( vi_Band )
  253.                                   );
  254.             write_log_file();
  255.             return;
  256.         }
  257.     }
  258.     else
  259.     {
  260.         if (!m_rct_ctrl.RCT_sig_cellBand(m_psRct, vi_Band))
  261.         {
  262.             PostMessage(m_psRfRtc->hPostMsgDestHandle,
  263.                         WM_ML_RCT_SET_BAND_FAIL,
  264.                         0,
  265.                         0
  266.                         );
  267.             m_psRfRtc->p_stLog->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  268.                               " FAIL :"+
  269.                               " CMU 200 < Band = " + ViBand_To_Str(vi_Band)
  270.                             );
  271.             write_log_file();
  272.             return;
  273.         }
  274.     }
  275.     if (this->Terminated)
  276.     {
  277.         this->OnTerminate = m_psRfRtc->ne_onTermByUser;
  278.         return;
  279.     }
  280.         if (AGILENT_8960 == m_psRct->device_type)
  281.         {
  282.             if (!m_rct_ctrl.RCT_cellPower(m_psRct, m_psRfRtc->d_P_DL))
  283.             {
  284.                 PostMessage(m_psRfRtc->hPostMsgDestHandle,
  285.                             WM_ML_RCT_SET_DOWNLINK_POWER_FAIL,
  286.                             0,
  287.                             0);
  288.                 m_psRfRtc->p_stLog->Add(DateToStr(Date()) +  " " + CurrentTimeStr() + " FAIL: " + m_psRct->as_RCT + " < Power = " +
  289.                                        Double_To_AnsiString(m_psRfRtc->d_P_DL) + " dBm" );
  290.                 write_log_file();
  291.                 return;
  292.             }
  293.         }
  294.         else
  295.         {
  296.             if (!m_rct_ctrl.RCT_sig_cellPower(m_psRct, m_psRfRtc->d_P_DL))
  297.             {
  298.                 PostMessage(m_psRfRtc->hPostMsgDestHandle,
  299.                             WM_ML_RCT_SET_DOWNLINK_POWER_FAIL,
  300.                             0,
  301.                             0
  302.                             );
  303.                 m_psRfRtc->p_stLog->Add(DateToStr(Date()) +  " " + CurrentTimeStr() + " FAIL: " + m_psRct->as_RCT + " < Power = " +
  304.                                        Double_To_AnsiString(m_psRfRtc->d_P_DL) + " dBm");
  305.                 write_log_file();
  306.                 return;
  307.             }
  308.             if (!m_rct_ctrl.RCT_sig_TCHLevel(m_psRct, -70.0))
  309.             {
  310.                 PostMessage(m_psRfRtc->hPostMsgDestHandle,
  311.                             WM_ML_RCT_SET_TCH_LEVEL_FAIL,
  312.                             0,
  313.                             0
  314.                             );
  315.                 m_psRfRtc->p_stLog->Add(DateToStr(Date()) +  " " + CurrentTimeStr() + " FAIL: cmu200 < Power = " +
  316.                                        Double_To_AnsiString(-70.0) + " dBm");
  317.                 write_log_file();
  318.                 return;
  319.             }
  320.         }
  321.         if (this->Terminated)
  322.         {
  323.             this->OnTerminate = m_psRfRtc->ne_onTermByUser;
  324.             return;
  325.         }
  326.         if (AGILENT_8960 == m_psRct->device_type)
  327.         {
  328.             if (!m_rct_ctrl.RCT_BCHARFCN(m_psRct, m_psRfRtc->s_arfcn))
  329.             {
  330.                 PostMessage(m_psRfRtc->hPostMsgDestHandle,
  331.                             WM_ML_RCT_SET_BCH_ARFCN_FAIL,
  332.                             0,
  333.                             0
  334.                             );
  335.                 m_psRfRtc->p_stLog->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  336.                               " FAIL : "+
  337.                               m_psRct->as_RCT + " < BCH ARFCN = " + IntToStr( m_psRfRtc->s_arfcn )
  338.                     );
  339.                 write_log_file();
  340.                 return;
  341.             }
  342.         }
  343.         else
  344.         {
  345.             if (!m_rct_ctrl.RCT_sig_BCHARFCN(m_psRct, m_psRfRtc->s_arfcn))
  346.             {
  347.                 PostMessage(m_psRfRtc->hPostMsgDestHandle,
  348.                             WM_ML_RCT_SET_BCH_ARFCN_FAIL,
  349.                             0,
  350.                             0
  351.                             );
  352.                 m_psRfRtc->p_stLog->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  353.                               " FAIL :"+
  354.                               m_psRct->as_RCT + " < BCH ARFCN = " + IntToStr(m_psRfRtc->s_arfcn )
  355.                     );
  356.                 write_log_file();
  357.                 return;
  358.             }
  359.         }
  360.         if (this->Terminated)
  361.         {
  362.             this->OnTerminate = m_psRfRtc->ne_onTermByUser;
  363.             return;
  364.         }
  365.         if (AGILENT_8960 == m_psRct->device_type)
  366.         {
  367.             if (!m_rct_ctrl.RCT_TCHARFCN(m_psRct, m_psRfRtc->s_arfcn))
  368.             {
  369.                 PostMessage(m_psRfRtc->hPostMsgDestHandle,
  370.                             WM_ML_RCT_SET_TCH_ARFCN_FAIL,
  371.                             0,
  372.                             0
  373.                             );
  374.                 m_psRfRtc->p_stLog->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  375.                               " FAIL :"+
  376.                               m_psRct->as_RCT + " < TCH ARFCN = " + IntToStr(m_psRfRtc->s_arfcn)
  377.                         );
  378.                 write_log_file();
  379.                 return;
  380.             }
  381.         }
  382.         else
  383.         {
  384.             if (!m_rct_ctrl.RCT_sig_TCHARFCN(m_psRct, m_psRfRtc->s_arfcn))
  385.             {
  386.                 PostMessage(m_psRfRtc->hPostMsgDestHandle,
  387.                             WM_ML_RCT_SET_TCH_ARFCN_FAIL,
  388.                             0,
  389.                             0
  390.                             );
  391.                 m_psRfRtc->p_stLog->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  392.                               " FAIL :"+
  393.                               m_psRct->as_RCT + " < TCH ARFCN = " + IntToStr(m_psRfRtc->s_arfcn)
  394.                             );
  395.                 write_log_file();
  396.                 return;
  397.             }
  398.         }
  399.         if (this->Terminated)
  400.         {
  401.             this->OnTerminate = m_psRfRtc->ne_onTermByUser;
  402.             return;
  403.         }
  404.         if (AGILENT_8960 == m_psRct->device_type)
  405.         {
  406.             if (!m_rct_ctrl.RCT_TCHTimeslot(m_psRct, TIMESLOT_3))
  407.             {
  408.                 PostMessage(m_psRfRtc->hPostMsgDestHandle,
  409.                             WM_ML_RCT_SET_TCH_TIMESLOT_FAIL,
  410.                             0,
  411.                             0
  412.                             );
  413.                 m_psRfRtc->p_stLog->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  414.                               " FAIL :"+
  415.                               m_psRct->as_RCT + " < timeslot = " + IntToStr( TIMESLOT_3 )
  416.                             );
  417.                 write_log_file();
  418.                 return;
  419.             }
  420.         }
  421.         else
  422.         {
  423.             if (!m_rct_ctrl.RCT_sig_TCHTimeslot(m_psRct, TIMESLOT_3))
  424.             {
  425.                 PostMessage(m_psRfRtc->hPostMsgDestHandle,
  426.                             WM_ML_RCT_SET_TCH_TIMESLOT_FAIL,
  427.                             0,
  428.                             0
  429.                             );
  430.                 m_psRfRtc->p_stLog->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  431.                               " FAIL :"+
  432.                               m_psRct->as_RCT + " < timeslot = " + IntToStr(TIMESLOT_3)
  433.                             );
  434.                 write_log_file();
  435.                 return;
  436.             }
  437.         }
  438.         if (this->Terminated)
  439.         {
  440.             this->OnTerminate = m_psRfRtc->ne_onTermByUser;
  441.             return;
  442.         }
  443.         if (AGILENT_8960 == m_psRct->device_type)
  444.         {
  445.             if (!m_rct_ctrl.RCT_ConfigTSC(m_psRct, m_psRfRtc->c_tsc))
  446.             {
  447.                 PostMessage(m_psRfRtc->hPostMsgDestHandle,
  448.                             WM_ML_RCT_SET_TSC_FAIL,
  449.                             0,
  450.                             0
  451.                             );
  452.                 m_psRfRtc->p_stLog->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  453.                               "FAIL : " + m_psRct->as_RCT + " < set TSC fail."
  454.                             );
  455.                 write_log_file();
  456.                 return;
  457.             }
  458.         }
  459.         else
  460.         {
  461.             if (!m_rct_ctrl.RCT_sig_ConfigTSC(m_psRct, 0))
  462.             {
  463.                 PostMessage(m_psRfRtc->hPostMsgDestHandle,
  464.                             WM_ML_RCT_SET_TSC_FAIL,
  465.                             0,
  466.                             0
  467.                             );
  468.                 m_psRfRtc->p_stLog->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  469.                           " FAIL : " + m_psRct->as_RCT + " < TSC = " + IntToStr( 0 )
  470.                         );
  471.                 write_log_file();
  472.                 return;
  473.             }
  474.         }
  475.         if (this->Terminated)
  476.         {
  477.             this->OnTerminate = m_psRfRtc->ne_onTermByUser;
  478.             return;
  479.         }
  480.         // FB detection
  481.         unsigned char selectPCS1900;
  482.         if (BANDSEL_PCS1900 == m_psRfRtc->e_band)
  483.         {
  484.             selectPCS1900 = 1;
  485.         }
  486.         else
  487.         {
  488.             selectPCS1900 = 0;
  489.         }
  490.         short MF_SelectBand_token;
  491.         if (META_Rf_SelectFrequencyBand1900_r(m_META_HANDLE_Obj.Get_MainHandle(), selectPCS1900, ::CNF_SelectPcs1900, &MF_SelectBand_token, NULL) !=  META_SUCCESS)
  492.         {
  493.             PostMessage(m_psRfRtc->hPostMsgDestHandle,
  494.                         WM_ML_RF_SELECT_BAND_FAIL,
  495.                         0,
  496.                         0
  497.                         );
  498.             m_psRfRtc->p_stLog->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  499.                       " FAIL : Target < set Band1900 flag = " + IntToStr(selectPCS1900)
  500.                     );
  501.             return;
  502.         }
  503.         this->Suspend();
  504.         if (!m_ucSelectPcsCnf)
  505.         {
  506.             PostMessage(m_psRfRtc->hPostMsgDestHandle,
  507.                         WM_ML_RF_SELECT_BAND_FAIL,
  508.                         0,
  509.                         0
  510.                         );
  511.             m_psRfRtc->p_stLog->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  512.                       " FAIL : Target < set Band1900 flag = " + IntToStr(selectPCS1900) +
  513.                       " CNF"
  514.                     );
  515.             return;
  516.         }
  517.         if (this->Terminated)
  518.         {
  519.             this->OnTerminate = m_psRfRtc->ne_onTermByUser;
  520.             return;
  521.         }
  522.         Sleep(100);
  523.         short dacValue[2];
  524.         dacValue[0] = 3800;
  525.         dacValue[1] = 4200;
  526.         int freqOffset[2];
  527.         for (int i=0; i<2; i++)
  528.         {
  529.             RfAfc_Req afc_req;
  530.             afc_req.dacValue = dacValue[i];
  531.             afc_req.arfcn    = m_psRfRtc->s_arfcn;
  532.             afc_req.gain     = (MF_RF_GAIN_TO_BE_SUB - m_psRfRtc->d_P_DL) * GAIN_REQUEST_PC_SIDE_MULTIPLY;
  533.             afc_req.testNumber = 10;
  534.             short MF_rf_afc_token;
  535.             if (META_Rf_AFC_r(m_META_HANDLE_Obj.Get_MainHandle(), &afc_req, ::CNF_RfAfc, &MF_rf_afc_token, NULL) != META_SUCCESS)
  536.             {
  537.                 PostMessage(m_psRfRtc->hPostMsgDestHandle,
  538.                             WM_ML_RF_AFC_CONTROL_FAIL,
  539.                             0,
  540.                             0
  541.                            );
  542.                 m_psRfRtc->p_stLog->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  543.                                     " FAIL : Target < AFC: ARFCN = "+ IntToStr(afc_req.arfcn) +
  544.                                     ", dac value = "+ IntToStr(afc_req.dacValue) +
  545.                                     ", gain = " + Double_To_AnsiString(afc_req.gain/RF_RX_GAIN_SCALE) + " dB" +
  546.                                     ", testing number = " + IntToStr(10)
  547.                                    );
  548.                 return;
  549.             }
  550.             this->Suspend();
  551.             if ((STATUS_AFC_OK != (E_AFC_STATUS_T)m_sRfAfcCnf.ok) ||
  552.                 (m_sRfAfcCnf.fcb_ok_number <= 0)
  553.                )
  554.             {
  555.                 PostMessage(m_psRfRtc->hPostMsgDestHandle,
  556.                         WM_ML_RF_AFC_CONTROL_FAIL,
  557.                         0,
  558.                         0
  559.                         );
  560.                 m_psRfRtc->p_stLog->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  561.                                     " FAIL : Target > AFC CNF: fcb_ok_number = "+ IntToStr(m_sRfAfcCnf.fcb_ok_number) +
  562.                                     ", freqOffset = "+ IntToStr(m_sRfAfcCnf.freqOffset) +
  563.                                     ", deviation = " + IntToStr(m_sRfAfcCnf.deviation) +
  564.                                     ", ok = " + IntToStr(m_sRfAfcCnf.ok)
  565.                                    );
  566.                 return;
  567.             }
  568.             freqOffset[i] = m_sRfAfcCnf.freqOffset;
  569.         }
  570.         if (this->Terminated)
  571.         {
  572.             this->OnTerminate = m_psRfRtc->ne_onTermByUser;
  573.             return;
  574.         }
  575.         CRFAFC RF_AFC_Obj;
  576.        // float Afc_Slope_factor = RF_AFC_Obj.Get_Afc_Slope_factor(m_psRfRtc->e_band);
  577.         double d_Slope = (double)(freqOffset[0] - freqOffset[1])/(double)(dacValue[1] - dacValue[0]);
  578.         short sDefault_value = (unsigned short) ((freqOffset[0]/d_Slope)+ dacValue[0]);
  579.         if (AGILENT_8960 == m_psRct->device_type)
  580.         {
  581.             if (!m_rct_ctrl.RCT_MSTXLevel(m_psRct, m_psRfRtc->s_pcl))
  582.             {
  583.                 PostMessage(m_psRfRtc->hPostMsgDestHandle,
  584.                             WM_ML_RCT_SET_MS_TX_LEVEL_FAIL,
  585.                             0,
  586.                             0
  587.                             );
  588.                 m_psRfRtc->p_stLog->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  589.                       " FAIL : " + m_psRct->as_RCT + " < MS TX level = " + IntToStr(m_psRfRtc->s_pcl)
  590.                     );
  591.                 write_log_file();
  592.                 return;
  593.             }
  594.         }
  595.         else
  596.         {
  597.             if (!m_rct_ctrl.RCT_sig_MSTXLevel(m_psRct, m_psRfRtc->s_pcl))
  598.             {
  599.                 PostMessage(m_psRfRtc->hPostMsgDestHandle,
  600.                             WM_ML_RCT_SET_MS_TX_LEVEL_FAIL,
  601.                             0,
  602.                             0
  603.                             );
  604.                 m_psRfRtc->p_stLog->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  605.                       " FAIL : " + m_psRct->as_RCT + " < MS TX level = " + IntToStr( m_psRfRtc->s_pcl )
  606.                     );
  607.                 write_log_file();
  608.                 return;
  609.             }
  610.         }
  611.         if (this->Terminated)
  612.         {
  613.             this->OnTerminate = m_psRfRtc->ne_onTermByUser;
  614.             return;
  615.         }
  616.     // TX NB
  617.     CRFSTOP rf_stop_obj;
  618.     if (!rf_stop_obj.REQ_Start())
  619.     {
  620.         PostMessage(m_psRfRtc->hPostMsgDestHandle,
  621.                     WM_ML_RF_STOP_FAIL,
  622.                     0,
  623.                     0
  624.                     );
  625.         m_psRfRtc->p_stLog->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  626.                           " FAIL: Target < stop RF fail."
  627.                  );
  628.         return;
  629.     }
  630.     Sleep(50);
  631.     short s_token;
  632.     RfNbtx_Req req;
  633.     req.arfcn       = m_psRfRtc->s_arfcn;
  634.     if (AGILENT_8960 == m_psRct->device_type)
  635.     {
  636.         req.bsic = m_psRfRtc->c_tsc;
  637.     }
  638.     else
  639.     {
  640.         req.bsic = 0;
  641.     }
  642.     req.power       = m_psRfRtc->s_pcl;
  643.     req.frames      = -99;
  644.     req.dacValue    = sDefault_value | MASK_AFC_TRACKING;
  645.     req.burstTypeNB = NB_TX_RANDOM_WITH_TSC;
  646.     if (META_Rf_NB_TX_r(m_META_HANDLE_Obj.Get_MainHandle(),
  647.                         &req,
  648.                         ::CNF_RfNbTx,
  649.                         &s_token,
  650.                         NULL
  651.                         ) != META_SUCCESS)
  652.     {
  653.         PostMessage(m_psRfRtc->hPostMsgDestHandle,
  654.                     WM_ML_RF_TX_LEVEL_FAIL,
  655.                     0,
  656.                     0
  657.                     );
  658.         m_psRfRtc->p_stLog->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  659.                       " FAIL : Target< ARFCN = " + IntToStr(m_psRfRtc->s_arfcn) +
  660.                       ", TSC = " + IntToStr(req.bsic) +
  661.                       ", power = " + IntToStr(m_psRfRtc->s_pcl) +
  662.                       ", frames = " + IntToStr(req.frames) +
  663.                       ", dac value = " + IntToStr(sDefault_value)
  664.                     );
  665.             return;
  666.         }
  667.         this->Suspend();
  668.         if (!m_ucNbTxCnf)
  669.         {
  670.             PostMessage(m_psRfRtc->hPostMsgDestHandle,
  671.                         WM_ML_RF_TX_LEVEL_FAIL,
  672.                         0,
  673.                         0
  674.                         );
  675.             m_psRfRtc->p_stLog->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  676.                       " FAIL: TX level confirm."
  677.                     );
  678.             return;
  679.         }
  680.     char buf[256];
  681.     AnsiString as_str;
  682.     as_str = "RTC clock(Hz) clock/32768";
  683.     sprintf(buf, as_str.c_str());
  684.     m_psRfRtc->p_stLog->Add(buf);
  685.     write_log_file();
  686.     // config euqipment
  687.     for (unsigned int i=0; i<m_psRfRtc->ui_test_count; i++)
  688.     {
  689.         if (this->Terminated)
  690.         {
  691.             this->OnTerminate = m_psRfRtc->ne_onTermByUser;
  692.             return;
  693.         }
  694.         int iResult;
  695.         META_RESULT MetaResult = META_Rf_32kCalibration_r(m_META_HANDLE_Obj.Get_MainHandle(), 3000, &iResult);
  696.         if (MetaResult != META_SUCCESS)
  697.         {
  698.             return;
  699.         }
  700.         double d_rtc_clock = (13000000.0*8192.0*2.0)/iResult;
  701.         double d_norm_rtc_clock = d_rtc_clock / 32768.0;
  702.         sprintf(buf, "%.2f      %f", d_rtc_clock, d_norm_rtc_clock);
  703.         m_psRfRtc->p_stLog->Add(buf);
  704.         write_log_file();
  705.         PostMessage(m_psRfRtc->hPostMsgDestHandle,
  706.                     WM_ML_RTC_PRINT_MSG,
  707.                     (int) d_rtc_clock *100,
  708.                     0
  709.                     );
  710.         if (Abs_double(d_norm_rtc_clock-1) > 0.0004)
  711.         {
  712.             PostMessage(m_psRfRtc->hPostMsgDestHandle,
  713.                         WM_ML_RTC_CLOCK_OUT_OF_RANGE_MSG,
  714.                         (int) d_rtc_clock *100,
  715.                         0
  716.                        );
  717.             return;
  718.         }
  719.         Sleep(m_psRfRtc->ui_period);
  720.     }
  721.     if (!rf_stop_obj.REQ_Start())
  722.     {
  723.         PostMessage(m_psRfRtc->hPostMsgDestHandle,
  724.                     WM_ML_RF_STOP_FAIL,
  725.                     0,
  726.                     0
  727.                     );
  728.         m_psRfRtc->p_stLog->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  729.                           " FAIL: Target < stop RF fail."
  730.                  );
  731.         return;
  732.     }
  733.     this->OnTerminate = m_psRfRtc->ne_onTermSuccess;
  734. }
  735. //---------------------------------------------------------------------------
  736. void CRFRTC::read_cfg_file(void)
  737. {
  738.     // Agilent 8960
  739.     m_psRfRtc->p_cfg->getGSM400_CableLoss(m_psRct->age.d400);
  740.     m_psRfRtc->p_cfg->getGSM850_CableLoss(m_psRct->age.d850);
  741.     m_psRfRtc->p_cfg->getGSM900_CableLoss(m_psRct->age.d900);
  742.     m_psRfRtc->p_cfg->getDCS1800_CableLoss(m_psRct->age.d1800);
  743.     m_psRfRtc->p_cfg->getPCS1900_CableLoss(m_psRct->age.d1900);
  744.     m_psRfRtc->p_cfg->getTimeOut(m_psRct->age.TMO);
  745.     m_psRfRtc->p_cfg->getGPIB_Addr(m_psRct->age.ADD);
  746.     // CMU 200
  747.     m_psRfRtc->p_cfg->getCMU200_INPUT_GSM850_CableLoss(m_psRct->cmu.loss_gsm850_i);
  748.     m_psRfRtc->p_cfg->getCMU200_INPUT_GSM900_CableLoss(m_psRct->cmu.loss_gsm_i);
  749.     m_psRfRtc->p_cfg->getCMU200_INPUT_DCS1800_CableLoss(m_psRct->cmu.loss_dcs_i);
  750.     m_psRfRtc->p_cfg->getCMU200_INPUT_PCS1900_CableLoss(m_psRct->cmu.loss_pcs_i);
  751.     m_psRfRtc->p_cfg->getCMU200_OUTPUT_GSM850_CableLoss(m_psRct->cmu.loss_gsm850_o);
  752.     m_psRfRtc->p_cfg->getCMU200_OUTPUT_GSM900_CableLoss(m_psRct->cmu.loss_gsm_o);
  753.     m_psRfRtc->p_cfg->getCMU200_OUTPUT_DCS1800_CableLoss(m_psRct->cmu.loss_dcs_o);
  754.     m_psRfRtc->p_cfg->getCMU200_OUTPUT_PCS1900_CableLoss(m_psRct->cmu.loss_pcs_o);
  755.     m_psRfRtc->p_cfg->getCMU200_TimeOut(m_psRct->cmu.TMO);
  756.     m_psRfRtc->p_cfg->getCMU200_GPIB_Addr(m_psRct->cmu.ADD);
  757.     m_psRct->cmu.ADD = m_psRct->cmu.ADD.SubString(0, m_psRct->cmu.ADD.Pos("::INSTR")-1);
  758. }
  759. //---------------------------------------------------------------------------
  760. void CRFRTC::write_log_file(void)
  761. {
  762.     FILE *pf;
  763.     try
  764.     {
  765.         if (m_psRfRtc->as_LogFile.AnsiCompareIC("") != 0)
  766.         {
  767.             if ((pf = fopen(m_psRfRtc->as_LogFile.c_str() ,"at+"))== NULL)
  768.             {
  769.                 AnsiString as_warring_msg;
  770.                 as_warring_msg = "Cannot open output file: " + m_psRfRtc->as_LogFile;
  771.                 Application->MessageBox(as_warring_msg.c_str() , "Warning", MB_OK);
  772.                 return;
  773.             }
  774.             for (int I=0; I<m_psRfRtc->p_stLog->Count; I++)
  775.             {
  776.                 fprintf(pf, AnsiString(m_psRfRtc->p_stLog->Strings[I] + "n").c_str());
  777.             } // for
  778.             fclose(pf);
  779.             m_psRfRtc->p_stLog->Clear();
  780.         } // if
  781.     } // try
  782.     catch(...)
  783.     {
  784.         AnsiString as_warning_msg;
  785.         as_warning_msg = " write log file error " + m_psRfRtc->as_LogFile;
  786.         Application->MessageBox(as_warning_msg.c_str(), "Warning", MB_OK);
  787.     }
  788. }