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

MTK

开发平台:

C++ Builder

  1. /*****************************************************************************
  2. *  Copyright Statement:
  3. *  --------------------
  4. *  This software is protected by Copyright and the information contained
  5. *  herein is confidential. The software may not be copied and the information
  6. *  contained herein may not be used or disclosed except with the written
  7. *  permission of MediaTek Inc. (C) 2005
  8. *
  9. *  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  10. *  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
  11. *  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
  12. *  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
  13. *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
  14. *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
  15. *  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
  16. *  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
  17. *  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
  18. *  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
  19. *  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
  20. *  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
  21. *
  22. *  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
  23. *  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
  24. *  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
  25. *  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
  26. *  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
  27. *
  28. *  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
  29. *  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
  30. *  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
  31. *  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
  32. *  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
  33. *
  34. *****************************************************************************/
  35. /*****************************************************************************
  36.  *
  37.  * Filename:
  38.  * ---------
  39.  *   form_RFGUIApcProfile.cpp
  40.  *
  41.  * Project:
  42.  * --------
  43.  *   Maui META APP
  44.  *
  45.  * Description:
  46.  * ------------
  47.  *   RF graphic interface APC profile form source
  48.  *
  49.  * Author:
  50.  * -------
  51.  *  Andy Ueng (mtk00490)
  52.  *
  53.  *============================================================================
  54.  *             HISTORY
  55.  * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  56.  *------------------------------------------------------------------------------
  57.  * $Revision:   1.2  $
  58.  * $Modtime:   Sep 11 2004 14:13:48  $
  59.  * $Log:   //mtkvs01/vmdata/meta_app/archives/MauiMETA/Form/form_RFGUIApcProfile.cpp-arc  $
  60.  * 
  61.  *    Rev 1.2   Sep 11 2004 15:15:28   mtk00490
  62.  * Maui META ver 3.5.05
  63.  * 
  64.  *    Rev 1.1   Jun 24 2004 11:49:40   mtk00490
  65.  * Maui META ver 3.5.04
  66.  * 
  67.  *------------------------------------------------------------------------------
  68.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  69.  *============================================================================
  70.  ****************************************************************************/
  71. //---------------------------------------------------------------------------
  72. #include <vcl.h>
  73. #pragma hdrstop
  74. #include "man_fdm.h"
  75. // form
  76. #include "form_main.h"
  77. #include "form_RFGUIApcProfile.h"
  78. #include "form_RFApcProfile.h"
  79. // message
  80. #ifndef _META_LAB_MSG_H_
  81. #include "meta_lab_msg.h"
  82. #endif
  83. // thread
  84. #ifndef  _RF_TADO_THRD_H_
  85. #include "rf_tado_thrd.h"
  86. #endif
  87. #ifndef  _RF_SETRAMP_THRD_H_
  88. #include "rf_setramp_thrd.h"
  89. #endif
  90. //---------------------------------------------------------------------------
  91. #pragma package(smart_init)
  92. #pragma resource "*.dfm"
  93. TfrmGUIApcProfile *frmGUIApcProfile;
  94. HANDLE p_TxStop_Event;
  95. // query
  96. extern T_RFTADO*      pt_rftado;
  97. extern T_RFSETRAMP*      pt_rfsetramp;
  98. //==============================================================================
  99. static void CNF_NVRAM_Init(void)
  100. {
  101.     frmGUIApcProfile->CNF_NVRAM_Init();
  102. }
  103. //---------------------------------------------------------------------------
  104. static void CNF_ReadFromNVRAM(void)
  105. {
  106.     frmGUIApcProfile->CNF_ReadFromNVRAM();
  107. }
  108. //---------------------------------------------------------------------------
  109. static void CNF_WriteToNVRAM(void)
  110. {
  111.     frmGUIApcProfile->DownloadToFlashDone();
  112. }
  113. //---------------------------------------------------------------------------
  114. static void  ConfirmCallback_RfSetRampTable( void )
  115. {
  116.     frmGUIApcProfile->ConfirmCallback_RfSetRampTable();
  117. }
  118. //---------------------------------------------------------------------------
  119. static void ConfirmCallback_TX(void)
  120. {
  121.     frmGUIApcProfile->ConfirmCallback_TX();
  122. }
  123. //===========================================================================
  124. void TfrmGUIApcProfile::Init( void )
  125. {
  126.     m_bInit = true;
  127.     m_bTADOSupport = false;
  128.     CurrentPageReset();
  129. }
  130. //---------------------------------------------------------------------------
  131. void __fastcall TfrmGUIApcProfile::FormCreate(TObject *Sender)
  132. {
  133.     m_uiFinalRFID = 0;
  134.     WindowProc = SubClassWndProc;
  135.     Init();
  136. }
  137. //---------------------------------------------------------------------------
  138. void __fastcall TfrmGUIApcProfile::FormActivate(TObject *Sender)
  139. {
  140.     if (m_bInit)
  141.     {
  142.         m_bInit = false;
  143.         imRampProfile->Enabled = true;
  144.         m_bMultiSlotTxExSupport = frmRFTool->Get_MultiSlotTxExSupport();
  145.     }
  146.     AnsiString  text;
  147.     Tsc = frmRFTool->cbxTXTsc->ItemIndex;
  148.     text = frmRFTool->edtTXAfc->Text;   if( !IsValidAFC( text, m_sAfcDac ) )   {  m_sAfcDac = 4100;   }
  149.     m_eBurstType = frmRFTool->Get_GmskBurstType();
  150. }
  151. //===========================================================================
  152. void TfrmGUIApcProfile::ConfirmCallback_TX(void)
  153. {
  154.     E_METAAPP_RESULT_T state = RF_TX_Obj->Get_ConfirmState();
  155.     if (m_bDragTrigger)
  156.     {
  157.         imRampProfile->Enabled = true;
  158.         m_bDragTrigger = false;
  159.     }
  160.     switch (state)
  161.     {
  162.         case METAAPP_SUCCESS:
  163.         {
  164.             sbGUIAPCProfile->Panels->Items[0]->Text = (AnsiString)"  Burst TX progressing";
  165.         }
  166.         break;
  167.         case METAAPP_FAIL:
  168.         {
  169.             sbGUIAPCProfile->Panels->Items[0]->Text = (AnsiString)"  Burst TX fail";
  170.             Application->MessageBox("Execution failure : Burst TX", "FAILURE", MB_OK);
  171.         }
  172.         break;
  173.         case METAAPP_TIMEOUT:
  174.         {
  175.             sbGUIAPCProfile->Panels->Items[0]->Text = (AnsiString)"  Burst TX timeout";
  176.             Application->MessageBox("Execution Timeout : Burst TX", "TIMEOUT", MB_OK);
  177.         }
  178.         break;
  179.         case METAAPP_STOP:
  180.         {
  181.             sbGUIAPCProfile->Panels->Items[0]->Text = (AnsiString)"  Burst TX stop";
  182.         }
  183.         break;
  184.     }    
  185. }
  186. //==============================================================================
  187. __fastcall TfrmGUIApcProfile::TfrmGUIApcProfile(TComponent* Owner)
  188.         : TForm(Owner)
  189. {
  190.     // initialization
  191.     isRampUpCircleOnDrag = false;
  192.     isRampDownCircleOnDrag = false;
  193.     m_bDragTrigger = false;
  194.     Tsc       = 5;
  195.     m_sAfcDac    = 4100;
  196.     m_eBurstType = NB_TX_RANDOM_WITH_TSC;   // NB
  197.     m_eCurBand     = (E_BANDSEL) BANDSEL_GSM900;
  198.     m_sCurPCLIndex = 0;
  199.     for(int band=0; band<MAX_SUPPORT_BAND_NUM; band++)
  200.     {
  201.         m_usHighApcDcOffset[band] = 0;
  202.         m_usLowApcDcOffset[band]  = 0;
  203.     }    
  204.     m_sTestArfcn[BANDSEL_GSM900 ] = 0;
  205.     m_sTestArfcn[BANDSEL_DCS1800] = 512;
  206.     m_sTestArfcn[BANDSEL_PCS1900] = 512;
  207.     m_sTestArfcn[BANDSEL_GSM850] = 128;
  208.     lastTabIndex = 0; // GSM 900
  209.     edtPCLDAC[ 0]=edtPCLDAC00;   btnPCL[ 0]=btnPCL00;   edtRampUp[ 0]=edtRampUp00;   edtRampDn[ 0]=edtRampDn00;
  210.         edtPCLDAC[ 1]=edtPCLDAC01;   btnPCL[ 1]=btnPCL01;   edtRampUp[ 1]=edtRampUp01;   edtRampDn[ 1]=edtRampDn01;
  211.         edtPCLDAC[ 2]=edtPCLDAC02;   btnPCL[ 2]=btnPCL02;   edtRampUp[ 2]=edtRampUp02;   edtRampDn[ 2]=edtRampDn02;
  212.         edtPCLDAC[ 3]=edtPCLDAC03;   btnPCL[ 3]=btnPCL03;   edtRampUp[ 3]=edtRampUp03;   edtRampDn[ 3]=edtRampDn03;
  213.         edtPCLDAC[ 4]=edtPCLDAC04;   btnPCL[ 4]=btnPCL04;   edtRampUp[ 4]=edtRampUp04;   edtRampDn[ 4]=edtRampDn04;
  214.         edtPCLDAC[ 5]=edtPCLDAC05;   btnPCL[ 5]=btnPCL05;   edtRampUp[ 5]=edtRampUp05;   edtRampDn[ 5]=edtRampDn05;
  215.         edtPCLDAC[ 6]=edtPCLDAC06;   btnPCL[ 6]=btnPCL06;   edtRampUp[ 6]=edtRampUp06;   edtRampDn[ 6]=edtRampDn06;
  216.         edtPCLDAC[ 7]=edtPCLDAC07;   btnPCL[ 7]=btnPCL07;   edtRampUp[ 7]=edtRampUp07;   edtRampDn[ 7]=edtRampDn07;
  217.         edtPCLDAC[ 8]=edtPCLDAC08;   btnPCL[ 8]=btnPCL08;   edtRampUp[ 8]=edtRampUp08;   edtRampDn[ 8]=edtRampDn08;
  218.         edtPCLDAC[ 9]=edtPCLDAC09;   btnPCL[ 9]=btnPCL09;   edtRampUp[ 9]=edtRampUp09;   edtRampDn[ 9]=edtRampDn09;
  219.         edtPCLDAC[10]=edtPCLDAC10;   btnPCL[10]=btnPCL10;   edtRampUp[10]=edtRampUp10;   edtRampDn[10]=edtRampDn10;   
  220.         edtPCLDAC[11]=edtPCLDAC11;   btnPCL[11]=btnPCL11;   edtRampUp[11]=edtRampUp11;   edtRampDn[11]=edtRampDn11;
  221.         edtPCLDAC[12]=edtPCLDAC12;   btnPCL[12]=btnPCL12;   edtRampUp[12]=edtRampUp12;   edtRampDn[12]=edtRampDn12;
  222.         edtPCLDAC[13]=edtPCLDAC13;   btnPCL[13]=btnPCL13;   edtRampUp[13]=edtRampUp13;   edtRampDn[13]=edtRampDn13;
  223.         edtPCLDAC[14]=edtPCLDAC14;   btnPCL[14]=btnPCL14;   edtRampUp[14]=edtRampUp14;   edtRampDn[14]=edtRampDn14;
  224.         edtPCLDAC[15]=edtPCLDAC15;   btnPCL[15]=btnPCL15;   edtRampUp[15]=edtRampUp15;   edtRampDn[15]=edtRampDn15;
  225.         lblVertical[0] = lblVertical0;
  226.         lblVertical[1] = lblVertical1;
  227.         lblVertical[2] = lblVertical2;
  228.         lblVertical[3] = lblVertical3;
  229.         lblVertical[4] = lblVertical4;
  230.         lblVertical[5] = lblVertical5;
  231.         lblVertical[6] = lblVertical6;
  232.         lblVertical[7] = lblVertical7;
  233.         lblVertical[8] = lblVertical8;
  234.         lblVertical[9] = lblVertical9;
  235.         lblRampUpH[0] = lblRampUpH0;  lblRampDownH[0] = lblRampDownH0;
  236.         lblRampUpH[1] = lblRampUpH1;  lblRampDownH[1] = lblRampDownH1;
  237.         lblRampUpH[2] = lblRampUpH2;  lblRampDownH[2] = lblRampDownH2;
  238.         lblRampUpH[3] = lblRampUpH3;  lblRampDownH[3] = lblRampDownH3;
  239.         lblRampUpH[4] = lblRampUpH4;  lblRampDownH[4] = lblRampDownH4;
  240.         lblRampUpH[5] = lblRampUpH5;  lblRampDownH[5] = lblRampDownH5;
  241.         lblRampUpH[6] = lblRampUpH6;  lblRampDownH[6] = lblRampDownH6;
  242.         lblRampUpH[7] = lblRampUpH7;  lblRampDownH[7] = lblRampDownH7;
  243.         lblRampUpH[8] = lblRampUpH8;  lblRampDownH[8] = lblRampDownH8;
  244.         lblRampUpH[9] = lblRampUpH9;  lblRampDownH[9] = lblRampDownH9;
  245.         lblRampUpH[10] = lblRampUpH10;  lblRampDownH[10] = lblRampDownH10;
  246.         lblRampUpH[11] = lblRampUpH11;  lblRampDownH[11] = lblRampDownH11;
  247.         lblRampUpH[12] = lblRampUpH12;  lblRampDownH[12] = lblRampDownH12;
  248.         lblRampUpH[13] = lblRampUpH13;  lblRampDownH[13] = lblRampDownH13;
  249.         lblRampUpH[14] = lblRampUpH14;  lblRampDownH[14] = lblRampDownH14;
  250.         lblRampUpH[15] = lblRampUpH15;  lblRampDownH[15] = lblRampDownH15;
  251.         vStart = 30;
  252.         //ReDrawFields(DRAW_PCL|DRAW_RAMP);
  253.        // PlotCurve( PLOT_RAMP_GRID );
  254. }
  255. //---------------------------------------------------------------------------
  256. void _fastcall TfrmGUIApcProfile::SubClassWndProc( Messages::TMessage &Message)
  257. {
  258.     switch ( Message.Msg )
  259.     {
  260.         case WM_MF_QUERY_RFTWOAPCDOOFFSET_SUCCESS:
  261.         {
  262.             m_bTADOSupport = true;
  263.             lblLowApcDcOffset->Visible = true;
  264.             edtLowApcDcOffset->Visible = true;
  265.             lblAPCLowestPower->Visible = true;
  266.             edtAPCLowestPower->Visible = true;
  267.             Query_RfSetRampTable_Support();
  268.         }
  269.         break;
  270.         case WM_MF_QUERY_RFTWOAPCDOOFFSET_FAILED:
  271.         {
  272.             m_bTADOSupport = false;
  273.             lblLowApcDcOffset->Visible = false;
  274.             edtLowApcDcOffset->Visible = false;
  275.             lblAPCLowestPower->Visible = false;
  276.             edtAPCLowestPower->Visible = false;
  277.             Query_RfSetRampTable_Support();
  278.         }
  279.         break;
  280.         case WM_ML_NVRAM_READ_GMSK_APC_CNF:
  281.         {
  282.             UploadFromFlashDone();
  283.         }
  284.         break;
  285.        // case WM_ML_QUERY_RFSETRAMPTABLE_SUCCESS:
  286.        //      read_APC_files_setup( "MF_setup.txt", Application->ExeName );
  287.        //      btnUploadFromFlashClick(this);
  288.        // break;
  289.        // case WM_ML_QUERY_RFSETRAMPTABLE_FAILED:
  290.        //      read_APC_files_setup( "MF_setup.txt", Application->ExeName );
  291.        //      btnUploadFromFlashClick(this);
  292.        // break;
  293.         default:
  294.              this->WndProc( Message );
  295.         break;
  296.     }
  297. }
  298. //--------------------------------------------------------------------------
  299. void __fastcall TfrmGUIApcProfile::FormShow(TObject *Sender)
  300. {
  301.     if (m_bInit)
  302.     {
  303.         m_bInit = false;
  304.         Query_RfSetRampTable_Support();
  305.         m_bTADOSupport = frmMainSel->Get_TADO_Support();
  306.         DisplayTADOUI( m_bTADOSupport );
  307.     }
  308.     m_bDragTrigger = false;
  309.     ReDrawFields(DRAW_GUI_PCL|DRAW_GUI_RAMP);
  310.     PlotCurve( PLOT_RAMP_GRID | PLOT_RAMP_PROFILE_CURVE );
  311. }
  312. //---------------------------------------------------------------------------
  313. void TfrmGUIApcProfile::read_APC_files_setup( AnsiString asSetupFile, AnsiString asExeName )
  314. {
  315.     AnsiString as_NVRAM_DB_File;
  316.     AnsiString asPath;
  317.     if ( getPathFromStr(asExeName, asPath) &&
  318.          withPath( asPath) &&
  319.          !withPath( asSetupFile)
  320.        )
  321.     {
  322.        asSetupFile = asPath + asSetupFile;
  323.     }
  324.     TIniFile *ini;
  325.     try
  326.     {
  327.         ini = new TIniFile( asSetupFile );
  328.         if(ini != NULL)
  329.         {
  330.             //stNVRAMDB->Caption  = ini->ReadString("RF tool","NVRAM database file", "");
  331.            // if ( stNVRAMDB->Caption.Length() >0)
  332.            // {
  333.            //     read_APC_db_file( stNVRAMDB->Caption );
  334.            // }
  335.            as_NVRAM_DB_File = ini->ReadString("RF tool","NVRAM database file", "");
  336.            read_db_file(as_NVRAM_DB_File);
  337.           // {
  338.           //     UpdateDBFileCaption(as_NVRAM_DB_File);
  339.           //     frmRFTool->UpdateDBFileCaption(as_NVRAM_DB_File);
  340.           // }
  341.             delete ini;
  342.             ini = NULL;
  343.         }
  344.     }
  345.     catch (...)
  346.     {
  347.        AnsiString as_warning_msg;
  348.        as_warning_msg = " RF tool : read setup file : " + asSetupFile + " error ";
  349.        Application->MessageBox( as_warning_msg.c_str(), "Warning", MB_OK );
  350.     }
  351. }
  352. //---------------------------------------------------------------------------
  353. void TfrmGUIApcProfile::UpdateDBFileCaption( AnsiString asFileName )
  354. {
  355.     m_stNVRAMDB->Caption = asFileName;
  356. }
  357. //---------------------------------------------------------------------------
  358. void TfrmGUIApcProfile::read_db_file(AnsiString asFileName)
  359. {
  360.     
  361. #if 0
  362.     unsigned long nvram_idb;
  363.     if(! NVRAMMan->Get_IsInit() || asFileName.AnsiCompareIC(NVRAMMan->Get_NVRAM_DB_File()) )
  364.     {
  365.         frmMainSel->FDMDatabaseInit( asFileName.c_str());
  366.     }
  367.     if( ! NVRAMMan->Get_IsInit() )
  368.     {
  369.          Application->MessageBox( " Initialize NVRAM database fail", "Fail", MB_OK );
  370.          return false;
  371.     }
  372.     return true;
  373. #endif
  374. }
  375. //---------------------------------------------------------------------------
  376. void TfrmGUIApcProfile::write_APC_files_setup( AnsiString asSetupFile, AnsiString asExeName )
  377. {
  378.     AnsiString asPath;
  379.     if ( getPathFromStr(asExeName, asPath) &&
  380.          withPath( asPath) &&
  381.          !withPath( asSetupFile)
  382.        )
  383.     {
  384.         asSetupFile = asPath + asSetupFile;
  385.     }
  386.     TIniFile *ini;
  387.     try
  388.     {
  389.         ini = new TIniFile( asSetupFile );
  390.         if(ini != NULL)
  391.         {
  392.             ini->WriteString("RF tool","NVRAM database file", m_stNVRAMDB->Caption );
  393.             delete ini;
  394.             ini = NULL;
  395.         }
  396.     }
  397.     catch (...)
  398.     {
  399.         AnsiString as_warning_msg;
  400.         as_warning_msg = " RF tool : write setup file : " + asSetupFile + " error ";
  401.         Application->MessageBox( as_warning_msg.c_str(), "Warning", MB_OK );
  402.     }
  403. }
  404. //---------------------------------------------------------------------------
  405. void  TfrmGUIApcProfile::CNF_NVRAM_Init(void)
  406. {
  407.     if (!NVRAMMan->Get_IsInit())
  408.     {
  409.         sbGUIAPCProfile->Panels->Items[0]->Text = (AnsiString) "  NVRAM database file initialization fail";
  410.         Application->MessageBox("Execution Failure : NVRAM database file initialization fail", "FAILURE", MB_OK);
  411.         return;
  412.     }
  413.     m_stNVRAMDB->Caption = NVRAMMan->Get_NVRAM_DB_File();
  414.     switch (m_eNvramTrigger)
  415.     {
  416.         case NVRAM_TRIGGER_CHANGE_DB:
  417.         {
  418.             sbGUIAPCProfile->Panels->Items[0]->Text = (AnsiString) " Change NVRAM database file successfully";
  419.             CurrentPageReset();
  420.         }
  421.         break;
  422.         case NVRAM_TRIGGER_READ:
  423.         {
  424.             UploadFromFlash();
  425.         }
  426.         break;
  427.         case NVRAM_TRIGGER_WRITE:
  428.         {
  429.             DownloadToFlash();
  430.         }
  431.         break;
  432.     }
  433. }
  434. //---------------------------------------------------------------------------
  435. void __fastcall TfrmGUIApcProfile::btnUploadFromFlashClick(TObject *Sender)
  436. {
  437.     CurrentPageLock();
  438.     if (!NVRAMMan->Get_IsInit())
  439.     {
  440.         if (!m_dlgOpenDB->Execute())
  441.         {
  442.             return;
  443.         }
  444.         m_eNvramTrigger = NVRAM_TRIGGER_READ;
  445.         NVRAMMan->ConfirmCallback = ::CNF_NVRAM_Init;
  446.         NVRAMMan->REQ_Init(m_dlgOpenDB->FileName);
  447.     }
  448.     else
  449.     {
  450.         UploadFromFlash();
  451.     }
  452. }
  453. //---------------------------------------------------------------------------
  454. void TfrmGUIApcProfile::UploadFromFlash(void)
  455. {
  456.     RF_APC_Obj->ConfirmCallback = ::CNF_ReadFromNVRAM;
  457.     RF_APC_Obj->REQ_Read_APC_From_NVRAM_Start(m_uiFinalRFID, m_bTADOSupport);
  458. }
  459. //---------------------------------------------------------------------------
  460. void TfrmGUIApcProfile::CNF_ReadFromNVRAM(void)
  461. {
  462.     PostMessage(this->Handle,
  463.                 WM_ML_NVRAM_READ_GMSK_APC_CNF,
  464.                  0,
  465.                  0
  466.                  );
  467. }
  468. //---------------------------------------------------------------------------
  469. void  TfrmGUIApcProfile::UploadFromFlashDone(void)
  470. {
  471.     E_METAAPP_RESULT_T state = RF_APC_Obj->Get_ConfirmState();
  472.     switch (state)
  473.     {
  474.         case METAAPP_SUCCESS:
  475.         {
  476.             int total_band_num;
  477.             if (frmMainSel->cbGSM850->Checked)
  478.             {
  479.                 total_band_num = 4;
  480.             }
  481.             else
  482.             {
  483.                 total_band_num = 3;
  484.             }
  485.             for (int band=0; band<total_band_num; band++)
  486.             {
  487.                 m_usHighApcDcOffset[band] = RF_APC_Obj->Get_HighApcDcOffset(band);
  488.                 if (m_bTADOSupport)
  489.                 {
  490.                     m_usLowApcDcOffset[band] = RF_APC_Obj->Get_LowApcDcOffset(band);
  491.                     ApcLowestPower[band] = RF_APC_Obj->Get_ApcLowestPower(band);
  492.                 }
  493.                 l1cal_rampTable_T* ramp_table = RF_APC_Obj->Get_ApcProfile(band);
  494.                 m_sRFCal_RamTable[band] = *ramp_table;
  495.             }
  496.             if (RampDataChange(&m_sRFCal_RamTable[m_eCurBand], &m_sOldRFCal_RamTable[m_eCurBand]))
  497.             {
  498.                 for (int band=0; band<total_band_num; band++)
  499.                 {
  500.                     m_sOldRFCal_RamTable[band] = m_sRFCal_RamTable[band];
  501.                 }
  502.                 for (int band=0; band<total_band_num; band++)
  503.                 {
  504.                     for (int i=0; i<3; i++)
  505.                     {
  506.                         for (int j=0; j<3; j++)
  507.                         {
  508.                             m_sOldRFCal_RamTable[band].rampData.battery_compensate[i][j] = m_sRFCal_RamTable[band].rampData.battery_compensate[i][j] ;
  509.                         }
  510.                     }
  511.                 }
  512.                 PlotCurve(PLOT_RAMP_GRID | PLOT_RAMP_PROFILE_CURVE);
  513.             }
  514.             ReDrawFields(DRAW_GUI_PCL|DRAW_GUI_RAMP);
  515.             sbGUIAPCProfile->Panels->Items[0]->Text = (AnsiString) "  Upload APC profile setting from flash successfully";
  516.         }
  517.         break;
  518.         case METAAPP_FAIL:
  519.         {
  520.             sbGUIAPCProfile->Panels->Items[0]->Text = (AnsiString) "  Upload APC profile setting from flash fail, please check the version of load and NVRAM database are same.";
  521.             Application->MessageBox( "Execution Failure : Upload APC profile from flash, please check 1. GSM850 support. 2. The version of load and NVRAM database are same.", "FAILURE", MB_OK );
  522.         }
  523.         break;
  524.         case METAAPP_TIMEOUT:
  525.         {
  526.             sbGUIAPCProfile->Panels->Items[0]->Text = (AnsiString) "  Upload APC profile setting from flash timeout";
  527.             Application->MessageBox( "Execution Timeout : Upload APC profile from flash", "TIMEOUT", MB_OK );
  528.         }
  529.         break;
  530.         case METAAPP_STOP:
  531.         {
  532.             sbGUIAPCProfile->Panels->Items[0]->Text = (AnsiString) "  Upload APC profile setting from flash stop";
  533.             Application->MessageBox( "Execution Timeout : Upload APC profile from flash", "STOP", MB_OK );
  534.         }
  535.         break;
  536.     }
  537.     CurrentPageReset();
  538. }
  539. //==============================================================================
  540. void  TfrmGUIApcProfile::ReDrawFields( int draw_mask )
  541. {
  542.     int  i, j;
  543.     int  band = m_eCurBand;
  544.     char str[256];
  545.     edtTestArfcn->Text   = m_sTestArfcn[band];
  546.     edtHighApcDcOffset->Text = m_usHighApcDcOffset[band];
  547.     if( m_bTADOSupport )
  548.     {
  549.         edtLowApcDcOffset->Text = m_usLowApcDcOffset[band];
  550.         edtAPCLowestPower->Text = ApcLowestPower[band];
  551.     }
  552.     if( band!=BANDSEL_GSM900 && band!=BANDSEL_GSM850 )
  553.     {
  554.         edtPCLDAC[15]->Visible = true;
  555.         btnPCL[15]->Visible = true;
  556.     }
  557.     else
  558.     {
  559.         edtPCLDAC[15]->Visible = false;
  560.         btnPCL[15]->Visible = false;
  561.     }
  562.     if(draw_mask & DRAW_GUI_PCL)
  563.     {
  564.         for(i=0; i<16; i++)
  565.         {
  566.             edtPCLDAC[i]->Text = m_sRFCal_RamTable[band].rampData.power[i];
  567.             btnPCL[i]->Caption = PCL_RANGE[band][i];
  568.         }
  569.     }
  570.     if(draw_mask & DRAW_GUI_RAMP)
  571.     {
  572.         sprintf(str, "PCL %d Profile", PCL_RANGE[m_eCurBand][m_sCurPCLIndex]);
  573.         pnlProfileTItle->Caption = str;
  574.         for(i=0; i<16; i++)
  575.         {
  576.             edtRampUp[i]->Text = m_sRFCal_RamTable[band].rampData.ramp[m_sCurPCLIndex].point[0][i];
  577.             edtRampDn[i]->Text = m_sRFCal_RamTable[band].rampData.ramp[m_sCurPCLIndex].point[1][i];
  578.         }
  579.     }
  580. }
  581. //==============================================================================
  582. void TfrmGUIApcProfile::ClearImage( void )
  583. {
  584.     imRampProfile->Canvas->Brush->Color = clWhite;
  585.     imRampProfile->Canvas->Brush->Style = bsSolid;
  586.     imRampProfile->Canvas->FillRect(Rect(0,0,imRampProfile->Width,imRampProfile->Height));
  587. }
  588. //--------------------------------------------------------------------------
  589. void TfrmGUIApcProfile::PlotCurve( int plot_mask )
  590. {
  591.     // plot grid
  592.     double min_y, max_y;
  593.     if (plot_mask & PLOT_RAMP_GRID)
  594.     {
  595.         PlotGrid(0, 32, 0, 255);
  596.     }
  597.     // plot ramp profile curve
  598.     if( plot_mask & PLOT_RAMP_PROFILE_CURVE )
  599.     {
  600.         PlotRampProfileCurve();
  601.         PlotRampProfileCircle();
  602.     }
  603. }
  604. //---------------------------------------------------------------------------
  605. void TfrmGUIApcProfile::PlotGrid(int min_x, int max_x, int min_y, int max_y)
  606. {
  607.      int i;
  608.      double range;
  609.      ClearImage();
  610.      max_y_grid = max_y;
  611.      min_y_grid = min_y - 40;
  612.      range = max_y_grid - min_y_grid;
  613.      for( i=1; i<=100; i++ )
  614.      {
  615.          vScale = i*RAMP_VSCALE_UNIT;
  616.          if( vScale * 8 > range)
  617.          {
  618.             break;
  619.          }
  620.      }
  621.      vDistance = imRampProfile->Height / (range +10) * vScale;
  622.      Segments = (range / vScale) + 1;
  623.     imRampProfile->Canvas->Pen->Color = clBlack;
  624.     imRampProfile->Canvas->Pen->Width = 1;
  625.     imRampProfile->Canvas->Pen->Style = psDot;
  626.     // plot horizotal grid & label
  627.     for( i=0; i<Segments && i<RAMP_VERTICAL_LABEL_NUM; i++ )
  628.     {
  629.         if( (i*vDistance + vStart) > imRampProfile->Height || (i*vScale) > MAX_RAMP_DATA_VALUE )
  630.         {
  631.             lblVertical[i]->Visible = true;
  632.             lblVertical[i]->Top = imRampProfile->Top + imRampProfile->Height - vDistance*(1.0*MAX_RAMP_DATA_VALUE/vScale) - vStart - 5 ;
  633.             lblVertical[i]->Left = imRampProfile->Left - 20;
  634.             lblVertical[i]->Caption = (AnsiString) "255";
  635.             imRampProfile->Canvas->MoveTo( 1, imRampProfile->Height - vDistance*(1.0*MAX_RAMP_DATA_VALUE/vScale) - vStart );
  636.             imRampProfile->Canvas->LineTo( 1 + imRampProfile->Width, imRampProfile->Height - vDistance*(1.0*MAX_RAMP_DATA_VALUE/vScale) - vStart );
  637.             Segments = i;
  638.             break;
  639.         }
  640.         lblVertical[i]->Visible = true;
  641.         lblVertical[i]->Top =  imRampProfile->Top + imRampProfile->Height - i*vDistance - vStart - 5 ;
  642.         lblVertical[i]->Left = imRampProfile->Left - 20;
  643.         lblVertical[i]->Caption = IntToStr( i*vScale );
  644.         imRampProfile->Canvas->MoveTo( 1, imRampProfile->Height - i*vDistance - vStart );
  645.         imRampProfile->Canvas->LineTo( 1 + imRampProfile->Width, imRampProfile->Height - i*vDistance - vStart );
  646.     }
  647.     for(i=Segments+1; i<RAMP_VERTICAL_LABEL_NUM; i++)
  648.     {
  649.         lblVertical[i]->Visible = false;
  650.     }
  651.     // plot vertical grid
  652.     lblRampUpH[0]->Left = imRampProfile->Left - 5;
  653.     lblRampUpH[0]->Top = imRampProfile->Top + imRampProfile->Height + 5;
  654.     lblRampUpH[0]->Caption = IntToStr(0);
  655.     hDistance = imRampProfile->Width / TOTAL_HORIZONTAL_SAMPLE ;
  656.     for( i=1; i<TOTAL_HORIZONTAL_SAMPLE; i++ )
  657.     {
  658.         imRampProfile->Canvas->MoveTo( i * hDistance, 1 );
  659.         imRampProfile->Canvas->LineTo( i * hDistance, imRampProfile->Height );
  660.         if( i<RAMP_UP_SAMPLE_NUM) // ramp up
  661.         {
  662.             lblRampUpH[i]->Left = imRampProfile->Left + i * hDistance - 5;
  663.             lblRampUpH[i]->Top = imRampProfile->Top + imRampProfile->Height + 5;
  664.             lblRampUpH[i]->Caption = IntToStr(i);
  665.         }
  666.         else if( i>=(RAMP_UP_SAMPLE_NUM+DATA_SAMPLE_NUM)) // ramp down
  667.         {
  668.             lblRampDownH[(i-RAMP_UP_SAMPLE_NUM-DATA_SAMPLE_NUM)]->Left = imRampProfile->Left + i * hDistance - 5;
  669.             lblRampDownH[(i-RAMP_UP_SAMPLE_NUM-DATA_SAMPLE_NUM)]->Top = imRampProfile->Top + imRampProfile->Height + 5;
  670.             lblRampDownH[(i-RAMP_UP_SAMPLE_NUM-DATA_SAMPLE_NUM)]->Caption = IntToStr((i-RAMP_UP_SAMPLE_NUM-DATA_SAMPLE_NUM));
  671.         }
  672.     }
  673. }
  674. //---------------------------------------------------------------------------
  675. void TfrmGUIApcProfile::PlotRampProfileCurve( void )
  676. {
  677.     int i;
  678.     imRampProfile->Invalidate();
  679.    // isOrgCurvePlot = true;
  680.     imRampProfile->Canvas->Pen->Color = clBlue;
  681.     imRampProfile->Canvas->Pen->Width = 1;
  682.     imRampProfile->Canvas->Pen->Style = psSolid;
  683.     // ramp up
  684.     imRampProfile->Canvas->MoveTo(1, imRampProfile->Height - vDistance*(1.0*(m_sRFCal_RamTable[m_eCurBand].rampData.ramp[m_sCurPCLIndex].point[0][0])/vScale) - vStart )  ;
  685.     for( i=0; i<RAMP_UP_SAMPLE_NUM; i++)
  686.     {
  687.         //Sleep(10);
  688.         RampUpPoint.x[i] = hDistance*i;
  689.         RampUpPoint.y[i] = imRampProfile->Height - vDistance*(1.0*( m_sRFCal_RamTable[m_eCurBand].rampData.ramp[m_sCurPCLIndex].point[0][i])/vScale )- vStart;
  690.         imRampProfile->Canvas->LineTo( RampUpPoint.x[i], RampUpPoint.y[i] );
  691.     }
  692.     // ramp down
  693.     imRampProfile->Canvas->MoveTo( hDistance*(RAMP_UP_SAMPLE_NUM+DATA_SAMPLE_NUM), imRampProfile->Height - vDistance*(1.0*( m_sRFCal_RamTable[m_eCurBand].rampData.ramp[m_sCurPCLIndex].point[1][0])/vScale) - vStart );
  694.     for( i=0; i<RAMP_DOWN_SAMPLE_NUM; i++)
  695.     {
  696.         //Sleep(10);
  697.         RampDownPoint.x[i] = hDistance*(i+RAMP_UP_SAMPLE_NUM+DATA_SAMPLE_NUM);
  698.         RampDownPoint.y[i] = imRampProfile->Height - vDistance*(1.0*( m_sRFCal_RamTable[m_eCurBand].rampData.ramp[m_sCurPCLIndex].point[1][i])/vScale) - vStart;
  699.         imRampProfile->Canvas->LineTo( RampDownPoint.x[i], RampDownPoint.y[i] );
  700.     }
  701.     // midamble
  702.     imRampProfile->Canvas->Pen->Color = clPurple;
  703.     imRampProfile->Canvas->Pen->Width = 1;
  704.     imRampProfile->Canvas->Pen->Style = psSolid;
  705.     imRampProfile->Canvas->MoveTo(hDistance*(RAMP_UP_SAMPLE_NUM-1), imRampProfile->Height - vDistance*(1.0*MAX_RAMP_DATA_VALUE/vScale )- vStart );
  706.     imRampProfile->Canvas->LineTo(hDistance*(RAMP_UP_SAMPLE_NUM+DATA_SAMPLE_NUM), imRampProfile->Height - vDistance*(1.0*MAX_RAMP_DATA_VALUE/vScale )- vStart  );
  707. }
  708. //------------------------------------------------------------------------------
  709. void  TfrmGUIApcProfile::PlotRampProfileCircle( void )
  710. {
  711.     imRampProfile->Canvas->Brush->Color = clLime;
  712.     int x1;
  713.     int y1;
  714.     int x2;
  715.     int y2;
  716.     // ramp up
  717.     for(int i=0; i<RAMP_UP_SAMPLE_NUM; i++)
  718.     {
  719.         //Sleep(25);
  720.         x1 = max(RampUpPoint.x[i]-RAMP_CIRCLE_RADIOUS, 1);
  721.         y1 = max(RampUpPoint.y[i]-RAMP_CIRCLE_RADIOUS, 1);
  722.         x2 = min(RampUpPoint.x[i]+RAMP_CIRCLE_RADIOUS, imRampProfile->Width);
  723.         y2 = min(RampUpPoint.y[i]+RAMP_CIRCLE_RADIOUS, imRampProfile->Height);
  724.         imRampProfile->Canvas->Ellipse(x1, y1, x2, y2);
  725.     }
  726.     // ramp down
  727.     for(int i=0; i<RAMP_DOWN_SAMPLE_NUM; i++)
  728.     {
  729.        //Sleep(25);
  730.        x1 = max(RampDownPoint.x[i]-RAMP_CIRCLE_RADIOUS, 1);
  731.        y1 = max(RampDownPoint.y[i]-RAMP_CIRCLE_RADIOUS, 1);
  732.        x2 = min(RampDownPoint.x[i]+RAMP_CIRCLE_RADIOUS, imRampProfile->Width);
  733.        y2 = min(RampDownPoint.y[i]+RAMP_CIRCLE_RADIOUS, imRampProfile->Height);
  734.        imRampProfile->Canvas->Ellipse(x1, y1, x2, y2);
  735.     }
  736. }
  737. //==============================================================================
  738. void __fastcall TfrmGUIApcProfile::imRampProfileDragOver(TObject *Sender,
  739.       TObject *Source, int X, int Y, TDragState State, bool &Accept)
  740. {
  741.     if( State == dsDragEnter )
  742.     {
  743.        CheckFields( );
  744.        // char buf[20];
  745.        // sprintf(buf, " (x=%d, y=%d) ", X, Y);
  746.        // sbAudioCal->Panels->Items[0]->Text = (AnsiString) buf;
  747.         // ramp up
  748.         for(int i=0; i<RAMP_UP_SAMPLE_NUM; i++)
  749.         {
  750.             if( RampUpPoint.x[i]-RAMP_CIRCLE_RADIOUS<=X && X<=RampUpPoint.x[i]+RAMP_CIRCLE_RADIOUS &&
  751.                 RampUpPoint.y[i]-RAMP_CIRCLE_RADIOUS<=Y && Y<=RampUpPoint.y[i]+RAMP_CIRCLE_RADIOUS )
  752.             {
  753.                 isRampUpCircleOnDrag = true;
  754.                 RampCircleOnDragIndex = i;
  755.                 if( btnTXStart->Tag == BTN_TAG_START )
  756.                 {
  757.                    p_TxStop_Event = CreateEvent(NULL, TRUE, FALSE, NULL);
  758.                    ResetEvent( p_TxStop_Event );
  759.                    btnTXStopClick( this ); // stop TX burst
  760.                    WaitForSingleObject( p_TxStop_Event, 5000 );
  761.                 }
  762.                 return;
  763.             }
  764.         }
  765.         // ramp down
  766.         for(int i=0; i<RAMP_DOWN_SAMPLE_NUM; i++)
  767.         {
  768.             if( RampDownPoint.x[i]-RAMP_CIRCLE_RADIOUS<=X && X<=RampDownPoint.x[i]+RAMP_CIRCLE_RADIOUS &&
  769.                 RampDownPoint.y[i]-RAMP_CIRCLE_RADIOUS<=Y && Y<=RampDownPoint.y[i]+RAMP_CIRCLE_RADIOUS )
  770.             {
  771.                 isRampDownCircleOnDrag = true;
  772.                 RampCircleOnDragIndex = i;
  773.                 if( btnTXStart->Tag == BTN_TAG_START )
  774.                 {
  775.                     p_TxStop_Event = CreateEvent(NULL, TRUE, FALSE, NULL);
  776.                     ResetEvent( p_TxStop_Event );
  777.                     btnTXStopClick( this ); // stop TX burst
  778.                     WaitForSingleObject( p_TxStop_Event, 5000 );
  779.                 }
  780.                 return;
  781.             }
  782.         }
  783.     }
  784. }
  785. //---------------------------------------------------------------------------
  786. void __fastcall TfrmGUIApcProfile::imRampProfileEndDrag(TObject *Sender,
  787.       TObject *Target, int X, int Y)
  788. {
  789.     if( isRampUpCircleOnDrag || isRampDownCircleOnDrag )
  790.     {
  791.         int result;
  792.         if( X == 0 && Y == 0 ) // outside image
  793.         {
  794.             Application->MessageBox( " Destination coordinates is outside image range", "Warning", MB_OK );
  795.             return;
  796.         }
  797.         result = ImageRangeCheck(X, Y);
  798.         if( result == OUT_OF_TOP_RANGE )
  799.         {
  800.             Y = imRampProfile->Height - vDistance*(1.0*(255)/vScale) - vStart;
  801.         }
  802.         else if( result == OUT_OF_BOTTOM_RANGE )
  803.         {
  804.             Y = imRampProfile->Height - vStart;
  805.         }
  806.         if( isRampUpCircleOnDrag ) // ramp up
  807.         {
  808.             RampUpPoint.y[RampCircleOnDragIndex] = Y;
  809.             UpdateRampdata( RAMP_UP_FLAG, RampCircleOnDragIndex );
  810.             isRampUpCircleOnDrag = false;
  811.         }
  812.         else if( isRampDownCircleOnDrag ) // ramp dwon
  813.         {
  814.             RampDownPoint.y[RampCircleOnDragIndex] = Y;
  815.             UpdateRampdata( RAMP_DOWN_FLAG, RampCircleOnDragIndex );
  816.             isRampDownCircleOnDrag = false;
  817.         }
  818.         PlotCurve( PLOT_RAMP_GRID | PLOT_RAMP_PROFILE_CURVE );
  819.         ReDrawFields( DRAW_GUI_RAMP );
  820.         m_bDragTrigger = true;
  821.         imRampProfile->Enabled = false;
  822.         //p_TxStart_Event = CreateEvent(NULL, TRUE, FALSE, NULL);
  823.        // ResetEvent( p_TxStart_Event );
  824.         btnDownloadToFlashClick( this );
  825.         //WaitForSingleObject( p_TxStart_Event, 5000 );
  826.     }
  827. }
  828. //==============================================================================
  829. void  TfrmGUIApcProfile::UpdateRampdata( int ramp_flag, int idx )
  830. {
  831.     if( idx >= 0 )
  832.     {
  833.         if( ramp_flag == RAMP_UP_FLAG ) // ramp up
  834.         {
  835.             m_sRFCal_RamTable[m_eCurBand].rampData.ramp[m_sCurPCLIndex].point[0][idx] = 1.0*(imRampProfile->Height -RampUpPoint.y[idx] - vStart)*vScale/vDistance;
  836.             m_sOldRFCal_RamTable[m_eCurBand].rampData.ramp[m_sCurPCLIndex].point[0][idx] = m_sRFCal_RamTable[m_eCurBand].rampData.ramp[m_sCurPCLIndex].point[0][idx];
  837.         }
  838.         else // ramp down
  839.         {
  840.             m_sRFCal_RamTable[m_eCurBand].rampData.ramp[m_sCurPCLIndex].point[1][idx] = 1.0*(imRampProfile->Height -RampDownPoint.y[idx] - vStart)*vScale/vDistance;
  841.             m_sOldRFCal_RamTable[m_eCurBand].rampData.ramp[m_sCurPCLIndex].point[1][idx] = m_sRFCal_RamTable[m_eCurBand].rampData.ramp[m_sCurPCLIndex].point[1][idx];
  842.         }
  843.     }
  844. }
  845. //==============================================================================
  846. void __fastcall TfrmGUIApcProfile::btnUpRightClick(TObject *Sender)
  847. {
  848.     TButton *button = (TButton*)Sender;
  849.     int  up_down = button->Tag;
  850.     int  i;
  851.     for(i=15; i>=1; i--)
  852.     {
  853.         m_sRFCal_RamTable[m_eCurBand].rampData.ramp[m_sCurPCLIndex].point[up_down][i] =
  854.         m_sRFCal_RamTable[m_eCurBand].rampData.ramp[m_sCurPCLIndex].point[up_down][i-1];
  855.         m_sOldRFCal_RamTable[m_eCurBand].rampData.ramp[m_sCurPCLIndex].point[up_down][i] =
  856.         m_sOldRFCal_RamTable[m_eCurBand].rampData.ramp[m_sCurPCLIndex].point[up_down][i-1];
  857.     }
  858.     ReDrawFields( DRAW_GUI_RAMP );
  859.     PlotCurve( PLOT_RAMP_GRID | PLOT_RAMP_PROFILE_CURVE );
  860. }
  861. //---------------------------------------------------------------------------
  862. void __fastcall TfrmGUIApcProfile::btnDnRightClick(TObject *Sender)
  863. {
  864.     TButton *button = (TButton*)Sender;
  865.     int  up_down = button->Tag;
  866.     int  i;
  867.     for(i=15; i>=1; i--)
  868.     {
  869.         m_sRFCal_RamTable[m_eCurBand].rampData.ramp[m_sCurPCLIndex].point[up_down][i] =
  870.         m_sRFCal_RamTable[m_eCurBand].rampData.ramp[m_sCurPCLIndex].point[up_down][i-1];
  871.         m_sOldRFCal_RamTable[m_eCurBand].rampData.ramp[m_sCurPCLIndex].point[up_down][i] =
  872.         m_sOldRFCal_RamTable[m_eCurBand].rampData.ramp[m_sCurPCLIndex].point[up_down][i-1];
  873.     }
  874.     ReDrawFields( DRAW_GUI_RAMP );
  875.     PlotCurve( PLOT_RAMP_GRID | PLOT_RAMP_PROFILE_CURVE );
  876. }
  877. //---------------------------------------------------------------------------
  878. void __fastcall TfrmGUIApcProfile::btnUpLeftClick(TObject *Sender)
  879. {
  880.     TButton *button = (TButton*)Sender;
  881.     int  up_down = button->Tag;
  882.     int  i;
  883.     for(i=0; i<15; i++)
  884.     {
  885.         m_sRFCal_RamTable[m_eCurBand].rampData.ramp[m_sCurPCLIndex].point[up_down][i] =
  886.         m_sRFCal_RamTable[m_eCurBand].rampData.ramp[m_sCurPCLIndex].point[up_down][i+1];
  887.         m_sOldRFCal_RamTable[m_eCurBand].rampData.ramp[m_sCurPCLIndex].point[up_down][i] =
  888.         m_sOldRFCal_RamTable[m_eCurBand].rampData.ramp[m_sCurPCLIndex].point[up_down][i+1];
  889.     }
  890.     ReDrawFields( DRAW_GUI_RAMP );
  891.     PlotCurve( PLOT_RAMP_GRID | PLOT_RAMP_PROFILE_CURVE );
  892. }
  893. //---------------------------------------------------------------------------
  894. void __fastcall TfrmGUIApcProfile::btnDnLeftClick(TObject *Sender)
  895. {
  896.     TButton *button = (TButton*)Sender;
  897.     int  up_down = button->Tag;
  898.     int  i;
  899.     for(i=0; i<15; i++)
  900.     {
  901.         m_sRFCal_RamTable[m_eCurBand].rampData.ramp[m_sCurPCLIndex].point[up_down][i] =
  902.         m_sRFCal_RamTable[m_eCurBand].rampData.ramp[m_sCurPCLIndex].point[up_down][i+1];
  903.         m_sOldRFCal_RamTable[m_eCurBand].rampData.ramp[m_sCurPCLIndex].point[up_down][i] =
  904.         m_sOldRFCal_RamTable[m_eCurBand].rampData.ramp[m_sCurPCLIndex].point[up_down][i+1];
  905.     }
  906.     ReDrawFields( DRAW_GUI_RAMP );
  907.     PlotCurve( PLOT_RAMP_GRID | PLOT_RAMP_PROFILE_CURVE );
  908. }
  909. //---------------------------------------------------------------------------
  910. void __fastcall TfrmGUIApcProfile::edtRampUpCheck(TObject *Sender)
  911. {
  912.     unsigned char  ucdata;
  913.     AnsiString  text;
  914.     TEdit *edit = (TEdit*)Sender;
  915.     char  hint[] = " value shall be 0~255 ";
  916.     text = edit->Text;
  917.     if( !IsValidRamp( text, ucdata ) )
  918.     {
  919.         ShowHintLabel( edit, hint );
  920.         edit->SetFocus();
  921.         return;
  922.     }
  923.     m_sRFCal_RamTable[m_eCurBand].rampData.ramp[m_sCurPCLIndex].point[0][edit->Tag] = ucdata;
  924.     m_sOldRFCal_RamTable[m_eCurBand].rampData.ramp[m_sCurPCLIndex].point[0][edit->Tag] = ucdata;
  925.     PlotCurve( PLOT_RAMP_GRID | PLOT_RAMP_PROFILE_CURVE );
  926. }
  927. //---------------------------------------------------------------------------
  928. void __fastcall TfrmGUIApcProfile::edtRampDnCheck(TObject *Sender)
  929. {
  930.     unsigned char  ucdata;
  931.     AnsiString  text;
  932.     TEdit *edit = (TEdit*)Sender;
  933.     char  hint[] = " value shall be 0~255 ";
  934.     text = edit->Text;
  935.     if( !IsValidRamp( text, ucdata ) )
  936.     {
  937.         ShowHintLabel( edit, hint );
  938.         edit->SetFocus();
  939.         return;
  940.     }
  941.     m_sRFCal_RamTable[m_eCurBand].rampData.ramp[m_sCurPCLIndex].point[1][edit->Tag] = ucdata;
  942.     m_sOldRFCal_RamTable[m_eCurBand].rampData.ramp[m_sCurPCLIndex].point[1][edit->Tag] = ucdata;
  943.     PlotCurve( PLOT_RAMP_GRID | PLOT_RAMP_PROFILE_CURVE );
  944. }
  945. //---------------------------------------------------------------------------
  946. void  TfrmGUIApcProfile::ShowHintLabel( TControl *sender, char* hint )
  947. {
  948.    TPoint pt0 = this->ClientOrigin;
  949.    TPoint pt1 = sender->ClientOrigin;
  950.    lblHint->Left = (pt1.x-pt0.x);
  951.    lblHint->Top  = (pt1.y-pt0.y)+sender->Height+3;
  952.    lblHint->Caption = hint;
  953.    lblHint->Visible = true;
  954.    HintTimer->Enabled = true;
  955. }
  956. //---------------------------------------------------------------------------
  957. void __fastcall TfrmGUIApcProfile::HintTimerTimer(TObject *Sender)
  958. {
  959.     HintTimer->Enabled = false;
  960.     lblHint->Visible = false;    
  961. }
  962. //---------------------------------------------------------------------------
  963. void __fastcall TfrmGUIApcProfile::btnTXStartClick(TObject *Sender)
  964. {
  965.     if(btnTXStart->Tag==0)
  966.     {
  967.         CurrentPageLock();
  968.         frmRFTool->CurrentPageLock();
  969.         frmRFTool->Force_RF_Stop();
  970.         frmRFTool->pctlToolSel->Enabled = false;
  971.         if( t_RfSetRamp.rf_setramp.SetRampTableSupport )
  972.         {
  973.             int  total_band_num;
  974.             int  band;
  975.             if(frmMainSel->cbGSM850->Checked)
  976.             {   total_band_num = 4;
  977.             }
  978.             else
  979.             {   total_band_num = 3;
  980.             }
  981.             
  982.             for(band=0; band<total_band_num; band++)
  983.             {
  984.                 RF_APC_Obj->Set_HighApcDcOffset( band, m_usHighApcDcOffset[band] );
  985.                 if( m_bTADOSupport )
  986.                 {
  987.                     RF_APC_Obj->Set_LowApcDcOffset( band, m_usLowApcDcOffset[band] );
  988.                     RF_APC_Obj->Set_ApcLowestPower( band, ApcLowestPower[band] );
  989.                 }
  990.                 RF_APC_Obj->Set_ApcProfile( band, m_sRFCal_RamTable[band] );
  991.             }
  992.            // RF_APC_Obj->Set_ApcProfile( m_eCurBand, m_sRFCal_RamTable[m_eCurBand] );
  993.             RF_APC_Obj->ConfirmCallback   = ::ConfirmCallback_RfSetRampTable;
  994.             RF_APC_Obj->REQ_RfSetRampTable_Start(m_uiFinalRFID, m_bTADOSupport, m_eCurBand);
  995.         }
  996.         else
  997.         {
  998.             S_RFTX rf_tx;
  999.             rf_tx.e_bandsel = m_eCurBand;
  1000.             rf_tx.s_RfNbTxReq.arfcn  = m_sTestArfcn[m_eCurBand];
  1001.             rf_tx.s_RfNbTxReq.bsic   = Tsc;
  1002.             rf_tx.s_RfNbTxReq.power  = PCL_RANGE[m_eCurBand][m_sCurPCLIndex];
  1003.             rf_tx.s_RfNbTxReq.frames = -99;
  1004.             rf_tx.s_RfNbTxReq.dacValue = m_sAfcDac;
  1005.             rf_tx.s_RfNbTxReq.burstTypeNB = m_eBurstType;
  1006.             RF_TX_Obj->ConfirmCallback   = ::ConfirmCallback_TX;
  1007.             RF_TX_Obj->REQ_Start(rf_tx);
  1008.         }
  1009.         sbGUIAPCProfile->Panels->Items[0]->Text = (AnsiString)"  Burst TX progressing";
  1010.     }
  1011.     else
  1012.     {
  1013.        // frmRFTool->Force_RF_Stop();
  1014.        // frmRFTool->pctlToolSel->Enabled = true;
  1015.        // frmRFTool->btnTXStart->Enabled = true;
  1016.        // CurrentPageReset();
  1017.        // frmRFTool->CurrentPageReset();
  1018.        // sbGUIAPCProfile->Panels->Items[0]->Text = (AnsiString)"  Burst TX stop";
  1019.     }
  1020. }
  1021. //-----------------------------------------------
  1022. void  TfrmGUIApcProfile::ConfirmCallback_RfSetRampTable(void)
  1023. {
  1024.     E_METAAPP_RESULT_T state = RF_TX_Obj->Get_ConfirmState();
  1025.     switch (state)
  1026.     {
  1027.         case METAAPP_SUCCESS:
  1028.         {
  1029.             S_RFTX rf_tx;
  1030.             rf_tx.e_bandsel = m_eCurBand;
  1031.             rf_tx.s_RfNbTxReq.arfcn  = m_sTestArfcn[m_eCurBand];
  1032.             rf_tx.s_RfNbTxReq.bsic   = Tsc;
  1033.             rf_tx.s_RfNbTxReq.power  = PCL_RANGE[m_eCurBand][m_sCurPCLIndex];
  1034.             rf_tx.s_RfNbTxReq.frames = -99;
  1035.             rf_tx.s_RfNbTxReq.dacValue = m_sAfcDac;
  1036.             rf_tx.s_RfNbTxReq.burstTypeNB = m_eBurstType;
  1037.             RF_TX_Obj->ConfirmCallback = ::ConfirmCallback_TX;
  1038.             RF_TX_Obj->REQ_Start(rf_tx);
  1039.             sbGUIAPCProfile->Panels->Items[0]->Text = (AnsiString)"  Burst TX progressing";
  1040.         }
  1041.         break;
  1042.         case METAAPP_FAIL:
  1043.         {
  1044.             sbGUIAPCProfile->Panels->Items[0]->Text = (AnsiString)"  Burst TX fail";
  1045.             Application->MessageBox("Execution failure : Set ramp table", "FAILURE", MB_OK);
  1046.         }
  1047.         break;
  1048.         case METAAPP_TIMEOUT:
  1049.         {
  1050.             sbGUIAPCProfile->Panels->Items[0]->Text = (AnsiString)"  Burst TX timeout";
  1051.             Application->MessageBox("Execution Timeout : Set ramp table", "TIMEOUT", MB_OK);
  1052.         }
  1053.         break;
  1054.         case METAAPP_STOP:
  1055.         {
  1056.             sbGUIAPCProfile->Panels->Items[0]->Text = (AnsiString)"  Set ramp table stop";
  1057.         }
  1058.         break;
  1059.     }
  1060. }
  1061. //---------------------------------------------------------------------------
  1062. void __fastcall TfrmGUIApcProfile::edtHighApcDcOffsetCheck(TObject *Sender)
  1063. {
  1064.     unsigned short usdata;
  1065.     int  band = m_eCurBand;
  1066.     AnsiString  text;
  1067.     TEdit *edit = (TEdit*)Sender;
  1068.     char  hint[] = " value shall be 0~1023 ";
  1069.     text = edit->Text;
  1070.     if (!IsValidPCLDac(text, usdata))
  1071.     {
  1072.         ShowHintLabel(edit, hint);
  1073.         edit->SetFocus();
  1074.         return;
  1075.     }
  1076.     m_usHighApcDcOffset[band] = usdata;
  1077. }
  1078. //---------------------------------------------------------------------------
  1079. void __fastcall TfrmGUIApcProfile::OnBtnPclClick(TObject *Sender)
  1080. {
  1081.     if(btnTXStart->Tag==1)
  1082.     {   btnTXStartClick(this);
  1083.     }
  1084.     m_sCurPCLIndex = (*(TComponent*)Sender).Tag;
  1085.     ReDrawFields( DRAW_GUI_RAMP );
  1086.     PlotCurve( PLOT_RAMP_GRID | PLOT_RAMP_PROFILE_CURVE );
  1087. }
  1088. //---------------------------------------------------------------------------
  1089. void __fastcall TfrmGUIApcProfile::tctlAPCChange(TObject *Sender)
  1090. {
  1091.     if (!frmMainSel->cbGSM850->Checked)
  1092.     {
  1093.         if (BANDSEL_GSM850 == (E_BANDSEL) tctlAPC->TabIndex)
  1094.         {
  1095.             tctlAPC->TabIndex = lastTabIndex;
  1096.             Application->MessageBox( "Please check GSM 850 on main menu", "FAILURE", MB_OK );
  1097.             return;
  1098.         }
  1099.     }
  1100.     if( !CheckFields() )
  1101.     {
  1102.         tctlAPC->TabIndex = m_eCurBand;
  1103.         return;
  1104.     }
  1105.     if(btnTXStart->Tag)
  1106.     {
  1107.         btnTXStopClick(this);
  1108.     }
  1109.     m_eCurBand = (E_BANDSEL)tctlAPC->TabIndex;
  1110.     lastTabIndex =  tctlAPC->TabIndex;
  1111.     m_sCurPCLIndex = 0;
  1112.     ReDrawFields( DRAW_GUI_PCL|DRAW_GUI_RAMP );
  1113.     PlotCurve( PLOT_RAMP_GRID | PLOT_RAMP_PROFILE_CURVE );
  1114. }
  1115. //---------------------------------------------------------------------------
  1116. bool  TfrmGUIApcProfile::CheckFields( void )
  1117. {
  1118.     int  i;
  1119.     int  idata;
  1120.     unsigned short usdata;
  1121.     unsigned char ucdata;
  1122.     E_BANDSEL band = m_eCurBand;
  1123.     AnsiString  text;
  1124.     for(i=0; i<16; i++)
  1125.     {
  1126.         text = edtPCLDAC[i]->Text;  if (!IsValidPCLDac(text, usdata))         {  edtPCLDACCheck(edtPCLDAC[i]);   return(false);   }
  1127.         m_sRFCal_RamTable[band].rampData.power[i] = usdata;
  1128.         text = edtRampUp[i]->Text;  if (!IsValidRamp(text, ucdata))           {  edtRampUpCheck(edtRampUp[i]);   return(false);   }
  1129.         m_sRFCal_RamTable[band].rampData.ramp[m_sCurPCLIndex].point[0][i]    = ucdata;
  1130.         m_sOldRFCal_RamTable[band].rampData.ramp[m_sCurPCLIndex].point[0][i] = ucdata;
  1131.         text = edtRampDn[i]->Text;  if (!IsValidRamp(text, ucdata))           {  edtRampDnCheck(edtRampDn[i]);   return(false);   }
  1132.         m_sRFCal_RamTable[band].rampData.ramp[m_sCurPCLIndex].point[1][i]    = ucdata;
  1133.         m_sOldRFCal_RamTable[band].rampData.ramp[m_sCurPCLIndex].point[1][i] = ucdata;
  1134.     }
  1135.     text = edtTestArfcn->Text;     if( !IsValidARFCN( text, band, m_sTestArfcn[band] ) )    {  edtTestArfcnCheck(edtTestArfcn);       return(false);   }
  1136.     text = edtHighApcDcOffset->Text;   if (!IsValidPCLDac(text, m_usHighApcDcOffset[band]))             {  edtHighApcDcOffsetCheck(edtHighApcDcOffset);   return(false);   }
  1137.     if( m_bTADOSupport )
  1138.     {
  1139.         text = edtLowApcDcOffset->Text;   if (!IsValidPCLDac( text, m_usLowApcDcOffset[band]))             {  edtHighApcDcOffsetCheck(edtLowApcDcOffset);   return(false);   }
  1140.         text = edtAPCLowestPower->Text;   if( !IsValidApcLowestPower( text, m_eCurBand, ApcLowestPower[band] ) )     {  edtAPCLowestPowerCheck(edtAPCLowestPower);   return(false);   }
  1141.     }
  1142.     return true;
  1143. }
  1144. //--------------------------------------------------------------------------
  1145. void __fastcall TfrmGUIApcProfile::edtPCLDACCheck(TObject *Sender)
  1146. {
  1147.     int  i;
  1148.     unsigned short  usdata;
  1149.     AnsiString  text;
  1150.     TEdit *edit = (TEdit*)Sender;
  1151.     char  hint[] = " value shall be 0~1023 ";
  1152.     text = edit->Text;
  1153.     if (!IsValidPCLDac(text, usdata))
  1154.     {
  1155.         ShowHintLabel(edit, hint);
  1156.         edit->SetFocus();
  1157.         return;
  1158.     }
  1159.     m_sRFCal_RamTable[m_eCurBand].rampData.power[edit->Tag]    = usdata;
  1160.     m_sOldRFCal_RamTable[m_eCurBand].rampData.power[edit->Tag] = usdata;
  1161. }
  1162. //---------------------------------------------------------------------------
  1163. void __fastcall TfrmGUIApcProfile::edtTestArfcnCheck(TObject *Sender)
  1164. {
  1165.     short sdata;
  1166.     AnsiString  text;
  1167.     TEdit *edit = (TEdit*)Sender;
  1168.     char  hint[][256] =
  1169.     {   " value shall be 0~124 or 975~1023 ",
  1170.         " value shall be 512~885 ",
  1171.         " value shall be 512~810 ",
  1172.         " value shall be 128~251 ",
  1173.     };
  1174.     text = edit->Text;
  1175.     if (!IsValidARFCN(text, m_eCurBand, sdata))
  1176.     {   ShowHintLabel(edit, hint[m_eCurBand]);
  1177.         edit->SetFocus();
  1178.         return;
  1179.     }
  1180.     m_sTestArfcn[m_eCurBand] = sdata;
  1181. }
  1182. //---------------------------------------------------------------------------
  1183. void __fastcall TfrmGUIApcProfile::btnDownloadToFlashClick(TObject *Sender)
  1184. {
  1185.     if (!m_bDragTrigger)
  1186.     {
  1187.         CurrentPageLock();
  1188.     }
  1189.     if (!CheckFields())
  1190.     {
  1191.         sbGUIAPCProfile->Panels->Items[0]->Text = (AnsiString) "  Download APC profile setting to flash fail";
  1192.         Application->MessageBox("Execution Failure : Download APC profile to flash", "FAILURE", MB_OK);
  1193.         CurrentPageReset();
  1194.         return;
  1195.     }
  1196.     if (!NVRAMMan->Get_IsInit())
  1197.     {
  1198.         if (!m_dlgOpenDB->Execute())
  1199.         {
  1200.             return;
  1201.         }
  1202.         m_eNvramTrigger = NVRAM_TRIGGER_WRITE;
  1203.         NVRAMMan->ConfirmCallback = ::CNF_NVRAM_Init;
  1204.         NVRAMMan->REQ_Init(m_dlgOpenDB->FileName);
  1205.     }
  1206.     else
  1207.     {
  1208.         DownloadToFlash();
  1209.     }
  1210. }
  1211. //---------------------------------------------------------------------------
  1212. void  TfrmGUIApcProfile::DownloadToFlash(void)
  1213. {
  1214.     int band;
  1215.     int total_band_num;
  1216.     if (frmMainSel->cbGSM850->Checked)
  1217.     {
  1218.         total_band_num = 4;
  1219.     }
  1220.     else
  1221.     {
  1222.         total_band_num = 3;
  1223.     }
  1224.     for (band=0; band<total_band_num; band++)
  1225.     {
  1226.         RF_APC_Obj->Set_HighApcDcOffset(band, m_usHighApcDcOffset[band]);
  1227.         if (m_bTADOSupport)
  1228.         {
  1229.             RF_APC_Obj->Set_LowApcDcOffset(band, m_usLowApcDcOffset[band]);
  1230.             RF_APC_Obj->Set_ApcLowestPower(band, ApcLowestPower[band]);
  1231.         }
  1232.         RF_APC_Obj->Set_ApcProfile(band, m_sRFCal_RamTable[band]);
  1233.     }
  1234.     RF_APC_Obj->ConfirmCallback = ::CNF_WriteToNVRAM;
  1235.     RF_APC_Obj->REQ_Write_APC_To_NVRAM_Start(m_uiFinalRFID, m_bTADOSupport);
  1236. }
  1237. //---------------------------------------------------------------------------
  1238. void  TfrmGUIApcProfile::DownloadToFlashDone(void)
  1239. {
  1240.     E_METAAPP_RESULT_T state = RF_APC_Obj->Get_ConfirmState();
  1241.     switch (state)
  1242.     {
  1243.         case METAAPP_SUCCESS:
  1244.         {
  1245.             sbGUIAPCProfile->Panels->Items[0]->Text = (AnsiString) "  Download APC profile setting to flash successfully";
  1246.             if (m_bDragTrigger)
  1247.             {
  1248.                 btnTXStartClick(this);
  1249.             }
  1250.         }
  1251.         break;
  1252.         case METAAPP_FAIL:
  1253.         {
  1254.             sbGUIAPCProfile->Panels->Items[0]->Text = (AnsiString) "  Download APC profile setting to flash fail, please check the version of load and NVRAM database are same.";
  1255.             Application->MessageBox("Execution Failure : Download APC profile to flash, please check 1. GSM850 support. 2. The version of load and NVRAM database are same.", "FAILURE", MB_OK);
  1256.         }
  1257.         break;
  1258.         case METAAPP_TIMEOUT:
  1259.         {
  1260.             sbGUIAPCProfile->Panels->Items[0]->Text = (AnsiString) "  Download APC profile setting to flash timeout";
  1261.             Application->MessageBox("Execution Timeout : Download APC profile to flash", "TIMEOUT", MB_OK);
  1262.         }
  1263.         break;
  1264.         case METAAPP_STOP:
  1265.         {
  1266.             sbGUIAPCProfile->Panels->Items[0]->Text = (AnsiString) "  Download APC profile setting to flash stop";
  1267.         }
  1268.         break;
  1269.         default:
  1270.         {
  1271.         }
  1272.         break;
  1273.     }
  1274.     if (!m_bDragTrigger)
  1275.     {
  1276.         CurrentPageReset();
  1277.     }    
  1278. }
  1279. //==============================================================================
  1280. void __fastcall TfrmGUIApcProfile::btnLoadFromFileClick(TObject *Sender)
  1281. {
  1282.     char str[512];
  1283.     bool ok;
  1284.     int  band;
  1285.     int  total_band_num;
  1286.     ok = OpenDialog->Execute();
  1287.     if( !ok )
  1288.     {
  1289.         sbGUIAPCProfile->Panels->Items[0]->Text = (AnsiString) "  Load APC profile setting from file fail";
  1290.         Application->MessageBox( "Execution Failure : Load APC profile from file", "FAILURE", MB_OK );
  1291.         return;
  1292.     }
  1293.     strcpy( str, OpenDialog->FileName.c_str() );
  1294.     ok = RF_APC_Obj->REQ_Read_APC_From_File(str, m_uiFinalRFID, m_bTADOSupport);
  1295.     if( ok )
  1296.     {
  1297.         if(frmMainSel->cbGSM850->Checked)
  1298.         //frmMainSel->Get_FinalBandSupport( band_support );
  1299.         //if( band_support.GSM850 )
  1300.         {
  1301.             total_band_num = 4;
  1302.         }
  1303.         else
  1304.         {
  1305.             total_band_num = 3;
  1306.         }
  1307.         for (band=0; band<total_band_num; band++)
  1308.         {
  1309.            // ApcDcOffset[band] = RF_APC_Obj->ApcDcOffset[band];
  1310.            // m_sRFCal_RamTable[band] = RF_APC_Obj->ApcProfile[band];
  1311.               m_usHighApcDcOffset[band] = RF_APC_Obj->Get_HighApcDcOffset( band );
  1312.               if( m_bTADOSupport )
  1313.               {
  1314.                    m_usLowApcDcOffset[band] = RF_APC_Obj->Get_LowApcDcOffset(band);
  1315.                    ApcLowestPower[band] = RF_APC_Obj->Get_ApcLowestPower(band);
  1316.               }
  1317.               l1cal_rampTable_T* p_ramp_table = RF_APC_Obj->Get_ApcProfile(band);
  1318.               m_sRFCal_RamTable[band] = *p_ramp_table;
  1319.         }
  1320.         if( RampDataChange( &m_sRFCal_RamTable[m_eCurBand], &m_sOldRFCal_RamTable[m_eCurBand] ) )
  1321.         {
  1322.             for(band=0; band<total_band_num; band++)
  1323.             {
  1324.                 m_sOldRFCal_RamTable[band] = m_sRFCal_RamTable[band];
  1325.             }
  1326.             PlotCurve( PLOT_RAMP_GRID | PLOT_RAMP_PROFILE_CURVE );
  1327.         }    
  1328.         ReDrawFields(DRAW_GUI_PCL|DRAW_GUI_RAMP);
  1329.         sbGUIAPCProfile->Panels->Items[0]->Text = (AnsiString) "  Load APC profile setting from file successfully";
  1330.     }
  1331.     else
  1332.     {
  1333.         sbGUIAPCProfile->Panels->Items[0]->Text = (AnsiString) "  Load APC profile setting from file fail";
  1334.         Application->MessageBox( "Execution Failure : Load APC profile from file", "FAILURE", MB_OK );
  1335.     }
  1336. }
  1337. //---------------------------------------------------------------------------
  1338. void __fastcall TfrmGUIApcProfile::btnSaveToFileClick(TObject *Sender)
  1339. {
  1340.     char str[512];
  1341.     bool ok;
  1342.     int  band;
  1343.     int  total_band_num;
  1344.     ok = CheckFields();
  1345.     if(!ok)
  1346.     {
  1347.         sbGUIAPCProfile->Panels->Items[0]->Text = (AnsiString) "  Save APC profile setting to file fail";
  1348.         Application->MessageBox( "Execution Failure : Save APC profile to file", "FAILURE", MB_OK );
  1349.         return;
  1350.     }
  1351.     ok = SaveDialog->Execute();
  1352.     if( !ok )
  1353.     {
  1354.         sbGUIAPCProfile->Panels->Items[0]->Text = (AnsiString) "  Save APC profile setting to file fail";
  1355.         Application->MessageBox( "Execution Failure : Save APC profile to file", "FAILURE", MB_OK );
  1356.         return;
  1357.     }
  1358.     if(frmMainSel->cbGSM850->Checked)
  1359.     //frmMainSel->Get_FinalBandSupport( band_support );
  1360.     //if( band_support.GSM850 )
  1361.     {   total_band_num = 4;
  1362.     }
  1363.     else
  1364.     {
  1365.         total_band_num = 3;
  1366.     }
  1367.     for(band=0; band<total_band_num; band++)
  1368.     {
  1369.        // RF_APC_Obj->ApcDcOffset[band] = ApcDcOffset[band];
  1370.        // RF_APC_Obj->ApcProfile[band] = m_sRFCal_RamTable[band];
  1371.         RF_APC_Obj->Set_HighApcDcOffset( band, m_usHighApcDcOffset[band] );
  1372.         if( m_bTADOSupport )
  1373.         {
  1374.             RF_APC_Obj->Set_LowApcDcOffset( band, m_usLowApcDcOffset[band] );
  1375.             RF_APC_Obj->Set_ApcLowestPower(band, ApcLowestPower[band]);
  1376.         }
  1377.         RF_APC_Obj->Set_ApcProfile( band, m_sRFCal_RamTable[band] );
  1378.     }
  1379.     strcpy( str, SaveDialog->FileName.c_str() );
  1380.     m_uiFinalRFID = frmMainSel->Get_FinalRFID();
  1381.     ok = RF_APC_Obj->REQ_Write_APC_To_File(str, m_uiFinalRFID, m_bTADOSupport);
  1382.     if( !ok )
  1383.     {
  1384.         sbGUIAPCProfile->Panels->Items[0]->Text = (AnsiString) "  Save APC profile setting to file fail";
  1385.         Application->MessageBox( "Execution Failure : Save APC profile to file", "FAILURE", MB_OK );
  1386.         return;
  1387.     }
  1388.     sbGUIAPCProfile->Panels->Items[0]->Text = (AnsiString) "  Save APC profile setting to file successfully";
  1389. }
  1390. //==============================================================================
  1391. void __fastcall TfrmGUIApcProfile::btnTXProfileSettingClick(
  1392.       TObject *Sender)
  1393. {
  1394.     frmApcProfile->Top  = 4;
  1395.     frmApcProfile->Left = 152;
  1396.     frmApcProfile->Show();
  1397. }
  1398. //==============================================================================
  1399. void  TfrmGUIApcProfile::CurrentPageLock( void )
  1400. {
  1401.     int i;
  1402.     // button
  1403.    // btnTXStart->Kind = bkNo;
  1404.    // btnTXStart->Caption = "Stop";
  1405.     btnTXStart->Enabled = false;
  1406.     btnTXStart->Tag = 1;
  1407.     btnUpLeft->Enabled = false;
  1408.     btnDnLeft->Enabled = false;
  1409.     btnUpRight->Enabled = false;
  1410.     btnDnRight->Enabled = false;
  1411.     btnUploadFromFlash->Enabled = false;
  1412.     btnDownloadToFlash->Enabled = false;
  1413.     btnChangeDB->Enabled = false;
  1414.     btnLoadFromFile->Enabled = false;
  1415.     btnSaveToFile->Enabled = false;
  1416.     for(i=0; i<TOTAL_PCL_DAC_NUM; i++ )
  1417.     {
  1418.         btnPCL[i]->Enabled = false;
  1419.     }
  1420.     // editor
  1421.     edtHighApcDcOffset->Enabled = false;
  1422.     edtLowApcDcOffset->Enabled = false;
  1423.     edtAPCLowestPower->Enabled = false;
  1424.     edtTestArfcn->Enabled = false;
  1425.     // PCL DAC
  1426.     for( i=0; i<TOTAL_PCL_DAC_NUM; i++ )
  1427.     {   edtPCLDAC[i]->Enabled = false;
  1428.     }
  1429.     // Ramp up, ramp down
  1430.     for( i=0; i<TOTAL_RAMP_DOWN_NUM; i++ )
  1431.     {
  1432.         edtRampUp[i]->Enabled = false;
  1433.         edtRampDn[i]->Enabled = false;
  1434.     }
  1435. }
  1436. //----------------------------------------------------------------------------
  1437. void  TfrmGUIApcProfile::CurrentPageReset( void )
  1438. {
  1439.     int i;
  1440.     // button
  1441.  //   btnTXStart->Kind = bkRetry;
  1442.    // btnTXStart->Caption = "Start";
  1443.     btnTXStart->Enabled = true;
  1444.     btnTXStart->Tag = 0;
  1445.     btnUpLeft->Enabled = true;
  1446.     btnDnLeft->Enabled = true;
  1447.     btnUpRight->Enabled = true;
  1448.     btnDnRight->Enabled = true;
  1449.     btnUploadFromFlash->Enabled = true;
  1450.     btnDownloadToFlash->Enabled = true;
  1451.     btnChangeDB->Enabled = true;
  1452.     btnLoadFromFile->Enabled = true;
  1453.     btnSaveToFile->Enabled = true;
  1454.     for(i=0; i<TOTAL_PCL_DAC_NUM; i++ )
  1455.     {
  1456.         btnPCL[i]->Enabled = true;
  1457.     }
  1458.     // editor
  1459.     edtHighApcDcOffset->Enabled = true;
  1460.     edtLowApcDcOffset->Enabled = true;
  1461.     edtAPCLowestPower->Enabled = true;
  1462.     edtTestArfcn->Enabled = true;
  1463.     // PCL DAC
  1464.     for( i=0; i<TOTAL_PCL_DAC_NUM; i++ )
  1465.     {   edtPCLDAC[i]->Enabled = true;
  1466.     }
  1467.     // Ramp up, ramp down
  1468.     for( i=0; i<TOTAL_RAMP_DOWN_NUM; i++ )
  1469.     {
  1470.         edtRampUp[i]->Enabled = true;
  1471.         edtRampDn[i]->Enabled = true;
  1472.     }
  1473. }
  1474. //==============================================================================
  1475. int  TfrmGUIApcProfile::ImageRangeCheck( int X, int Y )
  1476. {
  1477.     sRfImageRange  ImageRange;
  1478.     getImageValidRange(&ImageRange);
  1479.    // if( X < ImageRange.LeftTop.x )
  1480.    // {
  1481.    //     return  OUT_OF_LEFT_RANGE;
  1482.    // }
  1483.    // else if( X > ImageRange.RightBottom.x )
  1484.    // {
  1485.    //     return  OUT_OF_RIGHT_RANGE;
  1486.    // }
  1487.     if(  Y <= ImageRange.LeftTop.y )
  1488.     {
  1489.         return  OUT_OF_TOP_RANGE;
  1490.     }
  1491.     else if(  Y >= ImageRange.RightBottom.y )
  1492.     {
  1493.         return  OUT_OF_BOTTOM_RANGE;
  1494.     }
  1495.     return  IN_RANGE;
  1496. }
  1497. //-------------------------------------------------------------------------
  1498. void  TfrmGUIApcProfile::getImageValidRange( sRfImageRange  *p_ImageRange )
  1499. {
  1500.     p_ImageRange->LeftTop.x = 1;
  1501.     p_ImageRange->LeftTop.y = imRampProfile->Height - vDistance*(1.0*MAX_RAMP_DATA_VALUE/vScale) - vStart;
  1502.     p_ImageRange->RightBottom.x = (TOTAL_HORIZONTAL_SAMPLE-1)*hDistance;
  1503.     p_ImageRange->RightBottom.y = imRampProfile->Height - vStart;
  1504. }
  1505. //---------------------------------------------------------------------------
  1506. void __fastcall TfrmGUIApcProfile::FormHide(TObject *Sender)
  1507. {
  1508.     if (BTN_TAG_START == btnTXStart->Tag)
  1509.     {
  1510.         btnTXStopClick(this);
  1511.     }
  1512. }
  1513. //---------------------------------------------------------------------------
  1514. void __fastcall TfrmGUIApcProfile::btnChangeDBClick(TObject *Sender)
  1515. {
  1516.     if (!m_dlgOpenDB->Execute())
  1517.     {
  1518.         return;
  1519.     }
  1520.     CurrentPageLock();
  1521.     m_eNvramTrigger = NVRAM_TRIGGER_CHANGE_DB;
  1522.     NVRAMMan->ConfirmCallback = ::CNF_NVRAM_Init;
  1523.     NVRAMMan->REQ_Init(m_dlgOpenDB->FileName);
  1524. }
  1525. //---------------------------------------------------------------------------
  1526. bool TfrmGUIApcProfile::RampDataChange(l1cal_rampTable_T *p_RFCal_RamTable1, l1cal_rampTable_T *p_RFCal_RamTable2)
  1527. {
  1528.     for(int i=0; i<=15; i++)
  1529.     {
  1530.         if( p_RFCal_RamTable1->rampData.ramp[m_sCurPCLIndex].point[0][i] !=
  1531.             p_RFCal_RamTable2->rampData.ramp[m_sCurPCLIndex].point[0][i]
  1532.           )
  1533.         {
  1534.             return true;
  1535.         }
  1536.         if( p_RFCal_RamTable1->rampData.ramp[m_sCurPCLIndex].point[1][i] !=
  1537.             p_RFCal_RamTable2->rampData.ramp[m_sCurPCLIndex].point[1][i]
  1538.           )
  1539.         {
  1540.             return true;
  1541.         }
  1542.     }
  1543.     return false;
  1544. }    
  1545. void __fastcall TfrmGUIApcProfile::btnTXStopClick(TObject *Sender)
  1546. {
  1547.     if(btnTXStart->Tag==1)
  1548.     {
  1549.         frmRFTool->Force_RF_Stop();
  1550.         frmRFTool->pctlToolSel->Enabled = true;
  1551.         frmRFTool->btnTXStart->Enabled = true;
  1552.         CurrentPageReset();
  1553.         frmRFTool->CurrentPageReset();
  1554.         sbGUIAPCProfile->Panels->Items[0]->Text = (AnsiString)"  Burst TX stop";
  1555.     }
  1556. }
  1557. //---------------------------------------------------------------------------
  1558. void __fastcall TfrmGUIApcProfile::FormClose(TObject *Sender,
  1559.       TCloseAction &Action)
  1560. {
  1561.     if( m_stNVRAMDB->Caption.AnsiCompareIC("") != 0 )
  1562.     {
  1563.         write_APC_files_setup( "MF_setup.txt", Application->ExeName );
  1564.     }
  1565.     
  1566.     if (BTN_TAG_START == btnTXStart->Tag)
  1567.     {
  1568.         btnTXStopClick(this);
  1569.     }  
  1570. }
  1571. //===========================================================================
  1572. /////////////////////////////        Query       ////////////////////////////
  1573. //===========================================================================
  1574. void __fastcall TfrmGUIApcProfile::on_QueryTwoApcDcOffset_Fail(TObject *Sender)
  1575. {
  1576. }
  1577. //---------------------------------------------------------------------------
  1578. void __fastcall TfrmGUIApcProfile::on_QueryTwoApcDcOffset_TerminateSuccess(TObject *Sender)
  1579. {
  1580.     
  1581. }
  1582. //---------------------------------------------------------------------------
  1583. void  TfrmGUIApcProfile::Query_TwoApcDcOffset_Support( void )
  1584. {
  1585.     t_RfTado.hPostMsgDestHandle = this->Handle;
  1586.     t_RfTado.ne_onTermSuccess   = on_QueryTwoApcDcOffset_TerminateSuccess;
  1587.     pt_rftado = new T_RFTADO(
  1588.                                        true,
  1589.                                        &t_RfTado);
  1590.     if(pt_rftado != NULL)
  1591.     {
  1592.         pt_rftado->FreeOnTerminate = true;
  1593.         pt_rftado->OnTerminate = on_QueryTwoApcDcOffset_Fail;
  1594.         pt_rftado->Priority = tpHighest;
  1595.         pt_rftado->Resume();
  1596.     }
  1597. }
  1598. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1599. void __fastcall TfrmGUIApcProfile::on_QueryRfSetRampTableSupport_Fail(TObject *Sender)
  1600. {
  1601. }
  1602. //---------------------------------------------------------------------------
  1603. void __fastcall TfrmGUIApcProfile::on_QueryRfSetRampTableSupport_TerminateSuccess(TObject *Sender)
  1604. {
  1605.     
  1606. }
  1607. //---------------------------------------------------------------------------
  1608. void  TfrmGUIApcProfile::Query_RfSetRampTable_Support( void )
  1609. {
  1610.     t_RfSetRamp.hPostMsgDestHandle = this->Handle;
  1611.     t_RfSetRamp.ne_onTermSuccess   = on_QueryRfSetRampTableSupport_TerminateSuccess;
  1612.     pt_rfsetramp = new T_RFSETRAMP(
  1613.                                        true,
  1614.                                        &t_RfSetRamp);
  1615.     if(pt_rfsetramp != NULL)
  1616.     {
  1617.         pt_rfsetramp->FreeOnTerminate = true;
  1618.         pt_rfsetramp->OnTerminate = on_QueryRfSetRampTableSupport_Fail;
  1619.         pt_rfsetramp->Priority = tpHighest;
  1620.         pt_rfsetramp->Resume();
  1621.     }
  1622. }
  1623. //--------------------------------------------------------------------------
  1624. void  TfrmGUIApcProfile::DisplayTADOUI( bool b_tado_support )
  1625. {
  1626.     if( b_tado_support )
  1627.     {
  1628.         lblLowApcDcOffset->Visible = true;
  1629.         edtLowApcDcOffset->Visible = true;
  1630.         lblAPCLowestPower->Visible = true;
  1631.         edtAPCLowestPower->Visible = true;
  1632.     }
  1633.     else
  1634.     {
  1635.         lblLowApcDcOffset->Visible = false;
  1636.         edtLowApcDcOffset->Visible = false;
  1637.         lblAPCLowestPower->Visible = false;
  1638.         edtAPCLowestPower->Visible = false;
  1639.     }
  1640. }
  1641. //---------------------------------------------------------------------------
  1642. void __fastcall TfrmGUIApcProfile::edtLowApcDcOffsetCheck(TObject *Sender)
  1643. {
  1644.     unsigned short  usdata;
  1645.     int  band = m_eCurBand;
  1646.     AnsiString  text;
  1647.     TEdit *edit = (TEdit*)Sender;
  1648.     char  hint[] = " value shall be 0~1023 ";
  1649.     text = edit->Text;
  1650.     if (!IsValidPCLDac(text, usdata))
  1651.     {
  1652.         ShowHintLabel(edit, hint);
  1653.         edit->SetFocus();
  1654.         return;
  1655.     }
  1656.     m_usLowApcDcOffset[band] = usdata;
  1657. }
  1658. //---------------------------------------------------------------------------
  1659. void __fastcall TfrmGUIApcProfile::edtAPCLowestPowerCheck(TObject *Sender)
  1660. {
  1661.     int  i_data;
  1662.     int  band = m_eCurBand;
  1663.     AnsiString  text;
  1664.     TEdit *edit = (TEdit*)Sender;
  1665.     char  hint[][256] =
  1666.     {
  1667.         " value shall be 0~36 ",
  1668.         " value shall be 0~33 ",
  1669.         " value shall be 0~33 ",
  1670.         " value shall be 0~36 ",
  1671.     };
  1672.     text = edit->Text;
  1673.     if( !IsValidApcLowestPower( text, m_eCurBand, i_data ) )
  1674.     {   ShowHintLabel( edit, hint[m_eCurBand] );
  1675.         edit->SetFocus();
  1676.         return;
  1677.     }
  1678.     ApcLowestPower[band] = i_data;
  1679. }
  1680. //---------------------------------------------------------------------------
  1681. //===========================================================================
  1682. /////////////////////////////  Global information  //////////////////////////
  1683. //===========================================================================
  1684. //---------------------------------------------------------------------------
  1685. void  TfrmGUIApcProfile::Set_RF_APC_Obj( CRFAPC   *rf_apc_obj)
  1686. {
  1687.     RF_APC_Obj = rf_apc_obj;
  1688. }
  1689. //---------------------------------------------------------------------------
  1690. void  TfrmGUIApcProfile::Set_RF_TX_Obj( CRFTX   *rf_tx_obj)
  1691. {
  1692.     RF_TX_Obj = rf_tx_obj;
  1693. }