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

MTK

开发平台:

C++ Builder

  1. /*****************************************************************************
  2. *  Copyright Statement:
  3. *  --------------------
  4. *  This software is protected by Copyright and the information contained
  5. *  herein is confidential. The software may not be copied and the information
  6. *  contained herein may not be used or disclosed except with the written
  7. *  permission of MediaTek Inc. (C) 2005
  8. *
  9. *  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
  10. *  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
  11. *  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
  12. *  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
  13. *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
  14. *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
  15. *  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
  16. *  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
  17. *  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
  18. *  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
  19. *  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
  20. *  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
  21. *
  22. *  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
  23. *  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
  24. *  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
  25. *  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
  26. *  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
  27. *
  28. *  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
  29. *  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
  30. *  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
  31. *  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
  32. *  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
  33. *
  34. *****************************************************************************/
  35. /*****************************************************************************
  36.  *
  37.  * Filename:
  38.  * ---------
  39.  *   rf_InterSlotRampProfile.cpp
  40.  *
  41.  * Project:
  42.  * --------
  43.  *   Maui META APP
  44.  *
  45.  * Description:
  46.  * ------------
  47.  *   RF inter slot ramp profile source
  48.  *
  49.  * Author:
  50.  * -------
  51.  *  Andy Ueng (mtk00490)
  52.  *
  53.  *============================================================================
  54.  *             HISTORY
  55.  * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  56.  *------------------------------------------------------------------------------
  57.  * $Revision$
  58.  * $Modtime$
  59.  * $Log$
  60.  * 
  61.  *------------------------------------------------------------------------------
  62.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  63.  *============================================================================
  64.  ****************************************************************************/
  65. //---------------------------------------------------------------------------
  66. #include <IniFiles.hpp>
  67. #pragma hdrstop
  68. #include "form_RFTool.h"
  69. #include "form_Main.h"
  70. #include "rf_InterSlotRampProfile.h"
  71. #include "man_fdm.h"
  72. #include "man_active.h"
  73. // misc
  74. #include "misc.h"
  75. #ifndef  _FT_UTILS_H_
  76. #include "ft_utils.h"
  77. #endif
  78. //---------------------------------------------------------------------------
  79. #pragma package(smart_init)
  80. //#include "meta2.h"
  81. //===========================================================================
  82. static CRFINTERSLOTRAMP*  rf_inter_slot_ramp_ptr;
  83. extern TfrmMainSel *frmMainSel;
  84. //===========================================================================
  85. static  void  REQ_ReadFromNVRAM( void )
  86. {
  87.   rf_inter_slot_ramp_ptr->REQ_ReadFromNVRAM( );
  88. }
  89. static void  CNF_ReadFromNVRAM( void )
  90. {
  91.  rf_inter_slot_ramp_ptr->CNF_ReadFromNVRAM();
  92. }
  93. static  void  REQ_WriteToNVRAM( void )
  94. {
  95.   rf_inter_slot_ramp_ptr->REQ_WriteToNVRAM( );
  96. }
  97. static  void  CNF_WriteToNVRAM( void )
  98. {
  99.    rf_inter_slot_ramp_ptr->CNF_WriteToNVRAM( );
  100. }
  101. static void  REQ_TimeOut( void )
  102. {  rf_inter_slot_ramp_ptr->REQ_TimeOut();
  103. }
  104. static void  REQ_Finish( void )
  105. {  rf_inter_slot_ramp_ptr->REQ_Finish();
  106. }
  107. //===========================================================================
  108. CRFINTERSLOTRAMP::CRFINTERSLOTRAMP(void)
  109. {
  110.    IsRunning = false;
  111.    ConfirmCallback = 0;
  112.    InterRampBufSize = 0;
  113.    InterRampBuf = NULL;
  114. }
  115. //---------------------------------------------------------------------------
  116. CRFINTERSLOTRAMP::~CRFINTERSLOTRAMP()
  117. {
  118.    IsRunning = false;
  119.    ConfirmCallback = 0;
  120.    if(InterRampBuf)
  121.    {
  122.       delete [] InterRampBuf;
  123.       InterRampBuf = NULL;
  124.    }   
  125. }
  126. //---------------------------------------------------------------------------
  127. void  CRFINTERSLOTRAMP::REQ_Finish( void )
  128. {
  129.    if(!IsRunning)  return;
  130.    Confirm( STATE_INTER_SLOT_RAMP_OK );
  131.    IsRunning = false;
  132. }
  133. //---------------------------------------------------------------------------
  134. void  CRFINTERSLOTRAMP::REQ_Stop( void )
  135. {
  136.    if(!IsRunning)  return;
  137.    NVRAMMan->REQ_Stop();
  138.    Confirm( STATE_INTER_SLOT_RAMP_STOP );
  139.    IsRunning = false;
  140. }
  141. //---------------------------------------------------------------------------
  142. void  CRFINTERSLOTRAMP::REQ_TimeOut( void )
  143. {
  144.    if(!IsRunning)  return;
  145.    NVRAMMan->REQ_Stop();
  146.    Confirm( STATE_INTER_SLOT_RAMP_TIMEOUT );
  147.    IsRunning = false;
  148. }
  149. //---------------------------------------------------------------------------
  150. void  CRFINTERSLOTRAMP::Confirm( int confirm_state )
  151. {
  152.    if(!IsRunning)  return;
  153.    if(ConfirmCallback==0)  return;
  154.    ConfirmState = confirm_state;
  155.    ActiveMan->SetActiveFunction( ConfirmCallback );
  156. }
  157. //===========================================================================
  158. //static int   NVRAM_APC_LOWEST_POWER[] =
  159. //{  5, 0, 0, 5 };
  160. //static char  NVRAM_RAMPNAME[][32] =
  161. //{
  162. //   "L1_RAMPTABLE_GSM900",
  163. //   "L1_RAMPTABLE_DCS1800",
  164. //   "L1_RAMPTABLE_PCS1900",
  165. //   "L1_RAMPTABLE_GSM9850",
  166. //};
  167. //---------------------------------------------------------------------------
  168. void  CRFINTERSLOTRAMP::REQ_Read_From_NVRAM( void )
  169. {
  170.    rf_inter_slot_ramp_ptr = this;
  171.    IsRunning = true;
  172.    CurWRBand = BANDSEL_GSM900;
  173.   ActiveMan->SetActiveFunction( ::REQ_ReadFromNVRAM );
  174. }
  175. //-------------------------------------
  176. void  CRFINTERSLOTRAMP::REQ_ReadFromNVRAM( void )
  177. {  int  band = CurWRBand;
  178.    if(!IsRunning)  return;
  179.    if(InterRampBuf==0)
  180.    {
  181.     MetaResult = META_NVRAM_GetRecLen("NVRAM_EF_L1_INTERSLOT_RAMP_GSM850_LID", &InterRampBufSize );
  182.       if(MetaResult!=META_SUCCESS)
  183.       {  Confirm( STATE_INTER_SLOT_RAMP_FAIL );  return;  }
  184.       InterRampBuf = new  char[InterRampBufSize];
  185.    }
  186.    NVRAMMan->ConfirmCallback = ::CNF_ReadFromNVRAM;
  187.     switch(band)
  188.     {
  189.      case BANDSEL_GSM850:
  190.      NVRAMMan->REQ_ReadNVRAM_Start( "NVRAM_EF_L1_INTERSLOT_RAMP_GSM850_LID",
  191.                                         1, // only 1 record
  192.                                         InterRampBufSize,
  193.                                         InterRampBuf );
  194.      break;
  195.      case BANDSEL_GSM900:
  196.      NVRAMMan->REQ_ReadNVRAM_Start( "NVRAM_EF_L1_INTERSLOT_RAMP_GSM900_LID",
  197.                                         1, // only 1 record
  198.                                         InterRampBufSize,
  199.                                         InterRampBuf );
  200.      break;
  201.      case BANDSEL_DCS1800:
  202.         NVRAMMan->REQ_ReadNVRAM_Start( "NVRAM_EF_L1_INTERSLOT_RAMP_DCS1800_LID",
  203.                                        1, // only 1 record
  204.                                        InterRampBufSize,
  205.                                        InterRampBuf );
  206.      break;
  207.      case BANDSEL_PCS1900:
  208.         NVRAMMan->REQ_ReadNVRAM_Start( "NVRAM_EF_L1_INTERSLOT_RAMP_PCS1900_LID",
  209.                                        1, // only 1 record
  210.                                        InterRampBufSize,
  211.                                        InterRampBuf );
  212.      break;
  213.     }
  214. }
  215. //-------------------------------------
  216. void  CRFINTERSLOTRAMP::CNF_ReadFromNVRAM( void )
  217. {
  218.    int  band = CurWRBand;
  219.    if(!IsRunning)  return;
  220.    E_METAAPP_RESULT_T state = NVRAMMan->Get_ConfirmState();
  221.    if(state==METAAPP_SUCCESS)
  222.    {  int  i;
  223.       int  idata;
  224.       MetaResult = META_NVRAM_Decompose_interRampData( &Inter_RamTable[band],
  225.                                                        InterRampBuf,
  226.                                                        InterRampBufSize );
  227.       if(MetaResult!=META_SUCCESS)
  228.       {  Confirm( STATE_INTER_SLOT_RAMP_FAIL );  return;  }
  229.        if(band==BANDSEL_GSM850)
  230.       {  ActiveMan->SetActiveFunction( ::REQ_Finish );
  231.       }
  232.       else
  233.       {  CurWRBand++;
  234.          ActiveMan->SetActiveFunction( ::REQ_ReadFromNVRAM );
  235.       }
  236.    }
  237.    else if(state==METAAPP_TIMEOUT)
  238.    {   Confirm( STATE_INTER_SLOT_RAMP_TIMEOUT );
  239.    }
  240.    else if(state==METAAPP_STOP)
  241.    {   Confirm( STATE_INTER_SLOT_RAMP_STOP );
  242.    }
  243.    else
  244.    {   Confirm( STATE_INTER_SLOT_RAMP_FAIL );
  245.    }
  246. }
  247. //===========================================================================
  248. void  CRFINTERSLOTRAMP::REQ_Write_To_NVRAM( void )
  249. {
  250.    rf_inter_slot_ramp_ptr = this;
  251.    IsRunning = true;
  252.    m_bSingleBand = false;
  253.    CurWRBand = BANDSEL_GSM900;
  254.    ActiveMan->SetActiveFunction( ::REQ_WriteToNVRAM );
  255. }
  256. //-------------------------------------
  257. void  CRFINTERSLOTRAMP::REQ_Write_To_NVRAM_Single_Band( int  band )
  258. {
  259.    rf_inter_slot_ramp_ptr = this;
  260.    IsRunning = true;
  261.    m_bSingleBand = true;
  262.    CurWRBand = band;
  263.    ActiveMan->SetActiveFunction( ::REQ_WriteToNVRAM );
  264. }
  265. //-------------------------------------
  266. void  CRFINTERSLOTRAMP::REQ_WriteToNVRAM( void )
  267. {
  268.   int  i;
  269.    int  idata;
  270.    int  band = CurWRBand;
  271.    if(!IsRunning)  return;
  272.    if(InterRampBuf==0)
  273.    {
  274.       MetaResult = META_NVRAM_GetRecLen("NVRAM_EF_L1_INTERSLOT_RAMP_GSM850_LID", &InterRampBufSize);
  275.       if(MetaResult!=META_SUCCESS)
  276.       {  Confirm( STATE_INTER_SLOT_RAMP_FAIL );  return;  }
  277.       InterRampBuf = new  char[InterRampBufSize];
  278.    }
  279.    MetaResult = META_NVRAM_Compose_interRampData( &Inter_RamTable[band],
  280.                                                   InterRampBuf,
  281.                                                   InterRampBufSize );
  282.     if(MetaResult!=META_SUCCESS)
  283.       {  Confirm( STATE_INTER_SLOT_RAMP_FAIL );  return;  }
  284.     NVRAMMan->ConfirmCallback = ::CNF_WriteToNVRAM;
  285.                                                     
  286.    switch(band)
  287.      {
  288.       case BANDSEL_GSM850:
  289.      NVRAMMan->REQ_WriteNVRAM_Start( "NVRAM_EF_L1_INTERSLOT_RAMP_GSM850_LID",
  290.                                         1, // only 1 record
  291.                                         InterRampBufSize,
  292.                                         InterRampBuf );
  293.       break;
  294.       case BANDSEL_GSM900:
  295.      NVRAMMan->REQ_WriteNVRAM_Start( "NVRAM_EF_L1_INTERSLOT_RAMP_GSM900_LID",
  296.                                         1, // only 1 record
  297.                                         InterRampBufSize,
  298.                                         InterRampBuf );
  299.       break;
  300.       case BANDSEL_DCS1800:
  301.         NVRAMMan->REQ_WriteNVRAM_Start( "NVRAM_EF_L1_INTERSLOT_RAMP_DCS1800_LID",
  302.                                         1, // only 1 record
  303.                                         InterRampBufSize,
  304.                                         InterRampBuf );
  305.       break;
  306.    
  307.       case BANDSEL_PCS1900:
  308.         NVRAMMan->REQ_WriteNVRAM_Start( "NVRAM_EF_L1_INTERSLOT_RAMP_PCS1900_LID",
  309.                                         1, // only 1 record
  310.                                         InterRampBufSize,
  311.                                         InterRampBuf );
  312.       break;
  313.      }
  314.    
  315. }
  316. //-------------------------------------
  317. void  CRFINTERSLOTRAMP::CNF_WriteToNVRAM( void )
  318. {  int  band = CurWRBand;
  319.    if(!IsRunning)  return;
  320.    E_METAAPP_RESULT_T state = NVRAMMan->Get_ConfirmState();
  321.    if(state==METAAPP_SUCCESS)
  322.    {
  323.       if( (band==BANDSEL_GSM850)||(m_bSingleBand) )
  324.       {  ActiveMan->SetActiveFunction( ::REQ_Finish );
  325.       }
  326.       else
  327.       {  CurWRBand++;
  328.  ActiveMan->SetActiveFunction( ::REQ_WriteToNVRAM );
  329.       }
  330.    }
  331.  else if(state==METAAPP_TIMEOUT)
  332.    {   Confirm( STATE_INTER_SLOT_RAMP_TIMEOUT );
  333.    }
  334.  else if(state==METAAPP_STOP)
  335.    {   Confirm( STATE_INTER_SLOT_RAMP_STOP );
  336.    }
  337.    else
  338.    {   Confirm( STATE_INTER_SLOT_RAMP_FAIL );
  339.    }
  340. }
  341. //===========================================================================
  342. static const char  SUBBAND_NAME[][32] =
  343. {
  344.    "GSM900 inter slot ramp",
  345.    "DCS1800 inter slot ramp",
  346.    "PCS1900 inter slot ramp",
  347.    "GSM850 inter slot ramp",
  348. };
  349. //-------------------------------------------------------------------------
  350. bool  CRFINTERSLOTRAMP::REQ_Read_From_File( char *filename )
  351. {
  352.    TIniFile   *ini_file;
  353.    int band;
  354.    AnsiString  data;
  355.    int         idata[16], i;
  356.    int         total_band_num;
  357.    char        str[2048];
  358.    ini_file = new TIniFile( filename );
  359.    if( ini_file == NULL )  return false;
  360.    if(ini_file != NULL)
  361.    {
  362.       if(frmMainSel->cbGSM850->Checked)
  363.       //frmMainSel->Get_FinalBandSupport( band_support );
  364.       //if( band_support.GSM850 )
  365.       {   total_band_num = 4;
  366.       }
  367.       else
  368.       {
  369.           total_band_num = 3;
  370.       }
  371.       for( band = 0; band<total_band_num; band++)
  372.       {
  373.            data = ini_file->ReadString( SUBBAND_NAME[band],
  374.                                       "inter slot ramp profile",
  375.                                       "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0");
  376.            strcpy( str, data.c_str() );
  377.            String_To_Array_int( str, idata, 16 );
  378.            for( i=0; i<16; i++ )
  379.            {  Inter_RamTable[band].interRampData[i] = idata[i];  }
  380.       }
  381.      delete  ini_file;
  382.    }
  383.    return  true;
  384. }
  385. //===========================================================================
  386. bool  CRFINTERSLOTRAMP::REQ_Write_To_File( char *filename)
  387. {
  388.     TIniFile   *ini_file;
  389.     int         i, band;
  390.     int         idata[16];
  391.     int         total_band_num;
  392.     char        str[2048];
  393.     ini_file = new TIniFile( filename );
  394.     if( ini_file == NULL )  return false;
  395.     if(ini_file != NULL)
  396.     {
  397.         if(frmMainSel->cbGSM850->Checked)
  398.         //frmMainSel->Get_FinalBandSupport( band_support );
  399.         //if( band_support.GSM850 )
  400.         {   total_band_num = 4;
  401.         }
  402.         else
  403.         {
  404.             total_band_num = 3;
  405.         }
  406.         for( band = 0; band<total_band_num; band++)
  407.         {
  408.             for( i=0; i<16; i++ )
  409.             {
  410.                 idata[i] = Inter_RamTable[band].interRampData[i];
  411.             }
  412.             Array_To_String_int( str, idata, 16, ',' );
  413.             ini_file->WriteString( SUBBAND_NAME[band],
  414.                                     "inter slot ramp profile",
  415.                                     str);
  416.         }
  417.        delete  ini_file;
  418.     }
  419.     return true;
  420. }
  421. //===========================================================================
  422. static const char  BAND_NAME1[MAX_SUPPORT_BAND_NUM][12] =
  423. {  "GSM",
  424.    "DCS",
  425.    "PCS",
  426.    "GSM"
  427. };
  428. static const char  BAND_NAME2[MAX_SUPPORT_BAND_NUM][12] =
  429. {  "GSM900",
  430.    "DCS1800",
  431.    "PCS1900",
  432.    "GSM850"
  433. };
  434. static const int  LOWEST_POWER[MAX_SUPPORT_BAND_NUM] =
  435. {  5, 0, 0, 5  };
  436. static const char  BAND_PCL_COMMENT[MAX_SUPPORT_BAND_NUM][128] =
  437. {  "   /*  5,  7,  9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35 dBm                        */n",
  438.    "   /*    0,  2,  4,  6,  8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30 dBm                      */n",
  439.    "   /*    0,  2,  4,  6,  8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30 dBm                      */n",
  440.    "   /*  5,  7,  9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35 dBm                        */n",
  441. };
  442. //===========================================================================
  443. ////////////////////////////  Global information  ///////////////////////////
  444. //===========================================================================
  445. int  CRFINTERSLOTRAMP::Get_ConfirmState( void )
  446. {
  447.     return  ConfirmState;
  448. }