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

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.  *   META_Factory.cpp
  40.  *
  41.  * Project:
  42.  * --------
  43.  *   Maui META APP
  44.  *
  45.  * Description:
  46.  * ------------
  47.  *  META factory form 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. //---------------------------------------------------------------------------
  66. #include <vcl.h>
  67. #include <inifiles.hpp>
  68. #include <stdio.h>
  69. #pragma hdrstop
  70. // misc
  71. #ifndef  _FT_UTILS_H_
  72. #include "ft_utils.h"
  73. #endif
  74. #ifndef  _TIME_UTILS_H_
  75. #include "time_utils.h"
  76. #endif
  77. #ifndef  _MISC_BARCODE_H_
  78. #include "misc_barcode.h"
  79. #endif
  80. #ifndef  _MISC_IMEI_H_
  81. #include "misc_imei.h"
  82. #endif
  83. // equipment
  84. #ifndef  _RCT_COMMON_H_
  85. #include "rct_common.h"
  86. #endif
  87. #ifndef  _DCS_COMMON_H_
  88. #include "dcs_common.h"
  89. #endif
  90. #include "META_factory_cfg.h"
  91. #include "meta_msg.h"
  92. #include "META_Factory.h"
  93. #include "META_factory_reboot_go.h"
  94. #include "META_error_handler.h"
  95. #include "META_Factory_AboutU.h"
  96. #include "com_utils.h"
  97. #include "TFT_Boot.h"
  98. #include "T_Init_Age8960.h"
  99. #include "meta_utils.h"
  100. #include "T_META_factory_calibration.h"
  101. ///
  102. #include "rf_apc.h"
  103. #include "rf_agc.h"
  104. #include "rf_afc.h"
  105. #include "crystal_afc.h"
  106. #include "man_dll.h"
  107. // form
  108. #include "form_Main.h"
  109. #include "form_CalPath.h"
  110. #include "form_CFGAfc.h"
  111. #include "form_CFGCrystalAfc.h"
  112. #include "form_CFGRxPathLoss.h"
  113. #include "form_CFGTxPcl.h"
  114. #ifndef form_CFGPhErrH
  115. #include "form_CFGPhErr.h"
  116. #endif
  117. #include "form_CFGADC.h"
  118. #include "form_CFGCommon.h"
  119. // ADC calibration
  120. #include "META_factory_ADC_cfg.h"
  121. // message
  122. #ifndef _META_LAB_MSG_H_
  123. #include "meta_lab_msg.h"
  124. #endif
  125. // query
  126. #ifndef  _QUERY_COMMON_H_
  127. #include "query_common.h"
  128. #endif
  129. #ifndef  _GNRL_MSCAP_H_
  130. #include "gnrl_mscap.h"
  131. #endif
  132. // handle
  133. #ifndef  _MAN_HANDLE_H_
  134. #include "man_handle.h"
  135. #endif
  136. //RF
  137. #ifndef _RF_MULTISLOTTX_H_
  138. #include "rf_multislottx.h"
  139. #endif
  140. // WiFi
  141. #ifndef  _WIFI_ALC_H_
  142. #include "wifi_alc.h"
  143. #endif
  144. //------------------------------------------------------------------------------
  145. #define MIN_FACTORY_ID 0
  146. #define MAX_FACTORY_ID 10000000000
  147. //---------------------------------------------------------------------------
  148. #pragma package(smart_init)
  149. #pragma resource "*.dfm"
  150. //------------------------------------------------------------------------------
  151. //------------------------------------------------------------------------------
  152. // equipment
  153. //extern CMU_VAR cmu;
  154. TfrmFatcory *frmFatcory;
  155. HANDLE hForm_PostMsgTarget;
  156. HANDLE hForm_MF;
  157. // AGC
  158. CRFAGC*  MF_rf_agc_ptr;
  159. // IP2
  160. CRFPM*   MF_rf_pm_ptr;
  161. // AFC
  162. CRFAFC*  MF_rf_afc_ptr;
  163. RfAfc_Req *MF_rf_afc_req;
  164. RfAfc_Cnf *MF_rf_afc_cnf;
  165. //RfSetAfcDacValue_Req *MF_rf_SetAfcDacValue;
  166. unsigned char RfSetAfcDacCnf = false;
  167. // crystal AFC
  168. CCRYSTALAFC* MF_crystal_afc_ptr;
  169. CBBREG* MF_bb_reg_ptr;
  170. // APC
  171. CRFAPC*  MF_rf_apc_ptr;
  172. CRFAPC8PSK*  MF_rf_apc_8psk_ptr;
  173. RfNbtx_Req *MF_rf_tx_level_req;
  174. bool MF_rf_tx_level_cnf;
  175. // phase error
  176. CRFTXIQ*  MF_rf_txiq_ptr;
  177. // ADC
  178. CBBADC* MF_BB_ADC_ptr;
  179. ADCMeaData_Req* MF_BB_ADC_Req;
  180. ADCMeaData_Cnf    *BBCnf_ADC;
  181. // Thread
  182. T_META_factory_calibration* pt_calibration;
  183. RfPm_Req  *MF_rf_pm_req;
  184. RfPm_Cnf  *MF_rf_pm_cnf;
  185. bool first_FactoryForm_Show = true;
  186. bool is_calibration_start = false;
  187. int TimerCalTimeoutID;
  188. // ADC
  189. int TimerADCCalTimeoutID;
  190. extern TfrmMainSel *frmMainSel; 
  191. extern  CNVRAMMan  *NVRAMMan;
  192. extern bool  is_suspend_cal; // in T_META_factory_calibration.cpp
  193. extern bool IS_AgilentPowerSupply_INITIALISE;  // in T_Init_Age8960.cpp
  194. extern HANDLE hCOM;  // in META_LAB_MainU.cpp
  195. extern bool is_age1960_fail;  // in T_Init_Age8960.cpp
  196. extern bool is_AgilentPowerSupply_fail; // in T_Init_Age8960.cpp
  197. // query
  198. extern T_RFTADO*      pt_rftado;
  199. extern T_RFID*      pt_rfid;
  200. //extern bool is_Age8960_start;
  201. // reconnect
  202. bool IsReconnectByFactory = false;
  203. extern bool isBootTarget;
  204. //extern bool Bootok;
  205. extern bool g_bHideEnable;
  206. //===========================================================================
  207. ////////////////////////  static function ///////////////////////////////////
  208. //===========================================================================
  209. static  void  CNF_NVRAMInitial( void )
  210. {
  211.     frmFatcory->CNF_NVRAMInitial();
  212. }
  213. //---------------------------------------------------------------------------
  214. static void CNF_ReadFromNVRAM( void )
  215. {   frmFatcory->UploadFromFlashDone();
  216. }
  217. //---------------------------------------------------------------------------
  218. static void  CNF_WriteToNVRAM( void )
  219. {   frmFatcory->DownloadToFlashDone();
  220. }
  221. //--------------------------------------------------------------------------
  222. static void  CNF_ReadIP2FromNVRAM( void )
  223. {
  224.     frmFatcory->CNF_ReadIP2FromNVRAM();
  225. }
  226. //--------------------------------------------------------------------------
  227. static void  CNF_WriteIP2ToNVRAM( void )
  228. {
  229.     frmFatcory->CNF_WriteIP2ToNVRAM();
  230. }
  231. //---------------------------------------------------------------------------
  232. bool  IsValidFactoryID( AnsiString &ansi_str, int &factory_id )
  233. {
  234.    bool  invalid = true;
  235.    RANGE_CHECK_ERROR( !AnsiString_To_Integer( ansi_str, factory_id, MIN_FACTORY_ID, MAX_FACTORY_ID ), RANGE_ERR_FACTORY_ID );
  236.    if((factory_id >= MIN_FACTORY_ID)&&(factory_id <=MAX_FACTORY_ID))
  237.    {  invalid = false;
  238.    }
  239.    RANGE_CHECK_ERROR( invalid, RANGE_ERR_FACTORY_ID );
  240.    return( true );
  241. }
  242. //---------------------------------------------------------------------------
  243. __fastcall TfrmFatcory::TfrmFatcory(TComponent* Owner)
  244.         : TForm(Owner)
  245. {
  246.     m_Rct.cmu.RM       = NULL;
  247.     m_Rct.cmu.base     = NULL;
  248.     m_Rct.cmu.gsm      = NULL;
  249.     m_Rct.cmu.dcs      = NULL;
  250.     m_Rct.cmu.pcs      = NULL;
  251.     m_Rct.cmu.gsm850   = NULL;
  252.     m_Rct.cmu.s_gsm    = NULL;
  253.     m_Rct.cmu.s_dcs    = NULL;
  254.     m_Rct.cmu.s_pcs    = NULL;
  255.     m_Rct.cmu.s_gsm850 = NULL;
  256.     m_Rct.age.vi       = NULL;
  257.     m_sBtt.cmu.s_bt = NULL;
  258. }
  259. //---------------------------------------------------------------------------
  260. //---------------------------------------------------------------------------
  261. void TfrmFatcory::CNF_NVRAMInitial(void)
  262. {
  263.     E_METAAPP_RESULT_T state = NVRAMMan->Get_ConfirmState();
  264.     if (METAAPP_NVRAM_INIT_FAIL == state)
  265.     {
  266.         Application->MessageBox( "Execution Failure : Initial NVRAM database", "FAILURE", MB_OK );
  267.     }
  268.     else if(METAAPP_TIMEOUT ==  state)
  269.     {
  270.         Application->MessageBox( "Execution Timeout : Initial NVRAM database", "TIMEOUT", MB_OK );
  271.     }
  272. }
  273. //---------------------------------------------------------------------------
  274. void _fastcall TfrmFatcory::SubClassWndProc( Messages::TMessage &Message)
  275. {
  276.     AnsiString as_readTXPower_Q_error;
  277.     switch ( Message.Msg )
  278.     {
  279.         ////////////////////////////////////  Query   //////////////////////////
  280.         // RF ID
  281.        // case WM_ML_QUERY_RFID_SUCCESS:
  282.        // {
  283.        //     DisplayIP2Visible( t_rf_id.ui_rf_id.RfModId.id );
  284.        //     m_Cal.ui_rf_id = t_rf_id.ui_rf_id.RfModId.id;
  285.        // }
  286.        // break;
  287.        //
  288.        // case WM_ML_QUERY_RFID_FAILED:
  289.        // {
  290.        //     cbIP2->Visible = false;
  291.        //     cbIP2->Checked = false;
  292.        //     m_Cal.ui_rf_id = RF_ID_UNKNOWN;
  293.       //  }
  294.       //  break;
  295.         //////////////////////////   Agilent 8960   ////////////////////////////
  296.         case WM_MF_AGE8960_SET_OPERATION_MODE_FAIL:
  297.         {
  298.             lb_META_factory_status->Font->Color = clRed;
  299.             lb_META_factory_status->Caption = m_Rct.as_RCT + " set operation mode fail!";
  300.             MF_state = eError;
  301.             write_log();
  302.         }
  303.         break;
  304.         case WM_MF_RCT_SET_CABLE_LOSS_FAIL:
  305.         {
  306.             lb_META_factory_status->Font->Color = clRed;
  307.             lb_META_factory_status->Caption = m_Rct.as_RCT + " set cable loss fail!";
  308.             MF_state = eError;
  309.             write_log();
  310.         }
  311.         break;
  312.         case WM_MF_AGE8960_SET_CODING_SCHEME_FAIL:
  313.         {
  314.             lb_META_factory_status->Font->Color = clRed;
  315.             lb_META_factory_status->Caption = m_Rct.as_RCT + " set coding scheme fail!";
  316.             MF_state = eError;
  317.             write_log();
  318.             //write_result();
  319.         }
  320.         break;
  321.         case WM_MF_AGE8960_INIT_FAIL:
  322.         {
  323.             lb_META_factory_status->Font->Color = clRed;
  324.             lb_META_factory_status->Caption = m_Rct.as_RCT + " initialize fail!";
  325.             MF_state = eError;
  326.             write_log();
  327.             //write_result(); // added by Andy Ueng
  328.         }
  329.         break;
  330.         case WM_MF_AGE8960_DCL_FAIL:
  331.         {
  332.             lb_META_factory_status->Font->Color = clRed;
  333.             lb_META_factory_status->Caption = m_Rct.as_RCT + " dcl fail!";
  334.             MF_state = eError;
  335.             write_log();
  336.             //write_result(); // added by Andy Ueng
  337.         }
  338.         break;
  339.         case WM_MF_AGE8960_RESET_FAIL:
  340.         {
  341.             lb_META_factory_status->Font->Color = clRed;
  342.             lb_META_factory_status->Caption = m_Rct.as_RCT + " reset fail!";
  343.             MF_state = eError;
  344.             write_log();
  345.         }
  346.         break;
  347.         case WM_MF_AGE8960_SET_BAND_FAIL:
  348.         {
  349.             lb_META_factory_status->Font->Color = clRed;
  350.             lb_META_factory_status->Caption = m_Rct.as_RCT + " set band fail!";
  351.             MF_state = eError;
  352.             write_log();
  353.             //write_result(); // added by Andy Ueng
  354.         }
  355.         break;
  356.         case WM_MF_AGE8960_SET_TRAN_CONT_FAIL:
  357.         {
  358.             lb_META_factory_status->Font->Color = clRed;
  359.             lb_META_factory_status->Caption = m_Rct.as_RCT + " set transmit continous fail!";
  360.             MF_state = eError;
  361.             write_log();
  362.         }
  363.         break;
  364.         case WM_MF_AGE8960_SET_TRAN_BURST_FAIL:
  365.         {
  366.             lb_META_factory_status->Font->Color = clRed;
  367.             lb_META_factory_status->Caption = m_Rct.as_RCT + " set transmit burst fail!";
  368.             MF_state = eError;
  369.             write_log();
  370.         }
  371.         break;
  372.         case WM_MF_AGE8960_SET_BCH_ARFCN_FAIL:
  373.         {
  374.             lb_META_factory_status->Font->Color = clRed;
  375.             lb_META_factory_status->Caption = m_Rct.as_RCT + " set BCH ARFCN fail!";
  376.             MF_state = eError;
  377.             write_log();
  378.         }
  379.         break;
  380.         // ---------------------------------------  cmu  ------------------
  381.         case WM_MF_AGE8960_SET_RF_GENERATOR_FAIL:
  382.         {
  383.             lb_META_factory_status->Font->Color = clRed;
  384.             lb_META_factory_status->Caption = m_Rct.as_RCT + " set RF generator fail!";
  385.             MF_state = eError;
  386.             write_log();
  387.             //write_result(); // added by Andy Ueng
  388.         }
  389.         break;
  390.         case WM_MF_AGE8960_SET_BURST_TRANSMIT_FAIL:
  391.         {
  392.             lb_META_factory_status->Font->Color = clRed;
  393.             lb_META_factory_status->Caption = m_Rct.as_RCT + " set burst transmit mode fail!";
  394.             MF_state = eError;
  395.             write_log();
  396.             //write_result(); // added by Andy Ueng
  397.         }
  398.         break;
  399.         case WM_MF_AGE8960_SET_GENERATOR_TSC_FAIL:
  400.         {
  401.             lb_META_factory_status->Font->Color = clRed;
  402.             lb_META_factory_status->Caption = m_Rct.as_RCT + " set generator TSC fail!";
  403.             MF_state = eError;
  404.             write_log();
  405.             //write_result(); // added by Andy Ueng
  406.         }
  407.         break;
  408.         case WM_MF_AGE8960_SET_BIT_MODULATION_FAIL:
  409.         {
  410.             lb_META_factory_status->Font->Color = clRed;
  411.             lb_META_factory_status->Caption = m_Rct.as_RCT + " set bit modulation fail!";
  412.             MF_state = eError;
  413.             write_log();
  414.             //write_result(); // added by Andy Ueng
  415.         }
  416.         break;
  417.         case WM_MF_AGE8960_SET_POWER_FAIL:
  418.         {
  419.             lb_META_factory_status->Font->Color = clRed;
  420.             lb_META_factory_status->Caption = m_Rct.as_RCT + " set power fail!";
  421.             MF_state = eError;
  422.             write_log();
  423.         }
  424.         break;
  425.         case WM_MF_AGE8960_SET_TSC_FAIL:
  426.         {
  427.             lb_META_factory_status->Font->Color = clRed;
  428.             lb_META_factory_status->Caption = m_Rct.as_RCT + " set TSC fail!";
  429.             MF_state = eError;
  430.             write_log();
  431.         }
  432.         break;
  433.         case WM_MF_AGE8960_SET_TCH_ARFCN_FAIL:
  434.         {
  435.             lb_META_factory_status->Font->Color = clRed;
  436.             lb_META_factory_status->Caption = m_Rct.as_RCT + " set TCH ARFCN fail!";
  437.             MF_state = eError;
  438.             write_log();
  439.         }
  440.         break;
  441.         case WM_MF_AGE8960_SET_PDTCH_ARFCN_FAIL:
  442.         {
  443.             lb_META_factory_status->Font->Color = clRed;
  444.             lb_META_factory_status->Caption = m_Rct.as_RCT + " set PDTCH ARFCN fail!";
  445.             MF_state = eError;
  446.             write_log();
  447.             //write_result(); // added by Andy Ueng
  448.         }
  449.         break;
  450.         case WM_MF_AGE8960_SET_TCH_TIMESLOT_FAIL:
  451.         {
  452.             lb_META_factory_status->Font->Color = clRed;
  453.             lb_META_factory_status->Caption = m_Rct.as_RCT + " set TCH timeslot fail!";
  454.             MF_state = eError;
  455.             write_log();
  456.             //write_result(); // added by Andy Ueng
  457.         }    
  458.         break;
  459.         case WM_MF_AGE8960_SET_MESA_FUNC_TX_POWER_FAIL:
  460.         {
  461.             lb_META_factory_status->Font->Color = clRed;
  462.             lb_META_factory_status->Caption = m_Rct.as_RCT + " set TX power fail!";
  463.             MF_state = eError;
  464.             write_log();
  465.         }
  466.         break;
  467.         case WM_MF_AGE8960_SET_MS_TX_LEVEL_FAIL:
  468.         {
  469.             lb_META_factory_status->Font->Color = clRed;
  470.             lb_META_factory_status->Caption = m_Rct.as_RCT + " set MS TX level fail!";
  471.             MF_state = eError;
  472.             write_log();
  473.         }
  474.         break;
  475.         case WM_MF_AGE8960_SET_TX_POWER_CONT_ON_FAIL:
  476.         {
  477.             lb_META_factory_status->Font->Color = clRed;
  478.             lb_META_factory_status->Caption = m_Rct.as_RCT + " set TX power continuous ON fail!";
  479.             MF_state = eError;
  480.             write_log();
  481.             //write_result(); // added by Andy Ueng
  482.         }
  483.         break;
  484.         case WM_MF_AGE8960_SET_TX_POWER_CONT_OFF_FAIL:
  485.         {
  486.             lb_META_factory_status->Font->Color = clRed;
  487.             lb_META_factory_status->Caption = m_Rct.as_RCT + " set TX power continuous OFF fail!";
  488.             MF_state = eError;
  489.             write_log();
  490.             //write_result(); // added by Andy Ueng
  491.         }
  492.         break;
  493.         case WM_MF_AGE8960_WAIT_FOR_INIT_DONE_Q_FAIL:
  494.         {
  495.             lb_META_factory_status->Font->Color = clRed;
  496.             lb_META_factory_status->Caption = m_Rct.as_RCT + " wait for init done Q fail!";
  497.             MF_state = eError;
  498.             write_log();
  499.         }
  500.         break;
  501.         case WM_MF_AGE8960_RESUME_FAIL:
  502.         {
  503.             lb_META_factory_status->Font->Color = clRed;
  504.             lb_META_factory_status->Caption = m_Rct.as_RCT + " resume fail!";
  505.             MF_state = eError;
  506.             write_log();
  507.         }
  508.         break;
  509.         case WM_MF_AGE8960_CONFIG_TX_POWER_FAIL:
  510.         {
  511.             lb_META_factory_status->Font->Color = clRed;
  512.             lb_META_factory_status->Caption = m_Rct.as_RCT + " config TX power fail!";
  513.             MF_state = eError;
  514.             write_log();
  515.         }
  516.         break;
  517.         case WM_MF_AGE8960_CONFIG_PFER_FAIL:
  518.         {
  519.             lb_META_factory_status->Font->Color = clRed;
  520.             lb_META_factory_status->Caption = m_Rct.as_RCT + " config phase and frequency error fail!";
  521.             MF_state = eError;
  522.             write_log();
  523.         }
  524.         break;
  525.         case WM_MF_AGE8960_CONFIG_IQ_TUNNING_FAIL:
  526.         {
  527.             lb_META_factory_status->Font->Color = clRed;
  528.             lb_META_factory_status->Caption = m_Rct.as_RCT + " config IQ tunning fail!";
  529.             MF_state = eError;
  530.             write_log();
  531.         }
  532.         break;
  533.         case WM_MF_AGE8960_READ_IQ_TUNNING_FAIL:
  534.         {
  535.             lb_META_factory_status->Font->Color = clRed;
  536.             lb_META_factory_status->Caption = m_Rct.as_RCT + " read IQ tunning fail!";
  537.             MF_state = eError;
  538.             write_log();
  539.         }
  540.         break;
  541.         case WM_MF_AGE8960_CONFIG_EPSK_MOD_ACCURACY_FAIL:
  542.         {
  543.             lb_META_factory_status->Font->Color = clRed;
  544.             lb_META_factory_status->Caption = m_Rct.as_RCT + " config EPSK modulation accuracy fail!";
  545.             MF_state = eError;
  546.             write_log();
  547.         }
  548.         break;
  549.         case WM_MF_AGE8960_FETCH_EPSK_OOS_FAIL:
  550.         {
  551.             lb_META_factory_status->Font->Color = clRed;
  552.             lb_META_factory_status->Caption = m_Rct.as_RCT + " read EPSK original offset fail!";
  553.             MF_state = eError;
  554.             write_log();
  555.         }
  556.         break;
  557.         case WM_MF_AGE8960_FETCH_EPSK_SBS_FAIL:
  558.         {
  559.             lb_META_factory_status->Font->Color = clRed;
  560.             lb_META_factory_status->Caption = m_Rct.as_RCT + " read EPSK IQ imbalance fail!";
  561.             MF_state = eError;
  562.             write_log();
  563.         }
  564.         break;
  565.         case WM_MF_AGE8960_READ_TX_POWER_FAIL:
  566.         {
  567.             lb_META_factory_status->Font->Color = clRed;
  568.             lb_META_factory_status->Caption = m_Rct.as_RCT + " read TX power fail!";
  569.             as_readTXPower_Q_error="";
  570.             switch ( Message.LParam )
  571.             {
  572.                 case 0: as_readTXPower_Q_error = " Normal";
  573.                 break;
  574.                 case 1: as_readTXPower_Q_error = " No Result Available";
  575.                 break;
  576.                 case 2: as_readTXPower_Q_error = " Measurement Timeout";
  577.                 break;
  578.                 case 3: as_readTXPower_Q_error = " Hardware Not Installed";
  579.                 break;
  580.                 case 4: as_readTXPower_Q_error = " Hardware Error";
  581.                 break;
  582.                 case 5: as_readTXPower_Q_error = " Over Range";
  583.                 break;
  584.                 case 6: as_readTXPower_Q_error = " Under Range";
  585.                 break;
  586.                 case 7: as_readTXPower_Q_error = " Burst Short";
  587.                 break;
  588.                 case 12: as_readTXPower_Q_error = " Oven Out of Range";
  589.                 break;
  590.                 default:
  591.                 case 13: as_readTXPower_Q_error = " Unidentified Error";
  592.                 break;
  593.             } // switch
  594.             st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  595.                              " FAIL: " +
  596.                              m_Rct.as_RCT + " > read TX power fail."+
  597.                              as_readTXPower_Q_error
  598.                            );
  599.             MF_state = eError;
  600.             write_log();
  601.         }
  602.         break;
  603.         case WM_MF_AGE8960_SET_MESA_FUNC_PFER_FAIL:
  604.         {
  605.             lb_META_factory_status->Font->Color = clRed;
  606.             lb_META_factory_status->Caption = m_Rct.as_RCT + " config TX frequency error fail!";
  607.             MF_state = eError;
  608.             write_log();
  609.         }
  610.         break;
  611.         case WM_MF_AGE8960_READ_PFER_FAIL:
  612.         {
  613.             lb_META_factory_status->Font->Color = clRed;
  614.             lb_META_factory_status->Caption = m_Rct.as_RCT + " read TX frequency error fail!";
  615.             MF_state = eError;
  616.             write_log();
  617.         }
  618.         break;
  619.         case WM_MF_AGE8960_SET_MESA_FUNC_IQ_TUNNING_FAIL:
  620.         {
  621.             lb_META_factory_status->Font->Color = clRed;
  622.             lb_META_factory_status->Caption = m_Rct.as_RCT + " config TX IQ tunning fail!";
  623.             MF_state = eError;
  624.             write_log();
  625.         }
  626.         break;
  627.         case WM_MF_AGE8960_CLOSE_FAIL:
  628.         {
  629.             lb_META_factory_status->Font->Color = clRed;
  630.             lb_META_factory_status->Caption = m_Rct.as_RCT + " close handle fail!";
  631.             MF_state = eError;
  632.             write_log();
  633.         }
  634.         break;
  635.         case WM_MF_PT_BOOT_RESUME_FAIL:
  636.         {
  637.             lb_META_factory_status->Font->Color = clRed;
  638.             lb_META_factory_status->Caption = " PT boot resume fail!";
  639.             MF_state = eError;
  640.             write_log();
  641.         }
  642.         break;
  643.         case WM_MF_PT_CALIBRATION_NEW_FAIL:
  644.         {
  645.             lb_META_factory_status->Font->Color = clRed;
  646.             lb_META_factory_status->Caption = " PT calibration new fail!";
  647.             MF_state = eError;
  648.             write_log();
  649.         }
  650.         break;
  651.         //////////////////////////     Query     ////////////////////////////
  652.         case WM_MF_QUERY_RFTWOAPCDOOFFSET_SUCCESS:
  653.         {
  654.             m_Cal.b_TADOSupport = true;
  655.         }
  656.         break;
  657.         case WM_MF_QUERY_RFTWOAPCDOOFFSET_FAILED:
  658.         {
  659.             m_Cal.b_TADOSupport = false;
  660.         }
  661.         break;
  662.         //////////////////////////    CFG file    ////////////////////////////
  663.         case WM_MF_CFG_READ_FAIL:
  664.         {
  665.             lb_META_factory_status->Font->Color = clRed;
  666.             lb_META_factory_status->Caption = " Read config file fail!";
  667.             MF_state = eError;
  668.             write_log();
  669.         }
  670.         break;
  671.         case WM_MF_CFG_CHECK_PCL_FAIL:
  672.         {
  673.             lb_META_factory_status->Font->Color = clRed;
  674.             lb_META_factory_status->Caption = " CHECK_PCL error in config file!";
  675.             MF_state = eError;
  676.             write_log();
  677.         }
  678.         break;
  679.         //////////////////////////    INI file    ////////////////////////////
  680.         case WM_MF_INI_READ_FAIL:
  681.         {
  682.             lb_META_factory_status->Font->Color = clRed;
  683.             lb_META_factory_status->Caption = " Read initial file fail!";
  684.             MF_state = eError;
  685.             write_log();
  686.         }
  687.         break;
  688.         case WF_MF_INI_RX_PATH_LOSS_FAIL:
  689.         {
  690.             lb_META_factory_status->Font->Color = clRed;
  691.             lb_META_factory_status->Caption = " No RX path loss section in initial file fail!";
  692.             MF_state = eError;
  693.             write_log();
  694.         }
  695.         break;
  696.         //////////////////////////    LOG file    ////////////////////////////
  697.         case WM_MF_LOG_OPEN_FAIL:
  698.         {
  699.             lb_META_factory_status->Font->Color = clRed;
  700.             lb_META_factory_status->Caption = " Open logging file fail!";
  701.             MF_state = eError;
  702.             write_log();
  703.         }
  704.         break;
  705.         case WM_MF_LOG_WRITE_FAIL:
  706.         {
  707.             lb_META_factory_status->Font->Color = clRed;
  708.             lb_META_factory_status->Caption = " Write logging file fail!";
  709.             MF_state = eError;
  710.             write_log();
  711.         }
  712.         break;
  713.         // baseband
  714.         case WM_MF_BB_REG_READ_FAIL:
  715.         {
  716.             lb_META_factory_status->Font->Color = clRed;
  717.             lb_META_factory_status->Caption = " Read baseband register fail!";
  718.             MF_state = eError;
  719.             write_log();
  720.         }
  721.         break;
  722.         case WM_MF_BB_REG_WRITE_FAIL:
  723.         {
  724.             lb_META_factory_status->Font->Color = clRed;
  725.             lb_META_factory_status->Caption = " Write baseband register fail!";
  726.             MF_state = eError;
  727.             write_log();
  728.         }
  729.         break;
  730.         case WM_MF_BB_REG_SET_FAIL:
  731.         {
  732.             lb_META_factory_status->Font->Color = clRed;
  733.             lb_META_factory_status->Caption = " Set baseband register fail!";
  734.             MF_state = eError;
  735.             write_log();
  736.         }
  737.         break;
  738.             // messages for META facotry RF calibration
  739.         //////////////////////////      RF general      ////////////////////////
  740.         case WM_MF_RF_SELECTBAND_CNF_FAIL:
  741.         {
  742.             lb_META_factory_status->Font->Color = clRed;
  743.             lb_META_factory_status->Caption = " selected band fail!";
  744.             write_log();
  745.         }
  746.         break;
  747.         case WM_MF_RF_SELECTBAND_CNF_SUCCESS:
  748.         {
  749.             lb_META_factory_status->Font->Color = clWindowText;
  750.             lb_META_factory_status->Caption = " selected band success!";
  751.             write_log();
  752.         }
  753.         break;
  754.         case WM_MF_RF_STOP_FAIL:
  755.         {
  756.             lb_META_factory_status->Font->Color = clRed;
  757.             lb_META_factory_status->Caption = " Stop RF fail!";
  758.             MF_state = eError;
  759.             write_log();
  760.         }
  761.         break;
  762.         //////////////////////////      AFC      ////////////////////////////
  763.         case WM_MF_RF_AFC_BEGIN:
  764.         {
  765.             lb_META_factory_status->Font->Color = clWindowText;
  766.             if( rbTCVCXO->Checked )
  767.             {
  768.                 lb_META_factory_status->Caption = " AFC calibration in progress!";
  769.             }
  770.             else
  771.             {
  772.                 lb_META_factory_status->Caption = " AFC slope calibration in progress!";
  773.             }
  774.             MF_state = eAFC;
  775.             write_log();
  776.         }
  777.         break;
  778.         case WM_MF_RF_AFC_CONTROL_CNF:
  779.         {
  780.             lb_META_factory_status->Font->Color = clWindowText;
  781.             write_log();
  782.             if(is_suspend_cal && pt_calibration != NULL)
  783.             {
  784.                 is_suspend_cal = false;
  785.                 pt_calibration->Resume();
  786.             }
  787.         }
  788.         break;
  789.         case WM_MF_RF_SET_AFC_DAC_FAIL:
  790.         {
  791.             lb_META_factory_status->Font->Color = clRed;
  792.             lb_META_factory_status->Caption = " AFC set DAC value fail!";
  793.             MF_state = eError;
  794.             write_log();
  795.         }
  796.         break;
  797.         case WM_MF_RF_SET_AFC_DAC_CNF_FAIL:
  798.         {
  799.             lb_META_factory_status->Font->Color = clRed;
  800.             lb_META_factory_status->Caption = " AFC set DAC value cnf fail!";
  801.             MF_state = eError;
  802.             write_log();
  803.         }
  804.         break;
  805.         case WM_MF_RF_AFC_SELECT_BAND_FAIL:
  806.         {
  807.             lb_META_factory_status->Font->Color = clRed;
  808.             lb_META_factory_status->Caption = " AFC calibration select band fail!";
  809.             MF_state = eError;
  810.             write_log();
  811.         }
  812.         break;
  813.         case WM_MF_AFC_NOT_CHECK:
  814.         {
  815.             lb_META_factory_status->Font->Color = clRed;
  816.             lb_META_factory_status->Caption = " Please turn on AFC calibration for TX IQ or TRX offset calibration";
  817.             MF_state = eError;
  818.             write_log();
  819.         }
  820.         break;
  821.         case WM_MF_RF_AFC_CONTROL_FAIL:
  822.         {
  823.             lb_META_factory_status->Font->Color = clRed;
  824.             lb_META_factory_status->Caption = " AFC calibration fail!";
  825.             MF_state = eError;
  826.             write_log();
  827.         }
  828.         break;
  829.         case WM_MF_RF_AFC_GET_AFCDAC_FAIL:
  830.         {
  831.             lb_META_factory_status->Font->Color = clRed;
  832.             lb_META_factory_status->Caption = " Get target AFC DAC value fail!";
  833.             MF_state = eError;
  834.             write_log();
  835.         }
  836.         break;
  837.         case WM_MF_NVRAM_AFC_WRITE_CNF:
  838.         {
  839.             lb_META_factory_status->Font->Color = clWindowText;
  840.             write_log();
  841.             if(is_suspend_cal && pt_calibration != NULL)
  842.             {
  843.                 is_suspend_cal = false;
  844.                 pt_calibration->Resume();
  845.             }
  846.         }
  847.         break;
  848.         case WM_MF_NVRAM_AFC_READ_FAIL:
  849.         {
  850.             lb_META_factory_status->Font->Color = clRed;
  851.             lb_META_factory_status->Caption = " Read AFC slope and offset from flash fail!";
  852.             MF_state = eError;
  853.             write_log();
  854.         }
  855.         break;
  856.         case WM_MF_NVRAM_AFC_WRITE_FAIL:
  857.         {
  858.             lb_META_factory_status->Font->Color = clRed;
  859.             lb_META_factory_status->Caption = " Write AFC calibration value to flash fail!";
  860.             MF_state = eError;
  861.             write_log();
  862.         }
  863.         break;
  864.         case WM_MF_NVRAM_EF_L1_AFCDATA_LID_VERNO_FAIL:
  865.         {
  866.             lb_META_factory_status->Font->Color = clRed;
  867.             lb_META_factory_status->Caption = " NVRAM_EF_L1_AFCDATA_LID version is not support, please update META to latest version.";
  868.             MF_state = eError;
  869.             write_log();
  870.         }
  871.         break;
  872.         case WM_MF_RF_AFC_CHECK_FAIL:
  873.         {
  874.             lb_META_factory_status->Font->Color = clRed;
  875.             lb_META_factory_status->Caption = " AFC calibration check fail!";
  876.             MF_state = eError;
  877.             write_log();
  878.         }
  879.         break;
  880.         case WM_MF_RF_AFC_WRITE_CAL_RESULT_FAIL:
  881.         {
  882.             lb_META_factory_status->Font->Color = clRed;
  883.             lb_META_factory_status->Caption = " AFC calibration write calibration data to file fail!";
  884.             MF_state = eError;
  885.             write_log();
  886.         }
  887.         break;
  888.         case WM_MF_RF_AFC_CALIBRATION_DONE:
  889.         {
  890.             lb_META_factory_status->Font->Color = clWindowText;
  891.             lb_META_factory_status->Caption = " AFC calibration done!";
  892.             MF_state = eAFC;
  893.             write_log();
  894.         }
  895.         break;
  896.         ///////////////////////  crystal AFC   /////////////////////////////////
  897.         case WM_MF_RF_CRYSTAL_AFC_CAPID_BEGIN:
  898.         {
  899.             lb_META_factory_status->Font->Color = clWindowText;
  900.             lb_META_factory_status->Caption = " Crystal CAPID calibration in progress!";
  901.             MF_state = eAFC;
  902.             write_log();
  903.         }
  904.         break;
  905.         case WM_MF_RF_CRYSTAL_AFC_CAPID_DONE:
  906.         {
  907.             lb_META_factory_status->Font->Color = clWindowText;
  908.             lb_META_factory_status->Caption = " Crystal CAPID calibration done!";
  909.             MF_state = eAFC;
  910.             write_log();
  911.         }
  912.         break;
  913.         case WM_MF_RF_CRYSTAL_AFC_CONTROL_START:
  914.         {
  915.             lb_META_factory_status->Font->Color = clWindowText;
  916.             lb_META_factory_status->Caption = " Crystal AFC calibration in progress!";
  917.             MF_state = eAFC;
  918.             write_log();
  919.         }
  920.         break;
  921.         case WM_MF_RF_CRYSTAL_AFC_SELECT_BAND_FAIL:
  922.         {
  923.             lb_META_factory_status->Font->Color = clRed;
  924.             lb_META_factory_status->Caption = " Crystal AFC calibration select band fail!";
  925.             MF_state = eError;
  926.             write_log();
  927.         }
  928.         break;
  929.         case WM_MF_NVRAM_CRYSTAL_AFC_CAPID_WRITE_FAIL:
  930.         {
  931.             lb_META_factory_status->Font->Color = clRed;
  932.             lb_META_factory_status->Caption = " Write AFC calibration CAP ID to flash fail!";
  933.             MF_state = eError;
  934.             write_log();
  935.         }
  936.         break;
  937.         case WM_MF_NVRAM_EF_L1_CRYSTAL_CAPDATA_LID_VERNO_FAIL:
  938.         {
  939.             lb_META_factory_status->Font->Color = clRed;
  940.             lb_META_factory_status->Caption = " NVRAM_EF_L1_CRYSTAL_CAPDATA_LID version is not support, please update META to latest version.";
  941.             MF_state = eError;
  942.             write_log();
  943.         }
  944.         break;
  945.         case WM_MF_RF_CRYSTAL_AFC_CONTROL_FAIL:
  946.         {
  947.             lb_META_factory_status->Font->Color = clRed;
  948.             lb_META_factory_status->Caption = " Crystal AFC calibration control fail!";
  949.             MF_state = eError;
  950.             write_log();
  951.         }
  952.         break;
  953.         case WM_MF_RF_CRYSTAL_AFC_TX_LEVEL_FAIL:
  954.         {
  955.             lb_META_factory_status->Font->Color = clRed;
  956.             lb_META_factory_status->Caption = " Crystal AFC calibration send NB fail!";
  957.             MF_state = eError;
  958.             write_log();
  959.         }
  960.         break;
  961.         case WM_MF_RF_CRYSTAL_AFC_PRECHECK_FAIL:
  962.         {
  963.             lb_META_factory_status->Font->Color = clRed;
  964.             lb_META_factory_status->Caption = " Crystal AFC calibration pre-check fail!";
  965.             MF_state = eError;
  966.             write_log();
  967.         }
  968.         break;
  969.         case WM_MF_RF_CRYSTAL_AFC_CHECK_FAIL:
  970.         {
  971.             lb_META_factory_status->Font->Color = clRed;
  972.             lb_META_factory_status->Caption = " Crystal AFC calibration check fail!";
  973.             MF_state = eError;
  974.             write_log();
  975.         }
  976.         break;
  977.         case WM_MF_RF_SET_CRYSTAL_AFC_DAC_FAIL:
  978.         {
  979.             lb_META_factory_status->Font->Color = clRed;
  980.             lb_META_factory_status->Caption = " Crystal AFC calibration set AFC DAC fail!";
  981.             MF_state = eError;
  982.             write_log();
  983.         }
  984.         break;
  985.         case WM_MF_RF_SET_CRYSTAL_AFC_DAC_CNF_FAIL:
  986.         {
  987.             lb_META_factory_status->Font->Color = clRed;
  988.             lb_META_factory_status->Caption = " Crystal AFC calibration set AFC DAC cnf fail!";
  989.             MF_state = eError;
  990.             write_log();
  991.         }
  992.         break;
  993.         case WM_MF_RF_CRYSTAL_AFC_WRITE_CAL_RESULT_FAIL:
  994.         {
  995.             lb_META_factory_status->Font->Color = clRed;
  996.             lb_META_factory_status->Caption = " Crystal AFC calibration write calibration data to file fail!";
  997.             MF_state = eError;
  998.             write_log();
  999.         }
  1000.         break;
  1001.         case WM_MF_RF_CRYSTAL_AFC_SET_CAPID_FAIL:
  1002.         {
  1003.             lb_META_factory_status->Font->Color = clRed;
  1004.             lb_META_factory_status->Caption = " Crystal AFC calibration set CAP ID fail!";
  1005.             MF_state = eError;
  1006.             write_log();
  1007.         }
  1008.         break;
  1009.         case WM_MF_RF_CRYSTAL_AFC_ALL_FREQ_ERR_POSITIVE_FAIL:
  1010.         {
  1011.             lb_META_factory_status->Font->Color = clRed;
  1012.             lb_META_factory_status->Caption = " Crystal AFC calibration all frequency error are positive fail!";
  1013.             MF_state = eError;
  1014.             write_log();
  1015.         }
  1016.         break;
  1017.         case WM_MF_RF_CRYSTAL_AFC_ALL_FREQ_ERR_NEGATIVE_FAIL:
  1018.         {
  1019.             lb_META_factory_status->Font->Color = clRed;
  1020.             lb_META_factory_status->Caption = " Crystal AFC calibration all frequency error are negative fail!";
  1021.             MF_state = eError;
  1022.             write_log();
  1023.         }
  1024.         break;
  1025.         case WM_MF_RF_CRYSTAL_AFC_TRX_OFFSET_BEGIN:
  1026.         {
  1027.             lb_META_factory_status->Font->Color = clWindowText;
  1028.             lb_META_factory_status->Caption = " TRX offset calibration in progress!";
  1029.             MF_state = eAFC;
  1030.             write_log();
  1031.         }
  1032.         break;
  1033.         case WM_MF_RF_CRYSTAL_AFC_TRX_OFFSET_CALIBRATION_DONE:
  1034.         {
  1035.             lb_META_factory_status->Font->Color = clWindowText;
  1036.             lb_META_factory_status->Caption = " TRX offset calibration done!";
  1037.             MF_state = eAFC;
  1038.             write_log();
  1039.         }
  1040.         break;
  1041.         case WM_MF_RF_CRYSTAL_AFC_CALIBRATION_DONE:
  1042.         {
  1043.             lb_META_factory_status->Font->Color = clWindowText;
  1044.             lb_META_factory_status->Caption = " AFC calibration done!";
  1045.             MF_state = eAFC;
  1046.             write_log();
  1047.         }
  1048.         break;
  1049.         //////////////////////////  RX path loss  ////////////////////////////
  1050.         case WM_MF_RF_PM_BEGIN:
  1051.         {
  1052.             lb_META_factory_status->Font->Color = clWindowText;
  1053.             lb_META_factory_status->Caption = " RX path loss calibration in progress!";
  1054.             MF_state = eRF_PathLoss;
  1055.             write_log();
  1056.         }
  1057.         break;
  1058.         case WM_MF_RF_PM_INI_FAIL:
  1059.         {
  1060.             lb_META_factory_status->Font->Color = clRed;
  1061.             lb_META_factory_status->Caption = " RX pathloss section not in initial file" ;
  1062.             MF_state = eError;
  1063.             write_log();
  1064.         }
  1065.         break;
  1066.         case WM_MF_RF_PM_SUPPORT_FAIL:
  1067.         {
  1068.             lb_META_factory_status->Font->Color = clRed;
  1069.             lb_META_factory_status->Caption = " PM setting in CFG file exceed mobile capability, PM setting = " + IntToStr(Message.WParam) +", MS capability = " + IntToStr(Message.LParam) ;
  1070.             MF_state = eError;
  1071.             write_log();
  1072.         }
  1073.         break;
  1074.         case WM_MF_RF_PM_CNF:
  1075.         {
  1076.             lb_META_factory_status->Font->Color = clWindowText;
  1077.             lb_META_factory_status->Caption = " Path loss calibration in progress!";
  1078.             write_log();
  1079.             if(is_suspend_cal  && pt_calibration != NULL )
  1080.             {
  1081.                 is_suspend_cal = false;
  1082.                 pt_calibration->Resume();
  1083.             }
  1084.         }    
  1085.         break;
  1086.         case WM_MF_RF_PM_FAIL:
  1087.         {
  1088.             lb_META_factory_status->Font->Color = clRed;
  1089.             lb_META_factory_status->Caption = " Path loss calibration fail!";
  1090.             MF_state = eError;
  1091.             write_log();
  1092.         }
  1093.         break;
  1094.         case WM_MF_RF_PM_CHECK_FAIL:
  1095.         {
  1096.             lb_META_factory_status->Font->Color = clRed;
  1097.             lb_META_factory_status->Caption = " Path loss calibration check fail!";
  1098.             MF_state = eError;
  1099.             write_log();
  1100.         }
  1101.         break;
  1102.         case WM_MF_NVRAM_PATH_LOSS_WRITE_CNF:
  1103.         {
  1104.             lb_META_factory_status->Font->Color = clWindowText;
  1105.             write_log();
  1106.             if(is_suspend_cal && pt_calibration != NULL)
  1107.             {
  1108.                 is_suspend_cal = false;
  1109.                 pt_calibration->Resume();
  1110.             }
  1111.         }
  1112.         break;
  1113.         case WM_MF_NVRAM_PATH_LOSS_WRITE_FAIL:
  1114.         {
  1115.             lb_META_factory_status->Font->Color = clRed;
  1116.             lb_META_factory_status->Caption = " Write path loss calibration value to flash fail!";
  1117.             MF_state = eError;
  1118.             write_log();
  1119.         }
  1120.         break;
  1121.         case WM_MF_NVRAM_EF_L1_AGCPATHLOSS_LID_VERNO_FAIL:
  1122.         {
  1123.             lb_META_factory_status->Font->Color = clRed;
  1124.             lb_META_factory_status->Caption = " NVRAM_EF_L1_AGCPATHLOSS_LID version is not support, please update META to latest version.";
  1125.             MF_state = eError;
  1126.             write_log();
  1127.         }
  1128.         break;
  1129.         case WM_MF_RF_PM_WRITE_CAL_RESULT_FAIL:
  1130.         {
  1131.             lb_META_factory_status->Font->Color = clRed;
  1132.             lb_META_factory_status->Caption = " Path loss calibration write calibration data to file fail!";
  1133.             MF_state = eError;
  1134.             write_log();
  1135.         }
  1136.         break;
  1137.         case WM_MF_RF_PM_CALIBRATION_DONE:
  1138.         {
  1139.             lb_META_factory_status->Font->Color = clWindowText;
  1140.             lb_META_factory_status->Caption = " RX path loss calibration done!";
  1141.             MF_state = eRF_PathLoss;
  1142.             write_log();
  1143.         }
  1144.         break;
  1145.         //////////////////////////     IP2     ////////////////////////////
  1146.         case WM_MF_RF_IP2_BEGIN:
  1147.         {
  1148.             lb_META_factory_status->Font->Color = clWindowText;
  1149.             lb_META_factory_status->Caption = " IP2 calibration progress!";
  1150.             MF_state = eIP2;
  1151.             write_log();
  1152.         }
  1153.         break;
  1154.         case WM_MF_NVRAM_IP2_READ_FAIL:
  1155.         {
  1156.             lb_META_factory_status->Font->Color = clRed;
  1157.             lb_META_factory_status->Caption = " Read IP2 calibration value from flash fail!";
  1158.             MF_state = eError;
  1159.             write_log();
  1160.         }
  1161.         break;
  1162.         case WM_MF_NVRAM_IP2_WRITE_FAIL:
  1163.         {
  1164.             lb_META_factory_status->Font->Color = clRed;
  1165.             lb_META_factory_status->Caption = " Write IP2 calibration value to flash fail!";
  1166.             MF_state = eError;
  1167.             write_log();
  1168.         }
  1169.         break;
  1170.         case WM_MF_NVRAM_EF_L1_RFSPECIALCOEF_LID_VERNO_FAIL:
  1171.         {
  1172.             lb_META_factory_status->Font->Color = clRed;
  1173.             lb_META_factory_status->Caption = " NVRAM_EF_L1_RFSPECIALCOEF_LID version is not support, please update META to latest version.";
  1174.             MF_state = eError;
  1175.             write_log();
  1176.         }
  1177.         break;
  1178.         case WM_MF_RF_IP2_SET_AMCALMODE_FAIL:
  1179.         {
  1180.             lb_META_factory_status->Font->Color = clRed;
  1181.             lb_META_factory_status->Caption = " IP2 set rxamcalmode to register fail!";
  1182.             MF_state = eError;
  1183.             write_log();
  1184.         }
  1185.         break;
  1186.         case WM_MF_RF_IP2_SET_MAG_FAIL:
  1187.         {
  1188.             lb_META_factory_status->Font->Color = clRed;
  1189.             lb_META_factory_status->Caption = " IP2 set mag to register fail!";
  1190.             MF_state = eError;
  1191.             write_log();
  1192.         }
  1193.         break;
  1194.         case WM_MF_RF_IP2_SET_POL_FAIL:
  1195.         {
  1196.             lb_META_factory_status->Font->Color = clRed;
  1197.             lb_META_factory_status->Caption = " IP2 set pol to register fail!";
  1198.             MF_state = eError;
  1199.             write_log();
  1200.         }
  1201.         break;
  1202.         case WM_MF_RF_IP2_SET_CW2_FAIL:
  1203.         {
  1204.             lb_META_factory_status->Font->Color = clRed;
  1205.             lb_META_factory_status->Caption = " IP2 set CW2 to register fail!";
  1206.             MF_state = eError;
  1207.             write_log();
  1208.         }
  1209.         break;
  1210.         case WM_MF_RF_IP2_SET_CW7_FAIL:
  1211.         {
  1212.             lb_META_factory_status->Font->Color = clRed;
  1213.             lb_META_factory_status->Caption = " IP2 set CW7 to register fail!";
  1214.             MF_state = eError;
  1215.             write_log();
  1216.         }
  1217.         break;
  1218.         case WM_MF_RF_IP2_SET_BCCODE_FAIL:
  1219.         {
  1220.             lb_META_factory_status->Font->Color = clRed;
  1221.             lb_META_factory_status->Caption = " IP2 set B, C code to register fail!";
  1222.             MF_state = eError;
  1223.             write_log();
  1224.         }
  1225.         break;
  1226.         case WM_MF_RF_IP2_SET_MT6139_COEF_FAIL:
  1227.         {
  1228.             lb_META_factory_status->Font->Color = clRed;
  1229.             lb_META_factory_status->Caption = " IP2 Set MT6139 coefficient fail!";
  1230.             MF_state = eError;
  1231.             write_log();
  1232.         }
  1233.         break;
  1234.         case WM_MF_RF_IP2_GET_ACODE_FAIL:
  1235.         {
  1236.             lb_META_factory_status->Font->Color = clRed;
  1237.             lb_META_factory_status->Caption = " IP2 get acode from register fail!";
  1238.             MF_state = eError;
  1239.             write_log();
  1240.         }
  1241.         break;
  1242.         case WM_MF_RF_IP2_GET_CW7_FAIL:
  1243.         {
  1244.             lb_META_factory_status->Font->Color = clRed;
  1245.             lb_META_factory_status->Caption = " IP2 get CW7 from register fail!";
  1246.             MF_state = eError;
  1247.             write_log();
  1248.         }
  1249.         break;
  1250.         case WM_MF_RF_IP2_GET_BCCODE_FAIL:
  1251.         {
  1252.             lb_META_factory_status->Font->Color = clRed;
  1253.             lb_META_factory_status->Caption = " IP2 get B, C code from register fail!";
  1254.             MF_state = eError;
  1255.             write_log();
  1256.         }
  1257.         break;
  1258.         case WM_MF_RF_IP2_PM_FAIL:
  1259.         {
  1260.             lb_META_factory_status->Font->Color = clRed;
  1261.             lb_META_factory_status->Caption = " IP2 calibration PM fail!";
  1262.             MF_state = eError;
  1263.             write_log();
  1264.         }
  1265.         break;
  1266.         case WM_MF_RF_IP2_FAIL:
  1267.         {
  1268.             lb_META_factory_status->Font->Color = clRed;
  1269.             lb_META_factory_status->Caption = " IP2 calibration fail!";
  1270.             MF_state = eError;
  1271.             write_log();
  1272.         }
  1273.         break;
  1274.         case WM_MF_RF_IP2_CHECK_FAIL:
  1275.         {
  1276.             lb_META_factory_status->Font->Color = clRed;
  1277.             lb_META_factory_status->Caption = " IP2 calibration check fail!";
  1278.             MF_state = eError;
  1279.             write_log();
  1280.         }
  1281.         break;
  1282.         case WM_MF_RF_IP2_WRITE_CAL_RESULT_FAIL:
  1283.         {
  1284.             lb_META_factory_status->Font->Color = clRed;
  1285.             lb_META_factory_status->Caption = " IP2 calibration write calibration data to file fail!";
  1286.             MF_state = eError;
  1287.             write_log();
  1288.         }
  1289.         break;
  1290.         case WM_MF_RF_IP2_CALIBRATION_DONE:
  1291.         {
  1292.             lb_META_factory_status->Font->Color = clWindowText;
  1293.             lb_META_factory_status->Caption = " IP2 calibration done!";
  1294.             MF_state = eIP2;
  1295.             write_log();
  1296.         }
  1297.         break;
  1298.         //////////////////////////   TX PCL    ////////////////////////////
  1299.         case WM_MF_RF_TX_LEVEL_BEGIN:
  1300.         {
  1301.             lb_META_factory_status->Font->Color = clWindowText;
  1302.             lb_META_factory_status->Caption = " TX power control level calibration in progress!";
  1303.             MF_state = eTX_PCL;
  1304.             write_log();
  1305.         }
  1306.         break;
  1307.         case WM_MF_RF_TX_LEVEL_CNF:
  1308.         {
  1309.             lb_META_factory_status->Font->Color = clWindowText;
  1310.             lb_META_factory_status->Caption = " TX power control level calibration in progress!";
  1311.             if(is_suspend_cal && pt_calibration != NULL)
  1312.             {
  1313.                 is_suspend_cal = false;
  1314.                 pt_calibration->Resume();
  1315.             }
  1316.         }
  1317.         break;
  1318.         case WM_MF_RF_TX_LEVEL_INI_FAIL:
  1319.         {
  1320.             lb_META_factory_status->Font->Color = clRed;
  1321.             lb_META_factory_status->Caption = " APC section is not in initial file!";
  1322.             MF_state = eError;
  1323.             write_log();
  1324.         }
  1325.         break;
  1326.         case WM_MF_RF_QUERY_ITC_PCL_FAIL:
  1327.         {
  1328.             lb_META_factory_status->Font->Color = clRed;
  1329.             lb_META_factory_status->Caption = " Query modulator switch PCL fail!";
  1330.             MF_state = eError;
  1331.             write_log();
  1332.         }
  1333.         break;
  1334.         case WM_MF_RF_TX_LEVEL_FAIL:
  1335.         {
  1336.             lb_META_factory_status->Font->Color = clRed;
  1337.             lb_META_factory_status->Caption = " TX PCL calibration send NB fail!";
  1338.             MF_state = eError;
  1339.             write_log();
  1340.         }
  1341.         break;
  1342.         case WM_MF_RF_TX_LEVEL_EVALDAC_FAIL:
  1343.         {
  1344.             lb_META_factory_status->Font->Color = clRed;
  1345.             lb_META_factory_status->Caption = " TX power control level evaluate DAC value fail!";
  1346.             MF_state = eError;
  1347.             write_log();
  1348.         }
  1349.         break;
  1350.         case WM_MF_RF_TX_LEVEL_CHECK_FAIL:
  1351.         {
  1352.             lb_META_factory_status->Font->Color = clRed;
  1353.             lb_META_factory_status->Caption = " TX power control level check fail!";
  1354.             MF_state = eError;
  1355.             write_log();
  1356.         }
  1357.         break;
  1358.         case WM_MF_RF_MAX_APC_DAC_OUT_OF_RANGE_FAIL:
  1359.         {
  1360.             lb_META_factory_status->Font->Color = clRed;
  1361.             lb_META_factory_status->Caption = " MAX APC DAC out of range fail!";
  1362.             MF_state = eError;
  1363.             write_log();
  1364.         }
  1365.         break;
  1366.         case WM_MF_SET_APC_DAC_FAIL:
  1367.         {
  1368.             lb_META_factory_status->Font->Color = clRed;
  1369.             lb_META_factory_status->Caption = " set TX PCL DAC fail!";
  1370.             MF_state = eError;
  1371.             write_log();
  1372.         }
  1373.         break;
  1374.         case WM_MF_SET_APC_DC_OFFSET_FAIL:
  1375.         {
  1376.             lb_META_factory_status->Font->Color = clRed;
  1377.             lb_META_factory_status->Caption = " set APC DC offset fail!";
  1378.             MF_state = eError;
  1379.             write_log();
  1380.         }
  1381.         break;
  1382.         case WM_MF_RF_TX_LEVEL_WRITE_CAL_RESULT_FAIL:
  1383.         {
  1384.             lb_META_factory_status->Font->Color = clRed;
  1385.             lb_META_factory_status->Caption = " TX PCL calibration write calibration data to file fail!";
  1386.             MF_state = eError;
  1387.             write_log();
  1388.         }
  1389.         break;
  1390.         case WM_MF_NVRAM_LEVEL_RAMP_READ_FAIL:
  1391.         {
  1392.             lb_META_factory_status->Font->Color = clRed;
  1393.             lb_META_factory_status->Caption = " Read TX power control level from flash fail!";
  1394.             MF_state = eError;
  1395.             write_log();
  1396.         }
  1397.         break;
  1398.         case WM_MF_NVRAM_LEVEL_RAMP_WRITE_CNF:
  1399.         {
  1400.             lb_META_factory_status->Font->Color = clWindowText;
  1401.                 write_log();
  1402.                 //write_result(); // added by Andy Ueng
  1403.             if(is_suspend_cal && pt_calibration != NULL)
  1404.             {
  1405.                 is_suspend_cal = false;
  1406.                 pt_calibration->Resume();
  1407.             }
  1408.         }
  1409.         break;
  1410.         case WM_MF_NVRAM_LEVEL_RAMP_WRITE_FAIL:
  1411.         {
  1412.             lb_META_factory_status->Font->Color = clRed;
  1413.             lb_META_factory_status->Caption = " Write TX power control level to flash fail!";
  1414.             MF_state = eError;
  1415.             write_log();
  1416.         }
  1417.         break;
  1418.         case WM_MF_NVRAM_EF_L1_RAMPTABLE_xxx_LID_VERNO_FAIL:
  1419.         {
  1420.             lb_META_factory_status->Font->Color = clRed;
  1421.             lb_META_factory_status->Caption = " NVRAM_EF_L1_RAMPTABLE_xxx_LID version is not support, please update META to latest version.";
  1422.             MF_state = eError;
  1423.             write_log();
  1424.         }
  1425.         break;
  1426.         case WM_MF_NVRAM_EF_L1_EPSK_RAMPTABLE_xxx_LID_VERNO_FAIL:
  1427.         {
  1428.             lb_META_factory_status->Font->Color = clRed;
  1429.             lb_META_factory_status->Caption = " NVRAM_EF_L1_EPSK_RAMPTABLE_xxx_LID version is not support, please update META to latest version.";
  1430.             MF_state = eError;
  1431.             write_log();
  1432.         }
  1433.         break;
  1434.         case WM_MF_SET_RAMPAPCLEVEL_FAIL:
  1435.         {
  1436.             lb_META_factory_status->Font->Color = clRed;
  1437.             lb_META_factory_status->Caption = " Set ramp APC level fail!";
  1438.             MF_state = eError;
  1439.             write_log();
  1440.         }
  1441.         break;
  1442.         case WM_MF_SET_RAMPAPCLEVEL_CNF:
  1443.         {
  1444.             lb_META_factory_status->Font->Color = clWindowText;
  1445.             write_log();
  1446.             if(is_suspend_cal && pt_calibration != NULL)
  1447.             {
  1448.                 is_suspend_cal = false;
  1449.                 pt_calibration->Resume();
  1450.             }
  1451.         }
  1452.         break;
  1453.         case WM_MF_RF_A60111A_ENTER_FACTORY_MODE_FAIL:
  1454.         {
  1455.             lb_META_factory_status->Font->Color = clRed;
  1456.             lb_META_factory_status->Caption = " A60111A enter factory mode fail!";
  1457.             MF_state = eError;
  1458.             write_log();
  1459.         }
  1460.         break;
  1461.         case WM_MF_RF_A60111A_READ_REF_TEMP_FAIL:
  1462.         {
  1463.             lb_META_factory_status->Font->Color = clRed;
  1464.             lb_META_factory_status->Caption = " A60111A read temp_ref fail!";
  1465.             MF_state = eError;
  1466.             write_log();
  1467.         }
  1468.         break;
  1469.         case WM_MF_NVRAM_REF_TEMP_WRITE_FAIL:
  1470.         {
  1471.             lb_META_factory_status->Font->Color = clRed;
  1472.             lb_META_factory_status->Caption = " write A60111A temp_ref to NVRAM fail!";
  1473.             MF_state = eError;
  1474.             write_log();
  1475.         }
  1476.         break;
  1477.         case WM_MF_RF_TX_LEVEL_CALIBRATION_DONE:
  1478.         {
  1479.             lb_META_factory_status->Font->Color = clWindowText;
  1480.             lb_META_factory_status->Caption = " TX PCL calibration done!";
  1481.             MF_state = eTX_PCL;
  1482.             write_log();
  1483.         }
  1484.         break;
  1485.         case WM_MF_RF_TX_LEVEL_CALIBRATION_DONE_NO_CHECK:
  1486.         {
  1487.             lb_META_factory_status->Font->Color = clWindowText;
  1488.             lb_META_factory_status->Caption = " TX PCL calibration done!(without TX PCL check)";
  1489.             MF_state = eTX_PCL;
  1490.             write_log();
  1491.         }
  1492.         break;
  1493.         ////////////////////// Trim, offset IQ calibration  ///////////////////
  1494.         case WM_MF_RF_TX_IQ_FAIL:
  1495.         {
  1496.             lb_META_factory_status->Font->Color = clWindowText;
  1497.             lb_META_factory_status->Caption = " TX IQ calibration fail!";
  1498.             MF_state = eError;
  1499.             write_log();
  1500.         }
  1501.         break;
  1502.         case WM_MF_RF_GET_BB_TX_CFG_FAIL:
  1503.         {
  1504.             lb_META_factory_status->Font->Color = clWindowText;
  1505.             lb_META_factory_status->Caption = " RF get BB TX config fail!";
  1506.             MF_state = eError;
  1507.             write_log();
  1508.         }
  1509.         break;
  1510.         case WM_MF_RF_SET_BB_TX_CFG_FAIL:
  1511.         {
  1512.             lb_META_factory_status->Font->Color = clWindowText;
  1513.             lb_META_factory_status->Caption = " RF set BB TX config fail!";
  1514.             MF_state = eError;
  1515.             write_log();
  1516.         }
  1517.         break;
  1518.         case WM_MF_RF_TX_GAIN_AUTO_CAL_FAIL:
  1519.         {
  1520.             lb_META_factory_status->Font->Color =  clRed;
  1521.             lb_META_factory_status->Caption = " TX gain auto calibration fail!";
  1522.             MF_state = eError;
  1523.             write_log();
  1524.         }
  1525.         break;
  1526.         case WM_MF_RF_TX_IQ_BEGIN:
  1527.         {
  1528.             lb_META_factory_status->Font->Color = clWindowText;
  1529.             lb_META_factory_status->Caption = " TX IQ calibration progress!";
  1530.             MF_state = eTX_DcOffset;
  1531.             write_log();
  1532.         }
  1533.         break;
  1534.         case WM_MF_NVRAM_TXIQ_WRITE_FAIL:
  1535.         {
  1536.             lb_META_factory_status->Font->Color = clRed;
  1537.             lb_META_factory_status->Caption = " Write TX IQ calibration data to flash fail!";
  1538.             MF_state = eError;
  1539.             write_log();
  1540.         }
  1541.         break;
  1542.         case WM_MF_NVRAM_EF_L1_TXIQ_LID_VERNO_FAIL:
  1543.         {
  1544.             lb_META_factory_status->Font->Color = clRed;
  1545.             lb_META_factory_status->Caption = " NVRAM_EF_L1_TXIQ_LID version is not support, please update META to latest version.";
  1546.             MF_state = eError;
  1547.             write_log();
  1548.         }
  1549.         break;
  1550.         case WM_MF_RF_TX_IQ_CHECK_FAIL:
  1551.         {
  1552.             lb_META_factory_status->Font->Color = clRed;
  1553.             lb_META_factory_status->Caption = " TX IQ calibration check fail!";
  1554.             MF_state = eError;
  1555.             write_log();
  1556.         }
  1557.         break;
  1558.         case WM_MF_RF_TX_IQ_CALIBRATION_DONE:
  1559.         {
  1560.             lb_META_factory_status->Font->Color = clWindowText;
  1561.             lb_META_factory_status->Caption = " TX IQ calibration done!";
  1562.             MF_state = eTX_DcOffset;
  1563.             write_log();
  1564.         }
  1565.         break;
  1566.         //////////////////////  calibration general  //////////////////////////
  1567.         case WM_MF_CA_SUCCESS:
  1568.         {
  1569.             lb_META_factory_status->Font->Color = clWindowText;
  1570.             after_Calibration_TerminateSuccess( NULL );
  1571.         }
  1572.         break;
  1573.         case WM_MF_CA_FAIL:
  1574.         {
  1575.             lb_META_factory_status->Font->Color = clRed;
  1576.             after_Calibration_Fail( NULL );
  1577.         }
  1578.         break;
  1579.         case WM_MF_CA_TERM_BY_USER:
  1580.         {
  1581.             lb_META_factory_status->Font->Color = clWindowText;
  1582.             after_Calibration_TerminateByUser( NULL );
  1583.         }
  1584.         break;
  1585.         case WM_MF_CALIBRATION_TIMER_TIME_OUT:
  1586.         {
  1587.             lb_META_factory_status->Font->Color = clRed;
  1588.             lb_META_factory_status->Caption = " Calibration timer timeout!";
  1589.             MF_state = eError;
  1590.             write_log();
  1591.         }
  1592.         break;
  1593.         case WM_MF_RECONNECT_WITH_TARGET_SUCCESS:
  1594.         {
  1595.              lb_META_factory_status->Font->Color = clWindowText;
  1596.              ReconnectWithTargetSuccess();
  1597.         }
  1598.         break;
  1599. //-----------------
  1600.         //////////////////////////    META dll    ////////////////////////////
  1601.         case WM_META_DLL_ERROR_FRAME_ERROR:
  1602.         {
  1603.             MessageBox(NULL, "Frame error!", NULL, MB_OK);
  1604.         }
  1605.         break;
  1606.         case WM_META_DLL_ERROR_NO_CALLBACK:
  1607.         {
  1608.             MessageBox(NULL, "There is no callback function for some confirm!", NULL, MB_OK);
  1609.         }
  1610.         break;
  1611.         case WM_META_DLL_ERROR_PRIMITIVE_ERROR:
  1612.         {
  1613.             MessageBox(NULL, "Corrupt primitive", NULL, MB_OK);
  1614.         }
  1615.         break;
  1616.         case WM_META_DLL_ERROR_UNDEFINE_ERROR:
  1617.         {
  1618.             MessageBox(NULL, "Unknow error!", NULL, MB_OK);
  1619.         }
  1620.         break;
  1621.         case WM_META_DLL_FAILED:
  1622.         {
  1623.             if (NULL == hCOM)
  1624.                 Application->MessageBox( " COM port is not initialized." , "Fail", MB_OK );
  1625.             else
  1626.                 Application->MessageBox( " FAILED ", "Fail", MB_OK );
  1627.         }
  1628.         break;
  1629.         case WM_META_DLL_COMM_FAIL:
  1630.         {
  1631.             Application->MessageBox( " Communication between PC and target is failed ", "Fail", MB_OK );
  1632.         }
  1633.         break;
  1634.         case WM_META_DLL_NORESPONSE:
  1635.         {
  1636.             Application->MessageBox( " NO response ", "Fail", MB_OK );
  1637.         }
  1638.         break;
  1639.         case WM_META_DLL_BUFFER_LEN:
  1640.         {
  1641.             Application->MessageBox( " Buffer length is not enough ", "Error", MB_OK );
  1642.         }
  1643.         break;
  1644.         case WM_META_DLL_GROUP_INVALID:
  1645.         {
  1646.             Application->MessageBox( " NVRAM group id invalid ", "Error", MB_OK );
  1647.         }
  1648.         break;
  1649.         case WM_META_DLL_ELEMENT_INVALID:
  1650.         {
  1651.             Application->MessageBox( " NVRAM element id invalid ", "Error", MB_OK );
  1652.         }
  1653.         break;
  1654.         case WM_META_DLL_FIELD_INVALID:
  1655.         {
  1656.             Application->MessageBox( " NVRAM field invalid ", "Error", MB_OK );
  1657.         }
  1658.         break;
  1659.         case WM_META_DLL_VALUE_LEN:
  1660.         {
  1661.              Application->MessageBox( " value of length is incorrect ", "Error", MB_OK );
  1662.         }
  1663.         break;
  1664.         case WM_META_DLL_FILE_BAD:
  1665.         {
  1666.             Application->MessageBox( " This file is bad.", "Error", MB_OK );
  1667.         }
  1668.         break;
  1669.         case WM_META_DLL_PARAM_INVALID:
  1670.         {
  1671.             Application->MessageBox( " parameter invalid ", "Error", MB_OK );
  1672.         }
  1673.         break;
  1674.         case WM_META_DLL_INTERNAL_DB_ERR:
  1675.         {
  1676.             Application->MessageBox( " meta dll internal db error ", "Error", MB_OK );
  1677.         }
  1678.         break;
  1679.         case WM_META_DLL_NO_MEMORY:
  1680.         {
  1681.             Application->MessageBox( " meta dll no memory ", "Error", MB_OK );
  1682.         }
  1683.         break;
  1684.         case WM_META_DLL_INVALID_ARGUMENTS:
  1685.         {
  1686.             Application->MessageBox( " meta dll invalid arguments ", "Error", MB_OK );
  1687.         }
  1688.         break;
  1689.         case WM_META_DLL_TIMEOUT:
  1690.         {
  1691.             Application->MessageBox( " meta dll timeout ", "Error", MB_OK );
  1692.         }
  1693.         break;
  1694.         case WM_META_DLL_BUSY:
  1695.         {
  1696.             Application->MessageBox( " meta dll busy ", "Error", MB_OK );
  1697.         }
  1698.         break;
  1699.         //////////////////////////   power supply   ///////////////////////////
  1700.         case WM_MF_ADC_DCS_INIT_FAIL:
  1701.         {
  1702.              lb_META_factory_status->Font->Color = clRed;
  1703.              lb_META_factory_status->Caption = " Power supply init fail!";
  1704.      MF_state = eError;
  1705.             write_log();
  1706.            //write_result(); // added by Andy Ueng
  1707.         }
  1708.         break;
  1709.         //case WM_MF_AGE663x2_INIT_FAIL:
  1710.         //     lb_META_factory_status->Font->Color = clRed;
  1711.        //      lb_META_factory_status->Caption = " Agilent 663x2 init fail!";
  1712.        //      MF_state = eError;
  1713.        ///      write_log();
  1714.        //      //write_result(); // added by Andy Ueng
  1715.       //  break;
  1716.        // case WM_MF_AGEE3631A_INIT_FAIL:
  1717.        //      lb_META_factory_status->Font->Color = clRed;
  1718.        //      lb_META_factory_status->Caption = " Agilent E3631A init fail!";
  1719.        //      MF_state = eError;
  1720.        //      write_log();
  1721.        //      //write_result(); // added by Andy Ueng
  1722.       //  break;
  1723.        // case WM_MF_RESUME_AGE661x_FAIL:
  1724.        //      lb_META_factory_status->Font->Color = clRed;
  1725.        //      lb_META_factory_status->Caption = " Agilent 661x resume fail!";
  1726.        //      MF_state = eError;
  1727.        //      write_log();
  1728.        //      //write_result(); // added by Andy Ueng
  1729.        // break;
  1730.        // case WM_MF_RESUME_AGE663x2_FAIL:
  1731.        //      lb_META_factory_status->Font->Color = clRed;
  1732.        //      lb_META_factory_status->Caption = " Agilent 663x2 resume fail!";
  1733.        //      MF_state = eError;
  1734.        //      write_log();
  1735.        //      //write_result(); // added by Andy Ueng
  1736.        // break;
  1737.         case WM_MF_ADC_DCS_MEASURE_VOLTAGE_FAIL:
  1738.         {
  1739.              lb_META_factory_status->Font->Color = clRed;
  1740.              lb_META_factory_status->Caption = " Power supply measure voltage fail!";
  1741.      MF_state = eError;
  1742.             write_log();
  1743.            //write_result(); // added by Andy Ueng
  1744.         }
  1745.         break;
  1746.        // case WM_MF_AGE663x2_MEASURE_VOLTAGE_FAIL:
  1747.        //      lb_META_factory_status->Font->Color = clRed;
  1748.        //      lb_META_factory_status->Caption = " Agilent 663x2 measure voltage fail!";
  1749.        ////      MF_state = eError;
  1750.        //      write_log();
  1751.        //      //write_result(); // added by Andy Ueng
  1752.        // break;
  1753.         case WM_MF_ADC_DCS_CLOSE_FAIL:
  1754.         {
  1755.             lb_META_factory_status->Font->Color = clRed;
  1756.             lb_META_factory_status->Caption = " Power supply close fail!";
  1757.             MF_state = eError;
  1758.             write_log();
  1759.             //write_result(); // added by Andy Ueng
  1760.         }    
  1761.         break;
  1762.     //    case WM_MF_AGE663x2_CLOSE_FAIL:
  1763.     //         lb_META_factory_status->Font->Color = clRed;
  1764.     //         lb_META_factory_status->Caption = " Agilent 663x2 close fail!";
  1765.     //         MF_state = eError;
  1766.     //         write_log();
  1767.     //         //write_result(); // added by Andy Ueng
  1768.     //    break;
  1769.         case WM_MF_ADC_DCS_SET_VOLTAGE_CURRENT_FAIL:
  1770.         {
  1771.             lb_META_factory_status->Font->Color = clRed;
  1772.             lb_META_factory_status->Caption = " Set voltage and current of power supply fail!";
  1773.             MF_state = eError;
  1774.             write_log();
  1775.             //write_result(); // added by Andy Ueng
  1776.         }    
  1777.         break;
  1778.         //////////////////////////    ADC    ////////////////////////////
  1779.         case WM_MF_ADC_BEGIN:
  1780.         {
  1781.             lb_META_factory_status->Font->Color = clWindowText;
  1782.             lb_META_factory_status->Caption = " ADC calibration in progress!";
  1783.             MF_state = eADC;
  1784.             write_log();
  1785.         }
  1786.         break;
  1787.         case WM_MF_PT_ADC_CALIBRATION_NEW_FAIL:
  1788.         {
  1789.             lb_META_factory_status->Font->Color = clRed;
  1790.             lb_META_factory_status->Caption = " ADC PT calibration new fail!";
  1791.             MF_state = eError;
  1792.             write_log();
  1793.         }
  1794.         break;
  1795.         case WM_MF_ADC_MEASURE_FAIL:
  1796.         {
  1797.             lb_META_factory_status->Font->Color = clRed;
  1798.             lb_META_factory_status->Caption = " ADC calibration ADC measure fail!";
  1799.             MF_state = eError;
  1800.             write_log();
  1801.         }
  1802.         break;
  1803.         case WM_MF_ADC_EVALUATE_SLOPE_OFFSET_FAIL:
  1804.         {
  1805.             lb_META_factory_status->Font->Color = clRed;
  1806.             lb_META_factory_status->Caption = " ADC calibration evaluate slope offset fail!";
  1807.             MF_state = eError;
  1808.             write_log();
  1809.         }
  1810.         break;
  1811.         case WM_MF_ADC_CHECK_BATTERY_VOLTAGE_DIFFERENCE_FAIL:
  1812.         {
  1813.             lb_META_factory_status->Font->Color = clRed;
  1814.             lb_META_factory_status->Caption = " ADC calibration check battery voltage difference fail!";
  1815.             MF_state = eError;
  1816.             write_log();
  1817.         }
  1818.         break;
  1819.         case WM_MF_ADC_CHECK_CURRENT_DIFFERENCE_FAIL:
  1820.         {
  1821.             lb_META_factory_status->Font->Color = clRed;
  1822.             lb_META_factory_status->Caption = " ADC calibration check current difference fail!";
  1823.             MF_state = eError;
  1824.             write_log();
  1825.         }
  1826.         break;
  1827.         case WM_MF_ADC_CHECK_SLOPE_OFFSET_FAIL:
  1828.         {
  1829.             lb_META_factory_status->Font->Color = clRed;
  1830.             lb_META_factory_status->Caption = " ADC calibration check slope offset fail!";
  1831.             MF_state = eError;
  1832.             write_log();
  1833.         }
  1834.         break;
  1835.         case WM_MF_NVRAM_ADC_WRITE_FAIL:
  1836.         {
  1837.              lb_META_factory_status->Font->Color = clRed;
  1838.              lb_META_factory_status->Caption = " Write ADC slope and offset to NVRAM fail!";
  1839.              MF_state = eError;
  1840.              write_log();
  1841.         }
  1842.         break;
  1843.         case WM_MF_NVRAM_EF_ADC_LID_VERNO_FAIL:
  1844.         {
  1845.             lb_META_factory_status->Font->Color = clRed;
  1846.             lb_META_factory_status->Caption = " NVRAM_EF_ADC_LID version is not support, please update META to latest version.";
  1847.             MF_state = eError;
  1848.             write_log();
  1849.         }
  1850.         break;
  1851.         case WM_MF_NVRAM_ADC_READ_FAIL:
  1852.         {
  1853.              lb_META_factory_status->Font->Color = clRed;
  1854.              lb_META_factory_status->Caption = " Read ADC slope and offset from NVRAM fail!";
  1855.              MF_state = eError;
  1856.              write_log();
  1857.         }
  1858.         break;
  1859.         case WM_MF_ADC_CHECK_SLOPE_OFFSET_PASS:
  1860.         {
  1861.              lb_META_factory_status->Font->Color = clWindowText;
  1862.              lb_META_factory_status->Caption = " ADC calibration check slope and offset pass!";
  1863.         }
  1864.         break;
  1865.         case WM_MF_ADC_SUCCESS:
  1866.         {
  1867.              lb_META_factory_status->Font->Color = clWindowText;
  1868.              after_Calibration_TerminateSuccess( NULL );
  1869.         }
  1870.         break;
  1871.         case WM_MF_ADC_FAIL:
  1872.         {
  1873.              lb_META_factory_status->Font->Color = clRed;
  1874.              after_Calibration_Fail( NULL );
  1875.         }
  1876.         break;
  1877.         case WM_MF_ADC_TERM_BY_USER:
  1878.         {
  1879.              lb_META_factory_status->Font->Color = clWindowText;
  1880.              after_Calibration_TerminateByUser( NULL );
  1881.         }
  1882.         break;
  1883.         case WM_MF_ADC_CALIBRATION_DONE:
  1884.         {
  1885.             lb_META_factory_status->Font->Color = clWindowText;
  1886.             lb_META_factory_status->Caption = " ADC calibration done!";
  1887.             write_log();
  1888.         }
  1889.         break;
  1890.         ///////////////////////////   CV calibration     ////////////////////////////
  1891.         case WM_MF_CV_BEGIN:
  1892.         {
  1893.             lb_META_factory_status->Font->Color = clWindowText;
  1894.             lb_META_factory_status->Caption = " CV calibration in progress!";
  1895.             MF_state = eCV;
  1896.             write_log();
  1897.         }
  1898.         break;
  1899.         case WM_MF_CV_CHECK_FAIL:
  1900.         {
  1901.             lb_META_factory_status->Font->Color = clRed;
  1902.             lb_META_factory_status->Caption = " CV calibration check fail!";
  1903.             MF_state = eError;
  1904.             write_log();
  1905.         }
  1906.         break;
  1907.         case WM_MF_NVRAM_CV_READ_FAIL:
  1908.         {
  1909.             lb_META_factory_status->Font->Color = clRed;
  1910.             lb_META_factory_status->Caption = " Read CV from NVRAM fail!";
  1911.             MF_state = eError;
  1912.             write_log();
  1913.         }
  1914.         break;
  1915.         case WM_MF_NVRAM_CV_WRITE_FAIL:
  1916.         {
  1917.             lb_META_factory_status->Font->Color = clRed;
  1918.             lb_META_factory_status->Caption = " Write CV to NVRAM fail!";
  1919.             MF_state = eError;
  1920.             write_log();
  1921.         }
  1922.         break;
  1923.         case WM_MF_CV_CALIBRATION_DONE:
  1924.         {
  1925.             lb_META_factory_status->Font->Color = clWindowText;
  1926.             lb_META_factory_status->Caption = " CV calibration done!";
  1927.             write_log();
  1928.         }
  1929.         break;
  1930.         ///////////////////////////   WiFi common        ////////////////////////////
  1931.         case WM_MF_WIFI_CHANNEL_INDEX_NOT_FOUND_FAIL:
  1932.         {
  1933.             lb_META_factory_status->Font->Color = clRed;
  1934.             lb_META_factory_status->Caption = " WiFi channel index not found fail!";
  1935.             MF_state = eError;
  1936.             write_log();
  1937.         }
  1938.         break;
  1939.         case WM_MF_WIFI_TX_RATE_802_11B_FAIL:
  1940.         {
  1941.             lb_META_factory_status->Font->Color = clRed;
  1942.             lb_META_factory_status->Caption = " Incorrect 802.11b TX rate fail!";
  1943.             MF_state = eError;
  1944.             write_log();
  1945.         }
  1946.         break;
  1947.         case WM_MF_WIFI_TX_RATE_802_11AG_FAIL:
  1948.         {
  1949.             lb_META_factory_status->Font->Color = clRed;
  1950.             lb_META_factory_status->Caption = " 802.11a, 802.11g TX rate should be 48 or 54 MHz!";
  1951.             MF_state = eError;
  1952.             write_log();
  1953.         }
  1954.         break;
  1955.         //////////////////////////    WiFi Equipment     ////////////////////////////
  1956.         case WM_LOAD_N4010A_DLL_FAILED:
  1957.         case WM_LOAD_N4010A_DLL_FUNCTION_FAILED:
  1958.         {
  1959.              Application->MessageBox("Load Agilent N40410A AgN4010WSODrv.dll fail", "Warning", MB_OK );
  1960.         }
  1961.         break;
  1962.         //////////////////////////    WiFi TX power    ////////////////////////////
  1963.         case WM_MF_WIFI_CPT_FAIL:
  1964.         {
  1965.             lb_META_factory_status->Font->Color = clRed;
  1966.             lb_META_factory_status->Caption = " WiFi TX power calibration continuous packet TX fail!";
  1967.             MF_state = eError;
  1968.             write_log();
  1969.         }
  1970.         break;
  1971.         case WM_MF_WIFI_CPT_STOP_FAIL:
  1972.         {
  1973.             lb_META_factory_status->Font->Color = clRed;
  1974.             lb_META_factory_status->Caption = " WiFi TX power calibration stop continuous packet TX fail!";
  1975.             MF_state = eError;
  1976.             write_log();
  1977.         }
  1978.         break;
  1979.         case WM_MF_NVRAM_WIFI_APC_READ_FAIL:
  1980.         {
  1981.             lb_META_factory_status->Font->Color = clRed;
  1982.             lb_META_factory_status->Caption = " WiFi TX power calibration read WiFi TX power from NVRAM fail!";
  1983.             MF_state = eError;
  1984.             write_log();
  1985.         }
  1986.         break;
  1987.         case WM_MF_NVRAM_WIFI_APC_WRITE_FAIL:
  1988.         {
  1989.             lb_META_factory_status->Font->Color = clRed;
  1990.             lb_META_factory_status->Caption = " WiFi TX power calibration write WiFi TX power to NVRAM fail!";
  1991.             MF_state = eError;
  1992.             write_log();
  1993.         }
  1994.         break;
  1995.         case WM_MF_NVRAM_WIFI_ALC_READ_FAIL:
  1996.         {
  1997.             lb_META_factory_status->Font->Color = clRed;
  1998.             lb_META_factory_status->Caption = " Read WiFi ALC from NVRAM fail!";
  1999.             MF_state = eError;
  2000.             write_log();
  2001.         }
  2002.         break;
  2003.         case WM_MF_NVRAM_WIFI_ALC_WRITE_FAIL:
  2004.         {
  2005.             lb_META_factory_status->Font->Color = clRed;
  2006.             lb_META_factory_status->Caption = " write WiFi ALC to NVRAM fail!";
  2007.             MF_state = eError;
  2008.             write_log();
  2009.         }
  2010.         break;
  2011.         case WM_MF_NVRAM_EF_WNDRV_DAC_DC_OFFSET_LID_VERNO_FAIL:
  2012.         {
  2013.             lb_META_factory_status->Font->Color = clRed;
  2014.             lb_META_factory_status->Caption = " NVRAM_EF_WNDRV_DAC_DC_OFFSET_LID version is not support, please update META to latest version.";
  2015.             MF_state = eError;
  2016.             write_log();
  2017.         }
  2018.         break;
  2019.         case WM_MF_NVRAM_WIFI_TX_DC_OFFSET_READ_FAIL:
  2020.         {
  2021.             lb_META_factory_status->Font->Color = clRed;
  2022.             lb_META_factory_status->Caption = " Read WiFi TX DC offset from NVRAM fail!";
  2023.             MF_state = eError;
  2024.             write_log();
  2025.         }
  2026.         break;
  2027.         case WM_MF_NVRAM_WIFI_TX_DC_OFFSET_WRITE_FAIL:
  2028.         {
  2029.             lb_META_factory_status->Font->Color = clRed;
  2030.             lb_META_factory_status->Caption = " Write WiFi TX DC offset to NVRAM fail!";
  2031.             MF_state = eError;
  2032.             write_log();
  2033.         }
  2034.         break;
  2035.         case WM_MF_NVRAM_EF_WNDRV_TX_POWER_xxx_LID_VERNO_FAIL:
  2036.         {
  2037.             lb_META_factory_status->Font->Color = clRed;
  2038.             lb_META_factory_status->Caption = " NVRAM_EF_WNDRV_TX_POWER_xxx_LID version is not support, please update META to latest version.";
  2039.             MF_state = eError;
  2040.             write_log();
  2041.         }
  2042.         break;
  2043.         case WM_MF_NVRAM_EF_WNDRV_TX_ALC_POWER_LID_VERNO_FAIL:
  2044.         {
  2045.             lb_META_factory_status->Font->Color = clRed;
  2046.             lb_META_factory_status->Caption = " NVRAM_EF_WNDRV_TX_ALC_POWER_LID version is not support, please update META to latest version.";
  2047.             MF_state = eError;
  2048.             write_log();
  2049.         }
  2050.         break;
  2051.         case WM_MF_NVRAM_EF_WNDRV_ALC_SLOPE_LID_VERNO_FAIL:
  2052.         {
  2053.             lb_META_factory_status->Font->Color = clRed;
  2054.             lb_META_factory_status->Caption = " NVRAM_EF_WNDRV_ALC_SLOPE_LID version is not support, please update META to latest version.";
  2055.             MF_state = eError;
  2056.             write_log();
  2057.         }
  2058.         break;
  2059.         case WM_MF_WIFI_TX_POWER_BEGIN:
  2060.         {
  2061.             lb_META_factory_status->Font->Color = clWindowText;
  2062.             lb_META_factory_status->Caption = " WiFi TX power calibration in progress!";
  2063.             MF_state = eWIFI_TXPCL;
  2064.             write_log();
  2065.         }
  2066.         break;
  2067.         case WM_MF_WIFI_INIT_FAIL:
  2068.         {
  2069.              lb_META_factory_status->Font->Color = clRed;
  2070.              lb_META_factory_status->Caption = " WiFi tester init fail!";
  2071.      MF_state = eError;
  2072.             write_log();
  2073.         }
  2074.         break;
  2075.         case WM_MF_WIFI_TERMINATE_FAIL:
  2076.         {
  2077.             lb_META_factory_status->Font->Color = clRed;
  2078.             lb_META_factory_status->Caption = " WiFi tester terminate fail!";
  2079.             MF_state = eError;
  2080.             write_log();
  2081.         }
  2082.         break;
  2083.         case WM_MF_WIFI_CONN_OPEN_FAIL:
  2084.         {
  2085.             lb_META_factory_status->Font->Color = clRed;
  2086.             lb_META_factory_status->Caption = " WiFi tester connection open fail!";
  2087.             MF_state = eError;
  2088.             write_log();
  2089.         }
  2090.         break;
  2091.         case WM_MF_WIFI_CONN_UPDATE_CALDATA_FAIL:
  2092.         {
  2093.             lb_META_factory_status->Font->Color = clRed;
  2094.             lb_META_factory_status->Caption = " WiFi tester update calibration data fail!";
  2095.             MF_state = eError;
  2096.             write_log();
  2097.         }
  2098.         break;
  2099.         case WM_MF_WIFI_CONN_CLOSE_FAIL:
  2100.         {
  2101.             lb_META_factory_status->Font->Color = clRed;
  2102.             lb_META_factory_status->Caption = " WiFi tester connection close fail!";
  2103.             MF_state = eError;
  2104.             write_log();
  2105.         }
  2106.         break;
  2107.         case WM_MF_WIFI_SET_DEFAULT_FAIL:
  2108.         {
  2109.             lb_META_factory_status->Font->Color = clRed;
  2110.             lb_META_factory_status->Caption = " WiFi tester sets default value fail!";
  2111.             MF_state = eError;
  2112.             write_log();
  2113.         }
  2114.         break;
  2115.         case WM_MF_WIFI_SET_PACKET_LEN_FAIL:
  2116.         {
  2117.             lb_META_factory_status->Font->Color = clRed;
  2118.             lb_META_factory_status->Caption = " WiFi tester sets packet length fail!";
  2119.             MF_state = eError;
  2120.             write_log();
  2121.         }
  2122.         break;
  2123.         case WM_MF_WIFI_SET_TRIGGER_STYLE_FAIL:
  2124.         {
  2125.             lb_META_factory_status->Font->Color = clRed;
  2126.             lb_META_factory_status->Caption = " WiFi tester sets trigger style fail!";
  2127.             MF_state = eError;
  2128.             write_log();
  2129.         }
  2130.         break;
  2131.         case WM_MF_WIFI_APPLY_CHANGE_FAIL:
  2132.         {
  2133.             lb_META_factory_status->Font->Color = clRed;
  2134.             lb_META_factory_status->Caption = " WiFi tester applies change value fail!";
  2135.             MF_state = eError;
  2136.             write_log();
  2137.         }
  2138.         break;
  2139.         case WM_MF_WIFI_SET_CENTRAL_FREQ_FAIL:
  2140.         {
  2141.             lb_META_factory_status->Font->Color = clRed;
  2142.             lb_META_factory_status->Caption = " WiFi tester sets central frequency fail!";
  2143.             MF_state = eError;
  2144.             write_log();
  2145.         }
  2146.         break;
  2147.         case WM_MF_WIFI_SET_POWER_RANGE_FAIL:
  2148.         {
  2149.             lb_META_factory_status->Font->Color = clRed;
  2150.             lb_META_factory_status->Caption = " WiFi tester sets power range fail!";
  2151.             MF_state = eError;
  2152.             write_log();
  2153.         }
  2154.         break;
  2155.         case WM_MF_WIFI_DATA_CAPTURE_FAIL:
  2156.         {
  2157.             lb_META_factory_status->Font->Color = clRed;
  2158.             lb_META_factory_status->Caption = " WiFi tester captures data fail!";
  2159.             MF_state = eError;
  2160.             write_log();
  2161.         }
  2162.         break;
  2163.         case WM_MF_WIFI_ANALYZE_POWER_FAIL:
  2164.         {
  2165.             lb_META_factory_status->Font->Color = clRed;
  2166.             lb_META_factory_status->Caption = " WiFi tester analyzes TX power fail!";
  2167.             MF_state = eError;
  2168.             write_log();
  2169.         }
  2170.         break;
  2171.         case WM_MF_WIFI_READ_POWER_FAIL:
  2172.         {
  2173.             lb_META_factory_status->Font->Color = clRed;
  2174.             lb_META_factory_status->Caption = " WiFi tester reads TX power fail!";
  2175.             MF_state = eError;
  2176.             write_log();
  2177.         }
  2178.         break;
  2179.         case WM_MF_WIFI_TX_POWER_CALIBRATION_DONE:
  2180.         {
  2181.             lb_META_factory_status->Font->Color = clWindowText;
  2182.             lb_META_factory_status->Caption = " WiFi TX power calibration done!";
  2183.             MF_state = eWIFI_TXPCL;
  2184.             write_log();
  2185.         }
  2186.         break;
  2187.         case WM_MF_WIFI_TX_DC_OFFSET_BEGIN:
  2188.         {
  2189.             lb_META_factory_status->Font->Color = clWindowText;
  2190.             lb_META_factory_status->Caption = " WiFi TX DC offset calibration in progress!";
  2191.             MF_state = eWIFI_TXPCL;
  2192.             write_log();
  2193.         }
  2194.         break;
  2195.         case WM_MF_WIFI_TX_DC_OFFSET_FAIL:
  2196.         {
  2197.             lb_META_factory_status->Font->Color = clRed;
  2198.             lb_META_factory_status->Caption = " WiFi TX DC offset calibration fail!";
  2199.             MF_state = eError;
  2200.             write_log();
  2201.         }
  2202.         break;
  2203.         case WM_MF_WIFI_TX_DC_OFFSET_CALIBRATION_DONE:
  2204.         {
  2205.             lb_META_factory_status->Font->Color = clWindowText;
  2206.             lb_META_factory_status->Caption = " WiFi TX DC offset calibration done!";
  2207.             MF_state = eWIFI_TXPCL;
  2208.             write_log();
  2209.         }
  2210.         break;
  2211.         /////////////////////////////////  BT tester  ///////////////////////
  2212.         case WM_MF_BTT_INIT_FAIL:
  2213.         {
  2214.             lb_META_factory_status->Font->Color = clRed;
  2215.             lb_META_factory_status->Caption = " BT tester initialize fail";
  2216.             MF_state = eError;
  2217.             write_log();
  2218.         }
  2219.         break;
  2220.         case WM_MF_BTT_CLOSE_FAIL:
  2221.         {
  2222.             lb_META_factory_status->Font->Color = clRed;
  2223.             lb_META_factory_status->Caption = " BT tester close fail";
  2224.             MF_state = eError;
  2225.             write_log();
  2226.         }
  2227.         break;
  2228.         case WM_MF_BTT_CONFIG_SLAVE_PARAMETER_FAIL:
  2229.         {
  2230.             lb_META_factory_status->Font->Color = clRed;
  2231.             lb_META_factory_status->Caption = " BT tester config slave parameter fail";
  2232.             MF_state = eError;
  2233.             write_log();
  2234.         }
  2235.         break;
  2236.         case WM_MF_BTT_CONFIG_DOWNLINK_POWER_FAIL:
  2237.         {
  2238.             lb_META_factory_status->Font->Color = clRed;
  2239.             lb_META_factory_status->Caption = " BT tester config BD address fail";
  2240.             MF_state = eError;
  2241.             write_log();
  2242.         }
  2243.         break;
  2244.         case WM_MF_BTT_CONFIG_BD_ADDRESS_FAIL:
  2245.         {
  2246.             lb_META_factory_status->Font->Color = clRed;
  2247.             lb_META_factory_status->Caption = " BT tester config BD address fail";
  2248.             MF_state = eError;
  2249.             write_log();
  2250.         }
  2251.         break;
  2252.         case WM_MF_BTT_CONFIG_INQUIRY_FAIL:
  2253.         {
  2254.             lb_META_factory_status->Font->Color = clRed;
  2255.             lb_META_factory_status->Caption = " BT tester config inquiry parameter fail";
  2256.             MF_state = eError;
  2257.             write_log();
  2258.         }
  2259.         break;
  2260.         case WM_MF_BTT_CONFIG_SCAN_FAIL:
  2261.         {
  2262.             lb_META_factory_status->Font->Color = clRed;
  2263.             lb_META_factory_status->Caption = " BT tester config scan parameter fail";
  2264.             MF_state = eError;
  2265.             write_log();
  2266.         }
  2267.         break;
  2268.         case WM_MF_BTT_INQUIRY_FAIL:
  2269.         {
  2270.             lb_META_factory_status->Font->Color = clRed;
  2271.             lb_META_factory_status->Caption = " BT tester inquiry fail";
  2272.             MF_state = eError;
  2273.             write_log();
  2274.         }
  2275.         break;
  2276.         case WM_MF_BTT_CONNECT_TEST_FAIL:
  2277.         {
  2278.             lb_META_factory_status->Font->Color = clRed;
  2279.             lb_META_factory_status->Caption = " BT tester connect testmode fail";
  2280.             MF_state = eError;
  2281.             write_log();
  2282.         }
  2283.         break;
  2284.         case WM_MF_BTT_RELEASE_FAIL:
  2285.         {
  2286.             lb_META_factory_status->Font->Color = clRed;
  2287.             lb_META_factory_status->Caption = " BT tester release connection fail";
  2288.             MF_state = eError;
  2289.             write_log();
  2290.         }
  2291.         break;
  2292.         case WM_MF_BTT_QUERY_STATE_FAIL:
  2293.         {
  2294.             lb_META_factory_status->Font->Color = clRed;
  2295.             lb_META_factory_status->Caption = " BT tester query state fail";
  2296.             MF_state = eError;
  2297.             write_log();
  2298.         }
  2299.         break;
  2300.         case WM_MF_BTT_CONFIG_MOD_FAIL:
  2301.         {
  2302.             lb_META_factory_status->Font->Color = clRed;
  2303.             lb_META_factory_status->Caption = " BT tester config modulation fail";
  2304.             MF_state = eError;
  2305.             write_log();
  2306.         }
  2307.         break;
  2308.         case WM_MF_BTT_READ_FREQ_ACCURACY:
  2309.         {
  2310.             lb_META_factory_status->Font->Color = clRed;
  2311.             lb_META_factory_status->Caption = " BT tester read frequency accuracy fail";
  2312.             MF_state = eError;
  2313.             write_log();
  2314.         }
  2315.         break;
  2316.         /////////////////////////////////  BT CAP ID  ///////////////////////
  2317.         case WM_MF_BT_CRYSTAL_CAPID_BEGIN:
  2318.         {
  2319.             lb_META_factory_status->Font->Color = clWindowText;
  2320.             lb_META_factory_status->Caption = " BT CAP ID calibration in progress";
  2321.             MF_state = eBT_CAP_ID;
  2322.             write_log();
  2323.         }
  2324.         break;
  2325.         case WM_MF_BT_CRYSTAL_CAPID_WRITE_CAL_RESULT_FAIL:
  2326.         {
  2327.             lb_META_factory_status->Font->Color = clRed;
  2328.             lb_META_factory_status->Caption = " Write BT CAP ID to .cal file fail";
  2329.             MF_state = eError;
  2330.             write_log();
  2331.         }
  2332.         break;
  2333.         case WM_MF_BT_ENABLE_PCM_CLOCK_SYNC_SIGNAL_FAIL:
  2334.         {
  2335.             lb_META_factory_status->Font->Color = clRed;
  2336.             lb_META_factory_status->Caption = " Enable PCM clock sync. signal fail";
  2337.             MF_state = eError;
  2338.             write_log();
  2339.         }
  2340.         break;
  2341.         case WM_MF_BT_START_CALIBRATE_CRYSTAL_CLOCK_FAIL:
  2342.         {
  2343.             lb_META_factory_status->Font->Color = clRed;
  2344.             lb_META_factory_status->Caption = " BT start to calibrate crystal clock fail";
  2345.             MF_state = eError;
  2346.             write_log();
  2347.         }
  2348.         break;
  2349.         case WM_MF_BT_READ_CRYSTAL_CLOCK_RESULT_FAIL:
  2350.         {
  2351.             lb_META_factory_status->Font->Color = clRed;
  2352.             lb_META_factory_status->Caption = " BT read crystal clock result fail";
  2353.             MF_state = eError;
  2354.             write_log();
  2355.         }
  2356.         break;
  2357.         case WM_MF_BT_SET_CRYSTAL_CAPID_FAIL:
  2358.         {
  2359.             lb_META_factory_status->Font->Color = clRed;
  2360.             lb_META_factory_status->Caption = " BT set crystal CAP ID fail";
  2361.             MF_state = eError;
  2362.             write_log();
  2363.         }
  2364.         break;
  2365.         case WM_MF_BT_CRYSTAL_CAPID_CHECK_FAIL:
  2366.         {
  2367.             lb_META_factory_status->Font->Color = clRed;
  2368.             lb_META_factory_status->Caption = " BT CAP ID calibration check fail";
  2369.             MF_state = eError;
  2370.             write_log();
  2371.         }
  2372.         break;
  2373.         case WM_MF_BT_ENTER_TEST_MODE_FAIL:
  2374.         {
  2375.             lb_META_factory_status->Font->Color = clRed;
  2376.             lb_META_factory_status->Caption = " BT enter test mode fail";
  2377.             MF_state = eError;
  2378.             write_log();
  2379.         }
  2380.         break;
  2381.         case WM_MF_BT_INQUIRY_ENABLE_FAIL:
  2382.         {
  2383.             lb_META_factory_status->Font->Color = clRed;
  2384.             lb_META_factory_status->Caption = " BT inquiry enable fail";
  2385.             write_log();
  2386.         }
  2387.         break;
  2388.         case WM_MF_NVRAM_BT_INFO_READ_FAIL:
  2389.         {
  2390.             lb_META_factory_status->Font->Color = clRed;
  2391.             lb_META_factory_status->Caption = " Read BT info. from NVRAM fail!";
  2392.             MF_state = eError;
  2393.             write_log();
  2394.         }
  2395.         break;
  2396.         case WM_MF_NVRAM_BT_INFO_WRITE_FAIL:
  2397.         {
  2398.             lb_META_factory_status->Font->Color = clRed;
  2399.             lb_META_factory_status->Caption = " Write BT info. to NVRAM fail!";
  2400.             MF_state = eError;
  2401.             write_log();
  2402.         }
  2403.         break;
  2404.         case WM_MF_NVRAM_EF_BTRADIO_MT6601_LID_VERNO_FAIL:
  2405.         {
  2406.             lb_META_factory_status->Font->Color = clRed;
  2407.             lb_META_factory_status->Caption = " NVRAM_EF_BTRADIO_MT6601_LID version is not support, please update META to latest version.";
  2408.             MF_state = eError;
  2409.             write_log();
  2410.         }
  2411.         break;
  2412.         case WM_MF_BT_CRYSTAL_CAPID_CALIBRATION_DONE:
  2413.         {
  2414.             lb_META_factory_status->Font->Color = clWindowText;
  2415.             lb_META_factory_status->Caption = " BT crystal CAP ID calibration done";
  2416.             MF_state = eInit;
  2417.             write_log();
  2418.         }
  2419.         break;
  2420.         default:
  2421.         {
  2422.            this->WndProc(Message);
  2423.         }
  2424.         break;
  2425.     } // switch
  2426. }
  2427. //---------------------------------------------------------------------------
  2428. void TfrmFatcory::write_log()
  2429. {
  2430.     FILE *pf;
  2431.     try
  2432.     {
  2433.         if ( b_SetupLogFile )
  2434.         {
  2435. //         st_Log->SaveToFile(as_LogFileName);
  2436.             if( (pf = fopen( as_LogFileName.c_str() ,"at+")) == NULL )
  2437.             {
  2438.                 AnsiString as_warning_msg;
  2439.                 as_warning_msg = "Cannot open output file: " + as_LogFileName;
  2440.                 Application->MessageBox( as_warning_msg.c_str(), "Warning", MB_OK );
  2441.                 return;
  2442.             }
  2443.             if ( NULL == st_Log )
  2444.             {
  2445.                 return;
  2446.             }
  2447.             for(int I=0; I<st_Log->Count; I++)
  2448.             {
  2449.                 fprintf(pf, AnsiString(st_Log->Strings[I] + "n").c_str() );
  2450.             } // for
  2451.             fclose(pf);
  2452.             st_Log->Clear();
  2453.         } // if
  2454.     } // try
  2455.     catch(...)
  2456.     {
  2457.         AnsiString as_warning_msg;
  2458.         as_warning_msg = " write log file error "+as_LogFileName;
  2459.         Application->MessageBox( as_warning_msg.c_str(), "Warning", MB_OK );
  2460.     }
  2461. }
  2462. //---------------------------------------------------------------------------
  2463. void TfrmFatcory::write_result()
  2464. {
  2465.     FILE *pf;
  2466.     if(m_Cal.as_ResultBuf.AnsiCompare("") == 0)
  2467.         return;
  2468.     try
  2469.     {
  2470.         if ( b_SetupResultFile )
  2471.         {
  2472.             if ((pf = fopen( as_ResultFileName.c_str() ,"at+")) == NULL)
  2473.             {
  2474.                 AnsiString as_warning_msg;
  2475.                 as_warning_msg = "Cannot open output file: " + as_ResultFileName;
  2476.                 Application->MessageBox( as_warning_msg.c_str(), "Warning", MB_OK );
  2477.                 return;
  2478.             }
  2479.        // modified by Andy Ueng
  2480.       // fprintf(pf, AnsiString(ResultHeaderBuf2 + "n").c_str());
  2481.             fprintf(pf, AnsiString(m_Cal.as_ResultBuf + "n").c_str());
  2482.        // for( int I=0; I<st_Result->Count; I++)
  2483.        // {
  2484.        //    fprintf(pf, AnsiString(st_Result->Strings[I] + "n").c_str() );
  2485.        // } // for
  2486.             fclose(pf);
  2487.        // st_Result->Clear();
  2488.         //ResultHeaderBuf2 = "";
  2489.             m_Cal.as_ResultBuf = "";
  2490.         // end of modified
  2491.         } // if
  2492.     } // try
  2493.     catch(...)
  2494.     {
  2495.         AnsiString as_warning_msg;
  2496.         as_warning_msg = " write result file error "+as_ResultFileName;
  2497.         Application->MessageBox( as_warning_msg.c_str(), "Warning", MB_OK );
  2498.     }
  2499. }
  2500. //---------------------------------------------------------------------------
  2501. void TfrmFatcory::clear_log()
  2502. {
  2503.     st_Log->Clear();
  2504. }
  2505. //---------------------------------------------------------------------------
  2506.  void TfrmFatcory::clear_result()
  2507.  {
  2508.     // modified by Andy Ueng
  2509.     //st_Result->Clear();
  2510.     //ResultHeaderBuf2 = "";
  2511.     m_Cal.as_ResultBuf = "";
  2512.     // end of modified
  2513.  }
  2514. //---------------------------------------------------------------------------
  2515.  void __fastcall TfrmFatcory::on_Calibration_TerminateByUser(TObject *Sender)
  2516.  {
  2517.      on_Calibration_TerminateByUser_function();
  2518.  }
  2519. //---------------------------------------------------------------------------
  2520. void __fastcall TfrmFatcory::on_Calibration_TerminateByUser_function(void)
  2521. {
  2522.     DisableAllCalTimer();
  2523.     is_calibration_start = false;
  2524.     PostMessage(
  2525.                           this->Handle,
  2526.                           WM_MF_CA_TERM_BY_USER,
  2527.                           0,
  2528.                           0
  2529.                         );
  2530.     //////////////////////// RF calibration /////////////////////////////////////////
  2531.     if (cbIP2->Checked        ||
  2532.         cbAFC->Checked        ||
  2533.         cbRxPathLoss->Checked ||
  2534.         cbTxIq->Checked       ||
  2535.         cbTxPcl->Checked      ||
  2536.         m_cbTrxOffset->Checked
  2537.       )
  2538.     {
  2539.         RCT_Dcl_Reset_Close();
  2540.     }
  2541.     //////////////////////// BT CAP ID calibration /////////////////////////////////////////
  2542.     if (m_cbBTCapID->Checked)
  2543.     {
  2544.         if (!m_btt_ctrl.BTT_Close(&m_sBtt))
  2545.         {
  2546.             PostMessage(
  2547.                           this->Handle,
  2548.                           WM_MF_BTT_CLOSE_FAIL,
  2549.                           0,
  2550.                           0
  2551.                         );
  2552.         }
  2553.     }
  2554.     ///////////////////////////// ADC calibration ///////////////////////////////////////////
  2555.     if(cbADC->Checked)
  2556.     {
  2557.          if( m_Dcs.vi )
  2558.          {
  2559.               SetNormalVoltage_CloseAgilentPowerSupply();
  2560.          }
  2561.          else
  2562.          {
  2563.              InitAgilentPowerSupply_SetNormalVoltage_CloseAgilentPowerSupply();
  2564.          }
  2565.          //PostMessage(
  2566.          //             this->Handle,
  2567.          //             WM_MF_ADC_TERM_BY_USER,
  2568.          //             0,
  2569.          //             0
  2570.          //           );
  2571.     }
  2572. }
  2573. //---------------------------------------------------------------------------
  2574. void __fastcall TfrmFatcory::after_Calibration_TerminateByUser(TObject *Sender)
  2575. {
  2576.         lb_META_factory_status->Caption = " Calibration terminated by user";
  2577.         st_Log->Add( DateToStr(Date()) + " " + CurrentTimeStr() +
  2578.                      " Calibration terminated by user"
  2579.                    );
  2580.         write_log();
  2581.         clear_log();
  2582.         write_result(); // added by Andy Ueng
  2583.       //  bb_Start->Kind = bkOK;
  2584.         bb_Start->Tag = BUTTON_TAG_START;
  2585.         bb_Start->Enabled = true;
  2586.         bb_Start->Caption = "Start (F6)";
  2587.         if( cbIP2->Checked            ||
  2588.             cbAFC->Checked            ||
  2589.             cbRxPathLoss->Checked     ||
  2590.             cbTxIq->Checked           ||
  2591.             cbTxPcl->Checked
  2592.         )
  2593.         {
  2594.             MF_state = eInit;
  2595.             CRFSTOP RF_STOP_Obj;
  2596.             RF_STOP_Obj.REQ_Start();
  2597.         }
  2598.         if( cbADC->Checked )
  2599.         {
  2600.             MF_state = eInit;
  2601.         }
  2602. }
  2603. //---------------------------------------------------------------------------
  2604.  void __fastcall TfrmFatcory::on_Calibration_Fail(TObject *Sender)
  2605.  {
  2606.       on_Calibration_Fail_function();
  2607.  }
  2608. //---------------------------------------------------------------------------
  2609. void __fastcall TfrmFatcory::on_Calibration_Fail_function( void )
  2610. {
  2611.     DisableAllCalTimer();
  2612.     //////////////////////// RF calibration //////////////////////////////////////