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

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) 2001
  8. *
  9. *****************************************************************************/
  10. /*****************************************************************************
  11.  *
  12.  * Filename:
  13.  * ---------
  14.  *   T_WiFi_TXPCL.cpp
  15.  *
  16.  * Project:
  17.  * --------
  18.  *   Maui META APP
  19.  *
  20.  * Description:
  21.  * ------------
  22.  *  WiFi TXPCL calibration source
  23.  *
  24.  * Author:
  25.  * -------
  26.  *  Andy Ueng (mtk00490)
  27.  *
  28.  *============================================================================
  29.  *             HISTORY
  30.  * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  31.  *------------------------------------------------------------------------------
  32.  * $Revision$
  33.  * $Modtime$
  34.  * $Log$
  35.  *
  36.  *------------------------------------------------------------------------------
  37.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  38.  *============================================================================
  39. ****************************************************************************/
  40. #include <assert.h>
  41. #include <math.h>
  42. #pragma hdrstop
  43. #ifndef _T_META_FACTORY_CALIBRATION_H_
  44. #include "T_META_factory_calibration.H"
  45. #endif
  46. #ifndef _CAL_COMMON_H_
  47. #include "cal_common.h"
  48. #endif
  49. // form
  50. #ifndef _META_FACTORY_H_
  51. #include "META_Factory.h"
  52. #endif
  53. #ifndef _FORM_MAIN_H_
  54. #include "form_Main.h"
  55. #endif
  56. // misc
  57. #ifndef  _TIME_UTILS_H_
  58. #include "time_utils.h"
  59. #endif
  60. #ifndef  _MISC_WIFI_H_
  61. #include "misc_wifi.h"
  62. #endif
  63. #ifndef  _FT_UTILS_H_
  64. #include "ft_utils.h"
  65. #endif
  66. // callback
  67. #ifndef _MF_WIFI_NVRAM_CB_H_
  68. #include "mf_wifi_nvram_cb.h"
  69. #endif
  70. #ifndef _MF_WIFI_RF_CB_H_
  71. #include "mf_wifi_rf_cb.h"
  72. #endif
  73. //----------------------------------------------------------------------------
  74. extern bool  is_suspend_cal; // in T_META_factory_calibration.cpp
  75. //----------------------------------------------------------------------------
  76. bool __fastcall T_META_factory_calibration::WiFiTxPclCal_cal(void)
  77. {
  78.      char tempbuf[256];
  79.     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  80.              " ====================== WiFi TX power calibration begin ===================== "
  81.            );
  82.     PostMessage(
  83.                      ctrl.hPostMsgDestHandle,
  84.                      WM_MF_WIFI_TX_POWER_BEGIN,
  85.                      0,
  86.                      0
  87.                     );
  88.     // m_pWft->rx.gain = -60;
  89.     if( IQVIEW == m_pWft->device_type )
  90.     {
  91.         m_pWft->iqv.p_handle->tx.rf_enabled = IQV_RF_DISABLED;
  92.         m_pWft->iqv.p_handle->rx.rf_enabled = IQV_RF_ENABLED;
  93.         m_pWft->iqv.p_handle->rx.rf_port    = IQV_PORT_LEFT;
  94.         m_pWft->iqv.p_handle->rx.vsa_type   = 1;
  95.     }
  96.     S_WIFICPT  wifi_cpt;
  97.     double   virTX;
  98.     WiFi_TestPktTx_Ex_S  pkt_tx_ex;
  99.     WiFi_TxStatus_Ex_S   pkt_tx_ex_status;
  100.     wifi_cpt.wifi_id = m_pCal->s_wifi_cap.rf_chip_id;
  101.     wifi_cpt.reg_domain.country_code[0] = 'U';
  102.     wifi_cpt.reg_domain.country_code[1] = 'S';;
  103.     wifi_cpt.pkt_length = 1024;
  104.     wifi_cpt.pkt_count = 0;
  105.     wifi_cpt.pkt_interval = 100;
  106.     wifi_cpt.pattern = WIFI_TX_PSEUDO_RANDOM;
  107.     wifi_cpt.is_short_preamble = 0;
  108.     wifi_cpt.s_mac_header.frame_ctrl[0] = 0x02;
  109.     wifi_cpt.s_mac_header.frame_ctrl[1] = 0x08;
  110.     wifi_cpt.s_mac_header.duration[0]   = 0x00;
  111.     wifi_cpt.s_mac_header.duration[1]   = 0x00;
  112.     wifi_cpt.s_mac_header.address1[0]   = 0xFF;
  113.     wifi_cpt.s_mac_header.address1[1]   = 0xFF;
  114.     wifi_cpt.s_mac_header.address1[2]   = 0xFF;
  115.     wifi_cpt.s_mac_header.address1[3]   = 0xFF;
  116.     wifi_cpt.s_mac_header.address1[4]   = 0xFF;
  117.     wifi_cpt.s_mac_header.address1[5]   = 0xFF;
  118.     wifi_cpt.s_mac_header.address2[0]   = 0x01;
  119.     wifi_cpt.s_mac_header.address2[1]   = 0x00;
  120.     wifi_cpt.s_mac_header.address2[2]   = 0x00;
  121.     wifi_cpt.s_mac_header.address2[3]   = 0x22;
  122.     wifi_cpt.s_mac_header.address2[4]   = 0x08;
  123.     wifi_cpt.s_mac_header.address2[5]   = 0x00;
  124.     wifi_cpt.s_mac_header.address3[0]   = 0xFF;
  125.     wifi_cpt.s_mac_header.address3[1]   = 0xFF;
  126.     wifi_cpt.s_mac_header.address3[2]   = 0xFF;
  127.     wifi_cpt.s_mac_header.address3[3]   = 0xFF;
  128.     wifi_cpt.s_mac_header.address3[4]   = 0xFF;
  129.     wifi_cpt.s_mac_header.address3[5]   = 0xFF;
  130.     wifi_cpt.s_mac_header.seq_ctrl[0]   = 0x00;
  131.     wifi_cpt.s_mac_header.seq_ctrl[1]   = 0x00;
  132.     pkt_tx_ex.pktCount          = wifi_cpt.pkt_count;
  133.     pkt_tx_ex.pktInterval       = wifi_cpt.pkt_interval;
  134.     pkt_tx_ex.pktLength         = wifi_cpt.pkt_length;
  135.     pkt_tx_ex.pattern           = wifi_cpt.pattern;
  136.     pkt_tx_ex.is_short_preamble = wifi_cpt.is_short_preamble;
  137.     int max_ch_num;
  138.     AnsiString as_cal_channel;
  139.     int nvram_ch_idx;
  140.     S_WIFI_CH_FREQ_MHZ s_cal_ch_freq_mhz;
  141.     double d_max_p;
  142.     double d_min_p;
  143.     double d_WANTED_P;
  144.     double d_Delta;
  145.     double d_CL;
  146.     double d_n4010a_power_range;
  147.     int i_C;
  148.     E_WIFI_MOD mod;
  149.     E_WIFI_GENERATION e_802_11_idx = WIFI_802_11A_IDX;
  150.     while (e_802_11_idx <= WIFI_802_11G_IDX)
  151.     {
  152.         switch(e_802_11_idx)
  153.         {
  154.             case WIFI_802_11A_IDX:
  155.             {
  156.                 if (! IsWiFiSupported( m_asWiFi_Support, e_802_11_idx) )
  157.                 {
  158.                     e_802_11_idx++;
  159.                     continue;
  160.                 }
  161.                 as_cal_channel  = m_as802_11G_CAL_CHANNEL;
  162.                 max_ch_num      = NUM_TX_POWER_5000M_CH;
  163.                 d_WANTED_P      = m_dOFDM_WANTED_P;
  164.                 d_max_p         = m_dOFDM_MAX_P;
  165.                 d_min_p         = m_dOFDM_MIN_P;
  166.                 d_Delta         = m_dOFDM_Delta;
  167.                 i_C             = m_iOFDM_C;
  168.                 mod             = WIFI_MOD_OFDM;
  169.                 if( IQVIEW == m_pWft->device_type )
  170.                 {
  171.                     d_CL            = m_pWft->iqv.d_5g_cl;
  172.                     m_pWft->iqv.p_handle->rx.ampl       = m_dOFDM_WANTED_P + 10;
  173.                     m_pWft->iqv.p_handle->adc.sampling_time = 0.001;
  174.                 }
  175.                 else
  176.                 {
  177.                     d_CL            = m_pWft->s_age_n4010a.d_5g_cl;
  178.                     d_n4010a_power_range                = m_dOFDM_WANTED_P + 5;
  179.                 }
  180.                 wifi_cpt.tx_rate = m_eOFDM_CAL_RATE;
  181.             }
  182.             break;
  183.             case WIFI_802_11B_IDX:
  184.             {
  185.                 if (! IsWiFiSupported( m_asWiFi_Support, e_802_11_idx) )
  186.                 {
  187.                     e_802_11_idx++;
  188.                     continue;
  189.                 }
  190.                 as_cal_channel  = m_as802_11B_CAL_CHANNEL;
  191.                 max_ch_num      = NUM_TX_POWER_2400M_CH;
  192.                 d_WANTED_P      = m_dCCK_WANTED_P;
  193.                 d_max_p         = m_dCCK_MAX_P;
  194.                 d_min_p         = m_dCCK_MIN_P;
  195.                 d_Delta         = m_dCCK_Delta;
  196.                 i_C             = m_iCCK_C;
  197.                 mod             = WIFI_MOD_CCK;
  198.                 if( IQVIEW == m_pWft->device_type )
  199.                 {
  200.                     d_CL            = m_pWft->iqv.d_2_4g_cl;
  201.                     m_pWft->iqv.p_handle->rx.ampl       = m_dCCK_WANTED_P + 2;
  202.                     m_pWft->iqv.p_handle->adc.sampling_time = 0.005;
  203.                 }
  204.                 else
  205.                 {
  206.                     d_CL            = m_pWft->s_age_n4010a.d_2_4g_cl;
  207.                     d_n4010a_power_range                = m_dCCK_WANTED_P + 5;
  208.                 }
  209.                 wifi_cpt.tx_rate = m_eCCK_CAL_RATE;
  210.             }
  211.             break;
  212.             case WIFI_802_11G_IDX:
  213.             {
  214.                 if (! IsWiFiSupported( m_asWiFi_Support, e_802_11_idx) )
  215.                 {
  216.                     e_802_11_idx++;
  217.                     continue;
  218.                 }
  219.                 as_cal_channel  = m_as802_11G_CAL_CHANNEL;
  220.                 max_ch_num      = NUM_TX_POWER_2400M_CH;
  221.                 d_WANTED_P      = m_dOFDM_WANTED_P;
  222.                 d_max_p         = m_dOFDM_MAX_P;
  223.                 d_min_p         = m_dOFDM_MIN_P;
  224.                 d_Delta         = m_dOFDM_Delta;
  225.                 i_C             = m_iOFDM_C;
  226.                 mod             = WIFI_MOD_OFDM;
  227.                 if( IQVIEW == m_pWft->device_type )
  228.                 {
  229.                     d_CL            = m_pWft->iqv.d_2_4g_cl;
  230.                     m_pWft->iqv.p_handle->rx.ampl       = m_dOFDM_WANTED_P + 10;
  231.                     m_pWft->iqv.p_handle->adc.sampling_time = 0.001;
  232.                 }
  233.                 else
  234.                 {
  235.                     d_CL            = m_pWft->s_age_n4010a.d_2_4g_cl;
  236.                     d_n4010a_power_range                = m_dOFDM_WANTED_P + 5;
  237.                 }
  238.                 wifi_cpt.tx_rate = m_eOFDM_CAL_RATE;
  239.             }
  240.             break;
  241.             default:
  242.                 assert(false);
  243.             break;
  244.         } // switch
  245.         log->Add( "n" + DateToStr(Date()) +  " " + CurrentTimeStr() +
  246.                          " ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
  247.                        );
  248.         if( ! m_wft_ctrl.WFT_SetTriggerStyle( m_pWft )  )
  249.         {
  250.                PostMessage(
  251.                          ctrl.hPostMsgDestHandle,
  252.                          WM_MF_WIFI_SET_TRIGGER_STYLE_FAIL,
  253.                          0,
  254.                          0
  255.                        );
  256.                log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  257.                       " WiFi tester sets trigger style fail "
  258.                     );
  259.                return false;
  260.         }
  261.                        
  262.         if( ! m_wft_ctrl.WFT_SetPowerRange( m_pWft, d_n4010a_power_range ) )
  263.         {
  264.                     PostMessage(
  265.                                  ctrl.hPostMsgDestHandle,
  266.                                  WM_MF_WIFI_SET_POWER_RANGE_FAIL,
  267.                                  0,
  268.                                  0
  269.                                );
  270.                     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  271.                               " WiFi tester < power range = " + Double_To_AnsiString( d_n4010a_power_range ) + " dBm fail"
  272.                             );
  273.                     return false;
  274.         }
  275.         s_cal_ch_freq_mhz.ch_num = String_To_Array_UnsignedInteger(as_cal_channel.c_str(), s_cal_ch_freq_mhz.ch_freq_MHz, max_ch_num);
  276.         for (int cal_ch_idx=0; cal_ch_idx<s_cal_ch_freq_mhz.ch_num; cal_ch_idx++ )
  277.         {
  278.             log->Add( "n" + DateToStr(Date()) +  " " + CurrentTimeStr() +
  279.                           " ------------------------------------------------------------------ "
  280.                         );
  281.             unsigned int freq_khz = s_cal_ch_freq_mhz.ch_freq_MHz[cal_ch_idx]*1000;
  282.             nvram_ch_idx = GetWiFiNVRAMChannelIndex(e_802_11_idx, s_cal_ch_freq_mhz.ch_freq_MHz[cal_ch_idx]);
  283.             if ((int)NOT_FOUND == nvram_ch_idx)
  284.             {
  285.                 PostMessage(ctrl.hPostMsgDestHandle,
  286.                             WM_MF_WIFI_CHANNEL_INDEX_NOT_FOUND_FAIL,
  287.                             0,
  288.                             0
  289.                            );
  290.                 log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  291.                               " WiFi Channel index not found fail, channel = " + IntToStr(s_cal_ch_freq_mhz.ch_freq_MHz[cal_ch_idx]) + " MHz fail"
  292.                             );
  293.                 return false;
  294.             }
  295.            // m_pWft->iqv.p_handle->rx.freq = 1000*freq_khz;
  296.             if (!m_wft_ctrl.WFT_SetCentralFreq( m_pWft, (double) s_cal_ch_freq_mhz.ch_freq_MHz[cal_ch_idx]) )
  297.             {
  298.                     PostMessage(
  299.                                  ctrl.hPostMsgDestHandle,
  300.                                  WM_MF_WIFI_SET_CENTRAL_FREQ_FAIL,
  301.                                  0,
  302.                                  0
  303.                                );
  304.                     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  305.                               " WiFi tester < RX channel frequency = " + IntToStr(s_cal_ch_freq_mhz.ch_freq_MHz[cal_ch_idx]) + " MHz fail"
  306.                             );
  307.                     return false;
  308.             }
  309.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  310.                               " WiFi tester < RX channel frequency = " + IntToStr(s_cal_ch_freq_mhz.ch_freq_MHz[cal_ch_idx]) + " MHz"
  311.                             );
  312.             if( ! m_wft_ctrl.WFT_ApplyChange( m_pWft ) )
  313.             {
  314.                 PostMessage(
  315.                              ctrl.hPostMsgDestHandle,
  316.                              WM_MF_WIFI_APPLY_CHANGE_FAIL,
  317.                              0,
  318.                              0
  319.                            );
  320.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  321.                           " WiFi tester applies change value fail "
  322.                         );
  323.                 return false;
  324.             }
  325.             wifi_cpt.channel_freq = freq_khz;
  326.                 for( int iRealRecursiveTimes=0; iRealRecursiveTimes<m_iWiFiTxPRecursive_Times;
  327.                      iRealRecursiveTimes++)
  328.                 {
  329.                     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  330.                               " RecursiveTimes = " + IntToStr(iRealRecursiveTimes)
  331.                             );
  332.                     wifi_cpt.tx_pwr_dac = m_pCal->s_cal_obj.pc_WIFI_APC_Obj->Get_TxPowerDac(e_802_11_idx, mod, nvram_ch_idx);
  333.                     if (wifi_cpt.tx_pwr_dac > WIFI_MAX_APC_VALUE )
  334.                     {
  335.                         wifi_cpt.tx_pwr_dac = WIFI_MAX_APC_VALUE;
  336.                     }
  337.                     pkt_tx_ex.ch_freq           = wifi_cpt.channel_freq;
  338.                     pkt_tx_ex.tx_rate           = wifi_cpt.tx_rate;
  339.                     pkt_tx_ex.tx_gain_dac       = wifi_cpt.tx_pwr_dac;
  340.                     pkt_tx_ex.txAnt             = 0;
  341.                     pkt_tx_ex.txFlags           = 0;
  342.                     pkt_tx_ex.targetAlc         = 0;
  343.                     log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  344.                                   " Dac[" + IntToStr(nvram_ch_idx) + "] = " + IntToStr(m_pCal->s_cal_obj.pc_WIFI_APC_Obj->Get_TxPowerDac(e_802_11_idx, mod, nvram_ch_idx))
  345.                                 );
  346.                    META_RESULT MetaResult = META_WiFi_Stop_r(m_pCal->i_MainMETAHandle, 500);
  347.                    if( META_SUCCESS != MetaResult )
  348.                     {
  349.                         CalErrorHandler( WM_MF_WIFI_CPT_FAIL );
  350.                         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  351.                                    " FAIL: Target > WiFi stop fail."
  352.                                 );
  353.                          return false;
  354.                     }
  355.                     Sleep(50);
  356.                     MetaResult = META_WiFi_SetRegDomain_r( m_pCal->i_MainMETAHandle, 500, &wifi_cpt.reg_domain );
  357.                     if( META_SUCCESS != MetaResult )
  358.                     {
  359.                         CalErrorHandler( WM_MF_WIFI_CPT_FAIL );
  360.                         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  361.                                    " FAIL: Target < WiFi set reg domain fail."
  362.                                 );
  363.                          return false;
  364.                     }
  365.                     WiFi_TestPktTx_S pkt_tx;
  366.                     m_cWIFI_CPT_Obj.Compose_MacHeader(wifi_cpt.s_mac_header, pkt_tx_ex.mac_header);
  367.                     if (m_pCal->b_WiFiAlcSupport)
  368.                     {
  369.                         MetaResult = META_WiFi_ContPktTx_Ex_r(m_pCal->i_MainMETAHandle, 500, &pkt_tx_ex);
  370.                         if (META_SUCCESS != MetaResult)
  371.                         {
  372.                             CalErrorHandler(WM_MF_WIFI_CPT_FAIL);
  373.                             log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  374.                                    " FAIL: Target < WiFi continuous packet TX fail."
  375.                                 );
  376.                             return false;
  377.                         }
  378.                     }
  379.                     else
  380.                     {
  381.                         pkt_tx.ch_freq           = pkt_tx_ex.ch_freq;
  382.                         pkt_tx.tx_rate           = pkt_tx_ex.tx_rate;
  383.                         pkt_tx.tx_gain_dac       = pkt_tx_ex.tx_gain_dac;
  384.                         pkt_tx.pktCount          = pkt_tx_ex.pktCount;
  385.                         pkt_tx.pktInterval       = pkt_tx_ex.pktInterval;
  386.                         pkt_tx.pktLength         = pkt_tx_ex.pktLength;
  387.                         pkt_tx.pattern           = pkt_tx_ex.pattern;
  388.                         pkt_tx.txAnt             = pkt_tx_ex.txAnt;
  389.                         pkt_tx.is_short_preamble = pkt_tx_ex.is_short_preamble;
  390.                         for (int i=0; i<24; i++)
  391.                         {
  392.                             pkt_tx.mac_header[i] = pkt_tx_ex.mac_header[i];
  393.                         }
  394.                         MetaResult = META_WiFi_ContPktTx_r(m_pCal->i_MainMETAHandle, 500, &pkt_tx);
  395.                     }
  396.                     if( META_SUCCESS != MetaResult )
  397.                     {
  398.                         CalErrorHandler( WM_MF_WIFI_CPT_FAIL );
  399.                         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  400.                                    " FAIL: Target > WiFi continuous packet TX fail."
  401.                                 );
  402.                          return false;
  403.                     }
  404.                     Sleep(100);
  405.                     if (!m_wft_ctrl.WFT_DataCapture(m_pWft))
  406.                     {
  407.                         PostMessage(
  408.                               ctrl.hPostMsgDestHandle,
  409.                               WM_MF_WIFI_APPLY_CHANGE_FAIL,
  410.                               0,
  411.                               0
  412.                             );
  413.                         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  414.                                   " WiFi tester applies change value fail "
  415.                                 );
  416.                         return false;
  417.                     }
  418.                     if (!m_wft_ctrl.WFT_PowerAnalyze(m_pWft))
  419.                     {
  420.                         PostMessage(
  421.                                      ctrl.hPostMsgDestHandle,
  422.                                      WM_MF_WIFI_ANALYZE_POWER_FAIL,
  423.                                      0,
  424.                                      0
  425.                                    );
  426.                         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  427.                                   " WiFi tester analyzes TX power fail "
  428.                                 );
  429.                         return false;
  430.                     }
  431.                     if (!m_wft_ctrl.WFT_ReadPower(m_pWft, virTX))
  432.                     {
  433.                         PostMessage(
  434.                                      ctrl.hPostMsgDestHandle,
  435.                                      WM_MF_WIFI_READ_POWER_FAIL,
  436.                                      0,
  437.                                      0
  438.                                    );
  439.                         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  440.                                   " WiFi tester reads TX power fail "
  441.                                 );
  442.                         return false;
  443.                     }
  444.                     virTX = virTX - d_CL;
  445.                     log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  446.                               " WiFi tester > read TX power = "+ Double_To_AnsiString(virTX)
  447.                             );
  448.                     signed short  ss1;
  449.                     double d1;
  450.                     unsigned char new_dac;
  451.                     if (iRealRecursiveTimes != m_iWiFiTxPRecursive_Times-1) //iteration
  452.                     {
  453.                         if ( virTX > (d_WANTED_P + d_Delta) ||
  454.                              virTX < (d_WANTED_P - d_Delta)
  455.                            )
  456.                         {
  457.                             d1 = i_C * ( d_WANTED_P - virTX );
  458.                             ss1 = (signed short) (d1>0) ? floor(d1+1.0): ceil(d1-1.0);
  459.                             new_dac = m_pCal->s_cal_obj.pc_WIFI_APC_Obj->Get_TxPowerDac(e_802_11_idx, mod, nvram_ch_idx)+ ss1;
  460.                             if(new_dac > WIFI_MAX_APC_VALUE)
  461.                             {
  462.                                 m_pCal->s_cal_obj.pc_WIFI_APC_Obj->Set_TxPowerDac(e_802_11_idx, mod, nvram_ch_idx, WIFI_MAX_APC_VALUE);
  463.                             }
  464.                             else
  465.                             {
  466.                                 m_pCal->s_cal_obj.pc_WIFI_APC_Obj->Set_TxPowerDac(e_802_11_idx, mod, nvram_ch_idx, new_dac);
  467.                             }
  468.                             log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  469.                                   " delta s = "+
  470.                                   AnsiString(ss1)
  471.                                 );
  472.                         }
  473.                         else
  474.                         {
  475.                            // log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  476.                            //       " delta s = 0 "
  477.                            //     );
  478.                             break; // for iRealRecursiveTimes
  479.                         }
  480.                     } // if no iteration
  481.                     else if( iRealRecursiveTimes == m_iWiFiTxPRecursive_Times-1 )
  482.                     {
  483.                         if ( virTX > d_max_p || virTX < d_min_p )
  484.                         {
  485.                             CalErrorHandler( WM_MF_WIFI_TX_POWER_CHECK_FAIL );
  486.                             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  487.                                       " WiFi test < read TX power = "+ Double_To_AnsiString( virTX ) +
  488.                                       " ( Out of Range ), min TX power = " + Double_To_AnsiString( d_min_p ) + ", max TX power = " + Double_To_AnsiString( d_max_p )
  489.                                     );
  490.                             return false;
  491.                         }
  492.                         else
  493.                         {
  494.                             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  495.                                       " Agilent 8960> read TX power = "+ Double_To_AnsiString( virTX ) +
  496.                                       " ( Pass ), min TX power = " + Double_To_AnsiString( d_min_p ) + ", max TX power = " + Double_To_AnsiString( d_max_p )
  497.                                     );
  498.                         }
  499.                     }
  500.                     if ( this->Terminated )
  501.                     {
  502.                         this->OnTerminate = neByUser;
  503.                         return false;
  504.                     }
  505.                 } // for (iRealRecursiveTimes)
  506.                 sprintf(tempbuf, "%2.1f", virTX);
  507.                 m_pCal->as_ResultBuf = m_pCal->as_ResultBuf + tempbuf + ", ";
  508.                 // get ALC value
  509.                 if (m_pCal->b_WiFiAlcSupport)
  510.                 {
  511.                     MetaResult = META_WiFi_QueryTxStatus_Ex_r(m_pCal->i_MainMETAHandle, 5000, &pkt_tx_ex_status);
  512.                     if (META_SUCCESS != MetaResult)
  513.                     {
  514.                         CalErrorHandler(WM_MF_WIFI_CPT_FAIL);
  515.                         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  516.                                    " FAIL: Target > Query WiFi ALC fail."
  517.                                 );
  518.                          return false;
  519.                     }
  520.                     if (WIFI_MOD_CCK == mod)
  521.                     {
  522.                         m_pCal->s_cal_obj.pc_WIFI_ALC_Obj->Set_AlcPower2400MAlc(mod, nvram_ch_idx, (WiFi_TestRate_E) 0, pkt_tx_ex_status.avgAlc);
  523.                     }
  524.                     else
  525.                     {
  526.                         for (int rate = 0; rate < WIFI_ALC_2400M_TX_RATE_NUM; rate++)
  527.                         {
  528.                             m_pCal->s_cal_obj.pc_WIFI_ALC_Obj->Set_AlcPower2400MAlc(mod, nvram_ch_idx, (WiFi_TestRate_E) rate, pkt_tx_ex_status.avgAlc);
  529.                         }
  530.                     }
  531.                 }
  532.         } // for (ch_idx)
  533.         // interpolate not calibrated channel
  534.         S_WIFI_CH_FREQ_MHZ s_remain_ch_freq_mhz;
  535.         int remain_ch_num = GetWiFiRemainChannels(e_802_11_idx, s_cal_ch_freq_mhz, s_remain_ch_freq_mhz);
  536.         if (remain_ch_num > 0)
  537.         {
  538.             log->Add( "n" +DateToStr(Date()) +  " " + CurrentTimeStr() +
  539.                   " --------------------- Evaluate WiFi TX power DAC value begin --------------------- "
  540.                 );
  541.             for (int i=0; i<remain_ch_num; i++)
  542.             {
  543.                 int first_ch_index;
  544.                 int second_ch_index;
  545.                 double d_slope;
  546.                 double d_offset;
  547.                 nvram_ch_idx = GetWiFiNVRAMChannelIndex(e_802_11_idx, s_remain_ch_freq_mhz.ch_freq_MHz[i]);
  548.                 if ((int)NOT_FOUND == nvram_ch_idx)
  549.                 {
  550.                     PostMessage(ctrl.hPostMsgDestHandle,
  551.                                 WM_MF_WIFI_CHANNEL_INDEX_NOT_FOUND_FAIL,
  552.                                 0,
  553.                                 0
  554.                                );
  555.                     log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  556.                               " WiFi Channel index not found fail, channel = " + IntToStr(s_remain_ch_freq_mhz.ch_freq_MHz[i]) + " MHz fail"
  557.                             );
  558.                     return false;
  559.                 }
  560.                 if (!GetWiFiTwoClosetNVRAMChannelIndex(e_802_11_idx, s_remain_ch_freq_mhz.ch_freq_MHz[i], s_cal_ch_freq_mhz, first_ch_index, second_ch_index))
  561.                 {
  562.                     PostMessage(ctrl.hPostMsgDestHandle,
  563.                                 WM_MF_WIFI_CHANNEL_INDEX_NOT_FOUND_FAIL,
  564.                                 0,
  565.                                 0
  566.                                );
  567.                     log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  568.                               " Two closest WiFi Channel index not found fail, channel = " + IntToStr(s_remain_ch_freq_mhz.ch_freq_MHz[i]) + " MHz fail"
  569.                             );
  570.                     return false;
  571.                 }
  572.                 unsigned char uc_first_dac  = m_pCal->s_cal_obj.pc_WIFI_APC_Obj->Get_TxPowerDac(e_802_11_idx, mod, first_ch_index);
  573.                 unsigned char uc_second_dac = m_pCal->s_cal_obj.pc_WIFI_APC_Obj->Get_TxPowerDac(e_802_11_idx, mod, second_ch_index);
  574.                 double d_data;
  575.                 unsigned char uc_target_dac;
  576.                 d_slope = (double) (uc_first_dac - uc_second_dac)/(double)(first_ch_index - second_ch_index);
  577.                 d_offset = (double) uc_first_dac - (d_slope * first_ch_index);
  578.                 d_data = d_slope * nvram_ch_idx + d_offset;
  579.                 d_data += (d_data>=0) ? 0.5 : -0.5 ;
  580.                 uc_target_dac = (unsigned char) d_data;
  581.                 m_pCal->s_cal_obj.pc_WIFI_APC_Obj->Set_TxPowerDac(e_802_11_idx, mod, nvram_ch_idx, uc_target_dac);
  582.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  583.                               " slope = " + Double_To_AnsiString(d_slope) +
  584.                               ", offset = " + Double_To_AnsiString(d_offset)
  585.                             );
  586.                 log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  587.                          " channel index = " + IntToStr(nvram_ch_idx) +
  588.                          ", WiFi TX power DAC = " + IntToStr(uc_target_dac)
  589.                         );
  590.                 // evaluate remain channel ALC vaue
  591.                 if (m_pCal->b_WiFiAlcSupport)
  592.                 {
  593.                     unsigned char uc_first_alc = m_pCal->s_cal_obj.pc_WIFI_ALC_Obj->Get_AlcPower2400MAlc(mod, first_ch_index, (WiFi_TestRate_E) 0);
  594.                     unsigned char uc_second_alc = m_pCal->s_cal_obj.pc_WIFI_ALC_Obj->Get_AlcPower2400MAlc(mod, second_ch_index, (WiFi_TestRate_E) 0);
  595.                     double d_data;
  596.                     unsigned char uc_target_alc;
  597.                     d_slope = (double) (uc_first_alc - uc_second_alc)/(double)(first_ch_index - second_ch_index);
  598.                     d_offset = (double) uc_first_alc - (d_slope * first_ch_index);
  599.                     d_data = d_slope * nvram_ch_idx + d_offset;
  600.                     d_data += (d_data>=0) ? 0.5 : -0.5 ;
  601.                     uc_target_alc = (unsigned char) d_data;
  602.                     if (WIFI_MOD_CCK == mod)
  603.                     {
  604.                         m_pCal->s_cal_obj.pc_WIFI_ALC_Obj->Set_AlcPower2400MAlc(mod, nvram_ch_idx, (WiFi_TestRate_E) 0, uc_target_alc);
  605.                     }
  606.                     else
  607.                     {
  608.                         for (int rate = 0; rate < WIFI_ALC_2400M_TX_RATE_NUM; rate++)
  609.                         {
  610.                             m_pCal->s_cal_obj.pc_WIFI_ALC_Obj->Set_AlcPower2400MAlc(mod, nvram_ch_idx, (WiFi_TestRate_E) rate, uc_target_alc);
  611.                         }
  612.                     }
  613.                     log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  614.                               " slope = " + Double_To_AnsiString(d_slope) +
  615.                               ", offset = " + Double_To_AnsiString(d_offset)
  616.                             );
  617.                     log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  618.                              " channel index = " + IntToStr(nvram_ch_idx) +
  619.                              ", WiFi ALC = " + IntToStr(uc_target_alc)
  620.                         );
  621.                 }
  622.             } // for(i)
  623.             log->Add("n" +DateToStr(Date()) +  " " + CurrentTimeStr() +
  624.                   " -------------------- Evaluate WiFi TX power DAC value end ------------------ "
  625.                 );
  626.         }
  627.         // write to NVRAM
  628.         m_pCal->s_cal_obj.pc_WIFI_APC_Obj->ConfirmCallback = ::CNF_MF_WriteToNVRAM;
  629.         if( WIFI_802_11A_IDX == e_802_11_idx )
  630.         {
  631.             m_pCal->s_cal_obj.pc_WIFI_APC_Obj->REQ_Write_TxPower5000M_To_NVRAM_Start();
  632.         }
  633.         else
  634.         {
  635.             m_pCal->s_cal_obj.pc_WIFI_APC_Obj->REQ_Write_TxPower2400M_To_NVRAM_Start();
  636.         }
  637.         RestartTimerCal( WM_MF_NVRAM_WIFI_APC_WRITE_FAIL );
  638.         SUSPEND_CAL_THREAD
  639.         CHECK_TERMINATE_BY_USER
  640.         E_METAAPP_RESULT_T state = m_pCal->s_cal_obj.pc_WIFI_APC_Obj->Get_ConfirmState();
  641.         if (state != METAAPP_SUCCESS)
  642.         {
  643.             if (METAAPP_NVRAM_LID_VER_NOT_SUPPORT == state)
  644.             {
  645.                 CalErrorHandler(WM_MF_NVRAM_EF_WNDRV_TX_POWER_xxx_LID_VERNO_FAIL);
  646.                 log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  647.                                " FAIL : NVRAM_EF_WNDRV_TX_POWER_xxx_LID version is not support, please update META to latest version. "
  648.                                );
  649.             }
  650.             else
  651.             {
  652.                 CalErrorHandler(WM_MF_NVRAM_WIFI_APC_WRITE_FAIL);
  653.                 log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  654.                       " FAIL: Target < write WiFi 2.4G TX power to NVRAM fail."
  655.                     );
  656.             }
  657.             return false;
  658.         }
  659.         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  660.                       " Target < write WiFi 2.4G TX power to NVRAM."
  661.                     );
  662.         if ( this->Terminated )
  663.         {
  664.             this->OnTerminate = neByUser;
  665.             return false;
  666.         }
  667.         WriteWiFiAPCCalResultToFile(as_ID+".cal",Application->ExeName, m_pCal->b_CalResultPath, e_802_11_idx );
  668.         e_802_11_idx++;
  669.     } // while
  670.     if (m_pCal->b_WiFiAlcSupport)
  671.     {
  672.         // CCK
  673.         for (int ch_idx=0; ch_idx<max_ch_num; ch_idx++)
  674.         {
  675.             m_pCal->s_cal_obj.pc_WIFI_ALC_Obj->Set_AlcPower2400MPowerDB(WIFI_MOD_CCK, ch_idx, (WiFi_TestRate_E) 0, m_dCCK_WANTED_P);
  676.         }
  677.         // OFDM
  678.         for (int rate = 0; rate < WIFI_ALC_2400M_TX_RATE_NUM; rate++)
  679.         {
  680.             for (int ch_idx = 0; ch_idx < max_ch_num; ch_idx++)
  681.             {
  682.                 m_pCal->s_cal_obj.pc_WIFI_ALC_Obj->Set_AlcPower2400MPowerDB(WIFI_MOD_OFDM, ch_idx, (WiFi_TestRate_E) rate, m_dOFDM_WANTED_P);
  683.             }
  684.         }
  685.         // write to NVRAM
  686.         m_pCal->s_cal_obj.pc_WIFI_ALC_Obj->ConfirmCallback = ::CNF_MF_WriteToNVRAM;
  687.         m_pCal->s_cal_obj.pc_WIFI_ALC_Obj->REQ_Write_To_NVRAM_Start();
  688.         RestartTimerCal(WM_MF_NVRAM_WIFI_ALC_WRITE_FAIL);
  689.         SUSPEND_CAL_THREAD
  690.         CHECK_TERMINATE_BY_USER
  691.         E_METAAPP_RESULT_T state = m_pCal->s_cal_obj.pc_WIFI_ALC_Obj->Get_ConfirmState();
  692.         if (state != METAAPP_SUCCESS)
  693.         {
  694.             if (METAAPP_NVRAM_LID_VER_NOT_SUPPORT == state)
  695.             {
  696.                 CalErrorHandler(WM_MF_NVRAM_EF_WNDRV_TX_ALC_POWER_LID_VERNO_FAIL);
  697.                 log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  698.                                " FAIL : NVRAM_EF_WNDRV_TX_ALC_POWER_LID version is not support, please update META to latest version. "
  699.                                );
  700.             }
  701.             else
  702.             {
  703.                 CalErrorHandler(WM_MF_NVRAM_WIFI_ALC_WRITE_FAIL);
  704.                 log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  705.                       " FAIL: Target < write WiFi 2.4G ALC to NVRAM fail."
  706.                     );
  707.             }
  708.             return false;
  709.         }
  710.         log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  711.                       " Target < write WiFi 2.4G TX power to NVRAM."
  712.                     );
  713.     }
  714.     frmFatcory->DisableAllCalTimer();
  715.     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  716.              " ====================== WiFi TX power calibration end ===================== "
  717.            );
  718.     return true;
  719. }
  720. //----------------------------------------------------------------------------
  721. bool __fastcall T_META_factory_calibration::WiFiTxPclCal_check( void )
  722. {
  723.     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  724.              " ====================== WiFi TX power check begin ===================== "
  725.            );
  726.     if( IQVIEW == m_pWft->device_type )
  727.     {
  728.         m_pWft->iqv.p_handle->tx.rf_enabled = IQV_RF_DISABLED;
  729.         m_pWft->iqv.p_handle->rx.rf_enabled = IQV_RF_ENABLED;
  730.         m_pWft->iqv.p_handle->rx.rf_port    = IQV_PORT_LEFT;
  731.         m_pWft->iqv.p_handle->rx.vsa_type   = 1;
  732.     }
  733.     WiFi_TestPktTx_Ex_S  pkt_tx_ex;
  734.     S_WIFICPT  wifi_cpt;
  735.     double   virTX;
  736.     wifi_cpt.wifi_id = m_pCal->s_wifi_cap.rf_chip_id;
  737.     wifi_cpt.reg_domain.country_code[0] = 'U';
  738.     wifi_cpt.reg_domain.country_code[1] = 'S';;
  739. //    wifi_cpt.tx_rate = WIFI_TEST_RATE_5_5M;
  740.     wifi_cpt.pkt_length = 1024;
  741.     wifi_cpt.pkt_count = 0;
  742.     wifi_cpt.pkt_interval = 100;
  743.     wifi_cpt.pattern = WIFI_TX_PSEUDO_RANDOM;
  744.     wifi_cpt.is_short_preamble = 0;
  745.     wifi_cpt.s_mac_header.frame_ctrl[0] = 0x02;
  746.     wifi_cpt.s_mac_header.frame_ctrl[1] = 0x08;
  747.     wifi_cpt.s_mac_header.duration[0]   = 0x00;
  748.     wifi_cpt.s_mac_header.duration[1]   = 0x00;
  749.     wifi_cpt.s_mac_header.address1[0]   = 0xFF;
  750.     wifi_cpt.s_mac_header.address1[1]   = 0xFF;
  751.     wifi_cpt.s_mac_header.address1[2]   = 0xFF;
  752.     wifi_cpt.s_mac_header.address1[3]   = 0xFF;
  753.     wifi_cpt.s_mac_header.address1[4]   = 0xFF;
  754.     wifi_cpt.s_mac_header.address1[5]   = 0xFF;
  755.     wifi_cpt.s_mac_header.address2[0]   = 0x01;
  756.     wifi_cpt.s_mac_header.address2[1]   = 0x00;
  757.     wifi_cpt.s_mac_header.address2[2]   = 0x00;
  758.     wifi_cpt.s_mac_header.address2[3]   = 0x22;
  759.     wifi_cpt.s_mac_header.address2[4]   = 0x08;
  760.     wifi_cpt.s_mac_header.address2[5]   = 0x00;
  761.     wifi_cpt.s_mac_header.address3[0]   = 0xFF;
  762.     wifi_cpt.s_mac_header.address3[1]   = 0xFF;
  763.     wifi_cpt.s_mac_header.address3[2]   = 0xFF;
  764.     wifi_cpt.s_mac_header.address3[3]   = 0xFF;
  765.     wifi_cpt.s_mac_header.address3[4]   = 0xFF;
  766.     wifi_cpt.s_mac_header.address3[5]   = 0xFF;
  767.     wifi_cpt.s_mac_header.seq_ctrl[0]   = 0x00;
  768.     wifi_cpt.s_mac_header.seq_ctrl[1]   = 0x00;
  769.     pkt_tx_ex.pktCount          = wifi_cpt.pkt_count;
  770.     pkt_tx_ex.pktInterval       = wifi_cpt.pkt_interval;
  771.     pkt_tx_ex.pktLength         = wifi_cpt.pkt_length;
  772.     pkt_tx_ex.pattern           = wifi_cpt.pattern;
  773.     pkt_tx_ex.is_short_preamble = wifi_cpt.is_short_preamble;
  774.     int max_ch_num;
  775.     int tx_power_ch_num;
  776.     AnsiString as_check_channel;
  777.     int nvram_ch_idx;
  778.     S_WIFI_CH_FREQ_MHZ s_check_ch_freq_mhz;
  779.     double d_max_p;
  780.     double d_min_p;
  781.     double d_CL;
  782.     double d_n4010a_power_range;
  783.     E_WIFI_MOD mod;
  784.     bool out_of_range_flag = false; // set initial value
  785.     E_WIFI_GENERATION e_802_11_idx = WIFI_802_11A_IDX;
  786.     while (e_802_11_idx <= WIFI_802_11G_IDX)
  787.     {
  788.         switch( e_802_11_idx )
  789.         {
  790.             case WIFI_802_11A_IDX:
  791.             {
  792.                 if (! IsWiFiSupported( m_asWiFi_Support, e_802_11_idx) )
  793.                 {
  794.                     e_802_11_idx++;
  795.                     continue;
  796.                 }
  797.                 as_check_channel  = m_as802_11G_CHECK_CHANNEL;
  798.                 max_ch_num      = NUM_TX_POWER_5000M_CH;
  799.                 d_max_p         = m_dOFDM_MAX_P;
  800.                 d_min_p         = m_dOFDM_MIN_P;
  801.                 mod             = WIFI_MOD_OFDM;
  802.                 if (IQVIEW == m_pWft->device_type)
  803.                 {
  804.                     d_CL            = m_pWft->iqv.d_5g_cl;
  805.                     m_pWft->iqv.p_handle->rx.ampl       = m_dOFDM_WANTED_P + 10;
  806.                     m_pWft->iqv.p_handle->adc.sampling_time = 0.001;
  807.                 }
  808.                 else
  809.                 {
  810.                     d_CL            = m_pWft->s_age_n4010a.d_5g_cl;
  811.                     d_n4010a_power_range                = m_dOFDM_WANTED_P + 5;
  812.                 }
  813.                 wifi_cpt.tx_rate = m_eOFDM_CHECK_RATE;
  814.             }
  815.             break;
  816.             case WIFI_802_11B_IDX:
  817.             {
  818.                 if (!IsWiFiSupported(m_asWiFi_Support, e_802_11_idx))
  819.                 {
  820.                     e_802_11_idx++;
  821.                     continue;
  822.                 }
  823.                 as_check_channel  = m_as802_11B_CHECK_CHANNEL;
  824.                 max_ch_num      = NUM_TX_POWER_2400M_CH;
  825.                 d_max_p         = m_dCCK_MAX_P;
  826.                 d_min_p         = m_dCCK_MIN_P;
  827.                 mod             = WIFI_MOD_CCK;
  828.                 if (IQVIEW == m_pWft->device_type)
  829.                 {
  830.                     d_CL                          = m_pWft->iqv.d_2_4g_cl;
  831.                     m_pWft->iqv.p_handle->rx.ampl = m_dCCK_WANTED_P + 2;
  832.                     m_pWft->iqv.p_handle->adc.sampling_time = 0.005;
  833.                 }
  834.                 else
  835.                 {
  836.                     d_CL                          = m_pWft->s_age_n4010a.d_2_4g_cl;
  837.                     d_n4010a_power_range          = m_dCCK_WANTED_P + 5;
  838.                 }
  839.                 wifi_cpt.tx_rate = m_eCCK_CHECK_RATE;
  840.             }
  841.             break;
  842.             case WIFI_802_11G_IDX:
  843.             {
  844.                 if (!IsWiFiSupported(m_asWiFi_Support, e_802_11_idx))
  845.                 {
  846.                     e_802_11_idx++;
  847.                     continue;
  848.                 }
  849.                 as_check_channel = m_as802_11G_CHECK_CHANNEL;
  850.                 max_ch_num       = NUM_TX_POWER_2400M_CH;
  851.                 d_max_p          = m_dOFDM_MAX_P;
  852.                 d_min_p          = m_dOFDM_MIN_P;
  853.                 mod              = WIFI_MOD_OFDM;
  854.                 if (IQVIEW == m_pWft->device_type)
  855.                 {
  856.                     d_CL                          = m_pWft->iqv.d_2_4g_cl;
  857.                     m_pWft->iqv.p_handle->rx.ampl = m_dOFDM_WANTED_P + 10;
  858.                     m_pWft->iqv.p_handle->adc.sampling_time = 0.001;
  859.                 }
  860.                 else
  861.                 {
  862.                     d_CL                          = m_pWft->s_age_n4010a.d_2_4g_cl;
  863.                     d_n4010a_power_range          = m_dOFDM_WANTED_P + 5;
  864.                 }
  865.                 wifi_cpt.tx_rate = m_eOFDM_CHECK_RATE;
  866.             }
  867.             break;
  868.             default:
  869.                 assert(false);
  870.             break;
  871.         } // switch
  872.         log->Add( "n" + DateToStr(Date()) +  " " + CurrentTimeStr() +
  873.                          " ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
  874.                        );
  875.         if( ! m_wft_ctrl.WFT_SetTriggerStyle( m_pWft )  )
  876.         {
  877.                PostMessage(
  878.                          ctrl.hPostMsgDestHandle,
  879.                          WM_MF_WIFI_SET_TRIGGER_STYLE_FAIL,
  880.                          0,
  881.                          0
  882.                        );
  883.                log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  884.                       " WiFi tester sets trigger style fail "
  885.                     );
  886.                return false;
  887.         }
  888.         if (!m_wft_ctrl.WFT_SetPowerRange(m_pWft, d_n4010a_power_range))
  889.         {
  890.             PostMessage(ctrl.hPostMsgDestHandle,
  891.                         WM_MF_WIFI_SET_POWER_RANGE_FAIL,
  892.                         0,
  893.                         0
  894.                         );
  895.             log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  896.                               " WiFi tester < power range = " + Double_To_AnsiString(d_n4010a_power_range) + " dBm fail"
  897.                             );
  898.             return false;
  899.         }
  900.         s_check_ch_freq_mhz.ch_num = String_To_Array_UnsignedInteger(as_check_channel.c_str(), s_check_ch_freq_mhz.ch_freq_MHz, max_ch_num);
  901.         for (int check_ch_idx=0; check_ch_idx<s_check_ch_freq_mhz.ch_num; check_ch_idx++)
  902.         {
  903.             unsigned int freq_khz = s_check_ch_freq_mhz.ch_freq_MHz[check_ch_idx] * 1000;
  904.            // m_pWft->iqv.p_handle->rx.freq = 1000*freq_khz;
  905.             if (!m_wft_ctrl.WFT_SetCentralFreq(m_pWft, (double) s_check_ch_freq_mhz.ch_freq_MHz[check_ch_idx]))
  906.             {
  907.                     PostMessage(
  908.                                  ctrl.hPostMsgDestHandle,
  909.                                  WM_MF_WIFI_SET_CENTRAL_FREQ_FAIL,
  910.                                  0,
  911.                                  0
  912.                                );
  913.                     log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  914.                               " WiFi tester < RX channel frequency = " + Double_To_AnsiString(s_check_ch_freq_mhz.ch_freq_MHz[check_ch_idx]) + " MHz fail"
  915.                             );
  916.                     return false;
  917.             }
  918.             log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  919.                               " WiFi tester < RX channel frequency = " + Double_To_AnsiString(s_check_ch_freq_mhz.ch_freq_MHz[check_ch_idx]) + " MHz"
  920.                             );
  921.             if (!m_wft_ctrl.WFT_ApplyChange(m_pWft))
  922.             {
  923.                 PostMessage(
  924.                              ctrl.hPostMsgDestHandle,
  925.                              WM_MF_WIFI_APPLY_CHANGE_FAIL,
  926.                              0,
  927.                              0
  928.                            );
  929.                 log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  930.                           " WiFi tester applies change value fail "
  931.                         );
  932.                 return false;
  933.             }
  934.             wifi_cpt.channel_freq = freq_khz;
  935.             nvram_ch_idx = GetWiFiNVRAMChannelIndex(e_802_11_idx, s_check_ch_freq_mhz.ch_freq_MHz[check_ch_idx]);
  936.             wifi_cpt.tx_pwr_dac   = m_pCal->s_cal_obj.pc_WIFI_APC_Obj->Get_TxPowerDac(e_802_11_idx, mod, nvram_ch_idx);
  937.             pkt_tx_ex.ch_freq     = wifi_cpt.channel_freq;
  938.             pkt_tx_ex.tx_rate     = wifi_cpt.tx_rate;
  939.             pkt_tx_ex.tx_gain_dac = wifi_cpt.tx_pwr_dac;
  940.             pkt_tx_ex.txAnt       = 0;
  941.             pkt_tx_ex.txFlags     = 0;
  942.             pkt_tx_ex.targetAlc   = 0;
  943.             log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  944.                                   " Dac[" + IntToStr(nvram_ch_idx) + "] = " + IntToStr(wifi_cpt.tx_pwr_dac)
  945.                                 );
  946.             // stop continuous packet TX
  947.             META_RESULT MetaResult = META_WiFi_Stop_r(m_pCal->i_MainMETAHandle, 500);
  948.             if (META_SUCCESS != MetaResult)
  949.             {
  950.                 CalErrorHandler(WM_MF_WIFI_CPT_FAIL);
  951.                 log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  952.                          " FAIL: Target > WiFi stop fail."
  953.                          );
  954.                 return false;
  955.             }
  956.             Sleep(50);
  957.             // start continuos packet TX
  958.             MetaResult = META_WiFi_SetRegDomain_r(m_pCal->i_MainMETAHandle, 500, &wifi_cpt.reg_domain );
  959.             if (META_SUCCESS != MetaResult)
  960.             {
  961.                 CalErrorHandler(WM_MF_WIFI_CPT_FAIL);
  962.                 log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  963.                          " FAIL: Target > WiFi set reg domain fail."
  964.                          );
  965.                 return false;
  966.             }
  967.             WiFi_TestPktTx_S pkt_tx;
  968.             m_cWIFI_CPT_Obj.Compose_MacHeader(wifi_cpt.s_mac_header, pkt_tx_ex.mac_header);
  969.             if (m_pCal->b_WiFiAlcSupport)
  970.             {
  971.                 MetaResult = META_WiFi_ContPktTx_Ex_r(m_pCal->i_MainMETAHandle, 500, &pkt_tx_ex);
  972.             }
  973.             else
  974.             {
  975.                 pkt_tx.ch_freq           = pkt_tx_ex.ch_freq;
  976.                 pkt_tx.tx_rate           = pkt_tx_ex.tx_rate;
  977.                 pkt_tx.tx_gain_dac       = pkt_tx_ex.tx_gain_dac;
  978.                 pkt_tx.pktCount          = pkt_tx_ex.pktCount;
  979.                 pkt_tx.pktInterval       = pkt_tx_ex.pktInterval;
  980.                 pkt_tx.pktLength         = pkt_tx_ex.pktLength;
  981.                 pkt_tx.pattern           = pkt_tx_ex.pattern;
  982.                 pkt_tx.txAnt             = pkt_tx_ex.txAnt;
  983.                 pkt_tx.is_short_preamble = pkt_tx_ex.is_short_preamble;
  984.                 for (int i=0; i<24; i++)
  985.                 {
  986.                     pkt_tx.mac_header[i] = pkt_tx_ex.mac_header[i];
  987.                 }
  988.                 MetaResult = META_WiFi_ContPktTx_r(m_pCal->i_MainMETAHandle, 500, &pkt_tx);
  989.             }
  990.             if (META_SUCCESS != MetaResult)
  991.             {
  992.                 CalErrorHandler(WM_MF_WIFI_CPT_FAIL);
  993.                 log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  994.                                    " FAIL: Target > WiFi continuous packet TX fail."
  995.                         );
  996.                 return false;
  997.             }
  998.             Sleep(100);
  999.             if (! m_wft_ctrl.WFT_DataCapture(m_pWft))
  1000.             {
  1001.                 PostMessage(
  1002.                               ctrl.hPostMsgDestHandle,
  1003.                               WM_MF_WIFI_APPLY_CHANGE_FAIL,
  1004.                               0,
  1005.                               0
  1006.                             );
  1007.                 log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  1008.                           " WiFi tester applies change value fail "
  1009.                         );
  1010.                 return false;
  1011.             }
  1012.             if (!m_wft_ctrl.WFT_PowerAnalyze(m_pWft))
  1013.             {
  1014.                 PostMessage(
  1015.                              ctrl.hPostMsgDestHandle,
  1016.                              WM_MF_WIFI_ANALYZE_POWER_FAIL,
  1017.                              0,
  1018.                              0
  1019.                            );
  1020.                 log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  1021.                           " WiFi tester analyzes TX power fail "
  1022.                         );
  1023.                 return false;
  1024.             }
  1025.             if (!m_wft_ctrl.WFT_ReadPower(m_pWft, virTX))
  1026.             {
  1027.                 PostMessage(
  1028.                              ctrl.hPostMsgDestHandle,
  1029.                              WM_MF_WIFI_READ_POWER_FAIL,
  1030.                              0,
  1031.                              0
  1032.                            );
  1033.                 log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  1034.                           " WiFi tester reads TX power fail "
  1035.                         );
  1036.                 return false;
  1037.             }
  1038.             virTX = virTX - d_CL;
  1039.             if (virTX > d_max_p || virTX < d_min_p)
  1040.             {
  1041.                 log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  1042.                           " WiFi tester > read TX power = "+ Double_To_AnsiString( virTX ) +
  1043.                           " ( Out of Range ), min TX power = " + Double_To_AnsiString( d_min_p ) + ", max TX power = " + Double_To_AnsiString( d_max_p )
  1044.                         );
  1045.                 out_of_range_flag = true;
  1046.             }
  1047.             else
  1048.             {
  1049.                 log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  1050.                           " WiFi tester > read TX power = "+ Double_To_AnsiString( virTX ) +
  1051.                           " ( Pass ), min TX power = " + Double_To_AnsiString( d_min_p ) + ", max TX power = " + Double_To_AnsiString( d_max_p )
  1052.                           );
  1053.             }
  1054.         } // for(ch_idx)
  1055.         e_802_11_idx++;
  1056.     } // while
  1057.     META_RESULT MetaResult = META_WiFi_Stop_r( m_pCal->i_MainMETAHandle, 500 );
  1058.     if (META_SUCCESS != MetaResult)
  1059.     {
  1060.         CalErrorHandler(WM_MF_WIFI_CPT_FAIL);
  1061.         log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  1062.                                    " FAIL: Target > WiFi stop fail."
  1063.                                 );
  1064.         return false;
  1065.     }
  1066.     if (out_of_range_flag)
  1067.     {
  1068.         CalErrorHandler(WM_MF_RF_TX_LEVEL_CHECK_FAIL );
  1069.         log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  1070.                     " FAIL : WiFi TX power check " + "n"
  1071.               );
  1072.         return false;
  1073.    }
  1074.     if (m_pCal->b_WiFiAlcSupport)
  1075.     {
  1076.         WriteWiFiALCCalResultToFile(as_ID+".cal",Application->ExeName, m_pCal->b_CalResultPath);
  1077.     }
  1078.    frmFatcory->DisableAllCalTimer();
  1079.    PostMessage(ctrl.hPostMsgDestHandle,
  1080.                WM_MF_WIFI_TX_POWER_CALIBRATION_DONE,
  1081.                0,
  1082.                0
  1083.               );
  1084.     log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  1085.              " ====================== WiFi TX power check end ===================== "
  1086.            );
  1087.     return true;
  1088. }