rf_EpskInterSlotRampProfile.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) 2001
  8. *
  9. *****************************************************************************/
  10. /*****************************************************************************
  11.  *
  12.  * Filename:
  13.  * ---------
  14.  *   rf_EpskInterSlotRampProfile.cpp
  15.  *
  16.  * Project:
  17.  * --------
  18.  *   Maui META APP
  19.  *
  20.  * Description:
  21.  * ------------
  22.  *   RF EPSK inter slot ramp profile source
  23.  *
  24.  * Author:
  25.  * -------
  26.  *  Andy Ueng (mtk00490)
  27.  *
  28.  *============================================================================
  29.  *             HISTORY
  30.  * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  31.  *------------------------------------------------------------------------------
  32.  * $Revision$
  33.  * $Modtime$
  34.  * $Log$
  35.  * 
  36.  *------------------------------------------------------------------------------
  37.  * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
  38.  *============================================================================
  39.  ****************************************************************************/
  40. //---------------------------------------------------------------------------
  41. #include <IniFiles.hpp>
  42. #pragma hdrstop
  43. #include "form_RFTool.h"
  44. #include "form_Main.h"
  45. #include "rf_InterSlotRampProfile.h"
  46. #include "man_fdm.h"
  47. #include "man_active.h"
  48. // misc
  49. #include "misc.h"
  50. #ifndef  _FT_UTILS_H_
  51. #include "ft_utils.h"
  52. #endif
  53. //---------------------------------------------------------------------------
  54. #pragma package(smart_init)
  55. #ifndef _RF_EPSKINTERSLOTRAMPPROFILE_H_
  56. #include "rf_epskinterslotrampprofile.h"
  57. #endif
  58. static const EPSK_INTER_RAMP_NUM=4;
  59. //===========================================================================
  60. static CRFEPSKINTERSLOTRAMP*  rf_epsk_inter_slot_ramp_ptr;
  61. static bool g_bIsRunning = false;
  62. extern TfrmMainSel *frmMainSel;
  63. //===========================================================================
  64. static  void  REQ_ReadFromNVRAM( void )
  65. {   rf_epsk_inter_slot_ramp_ptr->REQ_ReadFromNVRAM( );
  66. }
  67. //---------------------------------------------------------------------------
  68. static void  CNF_ReadFromNVRAM( void )
  69. {   rf_epsk_inter_slot_ramp_ptr->CNF_ReadFromNVRAM();
  70. }
  71. //---------------------------------------------------------------------------
  72. static  void  REQ_WriteToNVRAM( void )
  73. {   rf_epsk_inter_slot_ramp_ptr->REQ_WriteToNVRAM( );
  74. }
  75. //---------------------------------------------------------------------------
  76. static  void  CNF_WriteToNVRAM( void )
  77. {   rf_epsk_inter_slot_ramp_ptr->CNF_WriteToNVRAM( );
  78. }
  79. //---------------------------------------------------------------------------
  80. static void  REQ_TimeOut( void )
  81. {  rf_epsk_inter_slot_ramp_ptr->REQ_TimeOut();
  82. }
  83. //---------------------------------------------------------------------------
  84. static void  REQ_Finish( void )
  85. {  rf_epsk_inter_slot_ramp_ptr->REQ_Finish();
  86. }
  87. //===========================================================================
  88. CRFEPSKINTERSLOTRAMP::CRFEPSKINTERSLOTRAMP(void)
  89. {
  90.    g_bIsRunning = false;
  91.    ConfirmCallback = 0;
  92.    EpskInterRampBufSize = 0;
  93.    EpskInterRampBuf = NULL;
  94. }
  95. //---------------------------------------------------------------------------
  96. CRFEPSKINTERSLOTRAMP::~CRFEPSKINTERSLOTRAMP()
  97. {
  98.     g_bIsRunning = false;
  99.     ConfirmCallback = 0;
  100.     if(EpskInterRampBuf)
  101.     {
  102.         delete [] EpskInterRampBuf;
  103.         EpskInterRampBuf = NULL;
  104.     }
  105. }
  106. //---------------------------------------------------------------------------
  107. void  CRFEPSKINTERSLOTRAMP::REQ_Finish( void )
  108. {
  109.    if(!g_bIsRunning)  return;
  110.    Confirm( METAAPP_SUCCESS );
  111.    g_bIsRunning = false;
  112. }
  113. //---------------------------------------------------------------------------
  114. void  CRFEPSKINTERSLOTRAMP::REQ_Stop( void )
  115. {
  116.    if(!g_bIsRunning)  return;
  117.    NVRAMMan->REQ_Stop();
  118.    Confirm( METAAPP_STOP );
  119.    g_bIsRunning = false;
  120. }
  121. //---------------------------------------------------------------------------
  122. void  CRFEPSKINTERSLOTRAMP::REQ_TimeOut( void )
  123. {
  124.    if(!g_bIsRunning)  return;
  125.    NVRAMMan->REQ_Stop();
  126.    Confirm( METAAPP_TIMEOUT );
  127.    g_bIsRunning = false;
  128. }
  129. //---------------------------------------------------------------------------
  130. void CRFEPSKINTERSLOTRAMP::Confirm(E_METAAPP_RESULT_T confirm_state)
  131. {
  132.    if(!g_bIsRunning)  return;
  133.    if(ConfirmCallback==0)  return;
  134.    m_eConfirmState = confirm_state;
  135.    ActiveMan->SetActiveFunction( ConfirmCallback );
  136. }
  137. //===========================================================================
  138. //static int   NVRAM_APC_LOWEST_POWER[] =
  139. //{  5, 0, 0, 5 };
  140. //static char  NVRAM_RAMPNAME[][32] =
  141. //{
  142. //   "L1_RAMPTABLE_GSM900",
  143. //   "L1_RAMPTABLE_DCS1800",
  144. //   "L1_RAMPTABLE_PCS1900",
  145. //   "L1_RAMPTABLE_GSM9850",
  146. //};
  147. //---------------------------------------------------------------------------
  148. void  CRFEPSKINTERSLOTRAMP::REQ_Read_From_NVRAM( void )
  149. {
  150.    rf_epsk_inter_slot_ramp_ptr = this;
  151.    g_bIsRunning = true;
  152.    CurWRBand = BANDSEL_GSM900;
  153.    ActiveMan->SetActiveFunction( ::REQ_ReadFromNVRAM );
  154. }
  155. //-------------------------------------
  156. void  CRFEPSKINTERSLOTRAMP::REQ_ReadFromNVRAM( void )
  157. {
  158.     if(!g_bIsRunning)  return;
  159.     int  band = CurWRBand;
  160.     if (NULL == EpskInterRampBuf)
  161.     {
  162.         META_RESULT MetaResult = META_NVRAM_GetRecLen("NVRAM_EF_L1_EPSK_INTERSLOT_RAMP_GSM850_LID", &EpskInterRampBufSize);
  163.         if(MetaResult!=META_SUCCESS)
  164.         {  Confirm( METAAPP_FAIL );  return;  }
  165.         EpskInterRampBuf = new  char[EpskInterRampBufSize];
  166.     }
  167.     NVRAMMan->ConfirmCallback = ::CNF_ReadFromNVRAM;
  168.     switch(band)
  169.     {
  170.         case BANDSEL_GSM850:
  171.          NVRAMMan->REQ_ReadNVRAM_Start( "NVRAM_EF_L1_EPSK_INTERSLOT_RAMP_GSM850_LID",
  172.                                         1, // only 1 record
  173.                                         EpskInterRampBufSize,
  174.                                         EpskInterRampBuf );
  175.         break;
  176.         case BANDSEL_GSM900:
  177.          NVRAMMan->REQ_ReadNVRAM_Start( "NVRAM_EF_L1_EPSK_INTERSLOT_RAMP_GSM900_LID",
  178.                                         1, // only 1 record
  179.                                         EpskInterRampBufSize,
  180.                                         EpskInterRampBuf );
  181.         break;
  182.         case BANDSEL_DCS1800:
  183.             NVRAMMan->REQ_ReadNVRAM_Start( "NVRAM_EF_L1_EPSK_INTERSLOT_RAMP_DCS1800_LID",
  184.                                        1, // only 1 record
  185.                                        EpskInterRampBufSize,
  186.                                        EpskInterRampBuf );
  187.         break;
  188.         case BANDSEL_PCS1900:
  189.             NVRAMMan->REQ_ReadNVRAM_Start( "NVRAM_EF_L1_EPSK_INTERSLOT_RAMP_PCS1900_LID",
  190.                                        1, // only 1 record
  191.                                        EpskInterRampBufSize,
  192.                                        EpskInterRampBuf );
  193.         break;
  194.     }
  195. }
  196. //-------------------------------------
  197. void  CRFEPSKINTERSLOTRAMP::CNF_ReadFromNVRAM( void )
  198. {
  199.     if(!g_bIsRunning)  return;
  200.     int  band = CurWRBand;
  201.     E_METAAPP_RESULT_T state = NVRAMMan->Get_ConfirmState();
  202.     if(state==METAAPP_SUCCESS)
  203.     {
  204.         int  i;
  205.         int  idata;
  206.         META_RESULT MetaResult = META_NVRAM_Decompose_EPSK_interRampData( &EPSK_Inter_RamTable[band],
  207.                                                        EpskInterRampBuf,
  208.                                                        EpskInterRampBufSize );
  209.         if(MetaResult!=META_SUCCESS)
  210.         {   Confirm( METAAPP_FAIL );  return;  }
  211.         if(band==BANDSEL_GSM850)
  212.         {  ActiveMan->SetActiveFunction( ::REQ_Finish );
  213.         }
  214.         else
  215.         {
  216.             CurWRBand++;
  217.             ActiveMan->SetActiveFunction( ::REQ_ReadFromNVRAM );
  218.         }
  219.     }
  220.     else
  221.     {   Confirm(state);
  222.     }
  223. }
  224. //===========================================================================
  225. void  CRFEPSKINTERSLOTRAMP::REQ_Write_To_NVRAM( void )
  226. {
  227.     rf_epsk_inter_slot_ramp_ptr = this;
  228.     g_bIsRunning = true;
  229.     m_bSingleBand = false;
  230.     CurWRBand = BANDSEL_GSM900;
  231.     ActiveMan->SetActiveFunction( ::REQ_WriteToNVRAM );
  232. }
  233. //-------------------------------------
  234. void  CRFEPSKINTERSLOTRAMP::REQ_Write_To_NVRAM_Single_Band( int  band )
  235. {
  236.     rf_epsk_inter_slot_ramp_ptr = this;
  237.     g_bIsRunning = true;
  238.     m_bSingleBand = true;
  239.     CurWRBand = band;
  240.     ActiveMan->SetActiveFunction( ::REQ_WriteToNVRAM );
  241. }
  242. //-------------------------------------
  243. void  CRFEPSKINTERSLOTRAMP::REQ_WriteToNVRAM( void )
  244. {
  245.     if(!g_bIsRunning)  return;
  246.     int  i;
  247.     int  idata;
  248.     int  band = CurWRBand;
  249.     META_RESULT  MetaResult;
  250.     if (NULL == EpskInterRampBuf)
  251.     {
  252.         MetaResult = META_NVRAM_GetRecLen("NVRAM_EF_L1_EPSK_INTERSLOT_RAMP_GSM850_LID", &EpskInterRampBufSize );
  253.         if(MetaResult!=META_SUCCESS)
  254.         {  Confirm( METAAPP_FAIL );  return;  }
  255.         EpskInterRampBuf = new  char[EpskInterRampBufSize];
  256.     }
  257.     MetaResult = META_NVRAM_Compose_EPSK_interRampData( &EPSK_Inter_RamTable[band],
  258.                                                   EpskInterRampBuf,
  259.                                                   EpskInterRampBufSize );
  260.     if(MetaResult!=META_SUCCESS)
  261.     {  Confirm( METAAPP_FAIL );  return;  }
  262.     NVRAMMan->ConfirmCallback = ::CNF_WriteToNVRAM;
  263.     switch(band)
  264.     {
  265.         case BANDSEL_GSM850:
  266.          NVRAMMan->REQ_WriteNVRAM_Start( "NVRAM_EF_L1_EPSK_INTERSLOT_RAMP_GSM850_LID",
  267.                                         1, // only 1 record
  268.                                         EpskInterRampBufSize,
  269.                                         EpskInterRampBuf );
  270.         break;
  271.         case BANDSEL_GSM900:
  272.          NVRAMMan->REQ_WriteNVRAM_Start( "NVRAM_EF_L1_EPSK_INTERSLOT_RAMP_GSM900_LID",
  273.                                         1, // only 1 record
  274.                                         EpskInterRampBufSize,
  275.                                         EpskInterRampBuf );
  276.         break;
  277.         case BANDSEL_DCS1800:
  278.             NVRAMMan->REQ_WriteNVRAM_Start( "NVRAM_EF_L1_EPSK_INTERSLOT_RAMP_DCS1800_LID",
  279.                                         1, // only 1 record
  280.                                         EpskInterRampBufSize,
  281.                                         EpskInterRampBuf );
  282.         break;
  283.         case BANDSEL_PCS1900:
  284.             NVRAMMan->REQ_WriteNVRAM_Start( "NVRAM_EF_L1_EPSK_INTERSLOT_RAMP_PCS1900_LID",
  285.                                         1, // only 1 record
  286.                                         EpskInterRampBufSize,
  287.                                         EpskInterRampBuf );
  288.         break;
  289.     }
  290. }
  291. //-------------------------------------
  292. void  CRFEPSKINTERSLOTRAMP::CNF_WriteToNVRAM( void )
  293. {
  294.     if(!g_bIsRunning)  return;
  295.     int  band = CurWRBand;
  296.     E_METAAPP_RESULT_T state = NVRAMMan->Get_ConfirmState();
  297.     if(state==METAAPP_SUCCESS)
  298.     {
  299.         if( (band==BANDSEL_GSM850)||(m_bSingleBand) )
  300.         {  ActiveMan->SetActiveFunction( ::REQ_Finish );
  301.         }
  302.         else
  303.         {
  304.             CurWRBand++;
  305.             ActiveMan->SetActiveFunction( ::REQ_WriteToNVRAM );
  306.         }
  307.     }
  308.     else
  309.     {
  310.         Confirm(state);
  311.     }
  312. }
  313. //===========================================================================
  314. static const char  SUBBAND_NAME[][32] =
  315. {
  316.    "GSM900 EPSK inter slot ramp",
  317.    "DCS1800 EPSK inter slot ramp",
  318.    "PCS1900 EPSK inter slot ramp",
  319.    "GSM850 EPSK inter slot ramp",
  320. };
  321. //-------------------------------------------------------------------------
  322. static const char  SECTION_NAME[][32] =
  323. {
  324.    "GMSK GMSK inter slot ramp",
  325.    "GMSK EPSK inter slot ramp",
  326.    "EPSK GMSK inter slot ramp",
  327.    "EPSK EPSK inter slot ramp",
  328. };
  329. //-------------------------------------------------------------------------
  330. bool  CRFEPSKINTERSLOTRAMP::REQ_Read_From_File( char *filename )
  331. {
  332.     TIniFile   *ini_file;
  333.     int band;
  334.     AnsiString  as_data;
  335.     unsigned char         ucdata[16];
  336.     int         i, section;
  337.     int         total_band_num;
  338.     char        str[2048];
  339.     ini_file = new TIniFile( filename );
  340.     if( ini_file == NULL )  return false;
  341.     if(ini_file != NULL)
  342.     {
  343.         if(frmMainSel->cbGSM850->Checked)
  344.       //frmMainSel->Get_FinalBandSupport( band_support );
  345.       //if( band_support.GSM850 )
  346.         {   total_band_num = 4;
  347.         }
  348.         else
  349.         {
  350.             total_band_num = 3;
  351.         }
  352.         for( band = 0; band<total_band_num; band++)
  353.         {
  354.             for( section=0; section<EPSK_INTER_RAMP_NUM; section++ )
  355.             {
  356.                 as_data = ini_file->ReadString( SUBBAND_NAME[band],
  357.                                       SECTION_NAME[section],
  358.                                       "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0");
  359.                 strcpy( str, as_data.c_str() );
  360.                 String_To_Array_UnsignedChar( str, ucdata, 16 );
  361.                 for( i=0; i<16; i++ )
  362.                 {   EPSK_Inter_RamTable[band].EPSK_interRampData[section][i] = ucdata[i];  }
  363.             }    
  364.         }
  365.         delete  ini_file;
  366.     }
  367.     return  true;
  368. }
  369. //===========================================================================
  370. bool  CRFEPSKINTERSLOTRAMP::REQ_Write_To_File( char *filename)
  371. {
  372.     TIniFile   *ini_file;
  373.     int         i, band, section;
  374.     unsigned char         ucdata[16];
  375.     int         total_band_num;
  376.     char        str[2048];
  377.     ini_file = new TIniFile( filename );
  378.     if( ini_file == NULL )  return false;
  379.     if(ini_file != NULL)
  380.     {
  381.         if(frmMainSel->cbGSM850->Checked)
  382.         //frmMainSel->Get_FinalBandSupport( band_support );
  383.         //if( band_support.GSM850 )
  384.         {   total_band_num = 4;
  385.         }
  386.         else
  387.         {
  388.             total_band_num = 3;
  389.         }
  390.         for( band=0; band<total_band_num; band++)
  391.         {
  392.             for( section=0; section<EPSK_INTER_RAMP_NUM; section++ )
  393.             {
  394.                 for( i=0; i<16; i++ )
  395.                 {
  396.                     ucdata[i] = EPSK_Inter_RamTable[band].EPSK_interRampData[section][i];
  397.                 }
  398.                 Array_To_String_UnsignedChar( str, ucdata, 16, ',' );
  399.                 ini_file->WriteString( SUBBAND_NAME[band],
  400.                                     SECTION_NAME[section],
  401.                                     str);
  402.             }
  403.         }
  404.        delete  ini_file;
  405.     }
  406.     return true;
  407. }
  408. //===========================================================================
  409. static const char  BAND_NAME1[MAX_SUPPORT_BAND_NUM][12] =
  410. {  "GSM",
  411.    "DCS",
  412.    "PCS",
  413.    "GSM"
  414. };
  415. static const char  BAND_NAME2[MAX_SUPPORT_BAND_NUM][12] =
  416. {  "GSM900",
  417.    "DCS1800",
  418.    "PCS1900",
  419.    "GSM850"
  420. };
  421. static const int  LOWEST_POWER[MAX_SUPPORT_BAND_NUM] =
  422. {  5, 0, 0, 5  };
  423. static const char  BAND_PCL_COMMENT[MAX_SUPPORT_BAND_NUM][128] =
  424. {  "   /*  5,  7,  9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35 dBm                        */n",
  425.    "   /*    0,  2,  4,  6,  8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30 dBm                      */n",
  426.    "   /*    0,  2,  4,  6,  8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30 dBm                      */n",
  427.    "   /*  5,  7,  9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35 dBm                        */n",
  428. };
  429. //===========================================================================
  430. ////////////////////////////  Global information  ///////////////////////////
  431. //===========================================================================
  432. E_METAAPP_RESULT_T CRFEPSKINTERSLOTRAMP::Get_ConfirmState(void)
  433. {
  434.     return  m_eConfirmState;
  435. }
  436. //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  437. void  CRFEPSKINTERSLOTRAMP::Set_InterSlotRamp(int band_idx, l1cal_EPSK_interRampData_T  epsk_inter_ramp )
  438. {
  439.     EPSK_Inter_RamTable[band_idx] = epsk_inter_ramp;
  440. }
  441. //---------------------------------------------------------------------------
  442. l1cal_EPSK_interRampData_T    CRFEPSKINTERSLOTRAMP::Get_InterSlotRamp(int band_idx )
  443. {
  444.     return EPSK_Inter_RamTable[band_idx];
  445. }