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

MTK

开发平台:

C++ Builder

  1.     // if( is_calibration_start == false )
  2.     //  {
  3.     //      return;
  4.     //  }
  5.     is_calibration_start = false;
  6.     //////////////////////// RF calibration //////////////////////////////////////
  7.     if( cbIP2->Checked        ||
  8.         cbAFC->Checked        ||
  9.         cbRxPathLoss->Checked ||
  10.         cbTxIq->Checked       ||
  11.         cbTxPcl->Checked      ||
  12.         m_cbTrxOffset->Checked
  13.       )
  14.     {
  15.         RCT_Dcl_Reset_Close();
  16.     }
  17.     //////////////////////// BT CAP ID calibration /////////////////////////////////////////
  18.     if (m_cbBTCapID->Checked)
  19.     {
  20.         if (!m_btt_ctrl.BTT_Close(&m_sBtt))
  21.         {
  22.             PostMessage(
  23.                           this->Handle,
  24.                           WM_MF_BTT_CLOSE_FAIL,
  25.                           0,
  26.                           0
  27.                         );
  28.         }
  29.     }
  30.     ///////////////////////////// ADC calibration /////////////////////////////////
  31.     if(cbADC->Checked)
  32.     {
  33.         if( m_Dcs.vi )
  34.         {
  35.             SetNormalVoltage_CloseAgilentPowerSupply();
  36.         }
  37.         else
  38.         {
  39.             InitAgilentPowerSupply_SetNormalVoltage_CloseAgilentPowerSupply();
  40.         }
  41.     }
  42.     PostMessage(
  43.                  this->Handle,
  44.                  WM_MF_CA_FAIL,
  45.                  0,
  46.                  0
  47.                  );
  48. }
  49. //---------------------------------------------------------------------------
  50. void __fastcall TfrmFatcory::after_Calibration_Fail(TObject *Sender)
  51. {
  52.     after_Calibration_Fail_function();
  53. }
  54. //---------------------------------------------------------------------------
  55. void __fastcall TfrmFatcory::after_Calibration_Fail_function(void)
  56. {
  57.         write_log();
  58.         clear_log();
  59.         write_result();
  60.         clear_result();
  61.       //  bb_Start->Kind = bkOK;
  62.         bb_Start->Tag = BUTTON_TAG_START;
  63.         bb_Start->Enabled = true;
  64.         bb_Start->Caption = "Start (F6)";
  65.         if( cbIP2->Checked )
  66.         {
  67.             WriteIP2RxAmCalModeToNormal();
  68.         }
  69.         if( cbSaveBarcodeToFileFail->Checked )
  70.         {
  71.             SaveBarcodeToFile();
  72.         }
  73.         if( cbSaveBarcodeToNVRAMFail->Checked )
  74.         {
  75.             WriteBarcodeToNVRAM();
  76.         }
  77.         DisplayBarcodeAfterIncreasement( cbBarcodeIncreasementFail->ItemIndex );
  78.         if( cbTurnOffPowerSupplyFail->Checked )
  79.         {
  80.             if( IS_AgilentPowerSupply_INITIALISE == true )
  81.             {
  82.                 SetOffVoltage_CloseAgilentPowerSupply();
  83.             }
  84.             else
  85.             {
  86.                 OpenOffCloseAgilentPowerSupply();
  87.             }
  88.         }
  89.         if( cbTerminateMETAFail->Checked )
  90.         {
  91.             SaveFactoryUISetting();
  92.             FormDestroy_function();
  93.         }
  94.         if (cbIP2->Checked        ||
  95.             cbAFC->Checked        ||
  96.             cbRxPathLoss->Checked ||
  97.             cbTxIq->Checked       ||
  98.             cbTxPcl->Checked
  99.           )
  100.         {
  101.             CRFSTOP RF_STOP_Obj;
  102.             RF_STOP_Obj.REQ_Start();
  103.         }
  104.         MF_state = eInit;
  105. }
  106. //---------------------------------------------------------------------------
  107. void __fastcall TfrmFatcory::on_Calibration_TerminateSuccess(TObject *Sender)
  108. {
  109.     is_calibration_start = false;
  110.     DisableAllCalTimer();
  111.     if (cbIP2->Checked        ||
  112.         cbAFC->Checked        ||
  113.         cbRxPathLoss->Checked ||
  114.         cbTxIq->Checked       ||
  115.         cbTxPcl->Checked      ||
  116.         m_cbTrxOffset->Checked
  117.        )
  118.     {
  119.         RCT_Dcl_Reset_Close();
  120.     }
  121.     //////////////////////// BT CAP ID calibration /////////////////////////////////////////
  122.     if (m_cbBTCapID->Checked)
  123.     {
  124.         if (!m_btt_ctrl.BTT_Close(&m_sBtt))
  125.         {
  126.             PostMessage(
  127.                           this->Handle,
  128.                           WM_MF_BTT_CLOSE_FAIL,
  129.                           0,
  130.                           0
  131.                         );
  132.         }
  133.     }
  134.     ///////////////////////////// ADC calibration /////////////////////////////////
  135.     if( cbADC->Checked )
  136.     {
  137.         if( m_Dcs.vi )
  138.         {
  139.             SetNormalVoltage_CloseAgilentPowerSupply();
  140.         }
  141.         else
  142.         {
  143.             InitAgilentPowerSupply_SetNormalVoltage_CloseAgilentPowerSupply();
  144.         }
  145.     }
  146.     PostMessage(
  147.                      this->Handle,
  148.                      WM_MF_CA_SUCCESS,
  149.                      0,
  150.                      0
  151.                  );
  152. }
  153. //---------------------------------------------------------------------------
  154. void __fastcall TfrmFatcory::after_Calibration_TerminateSuccess(TObject *Sender)
  155. {
  156.     CRFSTOP RF_STOP_Obj;
  157.     RF_STOP_Obj.REQ_Start();
  158.     if( ! cbIP2->Visible )
  159.     {
  160.         if( cbAFC->Checked        &&
  161.             cbRxPathLoss->Checked &&
  162.             cbTxIq->Checked &&
  163.             cbTxPcl->Checked      &&
  164.             cbADC->Checked
  165.            )
  166.         {
  167.             lb_META_factory_status->Caption = " Calibration done!";
  168.         }
  169.     }
  170.     else
  171.     {
  172.         if( cbIP2->Checked        &&
  173.             cbAFC->Checked        &&
  174.             cbRxPathLoss->Checked &&
  175.             cbTxIq->Checked &&
  176.             cbTxPcl->Checked      &&
  177.             cbADC->Checked
  178.           )
  179.         {
  180.             lb_META_factory_status->Caption = " Calibration done!";
  181.         }
  182.     }
  183.     write_log();
  184.     clear_log();
  185.     write_result(); // added by Andy Ueng
  186.     clear_result(); // added by Andy Ueng
  187.     //i_ID++;   // marked by Andy Ueng
  188.    // bb_Start->Kind = bkOK;
  189.     bb_Start->Tag = BUTTON_TAG_START;
  190.     bb_Start->Enabled = true;
  191.     bb_Start->Caption = "Start (F6)";
  192.     MF_state = eInit;
  193.     if( cbIP2->Checked )
  194.     {
  195.         WriteIP2RxAmCalModeToNormal();
  196.     }
  197.     
  198.     if( cbSaveBarcodeToFileSuccess->Checked )
  199.     {
  200.         SaveBarcodeToFile();
  201.     }
  202.     if( cbSaveBarcodeToNVRAMSuccess->Checked )
  203.     {
  204.         WriteBarcodeToNVRAM();
  205.     }
  206.     DisplayBarcodeAfterIncreasement( cbBarcodeIncreasementSuccess->ItemIndex );
  207.     
  208.     if( cbTurnOffPowerSupplySuccess->Checked )
  209.     {
  210.         if( IS_AgilentPowerSupply_INITIALISE == true )
  211.         {
  212.             SetOffVoltage_CloseAgilentPowerSupply();
  213.         }
  214.         else
  215.         {
  216.             OpenOffCloseAgilentPowerSupply();
  217.         }
  218.     }
  219.     if( cbTerminateMETASuccess->Checked )
  220.     {
  221.         SaveFactoryUISetting();
  222.         FormDestroy_function();
  223.     }
  224. }
  225. //---------------------------------------------------------------------------
  226.  void TfrmFatcory::wrap_log_file()
  227.  {
  228.      FILE *fp = fopen( as_LogFileName.c_str(), "at+");
  229.      if ( fp == NULL )
  230.         return;
  231.      if  ( filesize(fp) > (1024*1024*20) )
  232.      {
  233.         change_file_name( as_LogFileName);
  234.         stLogFile->Caption = as_LogFileName;
  235.         fclose(fp);
  236.         if ((fp = fopen( as_LogFileName.c_str() ,"wt+"))
  237.              == NULL)
  238.         {
  239.                 //ShowMessage( "Cannot open output file: " + as_LogFileName );
  240.                  AnsiString as_warning_msg;
  241.                  as_warning_msg = "Cannot open output file: " + as_LogFileName;
  242.                  Application->MessageBox( as_warning_msg.c_str(), "Warning", MB_OK );
  243.                  return;
  244.         }
  245.      } // if
  246.      fclose(fp);
  247.  }
  248. //---------------------------------------------------------------------------
  249. void __fastcall TfrmFatcory::bb_StartClick(TObject *Sender)
  250. {
  251.     Calibration_Button_Click();
  252. }
  253. //---------------------------------------------------------------------------
  254. void __fastcall TfrmFatcory::Calibration_Button_Click(void)
  255. {
  256.     DisableAllCalTimer();
  257.     if( ! cbIP2->Checked                &&
  258.         ! cbAFC->Checked                &&
  259.         ! cbRxPathLoss->Checked         &&
  260.         ! cbTxIq->Checked               &&
  261.         ! cbTxPcl->Checked              &&
  262.         ! m_cbTrxOffset->Checked        &&
  263.         ! cbADC->Checked                &&
  264.         ! m_cbCV->Checked               &&
  265.         ! cbWiFiTxDcOffset->Checked     &&
  266.         ! cbWiFiTxPower->Checked        &&
  267.         ! m_cbBTCapID->Checked
  268.       )
  269.     {
  270.          Application->MessageBox(" Please choose at least one calibration item", "Warning", MB_OK);
  271.          return;
  272.     }
  273.     if (cbWiFiTxPower->Checked && rbAgilentN4010A->Checked)
  274.     {
  275.          if (!(DllMan->LoadN4010ADllFunctions(this->Handle)))
  276.          {
  277.               Application->MessageBox(" Load Agilent N4010A AgN4010WSODrv.dll fail", "Warning", MB_OK);
  278.               return;
  279.          }
  280.     }
  281.     MF_state = eInit;
  282.     if (BUTTON_TAG_START == bb_Start->Tag)
  283.     {
  284.         bb_Start->Tag = BUTTON_TAG_STOP;
  285.         bb_Start->Enabled = false;
  286.         as_ID = edtBarcode->Text;
  287.         //if (!read_ini_file(stIniFile->Caption))
  288.         //{
  289.         //    Application->MessageBox("Read INI file fail", "FAILURE", MB_OK);
  290.         //    return;
  291.         //}
  292.         st_Log->Clear();
  293.         wrap_log_file();
  294.         st_Log->Add( "nn********************************************************************************************"
  295.                         );
  296.         st_Log->Add(DateToStr(Date()) + " " + CurrentTimeStr() +
  297.                     ed_Label->Text + " " + "ID = " + as_ID
  298.                     );
  299.         m_Cal.as_ResultBuf = m_Cal.as_ResultBuf + as_ID + ", ";
  300.         lb_META_factory_ID->Caption = "ID: " + as_ID;
  301.         int time_out;
  302.         TNotifyEvent ne;
  303.         TNotifyEvent neTBU;
  304.         ne = on_Calibration_TerminateSuccess;
  305.         neTBU = on_Calibration_TerminateByUser;
  306.         SetRctParameter();
  307.         SetBttParameter();
  308.         SetWftParameter();
  309.         SetDcsParameter();
  310.         SetCalibrationParameter();
  311.         pt_calibration = new T_META_factory_calibration(
  312.                                                          true,
  313.                                                          MF_ctrl,
  314.                                                          MF_ADC_ctrl,
  315.                                                          META_factory_cfg,
  316.                                                          st_Log,
  317.                                                          ne,
  318.                                                          neTBU,
  319.                                                          as_ID,
  320.                                                          as_AgeTaModel,
  321.                                                          &m_Rct,
  322.                                                          &m_sBtt,
  323.                                                          &m_Wft,
  324.                                                          &m_Dcs,
  325.                                                          &m_Cal
  326.                                                      );
  327.         if (pt_calibration != NULL)
  328.         {
  329.             pt_calibration->FreeOnTerminate = true;
  330.             pt_calibration->OnTerminate = on_Calibration_Fail;
  331.             pt_calibration->Priority = tpHighest;
  332.             is_suspend_cal = true;
  333.         }
  334.         else
  335.         {
  336.             PostMessage(this->Handle,
  337.                         WM_MF_PT_CALIBRATION_NEW_FAIL,
  338.                         0,
  339.                         0
  340.                         );
  341.             st_Log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  342.                         " FAIL: new calibration 2"
  343.                         );
  344.             return;
  345.         }
  346.         if (is_suspend_cal && pt_calibration != NULL)
  347.         {
  348.             is_suspend_cal = false;
  349.             pt_calibration->Resume();
  350.         }
  351.     }
  352. }
  353. //---------------------------------------------------------------------------
  354. bool TfrmFatcory::read_META_factory_setup( AnsiString asSetupFile, AnsiString asExeName )
  355. {
  356.     AnsiString asPath;
  357.     if ( getPathFromStr(asExeName, asPath) &&
  358.          withPath( asPath) &&
  359.          !withPath( asSetupFile)
  360.        )
  361.     {
  362.        asSetupFile = asPath + asSetupFile;
  363.     }
  364.     TIniFile *ini;
  365.     try
  366.     {
  367.         ini = new TIniFile( asSetupFile );
  368.         if( ini == NULL )  return false;
  369.         if( ! b_OpenNVRAMdatabase )
  370.         {
  371.             stNVRAMDBFile->Caption  = ini->ReadString("META factory","NVRAM database file", "");
  372.             if ( stNVRAMDBFile->Caption.Length() >0)
  373.             {
  374.                 if( ! read_db_file( stNVRAMDBFile->Caption ) )
  375.                 {
  376.                     Application->MessageBox("Open NVRAM database file fail", "FAILURE", MB_OK);
  377.                     delete ini;
  378.                     return false;
  379.                 }
  380.             }
  381.         }
  382.         if( ! b_OpenCfgFile )
  383.         {
  384.             stCFGFile->Caption  = ini->ReadString("META factory","Configuration file", "");
  385.             if ( stCFGFile->Caption.Length() >0)
  386.             {
  387.                 if( ! read_cfg_file( stCFGFile->Caption ) )
  388.                 {
  389.                     Application->MessageBox( "Read configuration file fail", "FAILURE", MB_OK );
  390.                     delete ini;
  391.                     return false;
  392.                 }
  393.             }
  394.         }
  395.         if( ! b_SetupLogFile )
  396.         {
  397.             stLogFile->Caption  = ini->ReadString("META factory","Logging file", "");
  398.             if ( stLogFile->Caption.Length() >0)
  399.             {
  400.                 if( ! setup_log_file( stLogFile->Caption ) )
  401.                 {
  402.                     Application->MessageBox( "Setup log file fail", "FAILURE", MB_OK );
  403.                     delete ini;
  404.                     return false;
  405.                 }
  406.             }
  407.         }
  408.         if( ! b_SetupResultFile )
  409.         {
  410.             stResultFile->Caption  = ini->ReadString("META factory","Result file", "");
  411.             if ( stResultFile->Caption.Length() >0)
  412.             {
  413.                 if( ! setup_result_file( stResultFile->Caption ) )
  414.                 {
  415.                     Application->MessageBox( "Setup result file fail", "FAILURE", MB_OK );
  416.                     delete ini;
  417.                     return false;
  418.                 }
  419.             }
  420.         }
  421.         if( ! b_OpenIniFile )
  422.         {
  423.             stIniFile->Caption  = ini->ReadString("META factory","Calibration data initial file", "");
  424.             if ( stIniFile->Caption.Length() >0)
  425.             {
  426.                 if( ! read_ini_file(stIniFile->Caption) )
  427.                 {
  428.                     Application->MessageBox( "Read ini file fail", "FAILURE", MB_OK );
  429.                     delete ini;
  430.                     return false;
  431.                 }
  432.             }
  433.         }
  434.         if( ! m_Cal.b_CalResultPath )
  435.         {
  436.             stCalPath->Caption  = ini->ReadString("META factory","Calibration data result path", "");
  437.             if ( stIniFile->Caption.Length()<0 )
  438.             {
  439.                 Application->MessageBox( "Read calibration data result path fail", "FAILURE", MB_OK );
  440.                 delete ini;
  441.                 return false;
  442.             }
  443.             else
  444.             {
  445.                 m_Cal.b_CalResultPath = true;
  446.             }
  447.         }
  448.         delete ini;
  449.         return true;
  450.     }
  451.     catch (...)
  452.     {
  453.        AnsiString as_warning_msg;
  454.        as_warning_msg = " META factory : read setup file : " + asSetupFile + " error ";
  455.        Application->MessageBox( as_warning_msg.c_str(), "Warning", MB_OK );
  456.        return false;
  457.     }
  458. }
  459. //---------------------------------------------------------------------------
  460. bool TfrmFatcory::write_META_factory_setup(
  461.                                                    AnsiString asSetupFile,
  462.                                                    AnsiString asExeName
  463.                                                  )
  464. {
  465.     AnsiString asPath;
  466.     if ( getPathFromStr(asExeName, asPath) &&
  467.          withPath( asPath) &&
  468.          !withPath( asSetupFile)
  469.        )
  470.     {
  471.        asSetupFile = asPath + asSetupFile;
  472.     }
  473.     TIniFile *ini;
  474.     try
  475.     {
  476.         ini = new TIniFile( asSetupFile );
  477.         if(ini == NULL)  return false;
  478.         ini->WriteString("META factory","NVRAM database file", stNVRAMDBFile->Caption );
  479.         ini->WriteString("META factory","Configuration file", stCFGFile->Caption );
  480.         ini->WriteString("META factory","Logging file", stLogFile->Caption );
  481.         ini->WriteString("META factory","Result file", stResultFile->Caption );
  482.         ini->WriteString("META factory","Calibration data initial file", stIniFile->Caption );
  483.         ini->WriteString("META factory","Calibration data result path", stCalPath->Caption );
  484.         ini->WriteString("Main menu", "COM PORT", "COM"+IntToStr(frmMainSel->cbxCOM->ItemIndex+1) );
  485.         delete ini;
  486.         ini = NULL;
  487.     }
  488.     catch (...)
  489.     {
  490.         AnsiString as_warning_msg;
  491.         as_warning_msg = " META factory : write setup file : " + asSetupFile + " error ";
  492.         Application->MessageBox( as_warning_msg.c_str(), "Warning", MB_OK );
  493.     }
  494.     return true;
  495. }
  496. //---------------------------------------------------------------------------
  497. void __fastcall TfrmFatcory::FormClose(TObject *Sender,
  498.       TCloseAction &Action)
  499. {
  500.     DisableAllCalTimer();
  501.     if( ! write_META_factory_setup( "MF_setup.txt", Application->ExeName ) )
  502.     {
  503.         Application->MessageBox( "Execution Failure : Save META factory setup", "FAILURE", MB_OK );
  504.     }
  505.     TIniFile   *ini_file;
  506.     ini_file = new TIniFile( stCFGFile->Caption );
  507.     if(ini_file != NULL) // added by Andy Ueng
  508.     {
  509.       // ini_file->WriteString( "META factory",
  510.       //                       "FACTORY_ID",
  511.       //                       EditStartID->Text );
  512.        delete ini_file;
  513.     }
  514.     SaveFactoryUISetting();
  515.     if ( cbTerminateMETAExit->Checked )
  516.     {
  517.         FormDestroy_function();
  518.     }
  519. }
  520. //---------------------------------------------------------------------------
  521. void __fastcall TfrmFatcory::FormShow(TObject *Sender)
  522. {
  523.     static bool b_FirstFormShow = true;
  524.     if (b_FirstFormShow)
  525.     {
  526.         b_FirstFormShow = false;
  527.         m_Cal.e_bb_chip = frmMainSel->Get_FinalBBChip();
  528.         m_Cal.ui_rf_id = frmMainSel->Get_FinalRFID();
  529.         m_Cal.s_wifi_cap = frmMainSel->Get_FinalWiFiCap();
  530.         
  531.         if( read_META_factory_setup( "MF_setup.txt", Application->ExeName ) == false )
  532.         {
  533.            // Application->MessageBox("Read META factory setup fail", "FAILURE", MB_OK );
  534.         }
  535.         frmFatcory->AutoScroll = true;
  536.         lb_META_factory_ID->Caption = "";
  537.         lb_META_factory_status->Caption = "";
  538.         bb_Start->Tag = BUTTON_TAG_START;
  539.         bb_Start->Enabled = true;
  540.         bb_Start->Caption = "Start (F6)";
  541.         update_Start_button();
  542.         DisableAllCalTimer();
  543.         //DisplayInitialValueFrom();
  544.         DisplayPowerSupplyType();
  545.         DisplayAFCCal();
  546.         DisplayCrystalCapId();
  547.         //DisplayCapIdCal();
  548.         DisplayTxAfcOffsetCal();
  549.         DisplayResetRfTester();
  550.         DisplayAFCType();
  551.         DisplayRxPathLossCal();
  552.         DisplayIP2Cal();
  553.         DisplayTxIqCal();
  554.         DisplayTxPclCal();
  555.         DisplayADCCal();
  556.         DisplayCVCal();
  557.         DisplayWiFiTxDcOffsetCal();
  558.         DisplayWiFiTxPowerCal();
  559.         DisplayBTCrystalCAPIDCal();
  560.         DisplayPAType();
  561.         //DisplayPABiasType();
  562.         DisplayTXPCLType();
  563.         DisplayApcModulation();
  564.         DisplayRFCalibrationEquipment();
  565.         DisplayWiFiCalibrationEquipment();
  566.         DisplayBTCalibrationEquipment();
  567.         DisplayBarcodeIncreasementEnter();
  568.         DisplayReadBarcodeFromEnter();
  569.         DisplayAutoStartCalibrationEnter();
  570.         DisplaySaveBarcodeToNVRAMExit();
  571.         DisplaySaveBarcodeToFileExit();
  572.         DisplayBarcodeIncreasementExit();
  573.         DisplaySaveBarcodeToNVRAMSuccess();
  574.         DisplaySaveBarcodeToFileSuccess();
  575.         DisplayBarcodeIncreasementSuccess();
  576.         DisplaySaveBarcodeToNVRAMFail();
  577.         DisplaySaveBarcodeToFileFail();
  578.         DisplayBarcodeIncreasementFail();
  579.         //DisplayBarcodeSaveTo();
  580.         DisplayTerminateMETAExit();
  581.         DisplayTerminateMETAFail();
  582.         DisplayTurnOffPowerSupplyFail();
  583.         DisplayTerminateMETASuccess();
  584.         DisplayTurnOffPowerSupplySuccess();
  585.         ApplyHideProperty();
  586.     }
  587. }
  588. //---------------------------------------------------------------------------
  589. void __fastcall TfrmFatcory::About2Click(TObject *Sender)
  590. {
  591.   Form_About->lblAboutTitle->Caption ="META factory";
  592.   if ( Form_About->ShowModal() == mrOk)
  593.   {
  594.      Form_About->lblAboutTitle->Caption ="META LAB 2";   // recovery
  595.   } else
  596.   {
  597.      Form_About->lblAboutTitle->Caption ="META LAB 2";   // recovery
  598.   }
  599. }
  600. //---------------------------------------------------------------------------
  601. bool TfrmFatcory::read_cfg_file(AnsiString asFileName)
  602. {
  603.     if (NULL == META_factory_cfg )
  604.     {
  605.         META_factory_cfg = new TMETA_factory_cfg();
  606.     }
  607.     if( META_factory_cfg == NULL )
  608.     {
  609.         return  false;
  610.     }
  611.     if( ! b_OpenCfgFile )
  612.     {
  613.         if(! META_factory_cfg->ReadFromIniFile(asFileName))
  614.         {
  615.             b_OpenCfgFile = false;
  616.             return false;
  617.         }
  618.         else
  619.         {
  620.             b_OpenCfgFile = true;
  621.             stCFGFile->Caption = asFileName;
  622.             char cM_PM;
  623.             META_factory_cfg->getM_PM( cM_PM );
  624.             if( (cM_PM >=5) &&  (0 == m_Cal.RfCapability.capability.Calibration_8PM) )
  625.             {
  626.                 Application->MessageBox( "MS support at most 4 PM per frame, please modify M_PM in CFG file" , "Warning", MB_OK );
  627.                 return false;
  628.             }
  629.             else if( cM_PM >8 )
  630.             {
  631.                 Application->MessageBox( "MS support at most 8 PM per frame, please modify M_PM in CFG file" , "Warning", MB_OK );
  632.                 return false;
  633.             }
  634.         }
  635.     }
  636.     update_Start_button();
  637.     return true;
  638. }
  639. //---------------------------------------------------------------------------
  640. void __fastcall TfrmFatcory::miOpenConfigFileClick(TObject *Sender)
  641. {
  642.     if (dlg_OpenConfigFile->Execute())
  643.     {
  644.         b_OpenCfgFile = false;
  645.         if (!read_cfg_file(dlg_OpenConfigFile->FileName))
  646.         {
  647.             Application->MessageBox("Read configuration fail", "FAILURE", MB_OK);
  648.             return;
  649.         }
  650.         write_ConfigurationFile("MF_setup.txt", Application->ExeName, stCFGFile->Caption);
  651.     }
  652. }
  653. //---------------------------------------------------------------------------
  654. bool TfrmFatcory::setup_log_file( AnsiString asFileName)
  655. {
  656.     as_LogFileName = asFileName;
  657.     b_SetupLogFile = true;
  658.     stLogFile->Caption = asFileName;
  659.     return true;
  660. }
  661. //---------------------------------------------------------------------------
  662. bool TfrmFatcory::setup_result_file( AnsiString asFileName)
  663. {
  664.     as_ResultFileName = asFileName;
  665.     b_SetupResultFile = true;
  666.     stResultFile->Caption = asFileName;
  667.     return true;
  668. }
  669. //---------------------------------------------------------------------------
  670. bool TfrmFatcory::setup_cal_result_path( AnsiString asFileName)
  671. {
  672.     as_CalResultPath = asFileName;
  673.     m_Cal.b_CalResultPath = true;
  674.     stCalPath->Caption = asFileName;
  675.     return true;
  676. }
  677. //---------------------------------------------------------------------------
  678. void __fastcall TfrmFatcory::miSetupLoggingFileClick(
  679.       TObject *Sender)
  680. {
  681.     if ( dlg_SetupLogFile->Execute() )
  682.     {
  683.         b_SetupLogFile = false;
  684.         if( ! setup_log_file( dlg_SetupLogFile->FileName )  )
  685.         {
  686.             Application->MessageBox( "Setup log file fail", "FAILURE", MB_OK );
  687.             return;
  688.         }
  689.         write_LoggingFile( "MF_setup.txt", Application->ExeName, stLogFile->Caption );
  690.     }
  691. }
  692. //---------------------------------------------------------------------------
  693. bool TfrmFatcory::read_ini_file(AnsiString asFileName)
  694. {
  695.     AnsiString as;
  696.     // AFC
  697.     if (!MF_rf_afc_ptr->REQ_Read_From_File(asFileName.c_str()))
  698.     {
  699.         return false;
  700.     }
  701.     if (!MF_crystal_afc_ptr->REQ_Read_CAPID_From_File(asFileName.c_str()))
  702.     {
  703.         return false;
  704.     }
  705.     // RX path loss
  706.     if (!MF_rf_agc_ptr->REQ_Read_From_File(asFileName.c_str()))
  707.     {
  708.         return false;
  709.     }
  710.     // IP2
  711.     if (!MF_rf_pm_ptr->REQ_Read_IP2Reg_From_File(asFileName.c_str(), m_Cal.ui_rf_id))
  712.     {
  713.         return false;
  714.     }
  715.     // APC
  716.     if (!MF_rf_apc_ptr->REQ_Read_APC_From_File(asFileName.c_str(), m_Cal.ui_rf_id, m_Cal.b_TADOSupport))
  717.     {
  718.         return false;
  719.     }
  720.     if (!MF_rf_apc_8psk_ptr->REQ_Read_APC_From_File(asFileName.c_str(), m_Cal.ui_rf_id))
  721.     {
  722.         return false;
  723.     }
  724.     // BT CAP ID
  725.     if (!m_Cal.s_cal_obj.pc_BT_INFO6611_Obj->REQ_Read_From_File(asFileName.c_str()))
  726.     {
  727.         return false;
  728.     }
  729.     // ADC
  730.     if (!MF_BB_ADC_ptr->REQ_Read_From_File(asFileName.c_str()))
  731.     {
  732.         return false;
  733.     }
  734.     if (!m_Cal.s_cal_obj.pc_WIFI_APC_Obj->REQ_Read_TxPower2400M_From_File(asFileName.c_str()))
  735.     {
  736.         return false;
  737.     }
  738.     // ALC
  739.     if (!m_Cal.s_cal_obj.pc_WIFI_ALC_Obj->REQ_Read_From_File(asFileName.c_str()))
  740.     {
  741.         return false;
  742.     }
  743.     b_OpenIniFile = true;
  744.     stIniFile->Caption = asFileName;
  745.     update_Start_button();
  746.     return true;
  747. }
  748. //---------------------------------------------------------------------------
  749. void __fastcall TfrmFatcory::miOpenInitialFileClick(TObject *Sender)
  750. {
  751.     if ( dlg_OpenIniFile->Execute() )
  752.     {
  753.         b_OpenIniFile = false;
  754.         if( read_ini_file( dlg_OpenIniFile->FileName ) == false )
  755.         {
  756.             Application->MessageBox( "Read ini file fail", "FAILURE", MB_OK );
  757.             return;
  758.         }
  759.         write_InitialFile( "MF_setup.txt", Application->ExeName, stIniFile->Caption );
  760.     }
  761. }
  762. //---------------------------------------------------------------------------
  763. void __fastcall TfrmFatcory::Exit1Click(TObject *Sender)
  764. {
  765.    Close();
  766. }
  767. //---------------------------------------------------------------------------
  768.  void TfrmFatcory::update_Start_button()
  769.  {
  770.     if ( b_OpenCfgFile && b_OpenIniFile && bb_Start->Tag == BUTTON_TAG_START )
  771.     {
  772.         bb_Start->Enabled = true;
  773.     } else
  774.     {
  775.         bb_Start->Enabled = false;
  776.     }
  777.  }
  778. //---------------------------------------------------------------------------
  779. void __fastcall TfrmFatcory::ed_LabelKeyUp(TObject *Sender,
  780.       WORD &Key, TShiftState Shift)
  781. {
  782.     if ( AnsiCompareText(as_Label , ed_Label->Text) != 0)
  783.     {
  784.         //i_ID = 0;
  785.         as_ID = "0";
  786.     }
  787.     // lb_META_factory_ID->Caption = "ID:" + IntToStr( i_ID );
  788.     lb_META_factory_ID->Caption = "ID:" + as_ID;
  789. }
  790. //---------------------------------------------------------------------------
  791. bool TfrmFatcory::read_db_file( AnsiString asFileName )
  792. {
  793.     unsigned long nvram_idb;
  794.     META_RESULT meta_result;
  795.     meta_result = META_NVRAM_Init_r( m_META_HANDLE_Obj.Get_MainHandle(), asFileName.c_str(), &nvram_idb);
  796.     if( ! b_OpenNVRAMdatabase )
  797.     {
  798.         if ((META_SUCCESS != meta_result)             &&
  799.             (META_MAUI_DB_INCONSISTENT != meta_result)
  800.            )
  801.         {
  802.             Application->MessageBox("Open NVRAM database file fail", "FAILURE", MB_OK);
  803.             return false;
  804.         }
  805.         else
  806.         {
  807.             if (META_MAUI_DB_INCONSISTENT == meta_result)
  808.             {
  809.                 Application->MessageBox("NVRAM database file and target load is inconsistent", "WARNING", MB_OK);
  810.             }
  811.             b_OpenNVRAMdatabase = true;
  812.             //asFileName = frmMainSel->Get_NVRAMDBFileName();
  813.             stNVRAMDBFile->Caption = asFileName;
  814.             update_Start_button();
  815.             NVRAMMan->GetSupportInfoFromNVRAMDB();
  816.             return true;
  817.         }    
  818.     }
  819.      NVRAMMan->GetSupportInfoFromNVRAMDB();
  820.     return true;
  821. }
  822. //---------------------------------------------------------------------------
  823. void __fastcall TfrmFatcory::miOpenfdmfileClick(TObject *Sender)
  824. {
  825.     if (dlg_OpenFDM_DB->Execute())
  826.     {
  827.         b_OpenNVRAMdatabase = false;
  828.         if (!read_db_file( dlg_OpenFDM_DB->FileName ))
  829.         {
  830.             Application->MessageBox("Open NVRAM database file fail", "FAILURE", MB_OK);
  831.             return;
  832.         }
  833.         write_NVRAM_DATABASE_FILE( "MF_setup.txt", Application->ExeName, stNVRAMDBFile->Caption );
  834.     }
  835. }
  836. //---------------------------------------------------------------------------
  837. void __fastcall TfrmFatcory::miSetupresultfileClick(
  838.       TObject *Sender)
  839. {
  840.     if ( dlg_SetupResultFile->Execute() )
  841.     {
  842.         b_SetupResultFile = false;
  843.         if( ! setup_result_file( dlg_SetupResultFile->FileName )  )
  844.         {
  845.             Application->MessageBox( "Setup result file fail", "FAILURE", MB_OK );
  846.             return;
  847.         }
  848.         write_ResultFile( "MF_setup.txt", Application->ExeName, stResultFile->Caption );
  849.     }
  850. }
  851. //---------------------------------------------------------------------------
  852. void __fastcall TfrmFatcory::TimerCalTimer(TObject *Sender)
  853. {
  854.     DisableAllCalTimer();
  855.     if(pt_calibration != NULL && is_calibration_start)
  856.     {
  857.         pt_calibration->OnTerminate = on_Calibration_Fail;
  858.         pt_calibration->Terminate();
  859.         is_calibration_start = false;
  860.         pt_calibration = NULL;
  861.     }
  862.     switch(TimerCalTimeoutID)
  863.     {
  864.         ////////////////////////////   baseband //////////////////////////////
  865.         case WM_MF_BB_REG_READ_FAIL:
  866.         {
  867.             st_Log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  868.                           " FAIL: read baseband register (cal timer)"
  869.                          );
  870.         }
  871.         break;
  872.         case WM_MF_BB_REG_WRITE_FAIL:
  873.         {
  874.             st_Log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  875.                           " FAIL: write baseband register (cal timer)"
  876.                          );
  877.         }
  878.         break;
  879.         case WM_MF_BB_REG_SET_FAIL:
  880.         {
  881.             st_Log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  882.                           " FAIL: set baseband register (cal timer)"
  883.                          );
  884.         }
  885.         break;
  886.         //////////////////////////// RF general //////////////////////////////
  887.         case WM_MF_RF_STOP_FAIL:
  888.         {
  889.              st_Log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  890.                           " FAIL: stop RF (cal timer)"
  891.                          );
  892.         }
  893.         break;
  894.         //////////////////////////// RX path loss //////////////////////////////
  895.         case WM_MF_NVRAM_PATH_LOSS_WRITE_FAIL:
  896.         {
  897.              st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  898.                           " FAIL: write path loss to flash (cal timer)"
  899.                          );
  900.         }
  901.         break;
  902.         case WM_MF_RF_PM_FAIL:
  903.         {
  904.              st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  905.                           " FAIL: PM (cal timer)"
  906.                         );
  907.         }
  908.         break;
  909.         ////////////////////   AFC   ////////////////////////////////////////
  910.         case WM_MF_NVRAM_AFC_WRITE_FAIL:
  911.         {
  912.               st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  913.                             " FAIL: write AFC slope and offset to flash (cal timer)"
  914.                           );
  915.         }
  916.         break;
  917.         case WM_MF_RF_AFC_CONTROL_FAIL:
  918.         {
  919.              st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  920.                            " FAIL: AFC control (cal timer)"
  921.                          );
  922.         }
  923.         break;
  924.         case WM_MF_RF_AFC_GET_AFCDAC_FAIL:
  925.         {
  926.              st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  927.                            " FAIL: get target AFC DAC (cal timer)"
  928.                          );
  929.         }
  930.         break;
  931.         case WM_MF_RF_SET_AFC_DAC_FAIL:
  932.         {
  933.              st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  934.                           " FAIL: set AFC DAC (cal timer)"
  935.                          );
  936.         }
  937.         break;
  938.         ////////////////////// crystal AFC  ///////////////////////////////////
  939.         case WM_MF_RF_CRYSTAL_AFC_SELECT_BAND_FAIL:
  940.         {
  941.              st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  942.                           " FAIL: crystal AFC select band (cal timer)"
  943.                          );
  944.         }
  945.         break;
  946.         case WM_MF_RF_CRYSTAL_AFC_CONTROL_FAIL:
  947.         {
  948.              st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  949.                           " FAIL: crystal AFC cotnrol (cal timer)"
  950.                          );
  951.         }
  952.         break;
  953.         case WM_MF_NVRAM_CRYSTAL_AFC_CAPID_WRITE_FAIL:
  954.         {
  955.             st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  956.                           " FAIL: write crystal AFC CAP ID to NVRAM (cal timer)"
  957.                          );
  958.         }
  959.         break;
  960.         case WM_MF_RF_CRYSTAL_AFC_TX_LEVEL_FAIL:
  961.         {
  962.              st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  963.                           " FAIL: crystal AFC TX level (cal timer)"
  964.                          );
  965.         }
  966.         break;
  967.         case WM_MF_RF_CRYSTAL_AFC_CHECK_FAIL:
  968.         {
  969.              st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  970.                           " FAIL: crystal AFC check (cal timer)"
  971.                          );
  972.         }
  973.         break;
  974.         case WM_MF_RF_SET_CRYSTAL_AFC_DAC_FAIL:
  975.         {
  976.              st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  977.                           " FAIL: set crystal AFC DAC (cal timer)"
  978.                          );
  979.         }
  980.         break;
  981.         case WM_MF_RF_SET_CRYSTAL_AFC_DAC_CNF_FAIL:
  982.         {
  983.              st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  984.                           " FAIL: set crystal AFC DAC cnf(cal timer)"
  985.                          );
  986.         }
  987.         break;
  988.         case WM_MF_AGE8960_SET_MESA_FUNC_PFER_FAIL:
  989.         {
  990.             st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  991.                           " FAIL: set measurement function PFER(cal timer)"
  992.                          );
  993.         }
  994.         break;
  995.         case WM_MF_AGE8960_READ_PFER_FAIL:
  996.         {
  997.             st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  998.                           " FAIL: read PFER(cal timer)"
  999.                          );
  1000.         }
  1001.         break;
  1002.         //////////////////////     IP2     ///////////////////////////////////
  1003.         case WM_MF_RF_IP2_SET_MAG_FAIL:
  1004.         {
  1005.              st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1006.                            " FAIL: Set IP2 mag to register (cal timer)"
  1007.                          );
  1008.         }
  1009.         break;
  1010.         case WM_MF_RF_IP2_SET_POL_FAIL:
  1011.         {
  1012.              st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1013.                            " FAIL: Set IP2 pol to register (cal timer)"
  1014.                          );
  1015.         }
  1016.         break;
  1017.         case WM_MF_RF_IP2_SET_AMCALMODE_FAIL:
  1018.         {
  1019.              st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1020.                            " FAIL: IP2 set rxamcalmode to register (cal timer)"
  1021.                          );
  1022.         }
  1023.         break;
  1024.         case WM_MF_RF_IP2_SET_CW7_FAIL:
  1025.         {
  1026.             st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1027.                            " FAIL: IP2 set CW7 to register (cal timer)"
  1028.                          );
  1029.         }
  1030.         break;
  1031.         case WM_MF_RF_IP2_SET_BCCODE_FAIL:
  1032.         {
  1033.             st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1034.                            " FAIL: IP2 set B,C code to register (cal timer)"
  1035.                          );
  1036.         }
  1037.         break;
  1038.         case WM_MF_RF_IP2_SET_MT6139_COEF_FAIL:
  1039.         {
  1040.             st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1041.                            " FAIL: IP2 set MT6139 coefficient (cal timer)"
  1042.                          );
  1043.         }
  1044.         break;
  1045.         case WM_MF_RF_IP2_GET_BCCODE_FAIL:
  1046.         {
  1047.             st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1048.                            " FAIL: IP2 Get B,C code from register (cal timer)"
  1049.                          );
  1050.         }
  1051.         break;
  1052.         case WM_MF_RF_IP2_CHECK_FAIL:
  1053.         {
  1054.             st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1055.                            " FAIL: IP2 check (cal timer)"
  1056.                          );
  1057.         }
  1058.         break;
  1059.         case WM_MF_RF_IP2_SET_CW2_FAIL:
  1060.         {
  1061.              st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1062.                            " FAIL: IP2 set CW2 to register (cal timer)"
  1063.                          );
  1064.         }
  1065.         break;
  1066.         case WM_MF_RF_IP2_GET_ACODE_FAIL:
  1067.         {
  1068.              st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1069.                            " FAIL: IP2 get acode from register (cal timer)"
  1070.                          );
  1071.         }
  1072.         break;
  1073.         case WM_MF_RF_IP2_GET_CW7_FAIL:
  1074.         {
  1075.              st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1076.                            " FAIL: IP2 get CW7 from register (cal timer)"
  1077.                          );
  1078.         }
  1079.         break;
  1080.         case WM_MF_RF_IP2_PM_FAIL:
  1081.         {
  1082.              st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1083.                            " FAIL: IP2 PM (cal timer)"
  1084.                          );
  1085.         }
  1086.         break;
  1087.         case WM_MF_NVRAM_IP2_READ_FAIL:
  1088.         {
  1089.              st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1090.                            " FAIL: read IP2 from flash (cal timer)"
  1091.                          );
  1092.         }
  1093.         break;
  1094.         case WM_MF_NVRAM_IP2_WRITE_FAIL:
  1095.         {
  1096.              st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1097.                            " FAIL: write IP2 to flash (cal timer)"
  1098.                          );
  1099.         }
  1100.         break;
  1101.         //////////////////////     APC     ////////////////////////////////////
  1102.         case WM_MF_NVRAM_LEVEL_RAMP_WRITE_FAIL:
  1103.         {
  1104.              st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1105.                            " FAIL: write level ramp to flash (cal timer)"
  1106.                          );
  1107.         }
  1108.         break;
  1109.         case WM_MF_SET_RAMPAPCLEVEL_FAIL:
  1110.         {
  1111.              st_Log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  1112.                          " FAIL: set ramp APC level (cal timer)"
  1113.                          );
  1114.         }
  1115.         break;
  1116.         case WM_MF_RF_A60111A_ENTER_FACTORY_MODE_FAIL:
  1117.         {
  1118.             st_Log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  1119.                          " FAIL: A60111A enter factory mode (cal timer)"
  1120.                          );
  1121.         }
  1122.         break;
  1123.         case WM_MF_RF_A60111A_READ_REF_TEMP_FAIL:
  1124.         {
  1125.             st_Log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  1126.                          " FAIL: A60111A read temp_ref (cal timer)"
  1127.                          );
  1128.         }
  1129.         break;
  1130.         case WM_MF_RF_TX_LEVEL_FAIL:
  1131.         {
  1132.              st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1133.                            " FAIL: TX level (cal timer)"
  1134.                          );
  1135.         }
  1136.         break;
  1137.         case WM_MF_RF_TX_LEVEL_EVALDAC_FAIL:
  1138.         {
  1139.             st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1140.                            " FAIL: TX level evaluate DAC value(cal timer)"
  1141.                          );
  1142.         }
  1143.         break;
  1144.         case WM_MF_SET_APC_DAC_FAIL:
  1145.         {
  1146.               st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1147.                           " FAIL: set APC DAC (cal timer)"
  1148.                          );
  1149.         }
  1150.         break;
  1151.         case WM_MF_SET_APC_DC_OFFSET_FAIL:
  1152.         {
  1153.              st_Log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  1154.                           " FAIL: set APC DC offset (cal timer)"
  1155.                          );
  1156.         }
  1157.         break;
  1158.         case WM_MF_AGE8960_READ_TX_POWER_FAIL:
  1159.         {
  1160.               st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1161.                            " FAIL: read TX power (cal timer)"
  1162.                          );
  1163.          }
  1164.          break;
  1165.          case WM_MF_AGE8960_CONFIG_TX_POWER_FAIL:
  1166.          {
  1167.               st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1168.                           " FAIL: config TX power (cal timer)"
  1169.                          );
  1170.          }
  1171.          break;
  1172.          case WM_MF_AGE8960_CONFIG_PFER_FAIL:
  1173.          {
  1174.               st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1175.                           " FAIL: config PFER (cal timer)"
  1176.                          );
  1177.          }
  1178.          break;
  1179.          case WM_MF_AGE8960_CONFIG_IQ_TUNNING_FAIL:
  1180.          {
  1181.               st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1182.                           " FAIL: config IQ_TUNNING (cal timer)"
  1183.                          );
  1184.          }
  1185.          break;
  1186.          case WM_MF_AGE8960_CONFIG_EPSK_MOD_ACCURACY_FAIL:
  1187.         {
  1188.             st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1189.                           " FAIL: config EPSK modulation accuracy (cal timer)"
  1190.                          );
  1191.         }
  1192.         break;
  1193.         case WM_MF_AGE8960_FETCH_EPSK_OOS_FAIL:
  1194.         {
  1195.             st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1196.                           " FAIL: fetch EPSK original offset (cal timer)"
  1197.                          );
  1198.         }
  1199.         break;
  1200.         case WM_MF_AGE8960_FETCH_EPSK_SBS_FAIL:
  1201.         {
  1202.             st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1203.                           " FAIL: fetch EPSK IQ imbalance (cal timer)"
  1204.                          );
  1205.         }
  1206.         break;
  1207.          case WM_MF_WIFI_CPT_FAIL:
  1208.          {
  1209.              st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1210.                           " FAIL: WiFi continuous packet TX (cal timer)"
  1211.                          );
  1212.          }
  1213.          break;
  1214.          case WM_MF_WIFI_CPT_STOP_FAIL:
  1215.          {
  1216.              st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1217.                           " FAIL: WiFi stop continuous packet TX (cal timer)"
  1218.                          );
  1219.          }
  1220.          break;
  1221.          case WM_MF_WIFI_INIT_FAIL:
  1222.          {
  1223.              st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1224.                           " FAIL: WiFi tester init (cal timer)"
  1225.                          );
  1226.          }
  1227.          break;
  1228.          case WM_MF_WIFI_TERMINATE_FAIL:
  1229.          {
  1230.              st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1231.                           " FAIL: WiFi tester terminate (cal timer)"
  1232.                          );
  1233.          }
  1234.          break;
  1235.          case WM_MF_WIFI_CONN_OPEN_FAIL:
  1236.          {
  1237.              st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1238.                           " FAIL: WiFi tester connection open (cal timer)"
  1239.                          );
  1240.          }
  1241.          break;
  1242.          case WM_MF_WIFI_CONN_UPDATE_CALDATA_FAIL:
  1243.          {
  1244.              st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1245.                           " FAIL: WiFi tester updates calibration data (cal timer)"
  1246.                          );
  1247.          }
  1248.          break;
  1249.          case WM_MF_WIFI_CONN_CLOSE_FAIL:
  1250.          {
  1251.             st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1252.                           " FAIL: WiFi tester connection close (cal timer)"
  1253.                          );
  1254.          }
  1255.          break;
  1256.          case WM_MF_WIFI_SET_DEFAULT_FAIL:
  1257.          {
  1258.             st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1259.                           " FAIL: WiFi tester sets default value (cal timer)"
  1260.                          );
  1261.          }
  1262.          break;
  1263.          case WM_MF_WIFI_SET_PACKET_LEN_FAIL:
  1264.          {
  1265.             st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1266.                           " FAIL: WiFi tester sets packet length (cal timer)"
  1267.                          );
  1268.          }
  1269.          break;
  1270.          case WM_MF_WIFI_SET_TRIGGER_STYLE_FAIL:
  1271.          {
  1272.              st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1273.                           " FAIL: WiFi tester sets trigger style (cal timer)"
  1274.                          );
  1275.          }
  1276.          break;
  1277.          case WM_MF_WIFI_APPLY_CHANGE_FAIL:
  1278.          {
  1279.              st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1280.                           " FAIL: WiFi tester apply change value (cal timer)"
  1281.                          );
  1282.          }
  1283.          break;
  1284.          case WM_MF_WIFI_SET_CENTRAL_FREQ_FAIL:
  1285.          {
  1286.              st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1287.                           " FAIL: WiFi tester sets cental frequency (cal timer)"
  1288.                          );
  1289.          }
  1290.          break;
  1291.          case WM_MF_WIFI_SET_POWER_RANGE_FAIL:
  1292.          {
  1293.             st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1294.                           " FAIL: WiFi tester sets power range (cal timer)"
  1295.                          );
  1296.          }
  1297.          break;
  1298.          case WM_MF_WIFI_DATA_CAPTURE_FAIL:
  1299.          {
  1300.              st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1301.                           " FAIL: WiFi tester captures data (cal timer)"
  1302.                          );
  1303.          }
  1304.          break;
  1305.          case WM_MF_WIFI_ANALYZE_POWER_FAIL:
  1306.          {
  1307.              st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1308.                           " FAIL: WiFi tester analyzes TX power (cal timer)"
  1309.                          );
  1310.          }
  1311.          break;
  1312.          case WM_MF_WIFI_READ_POWER_FAIL:
  1313.          {
  1314.              st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1315.                           " FAIL: WiFi tester reads TX power (cal timer)"
  1316.                          );
  1317.          }
  1318.          break;
  1319.          case WM_MF_NVRAM_WIFI_APC_READ_FAIL:
  1320.          {
  1321.              st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1322.                           " FAIL: reads WiFi TX power from NVRAM (cal timer)"
  1323.                          );
  1324.          }
  1325.          break;
  1326.          case WM_MF_NVRAM_WIFI_APC_WRITE_FAIL:
  1327.          {
  1328.              st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1329.                           " FAIL: writes WiFi TX power to NVRAM (cal timer)"
  1330.                          );
  1331.          }
  1332.          break;
  1333.          case WM_MF_NVRAM_WIFI_ALC_READ_FAIL:
  1334.          {
  1335.              st_Log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  1336.                           " FAIL: reads WiFi ALC from NVRAM (cal timer)"
  1337.                          );
  1338.          }
  1339.          break;
  1340.          case WM_MF_NVRAM_WIFI_ALC_WRITE_FAIL:
  1341.          {
  1342.              st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1343.                           " FAIL: writes WiFi ALC to NVRAM (cal timer)"
  1344.                          );
  1345.          }
  1346.          break;
  1347.          case WM_MF_NVRAM_WIFI_TX_DC_OFFSET_READ_FAIL:
  1348.          {
  1349.              st_Log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  1350.                          " FAIL: reads WiFi TX DC offset from NVRAM (cal timer)"
  1351.                          );
  1352.          }
  1353.          break;
  1354.          case WM_MF_NVRAM_WIFI_TX_DC_OFFSET_WRITE_FAIL:
  1355.          {
  1356.              st_Log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  1357.                           " FAIL: writes WiFi TX DC offset to NVRAM (cal timer)"
  1358.                          );
  1359.          }
  1360.          break;
  1361.          case WM_MF_WIFI_TX_DC_OFFSET_FAIL:
  1362.          {
  1363.              st_Log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  1364.                           " FAIL: writes WiFi TX DC offset calibration (cal timer)"
  1365.                          );
  1366.          }
  1367.          break;
  1368.          // BT tester
  1369.          case WM_MF_BTT_INIT_FAIL:
  1370.          {
  1371.              st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1372.                           " FAIL: BT tester < initialization (cal timer)"
  1373.                          );
  1374.          }
  1375.          break;
  1376.          case WM_MF_BTT_CONFIG_SLAVE_PARAMETER_FAIL:
  1377.          {
  1378.              st_Log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  1379.                           " FAIL: BT tester < config slave parameter (cal timer)"
  1380.                          );
  1381.          }
  1382.          break;
  1383.          case WM_MF_BTT_CONFIG_DOWNLINK_POWER_FAIL:
  1384.          {
  1385.              st_Log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  1386.                           " FAIL: BT tester < config downlink power (cal timer)"
  1387.                          );
  1388.          }
  1389.          break;
  1390.          case WM_MF_BTT_CONFIG_BD_ADDRESS_FAIL:
  1391.          {
  1392.              st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1393.                           " FAIL: BT tester < config BD address (cal timer)"
  1394.                          );
  1395.          }
  1396.          break;
  1397.          case WM_MF_BTT_CONFIG_INQUIRY_FAIL:
  1398.          {
  1399.              st_Log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  1400.                           " FAIL: BT tester < config inquiry parameter (cal timer)"
  1401.                          );
  1402.          }
  1403.          break;
  1404.          case WM_MF_BTT_CONFIG_SCAN_FAIL:
  1405.          {
  1406.              st_Log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  1407.                           " FAIL: BT tester < config scan parameter (cal timer)"
  1408.                          );
  1409.          }
  1410.          break;
  1411.          case WM_MF_BTT_INQUIRY_FAIL:
  1412.          {
  1413.              st_Log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  1414.                           " FAIL: BT tester < inquiry (cal timer)"
  1415.                          );
  1416.          }
  1417.          break;
  1418.          case WM_MF_BTT_QUERY_STATE_FAIL:
  1419.          {
  1420.              st_Log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  1421.                           " FAIL: BT tester < query state (cal timer)"
  1422.                          );
  1423.          }
  1424.          break;
  1425.          case WM_MF_BTT_CONNECT_TEST_FAIL:
  1426.          {
  1427.              st_Log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  1428.                           " FAIL: BT tester < connect testmode (cal timer)"
  1429.                          );
  1430.          }
  1431.          break;
  1432.          case WM_MF_BTT_RELEASE_FAIL:
  1433.          {
  1434.              st_Log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  1435.                           " FAIL: BT tester < release connection (cal timer)"
  1436.                          );
  1437.          }
  1438.          break;
  1439.          case WM_MF_BTT_CONFIG_MOD_FAIL:
  1440.          {
  1441.              st_Log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  1442.                           " FAIL: BT tester < config modulation (cal timer)"
  1443.                          );
  1444.          }
  1445.          break;
  1446.          case WM_MF_BTT_READ_FREQ_ACCURACY:
  1447.          {
  1448.              st_Log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  1449.                           " FAIL: BT tester > read frequency accuracy (cal timer)"
  1450.                          );
  1451.          }
  1452.          break;
  1453.          // BT
  1454.          case WM_MF_BT_ENABLE_PCM_CLOCK_SYNC_SIGNAL_FAIL:
  1455.          {
  1456.              st_Log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  1457.                           " FAIL: target < enable PCM clock sync. signal (cal timer)"
  1458.                          );
  1459.          }
  1460.          break;
  1461.          case WM_MF_BT_START_CALIBRATE_CRYSTAL_CLOCK_FAIL:
  1462.          {
  1463.              st_Log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  1464.                           " FAIL: target < start calibrate BT crystal clock (cal timer)"
  1465.                          );
  1466.          }
  1467.          break;
  1468.          case WM_MF_BT_READ_CRYSTAL_CLOCK_RESULT_FAIL:
  1469.          {
  1470.              st_Log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  1471.                           " FAIL: target > read BT crystal clock result (cal timer)"
  1472.                          );
  1473.          }
  1474.          break;
  1475.          case WM_MF_BT_SET_CRYSTAL_CAPID_FAIL:
  1476.          {
  1477.              st_Log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  1478.                           " FAIL: target < set BT crystal CAP ID (cal timer)"
  1479.                          );
  1480.          }
  1481.          break;
  1482.          case WM_MF_BT_ENTER_TEST_MODE_FAIL:
  1483.          {
  1484.              st_Log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  1485.                           " FAIL: target < enter BT test mode (cal timer)"
  1486.                          );
  1487.          }
  1488.          break;
  1489.          case WM_MF_BT_INQUIRY_ENABLE_FAIL:
  1490.          {
  1491.              st_Log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  1492.                           " FAIL: target < BT inquiry enable (cal timer)"
  1493.                          );
  1494.          }
  1495.          break;
  1496.          case WM_MF_NVRAM_CV_READ_FAIL:
  1497.          {
  1498.              st_Log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  1499.                          " FAIL: reads CV from NVRAM (cal timer)"
  1500.                          );
  1501.          }
  1502.          break;
  1503.          case WM_MF_NVRAM_CV_WRITE_FAIL:
  1504.          {
  1505.              st_Log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  1506.                           " FAIL: writes CV to NVRAM (cal timer)"
  1507.                          );
  1508.          }
  1509.          break;
  1510.          case WM_MF_NVRAM_REF_TEMP_READ_FAIL:
  1511.          {
  1512.              st_Log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  1513.                          " FAIL: reads ref_temp from NVRAM (cal timer)"
  1514.                          );
  1515.          }
  1516.          break;
  1517.          default:
  1518.          {
  1519.          }
  1520.          break;
  1521.     } // switch
  1522.     PostMessage(
  1523.                           this->Handle,
  1524.                           TimerCalTimeoutID,
  1525.                           0,
  1526.                           0
  1527.                         );
  1528.     on_Calibration_Fail_function();
  1529. }
  1530. //---------------------------------------------------------------------------
  1531. void __fastcall TfrmFatcory::TimerADCCalTimer(TObject *Sender)
  1532. {
  1533.     DisableAllCalTimer();
  1534.     if( pt_calibration != NULL && is_calibration_start )
  1535.     {
  1536.         pt_calibration->OnTerminate = on_Calibration_Fail;
  1537.         pt_calibration->Terminate();
  1538.         is_calibration_start = false;
  1539.         pt_calibration = NULL;
  1540.     }
  1541.     switch(TimerADCCalTimeoutID)
  1542.     {
  1543.         case WM_MF_ADC_MEASURE_FAIL:
  1544.         {
  1545.           st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1546.                         " FAIL: ADC measure (ADC cal timer)"
  1547.                       );
  1548.         }              
  1549.         break;
  1550.         case WM_MF_NVRAM_ADC_WRITE_FAIL:
  1551.         {
  1552.           st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1553.                        " FAIL: write ADC to flash (ADC cal timer)"
  1554.                       );
  1555.         }
  1556.         break;
  1557.         case WM_MF_NVRAM_ADC_READ_FAIL:
  1558.         {
  1559.           st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1560.                        " FAIL: read ADC from flash (ADC cal timer)"
  1561.                  );
  1562.         }
  1563.         break;
  1564.         default:
  1565.         break;
  1566.     }
  1567.     PostMessage(
  1568.                         this->Handle,
  1569.                         TimerADCCalTimeoutID,
  1570.                         0,
  1571.                         0
  1572.                       );
  1573.     on_Calibration_Fail_function();
  1574. }
  1575. //---------------------------------------------------------------------------
  1576. //////////////////////////////////  ADC calibration end ////////////////////////////////////
  1577. void __fastcall TfrmFatcory::edtStartIDCheck(TObject *Sender)
  1578. {
  1579.    int  i;
  1580.    int  data;
  1581.    AnsiString  text;
  1582.    TEdit *edit = (TEdit*)Sender;
  1583.    char  hint[256] =
  1584.    {   " value shall be 0~10000000000 "
  1585.    };
  1586.    text = edit->Text;
  1587.    if( !IsValidFactoryID( text, data ) )
  1588.    {  ShowHintLabel( edit, hint );
  1589.       edit->SetFocus();
  1590.       return;
  1591.    }
  1592.   
  1593. }
  1594. //---------------------------------------------------------------------------
  1595. void  TfrmFatcory::ShowHintLabel( TControl *sender, char* hint )
  1596. {
  1597.    TPoint pt0 = this->ClientOrigin;
  1598.    TPoint pt1 = sender->ClientOrigin;
  1599.    lblHint->Left = (pt1.x-pt0.x);
  1600.    lblHint->Top  = (pt1.y-pt0.y)+sender->Height+3;
  1601.    lblHint->Caption = hint;
  1602.    lblHint->Visible = true;
  1603.    HintTimer->Enabled = true;
  1604. }
  1605. //------------------------------------------------------------------------------------------------
  1606. void __fastcall TfrmFatcory::HintTimerTimer(TObject *Sender)
  1607. {
  1608.   HintTimer->Enabled = false;
  1609.    lblHint->Visible = false;
  1610. }
  1611. //------------------------------------------------------------------------------------------------
  1612. AnsiString TfrmFatcory::read_Barcode(AnsiString asSetupFile, AnsiString asExeName)
  1613. {
  1614.  AnsiString asPath;
  1615.     if ( getPathFromStr(asExeName, asPath) &&
  1616.          withPath( asPath) &&
  1617.          !withPath( asSetupFile)
  1618.        )
  1619.     {
  1620.        asSetupFile = asPath + asSetupFile;
  1621.     }
  1622.     TIniFile *ini;
  1623.    AnsiString as_temp_BARCODE;
  1624.     try
  1625.     {
  1626.        ini = new TIniFile( asSetupFile );
  1627.        if(ini != NULL) // added by Andy Ueng
  1628.        {
  1629.         as_temp_BARCODE  = ini->ReadString("META factory","BARCODE", "0");
  1630.         delete ini;
  1631.         return  as_temp_BARCODE;
  1632.        }
  1633.      // end of added
  1634.        return("0");
  1635.     }
  1636.     catch (...)
  1637.     {
  1638.        //ShowMessage( " META factory : read setup file : " + asSetupFile + " error : barcode ");
  1639.         AnsiString as_warning_msg;
  1640.         as_warning_msg = " META factory : read setup file : " + asSetupFile + " error : barcode ";
  1641.         Application->MessageBox( as_warning_msg.c_str(), "Warning", MB_OK );
  1642.     }
  1643.     return("0");
  1644. }
  1645. //------------------------------------------------------------------------------
  1646. void  __fastcall TfrmFatcory::OpenOffCloseAgilentPowerSupply(void)
  1647. {
  1648.     if( ! m_dcs_ctrl.DCS_Init( &m_Dcs ) )
  1649.     {
  1650.         PostMessage(
  1651.                           this->Handle,
  1652.                           WM_MF_ADC_DCS_INIT_FAIL,
  1653.                           0,
  1654.                           0
  1655.                        );
  1656.         return;
  1657.     }
  1658.     if( ! m_dcs_ctrl.DCS_outputVoltCurr( &m_Dcs, 1.0*i_OFF_VOLTAGE/1000.0, i_CURRENT_LIMIT/1000.0) )
  1659.     {
  1660.         PostMessage(
  1661.                           this->Handle,
  1662.                           WM_MF_ADC_DCS_SET_VOLTAGE_CURRENT_FAIL,
  1663.                           0,
  1664.                           0
  1665.                        );
  1666.         return;
  1667.     }
  1668.     if( ! m_dcs_ctrl.DCS_close( &m_Dcs ) )
  1669.     {
  1670.         PostMessage(
  1671.                           this->Handle,
  1672.                           WM_MF_ADC_DCS_CLOSE_FAIL,
  1673.                           0,
  1674.                           0
  1675.                        );
  1676.         return;
  1677.     }
  1678. #if 0
  1679.     if ( rbAgilent661x->Checked )
  1680.     {
  1681.         if(( hp661x_init(as_Agilent_Power_Supply_GPIB_addr.c_str(), 0, 0, &MF_ADC_ctrl.vi)) != VI_SUCCESS)
  1682.         {
  1683.             PostMessage(
  1684.                           this->Handle,
  1685.                           WM_MF_AGE661x_INIT_FAIL,
  1686.                           0,
  1687.                           0
  1688.                        );
  1689.             return;
  1690.          }
  1691.          if((hp661x_outputVoltCurr(MF_ADC_ctrl.vi, 1.0*i_OFF_VOLTAGE/1000.0, i_CURRENT_LIMIT/1000.0)) != VI_SUCCESS)
  1692.          {
  1693.              PostMessage(
  1694.                            this->Handle,
  1695.                            WM_MF_ADC_SET_VOLTAGE_CURRENT_FAIL,
  1696.                            0,
  1697.                            0
  1698.                         );
  1699.              return;
  1700.          }
  1701.          if(hp661x_close(MF_ADC_ctrl.vi) != VI_SUCCESS)
  1702.          {
  1703.              PostMessage(
  1704.                             this->Handle,
  1705.                             WM_MF_AGE661x_CLOSE_FAIL,
  1706.                             0,
  1707.                             0
  1708.                         );
  1709.              return;
  1710.           }
  1711.      }
  1712.      else if ( rbAgilent663x2->Checked )
  1713.      {
  1714.         if(( hp663x2_init(m_Dcs.ADD, 0, 0, &MF_ADC_ctrl.vi)) != VI_SUCCESS)
  1715.         {
  1716.             PostMessage(
  1717.                           this->Handle,
  1718.                           WM_MF_AGE663x2_INIT_FAIL,
  1719.                           0,
  1720.                           0
  1721.                        );
  1722.             return;
  1723.          }
  1724.          if((hp663x2_outputVoltCurr(MF_ADC_ctrl.vi, 1.0*i_OFF_VOLTAGE/1000.0, i_CURRENT_LIMIT/1000.0)) != VI_SUCCESS)
  1725.          {
  1726.              PostMessage(
  1727.                            this->Handle,
  1728.                            WM_MF_ADC_SET_VOLTAGE_CURRENT_FAIL,
  1729.                            0,
  1730.                            0
  1731.                         );
  1732.              return;
  1733.          }
  1734.          if(hp663x2_close(MF_ADC_ctrl.vi) != VI_SUCCESS)
  1735.          {
  1736.              PostMessage(
  1737.                             this->Handle,
  1738.                             WM_MF_AGE663x2_CLOSE_FAIL,
  1739.                             0,
  1740.                             0
  1741.                         );
  1742.              return;
  1743.           }
  1744.      }
  1745. #endif
  1746. }
  1747. //-------------------------------------------------------------------------
  1748. void __fastcall TfrmFatcory::FormDestroy(TObject *Sender)
  1749. {
  1750.      FormDestroy_function();
  1751. }
  1752. //--------------------------------------------------------------------------
  1753. void __fastcall TfrmFatcory::FormDestroy_function( void )
  1754. {
  1755.     if( cbWiFiTxPower->Checked )
  1756.     {
  1757.             if( ! m_wft_ctrl.WFT_ConClose( &m_Wft )  )
  1758.             {
  1759.                 PostMessage(
  1760.                              this->Handle,
  1761.                              WM_MF_WIFI_CONN_CLOSE_FAIL,
  1762.                              0,
  1763.                              0
  1764.                            );
  1765.                 st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1766.                       " WiFi tester closes connection fail "
  1767.                     );
  1768.             }
  1769.             if( ! m_wft_ctrl.WFT_Terminate( &m_Wft )  )
  1770.             {
  1771.                 PostMessage(
  1772.                               this->Handle,
  1773.                               WM_MF_WIFI_TERMINATE_FAIL,
  1774.                               0,
  1775.                               0
  1776.                            );
  1777.                 st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1778.                       " WiFi tester terminates fail "
  1779.                     );
  1780.             }
  1781.     }
  1782.     
  1783.     TerminateFactoryThread();
  1784.     DeallocateDynamicMemory();
  1785.     if ( cbTerminateMETAExit->Checked || cbTerminateMETASuccess->Checked || cbTerminateMETAFail->Checked)
  1786.     {
  1787.         Application->Terminate();
  1788.     }
  1789. }
  1790. //---------------------------------------------------------------------------
  1791. void TfrmFatcory::DisableAllCalTimer(void)
  1792. {
  1793.     TimerCal->Enabled = false;
  1794.     TimerADCCal->Enabled = false;
  1795. }
  1796. //---------------------------------------------------------------------------
  1797. void __fastcall TfrmFatcory::InitAgilentPowerSupply_SetNormalVoltage_CloseAgilentPowerSupply( void )
  1798. {
  1799.     if( ! m_dcs_ctrl.DCS_Init( &m_Dcs ) )
  1800.     {
  1801.         PostMessage(
  1802.                           this->Handle,
  1803.                           WM_MF_ADC_DCS_INIT_FAIL,
  1804.                           0,
  1805.                           0
  1806.                        );
  1807.         return;
  1808.     }
  1809.     if( ! m_dcs_ctrl.DCS_outputVoltCurr( &m_Dcs, i_NORMAL_VOLTAGE/1000.0, i_CURRENT_LIMIT/1000.0) )
  1810.     {
  1811.         PostMessage(
  1812.                           this->Handle,
  1813.                           WM_MF_ADC_DCS_SET_VOLTAGE_CURRENT_FAIL,
  1814.                           0,
  1815.                           0
  1816.                        );
  1817.         return;
  1818.     }
  1819.     if( ! m_dcs_ctrl.DCS_close( &m_Dcs ) )
  1820.     {
  1821.         PostMessage(
  1822.                           this->Handle,
  1823.                           WM_MF_ADC_DCS_CLOSE_FAIL,
  1824.                           0,
  1825.                           0
  1826.                        );
  1827.         return;
  1828.     }
  1829. #if 0
  1830.     //===========================================================================
  1831.     if (! META_factory_cfg->get_NORMAL_VOLTAGE(i_NORMAL_VOLTAGE) )
  1832.     {
  1833.         PostMessage(
  1834.                     this->Handle,
  1835.                     WM_MF_CFG_READ_FAIL,
  1836.                     0,
  1837.                     0
  1838.                    );
  1839.         st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1840.                   " FAIL: Read config file fail (NORMAL_VOLTAGE)."
  1841.                    );
  1842.         return;
  1843.     }
  1844.     if (! META_factory_cfg->get_CURRENT_LIMIT(i_CURRENT_LIMIT) )
  1845.     {
  1846.         PostMessage(
  1847.                     this->Handle,
  1848.                     WM_MF_CFG_READ_FAIL,
  1849.                     0,
  1850.                     0
  1851.                    );
  1852.         st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1853.                   " FAIL: Read config file fail (CURRENT_LIMIT)."
  1854.                 );
  1855.         return;
  1856.     }
  1857.    // Agilent 661x
  1858.    if ( rbAgilent661x->Checked )
  1859.    {
  1860.    /////////////////////////////////// set power supply output voltage = 3.8V ///////////////////////
  1861.        // Initialize hp661x
  1862.        if(( hp661x_init(m_Dcs.ADD.c_str(), 0, 0, &MF_ADC_ctrl.vi)) != VI_SUCCESS)
  1863.        {
  1864.            Application->MessageBox( "Initial Agilent 661x fail" , "Fail", MB_OK );
  1865.            return;
  1866.        }
  1867.        // set power supply to normal voltage
  1868.    /* Set output voltage and current levels, turn output on*/
  1869.        if((hp661x_outputVoltCurr(MF_ADC_ctrl.vi, 1.0*i_NORMAL_VOLTAGE/1000.0, i_CURRENT_LIMIT/1000.0)) != VI_SUCCESS)
  1870.    {
  1871.             PostMessage(
  1872.                            this->Handle,
  1873.                            WM_MF_ADC_SET_VOLTAGE_CURRENT_FAIL,
  1874.                            0,
  1875.                            0
  1876.                         );
  1877.             st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " FAIL: Agilent 661x set vlotage = " +
  1878.                            Double_To_AnsiString(1.0*i_NORMAL_VOLTAGE/1000.0)
  1879.                        );
  1880.             return;
  1881.        }
  1882.        else
  1883.        {
  1884.             st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " set Agilent 663x2 set vlotage = " +
  1885.                          Double_To_AnsiString(1.0*i_NORMAL_VOLTAGE/1000.0)
  1886.                        );
  1887.        }
  1888.        // close hp661x
  1889.        if(hp661x_close(MF_ADC_ctrl.vi) != VI_SUCCESS)
  1890.        {
  1891.             PostMessage(
  1892.                           this->Handle,
  1893.                           WM_MF_AGE661x_CLOSE_FAIL,
  1894.                           0,
  1895.                           0
  1896.                        );
  1897.             st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " FAIL: Agilent 661x close fail"
  1898.                        );
  1899.             return;
  1900.        }
  1901. }
  1902. else if ( rbAgilent663x2->Checked )
  1903. {
  1904. //====================================================================================================
  1905.     // Agilent 663x2
  1906. /////////////////////////////////// set power supply output voltage = 3.8V ///////////////////////
  1907.    // Initialize hp663x2
  1908.    if(( hp663x2_init(m_Dcs.ADD.c_str(), 0, 0, &MF_ADC_ctrl.vi)) != VI_SUCCESS)
  1909.    {
  1910.         Application->MessageBox( "Initial Agilent 663x2 fail" , "Fail", MB_OK );
  1911.         return;
  1912.    }
  1913.    // set power supply to normal voltage
  1914.    /* Set output voltage and current levels, turn output on*/
  1915.    if((hp663x2_outputVoltCurr(MF_ADC_ctrl.vi, 1.0*i_NORMAL_VOLTAGE/1000.0, i_CURRENT_LIMIT/1000.0)) != VI_SUCCESS)
  1916.    {
  1917.         PostMessage(
  1918.                        this->Handle,
  1919.                        WM_MF_ADC_SET_VOLTAGE_CURRENT_FAIL,
  1920.                        0,
  1921.                        0
  1922.                     );
  1923.         st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " FAIL: Agilent 663x2 set vlotage = " +
  1924.                      Double_To_AnsiString(1.0*i_NORMAL_VOLTAGE/1000.0)
  1925.                    );
  1926.         return;
  1927.    }
  1928.    else
  1929.    {
  1930.         st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " set Agilent 663x2 set vlotage = " +
  1931.                      Double_To_AnsiString(1.0*i_NORMAL_VOLTAGE/1000.0)
  1932.                    );
  1933.    }
  1934.    // close hp663x2
  1935.    if(hp663x2_close(MF_ADC_ctrl.vi) != VI_SUCCESS)
  1936.    {
  1937.         PostMessage(
  1938.                       this->Handle,
  1939.                       WM_MF_AGE663x2_CLOSE_FAIL,
  1940.                       0,
  1941.                       0
  1942.                     );
  1943.         st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " FAIL: Agilent 663x2 close fail"
  1944.                    );
  1945.         return;
  1946.    }
  1947.      }
  1948. #endif
  1949. }
  1950. //---------------------------------------------------------------------------
  1951. void __fastcall TfrmFatcory::SetNormalVoltage_CloseAgilentPowerSupply( void )
  1952. {
  1953.     if( ! m_dcs_ctrl.DCS_outputVoltCurr( &m_Dcs, i_NORMAL_VOLTAGE/1000.0, i_CURRENT_LIMIT/1000.0) )
  1954.     {
  1955.         PostMessage(
  1956.                           this->Handle,
  1957.                           WM_MF_ADC_DCS_SET_VOLTAGE_CURRENT_FAIL,
  1958.                           0,
  1959.                           0
  1960.                        );
  1961.         return;
  1962.     }
  1963.     if( ! m_dcs_ctrl.DCS_close( &m_Dcs ) )
  1964.     {
  1965.         PostMessage(
  1966.                           this->Handle,
  1967.                           WM_MF_ADC_DCS_CLOSE_FAIL,
  1968.                           0,
  1969.                           0
  1970.                        );
  1971.         return;
  1972.     }
  1973. #if 0
  1974.     if (! META_factory_cfg->get_NORMAL_VOLTAGE( i_NORMAL_VOLTAGE))
  1975.     {
  1976.          PostMessage(
  1977.                         this->Handle,
  1978.                         WM_MF_CFG_READ_FAIL,
  1979.                         0,
  1980.                         0
  1981.                     );
  1982.          st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1983.                               " FAIL: Read config file fail (NORMAL_VOLTAGE)."
  1984.                             );
  1985.          return;
  1986.     }
  1987.     if (! META_factory_cfg->get_CURRENT_LIMIT( i_CURRENT_LIMIT))
  1988.     {
  1989.          PostMessage(
  1990.                         this->Handle,
  1991.                         WM_MF_CFG_READ_FAIL,
  1992.                         0,
  1993.                         0
  1994.                     );
  1995.          st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  1996.                               " FAIL: Read config file fail (CURRENT_LIMIT)."
  1997.                             );
  1998.          return;
  1999.     }
  2000.     if ( rbAgilent661x->Checked )
  2001.     {
  2002.         if(IS_AgilentPowerSupply_INITIALISE == true)
  2003.     {
  2004.            // set power supply to normal voltage
  2005.            /* Set output voltage and current levels, turn output on*/
  2006.            if((hp661x_outputVoltCurr(MF_ADC_ctrl.vi, 1.0*i_NORMAL_VOLTAGE/1000.0, 1.0*i_CURRENT_LIMIT/1000.0)) != VI_SUCCESS)
  2007.            {
  2008.                PostMessage(
  2009.                                this->Handle,
  2010.                                WM_MF_ADC_SET_VOLTAGE_CURRENT_FAIL,
  2011.                                0,
  2012.                                0
  2013.                           );
  2014.                st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " FAIL: Agilent 661x set vlotage = " +
  2015.                             Double_To_AnsiString(1.0*i_NORMAL_VOLTAGE/1000.0)
  2016.                           );
  2017.                return;
  2018.            }
  2019.            else
  2020.            {
  2021.                st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " set Agilent 661x set vlotage = " +
  2022.                             Double_To_AnsiString(1.0*i_NORMAL_VOLTAGE/1000.0)
  2023.           );
  2024.            }
  2025.            // close hp661x
  2026.            if(hp661x_close(MF_ADC_ctrl.vi) != VI_SUCCESS)
  2027.            {
  2028.                 PostMessage(
  2029.                                 this->Handle,
  2030.                                 WM_MF_AGE661x_CLOSE_FAIL,
  2031.                                 0,
  2032.                                 0
  2033.                            );
  2034.                 st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  2035.                              " FAIL: Agilent 661x close fail"
  2036.                            );
  2037.                 return;
  2038.            }
  2039.            IS_AgilentPowerSupply_INITIALISE = false;
  2040.          }
  2041. }
  2042.     //================================================================================================
  2043.     // Agilent 663x2
  2044.     else if ( rbAgilent663x2->Checked )
  2045.     {
  2046.          if(IS_AgilentPowerSupply_INITIALISE == true)
  2047.          {
  2048.              // set power supply to normal voltage
  2049.              /* Set output voltage and current levels, turn output on*/
  2050.              if((hp663x2_outputVoltCurr(MF_ADC_ctrl.vi, 1.0*i_NORMAL_VOLTAGE/1000.0, 1.0*i_CURRENT_LIMIT/1000.0)) != VI_SUCCESS)
  2051.              {
  2052.                  PostMessage(
  2053.                                 this->Handle,
  2054.                                 WM_MF_ADC_SET_VOLTAGE_CURRENT_FAIL,
  2055.                                 0,
  2056.                                 0
  2057.                             );
  2058.                  st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " FAIL: Agilent 663x2 set vlotage = " +
  2059.                               Double_To_AnsiString(1.0*i_NORMAL_VOLTAGE/1000.0)
  2060.                             );
  2061.                  return;
  2062.              }
  2063.              else
  2064.              {
  2065.                  st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " set Agilent 663x2 set vlotage = " +
  2066.                               Double_To_AnsiString(1.0*i_NORMAL_VOLTAGE/1000.0)
  2067.                             );
  2068.              }
  2069.              if(hp663x2_close(MF_ADC_ctrl.vi) != VI_SUCCESS)
  2070.              {
  2071.                  PostMessage(
  2072.                                 this->Handle,
  2073.                                 WM_MF_AGE663x2_CLOSE_FAIL,
  2074.                                 0,
  2075.                                 0
  2076.                              );
  2077.                  st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  2078.                               " FAIL: Agilent 663x2 close fail"
  2079.                             );
  2080.                  return;
  2081.              }
  2082.              IS_AgilentPowerSupply_INITIALISE = false;
  2083.          }
  2084.     }
  2085. #endif
  2086. }
  2087. //---------------------------------------------------------------------------
  2088. void __fastcall TfrmFatcory::CloseAgilentPowerSupply( void )
  2089. {
  2090.     if( ! m_dcs_ctrl.DCS_close( &m_Dcs ) )
  2091.     {
  2092.         PostMessage(
  2093.                           this->Handle,
  2094.                           WM_MF_ADC_DCS_CLOSE_FAIL,
  2095.                           0,
  2096.                           0
  2097.                        );
  2098.         return;
  2099.     }
  2100. #if 0
  2101.      //======================================================================
  2102.      // Agilent 661x
  2103.      if( rbAgilent661x->Checked )
  2104.      {
  2105.           if(IS_AgilentPowerSupply_INITIALISE == true)
  2106.           {
  2107.                if(hp661x_close(MF_ADC_ctrl.vi) != VI_SUCCESS)
  2108.                {
  2109.             PostMessage(
  2110.                            this->Handle,
  2111.                                    WM_MF_AGE661x_CLOSE_FAIL,
  2112.                                    0,
  2113.                                    0
  2114.                                );
  2115.                     st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  2116.                                  " FAIL: Agilent 661x close"
  2117.                                );
  2118.                     return;
  2119.                }
  2120.                IS_AgilentPowerSupply_INITIALISE = false;
  2121.           }
  2122.     }
  2123.     //=======================================================================
  2124.     // Agilent 663x2
  2125.     else if( rbAgilent663x2->Checked )
  2126.     {
  2127.         if(IS_AgilentPowerSupply_INITIALISE == true)
  2128.         {
  2129.             if(hp663x2_close(MF_ADC_ctrl.vi) != VI_SUCCESS)
  2130.             {
  2131.                 PostMessage(
  2132.                               this->Handle,
  2133.                               WM_MF_AGE663x2_CLOSE_FAIL,
  2134.                               0,
  2135.                               0
  2136.                            );
  2137.                 st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  2138.                              " FAIL: Agilent 663x2 close"
  2139.                            );
  2140.                 return;
  2141.            }
  2142.            IS_AgilentPowerSupply_INITIALISE = false;
  2143.        }
  2144.    }
  2145. #endif
  2146. }
  2147. //------------------------------------------------------------------------------
  2148. void __fastcall TfrmFatcory::SetOffVoltage_CloseAgilentPowerSupply(void)
  2149. {
  2150.     if( ! m_dcs_ctrl.DCS_outputVoltCurr( &m_Dcs, i_OFF_VOLTAGE/1000.0, i_CURRENT_LIMIT/1000.0) )
  2151.     {
  2152.         PostMessage(
  2153.                           this->Handle,
  2154.                           WM_MF_ADC_DCS_SET_VOLTAGE_CURRENT_FAIL,
  2155.                           0,
  2156.                           0
  2157.                        );
  2158.         return;
  2159.     }
  2160.     if( ! m_dcs_ctrl.DCS_close( &m_Dcs ) )
  2161.     {
  2162.         PostMessage(
  2163.                           this->Handle,
  2164.                           WM_MF_ADC_DCS_CLOSE_FAIL,
  2165.                           0,
  2166.                           0
  2167.                        );
  2168.         return;
  2169.     }
  2170. #if 0
  2171.       if( IS_AgilentPowerSupply_INITIALISE == true )
  2172.       {
  2173.           if ( rbAgilent661x->Checked )
  2174.           {
  2175.               /* Set output voltage and current levels, turn output off */
  2176.               if((hp661x_outputVoltCurr(MF_ADC_ctrl.vi, 1.0*i_OFF_VOLTAGE/1000.0, i_CURRENT_LIMIT/1000.0)) != VI_SUCCESS)
  2177.               {
  2178.                   PostMessage(
  2179.                                 this->Handle,
  2180.                                 WM_MF_ADC_SET_VOLTAGE_CURRENT_FAIL,
  2181.                                 0,
  2182.                                 0
  2183.                              );
  2184.                   st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " FAIL: Agilent 661x set vlotage = " +
  2185.                                Double_To_AnsiString(1.0*i_OFF_VOLTAGE/1000.0)
  2186.                              );
  2187.                  return;
  2188.               }
  2189.               else
  2190.               {
  2191.                  st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " set Agilent 661x set vlotage = " +
  2192.                               Double_To_AnsiString(1.0*i_OFF_VOLTAGE/1000.0)  + "n"
  2193.                             );
  2194.               }
  2195.               // Close hp663x2
  2196.               if(hp661x_close(MF_ADC_ctrl.vi) != VI_SUCCESS)
  2197.               {
  2198.                   PostMessage(
  2199.                                 this->Handle,
  2200.                                 WM_MF_AGE661x_CLOSE_FAIL,
  2201.                                 0,
  2202.                                 0
  2203.                              );
  2204.                   st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " FAIL: Agilent 661x close fail"
  2205.                              );
  2206.                   return;
  2207.               }
  2208.               IS_AgilentPowerSupply_INITIALISE = false;
  2209.            }
  2210.            else if ( rbAgilent663x2->Checked )
  2211.            {
  2212.                /* Set output voltage and current levels, turn output off */
  2213.               if((hp663x2_outputVoltCurr(MF_ADC_ctrl.vi, 1.0*i_OFF_VOLTAGE/1000.0, i_CURRENT_LIMIT/1000.0)) != VI_SUCCESS)
  2214.               {
  2215.                   PostMessage(
  2216.                                 this->Handle,
  2217.                                 WM_MF_ADC_SET_VOLTAGE_CURRENT_FAIL,
  2218.                                 0,
  2219.                                 0
  2220.                              );
  2221.                   st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " FAIL: Agilent 663x2 set vlotage = " +
  2222.                                Double_To_AnsiString(1.0*i_OFF_VOLTAGE/1000.0)
  2223.                              );
  2224.                  return;
  2225.               }
  2226.               else
  2227.               {
  2228.                  st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " set Agilent 663x2 set vlotage = " +
  2229.                               Double_To_AnsiString(1.0*i_OFF_VOLTAGE/1000.0)
  2230.                             );
  2231.               }
  2232.               // Close hp663x2
  2233.               if(hp663x2_close(MF_ADC_ctrl.vi) != VI_SUCCESS)
  2234.               {
  2235.                   PostMessage(
  2236.                                 this->Handle,
  2237.                                 WM_MF_AGE663x2_CLOSE_FAIL,
  2238.                                 0,
  2239.                                 0
  2240.                              );
  2241.                   st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() + " FAIL: Agilent 663x2 close fail"
  2242.                              );
  2243.                   return;
  2244.               }
  2245.               IS_AgilentPowerSupply_INITIALISE = false;
  2246.            }
  2247.      }
  2248. #endif
  2249. }
  2250. //---------------------------------------------------------------------------
  2251. void __fastcall TfrmFatcory::RCT_Dcl_Reset_Close( void )
  2252. {
  2253.      if(  ( m_Rct.age.vi      != NULL && rbAgilent8960->Checked ) ||
  2254.           ( m_Rct.cmu.base    != NULL && rbCMU200->Checked )
  2255.        )
  2256.      {
  2257.          if( ! m_rct_ctrl.RCT_dcl( &m_Rct ) )
  2258.          {
  2259.              PostMessage(
  2260.                           this->Handle,
  2261.                           WM_MF_AGE8960_DCL_FAIL,
  2262.                           0,
  2263.                           0
  2264.                       );
  2265.              st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  2266.                        " FAIL: Agilent 8960 DCL"
  2267.                      );
  2268.              return;
  2269.         }
  2270.         Sleep(50);
  2271.         if( ! m_rct_ctrl.RCT_reset( &m_Rct ) )
  2272.         {
  2273.             PostMessage(
  2274.                          this->Handle,
  2275.                          WM_MF_AGE8960_RESET_FAIL,
  2276.                          0,
  2277.                          0
  2278.                      );
  2279.             st_Log->Add( DateToStr(Date()) +  " " + CurrentTimeStr() +
  2280.                   " FAIL: Agilent 8960 reset");
  2281.             return;
  2282.         }
  2283.         Sleep(50);
  2284.         AnsiString asFreqBand;
  2285.         META_factory_cfg->getFreqBank(asFreqBand);
  2286.         if (rbCrystal->Checked && m_Cal.s_CalItem.b_trx_offset_cal)
  2287.         {
  2288.             if (!m_rct_ctrl.RCT_sig_close(&m_Rct, asFreqBand))
  2289.             {
  2290.                 PostMessage(
  2291.                             this->Handle,
  2292.                             WM_MF_AGE8960_CLOSE_FAIL,
  2293.                             0,
  2294.                             0
  2295.                            );
  2296.                 st_Log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  2297.                             " FAIL: " + m_Rct.as_RCT + " signalling close"
  2298.                          );
  2299.                 return;
  2300.             }
  2301.        }
  2302.        if (cbIP2->Checked        ||
  2303.            cbAFC->Checked        ||
  2304.            cbRxPathLoss->Checked ||
  2305.            cbTxIq->Checked       ||
  2306.            cbTxPcl->Checked
  2307.           )
  2308.        {
  2309.         if (!m_rct_ctrl.RCT_close(&m_Rct, asFreqBand))
  2310.            {
  2311.                 PostMessage(
  2312.                             this->Handle,
  2313.                             WM_MF_AGE8960_CLOSE_FAIL,
  2314.                             0,
  2315.                             0
  2316.                            );
  2317.                 st_Log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  2318.                             " FAIL: " + m_Rct.as_RCT + " close");
  2319.                 return;
  2320.             }
  2321.         }
  2322.         if (!m_rct_ctrl.RCT_close_RM(&m_Rct))
  2323.         {
  2324.             PostMessage(this->Handle,
  2325.                         WM_MF_AGE8960_CLOSE_FAIL,
  2326.                         0,
  2327.                         0
  2328.                         );
  2329.             st_Log->Add(DateToStr(Date()) +  " " + CurrentTimeStr() +
  2330.                             " FAIL: " + m_Rct.as_RCT + " close handle manager");
  2331.             return;
  2332.         }
  2333.     }
  2334. }
  2335. //====================================================================================
  2336. void TfrmFatcory::DisplayAFCType(void)
  2337. {
  2338.     AnsiString as_AFC_Type = read_AFC_Type("MF_setup.txt", Application->ExeName);
  2339.     if(as_AFC_Type.AnsiCompareIC("crystal") == 0)
  2340.      {
  2341.          rbCrystal->Checked = true;
  2342.      }
  2343.      else
  2344.      {
  2345.          rbTCVCXO->Checked = true;
  2346.      }
  2347.      if ((RF_ID_A60111A == m_Cal.ui_rf_id) ||
  2348.          (RF_ID_AD6548  == m_Cal.ui_rf_id) ||
  2349.          (RF_ID_AERO2   == m_Cal.ui_rf_id) ||
  2350.          (RF_ID_AERO2E  == m_Cal.ui_rf_id) ||
  2351.          (RF_ID_AG2550  == m_Cal.ui_rf_id) ||
  2352.          (RF_ID_MT6139B == m_Cal.ui_rf_id) ||
  2353.          (RF_ID_MT6139C == m_Cal.ui_rf_id) ||
  2354.          (RF_ID_MT6139E == m_Cal.ui_rf_id) ||
  2355.          (RF_ID_MT6140A == m_Cal.ui_rf_id) ||
  2356.          (RF_ID_MT6140B == m_Cal.ui_rf_id) ||
  2357.          (RF_ID_MT6140C == m_Cal.ui_rf_id) ||
  2358.          (RF_ID_MT6140D == m_Cal.ui_rf_id)
  2359.         )
  2360.      {
  2361.          rbCrystal->Checked = true;
  2362.      }
  2363.      else if ((RF_ID_MT6119  == m_Cal.ui_rf_id) ||
  2364.               (RF_ID_MT6119C == m_Cal.ui_rf_id) ||
  2365.               (RF_ID_MT6129A == m_Cal.ui_rf_id) ||
  2366.               (RF_ID_MT6129B == m_Cal.ui_rf_id) ||
  2367.               (RF_ID_MT6129C == m_Cal.ui_rf_id) ||
  2368.               (RF_ID_MT6129D == m_Cal.ui_rf_id)
  2369.              ) 
  2370.      {
  2371.          rbTCVCXO->Checked = true;
  2372.      }
  2373. }
  2374. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2375. void TfrmFatcory::SaveAFCType(void)
  2376. {
  2377.      if (rbCrystal->Checked)
  2378.      {
  2379.           write_AFC_Type( "MF_setup.txt", Application->ExeName, "Crystal" );
  2380.      }
  2381.      else
  2382.      {
  2383.           write_AFC_Type( "MF_setup.txt", Application->ExeName, "TCVCXO" );
  2384.      }
  2385. }
  2386. //====================================================================================
  2387. void TfrmFatcory::DisplayCrystalCapId(void)
  2388. {
  2389.     as_Crystal_Cap_Id = read_Crystal_CAP_ID("MF_setup.txt", Application->ExeName);
  2390.     if (as_Crystal_Cap_Id.AnsiCompareIC("run time update") == 0)
  2391.     {
  2392.         rbRunTimeUpdate->Checked = true;
  2393.     }
  2394.     else
  2395.     {
  2396.         rbWriteNVRAM->Checked = true;
  2397.         as_Crystal_Cap_Id = (AnsiString) "write NVRAM";
  2398.     }
  2399. }
  2400. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2401. void TfrmFatcory::SaveCrystalCapId(void)
  2402. {
  2403.      if (rbRunTimeUpdate->Checked)
  2404.      {
  2405.           write_Crystal_CAP_ID("MF_setup.txt", Application->ExeName, "run time update");
  2406.      }
  2407.      else
  2408.      {
  2409.           write_Crystal_CAP_ID("MF_setup.txt", Application->ExeName, "write NVRAM");
  2410.      }
  2411. }
  2412. //====================================================================================
  2413. void TfrmFatcory::DisplayTxAfcOffsetCal(void)
  2414. {
  2415.     AnsiString as_TxAfcOffsetCal = read_TxAfcOffsetCal("MF_setup.txt", Application->ExeName);
  2416.     if (as_TxAfcOffsetCal.AnsiCompareIC("yes") == 0)
  2417.     {
  2418.         m_cbTrxOffset->Checked = true;
  2419.     }
  2420.     else
  2421.     {
  2422.         m_cbTrxOffset->Checked = false;
  2423.     }
  2424.     if ((RF_ID_A60111A == m_Cal.ui_rf_id) ||
  2425.         (RF_ID_AG2550  == m_Cal.ui_rf_id) ||
  2426.         (RF_ID_MT6139B == m_Cal.ui_rf_id) ||
  2427.         (RF_ID_MT6139C == m_Cal.ui_rf_id) ||
  2428.         (RF_ID_MT6139E == m_Cal.ui_rf_id) ||
  2429.         (RF_ID_MT6140A == m_Cal.ui_rf_id) ||
  2430.         (RF_ID_MT6140B == m_Cal.ui_rf_id) ||
  2431.         (RF_ID_MT6140C == m_Cal.ui_rf_id) ||
  2432.         (RF_ID_MT6140D == m_Cal.ui_rf_id)
  2433.         )
  2434.      {
  2435.          m_cbTrxOffset->Checked = true;
  2436.      }
  2437.      else if (RF_ID_AERO2 == m_Cal.ui_rf_id)
  2438.      {
  2439.          m_cbTrxOffset->Checked = false;
  2440.      }
  2441. }
  2442. //---------------------------------------------------------------------------
  2443. void TfrmFatcory::SaveTxAfcOffsetCal( void )
  2444. {
  2445.      if ( m_cbTrxOffset->Checked )
  2446.      {
  2447.           write_TxAfcOffsetCal( "MF_setup.txt", Application->ExeName, "yes" );
  2448.      }
  2449.      else
  2450.      {
  2451.           write_TxAfcOffsetCal( "MF_setup.txt", Application->ExeName, "no" );
  2452.      }
  2453. }
  2454. //=============================================================================
  2455. void TfrmFatcory::DisplayResetRfTester( void )
  2456. {
  2457.     AnsiString as_ResetRfTester = read_ResetRfTester("MF_setup.txt", Application->ExeName);
  2458.     if(as_ResetRfTester.AnsiCompareIC("yes") == 0)
  2459.     {
  2460.         cbResetRfTester->Checked = true;
  2461.     }
  2462.     else
  2463.     {
  2464.         cbResetRfTester->Checked = false;
  2465.     }
  2466. }
  2467. //---------------------------------------------------------------------------
  2468. void TfrmFatcory::SaveResetRfTester( void )
  2469. {
  2470.      if ( cbResetRfTester->Checked )
  2471.      {
  2472.           write_ResetRfTester( "MF_setup.txt", Application->ExeName, "yes" );
  2473.      }
  2474.      else
  2475.      {
  2476.           write_ResetRfTester( "MF_setup.txt", Application->ExeName, "no" );
  2477.      }
  2478. }
  2479. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2480. void TfrmFatcory::DisplayAFCCal( void )
  2481. {
  2482.     AnsiString as_AFC = read_AFC("MF_setup.txt", Application->ExeName);
  2483.     if(as_AFC.AnsiCompareIC("yes") == 0)
  2484.     {
  2485.         cbAFC->Checked = true;
  2486.     }
  2487.     else
  2488.     {
  2489.         cbAFC->Checked = false;
  2490.     }
  2491. }
  2492. //---------------------------------------------------------------------------
  2493. void TfrmFatcory::SaveAFCCal(void)
  2494. {
  2495.      if ( cbAFC->Checked )
  2496.      {
  2497.           write_AFC("MF_setup.txt", Application->ExeName, "yes");
  2498.      }
  2499.      else
  2500.      {
  2501.           write_AFC("MF_setup.txt", Application->ExeName, "no");
  2502.      }
  2503. }
  2504. //====================================================================================
  2505. void TfrmFatcory::DisplayRxPathLossCal(void)
  2506. {
  2507.     AnsiString as_RxPathLoss = read_RxPathLoss("MF_setup.txt", Application->ExeName);
  2508.     if(as_RxPathLoss.AnsiCompareIC("yes") == 0)
  2509.     {
  2510.         cbRxPathLoss->Checked = true;
  2511.     }
  2512.     else
  2513.     {
  2514.         cbRxPathLoss->Checked = false;
  2515.     }
  2516. }
  2517. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2518. void TfrmFatcory::SaveRxPathLossCal(void)
  2519. {
  2520.     if (cbRxPathLoss->Checked)
  2521.     {
  2522.         write_RxPathLoss("MF_setup.txt", Application->ExeName, "yes");
  2523.     }
  2524.     else
  2525.     {
  2526.         write_RxPathLoss("MF_setup.txt", Application->ExeName, "no");
  2527.     }
  2528. }
  2529. //============================================================================
  2530. void TfrmFatcory::DisplayTxIqCal( void )
  2531. {
  2532.     AnsiString as_TxIqCal = read_TxIqCal("MF_setup.txt", Application->ExeName);
  2533.     if(as_TxIqCal.AnsiCompareIC("yes") == 0)
  2534.     {
  2535.         cbTxIq->Checked = true;
  2536.     }
  2537.     else
  2538.     {
  2539.         cbTxIq->Checked = false;
  2540.     }
  2541.     if ((RF_ID_A60111A == m_Cal.ui_rf_id) ||
  2542.         (RF_ID_AERO2E  == m_Cal.ui_rf_id) ||
  2543.         (RF_ID_MT6139B == m_Cal.ui_rf_id) ||
  2544.         (RF_ID_MT6139C == m_Cal.ui_rf_id) ||
  2545.         (RF_ID_MT6139E == m_Cal.ui_rf_id) ||
  2546.         (RF_ID_MT6140A == m_Cal.ui_rf_id) ||
  2547.         (RF_ID_MT6140B == m_Cal.ui_rf_id) ||
  2548.         (RF_ID_MT6140C == m_Cal.ui_rf_id) ||
  2549.         (RF_ID_MT6140D == m_Cal.ui_rf_id)
  2550.         )
  2551.      {
  2552.          cbTxIq->Checked = true;
  2553.      }
  2554. }
  2555. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2556. void TfrmFatcory::SaveTxIqCal( void )
  2557. {
  2558.      if ( cbTxIq->Checked )
  2559.      {
  2560.           write_TxIqCal( "MF_setup.txt", Application->ExeName, "yes" );
  2561.      }
  2562.      else
  2563.      {
  2564.           write_TxIqCal( "MF_setup.txt", Application->ExeName, "no" );
  2565.      }
  2566. }
  2567. //====================================================================================
  2568. void TfrmFatcory::DisplayIP2Cal( void )
  2569. {
  2570.     AnsiString as_IP2 = read_IP2("MF_setup.txt", Application->ExeName);
  2571.     if( as_IP2.AnsiCompareIC("yes") == 0 && cbIP2->Visible )
  2572.     {
  2573.         cbIP2->Checked = true;
  2574.     }
  2575.     else
  2576.     {
  2577.         cbIP2->Checked = false;
  2578.     }
  2579. }
  2580. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2581. void TfrmFatcory::DisplayIP2Visible(unsigned int ui_rf_id)
  2582. {
  2583.     switch (ui_rf_id)
  2584.     {
  2585.         case RF_ID_SKY74045:
  2586.         case RF_ID_SKY74117:
  2587.         case RF_ID_SKY74400:
  2588. //        case RF_ID_MT6139B:
  2589. //        case RF_ID_MT6139C:
  2590. //        case RF_ID_MT6139E:
  2591. //        case RF_ID_MT6140A:
  2592. //        case RF_ID_MT6140B:
  2593.         {
  2594.              cbIP2->Visible = true;
  2595.         }
  2596.         break;
  2597.         default:
  2598.         {
  2599.             cbIP2->Visible = false;
  2600.             cbIP2->Enabled = false;
  2601.             cbIP2->Checked = false;
  2602.         }
  2603.         break;
  2604.     }
  2605. }
  2606. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2607. void TfrmFatcory::SaveIP2Cal(void)
  2608. {
  2609.     if (cbIP2->Checked)
  2610.     {
  2611.         write_IP2("MF_setup.txt", Application->ExeName, "yes");
  2612.     }
  2613.     else
  2614.     {
  2615.         write_IP2("MF_setup.txt", Application->ExeName, "no");
  2616.     }
  2617. }
  2618. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2619. void TfrmFatcory::DisplayTxPclCal(void)
  2620. {
  2621.     AnsiString as_TxPcl = read_TxPcl("MF_setup.txt", Application->ExeName);
  2622.     if(as_TxPcl.AnsiCompareIC("yes") == 0)
  2623.     {
  2624.         cbTxPcl->Checked = true;
  2625.     }
  2626.     else
  2627.     {
  2628.         cbTxPcl->Checked = false;
  2629.     }
  2630. }
  2631. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2632. void TfrmFatcory::SaveTxPclCal(void)
  2633. {
  2634.     if (cbTxPcl->Checked)
  2635.     {
  2636.         write_TxPcl("MF_setup.txt", Application->ExeName, "yes");
  2637.     }
  2638.     else
  2639.     {
  2640.         write_TxPcl("MF_setup.txt", Application->ExeName, "no");
  2641.     }
  2642. }
  2643. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2644. void TfrmFatcory::DisplayADCCal( void )
  2645. {
  2646.     AnsiString  as_ADC_calibration = read_ADC_calibration("MF_setup.txt", Application->ExeName);
  2647.     if(as_ADC_calibration.AnsiCompareIC("yes") == 0)
  2648.     {
  2649.         cbADC->Checked = true;
  2650.     }
  2651.     else
  2652.     {
  2653.         cbADC->Checked = false;
  2654.     }